diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000000..d25a87139e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,69 @@ +name: Bug report +description: Report a bug with the twilio-java helper library. +title: "[BUG] Describe the issue briefly" +labels: "type: bug" +body: + - type: markdown + attributes: + value: | + Thank you for reporting a bug in the twilio-java helper library. Please provide the details below to help us investigate and resolve the issue. + + - type: textarea + attributes: + label: Describe the bug + description: Provide a clear and concise description of the issue. + placeholder: A clear and concise description of the bug. + validations: + required: true + + - type: textarea + attributes: + label: Code snippet + description: Provide the code snippet that reproduces the issue. + placeholder: "```\n// Code snippet here\n```" + validations: + required: true + + - type: textarea + attributes: + label: Actual behavior + description: Describe what actually happened. + placeholder: A description of the actual behavior. + validations: + required: true + + - type: textarea + attributes: + label: Expected behavior + description: Describe what you expected to happen. + placeholder: A description of the expected outcome. + validations: + required: true + + - type: input + attributes: + label: twilio-java version + description: Specify the version of the twilio-java helper library you are using. + placeholder: e.g., 10.5.1 + validations: + required: true + + - type: input + attributes: + label: Java version + description: Specify the version of Java you are using. + placeholder: e.g., OpenJDK 11.0.16 + validations: + required: true + + - type: textarea + attributes: + label: Logs or error messages + description: Provide relevant logs or error messages (if any). + placeholder: "Error: Something went wrong..." + + - type: textarea + attributes: + label: Additional context + description: Add any other context about the problem here. + placeholder: Any additional diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000000..cf26637ded --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,10 @@ +contact_links: + - name: Twilio Support + url: https://twilio.com/help/contact + about: Get Support + - name: Stack Overflow + url: https://stackoverflow.com/questions/tagged/twilio-java+or+twilio+java + about: Ask questions on Stack Overflow + - name: Documentation + url: https://www.twilio.com/docs/libraries/reference/twilio-java + about: View Reference Documentation diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..5ace4600a1 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..7bca2db28a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI + +on: + push: + branches: ['*'] + pull_request: + branches: [main] + workflow_dispatch: + inputs: + java-version: + description: "Java version (or 'all' for full matrix)" + required: false + default: "11" + +jobs: + test: + name: Test - Java ${{ matrix.java }} + runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }} + if: github.repository_owner == 'twilio' + timeout-minutes: 20 + permissions: + contents: read + id-token: write + strategy: + fail-fast: false + matrix: + java: ${{ github.event.inputs.java-version == 'all' && fromJson('[8, 11, 17, 21]') || fromJson(format('[{0}]', github.event.inputs.java-version || '11')) }} + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + fetch-depth: 0 + + - name: Artifactory OIDC + if: ${{ !github.event.pull_request.head.repo.fork }} + uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven + with: + ecosystem: maven + + - name: Set up Java + uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2 + with: + distribution: temurin + java-version: ${{ matrix.java }} + cache: maven + + - run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V + + - name: Run unit tests + run: mvn test -B + +# - name: SonarCloud scan +# if: ${{ matrix.java == 11 && !github.event.pull_request.head.repo.fork && (github.event_name == 'pull_request' || github.ref_type == 'branch') }} +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} +# run: mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=twilio_twilio-java diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml new file mode 100644 index 0000000000..fea5acfd2f --- /dev/null +++ b/.github/workflows/pr-lint.yml @@ -0,0 +1,21 @@ +# todo: whitelist or replace the action & enable it +name: Lint PR +on: + workflow_dispatch: + +jobs: + validate: + name: Validate title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@9ebc021bcf7ac66f840f985c84d0ef77afd5e8d9 # v5.5.1 + with: + types: | + chore + docs + fix + feat + misc + test + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 0000000000..3d217c32e1 --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -0,0 +1,88 @@ +name: Cluster Tests and Release Readiness + +on: + push: + branches: [main] + schedule: + - cron: '0 15 * * 1' # 8AM PST every Monday + workflow_dispatch: + +jobs: + cluster-test: + name: Cluster Tests + runs-on: ubuntu-x64 + if: github.repository_owner == 'twilio' + timeout-minutes: 20 +# todo: when the bot allows another env to exist +# environment: pre-production + environment: production + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + + - name: Artifactory OIDC + uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven + with: + ecosystem: maven + + - name: Set up Java + uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2 + with: + distribution: temurin + java-version: '11' + cache: maven + + - run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V + + - name: Run cluster tests + env: + TWILIO_ACCOUNT_SID: ${{ secrets.TWILIO_ACCOUNT_SID }} + TWILIO_API_KEY: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY }} + TWILIO_API_SECRET: ${{ secrets.TWILIO_CLUSTER_TEST_API_KEY_SECRET }} + TWILIO_FROM_NUMBER: ${{ secrets.TWILIO_FROM_NUMBER }} + TWILIO_TO_NUMBER: ${{ secrets.TWILIO_TO_NUMBER }} + TWILIO_ORGS_CLIENT_ID: ${{ secrets.TWILIO_ORGS_CLIENT_ID }} + TWILIO_ORGS_CLIENT_SECRET: ${{ secrets.TWILIO_ORGS_CLIENT_SECRET }} + TWILIO_ORG_SID: ${{ secrets.TWILIO_ORG_SID }} + TWILIO_CLIENT_ID: ${{ secrets.TWILIO_CLIENT_ID }} + TWILIO_CLIENT_SECRET: ${{ secrets.TWILIO_CLIENT_SECRET }} + TWILIO_MESSAGE_SID: ${{ secrets.TWILIO_MESSAGE_SID }} + run: mvn test -Dtest=ClusterTest -B + + deploy-dry-run: + name: Release Readiness Check + needs: [cluster-test] + runs-on: ubuntu-x64 + if: github.repository_owner == 'twilio' + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + + - name: Artifactory OIDC + uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven + with: + ecosystem: maven + + - name: Set up Java + uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2 + with: + distribution: temurin + java-version: '11' + cache: maven + + - run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V + + - name: Build artifacts (dry run) + run: mvn clean package -DskipTests -B -Prelease -Dgpg.skip + + - name: Dry run summary + run: | + PKG_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + echo "Built artifacts:" + ls -lh target/*.jar 2>/dev/null || echo "No artifacts found" + echo "Package version: $PKG_VERSION" + echo "--- DRY RUN COMPLETE ---" diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml new file mode 100644 index 0000000000..9904c6ddf7 --- /dev/null +++ b/.github/workflows/test-and-deploy.yml @@ -0,0 +1,119 @@ +name: Twilio Public release-maven + +on: + push: + tags: + - '*' + workflow_dispatch: + +jobs: + test: + name: Test + runs-on: ubuntu-x64 + if: github.repository_owner == 'twilio' + timeout-minutes: 20 + permissions: + contents: read + id-token: write + strategy: + matrix: + java: [8, 11, 17, 21] + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + + - name: Artifactory OIDC + uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven + with: + ecosystem: maven + + - name: Set up Java + uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2 + with: + distribution: temurin + java-version: ${{ matrix.java }} + cache: maven + + - run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V + - name: Run unit tests + run: mvn test -B + + deploy: + name: Publish to Maven Central + needs: [test] + runs-on: ubuntu-x64 + if: success() && github.ref_type == 'tag' && github.repository_owner == 'twilio' + environment: + name: production + url: https://central.sonatype.com/artifact/com.twilio.sdk/twilio/${{ github.ref_name }} + permissions: + contents: write + id-token: write + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + fetch-depth: 0 + + - name: Artifactory OIDC + uses: twilio/sdk-actions/artifactory-oidc@4ffc0c647c8d692a8fff24d4f767b207c3d1222e # java_maven + with: + ecosystem: maven + +# - name: Login to Docker Hub +# uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 # v2 +# with: +# username: ${{ secrets.DOCKER_USERNAME }} +# password: ${{ secrets.DOCKER_AUTH_TOKEN }} + + - name: Get tagged version + run: echo "GITHUB_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Create GitHub Release + uses: sendgrid/dx-automator/actions/release@08b601b726671445abc798ed59881766ec8fefc6 + with: + footer: '**[Maven](https://central.sonatype.com/artifact/com.twilio.sdk/twilio/${version})**' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +# - name: Build and push Docker image +# run: make docker-build && make docker-push + + - name: Set up Java for Maven Central publish + uses: actions/setup-java@e9fbacdec3bb3b6036605a3e6f7995d66773a8c6 # v3.14.2 + with: + java-version: '11' + distribution: temurin + server-id: central + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: GPG_PASSPHRASE + + # Workaround for apache/maven#13388: Maven 3.10.0 (default on the runner image) makes + # central-publishing-maven-plugin stage local-repository files (maven-metadata-local.xml, + # _remote.repositories) into the bundle, which Maven Central rejects with + # "Bundle has content that does NOT have a .pom file". Tracked upstream in + # mavenplugins/central-publishing-maven-plugin#79 / #80. Remove once the plugin is fixed. + - name: Pin Maven 3.9.16 + env: + MAVEN_VERSION: 3.9.16 + run: | + base="https://archive.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz" + curl -fsSL "$base" -o "$RUNNER_TEMP/maven.tgz" + echo "$(curl -fsSL "$base.sha512" | cut -d' ' -f1) $RUNNER_TEMP/maven.tgz" | sha512sum -c - + tar -xzf "$RUNNER_TEMP/maven.tgz" -C "$RUNNER_TEMP" + echo "$RUNNER_TEMP/apache-maven-${MAVEN_VERSION}/bin" >> "$GITHUB_PATH" + + - run: mvn install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V + + - name: Publish to Maven Central + env: + MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + run: mvn clean deploy -DskipTests=true -B -U -Prelease + +# - name: Submit metric to Datadog +# uses: sendgrid/dx-automator/actions/datadog-release-metric@08b601b726671445abc798ed59881766ec8fefc6 +# env: +# DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + diff --git a/.gitignore b/.gitignore index 5e50c12c1f..1c222a68ac 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,15 @@ .idea/ out/ target/ -java/** +docs/ src/main/java/com/twilio/Twilio.java.bak secret.key pom.xml.releaseBackup release.properties +.classpath +.project +.settings/ +settings.json +**/.openapi-generator* +.claude/settings.local.json +CLAUDE.md \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 56b21ea68b..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -language: java -sudo: false -jdk: - - oraclejdk8 - - openjdk7 -notifications: - slack: - on_success: change - on_failure: change - rooms: - - secure: MkRPjhMDkLMT0tKhSzSAEEdLxKlFrcEw00FBgpcpIl50kSpe3gxCJsm2bz5+LySblCfY1nI5D1+R++eB5cxJzgZvEBWIXQnGJVAV+X7WW1CI1FBZlv6FNLBe5gVPPzo5kIIM1g3o7AaERcraHK9h9S9N8cpnBRHe+Xf6wTRqmwo= - - secure: iRd6XcgHGFSJ/eS1ZwCUgUVTK0a+JAPmyPEx/OdFbma6DvF8WBhWtW5Q1dyrjQ3JWU8DW2Att9jRnGHd9F5wWWcykxYbD9DXrlfqCZpec9pHzEMAud9MG1PqK0d3y2oyjwps/fQ092PJcn9/y7zX6tzdVWKaKUe4iRDs1u1ehUo= diff --git a/AUTHORS.md b/AUTHORS.md index 33b90a6436..ec19fd756f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -45,6 +45,7 @@ A huge thanks to all of our contributors: - Phani - RonaldWentworth - Sam Kimbrel +- Sean C. Sullivan - Sunil Veluvali - Takuji Shimokawa - Thomas Wilsher diff --git a/CHANGES.md b/CHANGES.md index afdebbed7f..3f4169695f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,5242 @@ twilio-java changelog ===================== + +[2026-11-17] Version 13.2.1 +--------------------------- +**Twiml** +- Add `conversation_id` and `conversation_configuration` attributes to `` and `` nouns +- Add support for `` noun under `` and `` verbs + +**Accounts** +- Enable the Compliance Signals Check API in prod. +- Add Compliance Signals Check API + +**Audiences** +- ## 2026-11-04 +- **Content updates**: +- Updated description for `AdminListOperations` +- Updated description for `AdminListCohorts` +- Updated description for `AdminListCohortSnapshots` +- Updated description for `AdminFetchCohortOperation` +- Updated description for `AdminListSnapshotOperations` +- Updated description for `AdminListCohortOperations` +- Updated schema description for `OperationStatus` +- Added properties to `Cohort`: cohortId +- Updated schema description for `CohortOperationResult` +- Updated schema description for `CohortOperation` +- ## 2026-11-04 +- **Content updates**: +- Updated description for `ListCohorts` +- Updated description for `UpdateCohort` +- Updated description for `DeleteCohort` +- Updated description for `ListCohortSnapshots` +- Updated description for `CreateCohortSnapshot` +- Updated description for `DeleteCohortSnapshot` +- Updated description for `FetchCohortOperation` +- Updated schema description for `OperationStatus` +- Added properties to `Cohort`: cohortId +- Updated schema description for `CohortOperationResult` +- ...and 1 more changes + +**Destinations** +- ## 2026-11-10 +- **Content updates**: +- Updated description for `TriggerReplay` +- Updated description for `FetchReplayStatus` +- ## 2026-11-10 +- Minor updates (formatting, metadata) + +**Iam** +- Added the optional clientSid query parameter to GET /v1/Account/AuthorizedApps/list: keeps only the items of one application or agent by the item's client_sid (for an MCP or CLI connection, the agent's registration_sid), an exact match like the one GET /v1/Organization/AuthorizedApps already has. A value that is not an OAuth app SID is a bad request +- Added the optional app_permissions and allowed_permissions to the response of GET /v1/Organization/AuthorizedApps/{consentSid}, for an OAuth application: what the application is configured for and what the organization allowed it, as the account detail already has. The response is the new iam.v1.organization-consent-detail, iam.v1.consent plus those two fields, so the lists are unchanged. Both are empty arrays for an MCP or CLI connection, whose grant is in sections. Added offered to each of the sections of an MCP or CLI connection: what consent would offer the context now (the pool narrowed by the organization's agent permissions and by what the user who consented holds), worked out when the detail is fetched, so the detail page can show the full set and tick what the mode, read and write grant. It is nullable: empty on a list and when the detail could not read it, null when the service that answered does not return it yet, so the spec can be deployed before the services. GET /v1/Account/AuthorizedApps/{consentSid} returns it too, on the sections of an MCP or CLI connection (iam.v1.account-consent-detail), so any admin of the account sees it, including permissions the consenting user held but did not select +- Added the CIMD category type (MCP or CLI) to the POST /v1/Organization/AgentsRegistration request, where the Twilio CLI's URL may be registered as CLI only and any other URL as MCP only, and a type left out is taken from the URL and cimd_category to its response, a type query parameter to GET and a type to the PUT /v1/Organization/AgentsRegistration/Permissions request, whose organization and user parts are null for CLI, and CLI to the GET /v1/Account/AuthorizedApps type + +**Instrumentation** +- ## 2026-11-10 +- Synced with the instrumentation Control Plane spec (dev-us1, stage-us1): +- Replaced `/v1/ControlPlane/EventProducers/{producerId}/EventSchemas` (AdminListEventProducerSchemaAttachments) with `/v1/ControlPlane/EventProducers/{producerId}/EventSchemaAttachments` (AdminListEventSchemaAttachments); items carry `attachmentId` and `eventName`, the list key is `eventSchemaAttachments` +- Event schemas: `definition { type, eventName, eventProperties }` and typed `eventIdentifiers` replace `name`, `type`, `identifiers` and `properties`; no `deletedAt` +- Event producers: removed Memory Store `storeIds` and `NO_STORE` readiness +- `EventSchemaProperty.key` has `minLength: 1` +- Updated descriptions and transaction tests +- ## 2026-11-10 +- **Control Plane synced with the events-domain spec after the API review** (`dev-us1`): +- Schema attachments are their own sub-resource with an `attachmentId`: +- Replaced `/v1/ControlPlane/EventProducers/{producerId}/EventSchemas` (AttachEventProducerSchemaVersion, ListEventProducerSchemaAttachments) with `/v1/ControlPlane/EventProducers/{producerId}/EventSchemaAttachments` (CreateEventSchemaAttachment, ListEventSchemaAttachments); the list key is `eventSchemaAttachments` +- Replaced `DELETE /v1/ControlPlane/EventProducers/{producerId}/EventSchemas/{schemaId}/Versions/{version}` (DetachEventProducerSchemaVersion) with `DELETE /v1/ControlPlane/EventProducers/{producerId}/EventSchemaAttachments/{attachmentId}` (DeleteEventSchemaAttachment); an unknown or already-detached id is `404` `550118` +- Event schemas: the type and its fields move into `definition { type, eventName, eventProperties }` in create and in responses; PatchEventSchema sends any of `description`, `eventIdentifiers` and `definition { eventProperties }` +- Removed DeleteEventSchema and `deletedAt`; schemas and versions aren't deleted +- `550106` is returned only by DeleteEventProducer +- PatchEventSchema: `definition` needs `eventProperties` (`minProperties: 1`); new `400` examples. CreateEventSchema: `eventProperties` on an auto capture schema returns the same `400` message as PatchEventSchema +- `EventSchemaProperty.key` has `minLength: 1` +- Replaced the `CustomEventSchemaCreate`, `AutoCaptureEventSchemaCreate`, `CustomEventSchemaUpdate`, `AutoCaptureEventSchemaUpdate` and `EventProducerSchemaAttach*` components with `EventSchemaDefinition`, `CustomEventSchemaDefinition`, `AutoCaptureEventSchemaDefinition`, `EventSchemaUpdateDefinition`, `EventSchemaDefinitionView` and `EventSchemaAttachment*` +- Updated descriptions, examples and transaction tests +- ## 2026-11-06 +- **Event ingestion moves to the BehavioralEvents request shape** (`dev-us1`), matching the deployed events-api: +- Replaced `POST /v1/EventSources/{sourceId}/Batch` (IngestEventBatch) with `POST /v1/EventProducers/{producerId}/BehavioralEvents` (CreateBehavioralEvents); the old path is no longer served +- The body is `events` (1 to 8 `BehavioralEvent`s, each with `eventId`, `sessionId`, `anonymousId`, `index`, `occurredAt`, `schemaName`, optional `schemaVersion`, `identifiers` and `properties`) instead of `batch` +- Added the optional `Content-Encoding: gzip` header, the `403` disabled-producer response (`550052`) and the write-key `401` codes (`20401`, `550050`) +- Removed the now-unused `Event`, `DeviceContext`, `SessionContext`, `InstrumentationContext`, `EventBatchRequest`, `EventBatchResponse` and `EventBatchSuccess` components +- **Control Plane synced with the events-domain spec** (`dev-us1`): +- Removed `/v1/ControlPlane/Operations/{operationId}` (FetchControlPlaneOperationStatus, with its `Retry-After` header) and DeleteEventSchemaVersion; every Control Plane operation is synchronous +- Removed Memory Store: `storeIds` on event producers and `NO_STORE` readiness; readiness is `NO_SCHEMA` or `READY` +- Event schemas: `name`, `identifiers` and `properties` renamed to `eventName`, `eventIdentifiers` and `eventProperties`; identifiers are `{ key, dataType }` (`STRING` or `NUMBER`), 1 to 5, and are not repeated in `eventProperties` +- Schema attachments: `schemaName` renamed to `eventName` +- DeleteEventProducer `409` is `550106` (schema version attached), replacing `550107` (Memory Store attached); DeleteEventSchema no longer returns `550103`; PatchEventSchema `409` adds `550111` for the version limit +- Updated descriptions, examples and transaction tests + +**Knowledge** +- ## 2026-11-05 +- **Added 3 new path(s)**: +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/FailedRecords` (AdminListKnowledgeMigrationFailedRecords) +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/Retries` (AdminCreateKnowledgeMigrationRetry) +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/Retries/{retryId}` (AdminFetchKnowledgeMigrationRetry) + +**Memory** +- ## 2026-11-09 +- Added `PatchProfileTraits` (`PATCH /v1/Stores/{storeId}/Profiles/{profileId}/Traits`) to create or +- update up to 100 traits on a profile in one request, optionally recording where each value came from +- (`source`) and when it was observed (`occurredAt`). Setting a value to `null` removes the trait. The +- endpoint is hidden from the helper libraries and gated behind the `api.memory.2026Q3` beta feature. +- `ListProfileTraits` now returns `source` on each trait (behind the `api.memory.2026Q3` beta feature), when one was set. +- Additive and backwards compatible: existing request and response fields are unchanged. +- ## 2026-11-06 +- Documented the `409` response on `CreateProfile`, returned when an identifier belongs to a profile +- that is pending deletion. The `Conflict` response now includes a `Retry-After` header with the +- number of seconds to wait before retrying. + +**Routes** +- Add `GET`/`POST` `/v3/RcsAgents/{agentId}` to assign and fetch the Inbound Processing Region for RCS agents +- Set SDK and docs visibility of `GET`/`POST` `/v3/RcsAgents/{agentId}` to `private`, maturity to `preview` + +**Segment** +- ## 2026-11-17 +- Add Warehouse Tool routes under `/v1/Segment/WarehouseTool` (read, run/replay/backfill, feature and schema updates, stop task, SQL sessions) +- ## 2026-11-11 +- Add Cob routes: `DELETE /v1/Segment/Cob/Records/{Family}/{Name}`, `POST /v1/Segment/Cob/Records`, `POST /v1/Segment/Cob/Records/{Family}/{Name}/Clone` + +**Trusthub** +- Document the 409 (error code 60736) returned by DELETE /v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid} and DELETE /v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid} when a Branded Calling trust product still depends on the phone number. + + +[2026-11-05] Version 13.2.0 +--------------------------- +**Library - Fix** +- [PR #990](https://github.com/twilio/twilio-java/pull/990): respect client-configured request config in NetworkHttpClient. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Twiml** +- Add ElevenLabs voices to `` verb. +- Add `partialPromptOnHangup`, `eagerEotThreshold`, `asrSmartFormat`, `ttsTextNormalization`, `ttsLanguageTextNormalization`, `elevenlabsLanguageTextNormalization`, `includeInPrompt`, `customerName`, `applicationReconnect`, `echoPromptFiltering`, `turnDetection` attributes to ``, and `hints`, `asrSmartFormat`, `ttsTextNormalization`, `ttsLanguageTextNormalization` attributes to `` + +**Api** +- # API Changes +- ## 2026-09-22 +- Simplified the `criteria` field description. +- ## 2026-09-18 +- Moved `readOnly` on the snapshot count fields (`profileCount`, `partitionCount`) from the shared schema to the response usage sites, so the counts stay read-only in responses (no change for API consumers). +- ## 2026-09-17 +- Renamed 3 `Get*` operations to `Fetch*` to match the operationId standard: `FetchCohort`, `FetchSnapshot`, `FetchOperation`. +- Removed the unused `ExpressionId` schema and made the operation error example cohort-native, so no `aud_` identifiers remain in the spec. +- Kept `libraryVisibility: hidden` across the whole surface (info, path items, and operations). +- ## 2026-09-08 +- Removed the deprecated header-based-versioning unified specs, consolidating audiences onto the path-based `api.twilio.com/v1` surface. +- ## 2026-08-31 +- Published the unified audiences spec at `api.twilio.com/v1`. +- ## 2026-08-26 +- Fixed the Cohort operation response mapping in the unified audiences API. +- ## 2026-08-19 +- Migrated the unified audiences spec to the Cohort surface (Audiences renamed to Cohorts). +- Switched `downstreamServiceName` to `audiences-domain`. +- ## 2026-08-05 +- Added the `api.unified.version.preview` beta feature. +- Made the unified APIs available in prod us1. +- ## 2026-07-30 +- Fixed example values. +- ## 2026-07-29 +- Added the initial version of the audiences API to the unified APIs. +- ## 2026-07-20 +- Deployed the audiences-domain OAS to the dev edge. +- ## 2026-07-06 +- Added the prod-us1 realm to the audiences public API. +- ## 2026-06-23 +- Changed the `storeType` enum from `MEMORA` to `TWILIO`. +- ## 2026-05-04 +- Added the stage-us1 realm and `x-rate-limit` to the audiences API. +- ## 2026-04-08 +- Added the initial audiences endpoints. +- # API Changes +- ## 2026-10-28 +- Enabled the Redaction Configurations and Redaction Catalog resources in prod-us1. +- ## 2026-10-27 +- Enabled the Redaction Configurations and Redaction Catalog resources in stage-us1. +- ## 2026-09-28 +- Added the Redaction Configurations resource (`/v1/RedactionConfigurations`) as a private beta in dev-us1, gated by the `api.redaction.enabled` beta feature. +- Added the Redaction Catalog resource (`/v1/RedactionCatalog`), under the same beta feature. It is restricted to One Console. +- Add `ApplicationSid` parameter to TwimlSession and TwimlProcess Create endpoints + +**Audiences** +- ## 2026-10-23 +- **Content updates**: +- Updated description for `AdminFetchRecord` +- Updated description for `AdminListCohorts` +- Updated description for `AdminListCohortSnapshots` +- Updated description for `AdminFetchCohortOperation` +- Updated description for `AdminListSnapshotOperations` +- Updated schema description for `OperationStatus` +- Added properties to `Cohort`: tags +- Removed properties from `Cohort`: labels +- Added properties to `CohortSnapshot`: tags +- Removed properties from `CohortSnapshot`: labels +- ## 2026-10-23 +- **Content updates**: +- Updated description for `ListCohorts` +- Updated description for `CreateCohort` +- Updated description for `UpdateCohort` +- Updated description for `ListCohortSnapshots` +- Updated description for `CreateCohortSnapshot` +- Updated description for `FetchCohortOperation` +- Updated schema description for `OperationStatus` +- Added properties to `Cohort`: tags +- Removed properties from `Cohort`: labels +- Added properties to `CohortSnapshot`: tags +- ...and 8 more changes +- ## 2026-10-14 +- Minor updates (formatting, metadata) +- ## 2026-10-07 +- Minor updates (formatting, metadata) + +**Conversations** +- Enable the Imports endpoints (list, create, fetch, cancel) and the Import Outcomes list endpoint in prod-us1 +- Add GET /v2/Imports/{ImportId}/Outcomes to list an import's per-resource outcomes (dev-us1 and stage-us1) +- Add `EMAIL` to the Conversations v2 Communication channel enum. + +**Deletions** +- ## 2026-10-28 +- Enable the User Data Deletions API in the `stage-us1` realm. + +**Destinations** +- ## 2026-11-03 +- Enable Replay admin APIs for prod-us1 and prod-ie1 realms + +**Iam** +- Raised the most permissions in a POST /v1/Account/AuthorizedApps section, and in a part of the PUT /v1/Organization/AgentsRegistration/Permissions request, to 2000 for MCP agents; the limit of other consents is unchanged +- Lowered the most permissions in a POST /v1/Account/AuthorizedApps section to 150, which is what an XMS policy holds +- Made the GET and PUT /v1/Organization/AgentsRegistration/Permissions routes available in stage-us1 and prod-us1 +- Added the MCP agent consent fields to GET /v1/Account/AuthorizedApps: agent, account, organization, sections (the offered permissions per context) and redirect, and a 401 body with redirect when the account's organization has not registered or enabled the agent (code 25110, with organization_sid) or the account has no organization (code 25111). oauth_app_sid, client_sid, consent_state and app_permissions are now nullable, since an MCP agent response does not use them +- Added sections (at least 1) with permissionSelectionMode (ALL_READ, ALL_READ_WRITE, SPECIFIC) and permissions (at most 200) to the POST /v1/Account/AuthorizedApps request, and response_mode and form_params to its 201 response +- Made the /v1/Organization/AgentsRegistration routes available in stage-us1 and prod-us1 +- Added created_by (the name of the user who registered the agent) and created_by_sid to the /v1/Organization/AgentsRegistration responses; both are null for a registration made before the user was recorded +- Moved the POST /v1/actions/post_login (PostLoginActionRequest) webhook payload to camelCase (accountSid, nodeId, actionId, userContext, authenticationContext, requestContext, ipAddress, userAgent, requestId, clientId, identifierType); replaced timestamp with the RFC 3339 sentAt, made authorizationDetails a JSON array, made completedAt an RFC 3339 string, and added userContext (isFirstLogin, user) with the CIAM id at userContext.user.userId +- Added the optional type, agent, account, organization, sections, last_used and expires_at to the iam.v1.consent responses of the GET /v1/Account/AuthorizedApps and GET /v1/Organization/AuthorizedApps lists, for MCP connections. The list shows an MCP connection beside the OAuth applications, and deleting it revokes the whole connection +- Added a 404 to PUT /v1/Account/AuthorizedApps/{consentSid} for an MCP connection, which cannot be updated +- Added the GET and PUT /v1/Organization/AgentsRegistration/Permissions routes for what any agent may do in the caller's organization (dev-us1) +- Renamed the properties of the /v1/Organization/AgentsRegistration responses to snake_case (registration_sid, friendly_name, client_url, date_created, date_updated), as the other IAM responses are; the request bodies keep clientUrl and enabled +- Fixed the pagination meta of the GET /v1/Organization/AgentsRegistration response: it is mapped from the service's snake_case fields, as in the other IAM list routes, so key, pageSize and the tokens are no longer null +- Added the /v1/Organization/AgentsRegistration routes (list, register, fetch, enable or disable, remove) for the MCP agents an organization lets its users connect (dev-us1) + +**Instrumentation** +- # API Changes +- ## 2026-10-12 +- Initial read-only admin-api spec for the Behavioral Events (events-domain) One Admin console: event producers (list, fetch), write keys (list), event schemas (list, fetch). dev-us1 and stage-us1 only. +- ## 2026-10-27 +- **Control Plane create, update and attach are synchronous** (`dev-us1`), matching the deployed service: +- CreateEventProducer returns `201` with the event producer (`ETag`, `Idempotent-Replayed`), not `202` with an operation +- PatchEventProducer returns `200` with the event producer (`ETag`), not `202`; `If-Match` is its only header parameter +- AttachEventProducerSchemaVersion returns `201` with the attachment (`Idempotent-Replayed`), not `202` +- ## 2026-10-21 +- **Replaced the Control Plane with the private-beta API** (`/v1/ControlPlane/…`), enabled in `dev-us1` only: +- Removed the EventSources, Datasets, EventSources EventSchemas and AutoInstrumentationRules operations +- Added `/v1/ControlPlane/EventProducers` (CreateEventProducer, ListEventProducers) +- Added `/v1/ControlPlane/EventProducers/{producerId}` (FetchEventProducer, PatchEventProducer, DeleteEventProducer) +- Added `/v1/ControlPlane/EventProducers/{producerId}/WriteKeys` (CreateWriteKey, ListWriteKeys) +- Added `/v1/ControlPlane/EventProducers/{producerId}/WriteKeys/{writeKey}` (DeleteWriteKey) +- Added `/v1/ControlPlane/EventProducers/{producerId}/EventSchemas` (AttachEventProducerSchemaVersion, ListEventProducerSchemaAttachments) +- Added `/v1/ControlPlane/EventProducers/{producerId}/EventSchemas/{schemaId}/Versions/{version}` (DetachEventProducerSchemaVersion) +- Added `/v1/ControlPlane/EventSchemas` (CreateEventSchema, ListEventSchemas) +- Added `/v1/ControlPlane/EventSchemas/{schemaId}` (FetchEventSchema, PatchEventSchema, DeleteEventSchema) +- Added `/v1/ControlPlane/EventSchemas/{schemaId}/Versions` (ListEventSchemaVersions) +- Added `/v1/ControlPlane/EventSchemas/{schemaId}/Versions/{version}` (FetchEventSchemaVersion, DeleteEventSchemaVersion) +- Updated `/v1/ControlPlane/Operations/{operationId}` (FetchControlPlaneOperationStatus) to the new operation shape; now `dev-us1` only + +**Knowledge** +- ## 2026-10-27 +- **Added 1 new path(s)**: +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/Limits` (AdminFetchKnowledgeMigrationLimits) +- ## 2026-10-21 +- **Content updates**: +- `AdminListKnowledgeMigrations`: the `state` query parameter is optional; without it the list returns every account with knowledge bases +- Added properties to `MigrationSummary`: knowledgeBaseCount +- ## 2026-10-19 +- **Added 7 new path(s)**: +- `/v2/ControlPlane/KnowledgeMigrations` (AdminListKnowledgeMigrations) +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}` (AdminFetchKnowledgeMigration) +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/History` (AdminListKnowledgeMigrationHistory) +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/Readiness` (AdminFetchKnowledgeMigrationReadiness) +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/Runs` (AdminListKnowledgeMigrationRuns) +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/Transitions` (AdminListKnowledgeMigrationTransitions, AdminCreateKnowledgeMigrationTransition) +- `/v2/ControlPlane/KnowledgeMigrations/{accountSid}/Transitions/{transitionId}` (AdminFetchKnowledgeMigrationTransition) + +**Lookups** +- Add test api support for Lookup Bulk Jobs endpoints + +**Memory** +- ## 2026-10-14 +- No path changes (schema only) +- Added optional `dataAsOf` to the `Store` schema returned by `AdminFetchStore`. +- ## 2026-10-14 +- Added optional `dataAsOf` to the `Store` schema returned by `FetchStore`. +- ## 2026-10-08 +- Added `FetchProfileOperation` (`GET /v1/ProfileOperations/{operationId}`) to check the status and +- progress of an asynchronous profile operation. The response includes a `Retry-After` header with +- the minimum number of seconds to wait before polling again. The endpoint is hidden from the +- helper libraries and gated behind the `api.memory.2026Q3` beta feature. +- The `202` responses of `UpdateProfilesBulk` and `CreateProfilesImportV2` now return `operationId`, +- `createdAt` and `statusUrl` (behind the `api.memory.2026Q3` beta feature), plus the `Operation-Id`, +- `Location` and `Retry-After` response headers. Use `statusUrl` with `FetchProfileOperation` to +- track the operation. +- Additive and backwards compatible: existing request and response fields are unchanged. + +**Messaging** +- Add data access policy admin endpoints (`GET/PUT /v1/Accounts/{AccountSid}/DataAccessPolicy`) to the messaging admin-api, backed by `postflight-messaging-api` (dev-us1 and stage-us1 only) +- Enable data access policy admin endpoints (`GET/PUT /v1/Accounts/{AccountSid}/DataAccessPolicy`) in prod-us1 and prod-ie1 + +**Segment** +- # API Changes +- ## 2026-11-04 +- Add read-only Cob routes: `GET /v1/Segment/Cob/Whoami`, `/Records`, `/Audits`, `/Audits/{Family}/{Name}` +- ## 2026-10-30 +- Add `GET /v1/Whoami` (One Admin identity check for the Segment oneadmin-gateway) + +**Trusthub** +- Make id, sessionId and sessionToken required and non-nullable in the A2P embedded session response. **(breaking change)** + +**Voice** +- Add internal console ProvisioningStatus endpoint. + +**Webhooks** +- ## 2026-10-28 +- **Changed**: Rule `prefix` and `value` are limited to 1000 characters. A `prefix` must end with `/` and a `value` must not. +- ## 2026-10-13 +- API maturity level changed from `beta` to `ga`. Library visibility changed from `private` to `public`. + + +[2026-10-12] Version 13.1.0 +--------------------------- +**Audiences** +- ## 2026-10-06 +- Minor updates (formatting, metadata) +- ## 2026-10-05 +- Minor updates (formatting, metadata) +- ## 2026-10-02 +- **Added 1 new path(s)**: +- `/preview/Cohorts/{cohortId}/Operations` (AdminListCohortOperations) +- ## 2026-10-01 +- **Content updates**: +- Updated description for `AdminListSnapshotOperations` +- ## 2026-09-28 +- **Content updates**: +- Updated description for `AdminListCohortSnapshots` +- Updated description for `AdminFetchCohortSnapshot` +- Updated schema description for `Criteria` +- Added properties to `OperationPayload`: cohortId +- Removed properties from `OperationPayload`: audienceId +- Updated schema description for `OperationResult` +- Added properties to `OperationResult`: cohortId +- Removed properties from `OperationResult`: audienceId +- Updated schema description for `Record` +- Updated schema description for `Cohort` +- ...and 3 more changes +- ## 2026-10-01 +- Minor updates (formatting, metadata) +- ## 2026-09-28 +- **Content updates**: +- Updated schema description for `CohortOperationResult` +- Updated schema description for `PartitionCount` + +**Conversations** +- Add PATCH /v2/Imports/{id} to cancel an import, and the `CANCELED` import status (dev-us1 and stage-us1) +- Add Imports endpoints for 1console (private visibility, dev-us1 and stage-us1) +- Add `traitExtractionStrategyIds` and `observationExtractionStrategyIds` to the Conversations v2 Admin Configuration schema. +- Align the Conversations v2 Capabilities list and create contracts with the backend `domainId` field. + +**Data-ingress** +- ## 2026-10-01 +- Minor updates (formatting, metadata) +- ## 2026-09-17 +- Add support for Hubspot connector +- ## 2026-10-01 +- Minor updates (formatting, metadata) +- ## 2026-09-17 +- Add support for Hubspot connector + +**Events** +- Remove the Replays API (`/v1/Replays`, beta feature `api.eventstreams.replay`); the feature was never GA and is being sunset **(breaking change)** + +**Knowledge** +- ## 2026-09-24 +- **Routing updates**: +- Changed `downstreamServiceName` from `memora-domain` to `enterprise-knowledge-domain` for all operations + +**Memory** +- ## 2026-09-30 +- The `source` field on observations and conversation summaries, and the `source` filter +- on `ListProfileObservations`, now also accept forward slashes (`/`). The pattern is +- `^[a-zA-Z0-9 _./-]+$`. This is additive and backwards compatible: every previously +- valid value is still accepted. +- `UpdateStore`, `UpdateTraitGroup`, and `UpdateDataMapping` now require a body with at least one property. An empty `{}` gets a 400. + +**Messaging** +- Add opt-out configuration admin endpoints (`GET/PUT/DELETE /v1/Accounts/{AccountSid}/OptOuts/{OptOutSid}/...`) to the messaging admin-api (dev-us1 and stage-us1 only) +- Add create opt-out configuration endpoint (`POST /v1/Accounts/{AccountSid}/OptOuts`) to the messaging admin-api (dev-us1 and stage-us1 only) +- Add update messaging service endpoint (`PUT /v1/Accounts/{AccountSid}/Services/{MessagingServiceSid}`) to the messaging admin-api (dev-us1 and stage-us1 only) +- Enable messaging service add-ons, update messaging service, and opt-out configuration admin endpoints in prod-us1 and prod-ie1 +- Add WhatsApp display name change support to Sender API: `pending_display_name`, `pending_display_name_status` and `pending_display_name_status_date` on fetch, and `display_name_status` on update and partial update + +**Routes** +- Set SDK and docs visibility of `GET`/`POST` `/v3/ShortCodes/{isoCountryCode}/{shortCode}` to `public`, maturity to `ga` + + +[2026-09-28] Version 13.0.2 +--------------------------- +**Twiml** +- Add `audio_format` and `sample_rate` to Stream for HDCodec + +**Api** +- # API Changes +- ## 2026-09-22 +- Simplified the `criteria` field description. +- ## 2026-09-18 +- Moved `readOnly` on the snapshot count fields (`profileCount`, `partitionCount`) from the shared schema to the response usage sites, so the counts stay read-only in responses (no change for API consumers). +- ## 2026-09-17 +- Renamed 3 `Get*` operations to `Fetch*` to match the operationId standard: `FetchCohort`, `FetchSnapshot`, `FetchOperation`. +- Removed the unused `ExpressionId` schema and made the operation error example cohort-native, so no `aud_` identifiers remain in the spec. +- Kept `libraryVisibility: hidden` across the whole surface (info, path items, and operations). +- ## 2026-09-08 +- Removed the deprecated header-based-versioning unified specs, consolidating audiences onto the path-based `api.twilio.com/v1` surface. +- ## 2026-08-31 +- Published the unified audiences spec at `api.twilio.com/v1`. +- ## 2026-08-26 +- Fixed the Cohort operation response mapping in the unified audiences API. +- ## 2026-08-19 +- Migrated the unified audiences spec to the Cohort surface (Audiences renamed to Cohorts). +- Switched `downstreamServiceName` to `audiences-domain`. +- ## 2026-08-05 +- Added the `api.unified.version.preview` beta feature. +- Made the unified APIs available in prod us1. +- ## 2026-07-30 +- Fixed example values. +- ## 2026-07-29 +- Added the initial version of the audiences API to the unified APIs. +- ## 2026-07-20 +- Deployed the audiences-domain OAS to the dev edge. +- ## 2026-07-06 +- Added the prod-us1 realm to the audiences public API. +- ## 2026-06-23 +- Changed the `storeType` enum from `MEMORA` to `TWILIO`. +- ## 2026-05-04 +- Added the stage-us1 realm and `x-rate-limit` to the audiences API. +- ## 2026-04-08 +- Added the initial audiences endpoints. +- Add `TwimlProcessStatusCallbackEvents` parameter to CreateTwimlProcess endpoint +- Add `twiml_process` resource alongside `twiml_session` (`twiml_session` is deprecated and will be removed in a future release) + +**Audiences** +- ## 2026-09-14 +- Minor updates (formatting, metadata) +- ## 2026-09-11 +- **Content updates**: +- Updated summary for `AdminFetchRecord` +- Updated summary for `AdminFetchCohort` +- Updated summary for `AdminFetchCohortSnapshot` +- Updated summary for `AdminFetchCohortOperation` +- Updated schema description for `ResourceLabels` +- ## 2026-09-22 +- **Content updates**: +- Updated schema description for `Criteria` +- ## 2026-09-18 +- Minor updates (formatting, metadata) +- ## 2026-09-17 +- Minor updates (formatting, metadata) +- ## 2026-09-17 +- **Content updates**: +- Updated description for `CreateCohort` +- Updated description for `ListCohortSnapshots` +- Updated description for `CreateCohortSnapshot` +- Updated description for `FetchCohortSnapshot` +- Updated description for `ListCohortSnapshotProfiles` +- Updated schema description for `Criteria` +- Updated schema description for `Cohort` +- Updated schema description for `CohortSnapshot` +- Updated schema description for `CohortOperationResult` +- Updated schema description for `CohortOperation` +- ## 2026-09-15 +- Minor updates (formatting, metadata) +- ## 2026-09-14 +- **Content updates**: +- Updated summary for `FetchCohort` +- Updated summary for `FetchCohortSnapshot` +- Updated summary for `FetchCohortOperation` +- Updated schema description for `ResourceLabels` + +**Capabilities** +- Add a feature-gated preview endpoint to create Capabilities. + +**Conversations** +- Add the feature-gated Capabilities list and create endpoints to Conversations v2. + +**Data-ingress** +- ## 2026-09-07 +- Minor updates (formatting, metadata) +- ## 2026-09-09 +- **Added 16 new path(s)**: +- `/v1/DataSyncs/{syncId}` (FetchDataSync) +- `/v1/CloudAppSources/{sourceId}/Objects` (ListCloudAppObjects) +- `/v1/WarehouseSources/{sourceId}/Preview` (CreateWarehousePreview) +- `/v1/WarehouseSources/{sourceId}/Preview/{operationId}` (FetchWarehousePreview) +- `/v1/DataSample/{operationId}` (FetchDataSample) +- `/v1/ControlPlane/CloudAppSources/{sourceId}` (FetchCloudAppSource, PatchCloudAppSource, DeleteCloudAppSource) +- `/v1/ControlPlane/CloudAppSources/{sourceId}/Datasets` (ListCloudAppDatasets, CreateCloudAppDataset) +- `/v1/ControlPlane/CloudAppSources/{sourceId}/Datasets/{datasetId}` (FetchCloudAppDataset, PatchCloudAppDataset, DeleteCloudAppDataset) +- `/v1/ControlPlane/WarehouseSources/{sourceId}` (FetchWarehouseSource, PatchWarehouseSource, DeleteWarehouseSource) +- `/v1/ControlPlane/WarehouseSources/{sourceId}/Datasets` (ListWarehouseDatasets, CreateWarehouseDataset) +- ...and 6 more paths +- **Removed 31 path(s)**: +- `/v1/DataSyncs/{SyncId}` (FetchDataSync) +- `/v1/CloudAppSources/{SourceId}/Objects` (ListCloudAppObjects) +- `/v1/WarehouseSources/{SourceId}/Preview` (CreateWarehousePreview) +- `/v1/WarehouseSources/{SourceId}/Preview/{OperationId}` (FetchWarehousePreview) +- `/v1/DataSample/{OperationId}` (FetchDataSample) +- `/v1/ControlPlane/CloudAppSources/{SourceId}` (FetchCloudAppSource, PatchCloudAppSource, DeleteCloudAppSource) +- `/v1/ControlPlane/CloudAppSources/{SourceId}/Datasets` (ListCloudAppDatasets, CreateCloudAppDataset) +- `/v1/ControlPlane/CloudAppSources/{SourceId}/Datasets/{DatasetId}` (FetchCloudAppDataset, PatchCloudAppDataset, DeleteCloudAppDataset) +- `/v1/ControlPlane/WarehouseSources/{SourceId}` (FetchWarehouseSource, PatchWarehouseSource, DeleteWarehouseSource) +- `/v1/ControlPlane/WarehouseSources/{SourceId}/Datasets` (ListWarehouseDatasets, CreateWarehouseDataset) +- ...and 21 more paths + +**Destinations** +- ## 2026-09-24 +- **Content updates**: +- Removed `GET` from the `method` enum on the `webhook` destination type's config options +- ## 2026-09-22 +- **Content updates**: +- Added `CDP` to the `categories` enum on `DestinationType` +- ## 2026-09-14 +- Enable admin APIs for stage-us1 and prod-ie1 realms +- ## 2026-09-11 +- **Content updates**: +- Updated description for `CreateDestination` +- Updated description for `UpdateDestination` +- Updated description for `DeleteDestination` +- Updated schema description for `CredentialInput` +- Updated schema description for `DestinationCredentialOptions` +- ## 2026-09-11 +- **Content updates**: +- Updated description for `ListDestinationTypes` +- Updated description for `GetDestinationType` +- Updated description for `CreateDestination` +- Updated description for `UpdateDestination` +- ## 2026-09-10 +- Made `ListDestinationTypes` and `GetDestinationType` unauthenticated (`security: []`). +- Removed `iamOperation`, `addAuthorizationHeader`, and `betaFeature` from these operations. + +**Iam** +- Removed user_context from the POST /v1/actions/post_login (PostLoginActionRequest) webhook payload; the login email is read from authentication_context.methods +- Replaced acr and completed_factors with authentication_context (acr, amr, methods) on the POST /v1/actions/post_login (PostLoginActionRequest) webhook payload +- Made request_context and request_context.ip_address required on the POST /v1/actions/post_login (PostLoginActionRequest) webhook payload + +**Intelligence** +- Added optional `rule.operators[]` parameter override field to `POST /v3/RuleExecutions +- Change Summary in `POST /v3/RuleExecutions` + +**Knowledge** +- ## 2026-09-23 +- **Content updates**: +- Added properties to `WebSourceDetails`: errors +- **Routing updates**: +- Changed `downstreamServiceName` from `memora-domain` to `enterprise-knowledge-domain` for all operations + +**Memory** +- ## 2026-09-18 +- **Added 2 new path(s)**: +- `/v1/ControlPlane/TraitExtractionStrategies` (AdminListTraitExtractionStrategies) +- `/v1/ControlPlane/TraitExtractionStrategies/{traitStrategyId}` (AdminFetchTraitExtractionStrategy) +- ## 2026-09-03 +- No path changes (schema description only) +- Clarified the `DataMappingCore` description: the PATCH body requires at least one field. +- ## 2026-09-10 +- **Added 2 new path(s)** for Observation Extraction Strategies: +- `/v1/ControlPlane/ObservationExtractionStrategies` (ListObservationExtractionStrategies, CreateObservationExtractionStrategy) +- `/v1/ControlPlane/ObservationExtractionStrategies/{observationExtractionStrategyId}` (FetchObservationExtractionStrategy, UpdateObservationExtractionStrategy, DeleteObservationExtractionStrategy) +- **Content updates**: +- Updated `CreateObservationExtractionStrategyInput` description to document that at least one of `allowedCategories`/`prohibitedCategories` must be provided with a non-empty list +- ## 2026-09-07 +- **Added 1 new path(s)** for Profile: +- `/v1/Stores/{storeId}/Profiles/BulkDeletions` (CreateProfilesBulkDeletion) +- ## 2026-09-03 +- `UpdateStore`, `UpdateTraitGroup`, `UpdateDataMapping`, and `UpdateTraitExtractionStrategy` now require a body with at least one property. An empty `{}` gets a 400. + +**Routes** +- Add `GET`/`POST` `/v3/ShortCodes/{isoCountryCode}/{shortCode}` to assign and fetch the Inbound Processing Region for short codes + +**Verify** +- Add `aaguid` and `date_last_approved` to passkeys factors `metadata`. + +**Voice** +- Add typed Recording AccountDefaultConfiguration public API endpoints. + +**Webhooks** +- ## 2026-09-24 +- **Changed**: `GET /v1/Webhooks/Settings` now documents each item as the full `Setting` rather than `SettingSummary`, adding `auth`, `signature`, `connection` and `edgeZones` to the list response. The service already returned these fields; only the schema understated them. Additive for consumers — no field is removed or renamed. The now-unreferenced `SettingSummary` schema is removed. + + +[2026-09-09] Version 13.0.1 +--------------------------- +**Library - Chore** +- [PR #959](https://github.com/twilio/twilio-java/pull/959): grant type is now required. Thanks to [@manisha1997](https://github.com/manisha1997)! +- [PR #971](https://github.com/twilio/twilio-java/pull/971): readme update with version. Thanks to [@sbansla](https://github.com/sbansla)! + +**Library - Fix** +- [PR #973](https://github.com/twilio/twilio-java/pull/973): update javadoc outputDirectory for maven-javadoc-plugin 3.12.0. Thanks to [@shrutiburman](https://github.com/shrutiburman)! +- [PR #970](https://github.com/twilio/twilio-java/pull/970): auto-pin shas in workflows. Thanks to [@shrutiburman](https://github.com/shrutiburman)! + +**Audiences** +- ## 2026-09-01 +- Backticked brace- and angle-bracket-bearing tokens in descriptions for MDX safety. +- Updated a prose reference to the renamed `FetchCohortSnapshot` operation. +- ## 2026-08-26 +- **Removed 5 path(s)**: +- `/preview/Audiences` (AdminListAudiences) +- `/preview/Audiences/{audienceId}` (AdminGetAudience) +- `/preview/Snapshots` (AdminListSnapshots) +- `/preview/Snapshots/{snapshotId}` (AdminGetSnapshot) +- `/preview/Operations/{operationId}` (AdminGetOperation) +- ## 2026-08-25 +- Minor updates (formatting, metadata) +- ## 2026-08-24 +- **Added 1 new path(s)**: +- `/preview/Snapshots/{cohortSnapshotId}/Operations` (AdminListSnapshotOperations) +- **Removed 1 path(s)**: +- `/preview/Snapshots/{snapshotId}/Operations` (ListAdminSnapshotOperations) +- ## 2026-09-01 +- Renamed 3 `Get*` operations to `Fetch*` to match the operationId standard: `FetchCohort`, `FetchCohortSnapshot`, `FetchCohortOperation`. The transpiler skips operations whose operationId does not start with a standard keyword, which had been dropping all three from generated output. +- Set `libraryVisibility` to `private` (was `hidden`) so the spec is eligible for the private docs pipeline. +- Backticked brace- and angle-bracket-bearing tokens in descriptions for MDX safety. +- ## 2026-08-28 +- **Removed 6 path(s)**: +- `/preview/Audiences` (ListAudiences, CreateAudience) +- `/preview/Audiences/{audienceId}` (FetchAudience, UpdateAudience, DeleteAudience) +- `/preview/Snapshots` (ListSnapshots, CreateSnapshot) +- `/preview/Snapshots/{snapshotId}` (FetchSnapshot, DeleteSnapshot) +- `/preview/Snapshots/{snapshotId}/Profiles` (ListSnapshotProfiles) +- `/preview/Operations/{operationId}` (FetchOperation) + +**Conversations** +- Add PATCH support for partial updates to Configuration +- Add `VIDEO` to the Conversations v2 Communication channel enum. + +**Data-ingress** +- # API Changes +- ## 2026-09-01 +- Minor updates (formatting, metadata) +- ## 2026-08-12 +- Minor updates (formatting, metadata) +- ## 2026-08-12 +- Initial release with 13 paths and 13 operations + +**Destinations** +- ## 2026-09-08 +- Added `prod-ie1` to `supportedRealms` and `iamOperationEnabledRealms` for all endpoints +- ## 2026-09-01 +- Removed the unused `admin-api` placeholder from `supportedRealms` on the public endpoints; +- One Admin routes now live in `admin_openapi.yaml`. +- **Added 6 new path(s)** (admin_openapi.yaml): +- `/v1/ControlPlane/Destinations` (AdminListDestinations) +- `/v1/ControlPlane/Destinations/{destinationId}` (AdminGetDestination) +- `/v1/ControlPlane/Subscriptions` (AdminListSubscriptions) +- `/v1/ControlPlane/Subscriptions/{subscriptionId}` (AdminGetSubscription) +- `/v1/ControlPlane/Subscriptions/{subscriptionId}/EventTypes` (AdminListSubscribedEvents) +- `/v1/ControlPlane/Subscriptions/{subscriptionId}/EventTypes/{eventType}` (AdminGetSubscribedEvent) +- ## 2026-08-26 +- Minor updates (formatting, metadata) +- ## 2026-08-26 +- Minor updates (formatting, metadata) +- ## 2026-08-25 +- **Content updates**: +- Updated description for `CreateDestination` + +**Email** +- # API Changes +- ## 2026-09-02 +- **Added 1 new path(s)**: +- `/v1/Sends/Cohorts` (sendCohort) +- ## 2026-08-28 +- **Content updates**: +- Updated summary for `sendTransactional` +- Added parameter(s) to `sendTransactional`: X-Twilio-Version +- Updated schema description for `SuppressionsGroup` +- Added properties to `SuppressionsGroup`: type +- Removed properties from `SuppressionsGroup`: mode +- Updated schema description for `SuppressionsGlobal` +- Added properties to `SuppressionsGlobal`: type +- Removed properties from `SuppressionsGlobal`: mode +- Updated schema description for `Suppressions` +- Updated schema description for `LongRunningOperationResponse` +- ## 2026-08-27 +- **Content updates**: +- Updated description for `SendEmail` +- Added parameter(s) to `SendEmail`: Content-Encoding, Idempotency-Key +- Updated schema description for `Envelope` +- Updated schema description for `SuppressionsGroup` +- Updated schema description for `SuppressionsGlobal` + +**Iam** +- Removed redirect_urls from the GET /v1/Account/AuthorizedApps/{consentSid} response +- Added company_name, homepage_url, tos_url, and redirect_urls to the GET /v1/Account/AuthorizedApps/{consentSid} response +- Added GET /v1/Account/AuthorizedApps/{consentSid} - fetch authorized app details, including allowed permissions, by consent identifier SID +- added container-scoped entitlements endpoint (GET /v2/Container/{containerId}/Entitlements) + +**Instrumentation** +- # API Changes +- ## 2026-09-04 +- **Content updates**: +- Added `IdempotencyKeyHeader` to Create/Patch/Delete `AutoInstrumentationRule`; corrected the shared header's description +- Added `operationId`/`createdAt` to `LongRunningOperationResponse`; corrected example `status` from `RUNNING` to `PENDING` +- Renamed `Signal.timestamp` → `occurredAt`, `HourlyStats.hourTimestamp` → `hourAt`; uppercased `Signal.type` and `ListSignals`' `signalType` enums to SCREAMING_SNAKE_CASE +- Renamed `UserBehaviors` request/response fields to camelCase; added the `summaryDelivery` webhook callback +- Reshaped `PaginationMeta` (added required `key`, corrected `pageSize` bounds) and all 6 list operations (`ListEventSources`, `ListEventSourceDatasets`, `ListEventSchemas`, `ListAutoInstrumentationRules`, `ListSignals`, `ListSignalStats`) to the `meta` envelope; added `ListSignalStats`' `500` response +- Narrowed the domain's default `supportedRealms` to `dev-us1` only; `POST /v1/UserBehaviors` (`AnalyzeUserBehaviors`) keeps its own `dev-us1`/`stage-us1` override (prod withheld pending stage validation) — every other operation is now dev-only +- ## 2026-08-31 +- **Content updates**: +- Fixed stale `tdi_` TTID prefix throughout (path params, examples, transaction URLs) to `events_`; unified dataset/schema ID formats (`tdi_dat_`/`tdi_dataset_` → `events_dataset_`, `tdi_schema_` → `events_evsch_`); fixed rule-version examples to match the real `version: integer` field +- Fixed `operationId` to use the domain-agnostic `proc_job_` TTID prefix; corrected the `OperationId` parameter's length constraint (`max=34` → `max=35`) and added a `pattern` +- Fixed two length constraints hardcoded for the old `tdi_` prefix length: `IngestEventBatch`'s `sourceId` path parameter (`maxLength` 37 → 40); removed the stale, redundant `Twilio-Write-Key` header parameter +- Added the missing `AutoInstrumentationRuleId` regex `pattern` +- Fixed `info.title` ("Twilio Data Ingress - Instrumentation API" → "Events Domain - Instrumentation API") +- **Added 1 new API path**: +- `/v1/UserBehaviors` (AnalyzeUserBehaviors) +- ## 2026-07-28 +- **Initial release** — 21 paths, 37 operations across three API surfaces: +- **Control Plane** (`/v1/ControlPlane/…`): +- `/v1/ControlPlane/EventSources` (CreateEventSource, ListEventSources) +- `/v1/ControlPlane/EventSources/{sourceId}` (FetchEventSource, PatchEventSource, DeleteEventSource) +- `/v1/ControlPlane/EventSources/{sourceId}/WriteKeys` (CreateWriteKey, ListWriteKeys) +- `/v1/ControlPlane/EventSources/{sourceId}/WriteKeys/{writeKey}` (DeleteWriteKey) +- `/v1/ControlPlane/EventSources/{sourceId}/Datasets` (CreateEventSourceDataset, ListEventSourceDatasets) +- `/v1/ControlPlane/EventSources/{sourceId}/Datasets/{datasetId}` (FetchEventSourceDataset, PatchEventSourceDataset, DeleteEventSourceDataset) +- `/v1/ControlPlane/EventSources/{sourceId}/EventSchemas` (CreateEventSchema, ListEventSchemas) +- `/v1/ControlPlane/EventSources/{sourceId}/EventSchemas/{schemaId}` (FetchEventSchema, PatchEventSchema, DeleteEventSchema) +- `/v1/ControlPlane/EventSources/{sourceId}/AutoInstrumentationRules` (CreateAutoInstrumentationRule, ListAutoInstrumentationRules) +- `/v1/ControlPlane/EventSources/{sourceId}/AutoInstrumentationRules/{autoInstrumentationRuleId}` (FetchAutoInstrumentationRule, PatchAutoInstrumentationRule, DeleteAutoInstrumentationRule) +- `/v1/ControlPlane/EventSources/{sourceId}/AutoInstrumentationRules/{autoInstrumentationRuleId}/Versions` (ListAutoInstrumentationRuleVersions) +- `/v1/ControlPlane/EventSources/{sourceId}/AutoInstrumentationRules/{autoInstrumentationRuleId}/Versions/{version}` (FetchAutoInstrumentationRuleVersion) +- `/v1/ControlPlane/Datasets` (ListDatasets) +- `/v1/ControlPlane/Datasets/{datasetId}` (FetchDataset) +- `/v1/ControlPlane/Operations/{operationId}` (FetchControlPlaneOperationStatus) +- `/v1/ControlPlane/Datasets` (ListDatasets) +- `/v1/ControlPlane/Datasets/{datasetId}` (FetchDataset) +- **Event Ingestion** (`/v1/EventSources/…`): +- `/v1/EventSources/{sourceId}/Batch` (IngestEventBatch) +- `/v1/EventSources/{sourceId}/AutoInstrumentationRules/{autoInstrumentationRuleId}/Preview` (TriggerAutoInstrumentationPreview) +- `/v1/EventSources/{sourceId}/AutoInstrumentationRules/{autoInstrumentationRuleId}/Preview/{operationId}` (GetAutoInstrumentationPreviewResult) +- **Signal API** (`/v1/EventSources/…`): +- `/v1/EventSources/{sourceId}/Signals` (IngestSignals, ListSignals) +- `/v1/EventSources/{sourceId}/Signals/{signalKey}` (GetSignalBySignalKey) +- `/v1/EventSources/{sourceId}/SignalStats` (ListSignalStats) + +**Memory** +- ## 2026-08-27 +- **Added 2 new path(s)** for Trait Extraction Strategies: +- `/v1/ControlPlane/TraitExtractionStrategies` (ListTraitExtractionStrategies, CreateTraitExtractionStrategy) +- `/v1/ControlPlane/TraitExtractionStrategies/{traitStrategyId}` (FetchTraitExtractionStrategy, UpdateTraitExtractionStrategy, DeleteTraitExtractionStrategy) + +**Messaging** +- Remove the WhatsApp Senders v1 endpoints (`/v1/Channels/WhatsApp/Senders`) from RestProxy; the sender was routed to the sunsetting `messaging-whatsapp-k8s-orch` downstream. Use the Senders v2 API (`/v2/Channels/Senders`) instead. + +**Voice** +- ## 2026-09-03 +- Added `links.conversation` to Transcription resources as the absolute Conversations API URL for the +- transcript's `conversationId`. It is present once the transcript has been stored; the `links` object +- is omitted otherwise. +- ## 2026-09-01 +- Removed `mediaUrl` from `CreateRequestWithMediaUrl`'s required fields so a request with neither `sourceId` nor `mediaUrl` reaches the downstream service, which rejects it with the specific error code 17500 instead of a generic gateway 400 +- Set `additionalProperties: false` on both `CreateRequestWithSourceId` and `CreateRequestWithMediaUrl` so the two `oneOf` variants stay mutually exclusive: `sourceId` is undeclared on the media-URL variant and `mediaUrl` is undeclared on the source-ID variant, keeping every request shape resolvable to exactly one variant + + +[2026-08-26] Version 13.0.0 +--------------------------- +**Library - Fix** +- [PR #826](https://github.com/twilio/twilio-oai-generator/pull/826): Fixed deserialization failure when API responses contain unknown fields in nested objects. Thanks to [@sbansla](https://github.com/sbansla)! + +**Library - Breaking Changes** +- Renamed nested model classes in Conversations v2 and Messaging v2 APIs to correct class name generation. Affected resources: `Action`, `Communication`, `Configuration`, `Conversation`, `Operation`, `Participant` (conversations/v2) and `ChannelsSender` (messaging/v2). **(breaking change)** + +[2026-08-26] Version 12.2.0 +--------------------------- +**Library - Fix** +- [PR #963](https://github.com/twilio/twilio-java/pull/963): publishing to maven. Thanks to [@shrutiburman](https://github.com/shrutiburman)! + +**Twiml** +- Remove `` noun from `` verb as part of the AI Assistants deprecation **(breaking change)** +- Add `passports` attribute to `` verb for SHAKEN/STIR passport passthrough + +**Accounts** +- Add `SuppressEmailNotification` parameter to the Secondary Auth Token and Auth Token promotion endpoints. Set it to `true` to suppress the email notification sent to account owners and administrators. Defaults to `false`, preserving existing behavior. +- Add SMS Pumping Protection GET and POST API + +**Ai** +- Removing ai workbench apis + +**Api** +- Add missing `uri` property to the `twiml_session` resource + +**Data-ingress** +- ## 2026-08-07 +- **Removed 1 API path**: +- `/v1/DataQuery` (Realtime DataQuery) +- ## 2026-07-07 +- **Added 1 new API path (data plane)**: +- `/v1/DataQuery` (Realtime DataQuery) +- ## 2026-06-17 +- **Content updates**: +- Added properties to `OAuthJWTBearerCredentials`: privateKey, privateKeyPassphrase +- ## 2026-06-12 +- **Added 16 new path(s)**: +- `/v1/DataSyncs/{syncId}` (FetchDataSync) +- `/v1/CloudAppSources/{sourceId}/Objects` (ListCloudAppObjects) +- `/v1/WarehouseSources/{sourceId}/Preview` (CreateWarehousePreview) +- `/v1/WarehouseSources/{sourceId}/Preview/{operationId}` (FetchWarehousePreview) +- `/v1/DataSample/{operationId}` (FetchDataSample) +- `/v1/ControlPlane/CloudAppSources/{sourceId}` (FetchCloudAppSource, PatchCloudAppSource, DeleteCloudAppSource) +- `/v1/ControlPlane/CloudAppSources/{sourceId}/Datasets` (ListCloudAppDatasets, CreateCloudAppDataset) +- `/v1/ControlPlane/CloudAppSources/{sourceId}/Datasets/{datasetId}` (FetchCloudAppDataset, PatchCloudAppDataset, DeleteCloudAppDataset) +- `/v1/ControlPlane/WarehouseSources/{sourceId}` (FetchWarehouseSource, PatchWarehouseSource, DeleteWarehouseSource) +- `/v1/ControlPlane/WarehouseSources/{sourceId}/Datasets` (ListWarehouseDatasets, CreateWarehouseDataset) +- ...and 6 more paths +- **Removed 16 path(s)**: +- `/v1/DataSyncs/{SyncId}` (FetchDataSync) +- `/v1/CloudAppSources/{SourceId}/Objects` (ListCloudAppObjects) +- `/v1/WarehouseSources/{SourceId}/Preview` (CreateWarehousePreview) +- `/v1/WarehouseSources/{SourceId}/Preview/{OperationId}` (FetchWarehousePreview) +- `/v1/DataSample/{OperationId}` (FetchDataSample) +- `/v1/ControlPlane/CloudAppSources/{SourceId}` (FetchCloudAppSource, PatchCloudAppSource, DeleteCloudAppSource) +- `/v1/ControlPlane/CloudAppSources/{SourceId}/Datasets` (ListCloudAppDatasets, CreateCloudAppDataset) +- `/v1/ControlPlane/CloudAppSources/{SourceId}/Datasets/{DatasetId}` (FetchCloudAppDataset, PatchCloudAppDataset, DeleteCloudAppDataset) +- `/v1/ControlPlane/WarehouseSources/{SourceId}` (FetchWarehouseSource, PatchWarehouseSource, DeleteWarehouseSource) +- `/v1/ControlPlane/WarehouseSources/{SourceId}/Datasets` (ListWarehouseDatasets, CreateWarehouseDataset) +- ...and 6 more paths +- ## 2026-06-11 +- **Added 3 new Signal API path(s) for public exposure (data plane)**: +- `/v1/EventSources/{sourceId}/Signals` (ListSignals) +- `/v1/EventSources/{sourceId}/Signals/{signalKey}` (GetSignalBySignalKey) +- `/v1/EventSources/{sourceId}/SignalStats` (ListSignalStats) +- **Added new Signal API schemas**: +- Signal, SignalListResponse, HourlyStats, SignalStatsResponse +- ## 2026-05-26 +- **Added 12 new path(s) for public exposure**: +- `/v1/ControlPlane/EventSources` (CreateEventSource, ListEventSources) +- `/v1/ControlPlane/EventSources/{SourceId}` (FetchEventSource, PatchEventSource, DeleteEventSource) +- `/v1/ControlPlane/EventSources/{SourceId}/WriteKeys` (CreateWriteKey, ListWriteKeys) +- `/v1/ControlPlane/EventSources/{SourceId}/WriteKeys/{WriteKey}` (DeleteWriteKey) +- `/v1/ControlPlane/EventSources/{SourceId}/Datasets` (CreateEventSourceDataset, ListEventSourceDatasets) +- `/v1/ControlPlane/EventSources/{SourceId}/Datasets/{DatasetId}` (FetchEventSourceDataset, PatchEventSourceDataset, DeleteEventSourceDataset) +- `/v1/ControlPlane/EventSources/{SourceId}/EventSchemas` (CreateEventSchema, ListEventSchemas) +- `/v1/ControlPlane/EventSources/{SourceId}/EventSchemas/{SchemaId}` (FetchEventSchema, PatchEventSchema, DeleteEventSchema) +- `/v1/ControlPlane/AutoInstrumentationRule` (CreateAutoInstrumentationRule, ListAutoInstrumentationRules) +- `/v1/ControlPlane/AutoInstrumentationRule/{AutoInstrumentationRuleId}` (FetchAutoInstrumentationRule, PatchAutoInstrumentationRule, DeleteAutoInstrumentationRule) +- `/v1/ControlPlane/AutoInstrumentationRule/{AutoInstrumentationRuleId}/Versions` (ListAutoInstrumentationRuleVersions) +- `/v1/ControlPlane/AutoInstrumentationRule/{AutoInstrumentationRuleId}/Versions/{Version}` (FetchAutoInstrumentationRuleVersion) +- **Added new schemas**: +- EventSource, EventSourceCreate, EventSourceUpdate +- WriteKey, WriteKeyCreate +- EventSourceDataset, EventSourceDatasetCreate, EventSourceDatasetUpdate +- EventSchema, EventSchemaCreate, EventSchemaUpdate, EventSchemaField, EventSchemaProperty +- AutoInstrumentationRule, AutoInstrumentationRuleCreate, AutoInstrumentationRuleUpdate +- AutoInstrumentationRuleVersion, AutoInstrumentationRuleVersionsResponse +- ## 2026-06-12 +- **Added 16 new path(s)**: +- `/v1/DataSyncs/{syncId}` (FetchDataSync) +- `/v1/CloudAppSources/{sourceId}/Objects` (ListCloudAppObjects) +- `/v1/WarehouseSources/{sourceId}/Preview` (CreateWarehousePreview) +- `/v1/WarehouseSources/{sourceId}/Preview/{operationId}` (FetchWarehousePreview) +- `/v1/DataSample/{operationId}` (FetchDataSample) +- `/v1/ControlPlane/CloudAppSources/{sourceId}` (FetchCloudAppSource, PatchCloudAppSource, DeleteCloudAppSource) +- `/v1/ControlPlane/CloudAppSources/{sourceId}/Datasets` (ListCloudAppDatasets, CreateCloudAppDataset) +- `/v1/ControlPlane/CloudAppSources/{sourceId}/Datasets/{datasetId}` (FetchCloudAppDataset, PatchCloudAppDataset, DeleteCloudAppDataset) +- `/v1/ControlPlane/WarehouseSources/{sourceId}` (FetchWarehouseSource, PatchWarehouseSource, DeleteWarehouseSource) +- `/v1/ControlPlane/WarehouseSources/{sourceId}/Datasets` (ListWarehouseDatasets, CreateWarehouseDataset) +- ...and 6 more paths +- **Removed 16 path(s)**: +- `/v1/DataSyncs/{SyncId}` (FetchDataSync) +- `/v1/CloudAppSources/{SourceId}/Objects` (ListCloudAppObjects) +- `/v1/WarehouseSources/{SourceId}/Preview` (CreateWarehousePreview) +- `/v1/WarehouseSources/{SourceId}/Preview/{OperationId}` (FetchWarehousePreview) +- `/v1/DataSample/{OperationId}` (FetchDataSample) +- `/v1/ControlPlane/CloudAppSources/{SourceId}` (FetchCloudAppSource, PatchCloudAppSource, DeleteCloudAppSource) +- `/v1/ControlPlane/CloudAppSources/{SourceId}/Datasets` (ListCloudAppDatasets, CreateCloudAppDataset) +- `/v1/ControlPlane/CloudAppSources/{SourceId}/Datasets/{DatasetId}` (FetchCloudAppDataset, PatchCloudAppDataset, DeleteCloudAppDataset) +- `/v1/ControlPlane/WarehouseSources/{SourceId}` (FetchWarehouseSource, PatchWarehouseSource, DeleteWarehouseSource) +- `/v1/ControlPlane/WarehouseSources/{SourceId}/Datasets` (ListWarehouseDatasets, CreateWarehouseDataset) +- ...and 6 more paths + +**Deletions** +- # API Changes +- ## 2026-06-23 +- Initial public Rest Proxy registration for the User Data Deletions API +- (`POST` / `GET /v1/UserDataDeletions`, `GET /v1/UserDataDeletions/{deletionId}`, +- `GET /v1/Operations/{operationId}`). +- A single request may mix identifier formats: E.164 phone numbers, email +- addresses, and profile IDs. + +**Destinations** +- # API Changes +- ## 2026-08-12 +- Minor updates (formatting, metadata) +- ## 2026-08-12 +- **Content updates**: +- Added properties to `DestinationType`: releaseStatus +- Removed properties from `DestinationType`: maturity +- ## 2026-08-07 +- **Content updates**: +- Updated summary for `ListDestinationSupportedEventTypes` +- ## 2026-08-07 +- **Content updates**: +- Updated summary for `ListDestinationSupportedEventTypes` +- ## 2026-08-07 +- **Added 3 new path(s)**: +- `/v1/Catalog/DestinationSupportedEventTypes` (ListDestinationSupportedEventTypes) +- `/v1/ControlPlane/Subscriptions/{subscriptionId}/EventTypes` (ListSubscribedEvents, CreateSubscribedEvent) +- `/v1/ControlPlane/Subscriptions/{subscriptionId}/EventTypes/{eventType}` (GetSubscribedEvent, UpdateSubscribedEvent, DeleteSubscribedEvent) +- **Removed 3 path(s)**: +- `/v1/ControlPlane/Subscriptions/{subscriptionId}/SubscribedEvents` (ListSubscribedEvents, CreateSubscribedEvent) +- `/v1/ControlPlane/Subscriptions/{subscriptionId}/SubscribedEvents/{eventType}` (GetSubscribedEvent, UpdateSubscribedEvent, DeleteSubscribedEvent) +- `/v1/Catalog/DestinationEventTypes` (ListDestinationEventTypes) +- ## 2026-08-04 +- Minor updates (formatting, metadata) +- ## 2026-08-04 +- Minor updates (formatting, metadata) +- ## 2026-08-04 +- Minor updates (formatting, metadata) +- ## 2026-08-04 +- Minor updates (formatting, metadata) +- ## 2026-08-04 +- **Content updates**: +- Added properties to `SubscriptionResponse`: eventTypes +- ## 2026-08-03 +- **Content updates**: +- Added properties to `DestinationType`: documentationUrl, maturity, tier, categories +- ## 2026-07-27 +- Minor updates (formatting, metadata) +- ## 2026-07-23 +- **Content updates**: +- `meta` is now a required property in the response of `ListDestinations`, `ListSubscriptions`, and `ListSubscribedEvents` +- `CreateSubscribedEvent` request body schema consolidated onto `SubscribedEventInput` (previously `SubscribedEventCreate`, a duplicate schema) +- Added response examples for `ListDestinations`, `ListSubscriptions`, and `ListSubscribedEvents` +- ## 2026-07-23 +- **Added 1 new path(s)**: +- `/v1/Catalog/DestinationEventTypes` (ListDestinationEventTypes) +- ## 2026-07-22 +- **Content updates**: +- Added parameter(s) to `ListDestinations`: namePrefix +- Updated description for `UpdateSubscription` +- Added properties to `SubscriptionUpdate`: eventTypes +- ## 2026-07-16 +- Initial release with 9 paths and 18 operations + +**Events** +- Add `stage-ie1` realm support for EventTypes and Schemas endpoints (datataps-catalog) + +**Memory** +- ## 2026-08-18 +- **Breaking change**: +- Removed the deprecated `CSV` and `DATASET` values from the `DataMappingType` enum. +- `INGRESS`, `DATASET_CLOUDAPP`, and `DATASET_WAREHOUSE` are the only valid values now. +- Removed the `DataMappingFromCSV` and `DataMappingFromDataSet` schemas and their +- `oneOf`/discriminator entries on `DataMappingFromTypes`, along with the corresponding +- `CSV`/`DATASET` discriminator mapping keys. +- Any caller still sending `type: CSV` or `type: DATASET` on `CreateDataMapping` or +- `UpdateDataMapping` (or filtering `ListDataMappings`/`ListDataMappingSuggestions` by +- those values) will get a 400. +- ## 2026-08-10 +- No path changes (updated metadata only) +- `DataMappingType` gains `INGRESS`, `DATASET_CLOUDAPP`, and `DATASET_WAREHOUSE`. +- `CSV` and `DATASET` remain valid and unchanged; they are deprecated aliases and +- will be removed in a follow-up change. +- `DataMappingFromTypes` gains three `oneOf` members and three discriminator keys: +- `DataMappingFromIngress` (renames `DataMappingFromCSV`), +- `DataMappingFromCloudAppDataSet` and `DataMappingFromWarehouseDataSet` +- (both split from `DataMappingFromDataSet`, distinguishing a cloud-app-backed +- TDI dataset from a warehouse-backed one). +- Additive and backwards compatible: existing `CSV` and `DATASET` payloads are +- unaffected. +- ## 2026-08-10 +- **Content updates**: +- Removed `Events` endpoints from the spec, as they were hidden, never implemented, and are not part of the public API +- ## 2026-08-07 +- **New functionality**: +- Added `pageSize`, `pageToken`, and `orderBy` query parameters to `ListProfileImportsV2`, plus a `meta` object in its response, to support pagination. +- **Content updates**: +- Updated the `ListProfileImportsV2` description to document the new pagination behavior. +- Corrected the example presigned upload URL on `CreateProfilesImportV2` to match the real S3 bucket naming convention. +- Corrected the `meta.key` example on `ListProfileTraits`'s response (was `profiles`, now `traits`) to accurately describe which response field it points to. +- ## 2026-08-07 +- **Content updates**: +- Updated `matchingRules` description in `IdentityResolutionSettingsCore` to remove compound `AND` rule documentation +- ## 2026-07-30 +- **Content updates**: +- Increased the maximum value for the Twilio error `code` from `99999` to `999999` +- ## 2026-07-28 +- **Content updates**: +- Updated the `pageSize` description on the pagination `Meta` schema to clarify it reflects the number of items actually returned, not the requested or default page size. +- ## 2026-07-13 +- **Content updates**: +- Renamed `ListProfiles` response schema references from `ProfileID`/`ProfilesMeta` to `IdentityProfileID`/`IdentityProfilesMeta` (new `IdentityProfilesMeta` schema added; `ProfileID`/`ProfilesMeta` retained for other operations). +- ## 2026-07-08 +- **Content updates**: +- Updated description for `CreateDataMappingSuggestion` +- Updated description for `FetchDataMappingSuggestion` +- ## 2026-07-06 +- **Added 2 new path(s)**: +- `/v1/ControlPlane/Stores/{storeId}/DataMappings/Suggestions` (ListDataMappingSuggestions, CreateDataMappingSuggestion) +- `/v1/ControlPlane/Stores/{storeId}/DataMappings/Suggestions/{suggestionId}` (FetchDataMappingSuggestion) +- ## 2026-06-26 +- **Content updates**: +- Minor updates (formatting, metadata) +- Updated x-twilio location parameter from `instance` to `list` for all endpoints that don't end with a /{param} +- Updated description for `UpdateProfileTraits` +- Updated summary for `UpdateProfileTraits` +- Removed properties from `MappingTraitItem`: fieldName +- Removed `additionalProperties` from `allof` schemas since it isn't supported and causes invalid lint errors on example blocks. +- matruity ga and libraryVisibility public +- ## 2026-06-24 +- **Content updates**: +- Add ConversationID as an optional query parameter for ListObservations and ListConversationSummaries +- ## 2026-05-01 +- Updated description & summary for `UpdateProfileTraits` +- Updated description for `FetchIdentityResolutionSettings` +- Removed properties from `MappingTraitItem`: fieldName +- Updated patch Observations to not require `occurredAt`, `content`, or `source` +- ## 2026-04-28 +- **Content updates**: +- Updated description for `UpdateProfileTraits` +- Updated summary for `UpdateProfileTraits` +- Added properties to `TraitDefinition`: validationRule +- Removed properties from `MappingTraitItem`: fieldName + +**Messaging_admin** +- Add Intelligent Alerts endpoints at `/v1/Messaging/IntelligentAlertsEvents/*`, routing to intelligent-alerts-api via messaging-monkey-backend. Account SID is a required query parameter (`accountSid`) on all three endpoints. + +**Voice** +- ## 2026-08-05 +- Added GET /v3/Transcriptions to list and filter transcriptions (status, sourceId, languageCode, createdAfter/createdBefore) with pageSize/pageToken pagination. createdAfter is inclusive and createdBefore exclusive. Returns 422 (error code 17535) when a sourceId's historical item count exceeds the service scan cap + +**Webhooks** +- # API Changes +- ## 2026-08-24 +- **Changed**: Created Webhooks Config API ( https://docs.google.com/document/d/1zkAJD8a8MgoxWifdYDl_d465Az3W6CcD9fuCC2xlSXE/edit?tab=t.0#heading=h.u9e0ry6oe89j ), that includes 7 new resource(s)**: SharedKeys, AuthProfiles, Settings, Rules, Operations, Tests, EdgeZones in /v1/Webhooks referencing webhooks-config downstream. + + +[2026-05-07] Version 12.1.1 +--------------------------- +**Library - Chore** +- [PR #957](https://github.com/twilio/twilio-java/pull/957): changed reference of mvn repo. Thanks to [@sbansla](https://github.com/sbansla)! + +**Conversations** +- update actions api visibility + +**Memory** +- ## 2026-05-07 +- **Content updates**: +- include store api + + +[2026-05-06] Version 12.1.0 +--------------------------- +**Library - Feature** +- [PR #956](https://github.com/twilio/twilio-java/pull/956): add new exception attributes. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Library - Chore** +- [PR #955](https://github.com/twilio/twilio-java/pull/955): java 12.0.0 mvr prep. Thanks to [@sbansla](https://github.com/sbansla)! + +**Twiml** +- Set `recording_configuration_id` attribute to public visibility in ``, ``, `` verbs and `` noun + +**Api** +- Add RecordingConfigurationId parameter for CreateCall, CreateCallRecording, CreateConferenceRecording, and CreateParticipant endpoints + +**Authy** +- # Changelog +- ## v1 +- Added Authy API v1 under `/v1` — initial onboarding of Public API (`/v1/protected/*`), Device API (`/v1/json/*`), and Dashboard API (`/v1/dashboard/*`) behind REST Proxy using transparent proxy mode. + +**Data-ingress** +- ## 2026-04-21 +- **Content updates**: +- Updated description for `CreateDataSync` +- Updated description for `DeleteCloudAppDataset` +- Updated description for `DeleteWarehouseDataset` +- ## 2026-04-20 +- Minor updates (formatting, metadata) +- ## 2026-04-17 +- updated operationId for dataplane APIs,Minor updates (formatting, metadata) +- ## 2026-04-15 +- libraryVisibility to private +- ## 2026-04-14 +- **Added 1 new path(s)**: +- `/v1/DataSyncs/Latest` (GetLatestDataSyncs) + +**Memory** +- ## 2026-04-21 +- **Content updates**: +- Remove Prefer/Async-Operation headers +- ## 2026-04-21 +- **Content updates**: +- Added 301 response for `ListIdentifiers` and `GetIdentifier` +- Added 308 response for `DeleteProfile`, `CreateIdentifier`, `PatchIdentifier`, and `DeleteIdentifier` +- ## 2026-04-14 +- **Modified 1 path(s)**: +- `/v1/ControlPlane/Stores/{storeId}` (added delete) +- Minor updates (formatting, metadata) + +**Voice** +- ## 2026-04-17 +- Added `I-Twilio-Auth-Account` to `downstreamRequest` headers in POST /v3/Transcriptions transactions to document RestProxy account header injection +- ## 2026-04-10 +- Added initial version of Transcriptions V3 API +- Added POST /v3/Transcriptions endpoint to create a new transcription from a source ID or media URL + + +[2026-04-21] Version 12.0.0 +--------------------------- +**Library - Chore** +- Added JDK 21 support. +- Replace deprecated io.jsonwebtoken.SignatureAlgorithm enum with io.jsonwebtoken.security.SecureDigestAlgorithm from jjwt 0.12.x across all public APIs (Jwt, ValidationClient, ValidationInterceptor, ValidationToken) +- Replace deprecated URLEncodedUtils with URIBuilder in RequestValidator (internal, no public API impact) + + +[2026-04-14] Version 11.4.0 +--------------------------- +**Library - Chore** +- [PR #949](https://github.com/twilio/twilio-java/pull/949): add ISO8601Serializer. Thanks to [@manisha1997](https://github.com/manisha1997)! +- [PR #948](https://github.com/twilio/twilio-java/pull/948): add page without meta. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Library - Feature** +- [PR #947](https://github.com/twilio/twilio-java/pull/947): Added ResourceDeleter. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Twiml** +- Add `backgroundNoiseReduction`, `speechTimeout`, `deepgramSmartFormat`, `ignoreBackchannel`, `events` attributes to `` + +**Api** +- Enabled incoming phone numbers(IPN) public apis in stage-ie1 + +**Data-ingress** +- ## 2026-04-09 +- **Content updates**: +- Added parameter(s) to `GetDataSync`: datasetId +- ## 2026-04-09 +- Minor updates (formatting, metadata) +- ## 2026-04-06 +- Minor updates (formatting, metadata) +- ## 2026-04-06 +- Minor updates (formatting, metadata) +- ## 2026-04-06 +- Minor updates (formatting, metadata) +- ## 2026-04-06 +- Minor updates (formatting, metadata) +- ## 2026-04-06 +- **Content updates**: +- Added properties to `CloudAppSourceUpdate`: config +- Added properties to `CloudAppDatasetUpdate`: schedule +- Added properties to `WarehouseSourceUpdate`: config +- Added properties to `WarehouseDatasetUpdate`: schedule +- ## 2026-04-06 +- **Content updates**: +- Updated description for `GetCloudAppPreviewResult` +- Updated description for `GetWarehousePreviewResult` +- Updated description for `GetDataSampleResult` +- ## 2026-03-27 +- Add schema oneOf back without discriminator +- ## 2026-03-26 +- Minor updates (formatting, metadata) +- ## 2026-03-26 +- Added prod-us1 to supportedRealms for all endpoints +- ## 2026-03-25 +- Minor updates (formatting, metadata) +- ## 2026-03-24 +- Minor updates (formatting, metadata) +- ## 2026-03-24 +- Minor updates (formatting, metadata) +- ## 2026-03-24 +- Minor updates (formatting, metadata) +- ## 2026-03-24 +- **Added 10 new path(s)**: +- `/v1/DataSyncs` (ListDataSyncs, TriggerDataSync) +- `/v1/DataSyncs/{SyncId}` (GetDataSync) +- `/v1/CloudAppSources/{SourceId}/Objects` (ListCloudAppObjects) +- `/v1/CloudAppSources/{SourceId}/Objects/{Name}/Properties` (ListCloudAppObjectProperties) +- `/v1/CloudAppSources/{SourceId}/Objects/{Name}/Preview` (PreviewCloudAppObjectData) +- `/v1/CloudAppSources/{SourceId}/Objects/{Name}/Preview/{OperationId}` (GetCloudAppPreviewResult) +- `/v1/WarehouseSources/{SourceId}/Preview` (PreviewWarehouseData) +- `/v1/WarehouseSources/{SourceId}/Preview/{OperationId}` (GetWarehousePreviewResult) +- `/v1/DataSample` (TriggerDataSample) +- `/v1/DataSample/{OperationId}` (GetDataSampleResult) +- ## 2026-03-24 +- Minor updates (formatting, metadata) +- ## 2026-03-24 +- Use `explode: true` for query params when getting by ids and limit max items to 25 +- Make schema description for `Schema` more specific by using oneOf without discriminator for now. + +**Insights** +- Added Insights Domains endpoints under `/v3/InsightsDomains/*` (Query + Metadata) to provide a versioned, GA-ready namespace alongside existing `/preview` endpoints. + +**Mcp** +- # API Changes +- ## 2026-04-07 +- **Added 1 new path(s)**: +- `/v1/docs` (InvokeDocsMcp) + +**Memory** +- ## 2026-04-09 +- **Removed 2 path(s)**: +- `/v1/Stores/{storeId}/Profiles/Import` (ListProfileImports, CreateProfilesImport) +- `/v1/Stores/{storeId}/Profiles/Import/{importId}` (FetchProfileImport) +- libraryVisibility: private, docsVisibility: private +- ## 2026-04-08 +- **Content updates**: +- Added 301 response for `GetProfile` and `GetProfileTraits` +- Added canonical ID header to response for `GetProfile` and `GetProfileTraits` +- Add 308 response for `PatchProfile` +- ## 2026-04-07 +- Added `AGENT` and `UNKNOWN` values to `ParticipantType` enum +- ## 2026-04-06 +- **Content updates**: +- Added async operation support to `UpdateTraitGroup` 202 response (Operation-Id, Location, Retry-After headers; statusUrl in body) +- Added async operation support to `CreateDataMapping`, `UpdateDataMapping`, `DeleteDataMapping` 202 responses (Operation-Id, Location, Retry-After headers; statusUrl in body) +- ## 2026-03-30 +- **Content updates**: +- Updated description for `FetchProfileMemory` +- ## 2026-03-27 +- **Content updates**: +- Updated schema description for `TraitGroupCore` +- ## 2026-03-25 +- **Content updates**: +- Removed properties from `TraitDefinition`: displayName +- ## 2026-03-25 +- **Content updates**: +- Updated description for `UpdateProfileTraits` +- Updated description for `FetchIdentityResolutionSettings` +- Updated description for `UpdateIdentityResolutionSettings` +- Updated schema description for `IdentityResolutionSettingsCore` +- Updated schema description for `TraitGroupCore` +- Made all fields besides `idType` optional w/ defaults for schema `IdentifierConfig` +- ## 2026-03-24 +- **Content updates**: +- Added properties to `OperationStatus`: result + + +[2026-03-24] Version 11.3.6 +--------------------------- +**Data-ingress** +- # API Changes +- ## 2026-03-23 +- Added stage-us1 to supportedRealms for all endpoints +- ## 2026-03-20 +- **Content updates**: +- Removed estimatedCompletionTime from `LongRunningOperationResponse` +- Moved operationId from `LongRunningOperationResponse` to headers +- ## 2026-03-18 +- **Added 1 new path(s)**: +- `/v1/ControlPlane/Operations/{OperationId}` (GetControlPlaneOperationStatus) +- ## 2026-03-11 +- Minor updates (formatting, metadata) +- ## 2026-03-11 +- Minor updates (formatting, metadata) +- ## 2026-03-11 +- Minor updates (formatting, metadata) +- ## 2026-03-11 +- Minor updates (formatting, metadata) +- ## 2026-03-11 +- Minor updates (formatting, metadata) +- ## 2026-03-05 +- Initial release with 10 paths and 22 operations + +**Memory** +- ## 2026-03-19 +- **Added 1 new path(s)**: +- `/v1/ControlPlane/Operations/{operationId}` (FetchOperation) +- ## 2026-03-11 +- Minor updates (formatting, metadata) + + +[2026-03-10] Version 11.3.5 +--------------------------- +**Library - Chore** +- [PR #943](https://github.com/twilio/twilio-java/pull/943): bump com.fasterxml.jackson.core:jackson-core from 2.15.0 to 2.18.6. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #945](https://github.com/twilio/twilio-java/pull/945): added memory domain. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #941](https://github.com/twilio/twilio-java/pull/941): add validTwilioUrl utility check. Thanks to [@kridai](https://github.com/kridai)! + +**Library - Fix** +- [PR #942](https://github.com/twilio/twilio-java/pull/942): encode URL path spaces as %20 instead of +. Thanks to [@hubert-ren](https://github.com/hubert-ren)! + +**Twiml** +- Rename `recording_configuration` to `recording_configuration_id` attribute in ``, ``, `` verbs and `` noun + +**Ace** +- # ACE Signals API Changes +- ## 2026-02-18 +- Initial release: POST /signals, GET/POST /signals/{signal_id}/results, GET /health +- Enables OneAdmin integration for synchronous signal ingestion and policy result polling +- Supports permission-based authorization for signal operations +- Health endpoint available for monitoring without authentication + +**Api** +- Added optional parameter `Confirmation` to Payments create endpoint to enable payment confirmation prompt before gateway submission +- Added optional parameter `RequireMatchingInputs` to Payments create endpoint for input confirmation in agent-assisted payment flows +- Added matcher capture types (`payment-card-number-matcher`, `expiration-date-matcher`, `security-code-matcher`, `postal-code-matcher`) to Payments update endpoint + +**Memory** +- ## 2026-03-06 +- **Modified 1 path(s)**: +- `/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId}` (added patch, get) + + +[2026-02-18] Version 11.3.4 +--------------------------- +**Library - Chore** +- [PR #937](https://github.com/twilio/twilio-java/pull/937): added exception as per rfc-9457 standards. Thanks to [@sbansla](https://github.com/sbansla)! + +**Api** +- Remove inequality examples from Calls StartTime and EndTime filter descriptions + +**Memory** +- ## 2026-02-06 +- Minor updates (formatting, metadata) +- ## 2026-02-06 +- Minor updates (formatting, metadata) +- ## 2026-02-06 +- ## 2026-01-23 +- ## 2026-01-23 +- **Added 3 new path(s)**: +- `/v1/Stores/{storeId}/Profiles/Imports` (ListProfileImportsV2, CreateProfilesImportV2) +- `/v1/Stores/{storeId}/Profiles/Imports/{importId}` (FetchProfileImportV2) +- **Removed 6 path(s)**: +- `/v1/KnowledgeBases/{kbId}/Knowledge` (ListKnowledge, CreateKnowledge) +- `/v1/KnowledgeBases/{kbId}/Search` (KnowledgeSearch) +- `/v1/KnowledgeBases/{kbId}/Knowledge/{knowledgeId}` (RetrieveKnowledge, PatchKnowledge, DeleteKnowledge) +- `/v1/KnowledgeBases/{kbId}/Knowledge/{knowledgeId}/Chunks` (ListKnowledgeChunks) +- `/v1/ControlPlane/KnowledgeBases` (ListKnowledgeBases, CreateKnowledgeBase) +- `/v1/ControlPlane/KnowledgeBases/{kbId}` (GetKnowledgeBase, UpdateKnowledgeBase, DeleteKnowledgeBase) +- ## 2026-01-05 +- ## 2026-01-05 +- Initial release with 26 paths and 48 operations + + +[2026-02-05] Version 11.3.3 +--------------------------- +**Library - Fix** +- [PR #936](https://github.com/twilio/twilio-java/pull/936): java regional endpoint processing. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Twiml** +- Add `recording_configuration` attribute to `` noun + +**Api** +- Clarify the behavior of date filters with the Calls API +- Added Phone Number `type` property to `/IncomingPhoneNumbers` resource + +**Memory** +- ## 2026-01-23 +- No path changes (updated metadata only) +- ## 2026-01-22 +- No path changes (updated metadata only) +- ## 2026-01-22 +- **Modified 1 path(s)**: +- `/v1/Stores/{storeId}/Profiles/{profileId}` (added delete) + + +[2026-01-22] Version 11.3.2 +--------------------------- +**Library - Chore** +- [PR #933](https://github.com/twilio/twilio-java/pull/933): added methods to support response headers and status code. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #934](https://github.com/twilio/twilio-java/pull/934): update mockwebserver, okio to resolve CVE-2022-24329. Thanks to [@kridai](https://github.com/kridai)! + +**Twiml** +- Added support for and inside + +**Assistants** +- AI Assistants v1 release + +**Autopilot** +- Remove Export resource from Autopilot Assistant +- Add dialogue_sid param to Query list resource +- Add Restore resource to Autopilot Assistant +- Add one new property in Query i.e dialogue_sid +- Add Export resource to Autopilot Assistant. +- Adds two new properties in Assistant i.e needs_model_build and development_stage +- Add Webhooks resource to Autopilot Assistant. +- Introduce `autopilot` subdomain with all resources from `preview.understand` + +**Compliance** +- Added the new InventoryComplianceInsights API under version `/v1`. + +**Content** +- changes for adding v2 endpoints + +**Marketplace** +- Initial transition to Marketplace domain + +**Memory** +- # API Changes +- ## 2026-01-15 +- No path changes (updated metadata only) +- ## 2026-01-13 +- **Added 1 new path(s)**: +- `/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId}` (DeleteProfileConversationSummary) +- ## 2026-01-12 +- No path changes (updated metadata only) +- ## 2026-01-12 +- No path changes (updated metadata only) +- ## 2026-01-12 +- No path changes (updated metadata only) +- ## 2026-01-12 +- **Added 2 new path(s)**: +- `/v1/Stores/{storeId}/Profiles/Imports` (ListProfileImportsV2, ImportProfilesV2) +- `/v1/Stores/{storeId}/Profiles/Imports/{importId}` (GetProfileImportV2) +- ## 2026-01-13 +- No path changes (updated metadata only) +- ## 2026-01-07 +- No path changes (updated metadata only) +- ## 2026-01-05 +- No path changes (updated metadata only) +- ## 2025-12-17 +- No path changes (updated metadata only) +- ## 2025-12-17 +- No path changes (updated metadata only) +- ## 2025-12-17 +- **Added 1 new path(s)**: +- `/v1/Stores/{storeId}/Profiles/{profileId}/Observations/{observationId}/Revisions` (ListObservationRevisions) + +**Sender-ids** +- Added all v2 sender-id-service endpoints + +**Trusthub** +- Add new delete endpoint for compliance_registration. + +**Voice** +- Add ProvisioningStatus public API endpoints. + +**Wise_owl** +- Init API as open-api spec +- Updated Get Chat, Send Message and Create Chat to include `contexts` in Message, instead of root Chat + +**Www** +- Port APIs from oauth.twilio.com to www.twilio.com + + +[2026-01-07] Version 11.3.1 +--------------------------- +**Api** +- Added optional parameter `clientNotificationUrl` for create call api +- Added optional parameter `clientNotificationUrl` for create participant api + + +[2025-12-17] Version 11.3.0 +--------------------------- +**Trunking** +- Corrected the type used for phone number capabilities when accessed through a Trunk. **(breaking change)** +- Corrected the type used for phone number capabilities when accessed through a Trunk. **(breaking change)** + +**Trusthub** +- Added new parameters in in toll-free initialize api payload. +- Remove the invalid status transition to Draft from the examples +- Change the value of email to a valid one in the examples. + + +[2025-12-03] Version 11.2.0 +--------------------------- +**Library - Chore** +- [PR #931](https://github.com/twilio/twilio-java/pull/931): ignore region and edge for noauth apis example tokencreator. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #928](https://github.com/twilio/twilio-java/pull/928): Regional API domain processing. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Library - Feature** +- [PR #918](https://github.com/twilio/twilio-java/pull/918): add patch operation support. Thanks to [@kridai](https://github.com/kridai)! +- [PR #917](https://github.com/twilio/twilio-java/pull/917): add token pagination strategy. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + +**Api** +- Add `twiml_session` resource for calls +- Add `twiml_session` resource for calls + +**Monitor** +- Update default output properties + +**Trusthub** +- Added customer_profile_sid in toll-free initialize api payload. + + +[2025-11-11] Version 11.1.0 +--------------------------- +**Memory** +# Memory API Changes +- Added initial Memory API endpoints with darkseagreen badge status + +[2025-11-11] Version 11.0.3 +--------------------------- +**Twiml** +- Add new noun `` +- Add support for `` noun under `` verb + + +[2025-10-28] Version 11.0.2 +--------------------------- +**Ai** +- Add `error` as possible transcript status +- Add `error` as possible transcript status + +**Chat** +- Updated v2 UserChannel `channel_status` from `not_participating` to `notParticipating` + +**Intelligence** +- Make intelligence work with RestProxy +- Add additional enums to better represent the possible states +- Add `error` enum to transcription status to better align with possible outputs +- Add `json` output type to text classification + +**Trusthub** +- Remove required parameter Primary Profile Sid from compliance_inquiry and compliance_inquiry_individual + +**Accounts** +- Add Messaging GeoPermissions API changes + + +[2025-10-15] Version 11.0.1 +---------------------------- + +**Api** + +- Updated description for property CallerDisplayName for participant create request +- Updated description for property CallerDisplayName for participant create request + + +[2025-09-30] Version 11.0.0 +------------------------------------ + +**Library - Breaking Changes** +- Refer [Upgrade.md](https://github.com/twilio/twilio-java/blob/main/UPGRADE.md) for detailed migration notes and list of Breaking Changes. + +**Accounts** +- Update beta feature flag for consent and contact bulk upsert APIs + +**Api** +- Add `date_created` property to media resource and date_created filtering parameters for read action +- Updated the Recordings Resource `channels` property to clarify channels = # of channels in the recording resource and how to specify the # of channels in recording download +- Remove usage category enum from usage record and usage triggers API **(breaking change)** +- Add multiple missing usage categories to usage records and usage triggers api +- Add `channels-whatsapp-template-marketing` and `channels-whatsapp-template-utility` to usage categories + +**Bulkexports** +- Changed the type of 'details' field to be a list of objects instead of a single object + +**Conversations** +- Fix `state` spelling for `initializing` enum value +- Update `state` to include `intializing` for ServiceConversationWithParticipants and ConversationWithParticipants +- Updates to `method` casing for ConfgurationAddress, ConversationScopedWebhook, and ServiceConversationScopedWebhook for RestProxy compatibility + +**Events** +- Remove `SinkSid` parameter when updating subscriptions. **(breaking change)** + +**Intelligence** +- Add encryption_credential_sid field in transcripts and services in v2 + +**Flex** +- Adding new optional parameter `identity` to `web_channels` API in version `v2` +- update team name for web_channel, webchat_init_token, webchat_refresh_token + +**Verify** +- Add passkeys support to Verify API creating and updating services. +- Update `ienum` type for Factor creation +- Add passkeys as challenge and factor type + +**Proxy** +- remove shortcodes resource as its no longer used + +**Studio** +- Add `type` to Step resource APIs + +**Serverless** +- Change log field level from type `ienum` to `string` in Logs api + +**Taskrouter** +- Remove `URL-encoded` from attributes param definition in tasks + +**Trunking** +- Added `symmetric_rtp_enabled` property on Trunks.- + +**Trusthub** +- Remove beta feature flag for all TH APIs +- Remove beta feature flag for ComplianceInquiries API to support OneConsole traffic +- Add required Permissions to the ComplianceInquiries API + +**Twiml** +- Add new noun `` +- Remove Duplicates. +- Add Polly Generative voices. +- Add Latest Google (Chirp3-HD) voices. +- Add support for `` noun under `` verb + +**Verify** +- Allow to update all passkeys parameters in the service update + + +[2025-06-12] Version 10.9.2 +--------------------------- +**Library - Chore** +- [PR #858](https://github.com/twilio/twilio-java/pull/858): handle any Type with object datatype. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + +**Api** +- Change DependentPhoneNumber `capabilities` type `object` and `date_created`, `date_updated` to `date_time` +- Updated the `Default` value from 0 to 1 in the Recordings Resource `channels` property + +**Serverless** +- Update `ienum` type level in Logs api + +**Verify** +- Update Channel list in Verify Attempst API +- Update `ienum` type for Conversion_Status in Verify Attempts API + +**Twiml** +- Add `us2` to the list of supported values for the region attribute in the `` TwiML noun. + + +[2025-05-29] Version 10.9.1 +--------------------------- +**Library - Chore** +- [PR #860](https://github.com/twilio/twilio-java/pull/860): update dependency version. Thanks to [@manisha1997](https://github.com/manisha1997)! +- [PR #857](https://github.com/twilio/twilio-java/pull/857): use iam token endpoint. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Api** +- Added several usage category enums to `usage_record` API + +**Numbers** +- Update the porting documentation + +**Verify** +- Update `ienum` type for Channels in Verify Attempts API + + +[2025-05-13] Version 10.9.0 +--------------------------- +**Library - Feature** +- [PR #844](https://github.com/twilio/twilio-java/pull/844): Support custom ObjectMappers, with singleton defaults. Thanks to [@egoodhall](https://github.com/egoodhall)! + +**Library - Chore** +- [PR #853](https://github.com/twilio/twilio-java/pull/853): add changelog for jwt. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + +**Accounts** +- Changes to add date_of_consent param in Bulk Consent API + +**Api** +- Change `friendly_name`, `date_created` and `date_updated` properties to type `string`. + +**Twiml** +- Update twiml definition for `` and `` + + +[2025-05-05] Version 10.8.0 +--------------------------- +**Library - Chore** +- [PR #852](https://github.com/twilio/twilio-java/pull/852): removing jwt changelog. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! +- [PR #849](https://github.com/twilio/twilio-java/pull/849): Add example for using multi region setup in a single application. Thanks to [@manisha1997](https://github.com/manisha1997)! +- [PR #847](https://github.com/twilio/twilio-java/pull/847): bump com.google.code.gson:gson from 2.8.6 to 2.8.9. Thanks to [@dependabot](https://github.com/dependabot)! + +**Library - Fix** +- [PR #846](https://github.com/twilio/twilio-java/pull/846): update jjwt version. Thanks to [@manisha1997](https://github.com/manisha1997)! +- **AccessToken** + - **Breaking Change**: Updated `AccessTokenBuilder` to use `byte[]` for the `secret` instead of `String`. + - Updated method signatures: + - `AccessTokenBuilder(String accountSid, String keySid, byte[] secret)` + - Example usage: + ```java + byte[] secret = “your_secret”.getBytes(); + AccessTokenBuilder builder = new AccessTokenBuilder(accountSid, keySid, secret); + ``` + **ClientCapability** + - **Breaking Change**: Updated `ClientCapability.Builder` to use `byte[]` for the `authToken` instead of `String`. + - Updated method signatures: + - `ClientCapability.Builder(String accountSid, byte[] authToken)` + - Example usage: + ```java + byte[] authToken = “your_auth_token”.getBytes(); + ClientCapability.Builder builder = new ClientCapability.Builder(accountSid, authToken); + ``` + **TaskRouterCapability** + - **Breaking Change**: Updated `TaskRouterCapability.Builder` to use `byte[]` for the `authToken` instead of `String`. + - Updated method signatures: + - `TaskRouterCapability.Builder(String accountSid, byte[] authToken)` + - Example usage: + ```java + byte[] authToken = “your_auth_token”.getBytes(); + TaskRouterCapability.Builder builder = new TaskRouterCapability.Builder(accountSid, authToken); + ``` + +**Api** +- Add `response_key` for `Usage Triggers` fetch endpoint. + +**Flex** +- Add Update Interaction API +- Adding `webhook_ttid` as optional parameter in Interactions API + +**Serverless** +- Add node22 as a valid Build runtime +- Add node20 as a valid Build runtime + +**Video** +- removed `transcribe_participants_on_connect` and `transcriptions_configuration` from the room resource **(breaking change)** +- Added `transcribe_participants_on_connect` and `transcriptions_configuration` to the room resource + + +[2025-04-07] Version 10.7.2 +--------------------------- +**Library - Chore** +- [PR #842](https://github.com/twilio/twilio-java/pull/842): added patch method. Thanks to [@sbansla](https://github.com/sbansla)! + +**Studio** +- Add documentation for parent_step_sid field in Step resource + + +[2025-03-20] Version 10.7.1 +--------------------------- +**Accounts** +- Update Safelist API docs as part of prefix supoort + +**Flex** +- Removing `first_name`, `last_name`, and `friendly_name` from the Flex User API + +**Messaging** +- Add missing tests under transaction/phone_numbers and transaction/short_code + + +[2025-03-11] Version 10.7.0 +--------------------------- +**Library - Chore** +- [PR #839](https://github.com/twilio/twilio-java/pull/839): MVR Release Preparation. Thanks to [@manisha1997](https://github.com/manisha1997)! +- [PR #841](https://github.com/twilio/twilio-java/pull/841): update upgrade doc. Thanks to [@manisha1997](https://github.com/manisha1997)! +- [PR #840](https://github.com/twilio/twilio-java/pull/840): add version. Thanks to [@manisha1997](https://github.com/manisha1997)! +- [PR #838](https://github.com/twilio/twilio-java/pull/838): Add domain and noauth base classes. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #837](https://github.com/twilio/twilio-java/pull/837): enable java test. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Api** +- Add the missing `emergency_enabled` field for `Address Service` endpoints + +**Messaging** +- Add missing enums for A2P and TF + +**Numbers** +- add missing enum values to hosted_number_order_status + +**Twiml** +- Convert Twiml Attribute `speechModel` of type enum to string **(breaking change)** + + +[2025-02-20] Version 10.6.10 +---------------------------- +**Library - Chore** +- [PR #836](https://github.com/twilio/twilio-java/pull/836): disable java test. Thanks to [@manisha1997](https://github.com/manisha1997)! +- [PR #835](https://github.com/twilio/twilio-java/pull/835): disable java test. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Flex** +- Adding Digital Transfers APIs under v1/Interactions + +**Numbers** +- Convert webhook_type to ienum type in v1/Porting/Configuration/Webhook/{webhook_type} + +**Trusthub** +- Changing TrustHub SupportingDocument status enum from lowercase to uppercase since kyc-orch returns status capitalized and rest proxy requires strict casing + + +[2025-02-11] Version 10.6.9 +--------------------------- +**Api** +- Change downstream url and change media type for file `base/api/v2010/validation_request.json`. + +**Intelligence** +- Add json_results for Generative JSON operator results + +**Messaging** +- Add DestinationAlphaSender API to support Country-Specific Alpha Senders + +**Video** +- Change codec type from enum to case-insensitive enum in recording and room_recording apis + + +[2025-01-28] Version 10.6.8 +--------------------------- +**Library - Fix** +- [PR #809](https://github.com/twilio/twilio-java/pull/809): Fix for 1 vulnerabilities. Thanks to [@twilio-product-security](https://github.com/twilio-product-security)! +- [PR #830](https://github.com/twilio/twilio-java/pull/830): Voice v2 fix. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Library - Chore** +- [PR #831](https://github.com/twilio/twilio-java/pull/831): added bug report issue template. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #829](https://github.com/twilio/twilio-java/pull/829): add variant class. Thanks to [@manisha1997](https://github.com/manisha1997)! + +**Api** +- Add open-api file tag to `conference/call recordings` and `recording_transcriptions`. + +**Events** +- Add support for subaccount subscriptions (beta) + +**Insights** +- add new region to conference APIs + +**Lookups** +- Add new `parnter_sub_id` query parameter to the lookup request + + +[2025-01-13] Version 10.6.7 +--------------------------- +**Messaging** +- Adds validity period Default value in service resource documentation + + +[2025-01-09] Version 10.6.6 +--------------------------- +**Numbers** +- Change beta feature flag to use v2/BulkHostedNumberOrders + + +[2024-12-12] Version 10.6.5 +--------------------------- +**Library - Fix** +- [PR #822](https://github.com/twilio/twilio-java/pull/822): Update org.json:json library to resolve high severity vulnerability. Thanks to [@allantodd](https://github.com/allantodd)! + + +[2024-12-05] Version 10.6.4 +--------------------------- +**Api** +- Add optional parameter `intelligence_service` to `transcription` +- Updated `phone_number_sid` to be populated for sip trunking terminating calls. + +**Numbers** +- Add Update Hosted Number Order V2 API endpoint +- Update Port in docs + +**Twiml** +- Add optional parameter `intelligence_service` to `` +- Add support for new `` and `` noun +- Add `events` attribute to `` verb + + +[2024-11-15] Version 10.6.3 +--------------------------- +**Api** +- Added `ivr-virtual-agent-custom-voices` and `ivr-virtual-agent-genai` to `usage_record` API. +- Add open-api file tag to realtime_transcriptions + +**Taskrouter** +- Add `api-tag` property to workers reservation +- Add `api-tag` property to task reservation + + +[2024-10-24] Version 10.6.2 +--------------------------- +**Library - Fix** +- [PR #741](https://github.com/twilio/twilio-java/pull/741): Security upgrade org.json:json from 20220320 to 20230227. Thanks to [@twilio-product-security](https://github.com/twilio-product-security)! +- [PR #819](https://github.com/twilio/twilio-java/pull/819): Security upgrade commons-io:commons-io from 2.7 to 2.14.0. Thanks to [@twilio-product-security](https://github.com/twilio-product-security)! + +**Conversations** +- Expose ConversationWithParticipants resource that allows creating a conversation with participants + + +[2024-10-17] Version 10.6.1 +--------------------------- +**Api** +- Add response key `country` to fetch AvailablePhoneNumber resource by specific country. + +**Messaging** +- Make library and doc public for requestManagedCert Endpoint + + +[2024-10-03] Version 10.6.0 +--------------------------- +**Library - Chore** +- [PR #818](https://github.com/twilio/twilio-java/pull/818): updated readme with Orgs example. Thanks to [@sbansla](https://github.com/sbansla)! + +**Library - Feature** +- [PR #813](https://github.com/twilio/twilio-java/pull/813): Added OAuth Support for Public APIs with TokenManager Integration. Thanks to [@sbansla](https://github.com/sbansla)! + +**Messaging** +- Add A2P external campaign CnpMigration flag + +**Numbers** +- Add address sid to portability API + +**Verify** +- Add `SnaClientToken` optional parameter on Verification check. +- Add `EnableSnaClientToken` optional parameter for Verification creation. + + +[2024-09-25] Version 10.5.2 +--------------------------- +**Library - Chore** +- [PR #815](https://github.com/twilio/twilio-java/pull/815): updated readme for Beta flag. Thanks to [@sbansla](https://github.com/sbansla)! + +**Accounts** +- Update docs and mounts. +- Change library visibility to public +- Enable consent and contact bulk upsert APIs in prod. + +**Serverless** +- Add is_plugin parameter in deployments api to check if it is plugins deployment + + +[2024-09-18] Version 10.5.1 +--------------------------- +**Intelligence** +- Remove public from operator_type +- Update operator_type to include general-availablity and deprecated + +**Numbers** +- Remove beta flag for bundle clone API + + +[2024-09-05] Version 10.5.0 +--------------------------- +**Iam** +- updated library_visibility public for new public apikeys + +**Numbers** +- Add new field in Error Codes for Regulatory Compliance. +- Change typing of Port In Request date_created field to date_time instead of date **(breaking change)** + + +[2024-08-26] Version 10.4.2 +--------------------------- +**Library - Fix** +- [PR #811](https://github.com/twilio/twilio-java/pull/811): making previewiam versionless. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #808](https://github.com/twilio/twilio-java/pull/808): added new httpclient for noauth and bearertoken requests. Thanks to [@sbansla](https://github.com/sbansla)! + +**Library - Chore** +- [PR #806](https://github.com/twilio/twilio-java/pull/806): added multipart test in call api. Thanks to [@sbansla](https://github.com/sbansla)! + +**Api** +- Update documentation of `error_code` and `error_message` on the Message resource. +- Remove generic parameters from `transcription` resource +- Added public documentation for Payload Data retrieval API + +**Flex** +- Adding update Flex User api + +**Insights** +- Added 'branded', 'business_profile' and 'voice_integrity' fields in List Call Summary + +**Intelligence** +- Add `words` array information to the Sentences v2 entity. +- Add `X-Rate-Limit-Limit`, `X-Rate-Limit-Remaining`, and `X-Rate-Limit-Config` headers for Operator Results. +- Change the path parameter when fetching an `/OperatorType/{}` from `sid` to `string` to support searching by SID or by name +- Add `X-Rate-Limit-Limit`, `X-Rate-Limit-Remaining`, and `X-Rate-Limit-Config` headers for Transcript and Service endpoints. + +**Messaging** +- Adds two new channel senders api to add/remove channel senders to/from a messaging service +- Extend ERC api to accept an optional attribute in request body to indicate CNP migration for an ERC + +**Numbers** +- Modify visibility to public in bundle clone API +- Add `port_date` field to Port In Request and Port In Phone Numbers Fetch APIs +- Change properties docs for port in phone numbers api +- Add is_test body param to the Bundle Create API +- Change properties docs for port in api + +**Trusthub** +- Add new field in themeSetId in compliance_inquiry. + +**Verify** +- Update `custom_code_enabled` description on verification docs + + +[2024-07-02] Version 10.4.1 +--------------------------- +**Library - Fix** +- [PR #804](https://github.com/twilio/twilio-java/pull/804): adding cluster tests for orgs api. Thanks to [@AsabuHere](https://github.com/AsabuHere)! + +**Intelligence** +- Deprecate account flag api.twilio-intelligence.v2 + + +[2024-06-27] Version 10.4.0 +--------------------------- +**Library - Feature** +- [PR #803](https://github.com/twilio/twilio-java/pull/803): Support for bearer token authentication and no authentication and PUT method in REST calls. Thanks to [@AsabuHere](https://github.com/AsabuHere)! + +**Api** +- Add `transcription` resource +- Add beta feature request managed cert + +**Flex** +- Changed mount name for flex_team v2 api + +**Intelligence** +- Add `X-Rate-Limit-Limit`, `X-Rate-Limit-Remaining`, and `X-Rate-Limit-Config` as Response Headers to Operator resources + +**Numbers** +- Added include_constraints query parameter to the Regulations API + +**Twiml** +- Add support for `` noun + + +[2024-06-18] Version 10.3.0 +--------------------------- +**Library - Chore** +- [PR #799](https://github.com/twilio/twilio-java/pull/799): process form and body params for all methods except GET. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + +**Events** +- Add `status` and `documentation_url` to Event Types + +**Lookups** +- Removed unused `fraud` lookups in V1 only to facilitate rest proxy migration + +**Numbers** +- Add date_created field to the Get Port In Request API +- Rename the `status_last_time_updated_timestamp` field to `last_updated` in the Get Port In Phone Number API **(breaking change)** +- Add Rejection reason and rejection reason code to the Get Port In Phone Number API +- Remove the carrier information from the Portability API + +**Proxy** +- Change property `type` from enum to ienum + +**Trusthub** +- Add skipMessagingUseCase field in compliance_tollfree_inquiry. + + +[2024-06-06] Version 10.2.1 +--------------------------- +**Api** +- Mark MaxPrice as obsolete + +**Lookups** +- Update examples for `phone_number_quality_score` + +**Messaging** +- List tollfree verifications on parent account and all sub-accounts + + +[2024-05-24] Version 10.2.0 +--------------------------- +**Library - Docs** +- [PR #792](https://github.com/twilio/twilio-java/pull/792): added json examples. Thanks to [@sbansla](https://github.com/sbansla)! + +**Library - Chore** +- [PR #796](https://github.com/twilio/twilio-java/pull/796): adding variant class. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #794](https://github.com/twilio/twilio-java/pull/794): Update pom.xml. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + +**Api** +- Add ie1 as supported region for UserDefinedMessage and UserDefinedMessageSubscription. + +**Flex** +- Adding validated field to `plugin_versions` +- Corrected the data type for `runtime_domain`, `call_recording_webhook_url`, `crm_callback_url`, `crm_fallback_url`, `flex_url` in Flex Configuration +- Making `routing` optional in Create Interactions endpoint + +**Intelligence** +- Expose operator authoring apis to public visibility +- Deleted `language_code` parameter from updating service in v2 **(breaking change)** +- Add read_only_attached_operator_sids to v2 services + +**Numbers** +- Add API endpoint for GET Porting Webhook Configurations By Account SID +- Remove bulk portability api under version `/v1`. **(breaking change)** +- Removed porting_port_in_fetch.json files and move the content into porting_port_in.json files +- Add API endpoint to deleting Webhook Configurations +- Add Get Phone Number by Port in request SID and Phone Number SID api +- Add Create Porting webhook configuration API +- Added bundle_sid and losing_carrier_information fields to Create PortInRequest api to support Japan porting + +**Taskrouter** +- Add back `routing_target` property to tasks +- Add back `ignore_capacity` property to tasks +- Removing `routing_target` property to tasks due to revert +- Removing `ignore_capacity` property to tasks due to revert +- Add `routing_target` property to tasks +- Add `ignore_capacity` property to tasks + +**Trusthub** +- Add new field errors to bundle as part of public API response in customer_profile.json and trust_product.json **(breaking change)** +- Add themeSetId field in compliance_tollfree_inquiry. + +**Verify** +- Update `friendly_name` description on service docs + + +[2024-04-18] Version 10.1.5 +--------------------------- +**Library - Chore** +- [PR #791](https://github.com/twilio/twilio-java/pull/791): add variant class to compliance tests. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #789](https://github.com/twilio/twilio-java/pull/789): bumping nexus staging maven plugin version. Thanks to [@tiwarishubham635](https://github.com/tiwarishubham635)! + +**Flex** +- Add header `ui_version` to `web_channels` API + +**Messaging** +- Redeploy after failed pipeline + +**Numbers** +- Add Delete Port In request phone number api and Add Delete Port In request api + + +[2024-04-04] Version 10.1.4 +--------------------------- +**Api** +- Correct conference filtering by date_created and date_updated documentation, clarifying that times are UTC. + +**Flex** +- Remove optional parameter from `plugins` and it to `plugin_versions` + +**Lookups** +- Add new `pre_fill` package to the lookup response + +**Messaging** +- Cleanup api.messaging.next-gen from Messaging Services endpoints +- Readd Sending-Window after fixing test failure + +**Verify** +- Add `whatsapp.msg_service_sid` and `whatsapp.from` parameters to create, update, get and list of services endpoints + +**Voice** +- Correct conference filtering by date_created and date_updated documentation, clarifying that times are UTC. + +**Twiml** +- Add new `token_type` value `payment-method` for `Pay` verb + + +[2024-04-01] Version 10.1.3 +--------------------------- +**Api** +- Add property `queue_time` to conference participant resource +- Update RiskCheck documentation +- Correct call filtering by start and end time documentation, clarifying that times are UTC. + +**Flex** +- Adding optional parameter to `plugins` + +**Media** +- Remove API: MediaProcessor + +**Messaging** +- Remove Sending-Window due to test failure +- Add Sending-Window as a response property to Messaging Services, gated by a beta feature flag + +**Numbers** +- Correct valid_until_date field to be visible in Bundles resource +- Adding port_in_status field to the Port In resource and phone_number_status and sid fields to the Port In Phone Number resource + +**Oauth** +- Modified token endpoint response +- Added refresh_token and scope as optional parameter to token endpoint + +**Trusthub** +- Add update inquiry endpoint in compliance_registration. +- Add new field in themeSetId in compliance_registration. + +**Voice** +- Correct call filtering by start and end time documentation, clarifying that times are UTC. + +**Twiml** +- Add support for new Google voices (Q1 2024) for `Say` verb - gu-IN voices +- Add support for new Amazon Polly and Google voices (Q1 2024) for `Say` verb - Niamh (en-IE) and Sofie (da-DK) voices + + +[2024-03-14] Version 10.1.2 +--------------------------- +**Oauth** +- Add new APIs for vendor authorize and token endpoints + + +[2024-03-12] Version 10.1.1 +--------------------------- +**Api** +- Correct precedence documentation for application_sid vs status_callback in message creation +- Mark MaxPrice as deprecated + +**Flex** +- Making `plugins` visibility to public + +**Messaging** +- Add new `errors` attribute to the Brand Registration resource. +- Mark `brand_feedback` attribute as deprecated. +- Mark `failure_reason` attribute as deprecated. +- The new `errors` attribute is expected to provide additional information about Brand registration failures and feedback (if any has been provided by The Campaign Registry). Consumers should use this attribute instead of `brand_feedback` and `failure_reason`. + +**Numbers** +- Correcting mount_name for porting port in fetch API + +**Trusthub** +- Add new field in statusCallbackUrl in compliance_registration. +- Add new field in isvRegisteringForSelfOrTenant in compliance_registration. + +**Twiml** +- Expanded description of Action parameter for Message verb + + +[2024-02-27] Version 10.1.0 +--------------------------- +**Library - Chore** +- [PR #781](https://github.com/twilio/twilio-java/pull/781): cluster tests enabled. Thanks to [@sbansla](https://github.com/sbansla)! + +**Api** +- remove feedback and feedback summary from call resource + +**Flex** +- Adding `routing_properties` to Interactions Channels Participant + +**Lookups** +- Add new `line_status` package to the lookup response +- Remove `live_activity` package from the lookup response **(breaking change)** + +**Messaging** +- Add tollfree multiple rejection reasons response array + +**Trusthub** +- Add ENUM for businessRegistrationAuthority in compliance_registration. **(breaking change)** +- Add new field in isIsvEmbed in compliance_registration. +- Add additional optional fields in compliance_registration for Individual business type. + +**Twiml** +- Add support for new Amazon Polly and Google voices (Q1 2024) for `Say` verb + + +[2024-02-09] Version 10.0.0 +--------------------------- +**Note:** This release contains breaking changes, check our [upgrade guide](./UPGRADE.md#2024-02-08-9xx-to-10xx) for detailed migration notes. + +**Library - Chore** +- [PR #780](https://github.com/twilio/twilio-java/pull/780): changed java version. Thanks to [@sbansla](https://github.com/sbansla)! + +**Library - Feature** +- [PR #779](https://github.com/twilio/twilio-java/pull/779): MVR Release Preparation. Thanks to [@sbansla](https://github.com/sbansla)! **(breaking change)** + +**Api** +- Updated service base url for connect apps and authorized connect apps APIs **(breaking change)** +- Update documentation to reflect RiskCheck GA +- Added optional parameter `CallToken` for create participant api + +**Events** +- Marked as GA + +**Flex** +- Adding `flex_instance_sid` to Flex Configuration +- Adding `provisioning_status` for Email Manager +- Adding `offline_config` to Flex Configuration + +**Insights** +- add flag to restrict access to unapid customers +- decommission voice-qualitystats-endpoint role + +**Intelligence** +- Add text-generation operator (for example conversation summary) results to existing OperatorResults collection. + +**Lookups** +- Remove `carrier` field from `sms_pumping_risk` and leave `carrier_risk_category` **(breaking change)** +- Remove carrier information from call forwarding package **(breaking change)** + +**Messaging** +- Add update instance endpoints to us_app_to_person api +- Add tollfree edit_allowed and edit_reason fields +- Update Phone Number, Short Code, Alpha Sender, US A2P and Channel Sender documentation +- Add DELETE support to Tollfree Verification resource + +**Numbers** +- Add Get Port In request api + +**Push** +- Migrated to new Push API V4 with Resilient Notification Delivery. + +**Serverless** +- Add node18 as a valid Build runtime + +**Taskrouter** +- Add `jitter_buffer_size` param in update reservation +- Add container attribute to task_queue_bulk_real_time_statistics endpoint +- Remove beta_feature check on task_queue_bulk_real_time_statistics endpoint + +**Trusthub** +- Add optional field NotificationEmail to the POST /v1/ComplianceInquiries/Customers/Initialize API +- Add additional optional fields in compliance_tollfree_inquiry.json +- Rename did to tollfree_phone_number in compliance_tollfree_inquiry.json +- Add new optional field notification_email to compliance_tollfree_inquiry.json + +**Verify** +- `Tags` property added again to Public Docs **(breaking change)** +- Remove `Tags` from Public Docs **(breaking change)** +- Add `VerifyEventSubscriptionEnabled` parameter to service create and update endpoints. +- Add `Tags` optional parameter on Verification creation. +- Update Verify TOTP maturity to GA. + + +[2024-01-25] Version 9.16.0 +--------------------------- +**Oauth** +- updated openid discovery endpoint uri **(breaking change)** +- Added device code authorization endpoint +- added oauth JWKS endpoint +- Get userinfo resource +- OpenID discovery resource +- Add new API for token endpoint + + +[2024-01-14] Version 9.15.1 +--------------------------- +**Push** +- Migrated to new Push API V4 with Resilient Notification Delivery. + + +[2023-12-14] Version 9.15.0 +--------------------------- +**Api** +- Updated service base url for connect apps and authorized connect apps APIs **(breaking change)** + +**Events** +- Marked as GA + +**Insights** +- decommission voice-qualitystats-endpoint role + +**Numbers** +- Add Get Port In request api + +**Taskrouter** +- Add `jitter_buffer_size` param in update reservation + +**Trusthub** +- Add additional optional fields in compliance_tollfree_inquiry.json + +**Verify** +- Remove `Tags` from Public Docs **(breaking change)** + + +[2023-12-01] Version 9.14.3 +--------------------------- +**Verify** +- Add `VerifyEventSubscriptionEnabled` parameter to service create and update endpoints. + + +[2023-11-17] Version 9.14.2 +--------------------------- +**Api** +- Update documentation to reflect RiskCheck GA + +**Messaging** +- Add tollfree edit_allowed and edit_reason fields +- Update Phone Number, Short Code, Alpha Sender, US A2P and Channel Sender documentation + +**Taskrouter** +- Add container attribute to task_queue_bulk_real_time_statistics endpoint + +**Trusthub** +- Rename did to tollfree_phone_number in compliance_tollfree_inquiry.json +- Add new optional field notification_email to compliance_tollfree_inquiry.json + +**Verify** +- Add `Tags` optional parameter on Verification creation. + + +[2023-11-06] Version 9.14.1 +--------------------------- +**Flex** +- Adding `provisioning_status` for Email Manager + +**Intelligence** +- Add text-generation operator (for example conversation summary) results to existing OperatorResults collection. + +**Messaging** +- Add DELETE support to Tollfree Verification resource + +**Serverless** +- Add node18 as a valid Build runtime + +**Verify** +- Update Verify TOTP maturity to GA. + + +[2023-10-19] Version 9.14.0 +--------------------------- +**Library - Chore** +- [PR #771](https://github.com/twilio/twilio-java/pull/771): added constructor in api exception. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #768](https://github.com/twilio/twilio-java/pull/768): increased default number of total connections and connection p…. Thanks to [@sbansla](https://github.com/sbansla)! + +**Accounts** +- Updated Safelist metadata to correct the docs. +- Add Global SafeList API changes + +**Api** +- Added optional parameter `CallToken` for create participant api + +**Flex** +- Adding `offline_config` to Flex Configuration + +**Intelligence** +- Deleted `redacted` parameter from fetching transcript in v2 **(breaking change)** + +**Lookups** +- Add new `phone_number_quality_score` package to the lookup response +- Remove `disposable_phone_number_risk` package **(breaking change)** + +**Messaging** +- Update US App To Person documentation with current `message_samples` requirements + +**Taskrouter** +- Remove beta_feature check on task_queue_bulk_real_time_statistics endpoint +- Add `virtual_start_time` property to tasks +- Updating `task_queue_data` format from `map` to `array` in the response of bulk get endpoint of TaskQueue Real Time Statistics API **(breaking change)** + + +[2023-10-05] Version 9.13.1 +--------------------------- +**Library - Chore** +- [PR #764](https://github.com/twilio/twilio-java/pull/764): twilio help changes. Thanks to [@kridai](https://github.com/kridai)! + +**Library - Fix** +- [PR #765](https://github.com/twilio/twilio-java/pull/765): Update ValidateSslCertificate method changes to the security testing method. Thanks to [@AsabuHere](https://github.com/AsabuHere)! + +**Lookups** +- Add test api support for Lookup v2 + + +[2023-09-21] Version 9.13.0 +--------------------------- +**Conversations** +- Enable conversation email bindings, email address configurations and email message subjects + +**Flex** +- Adding `console_errors_included` to Flex Configuration field `debugger_integrations` +- Introducing new channel status as `inactive` in modify channel endpoint for leave functionality **(breaking change)** +- Adding `citrix_voice_vdi` to Flex Configuration + +**Taskrouter** +- Add Update Queues, Workers, Workflow Real Time Statistics API to flex-rt-data-api-v2 endpoint +- Add Update Workspace Real Time Statistics API to flex-rt-data-api-v2 endpoint + + +[2023-09-07] Version 9.12.0 +--------------------------- +**Api** +- Make message tagging parameters public **(breaking change)** + +**Flex** +- Adding `agent_conv_end_methods` to Flex Configuration + +**Messaging** +- Mark Mesasging Services fallback_to_long_code feature obsolete + +**Numbers** +- Add Create Port In request api +- Renaming sid for bulk_hosting_sid and remove account_sid response field in numbers/v2/BulkHostedNumberOrders **(breaking change)** + +**Pricing** +- gate resources behind a beta_feature + + +[2023-08-24] Version 9.11.0 +--------------------------- +**Library - Chore** +- [PR #761](https://github.com/twilio/twilio-java/pull/761): update validation example. Thanks to [@kridai](https://github.com/kridai)! + +**Library - Feature** +- [PR #759](https://github.com/twilio/twilio-java/pull/759): add support for PS256, RS256 PKCV in validationClient. Thanks to [@kridai](https://github.com/kridai)! + +**Api** +- Add new property `RiskCheck` for SMS pumping protection feature only (public beta to be available soon): Include this parameter with a value of `disable` to skip any kind of risk check on the respective message request + +**Flex** +- Changing `sid` path param to `sid` in interaction channel participant update endpoint **(breaking change)** + +**Messaging** +- Add Channel Sender api +- Fixing country code docs and removing Zipwhip references + +**Numbers** +- Request status changed in numbers/v2/BulkHostedNumberOrders **(breaking change)** +- Add bulk hosting orders API under version `/v2 + + +[2023-08-10] Version 9.10.0 +--------------------------- +**Insights** +- Normalize annotations parameters in list summary api to be prefixed + +**Numbers** +- Change Bulk_hosted_sid from BHR to BH prefix in HNO and dependent under version `/v2` API's. **(breaking change)** +- Added parameter target_account_sid to portability and account_sid to response body + +**Verify** +- Remove beta feature flag to list attempts API. +- Remove beta feature flag to verifications summary attempts API. + + +[2023-07-27] Version 9.9.1 +-------------------------- +**Api** +- Added `voice-intelligence`, `voice-intelligence-transcription` and `voice-intelligence-operators` to `usage_record` API. +- Added `tts-google` to `usage_record` API. + +**Lookups** +- Add new `disposable_phone_number_risk` package to the lookup response + +**Verify** +- Documentation of list attempts API was improved by correcting `date_created_after` and `date_created_before` expected date format. +- Documentation was improved by correcting `date_created_after` and `date_created_before` expected date format parameter on attempts summary API. +- Documentation was improved by adding `WHATSAPP` as optional valid parameter on attempts summary API. + +**Twiml** +- Added support for he-il inside of ssm_lang.json that was missing +- Added support for he-il language in say.json that was missing +- Add `statusCallback` and `statusCallbackMethod` attributes to ``. + + +[2023-07-14] Version 9.9.0 +-------------------------- +**Flex** +- Adding `interaction_context_sid` as optional parameter in Interactions API + +**Messaging** +- Making visiblity public for tollfree_verification API + +**Numbers** +- Remove Sms capability property from HNO creation under version `/v2` of HNO API. **(breaking change)** +- Update required properties in LOA creation under version `/v2` of Authorization document API. **(breaking change)** + +**Taskrouter** +- Add api to fetch task queue statistics for multiple TaskQueues + +**Verify** +- Add `RiskCheck` optional parameter on Verification creation. + +**Twiml** +- Add Google Voices and languages + + +[2023-06-28] Version 9.8.0 +-------------------------- +**Library - Chore** +- [PR #754](https://github.com/twilio/twilio-java/pull/754): Add content type enum to request. Thanks to [@sbansla](https://github.com/sbansla)! +- [PR #753](https://github.com/twilio/twilio-java/pull/753): added content type enum. Thanks to [@sbansla](https://github.com/sbansla)! + +**Lookups** +- Add `reassigned_number` package to the lookup response + +**Numbers** +- Add hosted_number_order under version `/v2`. +- Update properties in Porting and Bulk Porting APIs. **(breaking change)** +- Added bulk Portability API under version `/v1`. +- Added Portability API under version `/v1`. + + +[2023-06-15] Version 9.7.0 +-------------------------- +**Api** +- Added `content_sid` as conditional parameter +- Removed `content_sid` as optional field **(breaking change)** + +**Insights** +- Added `annotation` to list summary output + + +[2023-06-01] Version 9.6.2 +-------------------------- +**Api** +- Add `Trim` to create Conference Participant API + +**Intelligence** +- First public beta release for Voice Intelligence APIs with client libraries + +**Messaging** +- Add new `errors` attribute to us_app_to_person resource. This attribute will provide additional information about campaign registration errors. + + +[2023-05-18] Version 9.6.1 +-------------------------- +**Library - Fix** +- [PR #743](https://github.com/twilio/twilio-java/pull/743): Removing org.json as this repo doesnot contain a direct dependency. Thanks to [@AsabuHere](https://github.com/AsabuHere)! + +**Conversations** +- Added `AddressCountry` parameter to Address Configuration endpoint, to support regional short code addresses +- Added query parameters `start_date`, `end_date` and `state` in list Conversations resource for filtering + +**Insights** +- Added annotations parameters to list summary api + +**Messaging** +- Add GET domainByMessagingService endpoint to linkShortening service +- Add `disable_https` to link shortening domain_config properties + +**Numbers** +- Add bulk_eligibility api under version `/v1`. + + +[2023-05-04] Version 9.6.0 +-------------------------- +**Conversations** +- Remove `start_date`, `end_date` and `state` query parameters from list operation on Conversations resource **(breaking change)** + +**Twiml** +- Add support for new Amazon Polly voices (Q1 2023) for `Say` verb + + +[2023-04-19] Version 9.5.0 +-------------------------- +**Library - Docs** +- [PR #739](https://github.com/twilio/twilio-java/pull/739): consolidate. Thanks to [@stern-shawn](https://github.com/stern-shawn)! + +**Messaging** +- Remove `messaging_service_sids` and `messaging_service_sid_action` from domain config endpoint **(breaking change)** +- Add error_code and rejection_reason properties to tollfree verification API response + +**Numbers** +- Added the new Eligibility API under version `/v1`. + + +[2023-04-05] Version 9.4.0 +-------------------------- +**Library - Docs** +- [PR #738](https://github.com/twilio/twilio-java/pull/738): provide more detailed debug logging example. Thanks to [@stern-shawn](https://github.com/stern-shawn)! + +**Conversations** +- Expose query parameters `start_date`, `end_date` and `state` in list operation on Conversations resource for sorting and filtering + +**Insights** +- Added answered by filter in Call Summaries + +**Lookups** +- Remove `disposable_phone_number_risk` package **(breaking change)** + +**Messaging** +- Add support for `SOLE_PROPRIETOR` brand type and `SOLE_PROPRIETOR` campaign use case. +- New Sole Proprietor Brands should be created with `SOLE_PROPRIETOR` brand type. Brand registration requests with `STARTER` brand type will be rejected. +- New Sole Proprietor Campaigns should be created with `SOLE_PROPRIETOR` campaign use case. Campaign registration requests with `STARTER` campaign use case will be rejected. +- Add Brand Registrations OTP API + + +[2023-03-22] Version 9.3.0 +-------------------------- +**Library - Chore** +- [PR #735](https://github.com/twilio/twilio-java/pull/735): protected NetworkHttpClient field. Thanks to [@bcanseco](https://github.com/bcanseco)! + +**Api** +- Revert Corrected the data type for `friendly_name` in Available Phone Number Local, Mobile and TollFree resources +- Corrected the data type for `friendly_name` in Available Phone Number Local, Mobile and TollFree resources **(breaking change)** + +**Messaging** +- Add `linkshortening_messaging_service` resource +- Add new endpoint for GetDomainConfigByMessagingServiceSid +- Remove `validated` parameter and add `cert_in_validation` parameter to Link Shortening API **(breaking change)** + + +[2023-03-09] Version 9.2.5 +-------------------------- +**Api** +- Add new categories for whatsapp template + +**Lookups** +- Remove `validation_results` from the `default_output_properties` + +**Supersim** +- Add ESimProfile's `matching_id` and `activation_code` parameters to libraries + + +[2023-02-22] Version 9.2.4 +-------------------------- +**Api** +- Remove `scheduled_for` property from message resource +- Add `scheduled_for` property to message resource + + +[2023-02-08] Version 9.2.3 +-------------------------- +**Library - Fix** +- [PR #731](https://github.com/twilio/twilio-java/pull/731): add request null check. Thanks to [@charan678](https://github.com/charan678)! +- [PR #730](https://github.com/twilio/twilio-java/pull/730): add null string check. Thanks to [@charan678](https://github.com/charan678)! +- [PR #729](https://github.com/twilio/twilio-java/pull/729): set correct Parameter name. Thanks to [@isha689](https://github.com/isha689)! +- [PR #727](https://github.com/twilio/twilio-java/pull/727): add non null values to param list. Thanks to [@charan678](https://github.com/charan678)! + +**Lookups** +- Add `disposable_phone_number_risk` package to the lookup response +- Add `sms_pumping_risk` package to the lookup response + + +[2023-01-25] Version 9.2.2 +-------------------------- +**Api** +- Add `public_application_connect_enabled` param to Application resource + +**Messaging** +- Add new tollfree verification API property (ExternalReferenceId)] + +**Verify** +- Add `device_ip` parameter and channel `auto` for sna/sms orchestration + +**Twiml** +- Add support for `` noun and `` noun, nested `` to `` and `` verb + + +[2023-01-11] Version 9.2.1 +-------------------------- +**Conversations** +- Add support for creating Multi-Channel Rich Content Messages + +**Lookups** +- Changed the no data message for match postal code from `no_data` to `data_not_available` in identity match package + +**Messaging** +- Add update/edit tollfree verification API + + +[2022-12-14] Version 9.2.0 +-------------------------- +**Library - Fix** +- [PR #725](https://github.com/twilio/twilio-java/pull/725): Fixing Flaky Tests. Thanks to [@priyanka-28](https://github.com/priyanka-28)! +- [PR #722](https://github.com/twilio/twilio-java/pull/722): fromXml for self-closing child twiml. Thanks to [@bcanseco](https://github.com/bcanseco)! + +**Api** +- Add `street_secondary` param to address create and update +- Make `method` optional for user defined message subscription **(breaking change)** + +**Flex** +- Flex Conversations is now Generally Available +- Adding the ie1 mapping for authorization api, updating service base uri and base url response attribute **(breaking change)** +- Change web channels to GA and library visibility to public +- Changing the uri for authorization api from using Accounts to Insights **(breaking change)** + +**Media** +- Gate Twilio Live endpoints behind beta_feature for EOS + +**Messaging** +- Mark `MessageFlow` as a required field for Campaign Creation **(breaking change)** + +**Oauth** +- updated openid discovery endpoint uri **(breaking change)** +- Added device code authorization endpoint + +**Supersim** +- Allow filtering the SettingsUpdates resource by `status` + +**Twiml** +- Add new Polly Neural voices +- Add tr-TR, ar-AE, yue-CN, fi-FI languages to SSML `` element. +- Add x-amazon-jyutping, x-amazon-pinyin, x-amazon-pron-kana, x-amazon-yomigana alphabets to SSML `` element. +- Rename `character` value for SSML `` `interpret-as` attribute to `characters`. **(breaking change)** +- Rename `role` attribute to `format` in SSML `` element. **(breaking change)** + + +[2022-11-30] Version 9.1.4 +-------------------------- +**Flex** +- Adding new `assessments` api in version `v1` + +**Lookups** +- Add `identity_match` package to the lookup response + +**Messaging** +- Added `validated` parameter to Link Shortening API + +**Serverless** +- Add node16 as a valid Build runtime +- Add ie1 and au1 as supported regions for all endpoints. + + +[2022-11-16] Version 9.1.3 +-------------------------- +**Library - Chore** +- [PR #721](https://github.com/twilio/twilio-java/pull/721): bump jackson to 2.14.0. Thanks to [@JenniferMah](https://github.com/JenniferMah)! +- [PR #720](https://github.com/twilio/twilio-java/pull/720): bump jackson-databind to latest 2.13.4.2. Thanks to [@jacobdanner](https://github.com/jacobdanner)! +- [PR #719](https://github.com/twilio/twilio-java/pull/719): upgrade GitHub Actions dependencies. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Api** +- Set the Content resource to have public visibility as Preview + +**Flex** +- Adding new parameter `base_url` to 'gooddata' response in version `v1` + +**Insights** +- Added `answered_by` field in List Call Summary +- Added `answered_by` field in call summary + + +[2022-11-10] Version 9.1.2 +-------------------------- +**Flex** +- Adding two new authorization API 'user_roles' and 'gooddata' in version `v1` + +**Messaging** +- Add new Campaign properties (MessageFlow, OptInMessage, OptInKeywords, OptOutMessage, OptOutKeywords, HelpMessage, HelpKeywords) + +**Twiml** +- Add new speech models to `Gather`. + + +[2022-11-02] Version 9.1.1 +-------------------------- +**Api** +- Added `contentSid` and `contentVariables` to Message resource with public visibility as Beta +- Add `UserDefinedMessageSubscription` and `UserDefinedMessage` resource + +**Proxy** +- Remove FailOnParticipantConflict param from Proxy Session create and update and Proxy Participant create + +**Supersim** +- Update SettingsUpdates resource to remove PackageSid + +**Taskrouter** +- Add `Ordering` query parameter to Workers and TaskQueues for sorting by +- Add `worker_sid` query param for list reservations endpoint + +**Twiml** +- Add `url` and `method` attributes to `` + + +[2022-10-19] Version 9.1.0 +-------------------------- +**Library - Fix** +- [PR #717](https://github.com/twilio/twilio-java/pull/717): update reserved words. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Chore** +- [PR #715](https://github.com/twilio/twilio-java/pull/715): Fix for 1 vulnerabilities. Thanks to [@twilio-product-security](https://github.com/twilio-product-security)! + +**Library - Miscellaneous** +- [PR #716](https://github.com/twilio/twilio-java/pull/716): remove the duplicate header comments. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #714](https://github.com/twilio/twilio-java/pull/714): remove dependency on javax jaxb-api. Thanks to [@codylerum](https://github.com/codylerum)! + +**Api** +- Make link shortening parameters public **(breaking change)** + +**Oauth** +- added oauth JWKS endpoint +- Get userinfo resource +- OpenID discovery resource +- Add new API for token endpoint + +**Supersim** +- Add SettingsUpdates resource + +**Verify** +- Update Verify Push endpoints to `ga` maturity +- Verify BYOT add Channels property to the Get Templates response + +**Twiml** +- Add `requireMatchingInputs` attribute and `input-matching-failed` errorType to `` + + +[2022-10-05] Version 9.0.1 +-------------------------- +**Library - Miscellaneous** +- [PR #712](https://github.com/twilio/twilio-java/pull/712): ignore openapi generation relics. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Docs** +- [PR #710](https://github.com/twilio/twilio-java/pull/710): updating contribution docs. Thanks to [@kridai](https://github.com/kridai)! + +**Api** +- Added `virtual-agent` to `usage_record` API. +- Add AMD attributes to participant create request + +**Twiml** +- Add AMD attributes to `Number` and `Sip` + + +[2022-09-21] Version 9.0.0 +-------------------------- +**Note:** This release contains breaking changes, check our [upgrade guide](./UPGRADE.md#2022-09-21-8xx-to-9xx) for detailed migration notes. + +**Library - Feature** +- [PR #709](https://github.com/twilio/twilio-java/pull/709): merging 9.0.0-rc to main. Thanks to [@kridai](https://github.com/kridai)! **(breaking change)** + + +[2022-09-07] Version 8.36.0 +--------------------------- +**Library - Fix** +- [PR #706](https://github.com/twilio/twilio-java/pull/706): fix repeated get content calls issue. Thanks to [@kridai](https://github.com/kridai)! + +**Flex** +- Removed redundant `close` status from Flex Interactions flow **(breaking change)** +- Adding `debugger_integration` and `flex_ui_status_report` to Flex Configuration + +**Messaging** +- Add create, list and get tollfree verification API + +**Verify** +- Verify SafeList API endpoints added. + +**Video** +- Add `Anonymize` API + +**Twiml** +- Update `event` value `call-in-progress` to `call-answered` + + +[2022-08-24] Version 8.35.0 +--------------------------- +**Library - Test** +- [PR #704](https://github.com/twilio/twilio-java/pull/704): add test-docker rule. Thanks to [@beebzz](https://github.com/beebzz)! + +**Api** +- Remove `beta feature` from scheduling params and remove optimize parameters. **(breaking change)** + +**Routes** +- Remove Duplicate Create Method - Update Method will work even if Inbound Processing Region is currently empty/404. **(breaking change)** + +**Twiml** +- Add new Polly Neural voices +- Add new languages to SSML ``. + + +[2022-08-10] Version 8.34.1 +--------------------------- +**Library - Docs** +- [PR #702](https://github.com/twilio/twilio-java/pull/702): updated readme.md for java release candidate. Thanks to [@kridai](https://github.com/kridai)! + +**Routes** +- Inbound Proccessing Region API - Public GA + +**Supersim** +- Allow updating `DataLimit` on a Fleet + + +[2022-07-21] Version 8.34.0 +--------------------------- +**Flex** +- Add `status`, `error_code`, and `error_message` fields to Interaction `Channel` +- Adding `messenger` and `gbm` as supported channels for Interactions API + +**Messaging** +- Update alpha_sender docs with new valid characters + +**Verify** +- Reorder Verification Check parameters so `code` stays as the first parameter **(breaking change)** +- Rollback List Attempts API V2 back to pilot stage. + + +[2022-07-13] Version 8.33.0 +--------------------------- +**Library - Test** +- [PR #699](https://github.com/twilio/twilio-java/pull/699): Adding misc as PR type. Thanks to [@rakatyal](https://github.com/rakatyal)! + +**Conversations** +- Allowed to use `identity` as part of Participant's resource **(breaking change)** + +**Lookups** +- Remove `enhanced_line_type` from the lookup response **(breaking change)** + +**Supersim** +- Add support for `sim_ip_addresses` resource to helper libraries + +**Verify** +- Changed summary param `service_sid` to `verify_service_sid` to be consistent with list attempts API **(breaking change)** +- Make `code` optional on Verification check to support `sna` attempts. **(breaking change)** + + +[2022-06-29] Version 8.32.0 +--------------------------- +**Api** +- Added `amazon-polly` to `usage_record` API. + +**Insights** +- Added `annotation` field in call summary +- Added new endpoint to fetch/create/update Call Annotations + +**Verify** +- Remove `api.verify.totp` beta flag and set maturity to `beta` for Verify TOTP properties and parameters. **(breaking change)** +- Changed summary param `verify_service_sid` to `service_sid` to be consistent with list attempts API **(breaking change)** + +**Twiml** +- Add `maxQueueSize` to `Enqueue` + + +[2022-06-15] Version 8.31.1 +--------------------------- +**Library - Chore** +- [PR #677](https://github.com/twilio/twilio-java/pull/677): bump jackson-databind from 2.12.6 to 2.13.3. Thanks to [@dependabot](https://github.com/dependabot)! + +**Lookups** +- Adding support for Lookup V2 API + +**Studio** +- Corrected PII labels to be 30 days and added context to be PII + +**Twiml** +- Add `statusCallbackMethod` attribute, nested `` elements to `` noun. +- Add support for new Amazon Polly voices (Q2 2022) for `Say` verb +- Add support for `` noun + + +[2022-06-01] Version 8.31.0 +--------------------------- +**Library - Chore** +- [PR #693](https://github.com/twilio/twilio-java/pull/693): use Docker 'rc' tag for release candidate images. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Fix** +- [PR #692](https://github.com/twilio/twilio-java/pull/692): reset account sid when using username and password only. Thanks to [@aarya-brex](https://github.com/aarya-brex)! +- [PR #688](https://github.com/twilio/twilio-java/pull/688): support setting null account sid. Thanks to [@aarya-brex](https://github.com/aarya-brex)! + +**Library - Feature** +- [PR #683](https://github.com/twilio/twilio-java/pull/683): modify user agent string. Thanks to [@sbansla](https://github.com/sbansla)! + + +[2022-05-18] Version 8.30.1 +--------------------------- +**Api** +- Add property `media_url` to the recording resources + +**Verify** +- Include `silent` as a channel type in the verifications API. + + +[2022-05-04] Version 8.30.0 +--------------------------- +**Conversations** +- Expose query parameter `type` in list operation on Address Configurations resource + +**Supersim** +- Add `data_total_billed` and `billed_units` fields to Super SIM UsageRecords API response. +- Change ESimProfiles `Eid` parameter to optional to enable Activation Code download method support **(breaking change)** + +**Verify** +- Deprecate `push.include_date` parameter in create and update service. + + +[2022-04-20] Version 8.29.1 +--------------------------- +**Library - Chore** +- [PR #678](https://github.com/twilio/twilio-java/pull/678): update testcase to remove dependency from generated files. Thanks to [@shrutiburman](https://github.com/shrutiburman)! + + +[2022-04-06] Version 8.29.0 +--------------------------- +**Library - Feature** +- [PR #676](https://github.com/twilio/twilio-java/pull/676): support shortcode as an InboundSmsPrice type. Thanks to [@beebzz](https://github.com/beebzz)! + +**Api** +- Updated `provider_sid` visibility to private + +**Verify** +- Verify List Attempts API summary endpoint added. +- Update PII documentation for `AccessTokens` `factor_friendly_name` property. + +**Voice** +- make annotation parameter from /Calls API private + + +[2022-03-23] Version 8.28.0 +--------------------------- +**Api** +- Change `stream` url parameter to non optional +- Add `verify-totp` and `verify-whatsapp-conversations-business-initiated` categories to `usage_record` API + +**Chat** +- Added v3 Channel update endpoint to support Public to Private channel migration + +**Flex** +- Private Beta release of the Interactions API to support the upcoming release of Flex Conversations at the end of Q1 2022. +- Adding `channel_configs` object to Flex Configuration + +**Media** +- Add max_duration param to PlayerStreamer + +**Supersim** +- Remove Commands resource, use SmsCommands resource instead **(breaking change)** + +**Taskrouter** +- Add limits to `split_by_wait_time` for Cumulative Statistics Endpoint + +**Video** +- Change recording `status_callback_method` type from `enum` to `http_method` **(breaking change)** +- Add `status_callback` and `status_callback_method` to composition +- Add `status_callback` and `status_callback_method` to recording + + +[2022-03-09] Version 8.27.1 +--------------------------- +**Library - Chore** +- [PR #672](https://github.com/twilio/twilio-java/pull/672): push Datadog Release Metric upon deploy success. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Api** +- Add optional boolean include_soft_deleted parameter to retrieve soft deleted recordings + +**Chat** +- Add `X-Twilio-Wehook-Enabled` header to `delete` method in UserChannel resource + +**Numbers** +- Expose `failure_reason` in the Supporting Documents resources + +**Verify** +- Add optional `metadata` parameter to "verify challenge" endpoint, so the SDK/App can attach relevant information from the device when responding to challenges. +- remove beta feature flag to list atempt api operations. + + +[2022-02-23] Version 8.27.0 +--------------------------- +**Library - Chore** +- [PR #671](https://github.com/twilio/twilio-java/pull/671): archunit 0.23.0. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Add `uri` to `stream` resource +- Add A2P Registration Fee category (`a2p-registration-fee`) to usage records +- Detected a bug and removed optional boolean include_soft_deleted parameter to retrieve soft deleted recordings. **(breaking change)** +- Add optional boolean include_soft_deleted parameter to retrieve soft deleted recordings. + +**Numbers** +- Unrevert valid_until and sort filter params added to List Bundles resource +- Revert valid_until and sort filter params added to List Bundles resource +- Update sorting params added to List Bundles resource in the previous release + +**Preview** +- Moved `web_channels` from preview to beta under `flex-api` **(breaking change)** + +**Taskrouter** +- Add `ETag` as Response Header to List of Task, Reservation & Worker + +**Verify** +- Add `ttl` and `date_created` properties to `AccessTokens`. +- Remove outdated documentation commentary to contact sales. Product is already in public beta. +- Add optional `metadata` to factors. + +**Twiml** +- Add new Polly Neural voices + + +[2022-02-09] Version 8.26.0 +--------------------------- +**Library - Chore** +- [PR #668](https://github.com/twilio/twilio-java/pull/668): Fix for 1 vulnerabilities. Thanks to [@twilio-product-security](https://github.com/twilio-product-security)! +- [PR #669](https://github.com/twilio/twilio-java/pull/669): added sonarcloud integration. Thanks to [@BrimmingDev](https://github.com/BrimmingDev)! + +**Library - Fix** +- [PR #670](https://github.com/twilio/twilio-java/pull/670): set socket config with blocking operation timeout. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Api** +- Add `stream` resource + +**Conversations** +- Fixed DELETE request to accept "sid_like" params in Address Configuration resources **(breaking change)** +- Expose Address Configuration resource for `sms` and `whatsapp` + +**Fax** +- Removed deprecated Programmable Fax Create and Update methods **(breaking change)** + +**Insights** +- Rename `call_state` to `call_status` and remove `whisper` in conference participant summary **(breaking change)** + +**Numbers** +- Expose valid_until filters as part of provisionally-approved compliance feature on the List Bundles resource + +**Supersim** +- Fix typo in Fleet resource docs +- Updated documentation for the Fleet resource indicating that fields related to commands have been deprecated and to use sms_command fields instead. +- Add support for setting and reading `ip_commands_url` and `ip_commands_method` on Fleets resource for helper libraries +- Changed `sim` property in requests to create an SMS Command made to the /SmsCommands to accept SIM UniqueNames in addition to SIDs + +**Verify** +- Update list attempts API to include new filters and response fields. + + +[2022-01-26] Version 8.25.1 +--------------------------- +**Insights** +- Added new endpoint to fetch Conference Participant Summary +- Added new endpoint to fetch Conference Summary + +**Messaging** +- Add government_entity parameter to brand apis + +**Verify** +- Add Access Token fetch endpoint to retrieve a previously created token. +- Add Access Token payload to the Access Token creation endpoint, including a unique Sid, so it's addressable while it's TTL is valid. + + +[2022-01-12] Version 8.25.0 +--------------------------- +**Library - Feature** +- [PR #666](https://github.com/twilio/twilio-java/pull/666): add GitHub release step during deploy. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Chore** +- [PR #665](https://github.com/twilio/twilio-java/pull/665): migrate sonatype hosts. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Api** +- Make fixed time scheduling parameters public **(breaking change)** + +**Messaging** +- Add update brand registration API + +**Numbers** +- Add API endpoint for List Bundle Copies resource + +**Video** +- Enable external storage for all customers + + +[2021-12-15] Version 8.24.0 +--------------------------- +**Library - Feature** +- [PR #662](https://github.com/twilio/twilio-java/pull/662): run tests before deploying. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Api** +- Add optional boolean send_as_mms parameter to the create action of Message resource **(breaking change)** +- Change team ownership for `call` delete + +**Conversations** +- Change wording for `Service Webhook Configuration` resource fields + +**Insights** +- Added new APIs for updating and getting voice insights flags by accountSid. + +**Media** +- Add max_duration param to MediaProcessor + +**Video** +- Add `EmptyRoomTimeout` and `UnusedRoomTimeout` properties to a room; add corresponding parameters to room creation + +**Voice** +- Add endpoint to delete archived Calls + + +[2021-12-01] Version 8.23.0 +--------------------------- +**Library - Feature** +- [PR #661](https://github.com/twilio/twilio-java/pull/661): add fromXml method on builders (twiml). Thanks to [@bcanseco](https://github.com/bcanseco)! + +**Library - Chore** +- [PR #660](https://github.com/twilio/twilio-java/pull/660): setup for XML deserialization. Thanks to [@bcanseco](https://github.com/bcanseco)! + +**Conversations** +- Add `Service Webhook Configuration` resource + +**Flex** +- Adding `flex_insights_drilldown` and `flex_url` objects to Flex Configuration + +**Messaging** +- Update us_app_to_person endpoints to remove beta feature flag based access + +**Supersim** +- Add IP Commands resource + +**Verify** +- Add optional `factor_friendly_name` parameter to the create access token endpoint. + +**Video** +- Add maxParticipantDuration param to Rooms + +**Twiml** +- Unrevert Add supported SSML children to ``, ``, `

`, ``, ``, and ``. +- Revert Add supported SSML children to ``, ``, `

`, ``, ``, and ``. + + +[2021-11-17] Version 8.22.1 +--------------------------- +**Library - Chore** +- [PR #658](https://github.com/twilio/twilio-java/pull/658): lombok 1.18.16. Thanks to [@sullis](https://github.com/sullis)! +- [PR #643](https://github.com/twilio/twilio-java/pull/643): maven-enforcer-plugin 3.0.0. Thanks to [@sullis](https://github.com/sullis)! +- [PR #654](https://github.com/twilio/twilio-java/pull/654): archunit 0.22.0. Thanks to [@sullis](https://github.com/sullis)! + +**Library - Fix** +- [PR #657](https://github.com/twilio/twilio-java/pull/657): git log retrieval issues. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! + +**Frontline** +- Added `is_available` to User's resource + +**Messaging** +- Added GET vetting API + +**Verify** +- Add `WHATSAPP` to the attempts API. +- Allow to update `config.notification_platform` from `none` to `apn` or `fcm` and viceversa for Verify Push +- Add `none` as a valid `config.notification_platform` value for Verify Push + +**Twiml** +- Add supported SSML children to ``, ``, `

`, ``, ``, and ``. + + +[2021-11-03] Version 8.22.0 +--------------------------- +**Library - Chore** +- [PR #655](https://github.com/twilio/twilio-java/pull/655): migrate from travis ci to gh actions. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Api** +- Updated `media_url` property to be treated as PII + +**Messaging** +- Added a new enum for brand registration status named DELETED **(breaking change)** +- Add a new K12_EDUCATION use case in us_app_to_person_usecase api transaction +- Added a new enum for brand registration status named IN_REVIEW + +**Serverless** +- Add node14 as a valid Build runtime + +**Verify** +- Fix typos in Verify Push Factor documentation for the `config.notification_token` parameter. +- Added `TemplateCustomSubstitutions` on verification creation +- Make `TemplateSid` parameter public for Verification resource and `DefaultTemplateSid` parameter public for Service resource. **(breaking change)** + + +[2021-10-18] Version 8.21.0 +--------------------------- +**Library - Chore** +- [PR #653](https://github.com/twilio/twilio-java/pull/653): bump jackson dependency version. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! +- [PR #651](https://github.com/twilio/twilio-java/pull/651): upgrade maven-javadoc-plugin. Thanks to [@sullis](https://github.com/sullis)! + +**Library - Feature** +- [PR #652](https://github.com/twilio/twilio-java/pull/652): Add PlaybackGrant. Thanks to [@miguelgrinberg](https://github.com/miguelgrinberg)! + +**Api** +- Corrected enum values for `emergency_address_status` values in `/IncomingPhoneNumbers` response. **(breaking change)** +- Clarify `emergency_address_status` values in `/IncomingPhoneNumbers` response. + +**Messaging** +- Add PUT and List brand vettings api +- Removes beta feature flag based visibility for us_app_to_person_registered and usecase field.Updates test cases to add POLITICAL usecase. **(breaking change)** +- Add brand_feedback as optional field to BrandRegistrations + +**Video** +- Add `AudioOnly` to create room + + +[2021-10-06] Version 8.20.0 +--------------------------- +**Library - Fix** +- [PR #649](https://github.com/twilio/twilio-java/pull/649): System Information Leak. Thanks to [@JenniferMah](https://github.com/JenniferMah)! + +**Api** +- Add `emergency_address_status` attribute to `/IncomingPhoneNumbers` response. +- Add `siprec` resource + +**Conversations** +- Added attachment parameters in configuration for `NewMessage` type of push notifications + +**Flex** +- Adding `flex_insights_hr` object to Flex Configuration + +**Numbers** +- Add API endpoint for Bundle ReplaceItems resource +- Add API endpoint for Bundle Copies resource + +**Serverless** +- Add domain_base field to Service response + +**Taskrouter** +- Add `If-Match` Header based on ETag for Worker Delete **(breaking change)** +- Add `If-Match` Header based on Etag for Reservation Update +- Add `If-Match` Header based on ETag for Worker Update +- Add `If-Match` Header based on ETag for Worker Delete +- Add `ETag` as Response Header to Worker + +**Trunking** +- Added `transfer_caller_id` property on Trunks. + +**Verify** +- Document new pilot `whatsapp` channel. + + +[2021-09-22] Version 8.19.2 +--------------------------- +**Events** +- Add segment sink + +**Messaging** +- Add post_approval_required attribute in GET us_app_to_person_usecase api response +- Add Identity Status, Russell 3000, Tax Exempt Status and Should Skip SecVet fields for Brand Registrations +- Add Should Skip Secondary Vetting optional flag parameter to create Brand API + + +[2021-09-08] Version 8.19.1 +--------------------------- +**Library - Fix** +- [PR #644](https://github.com/twilio/twilio-java/pull/644): deploy issues. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! + +**Api** +- Revert adding `siprec` resource +- Add `siprec` resource + +**Messaging** +- Add 'mock' as an optional field to brand_registration api +- Add 'mock' as an optional field to us_app_to_person api +- Adds more Use Cases in us_app_to_person_usecase api transaction and updates us_app_to_person_usecase docs + +**Verify** +- Verify List Templates API endpoint added. + + +[2021-08-25] Version 8.19.0 +--------------------------- +**Library - Chore** +- [PR #641](https://github.com/twilio/twilio-java/pull/641): integrate with sonarcloud. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! + +**Api** +- Add Programmabled Voice SIP Refer call transfers (`calls-transfers`) to usage records +- Add Flex Voice Usage category (`flex-usage`) to usage records +- Corrected the `price`, `call_sid_to_coach`, and `uri` data types for Conference, Participant, and Recording **(breaking change)** +- Made documentation for property `time_limit` in the call api public. **(breaking change)** +- Added `domain_sid` in sip_credential_list_mapping and sip_ip_access_control_list_mapping APIs **(breaking change)** + +**Conversations** +- Add `Order` query parameter to Message resource read operation + +**Insights** +- Added `partial` to enum processing_state_request +- Added abnormal session filter in Call Summaries +- Added new endpoint to fetch Call Summaries + +**Messaging** +- Add brand_registration_sid as an optional query param for us_app_to_person_usecase api +- Add brand_type field to a2p brand_registration api +- Revert brand registration api update to add brand_type field +- Add brand_type field to a2p brand_registration api + +**Pricing** +- add trunking_numbers resource (v2) +- add trunking_country resource (v2) + +**Taskrouter** +- Add `X-Rate-Limit-Limit`, `X-Rate-Limit-Remaining`, and `X-Rate-Limit-Config` as Response Headers to all TaskRouter endpoints + +**Verify** +- Changed to private beta the `TemplateSid` optional parameter on Verification creation. +- Added the optional parameter `Order` to the list Challenges endpoint to define the list order. +- Add `TemplateSid` optional parameter on Verification creation. +- Include `whatsapp` as a channel type in the verifications API. + + +[2021-07-28] Version 8.18.0 +--------------------------- +**Library - Feature** +- [PR #640](https://github.com/twilio/twilio-java/pull/640): add new constructor to ValidationClient. Thanks to [@sullis](https://github.com/sullis)! + +**Conversations** +- Expose ParticipantConversations resource + +**Taskrouter** +- Adding `links` to the activity resource + +**Verify** +- Added a `Version` to Verify Factors `Webhooks` to add new fields without breaking old Webhooks. + + +[2021-07-14] Version 8.17.0 +--------------------------- +**Conversations** +- Changed `last_read_message_index` and `unread_messages_count` type in User Conversation's resource **(breaking change)** +- Expose UserConversations resource + +**Messaging** +- Add brand_score field to brand registration responses + + +[2021-06-30] Version 8.16.0 +--------------------------- +**Conversations** +- Read-only Conversation Email Binding property `binding` + +**Supersim** +- Add Billing Period resource for the Super Sim Pilot +- Add List endpoint to Billing Period resource for Super Sim Pilot +- Add Fetch endpoint to Billing Period resource for Super Sim Pilot + +**Taskrouter** +- Update `transcribe` & `transcription_configuration` form params in Reservation update endpoint to have private visibility **(breaking change)** +- Add `transcribe` & `transcription_configuration` form params to Reservation update endpoint + +**Twiml** +- Add `modify` event to `statusCallbackEvent` for ``. + + +[2021-06-16] Version 8.15.0 +--------------------------- +**Library - Chore** +- [PR #637](https://github.com/twilio/twilio-java/pull/637): archunit 0.19.0. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Update `status` enum for Messages to include 'canceled' +- Update `update_status` enum for Messages to include 'canceled' + +**Trusthub** +- Corrected the sid for policy sid in customer_profile_evaluation.json and trust_product_evaluation.json **(breaking change)** + + +[2021-06-02] Version 8.14.0 +--------------------------- +**Library - Feature** +- [PR #636](https://github.com/twilio/twilio-java/pull/636): Update WorkflowRuleTarget to support Known Agent Routing. Thanks to [@akallimani](https://github.com/akallimani)! + +**Library - Chore** +- [PR #634](https://github.com/twilio/twilio-java/pull/634): equalsverifier 3.6.1. Thanks to [@sullis](https://github.com/sullis)! + +**Events** +- join Sinks and Subscriptions service + +**Verify** +- Improved the documentation of `challenge` adding the maximum and minimum expected lengths of some fields. +- Improve documentation regarding `notification` by updating the documentation of the field `ttl`. + + +[2021-05-19] Version 8.13.0 +--------------------------- +**Events** +- add query param to return types filtered by Schema Id +- Add query param to return sinks filtered by status +- Add query param to return sinks used/not used by a subscription + +**Messaging** +- Add fetch and delete instance endpoints to us_app_to_person api **(breaking change)** +- Remove delete list endpoint from us_app_to_person api **(breaking change)** +- Update read list endpoint to return a list of us_app_to_person compliance objects **(breaking change)** +- Add `sid` field to Preregistered US App To Person response + +**Supersim** +- Mark `unique_name` in Sim, Fleet, NAP resources as not PII + +**Video** +- [Composer] GA maturity level + + +[2021-05-05] Version 8.12.0 +--------------------------- +**Library - Feature** +- [PR #559](https://github.com/twilio/twilio-java/pull/559): allow conference participant to be any endpoint. Thanks to [@JaymoKang](https://github.com/JaymoKang)! + +**Library - Fix** +- [PR #632](https://github.com/twilio/twilio-java/pull/632): log correct URL in TwilioRestClient. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Corrected the data types for feedback summary fields **(breaking change)** +- Update the conference participant create `from` and `to` param to be endpoint type for supporting client identifier and sip address + +**Bulkexports** +- promoting API maturity to GA + +**Events** +- Add endpoint to update description in sink +- Remove beta-feature account flag + +**Messaging** +- Update `status` field in us_app_to_person api to `campaign_status` **(breaking change)** + +**Verify** +- Improve documentation regarding `push` factor and include extra information about `totp` factor. + + +[2021-04-21] Version 8.11.0 +--------------------------- +**Library - Chore** +- [PR #631](https://github.com/twilio/twilio-java/pull/631): protected TwilioRestClient constructor. Thanks to [@bcanseco](https://github.com/bcanseco)! + +**Api** +- Revert Update the conference participant create `from` and `to` param to be endpoint type for supporting client identifier and sip address +- Update the conference participant create `from` and `to` param to be endpoint type for supporting client identifier and sip address + +**Bulkexports** +- moving enum to doc root for auto generating documentation +- adding status enum and default output properties + +**Events** +- Change schema_versions prop and key to versions **(breaking change)** + +**Messaging** +- Add `use_inbound_webhook_on_number` field in Service API for fetch, create, update, read + +**Taskrouter** +- Add `If-Match` Header based on ETag for Task Delete + +**Verify** +- Add `AuthPayload` parameter to support verifying a `Challenge` upon creation. This is only supported for `totp` factors. +- Add support to resend the notifications of a `Challenge`. This is only supported for `push` factors. + +**Twiml** +- Add Polly Neural voices. + + +[2021-04-07] Version 8.10.0 +--------------------------- +**Library - Fix** +- [PR #629](https://github.com/twilio/twilio-java/pull/629): handle case where XML transformer attributes are not supported. Thanks to [@codylerum](https://github.com/codylerum)! + +**Api** +- Added `announcement` event to conference status callback events +- Removed optional property `time_limit` in the call create request. **(breaking change)** +- Added optional parameter `CallToken` for create calls api +- Add optional property `time_limit` in the call create request. + +**Bulkexports** +- adding two new fields with job api queue_position and estimated_completion_time + +**Events** +- Add new endpoints to manage subscribed_events in subscriptions + +**Messaging** +- Add rate_limits field to Messaging Services US App To Person API +- Add usecase field in Service API for fetch, create, update, read +- Add us app to person api and us app to person usecase api as dependents in service +- Add us_app_to_person_registered field in service api for fetch, read, create, update +- Add us app to person api +- Add us app to person usecase api +- Add A2P external campaign api +- Add Usecases API + +**Numbers** +- Remove feature flags for RegulatoryCompliance endpoints + +**Supersim** +- Add Create endpoint to Sims resource +- Add SmsCommands resource +- Add fields `SmsCommandsUrl`, `SmsCommandsMethod` and `SmsCommandsEnabled` to a Fleet resource + +**Taskrouter** +- Add `If-Match` Header based on ETag for Task Update +- Add `ETag` as Response Headers to Tasks and Reservations + +**Verify** +- The `Binding` field is now returned when creating a `Factor`. This value won't be returned for other endpoints. + +**Video** +- [Rooms] max_concurrent_published_tracks has got GA maturity +- Recording rule beta flag **(breaking change)** +- [Rooms] Add RecordingRules param to Rooms + +**Twiml** +- Add `announcement` event to `statusCallbackEvent` for ``. + + +[2021-03-15] Version 8.9.0 +-------------------------- +**Library - Fix** +- [PR #625](https://github.com/twilio/twilio-java/pull/625): date time conversion to String. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Library - Chore** +- [PR #624](https://github.com/twilio/twilio-java/pull/624): Enable maven depedency caching for travis. Thanks to [@Taher-Ghaleb](https://github.com/Taher-Ghaleb)! +- [PR #623](https://github.com/twilio/twilio-java/pull/623): protect against XML external entity injection. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Events** +- Set maturity to beta + +**Messaging** +- Adjust A2P brand registration status enum **(breaking change)** + +**Studio** +- Remove internal safeguards for Studio V2 API usage now that it's GA + +**Verify** +- Add support for creating and verifying totp factors. Support for totp factors is behind the `api.verify.totp` beta feature. + +**Twiml** +- Add support for `` noun + + +[2021-02-24] Version 8.8.0 +-------------------------- +**Library - Chore** +- [PR #622](https://github.com/twilio/twilio-java/pull/622): bump dependencies. Thanks to [@sullis](https://github.com/sullis)! +- [PR #621](https://github.com/twilio/twilio-java/pull/621): update jackson dependency. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Events** +- Update description of types in the create sink resource + +**Messaging** +- Add WA template header and footer +- Remove A2P campaign and use cases API **(breaking change)** +- Add number_registration_status field to read and fetch campaign responses + +**Trusthub** +- Make all resources public + +**Verify** +- Verify List Attempts API endpoints added. + + +[2021-02-11] Version 8.7.0 +-------------------------- +**Library - Chore** +- [PR #617](https://github.com/twilio/twilio-java/pull/617): archunit 0.16.0. Thanks to [@sullis](https://github.com/sullis)! +- [PR #618](https://github.com/twilio/twilio-java/pull/618): disallow Log4j. Thanks to [@sullis](https://github.com/sullis)! +- [PR #616](https://github.com/twilio/twilio-java/pull/616): equalsverifier 3.5.2. Thanks to [@sullis](https://github.com/sullis)! + +**Library - Fix** +- [PR #620](https://github.com/twilio/twilio-java/pull/620): temporarily remove log test. Thanks to [@thinkingserious](https://github.com/thinkingserious)! +- [PR #619](https://github.com/twilio/twilio-java/pull/619): no longer using log4j test config. Thanks to [@thinkingserious](https://github.com/thinkingserious)! +- [PR #610](https://github.com/twilio/twilio-java/pull/610): switch from log4j to SLF4J. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Revert change that conference participant create `from` and `to` param to be endpoint type for supporting client identifier and sip address +- Update the conference participant create `from` and `to` param to be endpoint type for supporting client identifier and sip address + +**Events** +- Documentation should state that no fields are PII + +**Flex** +- Adding `notifications` and `markdown` to Flex Configuration + +**Messaging** +- Add A2P use cases API +- Add Brand Registrations API +- Add Campaigns API + +**Serverless** +- Add runtime field to Build response and as an optional parameter to the Build create endpoint. +- Add @twilio/runtime-handler dependency to Build response example. + +**Sync** +- Remove If-Match header for Document **(breaking change)** + +**Twiml** +- Add `refer_url` and `refer_method` to `Dial`. + + +[2021-01-27] Version 8.6.1 +-------------------------- +**Studio** +- Studio V2 API is now GA + +**Supersim** +- Allow updating `CommandsUrl` and `CommandsMethod` on a Fleet + +**Twiml** +- Add `status_callback` and `status_callback_method` to `Stream`. + + +[2021-01-13] Version 8.6.0 +-------------------------- +**Api** +- Add 'Electric Imp v1 Usage' to usage categories + +**Conversations** +- Changed `last_read_message_index` type in Participant's resource **(breaking change)** + +**Insights** +- Added `created_time` to call summary. + +**Sync** +- Remove HideExpired query parameter for filtering Sync Documents with expired **(breaking change)** + +**Video** +- [Rooms] Expose maxConcurrentPublishedTracks property in Room resource + + +[2020-12-16] Version 8.5.1 +-------------------------- +**Api** +- Updated `call_event` default_output_properties to request and response. + +**Conversations** +- Added `last_read_message_index` and `last_read_timestamp` to Participant's resource update operation +- Added `is_notifiable` and `is_online` to User's resource +- Added `reachability_enabled` parameters to update method for Conversation Service Configuration resource + +**Messaging** +- Added WA template quick reply, URL, and phone number buttons + +**Twiml** +- Add `sequential` to `Dial`. + + +[2020-12-08] Version 8.5.0 +-------------------------- +**Library - Chore** +- [PR #609](https://github.com/twilio/twilio-java/pull/609): [Snyk] Security upgrade org.apache.httpcomponents:httpclient from 4.5.12 to 4.5.13. Thanks to [@snyk-bot](https://github.com/snyk-bot)! + +**Api** +- Added optional `RecordingTrack` parameter for create calls, create participants, and create call recordings +- Removed deprecated Programmable Chat usage record categories **(breaking change)** + +**Twiml** +- Add `recordingTrack` to `Dial`. + + +[2020-12-02] Version 8.4.0 +-------------------------- +**Library - Feature** +- [PR #606](https://github.com/twilio/twilio-java/pull/606): add http logging for Java. Thanks to [@JenniferMah](https://github.com/JenniferMah)! +- [PR #602](https://github.com/twilio/twilio-java/pull/602): Regional support for access token. Thanks to [@charliesantos](https://github.com/charliesantos)! + +**Api** +- Remove `RecordingTrack` parameter for create calls, create participants, and create call recordings **(breaking change)** +- Added `RecordingTrack` parameter for create calls and create call recordings +- Add optional property `recording_track` in the participant create request + +**Lookups** +- Changed `caller_name` and `carrier` properties type to object **(breaking change)** + +**Trunking** +- Added dual channel recording options for Trunks. + +**Twiml** +- Add `jitterBufferSize` and `participantLabel` to `Conference`. + + +[2020-11-18] Version 8.3.0 +-------------------------- +**Api** +- Add new call events resource - GET /2010-04-01/Accounts/{account_sid}/Calls/{call_sid}/Events.json + +**Conversations** +- Fixed default response property issue for Service Notifications Configuration + +**Insights** +- Removing call_sid from participant summary. **(breaking change)** + +**Serverless** +- Allow Service unique name to be used in path (in place of SID) in Service update request + +**Sync** +- Added HideExpired query parameter for filtering Sync Documents with expired + +**Verify** +- Challenge `Details` and `HiddenDetails` properties are now marked as `PII` +- Challenge `expiration_date` attribute updated to set a default value of five (5) minutes and to allow max dates of one (1) hour after creation. +- Entity `identity` attribute updated to allow values between 8 and 64 characters. +- Verify Service frinedly_name attribute updated from 64 max lenght to 30 characters. + + +[2020-11-05] Version 8.2.0 +-------------------------- +**Api** +- Added `verify-push` to `usage_record` API + +**Bulkexports** +- When creating a custom export the StartDay, EndDay, and FriendlyName fields were required but this was not reflected in the API documentation. The API itself failed the request without these fields. **(breaking change)** +- Added property descriptions for Custom Export create method +- Clarified WebhookUrl and WebhookMethod must be provided together for Custom Export + +**Insights** +- Added video room and participant summary apis. + +**Ip_messaging** +- Create separate definition for ip-messaging +- Restore v2 endpoints for ip-messaging + +**Verify** +- Verify Push madurity were updated from `preview` to `beta` +- `twilio_sandbox_mode` header was removed from Verify Push resources **(breaking change)** + +**Video** +- [Rooms] Add Recording Rules API + + +[2020-10-14] Version 8.1.0 +-------------------------- +**Library - Feature** +- [PR #573](https://github.com/twilio/twilio-java/pull/573): Add RecordingRule and RecordingRulesUpdate. Thanks to [@FMV1491](https://github.com/FMV1491)! + +**Library - Chore** +- [PR #598](https://github.com/twilio/twilio-java/pull/598): bump junit from 4.13 to 4.13.1. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #591](https://github.com/twilio/twilio-java/pull/591): upgrade Jackson to 2.11.3. Thanks to [@sullis](https://github.com/sullis)! + +**Library - Fix** +- [PR #596](https://github.com/twilio/twilio-java/pull/596): drop reflective access warnings to java.time.* classes. Thanks to [@mjg123](https://github.com/mjg123)! +- [PR #595](https://github.com/twilio/twilio-java/pull/595): serialize ZonedDateTime parameters to ISO-8601. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Test** +- [PR #594](https://github.com/twilio/twilio-java/pull/594): change RequestTest to use flexapi instead of ip-messaging. Thanks to [@mgmuscari](https://github.com/mgmuscari)! +- [PR #590](https://github.com/twilio/twilio-java/pull/590): use ArchUnit to detect JodaTime usage. Thanks to [@sullis](https://github.com/sullis)! + +**Ai** +- Add `Annotation Project` and `Annotation Task` endpoints +- Add `Primitives` endpoints +- Add `meta.total` to the search endpoint + +**Conversations** +- Mutable Conversation Unique Names + +**Insights** +- Added `trust` to summary. + +**Preview** +- Simplified `Channels` resource. The path is now `/BrandedChannels/branded_channel_sid/Channels` **(breaking change)** + +**Verify** +- Changed parameters (`config` and `binding`) to use dot notation instead of JSON string (e.i. Before: `binding={"alg":"ES256", "public_key": "xxx..."}`, Now: `Binding.Alg="ES256"`, `Binding.PublicKey="xxx..."`). **(breaking change)** +- Changed parameters (`details` and `hidden_details`) to use dot notation instead of JSON string (e.i. Before: `details={"message":"Test message", "fields": "[{\"label\": \"Action 1\", \"value\":\"value 1\"}]"}`, Now: `details.Message="Test message"`, `Details.Fields=["{\"label\": \"Action 1\", \"value\":\"value 1\"}"]`). **(breaking change)** +- Removed `notify_service_sid` from `push` service configuration object. Add `Push.IncludeDate`, `Push.ApnCredentialSid` and `Push.FcmCredentialSid` service configuration parameters. **(breaking change)** + + +[2020-09-28] Version 8.0.0 +-------------------------- +**Note:** This release contains breaking changes, check our [upgrade guide](./UPGRADE.md#2020-09-28-7xx-to-8xx) for detailed migration notes. + +**Library - Chore** +- [PR #584](https://github.com/twilio/twilio-java/pull/584): remove Guava Range(). Thanks to [@thinkingserious](https://github.com/thinkingserious)! **(breaking change)** +- [PR #585](https://github.com/twilio/twilio-java/pull/585): finish dropping Guava 'MoreObjects' usage. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #572](https://github.com/twilio/twilio-java/pull/572): remove joda-time dependency. Thanks to [@thinkingserious](https://github.com/thinkingserious)! **(breaking change)** +- [PR #574](https://github.com/twilio/twilio-java/pull/574): remove guava functional interfaces. Thanks to [@thinkingserious](https://github.com/thinkingserious)! +- [PR #576](https://github.com/twilio/twilio-java/pull/576): replace Guava toString(). Thanks to [@thinkingserious](https://github.com/thinkingserious)! +- [PR #575](https://github.com/twilio/twilio-java/pull/575): replace guava concurrency, hashing, and charstreams. Thanks to [@childish-sambino](https://github.com/childish-sambino)! **(breaking change)** +- [PR #578](https://github.com/twilio/twilio-java/pull/578): remove deprecated twiml methods. Thanks to [@eshanholtz](https://github.com/eshanholtz)! **(breaking change)** + +**Library - Feature** +- [PR #588](https://github.com/twilio/twilio-java/pull/588): make static 'Twilio' access synchronized. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #586](https://github.com/twilio/twilio-java/pull/586): add support for environment variables. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Fix** +- [PR #587](https://github.com/twilio/twilio-java/pull/587): replace ICE Server URL properties with String types. Thanks to [@childish-sambino](https://github.com/childish-sambino)! **(breaking change)** + +**Library - Docs** +- [PR #579](https://github.com/twilio/twilio-java/pull/579): Remove Java7 from supported languages and add upgrade guide. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Api** +- Add optional property `call_reason` in the participant create request +- Make sip-domain-service endpoints available in stage-au1 and prod-au1 + +**Messaging** +- Removed beta feature gate from WhatsApp Templates API + +**Serverless** +- Add Build Status endpoint + +**Video** +- [Rooms] Add new room type "go" for WebRTC Go + + +[2020-09-21] Version 7.55.3 +--------------------------- +**Library - Fix** +- [PR #583](https://github.com/twilio/twilio-java/pull/583): allow API redirect responses. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #571](https://github.com/twilio/twilio-java/pull/571): paging breaks with + sign on phone number. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Library - Chore** +- [PR #582](https://github.com/twilio/twilio-java/pull/582): upgrade jackson and HTTP dependencies. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Docs** +- [PR #581](https://github.com/twilio/twilio-java/pull/581): convert markdown links to href formatted links. Thanks to [@JenniferMah](https://github.com/JenniferMah)! + +**Accounts** +- Add Auth Token rotation API + +**Conversations** +- Change resource path for Webhook Configuration + +**Events** +- Schemas API get all Schemas names and versions + + +[2020-09-16] Version 7.55.2 +--------------------------- +**Conversations** +- Expose Configuration and Service Configuration resources +- Add Unique Name support for Conversations +- Add Services Push Notification resource +- Add Service scoped Conversation resources +- Support Identity in Users resource endpoint + +**Messaging** +- GA Deactivation List API +- Add domain cert API's(fetch, update, create) for link tracker + +**Numbers** +- Add API endpoint for Supporting Document deletion + +**Proxy** +- Updated usage of FailOnParticipantConflict param to apply only to accounts with ProxyAllowParticipantConflict account flag + +**Supersim** +- Add `AccountSid` parameter to Sim resource update request +- Add `ready` status as an available status for a Sim resource + + +[2020-09-02] Version 7.55.1 +--------------------------- +**Ai** +- Initial release + +**Bulkexports** +- removing public beta feature flag from BulkExports Jobs API + +**Messaging** +- Add Deactivation List API +- Added page token parameter for fetch in WhatsApp Templates API + +**Numbers** +- Add API endpoint for End User deletion + +**Routes** +- Add Resource Route Configurations API +- Add Route Configurations API +- Initial Release + +**Trunking** +- Added `transfer_mode` property on Trunks. + + +[2020-08-19] Version 7.55.0 +--------------------------- +**Library - Feature** +- [PR #568](https://github.com/twilio/twilio-java/pull/568): add support for custom HTTP headers. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Library - Chore** +- [PR #567](https://github.com/twilio/twilio-java/pull/567): drop some of the Guava usage which is easily replaced. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #565](https://github.com/twilio/twilio-java/pull/565): update GitHub branch references to use HEAD. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Conversations** +- Allow Identity addition to Participants + +**Events** +- Sinks API Get all Sinks + +**Proxy** +- Clarified usage of FailOnParticipantConflict param as experimental +- Add FailOnParticipantConflict param to Proxy Session create and Proxy Participant create + +**Supersim** +- Add fleet, network, and isoCountryCode to the UsageRecords resource +- Change sort order of UsageRecords from ascending to descending with respect to start time field, records are now returned newest to oldest + +**Wireless** +- Removed `Start` and `End` parameters from the Data Sessions list endpoint. **(breaking change)** + + +[2020-08-05] Version 7.54.2 +--------------------------- +**Messaging** +- Add rejection reason support to WhatsApp API +- Removed status parameter for create and update in WhatsApp Templates API + +**Proxy** +- Add FailOnParticipantConflict param to Proxy Session update + +**Verify** +- Add `CustomFriendlyName` optional parameter on Verification creation. +- Changes in `Challenge` resource to update documentation of both `details` and `hidden_details` properties. + + +[2020-07-22] Version 7.54.1 +--------------------------- +**Library - Fix** +- [PR #558](https://github.com/twilio/twilio-java/pull/558): encode path parameters. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Api** +- Add optional Click Tracking and Scheduling parameters to Create action of Message resource + +**Supersim** +- Add callback_url and callback_method parameters to Sim resource update request + + +[2020-07-08] Version 7.54.0 +--------------------------- +**Library - Feature** +- [PR #555](https://github.com/twilio/twilio-java/pull/555): add fax capability to deserialized phone number capabilities. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #553](https://github.com/twilio/twilio-java/pull/553): include API response headers in 'Last Response'. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Chore** +- [PR #554](https://github.com/twilio/twilio-java/pull/554): bump archunit from 0.13.0 to 0.14.1. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #550](https://github.com/twilio/twilio-java/pull/550): bump cobertura-maven-plugin from 2.2 to 2.7. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #551](https://github.com/twilio/twilio-java/pull/551): bump maven-assembly-plugin from 2.3 to 3.3.0. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #543](https://github.com/twilio/twilio-java/pull/543): bump joda-time from 2.5 to 2.10.6. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #545](https://github.com/twilio/twilio-java/pull/545): bump maven-surefire-plugin from 2.20 to 2.22.2. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #546](https://github.com/twilio/twilio-java/pull/546): bump spotbugs-maven-plugin from 3.1.12 to 4.0.4. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #547](https://github.com/twilio/twilio-java/pull/547): bump maven-checkstyle-plugin from 2.17 to 3.1.1. Thanks to [@dependabot](https://github.com/dependabot)! + +**Conversations** +- Allow Address updates for Participants +- Message delivery receipts + +**Events** +- Add account_sid to subscription and subscribed_events resources + +**Flex** +- Changed `wfm_integrations` Flex Configuration key to private **(breaking change)** + +**Messaging** +- Add error states to WhatsApp Sender status with failed reason **(breaking change)** +- Delete WhatsApp Template API +- Update WhatsApp Template API +- Add WhatsApp Template Get Api (fetch and read) + +**Numbers** +- Add `valid_until` in the Bundles resource +- Add API for Bundle deletion + +**Verify** +- Removed support for `sms`, `totp` and `app-push` factor types in Verify push **(breaking change)** + + +[2020-06-24] Version 7.53.0 +--------------------------- +**Library - Chore** +- [PR #535](https://github.com/twilio/twilio-java/pull/535): bump maven-javadoc-plugin from 2.10.4 to 3.2.0. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #542](https://github.com/twilio/twilio-java/pull/542): bump guava from 28.0-android to 29.0-android. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #540](https://github.com/twilio/twilio-java/pull/540): bump equalsverifier from 3.1.12 to 3.4.1. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #541](https://github.com/twilio/twilio-java/pull/541): bump junit from 4.11 to 4.13. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #539](https://github.com/twilio/twilio-java/pull/539): bump jjwt.version from 0.10.7 to 0.11.2. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #536](https://github.com/twilio/twilio-java/pull/536): bump jaxb-api from 2.2 to 2.3.1. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #538](https://github.com/twilio/twilio-java/pull/538): bump maven-source-plugin from 3.0.1 to 3.2.1. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #534](https://github.com/twilio/twilio-java/pull/534): add Dependabot. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Added optional `JitterBufferSize` parameter for creating conference participant +- Added optional `label` property for conference participants +- Added optional parameter `caller_id` for creating conference participant endpoint. + +**Autopilot** +- Remove Export resource from Autopilot Assistant + +**Conversations** +- Expose Conversation timers + +**Monitor** +- Update start/end date filter params to support date-or-time format **(breaking change)** + +**Numbers** +- Add `provisionally-approved` as a Supporting Document status + +**Preview** +- Removed `Authy` resources. **(breaking change)** + +**Supersim** +- Add ready state to the allowed transitions in the sim update call behind the feature flag supersim.ready-state.v1 + +**Verify** +- Webhook resources added to Verify services and put behind the `api.verify.push` beta feature + +**Twiml** +- Add more supported locales for the `Gather` verb. + + +[2020-06-10] Version 7.52.0 +--------------------------- +**Library - Docs** +- [PR #533](https://github.com/twilio/twilio-java/pull/533): link to custom HTTP client instructions. Thanks to [@thinkingserious](https://github.com/thinkingserious)! +- [PR #532](https://github.com/twilio/twilio-java/pull/532): link to descriptive exception types. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Library - Chore** +- [PR #531](https://github.com/twilio/twilio-java/pull/531): drop the region being passed to each request in the REST object. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Feature** +- [PR #530](https://github.com/twilio/twilio-java/pull/530): add regional and edge support. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Api** +- Added `pstnconnectivity` to `usage_record` API + +**Autopilot** +- Add dialogue_sid param to Query list resource + +**Notify** +- delivery_callback_url and delivery_callback_enabled added + +**Numbers** +- Add `provisionally-approved` as a Bundle status + +**Preview** +- `BrandsInformation` endpoint now returns a single `BrandsInformation` +- Deleted phone number required field in the brand phone number endpoint from `kyc-api` +- Removed insights `preview API` from API Definitions **(breaking change)** +- Added `BrandsInformation` endpoint to query brands information stored in KYC + +**Supersim** +- Require a Network Access Profile when creating a Fleet **(breaking change)** + + +[2020-05-27] Version 7.51.0 +--------------------------- +**Library - Fix** +- [PR #529](https://github.com/twilio/twilio-java/pull/529): Fix datetime filter when the DateTime instances have timezone other than UTC. Thanks to [@adrianboimvaser](https://github.com/adrianboimvaser)! + +**Api** +- Added `reason_conference_ended` and `call_sid_ending_conference` to Conference read/fetch/update +- Fixed some examples to use the correct "TK" SID prefix for Trunk resources. + +**Authy** +- Renamed `twilio_authy_sandbox_mode` headers to `twilio_sandbox_mode` **(breaking change)** +- Renamed `Twilio-Authy-*` headers to `Twilio-Veriry-*` **(breaking change)** + +**Flex** +- Adding `flex_service_instance_sid` to Flex Configuration + +**Preview** +- Removed insights preview API from API Definitions **(breaking change)** +- Added `Channels` endpoint to brand a phone number for BrandedCalls + +**Serverless** +- Add Build Sid to Log results + +**Supersim** +- Add Network Access Profile resource Networks subresource +- Allow specifying a Data Limit on Fleets + +**Trunking** +- Fixed some examples to use the correct "TK" SID prefix for Trunk resources. + + +[2020-05-13] Version 7.50.1 +--------------------------- +**Library - Chore** +- [PR #526](https://github.com/twilio/twilio-java/pull/526): bump jackson 2.10.4. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Add optional `emergency_caller_sid` parameter to SIP Domain +- Updated `call_reason` optional property to be treated as PII +- Added optional BYOC Trunk Sid property to Sip Domain API resource + +**Autopilot** +- Add Restore resource to Autopilot Assistant + +**Contacts** +- Added contacts Create API definition + +**Events** +- Subscriptions API initial release + +**Numbers** +- Add Evaluations API + +**Supersim** +- Allow filtering the Fleets resource by Network Access Profile +- Allow assigning a Network Access Profile when creating and updating a Fleet +- Add Network Access Profiles resource + +**Verify** +- Add `CustomCode` optional parameter on Verification creation. +- Add delete action on Service resource. + +**Voice** +- Added endpoints for BYOC trunks, SIP connection policies and source IP mappings + + +[2020-04-29] Version 7.50.0 +--------------------------- +**Library - Feature** +- [PR #524](https://github.com/twilio/twilio-java/pull/524): add error details to rest and api exceptions. Thanks to [@ashish-s](https://github.com/ashish-s)! + +**Preview** +- Added `Dispatch` version to `preview` + +**Studio** +- Reroute Create Execution for V2 to the V2 downstream + +**Supersim** +- Add Networks resource + + +[2020-04-15] Version 7.49.1 +--------------------------- +**Library - Fix** +- [PR #523](https://github.com/twilio/twilio-java/pull/523): adding new constructor. Thanks to [@Salil999](https://github.com/Salil999)! + +**Library - Docs** +- [PR #522](https://github.com/twilio/twilio-java/pull/522): instructions on building your own local .jar. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Library - Chore** +- [PR #521](https://github.com/twilio/twilio-java/pull/521): remove S3 URLs from test data. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Api** +- Updated description for property `call_reason` in the call create request + +**Contacts** +- Added Read, Delete All, and Delete by SID docs +- Initial Release + +**Studio** +- Rename `flow_valid` to `flow_validate` +- Removed `errors` and `warnings` from flows error response and added new property named `details` +- Add Update Execution endpoints to v1 and v2 to end execution via API +- Add new `warnings` attribute v2 flow POST api + +**Twiml** +- Add enhanced attribute to use with `speech_model` for the `Gather` verb + + +[2020-04-01] Version 7.49.0 +--------------------------- +**Library - Fix** +- [PR #520](https://github.com/twilio/twilio-java/pull/520): add exclusions for dependency convergence checks. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Api** +- Add optional 'secure' parameter to SIP Domain + +**Authy** +- Added an endpoint to list the challenges of a factor +- Added optional parameter `Push` when updating a service to send the service level push factor configuration + +**Bulkexports** +- exposing bulk exports (vault/slapchop) API as public beta API + +**Flex** +- Adding `queue_stats_configuration` and `wfm_integrations` to Flex Configuration + +**Serverless** +- Add Function Version Content endpoint +- Allow build_sid to be optional for deployment requests + +**Supersim** +- Remove `deactivated` status for Super SIM which is replaced by `inactive` **(breaking change)** + + +[2020-03-18] Version 7.48.0 +--------------------------- +**Library - Chore** +- [PR #519](https://github.com/twilio/twilio-java/pull/519): upgrade jackson to 2.10.3. Thanks to [@sullis](https://github.com/sullis)! + +**Library - Fix** +- [PR #502](https://github.com/twilio/twilio-java/pull/502): shut down executorService thread automatically to allow the JVM to shut down gracefully. Thanks to [@Salil999](https://github.com/Salil999)! + +**Api** +- Add optional `emergency_calling_enabled` parameter to SIP Domain +- Add optional property `call_reason` in the call create request + +**Authy** +- Added `friendly_name` and `config` as optional params to Factor update +- Added `config` param to Factor creation **(breaking change)** + +**Preview** +- Renamed `SuccessRate` endpoint to `ImpressionsRate` for Branded Calls (fka. Verified by Twilio) **(breaking change)** + + +[2020-03-04] Version 7.47.6 +--------------------------- +**Library - Chore** +- [PR #518](https://github.com/twilio/twilio-java/pull/518): fix JDK Travis failures. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Authy** +- Added the `configuration` property to services to return the service level configurations +- Added optional parameter `Push` when creating a service to send the service level push factor configuration +- Remove FactorStrength support for Factors and Challenges **(breaking change)** + +**Messaging** +- Correct the alpha sender capabilities property type **(breaking change)** + +**Preview** +- Removed `/Devices` register Branded Calls endpoint, as per iOS sample app deprecation **(breaking change)** +- Removed `Twilio-Sandbox-Mode` request header from the Branded Calls endpoints, as not officially supported **(breaking change)** +- Removed `Verify` version from `preview` subdomain in favor to `verify` subdomain. **(breaking change)** + +**Serverless** +- Add UI-Editable field to Services + +**Supersim** +- Add `inactive` status for Super SIM which is an alias for `deactivated` + +**Taskrouter** +- Adding value range to `priority` in task endpoint + +**Verify** +- Fix `SendCodeAttempts` type. It's an array of objects instead of a unique object. **(breaking change)** + + +[2020-02-19] Version 7.47.5 +--------------------------- +**Library - Fix** +- [PR #516](https://github.com/twilio/twilio-java/pull/516): Do not include null values in JWT payloads. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Api** +- Make call create parameters `async_amd`, `async_amd_status_callback`, and `async_amd_status_callback_method` public +- Add `trunk_sid` as an optional field to Call resource fetch/read responses +- Add property `queue_time` to successful response of create, fetch, and update requests for Call +- Add optional parameter `byoc` to conference participant create. + +**Authy** +- Added support for challenges associated to push factors + +**Flex** +- Adding `ui_dependencies` to Flex Configuration + +**Messaging** +- Deprecate Session API **(breaking change)** + +**Numbers** +- Add Regulations API + +**Studio** +- Add Execution and Step endpoints to v2 API +- Add webhook_url to Flow response and add new /TestUsers endpoint to v2 API + +**Taskrouter** +- Adding `longest_relative_task_age_in_queue` and `longest_relative_task_sid_in_queue` to TaskQueue Real Time Statistics API. +- Add `wait_duration_in_queue_until_accepted` aggregations to TaskQueues Cumulative Statistics endpoint +- Add TaskQueueEnteredDate property to Tasks. + +**Video** +- [Composer] Clarification for the composition hooks creation documentation: one source is mandatory, either the `audio_sources` or the `video_layout`, but one of them has to be provided +- [Composer] `audio_sources` type on the composer HTTP POST command, changed from `sid[]` to `string[]` **(breaking change)** +- [Composer] Clarification for the composition creation documentation: one source is mandatory, either the `audio_sources` or the `video_layout`, but one of them has to be provided + + +[2020-02-05] Version 7.47.4 +--------------------------- +**Library - Chore** +- [PR #514](https://github.com/twilio/twilio-java/pull/514): Update jjwt dependency version 0.10.7. Thanks to [@eager](https://github.com/eager)! + +**Library - Test** +- [PR #506](https://github.com/twilio/twilio-java/pull/506): use [equalsverifier] library to verify 'equals' methods. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Making content retention and address retention public +- Update `status` enum for Messages to include 'partially_delivered' + +**Authy** +- Added support for push factors + +**Autopilot** +- Add one new property in Query i.e dialogue_sid + +**Verify** +- Add `SendCodeAttempts` to create verification response. + +**Video** +- Clarification in composition creation documentation: one source is mandatory, either `audio_sources` or `video_layout`, but on of them has to be provided + +**Twiml** +- Add Polly Neural voices. + + +[2020-01-23] Version 7.47.3 +--------------------------- +**Library - Docs** +- [PR #510](https://github.com/twilio/twilio-java/pull/510): baseline all the templated markdown docs. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Library - Chore** +- [PR #509](https://github.com/twilio/twilio-java/pull/509): Upgrade archunit to version 0.13.0. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Add payments public APIs +- Add optional parameter `byoc` to call create request. + +**Flex** +- Updating a Flex Flow `creation_on_message` parameter documentation + +**Preview** +- +- Removed Verify v2 from preview in favor of its own namespace as GA **(breaking change)** + +**Studio** +- Flow definition type update from string to object + +**Verify** +- Add `AppHash` parameter when creating a Verification. +- Add `DoNotShareWarningEnabled` parameter to the Service resource. + +**Twiml** +- Add `track` attribute to siprec noun. +- Add attribute `byoc` to `` + + +[2020-01-08] Version 7.47.2 +--------------------------- +**Library - Chore** +- [PR #508](https://github.com/twilio/twilio-java/pull/508): update jjwt to v0.9.1. Thanks to [@saksham93](https://github.com/saksham93)! +- [PR #507](https://github.com/twilio/twilio-java/pull/507): upgrade jackson to 2.10.2. Thanks to [@sullis](https://github.com/sullis)! + +**Numbers** +- Add Regulatory Compliance CRUD APIs + +**Studio** +- Add parameter validation for Studio v2 Flows API + +**Twiml** +- Add support for `speech_model` to `Gather` verb + + +[2019-12-18] Version 7.47.1 +--------------------------- +**Preview** +- Add `/Insights/SuccessRate` endpoint for Businesses Branded Calls (Verified by Twilio) + +**Studio** +- StudioV2 API in beta + +**Verify** +- Add `MailerSid` property to Verify Service resource. + +**Wireless** +- Added `data_limit_strategy` to Rate Plan resource. + + +[2019-12-12] Version 7.47.0 +--------------------------- +**Library** +- [PR #504](https://github.com/twilio/twilio-java/pull/504): feat: add 'order_by' and 'skip_if' parameters in WorkflowRuleTarget. Thanks to [@nikhil-vk](https://github.com/nikhil-vk)! + +**Api** +- Make `twiml` conditional for create. One of `url`, `twiml`, or `application_sid` is now required. +- Add `bundle_sid` parameter to /IncomingPhoneNumbers API +- Removed discard / obfuscate parameters from ContentRetention, AddressRetention **(breaking change)** + +**Chat** +- Added `last_consumed_message_index` and `last_consumption_timestamp` parameters in update method for UserChannel resource **(breaking change)** + +**Conversations** +- Add Participant SID to Message properties + +**Messaging** +- Fix incorrectly typed capabilities property for ShortCodes. **(breaking change)** + + +[2019-12-04] Version 7.46.0 +--------------------------- +**Library** +- [PR #500](https://github.com/twilio/twilio-java/pull/500): chore: upgrade archunit to version 0.12.0. Thanks to [@sullis](https://github.com/sullis)! +- [PR #499](https://github.com/twilio/twilio-java/pull/499): docs: add supported language versions to README. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #489](https://github.com/twilio/twilio-java/pull/489): chore: upgrade jackson to version 2.10.1. Thanks to [@sullis](https://github.com/sullis)! +- [PR #498](https://github.com/twilio/twilio-java/pull/498): fix: Rename child twiml methods to be the tag name and deprecate old methods. Thanks to [@eshanholtz](https://github.com/eshanholtz)! +- [PR #496](https://github.com/twilio/twilio-java/pull/496): docs: add an example for handling exceptions. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #494](https://github.com/twilio/twilio-java/pull/494): fix: Add URI encoding for phone numbers. Thanks to [@eshanholtz](https://github.com/eshanholtz)! +- [PR #492](https://github.com/twilio/twilio-java/pull/492): fix: add new Twiml type to deal with constructor overloading issue. Thanks to [@craigsdennis](https://github.com/craigsdennis)! +- [PR #491](https://github.com/twilio/twilio-java/pull/491): Allow missing GPG env vars when running on a fork. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #490](https://github.com/twilio/twilio-java/pull/490): docs: add an example using a different HTTP client. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Api** +- Add optional `twiml` parameter for call create + +**Chat** +- Added `delete` method in UserChannel resource + +**Conversations** +- Allow Messaging Service update + +**Taskrouter** +- Support ReEvaluateTasks parameter on Workflow update + +**Twiml** +- Remove unsupported `mixed_track` value from `` **(breaking change)** +- Add missing fax `` optional attributes + + +[2019-11-13] Version 7.45.1 +--------------------------- +**Library** +- [PR #487](https://github.com/twilio/twilio-java/pull/487): Bump jackson-databind from 2.9.9.1 to 2.9.10.1. Thanks to [@dependabot](https://github.com/dependabot)! +- [PR #486](https://github.com/twilio/twilio-java/pull/486): add TLS 1.2 warning. Thanks to [@eshanholtz](https://github.com/eshanholtz)! +- [PR #485](https://github.com/twilio/twilio-java/pull/485): Move generated docs to common location. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #484](https://github.com/twilio/twilio-java/pull/484): Auto-deploy via Travis CI upon tagged commit to main. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Api** +- Make `persistent_action` parameter public +- Add `twiml` optional private parameter for call create + +**Autopilot** +- Add Export resource to Autopilot Assistant. + +**Flex** +- Added Integration.RetryCount attribute to Flex Flow +- Updating a Flex Flow `channel_type` options documentation + +**Insights** +- Added edges to events and metrics +- Added new endpoint definitions for Events and Metrics + +**Messaging** +- **create** support for sender registration +- **fetch** support for fetching a sender +- **update** support for sender verification + +**Supersim** +- Add `Direction` filter parameter to list commands endpoint +- Allow filtering commands list by Sim Unique Name +- Add `Iccid` filter parameter to list sims endpoint + +**Twiml** +- Add support for `` verb + + +[2019-10-31] Version 7.45.0 +--------------------------- +**Api** +- Add new usage categories to the public api `sms-messages-carrierfees` and `mms-messages-carrierfees` + +**Conversations** +- Add ProjectedAddress to Conversations Participant resource + +**Preview** +- Implemented different `Sid` for Current Calls (Verified by Twilio), instead of relying in `Call.Sid` from Voice API team **(breaking change)** + +**Supersim** +- Add List endpoint to Commands resource for Super Sim Pilot +- Add UsageRecords resource for the Super Sim Pilot +- Add List endpoint to UsageRecords resource for the Super Sim Pilot +- Allow assigning a Sim to a Fleet by Fleet SID or Unique Name for Super SIM Pilot +- Add Update endpoint to Fleets resource for Super Sim Pilot +- Add Fetch endpoint to Commands resource for Super Sim Pilot +- Allow filtering the Sims resource List endpoint by Fleet +- Add List endpoint to Fleets resource for Super Sim Pilot + +**Wireless** +- Added `account_sid` to Sim update parameters. + +**Twiml** +- Add new locales and voices for `Say` from Polly + + +[2019-10-16] Version 7.44.0 +--------------------------- +**Library** +- [PR #483](https://github.com/twilio/twilio-java/pull/483): VIDEO-2338 TrackPriority.STANDARD before GA. Thanks to [@innerverse](https://github.com/innerverse)! +- [PR #482](https://github.com/twilio/twilio-java/pull/482): breaking: Correct video composition date and callback types. Thanks to [@childish-sambino](https://github.com/childish-sambino)! **(breaking change)** + +**Api** +- Add new property `attempt` to sms_messages +- Fixed a typo in the documentation for Feedback outcome enum **(breaking change)** +- Update the call price to be optional for deserializing **(breaking change)** + +**Flex** +- Added `JanitorEnabled` attribute to Flex Flow +- Change `features_enabled` Flex Configuration key to private **(breaking change)** + +**Supersim** +- Add Fetch endpoint to Fleets resource for Super Sim Pilot +- Allow assigning a Sim to a Fleet for Super Sim Pilot +- Add Create endpoint to Fleets resource for Super Sim Pilot + +**Twiml** +- Update `` rename "whisper" attribute to "coach" **(breaking change)** + + +[2019-10-02] Version 7.43.1 +--------------------------- +**Library** +- [PR #481](https://github.com/twilio/twilio-java/pull/481): added request validation for urls with and without ports. Thanks to [@eshanholtz](https://github.com/eshanholtz)! + +**Conversations** +- Add media to Conversations Message resource + +**Supersim** +- Add List endpoint to Sims resource for Super Sim Pilot + + +[2019-09-18] Version 7.43.0 +---------------------------- +**Numbers** +- Add v2 of the Identites API + +**Preview** +- Changed authentication method for SDK Trusted Comms endpoints: `/CPS`, `/CurrentCall`, and `/Devices`. Please use `Authorization: Bearer ` **(breaking change)** + +**Voice** +- Add Recordings endpoints + + +[2019-09-04] Version 7.42.0 +---------------------------- +**Library** +- [PR #480](https://github.com/twilio/twilio-java/pull/480): fix Javadoc copyright year. Thanks to [@sullis](https://github.com/sullis)! +- [PR #478](https://github.com/twilio/twilio-java/pull/478): Upgrade maven-source-plugin to 3.1.0. Thanks to [@sullis](https://github.com/sullis)! +- [PR #479](https://github.com/twilio/twilio-java/pull/479): Upgrade maven-javadoc-plugin to 3.1.1. Thanks to [@sullis](https://github.com/sullis)! +- [PR #471](https://github.com/twilio/twilio-java/pull/471): Catch NPE when creating URI. Thanks to [@pulkitsethi](https://github.com/pulkitsethi)! +- [PR #410](https://github.com/twilio/twilio-java/pull/410): Add jsonToMap in converter. Thanks to [@igracia](https://github.com/igracia)! +- [PR #477](https://github.com/twilio/twilio-java/pull/477): ComplianceTest: resources haveOnlyPrivateConstructors(). Thanks to [@sullis](https://github.com/sullis)! +- [PR #476](https://github.com/twilio/twilio-java/pull/476): Upgrade archunit to version 0.11.0. Thanks to [@sullis](https://github.com/sullis)! + +**Api** +- Pass Twiml in call update request + +**Conversations** +- Add attributes to Conversations resources + +**Flex** +- Adding `features_enabled` and `serverless_service_sids` to Flex Configuration + +**Messaging** +- Message API required params updated **(breaking change)** + +**Preview** +- Added support for the optional `CallSid` to `/BrandedCalls` endpoint + + +[2019-08-21] Version 7.41.2 +---------------------------- +**Library** +- [PR #475](https://github.com/twilio/twilio-java/pull/475): Update the Flex domain name to be 'flex-api'. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Conversations** +- Add Chat Conversation SID to conversation default output properties + +**Flex** +- Adding `outbound_call_flows` object to Flex Configuration +- Adding read and fetch to channels API + +**Supersim** +- Add Sims and Commands resources for the Super Sim Pilot + +**Sync** +- Added configuration option for enabling webhooks from REST. + +**Wireless** +- Added `usage_notification_method` and `usage_notification_url` properties to `rate_plan`. + +**Twiml** +- Add support for `ach-debit` transactions in `Pay` verb + + +[2019-08-05] Version 7.41.1 +---------------------------- +**Library** +- [PR #472](https://github.com/twilio/twilio-java/pull/472): add [Sean Sullivan] to authors document. Thanks to [@sullis](https://github.com/sullis)! + +**Preview** +- Added support for the header `Twilio-Sandbox-Mode` to mock all Voice dependencies + +**Twiml** +- Add support for `` noun +- Add support for `` noun +- Create verbs `` and `` + + +[2019-07-31] Version 7.41.0 +---------------------------- +**Library** +- [PR #473](https://github.com/twilio/twilio-java/pull/473): Security vulnerability fix by updating jackson-databind version to 2.9.9.1. Thanks to [@krantitalluri](https://github.com/krantitalluri)! + +**Insights** +- Added `properties` to summary. + +**Preview** +- Added endpoint to brand a call without initiating it, so it can be initiated manually by the Customer + +**Twiml** +- Update `` recording events **(breaking change)** + + +[2019-07-10] Version 7.40.1 +---------------------------- +**Library** +- [PR #459](https://github.com/twilio/twilio-java/pull/459): Update library dependencies. Thanks to [@duttonw](https://github.com/duttonw)! +- [PR #469](https://github.com/twilio/twilio-java/pull/469): Add urls property in ice servers. Thanks to [@FMV1491](https://github.com/FMV1491)! +- [PR #467](https://github.com/twilio/twilio-java/pull/467): Remove VS Code settings. Thanks to [@thinkingserious](https://github.com/thinkingserious)! +- [PR #465](https://github.com/twilio/twilio-java/pull/465): Replace commons codec. Thanks to [@jasonsoooz](https://github.com/jasonsoooz)! +- [PR #466](https://github.com/twilio/twilio-java/pull/466): Ignore local settings. Thanks to [@thinkingserious](https://github.com/thinkingserious)! + +**Api** +- Make `friendly_name` optional for applications create +- Add new property `as_of` date to Usage Record API calls + +**Wireless** +- Added Usage Records resource. + + +[2019-06-26] Version 7.40.0 +---------------------------- +**Library** +- [PR #464](https://github.com/twilio/twilio-java/pull/464): Add [archunit] rules. Thanks to [@sullis](https://github.com/sullis)! + +**Autopilot** +- Adds two new properties in Assistant i.e needs_model_build and development_stage + +**Preview** +- Changed phone numbers from _URL|Path_ to `X-XCNAM-Sensitive` headers **(breaking change)** + +**Verify** +- Add `MessagingConfiguration` resource to verify service + + +[2019-06-12] Version 7.39.0 +---------------------------- +**Autopilot** +- Add Webhooks resource to Autopilot Assistant. + +**Flex** +- Added missing 'custom' type to Flex Flow +- Adding `integrations` to Flex Configuration + +**Insights** +- Added attributes to summary. + +**Messaging** +- Message API Create updated with conditional params **(breaking change)** + +**Proxy** +- Document that Proxy will return a maximum of 100 records for read/list endpoints **(breaking change)** +- Remove non-updatable property parameters for Session update (mode, participants) **(breaking change)** + +**Sync** +- Added reachability debouncing configuration options. + +**Verify** +- Add `RateLimits` and `Buckets` resources to Verify Services +- Add `RateLimits` optional parameter on `Verification` creation. + +**Twiml** +- Fix `` participantIdentity casing + + +[2019-05-29] Version 7.38.1 +---------------------------- +**Library** +- [PR #461](https://github.com/twilio/twilio-java/pull/461): Add SubscribeRule and SubscribeRulesUpdate. Thanks to [@innerverse](https://github.com/innerverse)! +- [PR #456](https://github.com/twilio/twilio-java/pull/456): Code cleanup. Thanks to [@ethanwood17](https://github.com/ethanwood17)! +- [PR #444](https://github.com/twilio/twilio-java/pull/444): maven-compiler-plugin 3.8.0. Thanks to [@sullis](https://github.com/sullis)! +- [PR #460](https://github.com/twilio/twilio-java/pull/460): jackson 2.9.9. Thanks to [@sullis](https://github.com/sullis)! +- [PR #457](https://github.com/twilio/twilio-java/pull/457): Update the call create 'from' param to be endpoint type for client identifier support. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #458](https://github.com/twilio/twilio-java/pull/458): Prefix client identifiers with 'client:' if not already prefixed. Thanks to [@childish-sambino](https://github.com/childish-sambino)! + +**Verify** +- Add `approved` to status enum + + +[2019-05-15] Version 7.38.0 +---------------------------- +**Api** +- Make `method` optional for queue members update + +**Chat** +- Removed `webhook.*.format` update parameters in Service resource from public library visibility in v1 **(breaking change)** + +**Insights** +- Added client metrics as sdk_edge to summary. +- Added optional query param processing_state. + +**Numbers** +- Add addtional metadata fields on a Document +- Add status callback fields and parameters + +**Taskrouter** +- Added `channel_optimized_routing` attribute to task-channel endpoint + +**Video** +- [Rooms] Add Video Subscription API + +**Wireless** +- Added `imei` to Data Session resource. +- Remove `imeisv` from Data Session resource. **(breaking change)** + + +[2019-05-01] Version 7.37.4 +---------------------------- +**Serverless** +- Documentation + +**Wireless** +- Added `imeisv` to Data Session resource. + + +[2019-04-24] Version 7.37.3 +---------------------------- +**Api** +- Add `verified` property to Addresses + +**Numbers** +- Add API for Identites and documents + +**Proxy** +- Add in use count on number instance + + +[2019-04-12] Version 7.37.2 +---------------------------- +**Serverless** +- Serverless scaffolding + + +[2019-04-12] Version 7.37.1 +---------------------------- +**Library** +- PR #454: Add more JDK versions to Travis CI config. Thanks to @childish-sambino! +- PR #453: Bump JMockit version for minimum compatibility with Java 11. Thanks to @childish-sambino! + +**Flex** +- Adding PluginService to Flex Configuration + +**Numbers** +- Add API for Proof of Addresses + +**Proxy** +- Clarify documentation for Service and Session fetch + + +[2019-03-28] Version 7.37.0 +---------------------------- +**Api** +- Remove optional `if_machine` call create parameter from helper libraries **(breaking change)** +- Changed `call_sid` path parameter type on QueueMember fetch and update requests **(breaking change)** + +**Voice** +- changed file names to dialing_permissions prefix **(breaking change)** + +**Wireless** +- Added `ResetStatus` property to Sim resource to allow resetting connectivity via the API. + + +[2019-03-15] Version 7.36.2 +---------------------------- +**Library** +- PR #452: Add Help Center and Support Ticket links to the README. Thanks to @childish-sambino! + +**Api** +- Add `machine_detection_speech_threshold`, `machine_detection_speech_end_threshold`, `machine_detection_silence_timeout` optional params to Call create request + +**Flex** +- Adding Flex Channel Orchestration +- Adding Flex Flow + + +[2019-03-06] Version 7.36.1 +---------------------------- +**Twiml** +- Add `de1` to `` regions + + +[2019-03-01] Version 7.36.0 +---------------------------- +**Api** +- Make conference participant preview parameters public + +**Authy** +- Added support for FactorType and FactorStrength for Factors and Challenges + +**Iam** +- First public release + +**Verify** +- Add endpoint to update/cancel a Verification **(breaking change)** + +**Video** +- [Composer] Make RoomSid mandatory **(breaking change)** +- [Composer] Add `enqueued` state to Composition + +**Twiml** +- Update message body to not be required for TwiML `Dial` noun. + + +[2019-02-15] Version 7.35.1 +---------------------------- +**Library** +- PR #449: Allow POST requests that are void of a body or any params when using the ValidationClient. Thanks to @childish-sambino! + +**Api** +- Add `force_opt_in` optional param to Messages create request +- Add agent conference category to usage records + +**Flex** +- First public release + +**Taskrouter** +- Adding `reject_pending_reservations` to worker update endpoint +- Added `event_date_ms` and `worker_time_in_previous_activity_ms` to Events API response +- Add ability to filter events by TaskChannel + +**Verify** +- Add `EnablePsd2` optional parameter for PSD2 on Service resource creation or update. +- Add `Amount`, `Payee` optional parameters for PSD2. + + +[2019-02-04] Version 7.35.0 +---------------------------- +**Library** +- PR #448: Switch body validator to use hex instead of base64. Thanks to @cjcodes! +- PR #447: Upgrade jackson library to 2.9.8. Thanks to @mbichoffe! + +**Video** +- [Recordings] Add media type filter to list operation +- [Composer] Filter Composition Hook resources by FriendlyName + +**Twiml** +- Update `language` enum for `Gather` to fix language code for Filipino (Philippines) and include additional supported languages **(breaking change)** + + +[2019-01-11] Version 7.34.1 +---------------------------- +**Verify** +- Add `lookup` information in the response when creating a new verification (depends on the LookupEnabled flag being enabled at the service level) +- Add `VerificationSid` optional parameter on Verification check. + + +[2019-01-10] Version 7.34.0 +---------------------------- +**Chat** +- Mark Member attributes as PII + +**Proxy** +- Remove unsupported query parameters **(breaking change)** +- Remove invalid session statuses in doc + + +[2019-01-02] Version 7.33.1 +---------------------------- +**Insights** +- Initial revision. + + +[2018-12-14] Version 7.33.0 +---------------------------- +**Authy** +- Reverted the change to `FactorType` and `FormType`, avoiding conflicts with Helper Libraries reserved words (`type`) **(breaking change)** + +**Proxy** +- Remove incorrect parameter for Session List + +**Studio** +- Support date created filtering on list of executions + +**Taskrouter** +- Adding ability to Create, Modify and Delete Task Channels. + +**Verify** +- Add `SkipSmsToLandlines`, `TtsName`, `DtmfInputRequired` optional parameters on Service resource creation or update. + +**Wireless** +- Added delete action on Command resource. +- Added delete action on Sim resource. + +**Twiml** +- Change `currency` from enum to string for `Pay` **(breaking change)** + + +[2018-11-30] Version 7.32.0 +---------------------------- +**Library** +- PR #445: Bump httpclient httpcore and jackson version. Thanks to @yannieyip! + +**Api** +- Add `interactive_data` optional param to Messages create request + +**Authy** +- Required authentication for `/v1/Forms/{type}` endpoint **(breaking change)** +- Removed `Challenge.reason` to `Challenge.responded_reason` +- Removed `verification_sid` from Challenge responses +- Removed `config` param from the Factor creation +- Replaced all occurrences of `FactorType` and `FormType` in favor of a unified `Type` **(breaking change)** + +**Chat** +- Add Member attributes + +**Preview** +- Removed `Authy` version from `preview` subdomain in favor to `authy` subdomain. **(breaking change)** + +**Verify** +- Add `CustomCode` optional parameter on Verication creation. + + +[2018-11-16] Version 7.31.0 +---------------------------- +**Messaging** +- Session API + +**Twiml** +- Change `master-card` to `mastercard` as `cardType` for `Pay` and `Prompt`, remove attribute `credential_sid` from `Pay` **(breaking change)** + + +[2018-10-28] Version 7.30.0 +---------------------------- +**Api** +- Add new Balance resource: + - url: '/v1/Accounts/{account sid}/Balance' + - supported methods: GET + - returns the balance of the account + +**Proxy** +- Add chat_instance_sid to Service + +**Verify** +- Add `Locale` optional parameter on Verification creation. + + +[2018-10-15] Version 7.29.0 +---------------------------- +**Api** +- Add Verb Transactions category to usage records + +**Twiml** +- Add support for `Pay` verb + + +[2018-10-15] Version 7.28.0 +---------------------------- +**Library** +- PR #440: CLIENT-4598 | Fix null incomingAllow bug and add test. Thanks to @ryan-rowland! + +**Api** +- Add `coaching` and `call_sid_to_coach` to participant properties, create and update requests. + +**Authy** +- Set public library visibility, and added PII stanza +- Dropped support for `FactorType` param given new Factor prefixes **(breaking change)** +- Supported `DELETE` actions for Authy resources +- Move Authy Services resources to `authy` subdomain + +**Autopilot** +- Introduce `autopilot` subdomain with all resources from `preview.understand` + +**Preview** +- Renamed Understand intent to task **(breaking change)** +- Deprecated Authy endpoints from `preview` to `authy` subdomain + +**Taskrouter** +- Allow TaskQueue ReservationActivitySid and AssignmentActivitySid to not be configured for MultiTask Workspaces + +**Verify** +- Add `LookupEnabled` optional parameter on Service resource creation or update. +- Add `SendDigits` optional parameter on Verification creation. +- Add delete action on Service resourse. + +**Twiml** +- Add custom parameters to TwiML `Client` noun and renamed the optional `name` field to `identity`. This is a breaking change in Ruby, and applications will need to transition from `dial.client ''` and `dial.client 'alice'` formats to `dial.client` and `dial.client(identity: alice)` formats. **(breaking change)** + + +[2018-10-04] Version 7.27.0 +---------------------------- +**Library** +- PR #439: Nest IOException inside APIException. Thanks to @yannieyip! + +**Twiml** +- Add `debug` to `Gather` +- Add `participantIdentity` to `Room` + + +[2018-09-28] Version 7.26.0 +---------------------------- +**Api** +- Set `call_sid_to_coach` parameter in participant to be `preview` + +**Preview** +- Renamed response headers for Challenge and Factors Signatures +- Supported `totp` in Authy preview endpoints +- Allowed `latest` in Authy Challenges endpoints + +**Video** +- [Composer] Add Composition Hook resources + +**Voice** +- changed path param name from parent_iso_code to iso_code for highrisk_special_prefixes api **(breaking change)** +- added geo permissions public api + + +[2018-09-20] Version 7.25.0 +---------------------------- +**Preview** +- Add `Form` resource to Authy preview given a `form_type` +- Add Authy initial api-definitions in the 4 main resources: Services, Entities, Factors, Challenges + +**Pricing** +- add voice_numbers resource (v2) + +**Verify** +- Move from preview to beta **(breaking change)** + + +[2018-08-31] Version 7.24.2 +---------------------------- +**Library** +- PR #438: VCORE-3651 Add support for *for* attribute in twiml element. Thanks to @nmahure! + +**Api** +- Add `call_sid_to_coach` parameter to participant create request +- Add `voice_receive_mode` param to IncomingPhoneNumbers create + +**Video** +- [Recordings] Expose `offset` property in resource + + +[2018-08-23] Version 7.24.1 +---------------------------- +**Library** +- PR #436: Create new class, OutboundCallPriceWithOrigin. Thanks to @jbonner89! + +**Chat** +- Add User Channel instance resource + + +[2018-08-17] Version 7.24.0 +---------------------------- +**Library** +- PR #434: add type OutboundPrefixPriceWithOrigin. Thanks to @jbonner89! + +**Api** +- Add Proxy Active Sessions category to usage records + +**Preview** +- Add `Actions` endpoints and remove `ResponseUrl` from assistants on the Understand api + +**Pricing** +- add voice_country resource (v2) + + +[2018-08-09] Version 7.23.1 +---------------------------- +**Preview** +- Add new Intent Statistics endpoint +- Remove `ttl` from Assistants + +**Studio** +- Studio is now GA + + +[2018-08-03] Version 7.23.0 +---------------------------- +**Library** +- PR #426: Tag and push Docker latest image when deploying with TravisCI. Thanks to @jonatasbaldin! + +**Chat** +- Make message From field updatable +- Add REST API webhooks + +**Notify** +- Removing deprecated `segments`, `users`, `segment_memberships`, `user_bindings` classes from helper libraries. **(breaking change)** + +**Twiml** +- Add `Connect` and `Room` for Programmable Video Rooms + + +[2018-07-27] Version 7.22.2 +---------------------------- +**Library** +- PR #433: Clone the headers object and add test for thread safety. Thanks to @cjcodes! + + +[2018-07-26] Version 7.22.1 +---------------------------- +**Api** +- Add support for sip domains to map credential lists for registrations + +**Preview** +- Remove `ttl` from Assistants + +**Proxy** +- Enable setting a proxy number as reserved + +**Video** +- Add `group-small` room type + +**Twiml** +- Add support for SSML lang tag on Say verb + + +[2018-07-16] Version 7.22.0 +---------------------------- +**Library** +- PR #427: Update Response to use Scanner hasNext(). Thanks to @cjcodes! +- PR #424: Add a method for validation of JSON body. Thanks to @cjcodes! + +**Twiml** +- Add support for SSML on Say verb, the message body is changed to be optional **(breaking change)** + + +[2018-07-11] Version 7.21.8 +---------------------------- +**Library** +- PR #425: Add correct JDK version statement to deploy. Thanks to @jonatasbaldin! + +**Api** +- Add `cidr_prefix_length` param to SIP IpAddresses API + +**Studio** +- Add new /Execution endpoints to begin Engagement -> Execution migration + +**Video** +- [Rooms] Allow deletion of individual recordings from a room + + +[2018-07-05] Version 7.21.7 +---------------------------- +**Library** +- PR #418: Add Dockerfile and related changes to build the Docker image. Thanks to @jonatasbaldin! + +**Api** +- Release `Call Recording Controls` feature support in helper libraries +- Add Voice Insights sub-category keys to usage records + + +[2018-06-29] Version 7.21.6 +---------------------------- +**Library** +- PR #421: Tests for mixed TwiML content. Thanks to @ekarson! +- PR #420: Update tests with generated version. Thanks to @mbichoffe! +- PR #419: Allow adding TwiML children with generic tag names. Thanks to @mbichoffe! + + +[2018-06-21] Version 7.21.5 +---------------------------- +**Api** +- Add Fraud Lookups category to usage records + +**Video** +- Allow user to set `ContentDisposition` when obtaining media URLs for Room Recordings and Compositions +- Add Composition Settings resource + + [2018-06-15] Version 7.21.4 ---------------------------- **Library** diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..2f0727ed54 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,73 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at open-source@twilio.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 88e6757a5c..7c3d4050d1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,7 @@ even better than it is today! Here are the guidelines we'd like you to follow: - [Submission Guidelines](#submit) - [Coding Rules](#rules) + ## Code of Conduct Help us keep `twilio-java` open and inclusive. Please be kind to and considerate @@ -21,7 +22,7 @@ it can be. If you have questions about how to use `twilio-java`, please see our [docs][docs-link], and if you don't find the answer there, please contact -[help@twilio.com](mailto:help@twilio.com) with any issues you have. +[Twilio Support ](https://www.twilio.com/help/contact) with any issues you have. ## Found an Issue? @@ -29,12 +30,19 @@ If you find a bug in the source code or a mistake in the documentation, you can help us by submitting [an issue][issue-link]. If the file in which the error exists has this header: ``` -""" -This code was generated by -\ / _ _ _| _ _ - | (_)\/(_)(_|\/| |(/_ v1.0.0 - / / -""" +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - XXXX + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ ``` then it is a generated file and the change will need to be made by us, but submitting an issue will help us track it and keep you up-to-date. If the file @@ -67,10 +75,6 @@ you're working on. For large fixes, please build and test the documentation before submitting the PR to be sure you haven't accidentally introduced layout or formatting issues. -If you want to help improve the docs at -[https://www.twilio.com/docs/libraries/java][docs-link], please contact -[help@twilio.com](mailto:help@twilio.com). - ## Submission Guidelines ### Submitting an Issue @@ -104,7 +108,7 @@ Before you submit your pull request consider the following guidelines: * Make your changes in a new git branch: ```shell - git checkout -b my-fix-branch master + git checkout -b my-fix-branch main ``` * Create your patch, **including appropriate test cases**. @@ -131,7 +135,7 @@ Before you submit your pull request consider the following guidelines: git push origin my-fix-branch ``` -In GitHub, send a pull request to `twilio-java:master`. +In GitHub, send a pull request to `twilio-java:main`. If we suggest changes, then: * Make the required updates. @@ -154,6 +158,5 @@ you are working: * All features or bug fixes **must be tested** by one or more tests. * All classes and methods **must be documented**. -[docs-link]: https://www.twilio.com/docs/libraries/java [issue-link]: https://github.com/twilio/twilio-java/issues/new [github]: https://github.com/twilio/twilio-java \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..9dd07bf5fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM eclipse-temurin:8-jdk + +RUN mkdir /twilio +WORKDIR /twilio + +COPY src ./src +COPY pom.xml . + +RUN apt-get update && apt-get install maven -y +RUN mvn clean install -Dmaven.test.skip=true diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 0c2fa95a08..7360ea61ba 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,9 +1,18 @@ -*Note: These issues are for bugs and feature requests for the helper libraries. -If you need help or support, please email help@twilio.com and one of our experts -will assist you!* + + +### Issue Summary +A summary of the issue and the environment in which it occurs. If suitable, include the steps required to reproduce the bug. Please feel free to include screenshots, screencasts, or code examples. + +### Steps to Reproduce +1. This is the first step +2. This is the second step +3. Further steps, etc. ### Code Snippet ```java @@ -12,15 +21,10 @@ will assist you!* ### Exception/Log ``` - +# paste exception/log here ``` -### Steps to Reproduce -1. -2. -3. - +### Technical details: +* twilio-java version: +* java version: -### Feature Request -_If this is a feature request, make sure you search Issues for an existing -request before creating a new one!_ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..6485c1f845 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (C) 2023, Twilio, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index b2d5d8b8f1..0000000000 --- a/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (C) 2018, Twilio, Inc. - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/Makefile b/Makefile index 133949b06c..9192665431 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ -.PHONY: install analysis test docs +.PHONY: install analysis test test-docker docs install: @java -version || (echo "Java is not installed, please install Java >= 7"; exit 1); mvn clean install + mvn dependency:resolve-plugins analysis: mvn checkstyle:check @@ -10,5 +11,23 @@ analysis: test: mvn test +test-docker: + docker build -t twilio/twilio-java . + docker run twilio/twilio-java mvn test + docs: + rm -rf docs mvn javadoc:javadoc + +API_DEFINITIONS_SHA=$(shell git log --oneline | grep Regenerated | head -n1 | cut -d ' ' -f 5) +CURRENT_TAG=$(shell expr "${GITHUB_TAG}" : ".*-rc.*" >/dev/null && echo "rc" || echo "latest") +docker-build: + docker build -t twilio/twilio-java . + docker tag twilio/twilio-java twilio/twilio-java:${GITHUB_TAG} + docker tag twilio/twilio-java twilio/twilio-java:apidefs-${API_DEFINITIONS_SHA} + docker tag twilio/twilio-java twilio/twilio-java:${CURRENT_TAG} + +docker-push: + docker push twilio/twilio-java:${GITHUB_TAG} + docker push twilio/twilio-java:apidefs-${API_DEFINITIONS_SHA} + docker push twilio/twilio-java:${CURRENT_TAG} diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000..36ac56903d --- /dev/null +++ b/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,31 @@ + + +# Fixes # + +A short description of what this PR does. + +### Checklist +- [x] I acknowledge that all my contributions will be made under the project's license +- [ ] I have made a material change to the repo (functionality, testing, spelling, grammar) +- [ ] I have read the [Contribution Guidelines](https://github.com/twilio/twilio-java/blob/main/CONTRIBUTING.md) and my PR follows them +- [ ] I have titled the PR appropriately +- [ ] I have updated my branch with the main branch +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] I have added the necessary documentation about the functionality in the appropriate .md file +- [ ] I have added inline documentation to the code I modified + +If you have questions, please file a [support ticket](https://twilio.com/help/contact), or create a GitHub Issue in this repository. diff --git a/README.md b/README.md index 31a3fd6deb..ed6e1bbf1b 100644 --- a/README.md +++ b/README.md @@ -1,86 +1,339 @@ # twilio-java -[![Build Status](https://travis-ci.org/twilio/twilio-java.png?branch=master)](https://travis-ci.org/twilio/twilio-java) -[![Maven Central](https://img.shields.io/maven-central/v/com.twilio.sdk/twilio.svg)](http://mvnrepository.com/artifact/com.twilio.sdk/twilio) +[![Tests](https://github.com/twilio/twilio-java/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/twilio/twilio-java/actions/workflows/test-and-deploy.yml) +[![Maven Central](https://img.shields.io/maven-central/v/com.twilio.sdk/twilio.svg)](https://central.sonatype.com/artifact/com.twilio.sdk/twilio) +[![Learn with TwilioQuest](https://img.shields.io/static/v1?label=TwilioQuest&message=Learn%20to%20contribute%21&color=F22F46&labelColor=1f243c&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAASFBMVEUAAAAZGRkcHBwjIyMoKCgAAABgYGBoaGiAgICMjIyzs7PJycnMzMzNzc3UoBfd3d3m5ubqrhfrMEDu7u739/f4vSb/3AD///9tbdyEAAAABXRSTlMAAAAAAMJrBrEAAAKoSURBVHgB7ZrRcuI6EESdyxXGYoNFvMD//+l2bSszRgyUYpFAsXOeiJGmj4NkuWx1Qeh+Ekl9DgEXOBwOx+Px5xyQhDykfgq4wG63MxxaR4ddIkg6Ul3g84vCIcjPBA5gmUMeXESrlukuoK33+33uID8TWeLAdOWsKpJYzwVMB7bOzYSGOciyUlXSn0/ABXTosJ1M1SbypZ4O4MbZuIDMU02PMbauhhHMHXbmebmALIiEbbbbbUrpF1gwE9kFfRNAJaP+FQEXCCTGyJ4ngDrjOFo3jEL5JdqjF/pueR4cCeCGgAtwmuRS6gDwaRiGvu+DMFwSBLTE3+jF8JyuV1okPZ+AC4hDFhCHyHQjdjPHUKFDlHSJkHQXMB3KpSwXNGJPcwwTdZiXlRN0gSp0zpWxNtM0beYE0nRH6QIbO7rawwXaBYz0j78gxjokDuv12gVeUuBD0MDi0OQCLvDaAho4juP1Q/jkAncXqIcCfd+7gAu4QLMACCLxpRsSuQh0igu0C9Svhi7weAGZg50L3IE3cai4IfkNZAC8dfdhsUD3CgKBVC9JE5ABAFzg4QL/taYPAAWrHdYcgfLaIgAXWJ7OV38n1LEF8tt2TH29E+QAoDoO5Ve/LtCQDmKM9kPbvCEBApK+IXzbcSJ0cIGF6e8gpcRhUDogWZ8JnaWjPXc/fNnBBUKRngiHgTUSivSzDRDgHZQOLvBQgf8rRt+VdBUUhwkU6VpJ+xcOwQUqZr+mR0kvBUgv6cB4+37hQAkXqE8PwGisGhJtN4xAHMzrsgvI7rccXqSvKh6jltGlrOHA3Xk1At3LC4QiPdX9/0ndHpGVvTjR4bZA1ypAKgVcwE5vx74ulwIugDt8e/X7JgfkucBMIAr26ndnB4UCLnDOqvteQsHlgX9N4A+c4cW3DXSPbwAAAABJRU5ErkJggg==)](https://twil.io/learn-open-source) +[![libs.tech recommends](https://libs.tech/project/307476/badge.svg)](https://libs.tech/project/307476/twilio-java) -## Recent Update +## Documentation -As of release 7.14.0, Beta and Developer Preview products are now exposed via -the main `twilio-java` artifact. Releases of the `alpha` branch have been -discontinued. +The documentation for the Twilio API can be found [here][apidocs]. -If you were using the `alpha` release line, you should be able to switch back -to the normal release line without issue. +The Java library documentation can be found [here][libdocs]. -If you were using the normal release line, you should now see several new -product lines that were historically hidden from you due to their Beta or -Developer Preview status. Such products are explicitly documented as -Beta/Developer Preview both in the Twilio docs and console, as well as through -in-line code documentation here in the library. +## Versions -# Installing +`twilio-java` uses a modified version of [Semantic Versioning](https://semver.org) for all changes. [See this document](VERSIONS.md) for details. -twilio-java uses Maven. At present the jars *are* available from a public [maven](http://mvnrepository.com/artifact/com.twilio.sdk/twilio) repository. +### TLS 1.2 Requirements + +New accounts and subaccounts are now required to use TLS 1.2 when accessing the REST API. ["Upgrade Required" errors](https://www.twilio.com/docs/api/errors/20426) indicate that TLS 1.0/1.1 is being used. + +### Supported Java Versions + +This library supports the following Java implementations: + +- OpenJDK 8 +- OpenJDK 11 +- OpenJDK 17 +- OpenJDK 21 +- OracleJDK 8 +- OracleJDK 11 +- OracleJDK 17 +- OracleJDK 21 + +For Java 7 support, use `twilio-java` major version `7.X.X`. + +### Beta Annotation + +To indicate that a class or method is in beta and subject to change, we use the `@Beta` annotation. For example: + +```java + +@Beta +public class ClassName { + // Class implementation +} + + +public class ClassName { + @Beta + public void init() { + // Implementation + } +} +``` + +## Installation + +`twilio-java` uses Maven. At present the jars _are_ available from a public [maven](https://central.sonatype.com/artifact/com.twilio.sdk/twilio) repository. Use the following dependency in your project to grab via Maven: - - com.twilio.sdk - twilio - 7.X.X - compile - +```xml + + com.twilio.sdk + twilio + 13.X.X + compile + +``` or Gradle: + ```groovy -compile "com.twilio.sdk:twilio:7.X.X" -```` +implementation "com.twilio.sdk:twilio:13.X.X" +``` If you want to compile it yourself, here's how: - $ git clone git@github.com:twilio/twilio-java - $ cd twilio-java - $ mvn install # Requires maven, download from http://maven.apache.org/download.html +```shell +git clone git@github.com:twilio/twilio-java +cd twilio-java +mvn install # Requires maven, download from https://maven.apache.org/download.html +``` + +If you want to build your own .jar, execute the following from within the cloned directory: + +```shell +mvn package +``` + +If you run into trouble with local tests, use: + +```shell +mvn package -Dmaven.test.skip=true +``` + +### Test your installation -# Quickstart +Try sending yourself an SMS message, like this: -### Send a SMS ```java -String accountSid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account -String authToken = "XXXXXXXX"; // Your Auth Token from www.twilio.com/user/account +import com.twilio.Twilio; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.type.PhoneNumber; -Twilio.init(accountSid, authToken); +public class Example { + + // Find your Account Sid and Token at console.twilio.com + public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + public static final String AUTH_TOKEN = "your_auth_token"; + + public static void main(String[] args) { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + + Message message = Message + .creator( + new PhoneNumber("+15558675309"), + new PhoneNumber("+15017250604"), + "This is the ship that made the Kessel Run in fourteen parsecs?" + ) + .create(); + + System.out.println(message.getSid()); + } +} +``` + +> **Warning** +> It's okay to hardcode your credentials when testing locally, but you should use environment variables to keep them secret before committing any code or deploying to production. Check out [How to Set Environment Variables](https://www.twilio.com/blog/2017/01/how-to-set-environment-variables.html) for more information. + +## Usage + +### Initialize the Client + +```java +import com.twilio.Twilio; +import com.twilio.exception.AuthenticationException; + +public class Example { + + private static final String ACCOUNT_SID = + "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + private static final String AUTH_TOKEN = "your_auth_token"; + + public static void main(String[] args) throws AuthenticationException { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + } +} +``` +### Initialize the client when endpoints does not use basic authentication +The above example shows how to initialize the client in case the endpoints use basic authentication. When the endpoint does not require any authentication, use TwilioNoAuth client instead. +There are endpoints like Organization domain which uses bearer token authentication. Custom Clients needs to be used in such cases and initialize them with the values required for access token generation. + +To bypass the initialization step you can also use a custom token manager implementation. Token manager class should implement the Token interface and call a token generation endpoint of your choice. +Detailed examples [here](https://github.com/twilio/twilio-java/tree/main/examples) + +### Environment Variables + +`twilio-java` supports the credentials, region, and edge values stored in the following environment variables: + +- `TWILIO_ACCOUNT_SID` +- `TWILIO_AUTH_TOKEN` +- `TWILIO_REGION` +- `TWILIO_EDGE` + +If using these variables, the above client initialization can be skipped. + +### Make a Call + +```java +import com.twilio.Twilio; +import com.twilio.rest.api.v2010.account.Call; +import com.twilio.type.PhoneNumber; +import java.net.URI; +import java.net.URISyntaxException; + +public class Example { + + public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + public static final String AUTH_TOKEN = "your_auth_token"; -Message message = Message.creator( - new PhoneNumber("+15558881234"), // To number - new PhoneNumber("+15559994321"), // From number - "Hello world!" // SMS body -).create(); + public static void main(String[] args) throws URISyntaxException { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); -System.out.println(message.getSid()); + Call call = Call + .creator( + new PhoneNumber("+14155551212"), + new PhoneNumber("+15017250604"), + new URI("http://demo.twilio.com/docs/voice.xml") + ) + .create(); + + System.out.println(call.getSid()); + } +} ``` -### Make a call +### Get an existing Call + +```java +import com.twilio.Twilio; +import com.twilio.rest.api.v2010.account.Call; + +public class Example { + + public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + public static final String AUTH_TOKEN = "your_auth_token"; + + public static void main(String[] args) { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + + Call call = Call.fetcher("CA42ed11f93dc08b952027ffbc406d0868").fetch(); + + System.out.println(call.getTo()); + } +} +``` + + + +### OAuth Feature for Twilio APIs +We are introducing Client Credentials Flow-based OAuth 2.0 authentication. + +- API examples [here](https://github.com/twilio/twilio-java/blob/main/examples/PublicOAuthExample.md) +- Organisation API examples [here](https://github.com/twilio/twilio-java/blob/main/examples/OrgsAPIExample.md) + +### Iterate through records + +The library automatically handles paging for you. With the `read` method, you can specify the number of records you want to receive (`limit`) and the maximum size you want each page fetch to be (`pageSize`). The library will then handle the task for you, fetching new pages under the hood as you iterate over the records. + +For more information, view the [auto-generated library docs](https://www.twilio.com/docs/libraries/reference/twilio-java/). + +#### Use the `read` method + ```java -String accountSid = "ACXXXXXX"; // Your Account SID from www.twilio.com/user/account -String authToken = "XXXXXXXX"; // Your Auth Token from www.twilio.com/user/account +import com.twilio.Twilio; +import com.twilio.base.ResourceSet; +import com.twilio.rest.api.v2010.account.Call; + +public class Example { + + public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; + public static final String AUTH_TOKEN = "your_auth_token"; + + public static void main(String[] args) { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + + ResourceSet calls = Call.reader().read(); + + for (Call call : calls) { + System.out.println(call.getDirection()); + } + } +} +``` + +### Specify Region and/or Edge + +To take advantage of Twilio's [Global Infrastructure](https://www.twilio.com/docs/global-infrastructure), specify the target Region and/or Edge for the client: +```java Twilio.init(accountSid, authToken); +Twilio.setRegion("au1"); +Twilio.setEdge("sydney"); +``` + +This will result in the `hostname` transforming from `api.twilio.com` to `api.sydney.au1.twilio.com`. + +To use multiple region within same application, refer [MultiRegionClient.md](https://github.com/twilio/twilio-java/blob/main/examples/MultiRegionClient.md) + +### Enable Debug Logging + +This library uses SLF4J for logging. Consult the [SFL4J documentation](http://slf4j.org/docs.html) for information about logging configuration. + +For example, if you are using `log4j`: -Call call = Call.creator( - new PhoneNumber("+15558881234"), // To number - new PhoneNumber("+15559994321"), // From number +- Make sure you have `log4j-slf4j-impl`, `log4j-core` and `log4j-api` in your `pom.xml` file +- Define the logging level for the Twilio HTTP client in your configuration. For example, in `src/main/resources/log4j2.xml`: - // Read TwiML at this URL when a call connects (hold music) - new URI("http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient") -).create(); + ```xml + + + + + + + + + + + + + + + + + + ``` -System.out.println(call.getSid()); +### Handle Exceptions + +```java +import com.twilio.exception.ApiException; + +try { + Message message = Message.creator( + new PhoneNumber("+15558881234"), // To number + new PhoneNumber("+15559994321"), // From number + "Hello world!" // SMS body + ).create(); + + System.out.println(message.getSid()); +} catch (final ApiException e) { + System.err.println(e); +} ``` -### Generating TwiML -To control phone calls, your application needs to output [TwiML](http://www.twilio.com/docs/api/twiml/). +### Use a Client With PKCV Authentication + +Additional documentation here: https://twilio.com/docs/iam/pkcv/quickstart + +```java +ValidationClient httpClient = new ValidationClient(ACCOUNT_SID, key.getSid(), signingKey.getSid(), pair.getPrivate()); +TwilioRestClient client = new TwilioRestClient.Builder(signingKey.getSid(), signingKey.getSecret()) + .accountSid(ACCOUNT_SID) + .httpClient(httpClient) + .build(); +``` + +### Generate TwiML + +To control phone calls, your application needs to output [TwiML][twiml]. + TwiML in twilio-java now use the builder pattern! + ```java TwiML twiml = new VoiceResponse.Builder() .say(new Say.Builder("Hello World!").build()) @@ -89,24 +342,30 @@ TwiML twiml = new VoiceResponse.Builder() ``` That will output XML that looks like this: -``` + +```xml Hello World! https://api.twilio.com/cowbell.mp3 ``` +### Use a custom HTTP Client + +To use a custom HTTP client with this helper library, please see the [advanced example of how to do so](./advanced-examples/custom-http-client.md). + +## Docker image + +The `Dockerfile` present in this repository and its respective `twilio/twilio-java` Docker image are currently used by Twilio for testing purposes only. -# Documentation +## Getting Help -The documentation for the Twilio API can be found [here.](http://twilio.com/docs/api) +If you need help installing or using the library, please check the [Twilio Support Help Center](https://support.twilio.com) first, and [file a support ticket](https://twilio.com/help/contact) if you don't find an answer to your question. -# Getting help +If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo! -If you need help installing or using the library, please contact Twilio Support -at help@twilio.com first. Twilio's Support staff are well-versed in all of the -Twilio Helper Libraries, and usually reply within 24 hours. +[apidocs]: https://www.twilio.com/docs/api +[twiml]: https://www.twilio.com/docs/api/twiml +[libdocs]: https://twilio.github.io/twilio-java -If you've instead found a bug in the library or would like new features added, -go ahead and open issues or pull requests against this repo! diff --git a/UPGRADE.md b/UPGRADE.md index 80cff82b05..52c77b3329 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,10 +1,416 @@ # Upgrade Guide -_After `7.4.0` all `MINOR` and `MAJOR` version bumps will have upgrade notes -posted here._ +_`MAJOR` version bumps will have upgrade notes posted here._ + +[2026-08-26] 12.x.x to 13.x.x +----------------------------- +### Overview +##### Twilio Java Helper Library's major version 13.0.0 includes: +1. A fix to ensure nested response models gracefully handle unknown fields (forward compatibility). +2. A fix to class name generation for nested models and enums whose schema names contain numbers (e.g., API version identifiers like `v2`). + +##### Breaking Changes + +###### 1. Nested model and enum class names corrected +Type names derived from schema names containing numbers (e.g., `conversations.v2.action_status`) previously had those numbers silently dropped. They are now correctly included. + +**Who is impacted:** +Users who reference generated nested enum or model types by name in their code for the following resources: +- `com.twilio.rest.conversations.v2.Action` +- `com.twilio.rest.conversations.v2.Communication` +- `com.twilio.rest.conversations.v2.Configuration` +- `com.twilio.rest.conversations.v2.Conversation` +- `com.twilio.rest.conversations.v2.Operation` +- `com.twilio.rest.conversations.v2.Participant` +- `com.twilio.rest.messaging.v2.ChannelsSender` + +**Example of renamed type (generator fix):** + +| 12.x.x | 13.x.x | +|---------|---------| +| `Conversation.ConversationsVConversationGroupingType` | `Conversation.ConversationsV2ConversationGroupingType` | + +##### Migration + +Find and replace the old type names with the corrected names. If you use any nested enum or model class from the affected resources above, update the class reference. + +```java +// 12.x.x +Conversation.ConversationsVConversationGroupingType type = Conversation.ConversationsVConversationGroupingType.OPEN; + +// 13.x.x +Conversation.ConversationsV2ConversationGroupingType type = Conversation.ConversationsV2ConversationGroupingType.OPEN; +``` + +##### Non-Breaking Fix + +###### Forward compatibility for nested response models +All nested response model Builder classes now include `@JsonIgnoreProperties(ignoreUnknown = true)`. This prevents `UnrecognizedPropertyException` when the API returns new fields that are not yet defined in the SDK. No code changes required — this fix is transparent to existing users. + + +[2026-04-21] 11.x.x to 12.x.x +----------------------------- +### Overview +##### Twilio Java Helper Library's major version 12.0.0 is now available. This release adds JDK 21 build and test support and replaces the deprecated `io.jsonwebtoken.SignatureAlgorithm` enum with the modern `io.jsonwebtoken.security.SecureDigestAlgorithm` API from jjwt 0.12.x. The compiled JAR remains JDK 8 compatible. + +##### Breaking Changes + +###### 1. `SignatureAlgorithm` replaced with `SecureDigestAlgorithm` +Who is impacted: +Users who pass an explicit algorithm parameter to `ValidationClient`, `ValidationInterceptor`, `ValidationToken.fromHttpRequest()`, `ValidationToken.Builder.algorithm()`, or who subclass `com.twilio.jwt.Jwt` directly. + +Who is NOT impacted: +Users who use the default constructors of `ValidationClient` or `ValidationInterceptor` (the ones without an algorithm parameter). Users who only use `AccessToken`, `ClientCapability`, `TaskRouterCapability`, or the REST API resource classes (`Message`, `Call`, etc.). + +##### Migration + +Replace the import and algorithm constants: + +```java +// 11.x.x +import io.jsonwebtoken.SignatureAlgorithm; + +new ValidationClient(accountSid, credSid, signingKeySid, privateKey, SignatureAlgorithm.PS256); + +new ValidationToken.Builder(accountSid, credSid, signingKeySid, privateKey) + .algorithm(SignatureAlgorithm.RS256) + .build(); +``` + +```java +// 12.x.x +import io.jsonwebtoken.Jwts; + +new ValidationClient(accountSid, credSid, signingKeySid, privateKey, Jwts.SIG.PS256); + +new ValidationToken.Builder(accountSid, credSid, signingKeySid, privateKey) + .algorithm(Jwts.SIG.RS256) + .build(); +``` + +##### Affected Public API Signatures + +**`com.twilio.jwt.Jwt`** — Both constructors: +```java +// 11.x.x +public Jwt(SignatureAlgorithm algorithm, byte[] secret, String issuer, Date expiration) +public Jwt(SignatureAlgorithm algorithm, Key secretKey, String issuer, Date expiration) + +// 12.x.x +public Jwt(SecureDigestAlgorithm algorithm, byte[] secret, String issuer, Date expiration) +public Jwt(SecureDigestAlgorithm algorithm, Key secretKey, String issuer, Date expiration) +``` + +**`com.twilio.http.ValidationClient`** — Three constructors (the ones accepting an algorithm parameter): +```java +// 11.x.x +public ValidationClient(..., SignatureAlgorithm algorithm) + +// 12.x.x +public ValidationClient(..., SecureDigestAlgorithm algorithm) +``` + +**`com.twilio.http.ValidationInterceptor`** — One constructor: +```java +// 11.x.x +public ValidationInterceptor(String accountSid, String credentialSid, String signingKeySid, PrivateKey privateKey, SignatureAlgorithm algorithm) + +// 12.x.x +public ValidationInterceptor(String accountSid, String credentialSid, String signingKeySid, PrivateKey privateKey, SecureDigestAlgorithm algorithm) +``` + +**`com.twilio.jwt.validation.ValidationToken`** — Static factory method and builder: +```java +// 11.x.x +public static ValidationToken fromHttpRequest(..., SignatureAlgorithm algorithm) +public Builder algorithm(SignatureAlgorithm algorithm) + +// 12.x.x +public static ValidationToken fromHttpRequest(..., SecureDigestAlgorithm algorithm) +public Builder algorithm(SecureDigestAlgorithm algorithm) +``` + +###### 2. Internal: `URLEncodedUtils` replaced with `URIBuilder` in `RequestValidator` +This is an internal implementation change with no public API impact. The deprecated `org.apache.hc.core5.net.URLEncodedUtils` was replaced with `org.apache.hc.core5.net.URIBuilder`. + +##### JDK Support +The library now supports building and testing on both JDK 8 and JDK 11+ (including JDK 21) via Maven profiles that activate automatically based on the detected JDK version. The compiled JAR remains JDK 8 compatible (`-source 8 -target 8`). + +[2025-09-30] 10.x.x to 11.x.x +----------------------------- +### Overview +##### Twilio Java Helper Library’s major version 11.0.0 is now available. 11.0.0 version contains breaking changes + +##### Breaking Changes +###### 1. NetworkHttpClient upgraded from HttpClient4 → HttpClient5 +Who are impacted: +Users who override NetworkHttpClient. + +###### 2. Bug Fix: Enum suffix removed (StatusEnum → Status) +This was a bug in Account resource in Organisation API + +###### 3. Organisation API — Organisation API init authentication mechanism has been changed. +Who are impacted: +Users calling the Organisation API. Refer Examples +Organisation API examples [here](https://github.com/twilio/twilio-java/blob/main/examples/OrgsAPIExample.md) + +###### 4. Bug Fix: Using Object data type for [anyType](https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type) fields in open-api specifications +Who are impacted: +Properties/Parameters defined as [anyType](https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type) in open-api specifications will be represented using `Object` now. +Previous data type: `Map` +New data type: `Object` + + +[2024-02-08] 9.x.x to 10.x.x +----------------------------- +### Overview + +##### Twilio Java Helper Library’s major version 10.0.0 is now available. We ensured that you can upgrade to Java helper Library 10.0.0 version without any breaking changes of existing apis + +Behind the scenes Java Helper is now auto-generated via OpenAPI with this release. This enables us to rapidly add new features and enhance consistency across versions and languages. +We're pleased to inform you that version 10.0.0 adds support for the application/json content type in the request body. + +[2022-09-21] 8.x.x to 9.x.x +----------------------------- +### Overview + +##### Twilio Java Helper Library’s major version 9.0.0 is now available. We ensured that you can upgrade to Java helper Library 9.0.0 version without any breaking changes + +Behind the scenes Java Helper is now auto-generated via OpenAPI with this release. This enables us to rapidly add new features and enhance consistency across versions and languages. + +[2020-09-28] 7.x.x to 8.x.x +----------------------------- + +### Overview + +Version `8.x.x` is the first version that officially drops support for Java 7. + +- Removal of dependencies offering functionality included in Java 8 and beyond: + - [Guava concurrency, hashing, and charstreams](https://github.com/twilio/twilio-java/pull/575) + - [Guava `com.google.common.collect.Range` removal](https://github.com/twilio/twilio-java/pull/584) + - [joda-time](https://github.com/twilio/twilio-java/pull/572) + - `org.joda.time.DateTime` -> `java.time.ZonedDateTime` + - `org.joda.time.LocalDate` -> `java.time.LocalDate` +- [Removal of deprecated classes and methods](https://github.com/twilio/twilio-java/pull/578): + - `com.twilio.jwt.accesstoken.ConversationsGrant` + - `com.twilio.jwt.accesstoken.IpMessagingGrant` + - `com.twilio.jwt.accesstoken.VideoGrant.getConfigurationProfileSid()` + - `com.twilio.jwt.accesstoken.VideoGrant.setConfigurationProfileSid()` + - Renamed child TwiML methods: + - `com.twilio.twiml.voice.Refer.Builder.referSip` + - `com.twilio.twiml.voice.Say.Builder.ssml` + +### CHANGED - Migration to built-in Java concurrency dependencies +#### Getting/Setting a custom Executor Service +```java +// 7.x.x +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; + +ListeningExecutorService listeningExecutorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); +Twilio.setExecutorService(listeningExecutorService); +``` +```java +// 8.x.x +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executor; + +ExecutorService executorService = Executors.newCachedThreadPool(); +Twilio.setExecutorService(executorService); +``` + +#### Making asynchronous requests +Note that this change effects all asynchronous Create/Fetch/Update/Delete/Read return types. For example: +```java +// 7.x.x +import com.twilio.rest.api.v2010.account.IncomingPhoneNumber; +import com.twilio.type.PhoneNumber; +import com.google.common.util.concurrent.ListenableFuture; + +ListenableFuture incomingPhoneNumber = IncomingPhoneNumber.creator(new PhoneNumber("+11234567890")).createAsync(); +``` + +```java +// 8.x.x +import com.twilio.rest.api.v2010.account.IncomingPhoneNumber; +import com.twilio.type.PhoneNumber; +import java.util.concurrent.CompletableFuture; + +CompletableFuture incomingPhoneNumber = IncomingPhoneNumber.creator(new PhoneNumber("+11234567890")).createAsync(); +``` + +### CHANGED - `RequestCanonicalizer` no longer requires a hash function parameter +Note that this class is primarily used internally by `com.twilio.jwt.validation.ValidationToken`. +```java +// 7.x.x +import com.google.common.hash.HashFunction; +import com.google.common.hash.Hashing; +import com.twilio.jwt.validation; +import org.apache.http.Header; +import java.util.Arrays; +import java.util.List; + +Header[] headers; +List signedHeaders = Arrays.asList("authorization", "duplicate", "host"); +HashFunction hasher = Hashing.sha256(); + +String canonicalized = new RequestCanonicalizer("GET", "/Messages", "queryParam=Hello+World", "foobar", headers).create(signedHeaders, hasher); +``` + +```java +// 8.x.x +import com.twilio.jwt.validation; +import org.apache.http.Header; +import java.util.Arrays; +import java.util.List; + +Header[] headers; +List signedHeaders = Arrays.asList("authorization", "duplicate", "host"); + +String canonicalized = new RequestCanonicalizer("GET", "/Messages", "queryParam=Hello+World", "foobar", headers).create(signedHeaders); +``` + +### CHANGED - Guava Range removal +Methods previously accepting a single `Range` parameter now expect multiple date parameters representing the start and end of the range. +```java +// 7.x.x +import com.google.common.collect.Range; +import com.twilio.base.ResourceSet; +import com.twilio.rest.api.v2010.account.Message; +import org.joda.time.DateTime; + +ResourceSet messages = Message.reader() + .setDateSent( + Range.open(new DateTime(2019, 1, 1, 0, 0, 0), new DateTime(2019, 3, 1, 0, 0, 0))) + .limit(20) + .read(); +``` +```java +// 8.x.x +import com.twilio.base.ResourceSet; +import com.twilio.rest.api.v2010.account.Message; +import java.time.ZonedDateTime; +import java.time.ZoneId; + +ResourceSet messages = Message.reader() + .setDateSentAfter(ZonedDateTime.of(2019, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"))) + .setDateSentBefore(ZonedDateTime.of(2019, 3, 1, 0, 0, 0, 0, ZoneId.of("UTC"))) + .limit(20) + .read(); +``` + +### CHANGED - Dates now use java.time +This change effects the type needed for getting/setting date-related properties and parameters for all resources. For example: +```java +// 7.x.x +import com.twilio.rest.api.v2010.account.IncomingPhoneNumber; +import com.twilio.type.PhoneNumber; +import org.joda.time.DateTime; + +IncomingPhoneNumber incomingPhoneNumber = IncomingPhoneNumber.fetcher("PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").fetch(); +DateTime dateCreated = incomingPhoneNumber.getDateCreated(); +``` + +```java +// 8.x.x +import com.twilio.rest.api.v2010.account.IncomingPhoneNumber; +import com.twilio.type.PhoneNumber; +import java.time.ZonedDateTime; + +IncomingPhoneNumber incomingPhoneNumber = IncomingPhoneNumber.fetcher("PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").fetch(); +ZonedDateTime dateCreated = incomingPhoneNumber.getDateCreated(); +``` + +### CHANGED - Renamed nested TwiML methods +Method names now match the nested element's TwiML verb/noun name (previously used the nested element's resource name). For example: +```java +// 7.x.x +import com.twilio.twiml.voice.Refer; +import com.twilio.twiml.voice.ReferSip; + +ReferSip sip = new ReferSip.Builder("sip:alice@example.com").build(); +Refer refer = new Refer.Builder().referSip(sip).build(); +``` + +```java +// 8.x.x +import com.twilio.twiml.voice.Refer; +import com.twilio.twiml.voice.ReferSip; + +ReferSip sip = new ReferSip.Builder("sip:alice@example.com").build(); +Refer refer = new Refer.Builder().sip(sip).build(); +``` + +#### Effected methods: +- `com.twilio.twiml.voice.Refer` + - `referSip(ReferSip referSip)` -> `sip(ReferSip referSip)` +- `com.twilio.twiml.voice.Say` + - `ssmlBreak(SsmlBreak ssmlBreak)` -> `break_(SsmlBreak ssmlBreak)` + - `ssmlEmphasis(SsmlEmphasis ssmlEmphasis)` -> `emphasis(SsmlEmphasis ssmlEmphasis)` + - `ssmlLang(SsmlLang ssmlLang)` -> `lang(SsmlLang ssmlLang)` + - `ssmlP(SsmlP ssmlP)` -> `p(SsmlP ssmlP)` + - `ssmlPhoneme(SsmlPhoneme ssmlPhoneme)` -> `phoneme(SsmlPhoneme ssmlPhoneme)` + - `ssmlProsody(SsmlProsody ssmlProsody)` -> `prosody(SsmlProsody ssmlProsody)` + - `ssmlS(SsmlS ssmlS)` -> `s(SsmlS ssmlS)` + - `ssmlSayAs(SsmlSayAs ssmlSayAs)` -> `sayAs(SsmlSayAs ssmlSayAs)` + - `ssmlSub(SsmlSub ssmlSub)` -> `sub(SsmlSub ssmlSub)` + - `ssmlW(SsmlW ssmlW)` -> `w(SsmlW ssmlW)` + +### CHANGED - Remove deprecated JWT Access Token Grants +- `com.twilio.jwt.accesstoken.ConversationsGrant` has been deprecated in favor of `com.twilio.jwt.accesstoken.VoiceGrant` +- `com.twilio.jwt.accesstoken.IpMessagingGrant` has no replacement + +### CHANGED - Remove deprecated `com.twilio.jwt.accesstoken.VoiceGrant` methods +`configurationProfileSid` has been renamed to `room`. Getter and setter has been renamed: +```java +// 7.x.x +import com.twilio.jwt.accesstoken.VoiceGrant; + +VoiceGrant vg = new VoiceGrant(); +vg.setConfigurationProfileSid("sid"); +String sid = vg.getConfigurationProfileSid(); +``` + +```java +// 8.x.x +import com.twilio.jwt.accesstoken.VoiceGrant; + +VoiceGrant vg = new VoiceGrant(); +vg.setRoom("sid"); +String sid = vg.getRoom(); +``` + +### CHANGED - Updated `com.twilio.type.IceServer` URL types +`IceServer` properties `url` and `urls` types have been changed from `java.net.URI` to `String`: +```java +// 7.x.x +import com.twilio.rest.api.v2010.account.Token; +import com.twilio.type.IceServer; +import java.net.URI; + +Token token = Token.creator().create() + +for (IceServer iceServer : token.getIceServers()) { + URI url = iceServer.getUrl(); + URI urls = iceServer.getUrls(); +} +``` + +```java +// 8.x.x +import com.twilio.rest.api.v2010.account.Token; +import com.twilio.type.IceServer; + +Token token = Token.creator().create() + +for (IceServer iceServer : token.getIceServers()) { + String url = iceServer.getUrl(); + String urls = iceServer.getUrls(); +} +``` [2017-12-15] 7.16.x to 7.17.x ---------------------------- +----------------------------- ### Overview diff --git a/VERSIONS.md b/VERSIONS.md index 5af30eb263..0002a60505 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -5,11 +5,11 @@ all changes to the helper library. It is strongly encouraged that you pin at least the major version and potentially the minor version to avoid pulling in breaking changes. -Semantic Versions take the form of `MAJOR`.`MINOR`.`PATCH` +Semantic Versions take the form of `MAJOR.MINOR.PATCH` -When bugs are fixed in the library in a backwards compatible way, the `PATCH` +When bugs are fixed in the library in a backwards-compatible way, the `PATCH` level will be incremented by one. When new features are added to the library -in a backwards compatible way, the `PATCH` level will be incremented by one. +in a backwards-compatible way, the `PATCH` level will be incremented by one. `PATCH` changes should _not_ break your code and are generally safe for upgrade. When a new large feature set comes online or a small breaking change is @@ -19,8 +19,8 @@ change for upgrade. These backwards-incompatible changes will generally be limited to a small number of function signature changes. The `MAJOR` version is used to indicate the family of technology represented by -the helper library. Breaking changes that requires extensive reworking of code -will case the `MAJOR` version to be incremented by one, and the `MINOR` and +the helper library. Breaking changes that require extensive reworking of code +will cause the `MAJOR` version to be incremented by one, and the `MINOR` and `PATCH` versions will be reset to zero. Twilio understands that this can be very disruptive, so we will only introduce this type of breaking change when absolutely necessary. New `MAJOR` versions will be communicated in advance with @@ -28,9 +28,8 @@ absolutely necessary. New `MAJOR` versions will be communicated in advance with ## Supported Versions -`twilio-java` follows an evergreen model of support. New features and -functionality will only be added to the current version. The current version - -1 will continue to be supported with bug fixes and security updates, but no new -features. +Only the current `MAJOR` version of `twilio-java` is supported. New +features, functionality, bug fixes, and security updates will only be added to +the current `MAJOR` version. -[semver]: http://semver.org/ \ No newline at end of file +[semver]: https://semver.org \ No newline at end of file diff --git a/advanced-examples/custom-http-client.md b/advanced-examples/custom-http-client.md new file mode 100644 index 0000000000..c255bd2969 --- /dev/null +++ b/advanced-examples/custom-http-client.md @@ -0,0 +1,225 @@ +# Custom HTTP Clients for the Twilio Java Helper Library + +If you are working with the Twilio Java Helper Library, and you need to be able to modify the HTTP requests that the library makes to the Twilio servers, you’re in the right place. The most common need to alter the HTTP request is to connect and authenticate with an enterprise’s proxy server. We’ll provide sample code that you can drop right into your app to handle this use case. + +## Connect and authenticate with a proxy server + +To connect and provide credentials to a proxy server that may be between your app and Twilio, you need a way to modify the HTTP requests that the Twilio helper library makes on your behalf to invoke the Twilio REST API. + +The Twilio Java helper library uses the HttpClient interface (in the org.apache.http.client package) under the hood to make the HTTP requests. With this in mind, the following two facts should help us arrive at the solution: + +1. Connecting to a proxy server with HttpClient is a [solved problem](https://hc.apache.org/httpcomponents-client-ga/examples.html). +1. The Twilio Helper Library allows you to provide your own `HttpClient` for making API requests. + +So the question becomes: how do we apply this to a typical Twilio REST API example? + +```java +Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + +Message message = Message.creator(new PhoneNumber("+15558675310"), + new PhoneNumber("+15017122661"), "Hey there!").create(); +``` + +Where is `TwilioRestClient` created and used? Out of the box, the helper library creates a default `TwilioRestClient` for you, using the Twilio credentials you pass to the `init` method. However, nothing is stopping you from creating your own and using that. + +Once you have your own `TwilioRestClient`, you can pass it to any Twilio REST API resource action you want. Here’s an example of sending an SMS message with a custom client: + +```java +// Install the Java helper library from twilio.com/docs/java/install +import com.twilio.Twilio; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.type.PhoneNumber; +import io.github.cdimascio.dotenv.Dotenv; + +public class Example { + + public static void main(String args[]) { + Dotenv dotenv = Dotenv.configure().directory(".").load(); + String ACCOUNT_SID = dotenv.get("ACCOUNT_SID"); + String AUTH_TOKEN = dotenv.get("AUTH_TOKEN"); + String PROXY_HOST = dotenv.get("PROXY_HOST"); + int PROXY_PORT = Integer.parseInt(dotenv.get("PROXY_PORT")); + + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + + ProxiedTwilioClientCreator clientCreator = new ProxiedTwilioClientCreator( + ACCOUNT_SID, + AUTH_TOKEN, + PROXY_HOST, + PROXY_PORT + ); + TwilioRestClient twilioRestClient = clientCreator.getClient(); + Twilio.setRestClient(twilioRestClient); + + Message message = Message + .creator( + new PhoneNumber("+15558675310"), + new PhoneNumber("+15017122661"), + "Hey there!" + ) + .create(); + + System.out.println(message.getSid()); + } +} +``` + +## Create your custom TwilioRestClient + +When you take a closer look at the constructor for `TwilioRestClient`, you see that the `httpClient` parameter is actually of type `com.twilio.http.HttpClient`. + +`HttpClient` is an abstraction that allows plugging in any implementation of an HTTP client you want (or even creating a mocking layer for unit testing). + +However, within the helper library, there is an implementation of `com.twilio.http.HttpClient` called `NetworkHttpClient`. This class wraps the `org.apache.http.client.HttpClient` and provides it to the Twilio helper library to make the necessary HTTP requests. + +## Call Twilio through the proxy server + +Now that we understand how all the components fit together, we can create our own `TwilioRestClient` that can connect through a proxy server. To make this reusable, here’s a class that you can use to create this `TwilioRestClient` whenever you need one: + +```java +import com.twilio.http.HttpClient; +import com.twilio.http.NetworkHttpClient; +import com.twilio.http.TwilioRestClient; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.core5.http.HttpHost; + +public class ProxiedTwilioClientCreator { + + private String username; + private String password; + private String proxyHost; + private int proxyPort; + private HttpClient httpClient; + + /** + * Constructor for ProxiedTwilioClientCreator + * @param username + * @param password + * @param proxyHost + * @param proxyPort + */ + public ProxiedTwilioClientCreator( + String username, + String password, + String proxyHost, + int proxyPort + ) { + this.username = username; + this.password = password; + this.proxyHost = proxyHost; + this.proxyPort = proxyPort; + } + + /** + * Creates a custom HttpClient based on default config as seen on: + * {@link com.twilio.http.NetworkHttpClient#NetworkHttpClient() constructor} + */ + private void createHttpClient() { + RequestConfig config = RequestConfig + .custom() + .setConnectTimeout(Timeout.ofMilliseconds(10000)) + .build(); + + PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); + connectionManager.setDefaultMaxPerRoute(10); + connectionManager.setMaxTotal(10 * 2); + + HttpHost proxy = new HttpHost(proxyHost, proxyPort); + + HttpClientBuilder clientBuilder = HttpClientBuilder.create(); + clientBuilder + .setConnectionManager(connectionManager) + .setProxy(proxy) + .setDefaultRequestConfig(config); + + // Inclusion of Twilio headers and build() is executed under this constructor + this.httpClient = new NetworkHttpClient(clientBuilder); + } + + /** + * Get the custom client or builds a new one + * @return a TwilioRestClient object + */ + public TwilioRestClient getClient() { + if (this.httpClient == null) { + this.createHttpClient(); + } + + TwilioRestClient.Builder builder = new TwilioRestClient.Builder( + username, + password + ); + return builder.httpClient(this.httpClient).build(); + } +} +``` + +In this example, we use some environment variables loaded at the program startup to retrieve various configuration settings: + +- Your Twilio Account Sid and Auth Token (found here, in the Twilio console) +- Your proxy server host +- Your proxy port + +These settings are located in a file named `.env` like so: + +```env +ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +AUTH_TOKEN= your_auth_token + +PROXY_HOST=127.0.0.1 +PROXY_PORT=8888 +``` + +Here’s a console program that sends a text message and shows how it all can work together. It loads the `.env` file for us. + +```java +// Install the Java helper library from twilio.com/docs/java/install +import com.twilio.Twilio; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.type.PhoneNumber; +import io.github.cdimascio.dotenv.Dotenv; + +public class Example { + + public static void main(String args[]) { + Dotenv dotenv = Dotenv.configure().directory(".").load(); + String ACCOUNT_SID = dotenv.get("ACCOUNT_SID"); + String AUTH_TOKEN = dotenv.get("AUTH_TOKEN"); + String PROXY_HOST = dotenv.get("PROXY_HOST"); + int PROXY_PORT = Integer.parseInt(dotenv.get("PROXY_PORT")); + + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + + ProxiedTwilioClientCreator clientCreator = new ProxiedTwilioClientCreator( + ACCOUNT_SID, + AUTH_TOKEN, + PROXY_HOST, + PROXY_PORT + ); + TwilioRestClient twilioRestClient = clientCreator.getClient(); + Twilio.setRestClient(twilioRestClient); + + Message message = Message + .creator( + new PhoneNumber("+15558675310"), + new PhoneNumber("+15017122661"), + "Hey there!" + ) + .create(); + + System.out.println(message.getSid()); + } +} +``` + +## What else can this technique be used for? + +Now that you know how to inject your own HttpClient into the Twilio API request pipeline, you could use this technique to add custom HTTP headers and authorization to the requests, perhaps as required by an upstream proxy server. + +You could also implement your own HttpClient to mock the Twilio API responses so your unit and integration tests can run quickly without needing to make a connection to Twilio. In fact, there’s already an example online showing [how to do exactly that with Node.js and Prism](https://www.twilio.com/docs/openapi/mock-api-generation-with-twilio-openapi-spec). + +We can’t wait to see what you build! diff --git a/examples/Content.md b/examples/Content.md new file mode 100644 index 0000000000..b9c7298a4f --- /dev/null +++ b/examples/Content.md @@ -0,0 +1,25 @@ +public class ContentExamples { + public static void main { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + createTwilioText(); + } + + public static void createTwilioText() { + Content.ContentCreateRequest createRequest = new Content.ContentCreateRequest("es", types); + + Content.TwilioText twilioText = new Content.TwilioText(); + twilioText.setBody("text body"); + + Content.Types types = new Content.Types(); + types.setTwilioText(twilioText); + + Map variables = new HashMap<>(); + variables.put("var1", "val1"); + + createRequest.setVariables(variables); + createRequest.setFriendlyName("name"); + + Content newContent = Content.creator(createRequest).create(); + } + +} \ No newline at end of file diff --git a/examples/MultiRegionClient.md b/examples/MultiRegionClient.md new file mode 100644 index 0000000000..a5080a6e2c --- /dev/null +++ b/examples/MultiRegionClient.md @@ -0,0 +1,41 @@ +```java +package com.twilio.example; + +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.type.PhoneNumber; + +public class MultiRegionExample { + public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); + public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN"); + + public static void main(String[] args) { + + TwilioRestClient client = new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN).region("us1").build(); + + Message message = Message + .creator( + new PhoneNumber("+1XXXXXXXXXX"), + new PhoneNumber("+1XXXXXXXXXX"), + "This is the ship that made the Kessel Run in fourteen parsecs?" + ) + .create(client); + + System.out.println(message.getSid()); + + TwilioRestClient client2 = new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN).region("au1").build(); + + Message message2 = Message + .creator( + new PhoneNumber("+1XXXXXXXXXX"), + new PhoneNumber("+1XXXXXXXXXX"), + "This is the ship that made the Kessel Run in fourteen parsecs?" + ) + .create(client2); + + System.out.println(message2.getSid()); + } +} + + +``` diff --git a/examples/OrgsAPIExample.md b/examples/OrgsAPIExample.md new file mode 100644 index 0000000000..b4511f88bc --- /dev/null +++ b/examples/OrgsAPIExample.md @@ -0,0 +1,34 @@ + class OrgsAPIExample { + public static void main { + + private static final String GRANT_TYPE = "grant_type_to_be_used"; + private static final String CLIENT_SID = + "client_id_of_the_organization"; + private static final String CLIENT_SECRET = "client_secret_of_organization"; + private static final String ORGANISATION_ID = "id_of_the_organization"; + + //Getting access token - Method #1 + Twilio.init(new OrgsClientCredentialProvider(CLIENT_SID, CLIENT_SECRET)); + fetchAccountDetails(); + + + //Scenario: 2 If in case one doesn't want to change the existing stored credential + // Pass Custom TwilioRestClient + // TokenManager tokenManager = new OrgsTokenManager(GRANT_TYPE, CLIENT_SID, CLIENT_SECRET); + // TokenAuthStrategy tokenAuthStrategy = new TokenAuthStrategy(tokenManager); + // TwilioRestClient client = new TwilioRestClient.Builder(tokenAuthStrategy).build(); + // fetchAccountDetailsWithClient(client); + } + + private static void fetchAccountDetails() { + ResourceSet accountSet = Account.reader(ORGANISATION_ID).read(); + String accountSid = accountSet.iterator().next().getAccountSid(); + System.out.println(accountSid); + } + + private static void fetchAccountDetailsWithClient(TwilioRestClient client) { + ResourceSet accountSet = Account.reader(ORGANISATION_ID).read(client); + String accountSid = accountSet.iterator().next().getAccountSid(); + System.out.println(accountSid); + } + } \ No newline at end of file diff --git a/examples/PreviewMessaging.md b/examples/PreviewMessaging.md new file mode 100644 index 0000000000..401ae3231d --- /dev/null +++ b/examples/PreviewMessaging.md @@ -0,0 +1,28 @@ +class PreviewMessagingExamples { + public static void main { + Twilio.init(ACCOUNT_SID, AUTH_TOKEN); + sendBulkMessages(); + } + + private static void sendBulkMessages() { + Message.CreateMessagesRequest createMessagesRequest = new Message.CreateMessagesRequest(); + List toNumbers; // recipients numbers + + // Set from number + PhoneNumber fromNumber; + + // Set list of number where you want to send bulk message. + List phoneList = new ArrayList<>(); + for (String to: toNumbers) { + Message.MessagingV1Message phone = new Message.MessagingV1Message(); + phone.setTo(new PhoneNumber(to)); + phoneList.add(phone); + } + + createMessagesRequest.setFrom(fromNumber); + createMessagesRequest.setBody("Bulk message to send"); + createMessagesRequest.setMessages(phoneList); + Message message = Message.creator(createMessagesRequest).create(); + } + +} \ No newline at end of file diff --git a/examples/PublicOAuthExample.md b/examples/PublicOAuthExample.md new file mode 100644 index 0000000000..6ebdfed02e --- /dev/null +++ b/examples/PublicOAuthExample.md @@ -0,0 +1,44 @@ +``` +import com.twilio.Twilio; +import com.twilio.credential.ClientCredentialProvider; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.http.TwilioRestClient; +import com.twilio.http.bearertoken.ApiTokenManager; +import com.twilio.http.bearertoken.TokenManager; +import com.twilio.auth_strategy.TokenAuthStrategy; + +class PublicOAuthExample { + private static final String GRANT_TYPE = "client_credentials"; + private static final String OAUTH_CLIENT_SID = System.getenv("OAUTH_CLIENT_ID"); + private static final String OAUTH_CLIENT_SECRET = System.getenv("OAUTH_CLIENT_SECRET"); + private static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); + private static final String MESSAGE_SID = System.getenv("MESSAGE_SID"); + + public static void main(String[] args) { + + + //Getting access token - Method #1 + Twilio.init(new ClientCredentialProvider(OAUTH_CLIENT_SID, OAUTH_CLIENT_SECRET), ACCOUNT_SID); + fetchMessage(MESSAGE_SID); + + + //Scenario: 2 If in case one doesn't want to change the existing stored credential + // Pass Custom TwilioRestClient + // TokenManager tokenManager = new ApiTokenManager(GRANT_TYPE, OAUTH_CLIENT_SID, OAUTH_CLIENT_SECRET); + // TokenAuthStrategy tokenAuthStrategy = new TokenAuthStrategy(tokenManager); + // TwilioRestClient client = new TwilioRestClient.Builder(tokenAuthStrategy).accountSid(ACCOUNT_SID).build(); + // fetchMessageWithClient(MESSAGE_SID, client); + } + + public static void fetchMessage(String sid) { + Message message = Message.fetcher(sid).fetch(); + System.out.println("Fetched Message SID: " + message.getSid()); + } + + public static void fetchMessageWithClient(String sid, TwilioRestClient client) { + Message message = Message.fetcher(sid).fetch(client); + System.out.println("Fetched Message SID: " + message.getSid()); + } +} +``` + diff --git a/examples/ResponseWithHeaders.md b/examples/ResponseWithHeaders.md new file mode 100644 index 0000000000..a35711da7c --- /dev/null +++ b/examples/ResponseWithHeaders.md @@ -0,0 +1,71 @@ +```java + +package com.twilio; + +import com.twilio.base.Page; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.rest.api.v2010.account.Message; +import com.twilio.rest.api.v2010.account.MessageReader; + +import java.util.Map; + +public class Test { + public static void main(String[] args) { + Twilio.init("ACCOUNT_SID", "AUTH_TOKEN"); + deleteMessage(); + } + + public static void createMessage() { + TwilioResponse response = Message + .creator(new com.twilio.type.PhoneNumber("TO_NUMBER"), + new com.twilio.type.PhoneNumber("FROM_NUMBER"), + "Message body to send") + .createWithResponse(); + + System.out.println(response.getStatusCode()); + System.out.println(response.getHeaders()); + System.out.println(response.getContent()); + + } + + public static void fetchMessage() { + TwilioResponse response = Message.fetcher("SM1123").fetchWithResponse(); + + System.out.println(response.getStatusCode()); + System.out.println(response.getHeaders()); + System.out.println(response.getContent()); + } + + public static void updateMessage() { + TwilioResponse response = Message.updater("SM1123").setBody("").updateWithResponse(); + System.out.println(response.getStatusCode()); + System.out.println(response.getHeaders()); + System.out.println(response.getContent()); + } + + public static void deleteMessage() { + TwilioResponse response = Message.deleter("SM1123").deleteWithResponse(); + System.out.println(response.getStatusCode()); + System.out.println(response.getHeaders()); + System.out.println(response.getContent()); + } + + private static void readMessages() { + ResourceSetResponse result = Message.reader() + .limit(10) + .pageSize(3) + .readWithResponse(Twilio.getRestClient()); + + System.out.println(result.getStatusCode()); + System.out.println(result.getHeaders()); + + // Iterate (respects limit and pageSize) + for (Message message : result) { + System.out.println(message.getSid()); + } + } +} + +``` \ No newline at end of file diff --git a/examples/WebhookSignatureValidation.md b/examples/WebhookSignatureValidation.md new file mode 100644 index 0000000000..aa4239188f --- /dev/null +++ b/examples/WebhookSignatureValidation.md @@ -0,0 +1,67 @@ +# Validating webhook signatures (HMAC-SHA1 and HMAC-SHA256) + +By default Twilio signs webhooks with your Auth Token using HMAC-SHA1. If a +[Webhooks Rule](https://www.twilio.com/docs/usage/webhooks/webhook-rules) matches the webhook URL, Twilio signs +with the Setting's SharedKey and algorithm instead, and adds this header: + +``` +X-Twilio-Webhooks-Signature-Settings: key=,algorithm=HMAC_SHA256 +``` + +Only the hash changes. The signed string is still the full URL followed by the sorted POST parameters. + +## Validate any webhook + +Read the header to pick the secret and the algorithm: + +```java +import com.twilio.security.RequestValidator; + +String signature = request.getHeader(RequestValidator.SIGNATURE_HEADER); +String settings = request.getHeader(RequestValidator.SIGNATURE_SETTINGS_HEADER); // null if absent + +// No header means the Auth Token and HMAC_SHA1 +String secret = settings != null ? sharedKeySecret : authToken; +String algorithm = RequestValidator.getSignatureAlgorithm(settings); + +RequestValidator validator = new RequestValidator(secret); + +// Form-encoded body +boolean valid = validator.validate(url, params, signature, algorithm); + +// JSON body (the URL carries bodySHA256) +boolean validJson = validator.validate(url, jsonBody, signature, algorithm); +``` + +If you use more than one SharedKey, look up the secret by the `key=` value in the header. + +## Existing code + +The 3-argument `validate(...)` methods still use HMAC-SHA1, so code that validates with the Auth Token needs no change: + +```java +new RequestValidator(authToken).validate(url, params, signature); +``` + +## Where the values come from + +The validator needs only plain values, so it works with any framework or server. Read these from your request: + +- `url`: the full public URL Twilio calls, including the query string. Behind a proxy or tunnel, use the public `https` URL, not the internal one. +- `params`: every form field of the POST body, including empty ones, as a `Map`. For JSON webhooks pass the raw body string instead. +- `signature`: the `X-Twilio-Signature` header (`RequestValidator.SIGNATURE_HEADER`). +- `settings`: the `X-Twilio-Webhooks-Signature-Settings` header (`RequestValidator.SIGNATURE_SETTINGS_HEADER`), or `null` if absent. + +Respond `403` when `validate(...)` returns `false`. + +## Behaviour to know + +- An unsupported algorithm makes `validate(...)` return `false`, so the request is rejected rather than throwing. +- `getSignatureAlgorithm(...)` returns `HMAC_SHA1` for a missing or empty header, or one without `algorithm=`. + +## Troubleshooting a failed validation + +- **Wrong secret:** requests with the settings header need the SharedKey secret, not the Auth Token. +- **Wrong URL:** behind a proxy or tunnel, your framework may report `http` or an internal host. Use the public URL. +- **Dropped empty parameters:** pass every form field, including empty ones. +- **Parsed body:** for JSON webhooks pass the raw body string, not a re-serialized one. diff --git a/pom.xml b/pom.xml index 088cee2be9..fbdc570f70 100644 --- a/pom.xml +++ b/pom.xml @@ -1,13 +1,11 @@ - + 4.0.0 - - com.twilio.sdk twilio jar twilio - 7.21.5-SNAPSHOT + 13.2.1 Twilio Java Helper Library https://www.twilio.com @@ -21,7 +19,7 @@ git@github.com:twilio/twilio-java.git scm:git:git@github.com:twilio/twilio-java.git scm:git:git@github.com:twilio/twilio-java.git - HEAD + 13.2.1 @@ -33,7 +31,6 @@ -7 - gpg @@ -53,57 +50,228 @@ sign + + ${gpg.keyname} + ${gpg.passphrase} + + --pinentry-mode + loopback + + + + + + + + + + coverage + + true + + + + + org.jacoco + jacoco-maven-plugin + 0.8.7 + + + prepare-agent + + prepare-agent + + + + report + + report + + test + + + + + + release + + + release + + + + + + org.sonatype.central + central-publishing-maven-plugin + 0.8.0 + true - ${gpg.keyname} - ${gpg.passphrase} - + central + true + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${javadoc.plugin.version} + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + ${gpg.keyname} + ${gpg.passphrase} + --pinentry-mode loopback - - + + + + + + jdk8 + + 1.8 + + + 1.18.24 + 4.11.0 + 1.15.10 + 3.4 + 3.0.0-M4 + + + + + org.mockito + mockito-inline + ${mockito.version} + test + + + + + jdk11+ + + [11,) + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + + - - 2.8.11 + 2.18.6 + 3.12.0 + 0.12.6 + 1.18.34 + 5.14.2 + 3.17.3 + 1.15.10 + 3.4 + 3.5.2 + false + false + twilio + https://sonarcloud.io + twilio-java + **/test/**/*.*,**/rest/**/*.* + **/rest/**/*.* - - com.google.guava - guava - 18.0 + org.projectlombok + lombok + ${lombok.version} + provided + + + commons-codec + commons-codec + 1.15 - joda-time - joda-time - 2.5 + commons-io + commons-io + 2.14.0 io.jsonwebtoken - jjwt - 0.4 + jjwt-api + ${jjwt.version} - - org.apache.httpcomponents - httpclient - 4.5.2 + io.jsonwebtoken + jjwt-jackson + ${jjwt.version} + + + com.fasterxml.jackson.core + jackson-databind + + - - org.apache.httpcomponents - httpcore - 4.4.4 + io.jsonwebtoken + jjwt-impl + ${jjwt.version} + runtime + + + org.apache.httpcomponents.client5 + httpclient5 + 5.5 + + + commons-codec + commons-codec + + + + + org.apache.httpcomponents.core5 + httpcore5 + 5.3.4 - - com.fasterxml.jackson.core jackson-core @@ -119,45 +287,144 @@ jackson-databind ${jackson.version} - - - javax.xml.bind - jaxb-api - 2.2 + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} - - - org.jmockit - jmockit - 1.12 - test + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.version} + + + org.slf4j + slf4j-api + 1.7.36 junit junit - 4.11 + 4.13.2 + test + + + com.tngtech.archunit + archunit + 0.23.0 + test + + + org.slf4j + slf4j-api + + + + + nl.jqno.equalsverifier + equalsverifier + ${equalsverifier.version} + test + + + com.squareup.okhttp3 + mockwebserver + 5.2.2 + test + + + junit + junit + + + com.squareup.okio + okio + + + + + com.squareup.okio + okio + 3.16.3 + test + + + org.mockito + mockito-core + ${mockito.version} test + + + net.bytebuddy + byte-buddy + + + net.bytebuddy + byte-buddy-agent + + + org.objenesis + objenesis + + + + + net.bytebuddy + byte-buddy-agent + ${byte-buddy.version} + test + + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + + + org.objenesis + objenesis + ${objenesis.version} + test + + + org.json + json + 20240303 + + + com.auth0 + java-jwt + 4.4.0 + + + com.fasterxml.jackson.core + jackson-databind + + + + + com.google.code.gson + gson + 2.10.1 - org.apache.maven.plugins maven-compiler-plugin - 3.5 + 3.13.0 - 1.7 - 1.7 + 8 + 8 + true + true - org.apache.maven.plugins maven-assembly-plugin - 2.3 + 3.8.0 jar-with-dependencies @@ -166,29 +433,25 @@ make-assembly - package - single - org.apache.maven.plugins maven-checkstyle-plugin - 2.17 + 3.6.0 checkstyle.xml - org.apache.maven.plugins maven-source-plugin - 2.1.2 + 3.4.0 attach-sources @@ -198,22 +461,21 @@ - org.apache.maven.plugins maven-javadoc-plugin - 2.10.3 + ${javadoc.plugin.version} - ${env.TWILIO_DOCS_ROOT} - java/${project.version} + ${project.basedir}/docs + 8 public true true true true Twilio Java - Twilio Java]]> - Copyright © 2016 Twilio, Inc. All Rights Reserved.]]> + <h1>Twilio Java</h1> + <i>Copyright &#169; 2019 Twilio, Inc. All Rights Reserved.</i> @@ -224,46 +486,74 @@ - org.apache.maven.plugins maven-release-plugin - 2.5.3 + 3.3.1 @{project.version} -DskipTests=${skip.tests} - org.codehaus.mojo cobertura-maven-plugin - 2.2 + 2.7 xml - org.apache.maven.plugins maven-surefire-plugin - 2.20 + ${surefire.version} 8 true + ${surefire.argLine} + + + + com.github.spotbugs + spotbugs-maven-plugin + 4.0.4 + + Max + Low + true + false - + + org.apache.maven.plugins + maven-enforcer-plugin + 3.4.1 + + + enforce-versions + + enforce + + + + + + + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.7.0.1746 + + + org.jacoco + jacoco-maven-plugin + 0.8.8 + - - - - org.sonatype.oss - oss-parent - 7 - - - + \ No newline at end of file diff --git a/src/main/java/com/twilio/Domains.java b/src/main/java/com/twilio/Domains.java new file mode 100644 index 0000000000..aa5f454bc0 --- /dev/null +++ b/src/main/java/com/twilio/Domains.java @@ -0,0 +1,63 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ +package com.twilio.rest; + +public enum Domains { + ACCOUNTS("accounts"), + API("api"), + BULKEXPORTS("bulkexports"), + CHAT("chat"), + CONTENT("content"), + CONVERSATIONS("conversations"), + EVENTS("events"), + FLEXAPI("flex-api"), + FRONTLINEAPI("frontline-api"), + PREVIEWIAM("preview-iam"), + IAM("iam"), + INSIGHTS("insights"), + INTELLIGENCE("intelligence"), + IPMESSAGING("ip-messaging"), + KNOWLEDGE("knowledge"), + LOOKUPS("lookups"), + MARKETPLACE("marketplace"), + MEMORY("memory"), + MESSAGING("messaging"), + MONITOR("monitor"), + NOTIFY("notify"), + NUMBERS("numbers"), + OAUTH("oauth"), + PREVIEW("preview"), + PRICING("pricing"), + PROXY("proxy"), + ROUTES("routes"), + SERVERLESS("serverless"), + STUDIO("studio"), + SUPERSIM("supersim"), + SYNC("sync"), + TASKROUTER("taskrouter"), + TRUNKING("trunking"), + TRUSTHUB("trusthub"), + VERIFY("verify"), + VIDEO("video"), + VOICE("voice"), + WEBHOOKS("webhooks"), + WIRELESS("wireless"); + + private final String value; + + private Domains(final String value) { + this.value = value; + } + + public String toString() { + return value; + } +} diff --git a/src/main/java/com/twilio/Twilio.java b/src/main/java/com/twilio/Twilio.java index 17fe6fd76f..c19078159e 100644 --- a/src/main/java/com/twilio/Twilio.java +++ b/src/main/java/com/twilio/Twilio.java @@ -1,34 +1,82 @@ package com.twilio; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; - +import com.twilio.annotations.Beta; +import com.twilio.auth_strategy.AuthStrategy; import com.twilio.exception.ApiException; import com.twilio.exception.AuthenticationException; import com.twilio.exception.CertificateValidationException; +import com.twilio.credential.CredentialProvider; import com.twilio.http.HttpMethod; import com.twilio.http.NetworkHttpClient; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; +import java.util.Map; +import lombok.Getter; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** - * Singleton class to initialize Twilio environment. + * The {@code Twilio} class is a thread-safe singleton that manages the global configuration and initialization + * of the Twilio Java SDK environment. It provides static methods to set credentials, region, edge, and other + * runtime options, as well as to initialize and retrieve the shared {@link TwilioRestClient} instance. + *

+ * Usage of this class is required before making API requests. Credentials can be set via environment variables, + * system properties, or explicitly using the {@code init} methods. The class also manages a shared + * {@link ExecutorService} for asynchronous operations and provides utility methods for SSL certificate validation. + *

+ * Example usage: + *

+ *     Twilio.init("ACCOUNT_SID", "AUTH_TOKEN");
+ *     // or with a CredentialProvider
+ *     Twilio.init(new MyCredentialProvider());
+ * 
+ *

*/ public class Twilio { - public static final String VERSION = "7.21.4"; + public static final String VERSION = "13.2.1"; public static final String JAVA_VERSION = System.getProperty("java.version"); + public static final String OS_NAME = System.getProperty("os.name"); + public static final String OS_ARCH = System.getProperty("os.arch"); + private static String username = System.getenv("TWILIO_ACCOUNT_SID"); + private static String password = System.getenv("TWILIO_AUTH_TOKEN"); + private static String accountSid; // username used if this is null + @Getter + private static List userAgentExtensions; + private static String region = System.getenv("TWILIO_REGION"); + private static String edge = System.getenv("TWILIO_EDGE"); + private static volatile TwilioRestClient restClient; + private static volatile ExecutorService executorService; + + private static CredentialProvider credentialProvider; + + private static final Logger logger = LoggerFactory.getLogger(Twilio.class); - private static String username; - private static String password; - private static String accountSid; - private static TwilioRestClient restClient; - private static ListeningExecutorService executorService; - private Twilio() {} + + private Twilio() { + } + + /** + * Ensures that the ExecutorService is shutdown when the JVM exits. + */ + static { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + if (executorService != null) { + executorService.shutdownNow(); + } + } + }); + } /** * Initialize the Twilio environment. @@ -36,19 +84,45 @@ private Twilio() {} * @param username account to use * @param password auth token for the account */ - public static void init(final String username, final String password) { + public static synchronized void init(final String username, final String password) { Twilio.setUsername(username); Twilio.setPassword(password); + Twilio.setAccountSid(null); + } + + @Beta + public static synchronized void init(final CredentialProvider credentialProvider) { + Twilio.setCredentialProvider(credentialProvider); + Twilio.setAccountSid(null); + } + + @Beta + public static synchronized void init(final CredentialProvider credentialProvider, String accountSid) { + Twilio.setCredentialProvider(credentialProvider); + Twilio.setAccountSid(accountSid); + } + + private static void setCredentialProvider(final CredentialProvider credentialProvider) { + if (credentialProvider == null) { + throw new AuthenticationException("Credential Provider can not be null"); + } + + if (!credentialProvider.equals(Twilio.credentialProvider)) { + Twilio.invalidate(); + } + // Invalidate Basic Creds as they might be initialized via environment variables. + invalidateBasicCreds(); + Twilio.credentialProvider = credentialProvider; } /** * Initialize the Twilio environment. * - * @param username account to use - * @param password auth token for the account + * @param username account to use + * @param password auth token for the account * @param accountSid account sid to use */ - public static void init(final String username, final String password, final String accountSid) { + public static synchronized void init(final String username, final String password, final String accountSid) { Twilio.setUsername(username); Twilio.setPassword(password); Twilio.setAccountSid(accountSid); @@ -57,10 +131,10 @@ public static void init(final String username, final String password, final Stri /** * Set the username. * - * @param username account sid to use - * @throws AuthenticationException if accountSid is null + * @param username account to use + * @throws AuthenticationException if username is null */ - public static void setUsername(final String username) { + public static synchronized void setUsername(final String username) { if (username == null) { throw new AuthenticationException("Username can not be null"); } @@ -68,6 +142,7 @@ public static void setUsername(final String username) { if (!username.equals(Twilio.username)) { Twilio.invalidate(); } + Twilio.invalidateOAuthCreds(); Twilio.username = username; } @@ -78,7 +153,7 @@ public static void setUsername(final String username) { * @param password auth token to use * @throws AuthenticationException if password is null */ - public static void setPassword(final String password) { + public static synchronized void setPassword(final String password) { if (password == null) { throw new AuthenticationException("Password can not be null"); } @@ -86,6 +161,7 @@ public static void setPassword(final String password) { if (!password.equals(Twilio.password)) { Twilio.invalidate(); } + Twilio.invalidateOAuthCreds(); Twilio.password = password; } @@ -94,42 +170,95 @@ public static void setPassword(final String password) { * Set the account sid. * * @param accountSid account sid to use - * @throws AuthenticationException if account sid is null */ - public static void setAccountSid(final String accountSid) { - if (accountSid == null) { - throw new AuthenticationException("AccountSid can not be null"); + public static synchronized void setAccountSid(final String accountSid) { + if (!Objects.equals(accountSid, Twilio.accountSid)) { + Twilio.invalidate(); } - if (!accountSid.equals(Twilio.accountSid)) { + Twilio.accountSid = accountSid; + } + + public static synchronized void setUserAgentExtensions(final List userAgentExtensions) { + if (userAgentExtensions != null && !userAgentExtensions.isEmpty()) { + Twilio.userAgentExtensions = new ArrayList<>(userAgentExtensions); + } else { + // In case a developer wants to reset userAgentExtensions + Twilio.userAgentExtensions = null; + } + } + + /** + * Set the region. + * + * @param region region to make request + */ + public static synchronized void setRegion(final String region) { + if (!Objects.equals(region, Twilio.region)) { Twilio.invalidate(); } - Twilio.accountSid = accountSid; + Twilio.region = region; + } + + /** + * Set the edge. + * + * @param edge edge to make request + */ + public static synchronized void setEdge(final String edge) { + if (!Objects.equals(edge, Twilio.edge)) { + Twilio.invalidate(); + } + + Twilio.edge = edge; } /** * Returns (and initializes if not initialized) the Twilio Rest Client. * - * @return the TWilio Rest Client + * @return the Twilio Rest Client * @throws AuthenticationException if initialization required and either accountSid or authToken is null */ public static TwilioRestClient getRestClient() { if (Twilio.restClient == null) { - if (Twilio.username == null || Twilio.password == null) { + synchronized (Twilio.class) { + if (Twilio.restClient == null) { + Twilio.restClient = buildRestClient(); + } + } + } + + return Twilio.restClient; + } + + private static TwilioRestClient buildRestClient() { + if (Twilio.username == null || Twilio.password == null) { + if (credentialProvider == null) { throw new AuthenticationException( - "TwilioRestClient was used before AccountSid and AuthToken were set, please call Twilio.init()" + "Credentials have not been initialized or changed, please call Twilio.init()" ); } + } + TwilioRestClient.Builder builder; + if (credentialProvider != null) { + AuthStrategy authStrategy = credentialProvider.toAuthStrategy(); + builder = new TwilioRestClient.Builder(authStrategy); + } else { + builder = new TwilioRestClient.Builder(Twilio.username, Twilio.password); + } - TwilioRestClient.Builder builder = new TwilioRestClient.Builder(Twilio.username, Twilio.password); - if (Twilio.accountSid != null) { - builder.accountSid(Twilio.accountSid); - } - Twilio.restClient = builder.build(); + if (Twilio.accountSid != null) { + builder.accountSid(Twilio.accountSid); } - return Twilio.restClient; + if (userAgentExtensions != null) { + builder.userAgentExtensions(Twilio.userAgentExtensions); + } + builder.region(Twilio.region); + builder.edge(Twilio.edge); + + return builder.build(); } /** @@ -138,7 +267,9 @@ public static TwilioRestClient getRestClient() { * @param restClient rest client to use */ public static void setRestClient(final TwilioRestClient restClient) { - Twilio.restClient = restClient; + synchronized (Twilio.class) { + Twilio.restClient = restClient; + } } /** @@ -146,9 +277,13 @@ public static void setRestClient(final TwilioRestClient restClient) { * * @return the Twilio executor service */ - public static ListeningExecutorService getExecutorService() { + public static ExecutorService getExecutorService() { if (Twilio.executorService == null) { - Twilio.executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); + synchronized (Twilio.class) { + if (Twilio.executorService == null) { + Twilio.executorService = Executors.newCachedThreadPool(); + } + } } return Twilio.executorService; } @@ -158,25 +293,31 @@ public static ListeningExecutorService getExecutorService() { * * @param executorService executor service to use */ - public static void setExecutorService(final ListeningExecutorService executorService) { - Twilio.executorService = executorService; + public static void setExecutorService(final ExecutorService executorService) { + synchronized (Twilio.class) { + Twilio.executorService = executorService; + } } /** - * Validate that we can connect to the new SSL certificate posted on api.twilio.com. + * Validate that we can connect to the new SSL certificate posted on tls-test.twilio.com * - * @throws com.twilio.exception.CertificateValidationException if the connection fails + * @throws CertificateValidationException if the connection fails */ public static void validateSslCertificate() { final NetworkHttpClient client = new NetworkHttpClient(); - final Request request = new Request(HttpMethod.GET, "https://api.twilio.com:8443"); + validateSslCertificate(client); + } + + public static void validateSslCertificate(NetworkHttpClient client) { + final Request request = new Request(HttpMethod.GET, "https://tls-test.twilio.com:443"); try { final Response response = client.makeRequest(request); - if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { + if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { throw new CertificateValidationException( - "Unexpected response from certificate endpoint", request, response + "Unexpected response from certificate endpoint", request, response ); } } catch (final ApiException e) { @@ -190,4 +331,23 @@ public static void validateSslCertificate() { private static void invalidate() { Twilio.restClient = null; } + + private static void invalidateOAuthCreds() { + Twilio.credentialProvider = null; + } + + private static void invalidateBasicCreds() { + Twilio.username = null; + Twilio.password = null; + } + + /** + * Attempts to gracefully shutdown the ExecutorService if it is present. + */ + public static synchronized void destroy() { + if (executorService != null) { + executorService.shutdown(); + executorService = null; + } + } } diff --git a/src/main/java/com/twilio/annotations/Beta.java b/src/main/java/com/twilio/annotations/Beta.java new file mode 100644 index 0000000000..f80596f57c --- /dev/null +++ b/src/main/java/com/twilio/annotations/Beta.java @@ -0,0 +1,9 @@ +package com.twilio.annotations; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface Beta { + String value() default "This class/method is under beta and is subjected to change. Use with caution."; +} \ No newline at end of file diff --git a/src/main/java/com/twilio/auth_strategy/AuthStrategy.java b/src/main/java/com/twilio/auth_strategy/AuthStrategy.java new file mode 100644 index 0000000000..0478769b84 --- /dev/null +++ b/src/main/java/com/twilio/auth_strategy/AuthStrategy.java @@ -0,0 +1,17 @@ +package com.twilio.auth_strategy; + +import com.twilio.constant.EnumConstants; +import lombok.Getter; + +public abstract class AuthStrategy { + @Getter + private EnumConstants.AuthType authType; + + public AuthStrategy(EnumConstants.AuthType authType) { + this.authType = authType; + } + public abstract String getAuthString(); + + public abstract boolean requiresAuthentication(); + +} diff --git a/src/main/java/com/twilio/auth_strategy/BasicAuthStrategy.java b/src/main/java/com/twilio/auth_strategy/BasicAuthStrategy.java new file mode 100644 index 0000000000..569811bfee --- /dev/null +++ b/src/main/java/com/twilio/auth_strategy/BasicAuthStrategy.java @@ -0,0 +1,44 @@ +package com.twilio.auth_strategy; + +import com.twilio.constant.EnumConstants; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Objects; + +public class BasicAuthStrategy extends AuthStrategy { + private String username; + private String password; + + public BasicAuthStrategy(String username, String password) { + super(EnumConstants.AuthType.BASIC); + this.username = username; + this.password = password; + } + + @Override + public String getAuthString() { + String credentials = username + ":" + password; + String encoded = Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.US_ASCII)); + return "Basic " + encoded; + } + + @Override + public boolean requiresAuthentication() { + return true; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BasicAuthStrategy that = (BasicAuthStrategy) o; + return Objects.equals(username, that.username) && + Objects.equals(password, that.password); + } + + @Override + public int hashCode() { + return Objects.hash(username, password); + } +} diff --git a/src/main/java/com/twilio/auth_strategy/NoAuthStrategy.java b/src/main/java/com/twilio/auth_strategy/NoAuthStrategy.java new file mode 100644 index 0000000000..99941fa0fc --- /dev/null +++ b/src/main/java/com/twilio/auth_strategy/NoAuthStrategy.java @@ -0,0 +1,35 @@ +package com.twilio.auth_strategy; + +import com.twilio.constant.EnumConstants; + +// Does not have any state thus thread safe. +public class NoAuthStrategy extends AuthStrategy { + private static volatile NoAuthStrategy INSTANCE; + + private static volatile NoAuthStrategy instance; + + public static NoAuthStrategy getInstance() { + if (instance == null) { + synchronized (NoAuthStrategy.class) { + if (instance == null) { + instance = new NoAuthStrategy(); + } + } + } + return instance; + } + + private NoAuthStrategy() { + super(EnumConstants.AuthType.NO_AUTH); + } + + @Override + public String getAuthString() { + return ""; + } + + @Override + public boolean requiresAuthentication() { + return false; + } +} diff --git a/src/main/java/com/twilio/auth_strategy/TokenAuthStrategy.java b/src/main/java/com/twilio/auth_strategy/TokenAuthStrategy.java new file mode 100644 index 0000000000..d6a9146cdd --- /dev/null +++ b/src/main/java/com/twilio/auth_strategy/TokenAuthStrategy.java @@ -0,0 +1,66 @@ +package com.twilio.auth_strategy; + +import com.auth0.jwt.JWT; +import com.auth0.jwt.interfaces.DecodedJWT; +import com.twilio.constant.EnumConstants; +import com.twilio.http.bearertoken.TokenManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Date; +import java.util.Objects; + +public class TokenAuthStrategy extends AuthStrategy { + private String token; + private TokenManager tokenManager; + private static final Logger logger = LoggerFactory.getLogger(TokenAuthStrategy.class); + public TokenAuthStrategy(TokenManager tokenManager) { + super(EnumConstants.AuthType.TOKEN); + this.tokenManager = tokenManager; + } + + @Override + public String getAuthString() { + fetchToken(); + return "Bearer " + token; + } + + @Override + public boolean requiresAuthentication() { + return true; + } + + // Token-specific refresh logic + public void fetchToken() { + if (this.token == null || this.token.isEmpty() || isTokenExpired(this.token)) { + synchronized (TokenAuthStrategy.class){ + if (this.token == null || this.token.isEmpty() || isTokenExpired(this.token)) { + logger.info("Fetching new token for Apis"); + this.token = tokenManager.fetchAccessToken(); + } + } + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TokenAuthStrategy that = (TokenAuthStrategy) o; + return Objects.equals(token, that.token) && + Objects.equals(tokenManager, that.tokenManager); + } + @Override + public int hashCode() { + return Objects.hash(token, tokenManager); + } + + public boolean isTokenExpired(final String token) { + DecodedJWT jwt = JWT.decode(token); + Date expiresAt = jwt.getExpiresAt(); + // Add a buffer of 30 seconds + long bufferMilliseconds = 30 * 1000; + Date bufferExpiresAt = new Date(expiresAt.getTime() - bufferMilliseconds); + return bufferExpiresAt.before(new Date()); + } +} \ No newline at end of file diff --git a/src/main/java/com/twilio/base/Creator.java b/src/main/java/com/twilio/base/Creator.java index e9b36abbff..67c1453319 100644 --- a/src/main/java/com/twilio/base/Creator.java +++ b/src/main/java/com/twilio/base/Creator.java @@ -1,10 +1,9 @@ package com.twilio.base; -import com.google.common.util.concurrent.ListenableFuture; import com.twilio.Twilio; import com.twilio.http.TwilioRestClient; -import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; /** * Executor for creation of a resource. @@ -18,7 +17,7 @@ public abstract class Creator { * * @return future that resolves to requested object */ - public ListenableFuture createAsync() { + public CompletableFuture createAsync() { return createAsync(Twilio.getRestClient()); } @@ -28,12 +27,8 @@ public ListenableFuture createAsync() { * @param client client used to make request * @return future that resolves to requested object */ - public ListenableFuture createAsync(final TwilioRestClient client) { - return Twilio.getExecutorService().submit(new Callable() { - public T call() { - return create(client); - } - }); + public CompletableFuture createAsync(final TwilioRestClient client) { + return CompletableFuture.supplyAsync(() -> create(client), Twilio.getExecutorService()); } /** @@ -52,4 +47,12 @@ public T create() { * @return Requested object */ public abstract T create(final TwilioRestClient client); + + public TwilioResponse createWithResponse(final TwilioRestClient client) { + throw new UnsupportedOperationException("createWithResponse is not supported for this resource."); + } + + public TwilioResponse createWithResponse() { + return createWithResponse(Twilio.getRestClient()); + } } diff --git a/src/main/java/com/twilio/base/Deleter.java b/src/main/java/com/twilio/base/Deleter.java index 5092fc7876..a54531f3a1 100644 --- a/src/main/java/com/twilio/base/Deleter.java +++ b/src/main/java/com/twilio/base/Deleter.java @@ -1,10 +1,9 @@ package com.twilio.base; -import com.google.common.util.concurrent.ListenableFuture; import com.twilio.Twilio; import com.twilio.http.TwilioRestClient; -import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; /** * Executor for deletes of a resource. @@ -18,7 +17,7 @@ public abstract class Deleter { * * @return future that resolves to true if the object was deleted */ - public ListenableFuture deleteAsync() { + public CompletableFuture deleteAsync() { return deleteAsync(Twilio.getRestClient()); } @@ -28,12 +27,8 @@ public ListenableFuture deleteAsync() { * @param client client used to make request * @return future that resolves to true if the object was deleted */ - public ListenableFuture deleteAsync(final TwilioRestClient client) { - return Twilio.getExecutorService().submit(new Callable() { - public Boolean call() { - return delete(client); - } - }); + public CompletableFuture deleteAsync(final TwilioRestClient client) { + return CompletableFuture.supplyAsync(() -> delete(client), Twilio.getExecutorService()); } /** @@ -52,4 +47,12 @@ public boolean delete() { * @return true if the object was deleted */ public abstract boolean delete(final TwilioRestClient client); + + public TwilioResponse deleteWithResponse() { + return deleteWithResponse(Twilio.getRestClient()); + } + + public TwilioResponse deleteWithResponse(final TwilioRestClient client) { + throw new UnsupportedOperationException("deleteWithResponse is not supported for this resource."); + } } diff --git a/src/main/java/com/twilio/base/Fetcher.java b/src/main/java/com/twilio/base/Fetcher.java index 41c6ada582..4177f3141e 100644 --- a/src/main/java/com/twilio/base/Fetcher.java +++ b/src/main/java/com/twilio/base/Fetcher.java @@ -1,10 +1,9 @@ package com.twilio.base; -import com.google.common.util.concurrent.ListenableFuture; import com.twilio.Twilio; import com.twilio.http.TwilioRestClient; -import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; /** * Executor for fetches of a resource. @@ -18,7 +17,7 @@ public abstract class Fetcher { * * @return future that resolves to requested object */ - public ListenableFuture fetchAsync() { + public CompletableFuture fetchAsync() { return fetchAsync(Twilio.getRestClient()); } @@ -28,12 +27,8 @@ public ListenableFuture fetchAsync() { * @param client client used to make request * @return future that resolves to requested object */ - public ListenableFuture fetchAsync(final TwilioRestClient client) { - return Twilio.getExecutorService().submit(new Callable() { - public T call() { - return fetch(client); - } - }); + public CompletableFuture fetchAsync(final TwilioRestClient client) { + return CompletableFuture.supplyAsync(() -> fetch(client), Twilio.getExecutorService()); } /** @@ -52,4 +47,11 @@ public T fetch() { * @return Requested object */ public abstract T fetch(final TwilioRestClient client); + + public TwilioResponse fetchWithResponse() { + return fetchWithResponse(Twilio.getRestClient()); + } + public TwilioResponse fetchWithResponse(final TwilioRestClient client) { + throw new UnsupportedOperationException("fetchWithResponse is not supported for this resource."); + } } diff --git a/src/main/java/com/twilio/base/Page.java b/src/main/java/com/twilio/base/Page.java index 81ecd4fcd4..ff580d0d37 100644 --- a/src/main/java/com/twilio/base/Page.java +++ b/src/main/java/com/twilio/base/Page.java @@ -2,8 +2,6 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Joiner; -import com.google.common.base.Strings; import com.twilio.exception.ApiConnectionException; import java.io.IOException; @@ -11,18 +9,18 @@ import java.util.List; public class Page { - private final List records; - private final String firstPageUrl; - private final String firstPageUri; - private final String nextPageUrl; - private final String nextPageUri; - private final String previousPageUrl; - private final String previousPageUri; - private final String url; - private final String uri; - private final int pageSize; - - private Page(Builder b) { + protected final List records; + protected final String firstPageUrl; + protected final String firstPageUri; + protected final String nextPageUrl; + protected final String nextPageUri; + protected final String previousPageUrl; + protected final String previousPageUri; + protected final String url; + protected final String uri; + protected final int pageSize; + + protected Page(Builder b) { this.records = b.records; this.firstPageUri = b.firstPageUri; this.firstPageUrl = b.firstPageUrl; @@ -35,8 +33,8 @@ private Page(Builder b) { this.pageSize = b.pageSize; } - private String urlFromUri(String domain, String region, String uri) { - return "https://" + Joiner.on(".").skipNulls().join(domain, region, "twilio", "com") + uri; + protected String urlFromUri(String domain, String uri) { + return "https://" + domain + ".twilio.com" + uri; } public List getRecords() { @@ -47,45 +45,42 @@ public List getRecords() { * Generate first page url for a list result. * * @param domain domain to use - * @param region region to use * @return the first page url */ - public String getFirstPageUrl(String domain, String region) { + public String getFirstPageUrl(String domain) { if (firstPageUrl != null) { return firstPageUrl; } - return urlFromUri(domain, region, firstPageUri); + return urlFromUri(domain, firstPageUri); } /** * Generate next page url for a list result. * * @param domain domain to use - * @param region region to use * @return the next page url */ - public String getNextPageUrl(String domain, String region) { + public String getNextPageUrl(String domain) { if (nextPageUrl != null) { return nextPageUrl; } - return urlFromUri(domain, region, nextPageUri); + return urlFromUri(domain, nextPageUri); } /** * Generate previous page url for a list result. * * @param domain domain to use - * @param region region to use * @return the previous page url */ - public String getPreviousPageUrl(String domain, String region) { + public String getPreviousPageUrl(String domain) { if (previousPageUrl != null) { return previousPageUrl; } - return urlFromUri(domain, region, previousPageUri); + return urlFromUri(domain, previousPageUri); } public int getPageSize() { @@ -96,29 +91,36 @@ public int getPageSize() { * Generate page url for a list result. * * @param domain domain to use - * @param region region to use * @return the page url */ - public String getUrl(String domain, String region) { + public String getUrl(String domain) { if (url != null) { return url; } - return urlFromUri(domain, region, uri); + return urlFromUri(domain, uri); + } + + public String previousQueryString() { + return ""; + } + + public String nextQueryString() { + return ""; } public boolean hasNextPage() { - return !Strings.isNullOrEmpty(nextPageUri) || !Strings.isNullOrEmpty(nextPageUrl); + return (nextPageUri != null && !nextPageUri.isEmpty()) || (nextPageUrl != null && !nextPageUrl.isEmpty()); } /** * Create a new page of data from a json blob. * - * @param recordKey key which holds the records - * @param json json blob + * @param recordKey key which holds the records + * @param json json blob * @param recordType resource type - * @param mapper json parser - * @param record class type + * @param mapper json parser + * @param record class type * @return a page of records of type T */ public static Page fromJson(String recordKey, String json, Class recordType, ObjectMapper mapper) { @@ -175,8 +177,9 @@ private static Page buildPage(JsonNode root, List results) { private static Page buildNextGenPage(JsonNode root, List results) { JsonNode meta = root.get("meta"); - Builder builder = new Builder().url(meta.get("url").asText()); - + Builder builder = new Builder<>(); + if(meta != null && meta.get("url") != null) { + builder = builder.url(meta.get("url").asText()); JsonNode nextPageNode = meta.get("next_page_url"); if (!nextPageNode.isNull()) { builder.nextPageUrl(nextPageNode.asText()); @@ -198,11 +201,12 @@ private static Page buildNextGenPage(JsonNode root, List results) { } else { builder.pageSize(results.size()); } + } return builder.records(results).build(); } - private static class Builder { + protected static class Builder { private List records; private String firstPageUrl; private String firstPageUri; diff --git a/src/main/java/com/twilio/base/Patcher.java b/src/main/java/com/twilio/base/Patcher.java new file mode 100644 index 0000000000..4b00a71276 --- /dev/null +++ b/src/main/java/com/twilio/base/Patcher.java @@ -0,0 +1,57 @@ +package com.twilio.base; + +import com.twilio.Twilio; +import com.twilio.http.TwilioRestClient; + +import java.util.concurrent.CompletableFuture; + +/** + * Executor for updates of a resource. + * + * @param type of the resource + */ +public abstract class Patcher { + + /** + * Execute an async request using default client. + * + * @return future that resolves to requested object + */ + public CompletableFuture patchAsync() { + return patchAsync(Twilio.getRestClient()); + } + + /** + * Execute an async request using specified client. + * + * @param client client used to make request + * @return future that resolves to requested object + */ + public CompletableFuture patchAsync(final TwilioRestClient client) { + return CompletableFuture.supplyAsync(() -> patch(client), Twilio.getExecutorService()); + } + + /** + * Execute a request using default client. + * + * @return Requested object + */ + public T patch() { + return patch(Twilio.getRestClient()); + } + + /** + * Execute a request using specified client. + * + * @param client client used to make request + * @return Requested object + */ + public abstract T patch(final TwilioRestClient client); + + public TwilioResponse patchWithResponse() { + return patchWithResponse(Twilio.getRestClient()); + } + public TwilioResponse patchWithResponse(final TwilioRestClient client) { + throw new UnsupportedOperationException("patchWithResponse is not supported for this resource."); + } +} diff --git a/src/main/java/com/twilio/base/Reader.java b/src/main/java/com/twilio/base/Reader.java index 6684db21a1..0c2ef93703 100644 --- a/src/main/java/com/twilio/base/Reader.java +++ b/src/main/java/com/twilio/base/Reader.java @@ -1,10 +1,9 @@ package com.twilio.base; -import com.google.common.util.concurrent.ListenableFuture; import com.twilio.Twilio; import com.twilio.http.TwilioRestClient; -import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; /** * Executor for listing of a resource. @@ -33,12 +32,20 @@ public ResourceSet read() { */ public abstract ResourceSet read(final TwilioRestClient client); + public ResourceSetResponse readWithResponse() { + return readWithResponse(Twilio.getRestClient()); + } + + public ResourceSetResponse readWithResponse(final TwilioRestClient client) { + throw new UnsupportedOperationException("readWithResponse is not supported for this resource."); + } + /** * Execute an async request using default client. * * @return future that resolves to the ResourceSet of objects */ - public ListenableFuture> readAsync() { + public CompletableFuture> readAsync() { return readAsync(Twilio.getRestClient()); } @@ -48,12 +55,8 @@ public ListenableFuture> readAsync() { * @param client client used to make request * @return future that resolves to the ResourceSet of objects */ - public ListenableFuture> readAsync(final TwilioRestClient client) { - return Twilio.getExecutorService().submit(new Callable>() { - public ResourceSet call() { - return read(client); - } - }); + public CompletableFuture> readAsync(final TwilioRestClient client) { + return CompletableFuture.supplyAsync(() -> read(client), Twilio.getExecutorService()); } /** @@ -87,7 +90,7 @@ public Page getPage(final String targetUrl) { * Retrieve the target page of resources. * * @param targetUrl API-generated URL for the requested results page - * @param client client used to fetch + * @param client client used to fetch * @return Page containing the target pageSize of resources */ public abstract Page getPage(final String targetUrl, final TwilioRestClient client); @@ -105,7 +108,7 @@ public Page nextPage(final Page page) { /** * Fetch the following page of resources using specified client. * - * @param page current page of resources + * @param page current page of resources * @param client client used to fetch * @return Page containing the next pageSize of resources */ @@ -124,7 +127,7 @@ public Page previousPage(final Page page) { /** * Fetch the prior page of resources using specified client. * - * @param page current page of resources + * @param page current page of resources * @param client client used to fetch * @return Page containing the previous pageSize of resources */ @@ -153,10 +156,9 @@ public Reader limit(final long limit) { this.limit = limit; if (this.pageSize == null) { - this.pageSize = (new Long(this.limit)).intValue(); + this.pageSize = this.limit.intValue(); } return this; } - } diff --git a/src/main/java/com/twilio/base/ResourceDeleter.java b/src/main/java/com/twilio/base/ResourceDeleter.java new file mode 100644 index 0000000000..3c5d2f8778 --- /dev/null +++ b/src/main/java/com/twilio/base/ResourceDeleter.java @@ -0,0 +1,37 @@ +package com.twilio.base; + +import com.twilio.Twilio; +import com.twilio.http.TwilioRestClient; + +import java.util.concurrent.CompletableFuture; + +/** + * Executor for deletes of a resource that return a response object. + * + * @param type of the resource + * @param type of the delete response + */ +public abstract class ResourceDeleter { + + public CompletableFuture deleteAsync() { + return deleteAsync(Twilio.getRestClient()); + } + + public CompletableFuture deleteAsync(final TwilioRestClient client) { + return CompletableFuture.supplyAsync(() -> delete(client), Twilio.getExecutorService()); + } + + public R delete() { + return delete(Twilio.getRestClient()); + } + + public abstract R delete(final TwilioRestClient client); + + public TwilioResponse deleteWithResponse() { + return deleteWithResponse(Twilio.getRestClient()); + } + + public TwilioResponse deleteWithResponse(final TwilioRestClient client) { + throw new UnsupportedOperationException("deleteWithResponse is not supported for this resource."); + } +} diff --git a/src/main/java/com/twilio/base/ResourceSet.java b/src/main/java/com/twilio/base/ResourceSet.java index 37fec6c969..6e5608adce 100644 --- a/src/main/java/com/twilio/base/ResourceSet.java +++ b/src/main/java/com/twilio/base/ResourceSet.java @@ -14,6 +14,7 @@ public class ResourceSet implements Iterable { private final Reader reader; private final TwilioRestClient client; + private final Page firstPage; // Store reference to first page to enable multiple iterations private boolean autoPaging; private long pages = 1; @@ -32,6 +33,7 @@ public class ResourceSet implements Iterable { public ResourceSet(final Reader reader, final TwilioRestClient client, final Page page) { this.reader = reader; this.client = client; + this.firstPage = page; // Save first page to allow resetting iterator state this.page = page; this.iterator = page.getRecords().iterator(); this.autoPaging = true; @@ -74,6 +76,12 @@ public long getPageLimit() { @Override public Iterator iterator() { + // Reset state to allow multiple iterations + this.processed = 0; + this.pages = 1; + this.page = this.firstPage; // Reset to first page for new iteration + this.iterator = this.firstPage.getRecords().iterator(); // Reset iterator to start of first page + return new ResourceSetIterator<>(this); } diff --git a/src/main/java/com/twilio/base/ResourceSetResponse.java b/src/main/java/com/twilio/base/ResourceSetResponse.java new file mode 100644 index 0000000000..74482a6fd4 --- /dev/null +++ b/src/main/java/com/twilio/base/ResourceSetResponse.java @@ -0,0 +1,167 @@ +package com.twilio.base; + +import org.apache.hc.core5.http.Header; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * A wrapper around ResourceSet that preserves HTTP response metadata (headers and status code) + * from the initial page request while enabling pagination across multiple pages. + * + *

This class implements Iterable to allow direct iteration over resources while + * providing access to the response metadata from the first page.

+ * + * @param type of the resource + */ +public class ResourceSetResponse implements Iterable { + + private final ResourceSet resourceSet; + private final int statusCode; + private final Map headers; + + /** + * Create a ResourceSetResponse with the resource set, status code, and headers. + * + * @param resourceSet the underlying resource set + * @param statusCode HTTP status code from the first page response + * @param headers response headers from the first page as array + */ + public ResourceSetResponse(final ResourceSet resourceSet, final int statusCode, final Header[] headers) { + this.resourceSet = resourceSet; + this.statusCode = statusCode; + this.headers = convertHeaders(headers); + } + + /** + * Get the underlying ResourceSet. + * + * @return the resource set + */ + public ResourceSet getResourceSet() { + return resourceSet; + } + + /** + * Get the HTTP status code from the first page response. + * + * @return the status code + */ + public int getStatusCode() { + return statusCode; + } + + /** + * Get all response headers from the first page as a map. + * + * @return map of header names to values + */ + public Map getHeaders() { + return Collections.unmodifiableMap(headers); + } + + /** + * Get a specific header value by name. + * + * @param name the header name + * @return the header value, or null if not present + */ + public String getHeader(final String name) { + return headers.get(name); + } + + /** + * Check if auto-paging is enabled. + * + * @return true if auto-paging is enabled + */ + public boolean isAutoPaging() { + return resourceSet.isAutoPaging(); + } + + /** + * Enable or disable auto-paging. + * + * @param autoPaging whether to enable auto-paging + * @return this ResourceSetResponse for method chaining + */ + public ResourceSetResponse setAutoPaging(final boolean autoPaging) { + resourceSet.setAutoPaging(autoPaging); + return this; + } + + /** + * Get the page size. + * + * @return the page size + */ + public Integer getPageSize() { + return resourceSet.getPageSize(); + } + + /** + * Set the page size. + * + * @param pageSize the page size + * @return this ResourceSetResponse for method chaining + */ + public ResourceSetResponse setPageSize(final int pageSize) { + resourceSet.setPageSize(pageSize); + return this; + } + + /** + * Get the limit on total records. + * + * @return the limit + */ + public Long getLimit() { + return resourceSet.getLimit(); + } + + /** + * Set the limit on total records. + * + * @param limit the maximum number of records to return + * @return this ResourceSetResponse for method chaining + */ + public ResourceSetResponse setLimit(final long limit) { + resourceSet.setLimit(limit); + return this; + } + + /** + * Get the page limit. + * + * @return the page limit + */ + public long getPageLimit() { + return resourceSet.getPageLimit(); + } + + @Override + public Iterator iterator() { + return resourceSet.iterator(); + } + + private Map convertHeaders(final Header[] headerArray) { + Map headerMap = new HashMap<>(); + if (headerArray != null) { + for (Header header : headerArray) { + headerMap.put(header.getName(), header.getValue()); + } + } + return headerMap; + } + + @Override + public String toString() { + return "ResourceSetResponse{" + + "statusCode=" + statusCode + + ", headers=" + headers + + ", resourceSet=" + resourceSet + + '}'; + } +} diff --git a/src/main/java/com/twilio/base/TokenPaginationPage.java b/src/main/java/com/twilio/base/TokenPaginationPage.java new file mode 100644 index 0000000000..6512bfb308 --- /dev/null +++ b/src/main/java/com/twilio/base/TokenPaginationPage.java @@ -0,0 +1,211 @@ +package com.twilio.base; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import lombok.Getter; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class TokenPaginationPage extends Page { + @Getter + private final String key; + private final String nextToken; + private final String previousToken; + + private TokenPaginationPage(Builder b) { + super(b); + this.key = b.key; + this.nextToken = b.nextToken; + this.previousToken = b.previousToken; + } + + // adding custom getter and not using lombok to handle null token + // when token is null, lombok getter returns "null" not a null object + public String getNextToken() { + return nextToken; + } + + public String getPreviousToken() { + return previousToken; + } + + @Override + public String previousQueryString() { + return getQueryString(previousToken); + } + + @Override + public String nextQueryString() { + return getQueryString(nextToken); + } + + private void addQueryOperators(StringBuilder query) { + if(query.length() == 0) { + query.append("?"); + } else { + query.append("&"); + } + } + + private String getQueryString(String pageToken) { + StringBuilder query = new StringBuilder(); + if (pageSize > 0) { + addQueryOperators(query); + query.append("pageSize=").append(pageSize); + } + if(pageToken != null && !pageToken.isEmpty()) { + addQueryOperators(query); + query.append("pageToken=").append(pageToken); + } + return query.toString(); + } + + /** + * Checks if there is a next page of records available. + * + * @return true if a next page is available, false otherwise + */ + @Override + public boolean hasNextPage() { + return (nextToken != null && !nextToken.isEmpty()); + } + + + /** + * Create a new page of data from a json blob. + * + * @param recordKey key which holds the records + * @param json json blob + * @param recordType resource type + * @param mapper json parser + * @param record class type + * @return a page of records of type T + */ + public static TokenPaginationPage fromJson(String recordKey, String json, Class recordType, ObjectMapper mapper) { + try { + List results = new ArrayList<>(); + JsonNode root = mapper.readTree(json); + try { + JsonNode meta = root.get("meta"); + + if (meta == null) { + return buildPageWithoutMeta(recordKey, root, results, recordType, mapper); + } + String key = meta.get("key").asText(); + JsonNode records = root.get(key); + + if ( records == null ) + throw new NullPointerException("records not found in response"); + + if (records != null && records.isArray() && records.size() > 0 && !records.get(0).isObject()) { + // Records are primitives (e.g., strings/IDs); treat the entire + // response envelope as a single record of type T. + results.add(mapper.readValue(json, recordType)); + } else if (records != null) { + for (final JsonNode record : records) { + results.add(mapper.readValue(record.toString(), recordType)); + } + } + + return buildPage(meta, results); + } catch (NullPointerException e) { + throw new ApiException("Key not found", e); + } + + } catch (final IOException e) { + throw new ApiConnectionException( + "Unable to deserialize response: " + e.getMessage() + "\nJSON: " + json, e + ); + } + } + + private static TokenPaginationPage buildPageWithoutMeta( + String recordKey, JsonNode root, List results, Class recordType, ObjectMapper mapper) throws IOException { + JsonNode records = root.get(recordKey); + + if (records == null) { + throw new NullPointerException("records not found in response"); + } + + if (records.isArray() && records.size() > 0 && !records.get(0).isObject()) { + // Records are primitives; treat the entire response as a single record + results.add(mapper.readValue(root.toString(), recordType)); + } else { + for (final JsonNode record : records) { + results.add(mapper.readValue(record.toString(), recordType)); + } + } + + // Build a non-paginated page using the recordKey + return new Builder() + .key(recordKey) + .records(results) + .pageSize(results.size()) + .build(); + } + + private static TokenPaginationPage buildPage(JsonNode meta, List results) { + try { + Builder builder = new Builder() + .key(meta.get("key").asText()); + + JsonNode nextTokenNode = meta.get("nextToken"); + if (nextTokenNode != null && !nextTokenNode.isNull()) { + builder.nextToken(nextTokenNode.asText()); + } + + JsonNode previousTokenNode = meta.get("previousToken"); + if (previousTokenNode != null && !previousTokenNode.isNull()) { + builder.previousToken(previousTokenNode.asText()); + } + + JsonNode pageSizeNode = meta.get("pageSize"); + builder.pageSize(pageSizeNode.asInt()); + + return builder.records(results).build(); + } catch (NullPointerException e) { + throw new ApiException("Key not found", e); + } + } + + protected static class Builder extends Page.Builder { + private String key; + private String nextToken; + private String previousToken; + + @Override + public Builder records(List records) { + super.records(records); + return this; + } + + @Override + public Builder pageSize(int pageSize) { + super.pageSize(pageSize); + return this; + } + + public Builder key(String key) { + this.key = key; + return this; + } + + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public TokenPaginationPage build() { + return new TokenPaginationPage<>(this); + } + } +} diff --git a/src/main/java/com/twilio/base/TwilioResponse.java b/src/main/java/com/twilio/base/TwilioResponse.java new file mode 100644 index 0000000000..3a235fcc8a --- /dev/null +++ b/src/main/java/com/twilio/base/TwilioResponse.java @@ -0,0 +1,70 @@ +package com.twilio.base; + +import org.apache.hc.core5.http.Header; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Wrapper class that contains the resource along with response metadata + * including status code and headers. + * + * @param type of the resource + */ +public class TwilioResponse { + + private final T content; + private final int statusCode; + private final Map headers; + + /** + * Create a TwilioResponse with content, status code, and headers. + * + * @param content the resource content + * @param statusCode HTTP status code + * @param headers response headers as array + */ + public TwilioResponse(final T content, final int statusCode, final Header[] headers) { + this.content = content; + this.statusCode = statusCode; + this.headers = convertHeaders(headers); + } + + /** + * Get the resource content. + * + * @return the resource content + */ + public T getContent() { + return content; + } + + /** + * Get the HTTP status code. + * + * @return the status code + */ + public int getStatusCode() { + return statusCode; + } + + /** + * Get the response headers as a map. + * + * @return map of header names to values + */ + public Map getHeaders() { + return Collections.unmodifiableMap(headers); + } + + private Map convertHeaders(final Header[] headerArray) { + Map headerMap = new HashMap<>(); + if (headerArray != null) { + for (Header header : headerArray) { + headerMap.put(header.getName(), header.getValue()); + } + } + return headerMap; + } +} diff --git a/src/main/java/com/twilio/base/Updater.java b/src/main/java/com/twilio/base/Updater.java index 22f0479da8..458d979079 100644 --- a/src/main/java/com/twilio/base/Updater.java +++ b/src/main/java/com/twilio/base/Updater.java @@ -1,10 +1,9 @@ package com.twilio.base; -import com.google.common.util.concurrent.ListenableFuture; import com.twilio.Twilio; import com.twilio.http.TwilioRestClient; -import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; /** * Executor for updates of a resource. @@ -18,7 +17,7 @@ public abstract class Updater { * * @return future that resolves to requested object */ - public ListenableFuture updateAsync() { + public CompletableFuture updateAsync() { return updateAsync(Twilio.getRestClient()); } @@ -28,12 +27,8 @@ public ListenableFuture updateAsync() { * @param client client used to make request * @return future that resolves to requested object */ - public ListenableFuture updateAsync(final TwilioRestClient client) { - return Twilio.getExecutorService().submit(new Callable() { - public T call() { - return update(client); - } - }); + public CompletableFuture updateAsync(final TwilioRestClient client) { + return CompletableFuture.supplyAsync(() -> update(client), Twilio.getExecutorService()); } /** @@ -52,4 +47,12 @@ public T update() { * @return Requested object */ public abstract T update(final TwilioRestClient client); + + public TwilioResponse updateWithResponse() { + return updateWithResponse(Twilio.getRestClient()); + } + + public TwilioResponse updateWithResponse(final TwilioRestClient client) { + throw new UnsupportedOperationException("updateWithResponse is not supported for this resource."); + } } diff --git a/src/main/java/com/twilio/constant/EnumConstants.java b/src/main/java/com/twilio/constant/EnumConstants.java new file mode 100644 index 0000000000..f5f8438cf8 --- /dev/null +++ b/src/main/java/com/twilio/constant/EnumConstants.java @@ -0,0 +1,40 @@ +package com.twilio.constant; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +public class EnumConstants { + + @Getter + @RequiredArgsConstructor + public enum ContentType { + JSON("application/json"), + FORM_URLENCODED("application/x-www-form-urlencoded"), + MULTIPART_FORM_DATA("multipart/form-data"); + + private final String value; + } + + @Getter + @RequiredArgsConstructor + public enum AuthType { + NO_AUTH("noauth"), + BASIC("basic"), + TOKEN("token"), + API_KEY("api_key"), + CLIENT_CREDENTIALS("client_credentials"); + + private final String value; + } + + @Getter + @RequiredArgsConstructor + public enum ParameterType { + QUERY("Query"), + HEADER("Header"), + URLENCODED("Urlencoded"), + JSON("Json"); + + private final String value; + } +} diff --git a/src/main/java/com/twilio/converter/Converter.java b/src/main/java/com/twilio/converter/Converter.java index 62916d1eb1..2a9a5befbf 100644 --- a/src/main/java/com/twilio/converter/Converter.java +++ b/src/main/java/com/twilio/converter/Converter.java @@ -4,19 +4,69 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; import java.util.Map; public class Converter { private static final ObjectMapper MAPPER = new ObjectMapper(); + /** + * Convert a generic object to a JSON String. + * + * @param value object to convert + * @return converted JSON string + */ + public static String objectToJson(Object value) { + if (value == null) { + return "null"; + } + + // Primitive wrappers + if (value instanceof String || value instanceof Number || value instanceof Boolean || value instanceof Character) { + return value.toString(); + } + // Arrays: handle any arrays (primitive or object) + if (value.getClass().isArray()) { + // For primitive arrays, handle differently + if (value instanceof int[]) return Arrays.toString((int[]) value); + if (value instanceof long[]) return Arrays.toString((long[]) value); + if (value instanceof double[]) return Arrays.toString((double[]) value); + if (value instanceof float[]) return Arrays.toString((float[]) value); + if (value instanceof boolean[]) return Arrays.toString((boolean[]) value); + if (value instanceof byte[]) return Arrays.toString((byte[]) value); + if (value instanceof short[]) return Arrays.toString((short[]) value); + if (value instanceof char[]) return Arrays.toString((char[]) value); + // Object array + return Arrays.deepToString((Object[]) value); + } + + // Collection (List, Set, etc.) + if (value instanceof Collection || value instanceof Map) { + try { + return MAPPER.writeValueAsString(value); + } catch (JsonProcessingException e) { + return value.toString(); + } + } + // Fallback: Try JSON, else toString + try { + return MAPPER.writeValueAsString(value); + } catch (JsonProcessingException e) { + return value.toString(); + } + } + /** * Convert a map to a JSON String. * * @param map map to convert * @return converted JSON string */ - public static String mapToJson(final Map map) { + public static String mapToJson(final Map map) { try { return MAPPER.writeValueAsString(map); } catch (JsonProcessingException e) { @@ -24,4 +74,18 @@ public static String mapToJson(final Map map) { } } + /** + * Convert a JSON String to a map. + * + * @param json string representing the json hash map + * @return HashMap read + */ + public static Map jsonToMap(final String json) { + try { + return MAPPER.readValue(json, HashMap.class); + } catch (IOException e) { + return null; + } + } + } diff --git a/src/main/java/com/twilio/converter/DateConverter.java b/src/main/java/com/twilio/converter/DateConverter.java index e8502ba496..c508611c66 100644 --- a/src/main/java/com/twilio/converter/DateConverter.java +++ b/src/main/java/com/twilio/converter/DateConverter.java @@ -1,61 +1,56 @@ package com.twilio.converter; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.LocalDate; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; - +import java.time.LocalDate; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.Locale; public class DateConverter { private static final String DATE_PATTERN = "yyyy-MM-dd"; private static final String RFC2822_DATE_TIME = "EEE, dd MMM yyyy HH:mm:ss Z"; - private static final String ISO8601_DATE_TIME = "yyyy-MM-dd'T'HH:mm:ssZ"; private static final DateTimeFormatter DATE_FORMATTER = - DateTimeFormat.forPattern(DATE_PATTERN).withZone(DateTimeZone.UTC); + DateTimeFormatter.ofPattern(DATE_PATTERN); private static final DateTimeFormatter RFC2822_DATE_TIME_FORMATTER = - DateTimeFormat.forPattern(RFC2822_DATE_TIME).withZone(DateTimeZone.UTC).withLocale(new Locale("en_US")); + DateTimeFormatter.ofPattern(RFC2822_DATE_TIME).withLocale(new Locale("en_US")); - private static final DateTimeFormatter ISO8601_DATE_TIME_FORMATTER = - DateTimeFormat.forPattern(ISO8601_DATE_TIME).withZone(DateTimeZone.UTC); + private static final DateTimeFormatter ISO8601_DATE_TIME_FORMATTER =DateTimeFormatter.ISO_ZONED_DATE_TIME; /** - * Parse a @see org.joda.time.DateTime from a String. + * Parse a @see java.time.ZonedDateTime from a String. * * @param dateTimeString timestamp to parse - * @return parsed @see org.joda.time.DateTime if parseable, null otherwise + * @return parsed @see java.time.ZonedDateTime if parseable, null otherwise */ - public static DateTime rfc2822DateTimeFromString(String dateTimeString) { + public static ZonedDateTime rfc2822DateTimeFromString(String dateTimeString) { try { - return DateTime.parse(dateTimeString, RFC2822_DATE_TIME_FORMATTER); + return ZonedDateTime.parse(dateTimeString, RFC2822_DATE_TIME_FORMATTER); } catch (Exception e) { return null; } } /** - * Parse a @see org.joda.time.DateTime from a String. + * Parse a @see java.time.ZonedDateTime from a String. * * @param dateTimeString timestamp to parse - * @return parsed @see org.joda.time.DateTime if parseable, null otherwise + * @return parsed @see java.time.ZonedDateTime if parseable, null otherwise */ - public static DateTime iso8601DateTimeFromString(String dateTimeString) { + public static ZonedDateTime iso8601DateTimeFromString(String dateTimeString) { try { - return DateTime.parse(dateTimeString, ISO8601_DATE_TIME_FORMATTER); + return ZonedDateTime.parse(dateTimeString, ISO8601_DATE_TIME_FORMATTER); } catch (Exception e) { return null; } } /** - * Parse a @see org.joda.time.LocalDate from a String. - * + * Parse a @see java.time.LocalDate from a String. + * * @param dateString the date String - * @return parsed @see org.joda.time.LocalDate if parseable, null otherwise; + * @return parsed @see java.time.LocalDate if parseable, null otherwise; */ public static LocalDate localDateFromString(String dateString) { try { @@ -66,14 +61,14 @@ public static LocalDate localDateFromString(String dateString) { } /** - * Format a @see org.joda.time.LocalDate. + * Format a @see java.time.LocalDate. * * @param date date to format * @return formatted date in YYYY-MM-DD */ public static String dateStringFromLocalDate(LocalDate date) { try { - return date.toString(DATE_PATTERN); + return date.format(DATE_FORMATTER); } catch (Exception e) { return null; } diff --git a/src/main/java/com/twilio/converter/ISO8601Deserializer.java b/src/main/java/com/twilio/converter/ISO8601Deserializer.java new file mode 100644 index 0000000000..a867287b63 --- /dev/null +++ b/src/main/java/com/twilio/converter/ISO8601Deserializer.java @@ -0,0 +1,17 @@ +package com.twilio.converter; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +import java.io.IOException; +import java.time.ZonedDateTime; + +// open-api spec "format: date-time" +public class ISO8601Deserializer extends JsonDeserializer { + @Override + public ZonedDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException { + String dateString = parser.getText(); + return DateConverter.iso8601DateTimeFromString(dateString); + } +} \ No newline at end of file diff --git a/src/main/java/com/twilio/converter/ISO8601Serializer.java b/src/main/java/com/twilio/converter/ISO8601Serializer.java new file mode 100644 index 0000000000..f1f97a8986 --- /dev/null +++ b/src/main/java/com/twilio/converter/ISO8601Serializer.java @@ -0,0 +1,17 @@ +package com.twilio.converter; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import java.io.IOException; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +// open-api spec "format: date-time" +public class ISO8601Serializer extends JsonSerializer { + @Override + public void serialize(ZonedDateTime value, JsonGenerator gen, SerializerProvider provider) throws IOException { + gen.writeString(value.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); + } +} + diff --git a/src/main/java/com/twilio/converter/LocalDateDeserializer.java b/src/main/java/com/twilio/converter/LocalDateDeserializer.java new file mode 100644 index 0000000000..a8a2260a4d --- /dev/null +++ b/src/main/java/com/twilio/converter/LocalDateDeserializer.java @@ -0,0 +1,17 @@ +package com.twilio.converter; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +import java.io.IOException; +import java.time.LocalDate; + +// open-api spec "format: date" +public class LocalDateDeserializer extends JsonDeserializer { + @Override + public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException { + String dateString = parser.getText(); + return DateConverter.localDateFromString(dateString); + } +} \ No newline at end of file diff --git a/src/main/java/com/twilio/converter/PrefixedCollapsibleMap.java b/src/main/java/com/twilio/converter/PrefixedCollapsibleMap.java index d772897523..e0727a7dd9 100644 --- a/src/main/java/com/twilio/converter/PrefixedCollapsibleMap.java +++ b/src/main/java/com/twilio/converter/PrefixedCollapsibleMap.java @@ -1,8 +1,5 @@ package com.twilio.converter; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -17,13 +14,13 @@ private static Map flatten( List previous ) { for (Map.Entry entry : map.entrySet()) { - List next = Lists.newArrayList(previous); + List next = new ArrayList<>(previous); next.add(entry.getKey()); if (entry.getValue() instanceof Map) { - flatten((Map)entry.getValue(), result, next); + flatten((Map) entry.getValue(), result, next); } else { - result.put(Joiner.on('.').join(next), entry.getValue().toString()); + result.put(String.join(".", next), entry.getValue().toString()); } } @@ -34,7 +31,7 @@ private static Map flatten( * Flatten a Map of String, Object into a Map of String, String where keys are '.' separated * and prepends a key. * - * @param map map to transform + * @param map map to transform * @param prefix key to prepend * @return flattened map */ @@ -52,5 +49,4 @@ public static Map serialize(Map map, String pref return result; } - } diff --git a/src/main/java/com/twilio/converter/Promoter.java b/src/main/java/com/twilio/converter/Promoter.java index 497513c6c9..dd5e5638da 100644 --- a/src/main/java/com/twilio/converter/Promoter.java +++ b/src/main/java/com/twilio/converter/Promoter.java @@ -1,6 +1,7 @@ package com.twilio.converter; import com.twilio.type.PhoneNumber; +import com.twilio.type.Twiml; import java.net.URI; import java.net.URISyntaxException; @@ -18,7 +19,7 @@ public class Promoter { public static URI uriFromString(final String url) { try { return new URI(url); - } catch (URISyntaxException e) { + } catch (URISyntaxException | NullPointerException e) { return null; } } @@ -33,6 +34,18 @@ public static PhoneNumber phoneNumberFromString(final String pn) { return new PhoneNumber(pn); } + /** + * Create a @see com.twilio.types.Twiml from a string + * + * @param twiml Twiml to convert + * @return built @see com.twilio.types.Twiml + */ + public static Twiml twimlFromString(final String twiml) { + return new Twiml(twiml); + } + + + /** * Create a list from a single element. * diff --git a/src/main/java/com/twilio/converter/RFC2822Deserializer.java b/src/main/java/com/twilio/converter/RFC2822Deserializer.java new file mode 100644 index 0000000000..56eb3e891d --- /dev/null +++ b/src/main/java/com/twilio/converter/RFC2822Deserializer.java @@ -0,0 +1,17 @@ +package com.twilio.converter; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +import java.io.IOException; +import java.time.ZonedDateTime; + +// open-api spec "format: date-time-rfc-2822" +public class RFC2822Deserializer extends JsonDeserializer { + @Override + public ZonedDateTime deserialize(JsonParser parser, DeserializationContext context) throws IOException { + String dateString = parser.getText(); + return DateConverter.rfc2822DateTimeFromString(dateString); + } +} \ No newline at end of file diff --git a/src/main/java/com/twilio/converter/Serializer.java b/src/main/java/com/twilio/converter/Serializer.java new file mode 100644 index 0000000000..4687a184fa --- /dev/null +++ b/src/main/java/com/twilio/converter/Serializer.java @@ -0,0 +1,104 @@ +package com.twilio.converter; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.http.Request; +import java.io.IOException; + +import java.time.LocalDate; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Map; +import java.util.Objects; + +public class Serializer { + + public static void toString(Request request, String key, T value, ParameterType parameterType) { + if (value == null) return; + + String stringValue = convertToString(value); + addParamToRequest(request, key, stringValue, parameterType); + } + + public static void toString(Request request, ObjectMapper mapper, T value) { + if (value == null) return; + + if (mapper == null) { + throw new IllegalArgumentException("ObjectMapper is required for JSON serialization"); + } + + String stringValue = toJson(value, mapper); + request.setBody(stringValue); + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + private static String convertToString(T value) { + if (value instanceof Map) { + return Converter.mapToJson((Map) value); + } else if (value instanceof ZonedDateTime) { + return ((ZonedDateTime) value).format( + DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT)); + } + else { + return String.valueOf(value); + } + } + + private static void addParamToRequest(Request request, String key, String value, ParameterType parameterType) { + Objects.requireNonNull(parameterType, "ParameterType cannot be null"); + switch (parameterType) { + case HEADER: + request.addHeaderParam(key, value); + break; + case QUERY: + request.addQueryParam(key, value); + break; + case URLENCODED: + request.addPostParam(key, value); + break; + case JSON: + request.setBody(value); + default: + throw new IllegalArgumentException("Unsupported ParameterType: " + parameterType); + } + } + + /* + Inequality fields are only supported in Query parameters. + dateBefore is upperBound and dateAfter is lowerBound + */ + public static void toString(final Request request, final String key, LocalDate date, LocalDate dateBefore, LocalDate dateAfter) { + if (date != null) { + request.addQueryParam(key, date.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_FORMAT))); + } else if (dateAfter != null || dateBefore != null) { + request.addQueryDateRange(key, dateAfter, dateBefore); + } + } + + /* + Inequality fields are only supported in Query parameters. + dateBefore is upperBound and dateAfter is lowerBound + */ + public static void toString(final Request request, final String key, ZonedDateTime date, ZonedDateTime dateBefore, ZonedDateTime dateAfter) { + if (date != null) { + request.addQueryParam(key, date.format(DateTimeFormatter.ofPattern(Request.QUERY_STRING_DATE_TIME_FORMAT))); + } else if (dateAfter != null || dateBefore != null) { + request.addQueryDateTimeRange(key, dateAfter, dateBefore); + } + } +} diff --git a/src/main/java/com/twilio/converter/ZonedDateTimeListDeserializer.java b/src/main/java/com/twilio/converter/ZonedDateTimeListDeserializer.java new file mode 100644 index 0000000000..2d98994219 --- /dev/null +++ b/src/main/java/com/twilio/converter/ZonedDateTimeListDeserializer.java @@ -0,0 +1,28 @@ +package com.twilio.converter; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; + +import java.io.IOException; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; + +public class ZonedDateTimeListDeserializer extends JsonDeserializer> { + + @Override + public List deserialize(JsonParser parser, DeserializationContext context) throws IOException { + List dateStrings = parser.readValueAs(new TypeReference>() { + }); + List dates = new ArrayList<>(); + for (String dateString : dateStrings) { + ZonedDateTime date = DateConverter.rfc2822DateTimeFromString(dateString); + if (date != null) { + dates.add(date); + } + } + return dates; + } +} \ No newline at end of file diff --git a/src/main/java/com/twilio/credential/ClientCredentialProvider.java b/src/main/java/com/twilio/credential/ClientCredentialProvider.java new file mode 100644 index 0000000000..5dd5a75b9f --- /dev/null +++ b/src/main/java/com/twilio/credential/ClientCredentialProvider.java @@ -0,0 +1,67 @@ +package com.twilio.credential; + + +import com.twilio.annotations.Beta; +import com.twilio.auth_strategy.AuthStrategy; +import com.twilio.auth_strategy.TokenAuthStrategy; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.AuthenticationException; + +import com.twilio.http.bearertoken.ApiTokenManager; +import com.twilio.http.bearertoken.TokenManager; + +import java.util.Objects; + +@Beta +public class ClientCredentialProvider extends CredentialProvider { + private String grantType; + private String clientId; + private String clientSecret; + private TokenManager tokenManager; + + public ClientCredentialProvider(String clientId, String clientSecret) { + super(EnumConstants.AuthType.CLIENT_CREDENTIALS); + if (clientId == null || clientSecret == null) { + throw new AuthenticationException("ClientId or ClientSecret can not be null"); + } + this.grantType = "client_credentials"; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.tokenManager = null; + } + + public ClientCredentialProvider(String clientId, String clientSecret, TokenManager tokenManager) { + super(EnumConstants.AuthType.CLIENT_CREDENTIALS); + if (clientId == null || clientSecret == null || tokenManager == null) { + throw new AuthenticationException("ClientId or ClientSecret or TokenManager can not be null"); + } + this.grantType = "client_credentials"; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.tokenManager = tokenManager; + } + + @Override + public AuthStrategy toAuthStrategy() { + if (tokenManager == null) { + tokenManager = new ApiTokenManager(grantType, clientId, clientSecret); + } + return new TokenAuthStrategy(tokenManager); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ClientCredentialProvider other = (ClientCredentialProvider) o; + return Objects.equals(clientId, other.clientId) && + Objects.equals(clientSecret, other.clientSecret) && + Objects.equals(tokenManager, other.tokenManager); + } +} diff --git a/src/main/java/com/twilio/credential/CredentialProvider.java b/src/main/java/com/twilio/credential/CredentialProvider.java new file mode 100644 index 0000000000..d91b634725 --- /dev/null +++ b/src/main/java/com/twilio/credential/CredentialProvider.java @@ -0,0 +1,18 @@ +package com.twilio.credential; + +import com.twilio.auth_strategy.AuthStrategy; +import com.twilio.auth_strategy.TokenAuthStrategy; +import com.twilio.constant.EnumConstants; +import com.twilio.http.Request; +import lombok.Getter; + +public abstract class CredentialProvider { + @Getter + private EnumConstants.AuthType authType; + + public CredentialProvider(EnumConstants.AuthType authType) { + this.authType = authType; + } + + public abstract AuthStrategy toAuthStrategy(); +} diff --git a/src/main/java/com/twilio/credential/orgs/OrgsClientCredentialProvider.java b/src/main/java/com/twilio/credential/orgs/OrgsClientCredentialProvider.java new file mode 100644 index 0000000000..5d93404bc6 --- /dev/null +++ b/src/main/java/com/twilio/credential/orgs/OrgsClientCredentialProvider.java @@ -0,0 +1,64 @@ +package com.twilio.credential.orgs; + +import com.twilio.auth_strategy.AuthStrategy; +import com.twilio.auth_strategy.TokenAuthStrategy; +import com.twilio.constant.EnumConstants; +import com.twilio.credential.CredentialProvider; +import com.twilio.exception.AuthenticationException; +import com.twilio.http.bearertoken.OrgsTokenManager; +import com.twilio.http.bearertoken.TokenManager; + +import java.util.Objects; + +public class OrgsClientCredentialProvider extends CredentialProvider { + private String grantType; + private String clientId; + private String clientSecret; + private TokenManager tokenManager; + + public OrgsClientCredentialProvider(String clientId, String clientSecret) { + super(EnumConstants.AuthType.CLIENT_CREDENTIALS); + if (clientId == null || clientSecret == null) { + throw new AuthenticationException("ClientId or ClientSecret can not be null"); + } + this.grantType = "client_credentials"; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.tokenManager = null; + } + + public OrgsClientCredentialProvider(String clientId, String clientSecret, TokenManager tokenManager) { + super(EnumConstants.AuthType.CLIENT_CREDENTIALS); + if (clientId == null || clientSecret == null || tokenManager == null) { + throw new AuthenticationException("ClientId or ClientSecret or TokenManager can not be null"); + } + this.grantType = "client_credentials"; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.tokenManager = tokenManager; + } + + @Override + public AuthStrategy toAuthStrategy() { + if (tokenManager == null) { + tokenManager = new OrgsTokenManager(grantType, clientId, clientSecret); + } + return new TokenAuthStrategy(tokenManager); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OrgsClientCredentialProvider other = (OrgsClientCredentialProvider) o; + return Objects.equals(clientId, other.clientId) && + Objects.equals(clientSecret, other.clientSecret) && + Objects.equals(tokenManager, other.tokenManager); + } +} diff --git a/src/main/java/com/twilio/example/AccessTokenExample.java b/src/main/java/com/twilio/example/AccessTokenExample.java new file mode 100644 index 0000000000..a46977768f --- /dev/null +++ b/src/main/java/com/twilio/example/AccessTokenExample.java @@ -0,0 +1,38 @@ +package com.twilio.example; + +import com.twilio.jwt.accesstoken.AccessToken; +import com.twilio.jwt.accesstoken.VoiceGrant; +import java.util.HashMap; +import com.google.gson.Gson; + +public class AccessTokenExample { + public static void main(String args[]){ + String acctSid = System.getenv("TWILIO_ACCOUNT_SID"); + String applicationSid = System.getenv("TWILIO_TWIML_APP_SID"); + String apiKey = System.getenv("API_KEY"); + String apiSecret = System.getenv("API_SECRET"); + // Create Voice grant + VoiceGrant grant = new VoiceGrant(); + grant.setOutgoingApplicationSid(applicationSid); + + // Optional: add to allow incoming calls + grant.setIncomingAllow(true); + + String randomIdentity = "random-identity"; + // Create access token + AccessToken accessToken = new AccessToken.Builder(acctSid, apiKey, apiSecret.getBytes()) + .identity(randomIdentity) + .grant(grant) + .build(); + + String token = accessToken.toJwt(); + + // create JSON response payload + HashMap json = new HashMap<>(); + json.put("identity", randomIdentity); + json.put("token", token); + + Gson gson = new Gson(); + System.out.println(gson.toJson(json)); + } +} diff --git a/src/main/java/com/twilio/example/ValidationExample.java b/src/main/java/com/twilio/example/ValidationExample.java index b4bdac52a1..26de5c047b 100644 --- a/src/main/java/com/twilio/example/ValidationExample.java +++ b/src/main/java/com/twilio/example/ValidationExample.java @@ -8,10 +8,12 @@ import com.twilio.rest.api.v2010.account.NewSigningKey; import com.twilio.twiml.TwiMLException; import com.twilio.type.PhoneNumber; -import org.apache.commons.codec.binary.Base64; import java.security.KeyPair; import java.security.KeyPairGenerator; +import java.util.Base64; + +import io.jsonwebtoken.Jwts; public class ValidationExample { @@ -25,7 +27,6 @@ public class ValidationExample { * @throws TwiMLException if unable to generate TwiML */ public static void main(String[] args) throws Exception { - // Generate public/private key pair KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(2048); @@ -35,20 +36,21 @@ public static void main(String[] args) throws Exception { // Use the default rest client TwilioRestClient client = new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN) - .build(); + .build(); // Create a public key and signing key using the default client PublicKey key = PublicKey.creator( - Base64.encodeBase64String(pk.getEncoded()) + Base64.getEncoder().encodeToString(pk.getEncoded()) ).setFriendlyName("Public Key").create(client); NewSigningKey signingKey = NewSigningKey.creator().create(client); // Switch to validation client as the default client TwilioRestClient validationClient = new TwilioRestClient.Builder(signingKey.getSid(), signingKey.getSecret()) - .accountSid(ACCOUNT_SID) - .httpClient(new ValidationClient(ACCOUNT_SID, key.getSid(), signingKey.getSid(), pair.getPrivate())) - .build(); + .accountSid(ACCOUNT_SID) + // Validation client supports RS256 or PS256 algorithm. Default is RS256. + .httpClient(new ValidationClient(ACCOUNT_SID, key.getSid(), signingKey.getSid(), pair.getPrivate(), Jwts.SIG.PS256)) + .build(); // Make REST API requests Iterable messages = Message.reader().read(validationClient); diff --git a/src/main/java/com/twilio/exception/ApiException.java b/src/main/java/com/twilio/exception/ApiException.java index 1f8c35f007..ae6021c029 100644 --- a/src/main/java/com/twilio/exception/ApiException.java +++ b/src/main/java/com/twilio/exception/ApiException.java @@ -1,5 +1,7 @@ package com.twilio.exception; +import java.util.Map; + public class ApiException extends TwilioException { private static final long serialVersionUID = -3228320166955630014L; @@ -7,6 +9,10 @@ public class ApiException extends TwilioException { private final Integer code; private final String moreInfo; private final Integer status; + private final Map details; + private final Integer httpStatusCode; + private final Object params; + private final Boolean userError; /** * Create a new API Exception. @@ -14,7 +20,7 @@ public class ApiException extends TwilioException { * @param message exception message */ public ApiException(final String message) { - this(message, null, null, null, null); + this(message, null, null, null, null, null, null, null); } /** @@ -24,7 +30,17 @@ public ApiException(final String message) { * @param cause cause of the exception */ public ApiException(final String message, final Throwable cause) { - this(message, null, null, null, cause); + this(message, null, null, null, null, null, null, cause); + } + + /** + * Create a new API Exception. + * + * @param message exception message + * @param status status code + */ + public ApiException(final String message, final Integer status) { + this(message, null, null, status, null, null, null, null); } /** @@ -36,12 +52,48 @@ public ApiException(final String message, final Throwable cause) { * @param status status code * @param cause cause of the exception* @param cause */ - public ApiException(final String message, final Integer code, final String moreInfo, final Integer status, + public ApiException(final String message, final Integer code, final String moreInfo, final Integer status, final Integer httpStatusCode, final Object params, final Boolean userError, final Throwable cause) { super(message, cause); this.code = code; this.moreInfo = moreInfo; this.status = status; + this.details = null; + this.httpStatusCode = httpStatusCode; + this.params = params; + this.userError = userError; + } + + /** + * Create a new API Exception. + * + * @param restException the rest exception + */ + public ApiException(final RestException restException) { + super(restException.getMessage(), null); + this.code = restException.getCode(); + this.moreInfo = restException.getMoreInfo(); + this.status = restException.getStatus(); + this.details = restException.getDetails(); + this.httpStatusCode = restException.getHttpStatusCode(); + this.params = restException.getParams(); + this.userError = restException.getUserError(); + } + + /** + * Create a new API Exception from RFC-9457 Problem Details. + * + * @param restStandardException the rest standard exception + */ + public ApiException(final RestStandardException restStandardException) { + super(restStandardException.getTitle() + ": " + restStandardException.getDetail(), null); + this.code = restStandardException.getCode(); + this.moreInfo = restStandardException.getType(); + this.status = restStandardException.getStatus(); + this.details = null; + this.httpStatusCode = null; + this.params = null; + this.userError = null; } public Integer getCode() { @@ -55,4 +107,20 @@ public String getMoreInfo() { public Integer getStatusCode() { return status; } + + public Map getDetails() { + return details; + } + + public Integer getHttpStatusCode() { + return httpStatusCode; + } + + public Object getParams() { + return params; + } + + public Boolean getUserError() { + return userError; + } } diff --git a/src/main/java/com/twilio/exception/RestException.java b/src/main/java/com/twilio/exception/RestException.java index 2804d42671..0953c952db 100644 --- a/src/main/java/com/twilio/exception/RestException.java +++ b/src/main/java/com/twilio/exception/RestException.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.io.InputStream; +import java.util.Map; /** * Twilio Exceptions. @@ -20,6 +21,10 @@ public class RestException { private final String message; private final String moreInfo; private final Integer status; + private final Map details; + private final Integer httpStatusCode; + private final Object params; + private final Boolean userError; /** * Initialize a Twilio Rest Exception. @@ -31,11 +36,17 @@ public class RestException { */ @JsonCreator private RestException(@JsonProperty("status") final int status, @JsonProperty("message") final String message, - @JsonProperty("code") final Integer code, @JsonProperty("more_info") final String moreInfo) { + @JsonProperty("code") final Integer code, @JsonProperty("more_info") final String moreInfo, + @JsonProperty("details") final Map details, + @JsonProperty("httpStatusCode") final Integer httpStatusCode,@JsonProperty("params") final Object params,@JsonProperty("userError") final Boolean userError) { this.status = status; this.message = message; this.code = code; this.moreInfo = moreInfo; + this.details = details; + this.httpStatusCode = httpStatusCode; + this.params = params; + this.userError = userError; } /** @@ -71,4 +82,20 @@ public String getMoreInfo() { public Integer getStatus() { return status; } + + public Map getDetails() { + return details; + } + + public Boolean getUserError() { + return userError; + } + + public Integer getHttpStatusCode() { + return httpStatusCode; + } + + public Object getParams() { + return params; + } } diff --git a/src/main/java/com/twilio/exception/RestStandardException.java b/src/main/java/com/twilio/exception/RestStandardException.java new file mode 100644 index 0000000000..19d1674f6a --- /dev/null +++ b/src/main/java/com/twilio/exception/RestStandardException.java @@ -0,0 +1,175 @@ +package com.twilio.exception; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collections; +import java.util.List; + +/** + * RFC-9457 Problem Details Exception. + * + * Represents error responses compliant with RFC-9457 (Problem Details for HTTP APIs). + * See https://www.rfc-editor.org/rfc/rfc9457.html for the specification. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class RestStandardException { + + private final String type; + private final String title; + private final Integer status; + private final String detail; + private final String instance; + private final Integer code; + private final List errors; + + /** + * Represents a validation error for a specific field. + */ + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ValidationError { + private final String detail; + private final String pointer; + + @JsonCreator + public ValidationError( + @JsonProperty("detail") final String detail, + @JsonProperty("pointer") final String pointer) { + this.detail = detail; + this.pointer = pointer; + } + + /** + * Get the human-readable explanation of the validation error. + * + * @return validation error detail + */ + public String getDetail() { + return detail; + } + + /** + * Get the JSON Pointer (RFC 6901) to the location in the request where the error occurred. + * + * @return JSON pointer to the error location + */ + public String getPointer() { + return pointer; + } + } + + /** + * Initialize an RFC-9457 Problem Details Exception. + * + * @param type URI reference identifying the problem type + * @param title short, human-readable summary of the problem type + * @param status HTTP status code + * @param detail human-readable explanation specific to this occurrence + * @param instance URI reference identifying the specific occurrence + * @param code Twilio-specific error code + * @param errors array of validation errors for HTTP 400/422 responses + */ + @JsonCreator + private RestStandardException( + @JsonProperty("code") final Integer code, + @JsonProperty("status") final Integer status, + @JsonProperty("type") final String type, + @JsonProperty("title") final String title, + @JsonProperty("detail") final String detail, + @JsonProperty("instance") final String instance, + @JsonProperty("errors") final List errors) { + this.type = type; + this.title = title; + this.status = status; + this.code = code; + this.detail = detail == null ? "" : detail; + this.instance = instance == null ? "" : instance; + this.errors = errors == null ? Collections.emptyList() : errors; + } + + /** + * Build an exception from a JSON blob. + * + * @param json JSON blob + * @param objectMapper JSON reader + * @return Problem Exception as an object + */ + public static RestStandardException fromJson(final InputStream json, final ObjectMapper objectMapper) { + try { + return objectMapper.readValue(json, RestStandardException.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Get the URI reference identifying the problem type. + * + * @return problem type URI + */ + public String getType() { + return type; + } + + /** + * Get the short, human-readable summary of the problem type. + * + * @return problem title + */ + public String getTitle() { + return title; + } + + /** + * Get the HTTP status code. + * + * @return HTTP status code + */ + public Integer getStatus() { + return status; + } + + /** + * Get the human-readable explanation specific to this occurrence. + * + * @return problem detail + */ + public String getDetail() { + return detail; + } + + /** + * Get the URI reference identifying the specific occurrence. + * + * @return instance URI + */ + public String getInstance() { + return instance; + } + + /** + * Get the Twilio-specific error code. + * + * @return Twilio error code + */ + public Integer getCode() { + return code; + } + + /** + * Get the array of validation errors for HTTP 400/422 responses. + * + * @return non-null list of validation errors (empty if none are present) + */ + public List getErrors() { + return errors; + } +} diff --git a/src/main/java/com/twilio/http/HttpClient.java b/src/main/java/com/twilio/http/HttpClient.java index 2fc11baffa..297a093974 100644 --- a/src/main/java/com/twilio/http/HttpClient.java +++ b/src/main/java/com/twilio/http/HttpClient.java @@ -1,18 +1,85 @@ package com.twilio.http; +import java.nio.file.Path; +import lombok.Getter; +import lombok.Setter; + +import org.apache.hc.client5.http.classic.methods.HttpDelete; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpPatch; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.classic.methods.HttpPut; +import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.DefaultRedirectStrategy; +import org.apache.hc.core5.http.protocol.HttpContext; +import org.apache.hc.client5.http.protocol.RedirectStrategy; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpRequest; +import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.ProtocolException; +import org.apache.hc.core5.http.io.SocketConfig; +import org.apache.hc.core5.util.Timeout; + +/** + * Abstract class representing an HTTP client. + * This class provides methods to make reliable HTTP requests with retry logic and customizable request configurations. + */ public abstract class HttpClient { + public static final Timeout CONNECTION_TIMEOUT = Timeout.ofMilliseconds(10000); // The default connection timeout is 10 seconds + public static final Timeout CONNECT_TIMEOUT = Timeout.ofMilliseconds(30500); // The default socket timeout is 30.5 seconds + public static final Timeout CONNECTION_KEEP_ALIVE = Timeout.ofMilliseconds(60000); // The default keep-alive timeout is 60 seconds + public static final Timeout SOCKET_TIMEOUT = Timeout.ofMilliseconds(30000); // The default socket timeout is 30 seconds + /** + * Default request configuration for the HTTP client. + * This configuration sets the connection request timeout, socket timeout, and connection keep-alive timeout. + */ + public static final RequestConfig DEFAULT_REQUEST_CONFIG = RequestConfig + .custom() + .setConnectionRequestTimeout(CONNECTION_TIMEOUT) + .setConnectTimeout(CONNECT_TIMEOUT) + .setConnectionKeepAlive(CONNECTION_KEEP_ALIVE) + .build(); + /** + * Default socket configuration for the HTTP client. + * This configuration sets the socket timeout and enables keep-alive. + */ + public static final SocketConfig DEFAULT_SOCKET_CONFIG = SocketConfig.custom() + .setSoTimeout(SOCKET_TIMEOUT) + .setSoKeepAlive(true) + .build(); + + public static final int ANY_500 = -500; public static final int ANY_400 = -400; public static final int ANY_300 = -300; public static final int ANY_200 = -200; public static final int ANY_100 = -100; - public static final int[] RETRY_CODES = new int[]{ANY_500}; + public static final int[] RETRY_CODES = new int[] {ANY_500}; public static final int RETRIES = 3; public static final long DELAY_MILLIS = 100L; + /** + * Custom redirect strategy that disables automatic redirects. + */ + private static class TwilioRedirectStrategy extends DefaultRedirectStrategy { + @Override + public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException { + // Disable all automatic redirects + return false; + } + } + + // Default redirect strategy to not auto-redirect for any methods (empty string array). + @Getter + @Setter + private RedirectStrategy redirectStrategy = new TwilioRedirectStrategy(); + + @Getter private Response lastResponse; + @Getter private Request lastRequest; /** @@ -28,9 +95,9 @@ public Response reliableRequest(final Request request) { /** * Make a request. * - * @param request request to make - * @param retryCodes codes used for retries - * @param retries max number of retries + * @param request request to make + * @param retryCodes codes used for retries + * @param retries max number of retries * @param delayMillis delays between retries * @return Response of the HTTP request */ @@ -60,14 +127,6 @@ public Response reliableRequest(final Request request, final int[] retryCodes, i return response; } - public Response getLastResponse() { - return lastResponse; - } - - public Request getLastRequest() { - return lastRequest; - } - protected boolean shouldRetry(final Response response, final int[] retryCodes) { if (response == null) { return true; @@ -113,5 +172,31 @@ protected boolean shouldRetry(final Response response, final int[] retryCodes) { return false; } + public static ContentType getContentType(Path filePath) { + String fileName = filePath.getFileName().toString().toLowerCase(); + + if (fileName.endsWith(".pdf")) { + return ContentType.create("application/pdf"); + } else if (fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")) { + return ContentType.create("image/jpeg"); + } else if (fileName.endsWith(".png")) { + return ContentType.create("image/png"); + } else { + return ContentType.create("application/octet-stream"); // using "application/octet-stream" for generic binary data, often used by browsers for unknown binary files to prompt the user to download them + } + } + + public static HttpUriRequestBase createHttpUriRequestBase(final IRequest request) { + HttpUriRequestBase httpUriRequestBase = null; + switch (request.getMethod().toString().toUpperCase()) { + case "POST": httpUriRequestBase = new HttpPost(request.constructURL().toString()); break; + case "PUT": httpUriRequestBase = new HttpPut(request.constructURL().toString()); break; + case "PATCH": httpUriRequestBase = new HttpPatch(request.constructURL().toString()); break; + case "DELETE": httpUriRequestBase = new HttpDelete(request.constructURL().toString()); break; + case "GET": httpUriRequestBase = new HttpGet(request.constructURL().toString()); break; + } + return httpUriRequestBase; + } + public abstract Response makeRequest(final Request request); } diff --git a/src/main/java/com/twilio/http/HttpMethod.java b/src/main/java/com/twilio/http/HttpMethod.java index cd5961b9e6..6c3c8e7b13 100644 --- a/src/main/java/com/twilio/http/HttpMethod.java +++ b/src/main/java/com/twilio/http/HttpMethod.java @@ -7,6 +7,7 @@ public enum HttpMethod { GET("GET"), POST("POST"), PUT("PUT"), + PATCH("PATCH"), DELETE("DELETE"), HEAD("HEAD"), OPTIONS("OPTIONS"); diff --git a/src/main/java/com/twilio/http/HttpUtility.java b/src/main/java/com/twilio/http/HttpUtility.java new file mode 100644 index 0000000000..b597cc2f75 --- /dev/null +++ b/src/main/java/com/twilio/http/HttpUtility.java @@ -0,0 +1,62 @@ +package com.twilio.http; + +import com.twilio.Twilio; +import lombok.experimental.UtilityClass; + +import java.net.URI; +import java.util.List; + +@UtilityClass +public class HttpUtility { + public String getUserAgentString(final List userAgentExtensions) { + StringBuilder userAgentString = new StringBuilder(); + userAgentString.append("twilio-java/") + .append(Twilio.VERSION) + .append(" (") + .append(Twilio.OS_NAME) + .append(" ") + .append(Twilio.OS_ARCH) + .append(") ") + .append("java/") + .append(Twilio.JAVA_VERSION); + + if (userAgentExtensions != null && !userAgentExtensions.isEmpty()) { + userAgentExtensions.stream().forEach(userAgentExtension -> { + userAgentString.append(" "); + userAgentString.append(userAgentExtension); + }); + } + + return userAgentString.toString(); + } + + public String getUserAgentString(final List userAgentExtensions, final boolean isCustomClient) { + return isCustomClient ? getUserAgentString(userAgentExtensions) + " custom" + : getUserAgentString(userAgentExtensions); + } + + /** + * Validates that a URL is from a trusted Twilio domain. + * This prevents SSRF attacks by ensuring credentials are only sent to Twilio-owned domains. + * + * @param url the URL to validate + * @return true if the URL is from a Twilio domain, false otherwise + */ + public boolean isValidTwilioUrl(final String url) { + if (url == null || url.isEmpty()) { + return false; + } + try { + URI uri = new URI(url); + String host = uri.getHost(); + if (host == null) { + return false; + } + host = host.toLowerCase(); + // Allow only Twilio domains to prevent credential leakage + return host.equals("twilio.com") || host.endsWith(".twilio.com"); + } catch (Exception e) { + return false; + } + } +} diff --git a/src/main/java/com/twilio/http/IRequest.java b/src/main/java/com/twilio/http/IRequest.java new file mode 100644 index 0000000000..bcb26e5618 --- /dev/null +++ b/src/main/java/com/twilio/http/IRequest.java @@ -0,0 +1,406 @@ +package com.twilio.http; + +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiException; +import com.twilio.exception.InvalidRequestException; + +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLEncoder; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class IRequest { + private static final String DEFAULT_REGION = "us1"; + + public static final String QUERY_STRING_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; + public static final String QUERY_STRING_DATE_FORMAT = "yyyy-MM-dd"; + + protected final HttpMethod method; + protected final String url; + protected final Map> queryParams; + protected final Map> postParams; + protected final Map> headerParams; + protected List formParameters; + + protected String region; + protected String edge; + + private List userAgentExtensions; + + private EnumConstants.ContentType contentType; + + private String body; + + public static class FormParameters { + private String name; + private Type type; + private Object value; + + public enum Type { + TEXT, FILE + } + + public FormParameters(String name, Type type, Object value) { + this.name = name; + this.type = type; + this.value = value; + } + + public String getName() { + return name; + } + + public Type getType() { + return type; + } + + public Object getValue() { + return value; + } + } + + /** + * Create a new API request. + * + * @param method HTTP method + * @param url url of request + */ + public IRequest(final HttpMethod method, final String url) { + this.method = method; + this.url = url; + this.queryParams = new HashMap<>(); + this.postParams = new HashMap<>(); + this.headerParams = new HashMap<>(); + this.formParameters = new ArrayList<>(); + } + + /** + * Create a new API request. + * + * @param method HTTP method + * @param domain Twilio domain + * @param uri uri of request + */ + public IRequest(final HttpMethod method, final String domain, final String uri) { + this(method, domain, uri, null); + } + + /** + * Create a new API request. + * + * @param method HTTP Method + * @param domain Twilio domain + * @param uri uri of request + * @param region region to make request + */ + public IRequest(final HttpMethod method, final String domain, final String uri, final String region + ) { + this.method = method; + this.url = "https://" + domain + ".twilio.com" + uri; + this.region = region; + this.queryParams = new HashMap<>(); + this.postParams = new HashMap<>(); + this.headerParams = new HashMap<>(); + this.formParameters = new ArrayList<>(); + } + + public HttpMethod getMethod() { + return method; + } + + public String getUrl() { + return url; + } + + public void setRegion(final String region) { + this.region = region; + } + + public void setEdge(final String edge) { + this.edge = edge; + } + + public void setUserAgentExtensions(List userAgentExtensions) { + this.userAgentExtensions = userAgentExtensions; + } + + public List getUserAgentExtensions() { + return this.userAgentExtensions; + } + + public EnumConstants.ContentType getContentType() { + return contentType; + } + + public void setContentType(EnumConstants.ContentType contentType) { + this.contentType = contentType; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + public List getFormParameters() { + return this.formParameters; + } + + public void addFormParameter(String name, FormParameters.Type type, Object value) { + this.formParameters.add(new FormParameters(name, type, value)); + } + + public void setFormParameters(final List formParameters) { + if (formParameters == null) { + throw new IllegalArgumentException("Form parameters cannot be null"); + } + this.formParameters.addAll(formParameters); + } + + /** + * Build the URL for the request. + * + * @return URL for the request + */ + public URL constructURL() { + String params = encodeQueryParams(); + String stringUri = buildURL(); + + if (params.length() > 0) { + stringUri += "?" + params; + } + + try { + URI uri = new URI(stringUri); + return uri.toURL(); + } catch (final URISyntaxException e) { + throw new ApiException("Bad URI: " + e.getMessage()); + } catch (final MalformedURLException e) { + throw new ApiException("Bad URL: " + e.getMessage()); + } + } + + protected String buildURL() { + try { + final URL parsedUrl = new URL(url); + String host = parsedUrl.getHost(); + final String[] pieces = host.split("\\."); + + if (pieces.length > 1) { + final String product = pieces[0]; + final String domain = joinIgnoreNull(".", pieces[pieces.length - 2], pieces[pieces.length - 1]); + + String targetRegion = region; + String targetEdge = edge; + + if (pieces.length == 4) { // product.region.twilio.com + targetRegion = targetRegion != null ? targetRegion : pieces[1]; + } else if (pieces.length == 5) { // product.edge.region.twilio.com + targetEdge = targetEdge != null ? targetEdge : pieces[1]; + targetRegion = targetRegion != null ? targetRegion : pieces[2]; + } + + if (targetEdge != null && targetRegion == null) + targetRegion = DEFAULT_REGION; + + host = joinIgnoreNull(".", product, targetEdge, targetRegion, domain); + } + + String urlPort = parsedUrl.getPort() != -1 ? ":" + parsedUrl.getPort() : null; + String protocol = parsedUrl.getProtocol() + "://"; + String[] pathPieces = parsedUrl.getPath().split("/"); + for (int i = 0; i < pathPieces.length; i++) { + pathPieces[i] = URLEncoder.encode(pathPieces[i], "UTF-8").replace("+", "%20"); + } + String encodedPath = String.join("/", pathPieces); + String query = parsedUrl.getQuery() != null ? "?" + parsedUrl.getQuery() : null; + String ref = parsedUrl.getRef() != null ? "#" + parsedUrl.getRef() : null; + String credentials = parsedUrl.getUserInfo() != null ? parsedUrl.getUserInfo() + "@" : null; + return joinIgnoreNull("", protocol, credentials, host, urlPort, encodedPath, query, ref); + } catch (final MalformedURLException | UnsupportedEncodingException e) { + throw new ApiException("Bad URL: " + e.getMessage()); + } + } + + /** + * Add query parameters for date ranges. + * + * @param name name of query parameter + * @param lowerBound lower bound of LocalDate range + * @param upperBound upper bound of LocalDate range + */ + public void addQueryDateRange(final String name, LocalDate lowerBound, LocalDate upperBound) { + if (lowerBound != null) { + String value = lowerBound.toString(); + addQueryParam(name + ">", value); + } + + if (upperBound != null) { + String value = upperBound.toString(); + addQueryParam(name + "<", value); + } + } + + /** + * Add query parameters for date ranges. + * + * @param name name of query parameter + * @param lowerBound lower bound of ZonedDateTime range + * @param upperBound upper bound of ZonedDateTime range + */ + public void addQueryDateTimeRange(final String name, ZonedDateTime lowerBound, ZonedDateTime upperBound) { + if (lowerBound != null) { + String value = lowerBound.withZoneSameInstant(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern(QUERY_STRING_DATE_TIME_FORMAT)); + addQueryParam(name + ">", value); + } + + if (upperBound != null) { + String value = upperBound.withZoneSameInstant(ZoneId.of("UTC")).format(DateTimeFormatter.ofPattern(QUERY_STRING_DATE_TIME_FORMAT)); + addQueryParam(name + "<", value); + } + } + + /** + * Add a query parameter. + * + * @param name name of parameter + * @param value value of parameter + */ + public void addQueryParam(final String name, final String value) { + addParam(queryParams, name, value); + } + + /** + * Add a form parameter. + * + * @param name name of parameter + * @param value value of parameter + */ + public void addPostParam(final String name, final String value) { + addParam(postParams, name, value); + } + + /** + * Add a header parameter. + * + * @param name name of parameter + * @param value value of parameter + */ + public void addHeaderParam(final String name, final String value) { + addParam(headerParams, name, value); + } + + private void addParam(final Map> params, final String name, final String value) { + if (value == null || value.equals("null")) + return; + + if (!params.containsKey(name)) { + params.put(name, new ArrayList()); + } + + params.get(name).add(value); + } + + /** + * Encode the form body. + * + * @return url encoded form body + */ + public String encodeFormBody() { + return encodeParameters(postParams); + } + + /** + * Encode the query parameters. + * + * @return url encoded query parameters + */ + public String encodeQueryParams() { + return encodeParameters(queryParams); + } + + private static String encodeParameters(final Map> params) { + List parameters = new ArrayList<>(); + + for (final Map.Entry> entry : params.entrySet()) { + try { + String encodedName = URLEncoder.encode(entry.getKey(), "UTF-8"); + for (final String value : entry.getValue()) { + if (value == null) { + continue; + } + + String encodedValue = URLEncoder.encode(value, "UTF-8"); + parameters.add(encodedName + "=" + encodedValue); + } + } catch (final UnsupportedEncodingException e) { + throw new InvalidRequestException("Couldn't encode params", entry.getKey(), e); + } + } + return joinIgnoreNull("&", parameters); + } + + private static String joinIgnoreNull(final String separator, final String... items) { + return joinIgnoreNull(separator, Arrays.asList(items)); + } + + private static String joinIgnoreNull(final String separator, final List items) { + final StringBuilder builder = new StringBuilder(); + + for (final String item : items) { + if (item != null) { + if (builder.length() > 0) { + builder.append(separator); + } + + builder.append(item); + } + } + + return builder.toString(); + } + + public Map> getQueryParams() { + return queryParams; + } + + public Map> getPostParams() { + return postParams; + } + + public Map> getHeaderParams() { + return headerParams; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Request other = (Request) o; + return Objects.equals(this.method, other.method) && + Objects.equals(this.buildURL(), other.buildURL()) && + Objects.equals(this.queryParams, other.queryParams) && + Objects.equals(this.postParams, other.postParams) && + Objects.equals(this.headerParams, other.headerParams); + } +} diff --git a/src/main/java/com/twilio/http/NetworkHttpClient.java b/src/main/java/com/twilio/http/NetworkHttpClient.java index c1583238de..6dccc2fec7 100644 --- a/src/main/java/com/twilio/http/NetworkHttpClient.java +++ b/src/main/java/com/twilio/http/NetworkHttpClient.java @@ -1,70 +1,107 @@ package com.twilio.http; -import com.google.common.base.Strings; -import com.google.common.collect.Lists; import com.twilio.Twilio; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiException; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpHeaders; -import org.apache.http.HttpResponse; -import org.apache.http.HttpVersion; -import org.apache.http.client.utils.HttpClientUtils; -import org.apache.http.entity.BufferedHttpEntity; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.RequestBuilder; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.message.BasicHeader; +import com.twilio.http.IRequest.FormParameters; +import com.twilio.http.IRequest.FormParameters.Type; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.Map; +import java.util.Map.Entry; +import org.apache.hc.client5.http.classic.methods.HttpDelete; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpPatch; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.classic.methods.HttpPut; +import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.entity.UrlEncodedFormEntity; +import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpHeaders; +import org.apache.hc.core5.http.HttpVersion; +import org.apache.hc.core5.http.NameValuePair; +import org.apache.hc.core5.http.io.SocketConfig; +import org.apache.hc.core5.http.io.entity.BufferedHttpEntity; +import org.apache.hc.core5.http.io.entity.StringEntity; +import org.apache.hc.core5.http.message.BasicHeader; +import org.apache.hc.core5.http.message.BasicNameValuePair; + public class NetworkHttpClient extends HttpClient { - private static final int CONNECTION_TIMEOUT = 10000; - private static final int SOCKET_TIMEOUT = 30500; + protected final CloseableHttpClient client; - private final org.apache.http.client.HttpClient client; + private boolean isCustomClient; /** * Create a new HTTP Client. */ public NetworkHttpClient() { - RequestConfig config = RequestConfig.custom() - .setConnectTimeout(CONNECTION_TIMEOUT) - .setSocketTimeout(SOCKET_TIMEOUT) - .build(); + this(DEFAULT_REQUEST_CONFIG); + } - Collection
headers = Lists.
newArrayList( + /** + * Create a new HTTP Client with a custom request config. + * + * @param requestConfig a RequestConfig. + */ + public NetworkHttpClient(final RequestConfig requestConfig) { + this(requestConfig, DEFAULT_SOCKET_CONFIG); + } + + /** + * Create a new HTTP Client with a custom request and socket config. + * + * @param requestConfig a RequestConfig. + * @param socketConfig a SocketConfig. + */ + public NetworkHttpClient(final RequestConfig requestConfig, final SocketConfig socketConfig) { + Collection headers = Arrays.asList( new BasicHeader("X-Twilio-Client", "java-" + Twilio.VERSION), - new BasicHeader(HttpHeaders.USER_AGENT, "twilio-java/" + Twilio.VERSION + " (" + Twilio.JAVA_VERSION + ")"), - new BasicHeader(HttpHeaders.ACCEPT, "application/json"), + // The Accept header is intentionally omitted to support both SCIM and JSON content types. new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "utf-8") ); String googleAppEngineVersion = System.getProperty("com.google.appengine.runtime.version"); - boolean isNotGoogleAppEngine = Strings.isNullOrEmpty(googleAppEngineVersion); + boolean isGoogleAppEngine = googleAppEngineVersion != null && !googleAppEngineVersion.isEmpty(); - org.apache.http.impl.client.HttpClientBuilder clientBuilder = HttpClientBuilder.create(); + HttpClientBuilder clientBuilder = HttpClientBuilder.create(); - if (isNotGoogleAppEngine) { + if (!isGoogleAppEngine) { clientBuilder.useSystemProperties(); } PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); - connectionManager.setDefaultMaxPerRoute(10); - connectionManager.setMaxTotal(10*2); + connectionManager.setDefaultSocketConfig(socketConfig); + /* + * Example: Lets say client has one server. + * There are 4 servers on edge handling client request. + * Each request takes on an average 500ms (2 request per second) + * Total number request can be server in a second from a route: 20 * 4 * 2 (DefaultMaxPerRoute * edge servers * request per second) + */ + connectionManager.setDefaultMaxPerRoute(20); + connectionManager.setMaxTotal(100); - clientBuilder + client = clientBuilder .setConnectionManager(connectionManager) - .setDefaultRequestConfig(config) - .setDefaultHeaders(headers); - - client = clientBuilder.build(); + .setDefaultRequestConfig(requestConfig) + .setDefaultHeaders(headers) + .setRedirectStrategy(this.getRedirectStrategy()) + .build(); } /** @@ -72,18 +109,17 @@ public NetworkHttpClient() { * @param clientBuilder an HttpClientBuilder. */ public NetworkHttpClient(HttpClientBuilder clientBuilder) { - Collection
headers = Lists.
newArrayList( + Collection headers = Arrays.asList( new BasicHeader("X-Twilio-Client", "java-" + Twilio.VERSION), - new BasicHeader( - HttpHeaders.USER_AGENT, "twilio-java/" + Twilio.VERSION + " (" + Twilio.JAVA_VERSION + ") custom" - ), new BasicHeader(HttpHeaders.ACCEPT, "application/json"), new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "utf-8") ); + isCustomClient = true; client = clientBuilder - .setDefaultHeaders(headers) - .build(); + .setDefaultHeaders(headers) + .setRedirectStrategy(this.getRedirectStrategy()) + .build(); } /** @@ -92,46 +128,85 @@ public NetworkHttpClient(HttpClientBuilder clientBuilder) { * @param request request to make * @return Response of the HTTP request */ - public Response makeRequest(final Request request) { + public Response makeRequest(final Request request) { HttpMethod method = request.getMethod(); - RequestBuilder builder = RequestBuilder.create(method.toString()) - .setUri(request.constructURL().toString()) - .setVersion(HttpVersion.HTTP_1_1) - .setCharset(StandardCharsets.UTF_8); + HttpUriRequestBase httpUriRequestBase = createHttpUriRequestBase(request); + + httpUriRequestBase.setVersion(HttpVersion.HTTP_1_1); if (request.requiresAuthentication()) { - builder.addHeader(HttpHeaders.AUTHORIZATION, request.getAuthString()); + httpUriRequestBase.addHeader(HttpHeaders.AUTHORIZATION, request.getAuthString()); } - if (method == HttpMethod.POST) { - builder.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); + for (Entry> entry : request.getHeaderParams().entrySet()) { + for (String value : entry.getValue()) { + httpUriRequestBase.addHeader(entry.getKey(), value); + } + } - for (Map.Entry> entry : request.getPostParams().entrySet()) { - for (String value : entry.getValue()) { - builder.addParameter(entry.getKey(), value); + if (method != HttpMethod.GET) { + // TODO: It will be removed after one RC Release. + if (request.getContentType() == null) request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + if (EnumConstants.ContentType.JSON.getValue().equals(request.getContentType().getValue())) { + HttpEntity entity = new StringEntity(request.getBody(), ContentType.APPLICATION_JSON); + httpUriRequestBase.setEntity(entity); + httpUriRequestBase.addHeader( + HttpHeaders.CONTENT_TYPE, EnumConstants.ContentType.JSON.getValue()); + } else if (EnumConstants.ContentType.MULTIPART_FORM_DATA.getValue().equals(request.getContentType().getValue())) { + + MultipartEntityBuilder httpEntityBuilder = MultipartEntityBuilder.create(); + for( FormParameters formParameter: request.getFormParameters()) { + // Create a file to upload. + if ( formParameter.getType().equals(Type.TEXT) ) + httpEntityBuilder.addTextBody(formParameter.getName(), formParameter.getValue().toString()); + else if ( formParameter.getType().equals(Type.FILE) ) + { + Path path = Paths.get(formParameter.getValue().toString()); + byte[] fileBytes = null; + try{ + fileBytes = Files.readAllBytes(path); + } catch (IOException e) { + System.err.println("Failed to read file for upload: " + path + ". " + e.getMessage()); + throw new ApiException("Failed to read file for upload: " + path, e); + } + String fileName = path.getFileName().toString(); + ContentType contentType = getContentType(path); + httpEntityBuilder.addBinaryBody(formParameter.getName(), fileBytes, contentType, fileName); + } } + httpUriRequestBase.setEntity(httpEntityBuilder.build()); } + else { + List formParams = new ArrayList<>(); + for ( Entry> entry : request.getPostParams().entrySet()) { + for (String value : entry.getValue()) { + formParams.add(new BasicNameValuePair(entry.getKey(), value)); + } + } + + // Build the entity with URL form encoded parameters + UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(formParams, StandardCharsets.UTF_8); + // Set the entity on the request + httpUriRequestBase.setEntity(formEntity); + } + } + httpUriRequestBase.addHeader(HttpHeaders.USER_AGENT, HttpUtility.getUserAgentString(request.getUserAgentExtensions(), isCustomClient)); - HttpResponse response = null; try { - response = client.execute(builder.build()); + CloseableHttpResponse response = client.execute(httpUriRequestBase); HttpEntity entity = response.getEntity(); return new Response( // Consume the entire HTTP response before returning the stream entity == null ? null : new BufferedHttpEntity(entity).getContent(), - response.getStatusLine().getStatusCode() + response.getCode(), + response.getHeaders() ); } catch (IOException e) { - throw new ApiException(e.getMessage()); - } finally { - - // Ensure this response is properly closed - HttpClientUtils.closeQuietly(response); - + throw new ApiException(e.getMessage(), e); } - } + } diff --git a/src/main/java/com/twilio/http/Request.java b/src/main/java/com/twilio/http/Request.java index d192b648c7..6cddc93386 100644 --- a/src/main/java/com/twilio/http/Request.java +++ b/src/main/java/com/twilio/http/Request.java @@ -1,49 +1,28 @@ package com.twilio.http; -import com.google.common.base.Joiner; -import com.google.common.collect.Range; -import com.twilio.exception.ApiException; -import com.twilio.exception.InvalidRequestException; -import org.apache.commons.codec.binary.Base64; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; +import com.twilio.auth_strategy.AuthStrategy; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.nio.charset.StandardCharsets; +import java.util.Base64; import java.util.Objects; -public class Request { +public class Request extends IRequest { + private static final String DEFAULT_REGION = "us1"; public static final String QUERY_STRING_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss"; public static final String QUERY_STRING_DATE_FORMAT = "yyyy-MM-dd"; - - private final HttpMethod method; - private final String url; - private final Map> queryParams; - private final Map> postParams; - private String username; private String password; + private AuthStrategy authStrategy; /** * Create a new API request. * * @param method HTTP method - * @param url url of request + * @param url url of request */ public Request(final HttpMethod method, final String url) { - this.method = method; - this.url = url; - this.queryParams = new HashMap<>(); - this.postParams = new HashMap<>(); + super(method, url); } /** @@ -51,7 +30,7 @@ public Request(final HttpMethod method, final String url) { * * @param method HTTP method * @param domain Twilio domain - * @param uri uri of request + * @param uri uri of request */ public Request(final HttpMethod method, final String domain, final String uri) { this(method, domain, uri, null); @@ -59,34 +38,26 @@ public Request(final HttpMethod method, final String domain, final String uri) { /** * Create a new API request. + * * @param method HTTP Method * @param domain Twilio domain - * @param uri uri of request + * @param uri uri of request * @param region region to make request */ - public Request( - final HttpMethod method, - final String domain, - final String uri, - final String region - ) { - this.method = method; - this.url = "https://" + Joiner.on(".").skipNulls().join(domain, region, "twilio", "com") + uri; - this.queryParams = new HashMap<>(); - this.postParams = new HashMap<>(); - } - - public HttpMethod getMethod() { - return method; - } - - public String getUrl() { - return url; + public Request(final HttpMethod method, final String domain, final String uri, final String region) { + super(method, domain, uri, region); } public void setAuth(final String username, final String password) { this.username = username; this.password = password; + this.authStrategy = null; + } + + public void setAuth(final AuthStrategy authStrategy) { + this.authStrategy = authStrategy; + this.username = null; + this.password = null; } /** @@ -95,17 +66,15 @@ public void setAuth(final String username, final String password) { * @return basic authentication string */ public String getAuthString() { - String credentials = this.username + ":" + this.password; - try { - - String encoded = new Base64().encodeAsString(credentials.getBytes("ascii")); + if (username != null && password != null) { + final String credentials = this.username + ":" + this.password; + final String encoded = Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.US_ASCII)); return "Basic " + encoded; - - } catch (final UnsupportedEncodingException e) { - - throw new InvalidRequestException("It must be possible to encode credentials as ascii", credentials, e); - } + if (authStrategy != null) { + return authStrategy.getAuthString(); + } + return ""; } public String getUsername() { @@ -116,143 +85,12 @@ public String getPassword() { return password; } - public boolean requiresAuthentication() { - return username != null || password != null; + public AuthStrategy getAuthStrategy() { + return authStrategy; } - - /** - * Build the URL for the request. - * - * @return URL for the request - */ - @SuppressWarnings("checkstyle:abbreviationaswordinname") - public URL constructURL() { - String params = encodeQueryParams(); - String stringUri = url; - - if (params.length() > 0) { - stringUri += "?" + params; - } - - try { - URI uri = new URI(stringUri); - return uri.toURL(); - } catch (final URISyntaxException e) { - throw new ApiException("Bad URI: " + stringUri, e); - } catch (final MalformedURLException e) { - throw new ApiException("Bad URL: " + stringUri, e); - } - } - - /** - * Add query parameters for date ranges. - * - * @param name name of query parameter - * @param range date range - */ - public void addQueryDateRange(final String name, final Range range) { - if (range.hasLowerBound()) { - String value = range.lowerEndpoint().toString(QUERY_STRING_DATE_FORMAT); - addQueryParam(name + ">", value); - } - - if (range.hasUpperBound()) { - String value = range.upperEndpoint().toString(QUERY_STRING_DATE_FORMAT); - addQueryParam(name + "<", value); - } - } - - /** - * Add query parameters for date ranges. - * - * @param name name of query parameter - * @param range date range - */ - public void addQueryDateTimeRange(final String name, final Range range) { - if (range.hasLowerBound()) { - String value = range.lowerEndpoint().toString(QUERY_STRING_DATE_TIME_FORMAT); - addQueryParam(name + ">", value); - } - - if (range.hasUpperBound()) { - String value = range.upperEndpoint().toString(QUERY_STRING_DATE_TIME_FORMAT); - addQueryParam(name + "<", value); - } - } - - /** - * Add a query parameter. - * - * @param name name of parameter - * @param value value of parameter - */ - public void addQueryParam(final String name, final String value) { - addParam(queryParams, name, value); - } - - /** - * Add a form parameter. - * - * @param name name of parameter - * @param value value of parameter - */ - public void addPostParam(final String name, final String value) { - addParam(postParams, name, value); - } - - private void addParam(final Map> params, final String name, final String value) { - if (!params.containsKey(name)) { - params.put(name, new ArrayList()); - } - - params.get(name).add(value); - } - - /** - * Encode the form body. - * - * @return url encoded form body - */ - public String encodeFormBody() { - return encodeParameters(postParams); - } - - /** - * Encode the query parameters. - * - * @return url encoded query parameters - */ - public String encodeQueryParams() { - return encodeParameters(queryParams); - } - - private static String encodeParameters(final Map> params) { - List parameters = new ArrayList<>(); - - for (final Map.Entry> entry : params.entrySet()) { - try { - String encodedName = URLEncoder.encode(entry.getKey(), "UTF-8"); - for (final String value : entry.getValue()) { - if (value == null) { - continue; - } - - String encodedValue = URLEncoder.encode(value, "UTF-8"); - parameters.add(encodedName + "=" + encodedValue); - } - } catch (final UnsupportedEncodingException e) { - throw new InvalidRequestException("Couldn't encode params", entry.getKey(), e); - } - } - return Joiner.on("&").join(parameters); - } - - public Map> getQueryParams() { - return queryParams; - } - - public Map> getPostParams() { - return postParams; + + public boolean requiresAuthentication() { + return (username != null && password != null) || (authStrategy != null && authStrategy.requiresAuthentication()); } @Override @@ -267,10 +105,12 @@ public boolean equals(Object o) { Request other = (Request) o; return Objects.equals(this.method, other.method) && - Objects.equals(this.url, other.url) && + Objects.equals(this.buildURL(), this.buildURL()) && Objects.equals(this.username, other.username) && - Objects.equals(this.password, other.password) && + Objects.equals(this.password, other.password) && + Objects.equals(this.authStrategy, other.authStrategy) && Objects.equals(this.queryParams, other.queryParams) && - Objects.equals(this.postParams, other.postParams); + Objects.equals(this.postParams, other.postParams) && + Objects.equals(this.headerParams, other.headerParams); } } diff --git a/src/main/java/com/twilio/http/Response.java b/src/main/java/com/twilio/http/Response.java index 594d9e67a8..05f675ab7e 100644 --- a/src/main/java/com/twilio/http/Response.java +++ b/src/main/java/com/twilio/http/Response.java @@ -1,10 +1,9 @@ package com.twilio.http; -import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; +import org.apache.hc.core5.http.Header; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.util.Scanner; @@ -12,39 +11,64 @@ public class Response { private final InputStream stream; - private final String content; + private String content; private final int statusCode; + private final Header[] headers; /** * Create a Response from content string and status code. * - * @param content content string + * @param content content string * @param statusCode status code */ public Response(final String content, final int statusCode) { + this(content, statusCode, null); + } + + /** + * Create a Response from content string, status code, and headers. + * + * @param content content string + * @param statusCode status code + * @param headers headers + */ + public Response(final String content, final int statusCode, final Header[] headers) { this.stream = null; this.content = content; this.statusCode = statusCode; + this.headers = headers; } /** * Create a Response from input stream and status code. * - * @param stream input stream + * @param stream input stream * @param statusCode status code */ public Response(final InputStream stream, final int statusCode) { + this(stream, statusCode, null); + } + + /** + * Create a Response from input stream, status code, and headers. + * + * @param stream input stream + * @param statusCode status code + * @param headers headers + */ + public Response(final InputStream stream, final int statusCode, final Header[] headers) { this.stream = stream; this.content = null; this.statusCode = statusCode; + this.headers = headers; } /** * Get the the content of the response. * *

- * If there is a content string, that will be returned. - * Otherwise, will get content from input stream + * If there is a content string, that will be returned. + * Otherwise, will get content from input stream *

* * @return the content string @@ -53,21 +77,21 @@ public String getContent() { if (content != null) { return content; } - // XXX we probably don't need this and should convert strings into - // streams in the mock scaffolding - try { - if (stream.available() == 0) { + + if (stream != null) { + Scanner scanner = new Scanner(stream, "UTF-8").useDelimiter("\\A"); + + if (!scanner.hasNext()) { return ""; } - } catch (final IOException e) { - throw new ApiConnectionException("IOException during API request to Twilio", e); - } - Scanner scanner = new Scanner(stream, "UTF-8").useDelimiter("\\A"); - String data = scanner.next(); - scanner.close(); + content = scanner.next(); + scanner.close(); - return data; + return content; + } + + return ""; } /** @@ -89,4 +113,8 @@ public InputStream getStream() { public int getStatusCode() { return statusCode; } + + public Header[] getHeaders() { + return headers; + } } diff --git a/src/main/java/com/twilio/http/TwilioRestClient.java b/src/main/java/com/twilio/http/TwilioRestClient.java index 29d2cb0a12..2dafce8fad 100644 --- a/src/main/java/com/twilio/http/TwilioRestClient.java +++ b/src/main/java/com/twilio/http/TwilioRestClient.java @@ -1,34 +1,86 @@ package com.twilio.http; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Predicate; - +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.twilio.auth_strategy.AuthStrategy; +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.constant.EnumConstants; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; +import lombok.Getter; +import org.apache.hc.core5.http.Header; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The `TwilioRestClient` class is responsible for making HTTP requests to the Twilio API. + * It provides methods to configure authentication, region, edge, and other settings + * required to interact with Twilio's services. + * + *

Features:

+ *
    + *
  • Supports basic authentication and token-based authentication strategies.
  • + *
  • Allows configuration of custom HTTP clients and ObjectMapper for JSON processing.
  • + *
  • Handles request retries for specific HTTP status codes (e.g., 401 Unauthorized).
  • + *
  • Logs detailed request and response information for debugging purposes.
  • + *
+ * + *

Usage Example:

+ *
+ * {@code
+ * TwilioRestClient client = new TwilioRestClient.Builder(ACCOUNT_SID, AUTH_TOKEN)
+ *           .objectMapper(customMapper)
+ *           .build();
+ *
+ * Message message = Message
+ *           .creator(
+ *               new PhoneNumber("+1xxxxxxxxxx"),
+ *               new PhoneNumber("+1xxxxxxxxxx"),
+ *               "This is the ship that made the Kessel Run in fourteen parsecs?"
+ *           ).create(client);
+ * }
+ * 
+ * + *

Note: This class is designed to be thread-safe and reusable.

+ */ public class TwilioRestClient { public static final int HTTP_STATUS_CODE_CREATED = 201; public static final int HTTP_STATUS_CODE_NO_CONTENT = 204; + public static final int HTTP_STATUS_CODE_UNAUTHORIZED = 401; public static final int HTTP_STATUS_CODE_OK = 200; - public static final Predicate SUCCESS = new Predicate() { - @Override - public boolean apply(Integer i) { - return i != null && i >= 200 && i < 300; - } - }; + public static final Predicate SUCCESS = i -> i != null && i >= 200 && i < 400; + @Getter + private AuthStrategy authStrategy; + @Getter private final ObjectMapper objectMapper; private final String username; private final String password; + @Getter private final String accountSid; + @Getter private final String region; + @Getter + private final String edge; + @Getter private final HttpClient httpClient; + @Getter + private final List userAgentExtensions; + private static final Logger logger = LoggerFactory.getLogger(TwilioRestClient.class); - private TwilioRestClient(Builder b) { + protected TwilioRestClient(Builder b) { this.username = b.username; this.password = b.password; + this.authStrategy = b.authStrategy; this.accountSid = b.accountSid; this.region = b.region; + this.edge = b.edge; this.httpClient = b.httpClient; - this.objectMapper = new ObjectMapper(); + this.objectMapper = b.objectMapper; + this.userAgentExtensions = b.userAgentExtensions; } /** @@ -38,32 +90,70 @@ private TwilioRestClient(Builder b) { * @return Response object */ public Response request(final Request request) { - request.setAuth(username, password); - return httpClient.reliableRequest(request); - } + // If authStrategy is passed from NoAuth API, no need to set authStrategy (ex TokenCreator). + if (request.getAuthStrategy() == null) { + if (username != null && password != null) { + request.setAuth(username, password); + } else if (authStrategy != null) { + request.setAuth(authStrategy); + } + } - public String getAccountSid() { - return accountSid; - } + if (region != null) + request.setRegion(region); + if (edge != null) + request.setEdge(edge); - public String getRegion() { - return region; - } + // If NoAuthStrategy is used, clear region and edge as Token endpoint does not support region/edge. + if (request.getAuthStrategy() != null && request.getAuthStrategy() instanceof NoAuthStrategy) { + request.setRegion(null); + request.setEdge(null); + } - public ObjectMapper getObjectMapper() { - return objectMapper; - } - public HttpClient getHttpClient() { - return httpClient; + if (userAgentExtensions != null && !userAgentExtensions.isEmpty()) { + request.setUserAgentExtensions(userAgentExtensions); + } + + logRequest(request); + Response response = httpClient.reliableRequest(request); + if(response != null) { + int statusCode = response.getStatusCode(); + if (statusCode == HTTP_STATUS_CODE_UNAUTHORIZED && authStrategy != null && EnumConstants.AuthType.TOKEN.equals(authStrategy.getAuthType())) { + // Retry only once + response = httpClient.reliableRequest(request); + } + + if (logger.isDebugEnabled()) { + logger.debug("status code: {}", statusCode); + Header[] responseHeaders = response.getHeaders(); + logger.debug("response headers:"); + for (int i = 0; i < responseHeaders.length; i++) { + logger.debug("responseHeader: {}", responseHeaders[i]); + } + } + } + + return response; } public static class Builder { + // This module configures the ObjectMapper to use + // public API methods for manipulating java.time.* + // classes. The alternative is to use reflection which + // generates warnings from the module system on Java 9+ + private static final ObjectMapper DEFAULT_OBJECT_MAPPER = new ObjectMapper() + .registerModule(new JavaTimeModule()); + private String username; private String password; + private AuthStrategy authStrategy; private String accountSid; private String region; + private String edge; private HttpClient httpClient; + private List userAgentExtensions; + private ObjectMapper objectMapper = DEFAULT_OBJECT_MAPPER; /** * Create a new Twilio Rest Client. @@ -71,30 +161,56 @@ public static class Builder { * @param username username to use * @param password password for the username */ - public Builder(String username, String password) { + public Builder(final String username, final String password) { this.username = username; this.password = password; this.accountSid = username; } - public Builder accountSid(String accountSid) { + /** + * Create a new Twilio Rest Client. + * + * @param authStrategy authStrategy to use + */ + public Builder(final AuthStrategy authStrategy) { + this.authStrategy = authStrategy; + } + + public Builder accountSid(final String accountSid) { this.accountSid = accountSid; return this; } - public Builder region(String region) { + public Builder region(final String region) { this.region = region; return this; } - public Builder httpClient(HttpClient httpClient) { + public Builder edge(final String edge) { + this.edge = edge; + return this; + } + + public Builder httpClient(final HttpClient httpClient) { this.httpClient = httpClient; return this; } + public Builder userAgentExtensions(final List userAgentExtensions) { + if (userAgentExtensions != null && !userAgentExtensions.isEmpty()) { + this.userAgentExtensions = new ArrayList<>(userAgentExtensions); + } + return this; + } + + public Builder objectMapper(final ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + return this; + } + /** * Build new TwilioRestClient. - * + * * @return TwilioRestClient instance */ public TwilioRestClient build() { @@ -105,4 +221,32 @@ public TwilioRestClient build() { } } + /** + * Logging debug information about HTTP request. + */ + public void logRequest(final Request request) { + if (logger.isDebugEnabled()) { + logger.debug("-- BEGIN Twilio API Request --"); + logger.debug("request method: " + request.getMethod()); + logger.debug("request URL: " + request.constructURL().toString()); + final Map> queryParams = request.getQueryParams(); + final Map> headerParams = request.getHeaderParams(); + + if (queryParams != null && !queryParams.isEmpty()) { + logger.debug("query parameters: " + queryParams); + } + + if (headerParams != null && !headerParams.isEmpty()) { + logger.debug("header parameters: "); + for (String key : headerParams.keySet()) { + if (!key.toLowerCase().contains("authorization")) { + logger.debug(key + ": " + headerParams.get(key)); + } + } + } + + logger.debug("-- END Twilio API Request --"); + } + } + } diff --git a/src/main/java/com/twilio/http/ValidationClient.java b/src/main/java/com/twilio/http/ValidationClient.java index 6fd0aa8c1a..fe196573e0 100644 --- a/src/main/java/com/twilio/http/ValidationClient.java +++ b/src/main/java/com/twilio/http/ValidationClient.java @@ -1,93 +1,225 @@ package com.twilio.http; - -import com.google.common.collect.Lists; import com.twilio.Twilio; +import com.twilio.constant.EnumConstants; import com.twilio.exception.ApiException; -import org.apache.http.Header; -import org.apache.http.HttpHeaders; -import org.apache.http.HttpResponse; -import org.apache.http.HttpVersion; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.RequestBuilder; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.message.BasicHeader; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.security.SecureDigestAlgorithm; +import java.util.ArrayList; +import java.util.Map.Entry; +import org.apache.hc.client5.http.classic.methods.HttpDelete; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpPatch; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.classic.methods.HttpPut; +import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.entity.UrlEncodedFormEntity; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpHeaders; +import org.apache.hc.core5.http.NameValuePair; +import org.apache.hc.core5.http.io.SocketConfig; +import org.apache.hc.core5.http.io.entity.StringEntity; +import org.apache.hc.core5.http.message.BasicHeader; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.security.PrivateKey; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; +import org.apache.hc.core5.http.message.BasicNameValuePair; + +import java.security.Key; public class ValidationClient extends HttpClient { - private static final int CONNECTION_TIMEOUT = 10000; - private static final int SOCKET_TIMEOUT = 30500; + private final CloseableHttpClient client; - private final org.apache.http.client.HttpClient client; + /** + * Create a new ValidationClient. + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Credential SID + * @param signingKey Twilio Signing key + * @param privateKey Private Key + */ + public ValidationClient(final String accountSid, + final String credentialSid, + final String signingKey, + final PrivateKey privateKey) { + this(accountSid, credentialSid, signingKey, privateKey, DEFAULT_REQUEST_CONFIG); + } /** * Create a new ValidationClient. - * - * @param accountSid Twilio Account SID - * @param credentialSid Twilio Credential SID - * @param signingKey Twilio Signing key - * @param privateKey Private Key + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Credential SID + * @param signingKey Twilio Signing key + * @param privateKey Private Key + * @param algorithm Client validation algorithm */ - public ValidationClient(String accountSid, String credentialSid, String signingKey, PrivateKey privateKey) { - RequestConfig config = RequestConfig.custom() - .setConnectTimeout(CONNECTION_TIMEOUT) - .setSocketTimeout(SOCKET_TIMEOUT) - .build(); + public ValidationClient(final String accountSid, + final String credentialSid, + final String signingKey, + final PrivateKey privateKey, + final SecureDigestAlgorithm algorithm) { + this(accountSid, credentialSid, signingKey, privateKey, DEFAULT_REQUEST_CONFIG, algorithm); + } - Collection
headers = Lists.
newArrayList( + /** + * Create a new ValidationClient. + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Credential SID + * @param signingKey Twilio Signing key + * @param privateKey Private Key + * @param requestConfig HTTP Request Config + */ + public ValidationClient(final String accountSid, + final String credentialSid, + final String signingKey, + final PrivateKey privateKey, + final RequestConfig requestConfig) { + this(accountSid, credentialSid, signingKey, privateKey, requestConfig, DEFAULT_SOCKET_CONFIG, Jwts.SIG.RS256); + } + + /** + * Create a new ValidationClient. + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Credential SID + * @param signingKey Twilio Signing key + * @param privateKey Private Key + * @param requestConfig HTTP Request Config + * @param algorithm Client validation algorithm + */ + public ValidationClient(final String accountSid, + final String credentialSid, + final String signingKey, + final PrivateKey privateKey, + final RequestConfig requestConfig, + final SecureDigestAlgorithm algorithm) { + this(accountSid, credentialSid, signingKey, privateKey, requestConfig, DEFAULT_SOCKET_CONFIG, algorithm); + } + + /** + * Create a new ValidationClient. + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Credential SID + * @param signingKey Twilio Signing key + * @param privateKey Private Key + * @param requestConfig HTTP Request Config + * @param socketConfig HTTP Socket Config + */ + public ValidationClient(final String accountSid, + final String credentialSid, + final String signingKey, + final PrivateKey privateKey, + final RequestConfig requestConfig, + final SocketConfig socketConfig) { + + this(accountSid, credentialSid, signingKey, privateKey, requestConfig, socketConfig, Jwts.SIG.RS256); + } + + /** + * Create a new ValidationClient. + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Credential SID + * @param signingKey Twilio Signing key + * @param privateKey Private Key + * @param requestConfig HTTP Request Config + * @param socketConfig HTTP Socket Config + * @param algorithm Client validation algorithm + */ + public ValidationClient(final String accountSid, + final String credentialSid, + final String signingKey, + final PrivateKey privateKey, + final RequestConfig requestConfig, + final SocketConfig socketConfig, + final SecureDigestAlgorithm algorithm) { + + Collection headers = Arrays.asList( new BasicHeader("X-Twilio-Client", "java-" + Twilio.VERSION), - new BasicHeader(HttpHeaders.USER_AGENT, "twilio-java/" + Twilio.VERSION + " (" + Twilio.JAVA_VERSION + ")"), new BasicHeader(HttpHeaders.ACCEPT, "application/json"), new BasicHeader(HttpHeaders.ACCEPT_ENCODING, "utf-8") ); + final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); + connectionManager.setDefaultSocketConfig(socketConfig); + /* + * Example: Lets say client has one server. + * There are 4 servers on edge handling client request. + * Each request takes on an average 500ms (2 request per second) + * Total number request can be server in a second from a route: 20 * 4 * 2 (DefaultMaxPerRoute * edge servers * request per second) + */ + connectionManager.setDefaultMaxPerRoute(20); + connectionManager.setMaxTotal(100); client = HttpClientBuilder.create() - .setConnectionManager(new PoolingHttpClientConnectionManager()) - .setDefaultRequestConfig(config) + .setConnectionManager(connectionManager) + .setDefaultRequestConfig(requestConfig) .setDefaultHeaders(headers) - .setMaxConnPerRoute(10) - .addInterceptorLast(new ValidationInterceptor(accountSid, credentialSid, signingKey, privateKey)) + .addRequestInterceptorLast(new ValidationInterceptor(accountSid, credentialSid, signingKey, privateKey, algorithm)) + .setRedirectStrategy(this.getRedirectStrategy()) .build(); } @Override public Response makeRequest(Request request) { - RequestBuilder builder = RequestBuilder.create(request.getMethod().toString()) - .setUri(request.constructURL().toString()) - .setVersion(HttpVersion.HTTP_1_1) - .setCharset(StandardCharsets.UTF_8); + HttpMethod method = request.getMethod(); + HttpUriRequestBase httpUriRequestBase = createHttpUriRequestBase(request); if (request.requiresAuthentication()) { - builder.addHeader(HttpHeaders.AUTHORIZATION, request.getAuthString()); + httpUriRequestBase.addHeader(HttpHeaders.AUTHORIZATION, request.getAuthString()); } - HttpMethod method = request.getMethod(); - if (method == HttpMethod.POST) { - builder.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); - - for (Map.Entry> entry : request.getPostParams().entrySet()) { - for (String value : entry.getValue()) { - builder.addParameter(entry.getKey(), value); + if (method != HttpMethod.GET) { + // TODO: It will be removed after one RC Release. + if (request.getContentType() == null) request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + if (EnumConstants.ContentType.JSON.getValue().equals(request.getContentType().getValue())) { + HttpEntity entity = new StringEntity(request.getBody(), ContentType.APPLICATION_JSON); + httpUriRequestBase.setEntity(entity); + httpUriRequestBase.addHeader( + HttpHeaders.CONTENT_TYPE, EnumConstants.ContentType.JSON.getValue()); + } else { + httpUriRequestBase.addHeader( + HttpHeaders.CONTENT_TYPE, EnumConstants.ContentType.FORM_URLENCODED.getValue()); + // Create your form parameters + List formParams = new ArrayList<>(); + for ( Entry> entry : request.getPostParams().entrySet()) { + for (String value : entry.getValue()) { + formParams.add(new BasicNameValuePair(entry.getKey(), value)); + } } + + // Build the entity with URL form encoded parameters + UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(formParams, StandardCharsets.UTF_8); + // Set the entity on the request + httpUriRequestBase.setEntity(formEntity); } } + httpUriRequestBase.addHeader(HttpHeaders.USER_AGENT, HttpUtility.getUserAgentString(request.getUserAgentExtensions())); + try { - HttpResponse response = client.execute(builder.build()); + CloseableHttpResponse response = client.execute(httpUriRequestBase); return new Response( response.getEntity() == null ? null : response.getEntity().getContent(), - response.getStatusLine().getStatusCode() + response.getCode(), + response.getHeaders() ); } catch (IOException e) { - throw new ApiException(e.getMessage()); + throw new ApiException(e.getMessage(), e); } } } diff --git a/src/main/java/com/twilio/http/ValidationInterceptor.java b/src/main/java/com/twilio/http/ValidationInterceptor.java index 61442b68bc..1a620313a4 100644 --- a/src/main/java/com/twilio/http/ValidationInterceptor.java +++ b/src/main/java/com/twilio/http/ValidationInterceptor.java @@ -1,50 +1,73 @@ package com.twilio.http; -import com.google.common.collect.Lists; import com.twilio.jwt.Jwt; import com.twilio.jwt.validation.ValidationToken; -import org.apache.http.HttpException; -import org.apache.http.HttpRequest; -import org.apache.http.HttpRequestInterceptor; -import org.apache.http.protocol.HttpContext; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.security.SecureDigestAlgorithm; +import org.apache.hc.core5.http.EntityDetails; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpException; +import org.apache.hc.core5.http.HttpRequest; +import org.apache.hc.core5.http.HttpRequestInterceptor; import java.io.IOException; import java.security.PrivateKey; +import java.util.Arrays; import java.util.List; +import org.apache.hc.core5.http.protocol.HttpContext; public class ValidationInterceptor implements HttpRequestInterceptor { - private static final List HEADERS = Lists.newArrayList("authorization", "host"); + private static final List HEADERS = Arrays.asList("authorization", "host"); private final String accountSid; private final String credentialSid; private final String signingKeySid; private final PrivateKey privateKey; + private final SecureDigestAlgorithm algorithm; /** * Create a new ValidationInterceptor. - * - * @param accountSid Twilio Acocunt SID - * @param credentialSid Twilio Credential SID - * @param signingKeySid Twilio Signing Key - * @param privateKey Private Key + * + * @param accountSid Twilio Acocunt SID + * @param credentialSid Twilio Credential SID + * @param signingKeySid Twilio Signing Key + * @param privateKey Private Key */ public ValidationInterceptor(String accountSid, String credentialSid, String signingKeySid, PrivateKey privateKey) { + + this(accountSid, credentialSid, signingKeySid, privateKey, Jwts.SIG.RS256); + } + + + /** + * Create a new ValidationInterceptor. + * + * @param accountSid Twilio Acocunt SID + * @param credentialSid Twilio Credential SID + * @param signingKeySid Twilio Signing Key + * @param privateKey Private Key + * @param algorithm Client validaiton algorithm + */ + public ValidationInterceptor(String accountSid, String credentialSid, String signingKeySid, PrivateKey privateKey, + SecureDigestAlgorithm algorithm) { this.accountSid = accountSid; this.credentialSid = credentialSid; this.signingKeySid = signingKeySid; this.privateKey = privateKey; + this.algorithm = algorithm; } @Override - public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { + public void process(HttpRequest request, EntityDetails httpEntity, HttpContext context) throws HttpException, IOException { Jwt jwt = ValidationToken.fromHttpRequest( - accountSid, - credentialSid, - signingKeySid, - privateKey, - request, - HEADERS + accountSid, + credentialSid, + signingKeySid, + privateKey, + request, + HEADERS, + algorithm ); request.addHeader("Twilio-Client-Validation", jwt.toJwt()); } diff --git a/src/main/java/com/twilio/http/bearertoken/ApiTokenManager.java b/src/main/java/com/twilio/http/bearertoken/ApiTokenManager.java new file mode 100644 index 0000000000..b378e0288b --- /dev/null +++ b/src/main/java/com/twilio/http/bearertoken/ApiTokenManager.java @@ -0,0 +1,71 @@ +package com.twilio.http.bearertoken; + +import com.twilio.annotations.Beta; +import com.twilio.rest.oauth.v2.Token; +import com.twilio.rest.oauth.v2.TokenCreator; + +import java.util.Objects; + +@Beta +public class ApiTokenManager implements TokenManager { + + private final String grantType; + private final String clientId; + private final String clientSecret; + private String code; + private String redirectUri; + private String audience; + private String refreshToken; + private String scope; + + @Override + public String fetchAccessToken() { + TokenCreator tokenCreator = Token.creator(grantType).setClientId(clientId).setClientSecret(clientSecret); + + if (this.code != null) tokenCreator.setCode(code); + if (this.redirectUri != null) tokenCreator.setRedirectUri(redirectUri); + if (this.audience != null) tokenCreator.setAudience(audience); + if (this.refreshToken != null) tokenCreator.setRefreshToken(refreshToken); + if (this.scope != null) tokenCreator.setScope(scope); + Token token = tokenCreator.create(); + return token.getAccessToken(); + } + + public ApiTokenManager(String grantType, String clientId, String clientSecret){ + this.grantType = grantType; + this.clientId = clientId; + this.clientSecret = clientSecret; + } + + public ApiTokenManager(String grantType, String clientId, String clientSecret, String code, String redirectUri, String audience, String refreshToken, String scope){ + this.grantType = grantType; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.code = code; + this.redirectUri = redirectUri; + this.audience = audience; + this.refreshToken = refreshToken; + this.scope = scope; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ApiTokenManager other = (ApiTokenManager) o; + return Objects.equals(grantType, other.grantType) && + Objects.equals(clientId, other.clientId) && + Objects.equals(clientSecret, other.clientSecret) && + Objects.equals(code, other.code) && + Objects.equals(redirectUri, other.redirectUri) && + Objects.equals(audience, other.audience) && + Objects.equals(refreshToken, other.refreshToken) && + Objects.equals(scope, other.scope); + } +} diff --git a/src/main/java/com/twilio/http/bearertoken/OrgsTokenManager.java b/src/main/java/com/twilio/http/bearertoken/OrgsTokenManager.java new file mode 100644 index 0000000000..3125c15059 --- /dev/null +++ b/src/main/java/com/twilio/http/bearertoken/OrgsTokenManager.java @@ -0,0 +1,54 @@ +package com.twilio.http.bearertoken; + +import com.twilio.annotations.Beta; +import com.twilio.exception.ApiException; +import com.twilio.rest.oauth.v2.Token; +import com.twilio.rest.oauth.v2.TokenCreator; +@Beta +public class OrgsTokenManager implements TokenManager{ + + private final String grantType; + private final String clientId; + private final String clientSecret; + private String code; + private String redirectUri; + private String audience; + private String refreshToken; + private String scope; + + public OrgsTokenManager(String grantType, String clientId, String clientSecret){ + this.grantType = grantType; + this.clientId = clientId; + this.clientSecret = clientSecret; + } + + public OrgsTokenManager(String grantType, String clientId, String clientSecret, String code, String redirectUri, String audience, String refreshToken, String scope){ + this.grantType = grantType; + this.clientId = clientId; + this.clientSecret = clientSecret; + this.code = code; + this.redirectUri = redirectUri; + this.audience = audience; + this.refreshToken = refreshToken; + this.scope = scope; + } + + public synchronized String fetchAccessToken(){ + TokenCreator tokenCreator = Token.creator(grantType).setClientId(clientId).setClientSecret(clientSecret); + if (this.code != null) tokenCreator.setCode(code); + if (this.redirectUri != null) tokenCreator.setRedirectUri(redirectUri); + if (this.audience != null) tokenCreator.setAudience(audience); + if (this.refreshToken != null) tokenCreator.setRefreshToken(refreshToken); + if (this.scope != null) tokenCreator.setScope(scope); + Token token; + try { + token = tokenCreator.create(); + if(token == null || token.getAccessToken() == null){ + throw new ApiException("Token creation failed"); + } + } catch(Exception e){ + throw new ApiException("Token creation failed"); + } + return token.getAccessToken(); + } +} diff --git a/src/main/java/com/twilio/http/bearertoken/TokenManager.java b/src/main/java/com/twilio/http/bearertoken/TokenManager.java new file mode 100644 index 0000000000..5165cc1c94 --- /dev/null +++ b/src/main/java/com/twilio/http/bearertoken/TokenManager.java @@ -0,0 +1,5 @@ +package com.twilio.http.bearertoken; + +public interface TokenManager { + String fetchAccessToken(); +} \ No newline at end of file diff --git a/src/main/java/com/twilio/jwt/Jwt.java b/src/main/java/com/twilio/jwt/Jwt.java index da8349312e..48c888f025 100644 --- a/src/main/java/com/twilio/jwt/Jwt.java +++ b/src/main/java/com/twilio/jwt/Jwt.java @@ -2,7 +2,7 @@ import io.jsonwebtoken.JwtBuilder; import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.security.SecureDigestAlgorithm; import javax.crypto.spec.SecretKeySpec; import java.security.Key; @@ -15,7 +15,7 @@ */ public abstract class Jwt { - private final SignatureAlgorithm algorithm; + private final SecureDigestAlgorithm algorithm; private final Key secretKey; private final String issuer; private final Date expiration; @@ -29,17 +29,17 @@ public abstract class Jwt { * @param expiration expiration Date */ public Jwt( - SignatureAlgorithm algorithm, - String secret, + SecureDigestAlgorithm algorithm, + byte[] secret, String issuer, Date expiration ) { - this( - algorithm, - new SecretKeySpec(secret.getBytes(), algorithm.getJcaName()), - issuer, - expiration - ); + this.algorithm = algorithm; + String id = algorithm.getId(); + String jcaName = "HmacSHA" + id.substring(2); + this.secretKey = new SecretKeySpec(secret, jcaName); + this.issuer = issuer; + this.expiration = expiration; } /** @@ -51,7 +51,7 @@ public Jwt( * @param expiration expiration Date */ public Jwt( - SignatureAlgorithm algorithm, + SecureDigestAlgorithm algorithm, Key secretKey, String issuer, Date expiration @@ -72,9 +72,11 @@ public String toJwt() { headers.put("typ", "JWT"); headers.putAll(this.getHeaders()); + @SuppressWarnings("unchecked") + SecureDigestAlgorithm alg = (SecureDigestAlgorithm) this.algorithm; JwtBuilder builder = Jwts.builder() - .signWith(this.algorithm, this.secretKey) + .signWith(this.secretKey, alg) .setHeaderParams(headers) .setIssuer(this.issuer) .setExpiration(expiration); diff --git a/src/main/java/com/twilio/jwt/accesstoken/AccessToken.java b/src/main/java/com/twilio/jwt/accesstoken/AccessToken.java index 41356add42..22e29660fc 100644 --- a/src/main/java/com/twilio/jwt/accesstoken/AccessToken.java +++ b/src/main/java/com/twilio/jwt/accesstoken/AccessToken.java @@ -1,7 +1,7 @@ package com.twilio.jwt.accesstoken; import com.twilio.jwt.Jwt; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.Jwts; import java.util.Collection; import java.util.Collections; @@ -27,12 +27,13 @@ public class AccessToken extends Jwt { private final String id; private final String accountSid; private final String identity; + private final String region; private final Date nbf; private final Set grants; private AccessToken(Builder b) { super( - SignatureAlgorithm.HS256, + Jwts.SIG.HS256, b.secret, b.keySid, new Date(new Date().getTime() + b.ttl * 1000) @@ -42,6 +43,7 @@ private AccessToken(Builder b) { this.id = b.keySid + "-" + (int)(Math.floor(now.getTime() / 1000.0f)); this.accountSid = b.accountSid; this.identity = b.identity; + this.region = b.region; this.nbf = b.nbf; this.grants = Collections.unmodifiableSet(b.grants); } @@ -65,6 +67,9 @@ public String getSubject() { public Map getHeaders() { Map headers = new HashMap<>(); headers.put("cty", CTY); + if (this.region != null && !"".equals(this.region)) { + headers.put("twr", this.region); + } return headers; } @@ -89,8 +94,9 @@ public Map getClaims() { public static class Builder { private String accountSid; private String keySid; - private String secret; + private byte[] secret; private String identity; + private String region; private Date nbf = null; private int ttl = 3600; private Set grants = new HashSet(); @@ -102,7 +108,7 @@ public static class Builder { * @param keySid key to use * @param secret secret key */ - public Builder(String accountSid, String keySid, String secret) { + public Builder(String accountSid, String keySid, byte[] secret) { this.accountSid = accountSid; this.keySid = keySid; this.secret = secret; @@ -113,6 +119,11 @@ public Builder identity(String identity) { return this; } + public Builder region(String region) { + this.region = region; + return this; + } + public Builder ttl(int ttl) { this.ttl = ttl; return this; diff --git a/src/main/java/com/twilio/jwt/accesstoken/ChatGrant.java b/src/main/java/com/twilio/jwt/accesstoken/ChatGrant.java index 03a658347e..b972cae53f 100644 --- a/src/main/java/com/twilio/jwt/accesstoken/ChatGrant.java +++ b/src/main/java/com/twilio/jwt/accesstoken/ChatGrant.java @@ -1,5 +1,6 @@ package com.twilio.jwt.accesstoken; +import com.fasterxml.jackson.annotation.JsonInclude; /** * Grant used to access Twilio Chat. * @@ -63,6 +64,7 @@ public Object getPayload() { } @SuppressWarnings("checkstyle:membername") + @JsonInclude(JsonInclude.Include.NON_NULL) public class Payload { public final String service_sid; public final String deployment_role_sid; diff --git a/src/main/java/com/twilio/jwt/accesstoken/ConversationsGrant.java b/src/main/java/com/twilio/jwt/accesstoken/ConversationsGrant.java deleted file mode 100644 index 3b007a9805..0000000000 --- a/src/main/java/com/twilio/jwt/accesstoken/ConversationsGrant.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.twilio.jwt.accesstoken; - -/** - * Grant used to access Twilio Conversations. - * - * @deprecated use {@link VideoGrant} instead. - *

- * For more information see: - * - * https://www.twilio.com/docs/api/rest/access-tokens - * - *

- */ -@Deprecated -public class ConversationsGrant implements Grant { - - private String configurationProfileSid; - - public String getConfigurationProfileSid() { - return configurationProfileSid; - } - - public ConversationsGrant setConfigurationProfileSid(String configurationProfileSid) { - this.configurationProfileSid = configurationProfileSid; - return this; - } - - public String getGrantKey() { - return "rtc"; - } - - public Object getPayload() { - return new Payload(this); - } - - - @SuppressWarnings("checkstyle:membername") - public class Payload { - public final String configuration_profile_sid; - - /** - * Create the grant payload. - * - * @param grant Conversations grant - */ - public Payload(ConversationsGrant grant) { - this.configuration_profile_sid = grant.configurationProfileSid; - } - } -} diff --git a/src/main/java/com/twilio/jwt/accesstoken/IpMessagingGrant.java b/src/main/java/com/twilio/jwt/accesstoken/IpMessagingGrant.java deleted file mode 100644 index 61bda23845..0000000000 --- a/src/main/java/com/twilio/jwt/accesstoken/IpMessagingGrant.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.twilio.jwt.accesstoken; - -/** - * Grant used to access Twilio IP Messaging. - * - *

- * For more information see: - * - * https://www.twilio.com/docs/api/rest/access-tokens - * - *

- */ -@Deprecated -public class IpMessagingGrant implements Grant { - - private String serviceSid; - private String deploymentRoleSid; - private String pushCredentialSid; - private String endpointId; - - public String getServiceSid() { - return serviceSid; - } - - public IpMessagingGrant setServiceSid(String serviceSid) { - this.serviceSid = serviceSid; - return this; - } - - - public String getPushCredentialSid() { - return pushCredentialSid; - } - - public IpMessagingGrant setPushCredentialSid(String pushCredentialSid) { - this.pushCredentialSid = pushCredentialSid; - return this; - } - - public String getDeploymentRoleSid() { - return deploymentRoleSid; - } - - public IpMessagingGrant setDeploymentRoleSid(String deploymentRoleSid) { - this.deploymentRoleSid = deploymentRoleSid; - return this; - } - - public String getEndpointId() { - return endpointId; - } - - public IpMessagingGrant setEndpointId(String endpointId) { - this.endpointId = endpointId; - return this; - } - - public String getGrantKey() { - return "ip_messaging"; - } - - public Object getPayload() { - return new Payload(this); - } - - @SuppressWarnings("checkstyle:membername") - public class Payload { - public final String service_sid; - public final String deployment_role_sid; - public final String endpoint_id; - public final String push_credential_sid; - - /** - * Create the grant payload. - * - * @param grant IP Messaging grant - */ - public Payload(IpMessagingGrant grant) { - this.service_sid = grant.serviceSid; - this.deployment_role_sid = grant.deploymentRoleSid; - this.endpoint_id = grant.endpointId; - this.push_credential_sid = grant.pushCredentialSid; - } - } -} diff --git a/src/main/java/com/twilio/jwt/accesstoken/PlaybackGrant.java b/src/main/java/com/twilio/jwt/accesstoken/PlaybackGrant.java new file mode 100644 index 0000000000..b7f439f024 --- /dev/null +++ b/src/main/java/com/twilio/jwt/accesstoken/PlaybackGrant.java @@ -0,0 +1,44 @@ +package com.twilio.jwt.accesstoken; + +import java.util.Map; + +/** + * Grant used to access Twilio Live. + * + *

+ * For more information see: + * + * https://www.twilio.com/docs/api/rest/access-tokens + * + *

+ */ +public class PlaybackGrant implements Grant { + + private Map grant; + + /** + * Get the grant payload configured in this grant. + * @return The grant payload or null if not set. + */ + public Map getGrant() { + return this.grant; + } + + /** + * Set the playback grant + * @param grant the playback grant + * @return updated PlaybackGrant instance + */ + public PlaybackGrant setGrant(final Map grant) { + this.grant = grant; + return this; + } + + public String getGrantKey() { + return "player"; + } + + public Object getPayload() { + return this.grant; + } +} diff --git a/src/main/java/com/twilio/jwt/accesstoken/SyncGrant.java b/src/main/java/com/twilio/jwt/accesstoken/SyncGrant.java index 8850b8b3ed..6b28a525d8 100644 --- a/src/main/java/com/twilio/jwt/accesstoken/SyncGrant.java +++ b/src/main/java/com/twilio/jwt/accesstoken/SyncGrant.java @@ -1,5 +1,7 @@ package com.twilio.jwt.accesstoken; +import com.fasterxml.jackson.annotation.JsonInclude; + /** * Grant used to access Twilio Sync. * @@ -44,6 +46,7 @@ public Object getPayload() { } @SuppressWarnings("checkstyle:membername") + @JsonInclude(JsonInclude.Include.NON_NULL) public class Payload { public final String service_sid; public final String endpoint_id; diff --git a/src/main/java/com/twilio/jwt/accesstoken/TaskRouterGrant.java b/src/main/java/com/twilio/jwt/accesstoken/TaskRouterGrant.java index c123e6e042..18703640a8 100644 --- a/src/main/java/com/twilio/jwt/accesstoken/TaskRouterGrant.java +++ b/src/main/java/com/twilio/jwt/accesstoken/TaskRouterGrant.java @@ -1,5 +1,7 @@ package com.twilio.jwt.accesstoken; +import com.fasterxml.jackson.annotation.JsonInclude; + /** * Grant used to access Twilio TaskRouter. * @@ -54,6 +56,7 @@ public Object getPayload() { } @SuppressWarnings("checkstyle:membername") + @JsonInclude(JsonInclude.Include.NON_NULL) public class Payload { public final String workspace_sid; public final String worker_sid; diff --git a/src/main/java/com/twilio/jwt/accesstoken/VideoGrant.java b/src/main/java/com/twilio/jwt/accesstoken/VideoGrant.java index 8d46800836..370276104c 100644 --- a/src/main/java/com/twilio/jwt/accesstoken/VideoGrant.java +++ b/src/main/java/com/twilio/jwt/accesstoken/VideoGrant.java @@ -14,31 +14,8 @@ */ public class VideoGrant implements Grant { - private String configurationProfileSid; private String room; - /** - * Get the configuration profile sid of this grant. - * @deprecated use {@link #getRoom()} instead. - * @return The configuration profile sid or null if not set. - */ - @Deprecated - public String getConfigurationProfileSid() { - return this.configurationProfileSid; - } - - /** - * Set the configuration profile sid on the grant. - * @deprecated use {@link #setRoom(String)} instead. - * @param configurationProfileSid configuration profile sid - * @return updated VideoGrant instance - */ - @Deprecated - public VideoGrant setConfigurationProfileSid(final String configurationProfileSid) { - this.configurationProfileSid = configurationProfileSid; - return this; - } - /** * Get the room configured in this grant. * @return The room name or sid or null if not set. @@ -67,13 +44,11 @@ public Object getPayload() { @SuppressWarnings("checkstyle:membername") - @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonInclude(JsonInclude.Include.NON_NULL) public class Payload { - public final String configuration_profile_sid; public final String room; public Payload(VideoGrant grant) { - this.configuration_profile_sid = grant.configurationProfileSid; this.room = grant.room; } } diff --git a/src/main/java/com/twilio/jwt/accesstoken/VoiceGrant.java b/src/main/java/com/twilio/jwt/accesstoken/VoiceGrant.java index 9c717ee7c8..f2d2a7e506 100644 --- a/src/main/java/com/twilio/jwt/accesstoken/VoiceGrant.java +++ b/src/main/java/com/twilio/jwt/accesstoken/VoiceGrant.java @@ -1,6 +1,6 @@ package com.twilio.jwt.accesstoken; -import com.google.common.base.Strings; +import com.fasterxml.jackson.annotation.JsonInclude; import java.util.HashMap; import java.util.Map; @@ -35,9 +35,9 @@ public VoiceGrant setOutgoingApplicationSid(String outgoingApplicationSid) { /** * Set the outgoing application. - * - * @param outgoingApplicationSid outgoing application sid - * @param outgoingApplicationParams outgoing application parameters + * + * @param outgoingApplicationSid outgoing application sid + * @param outgoingApplicationParams outgoing application parameters * @return voice grant */ public VoiceGrant setOutgoingApplication( @@ -70,6 +70,7 @@ public Object getPayload() { } @SuppressWarnings("checkstyle:membername") + @JsonInclude(JsonInclude.Include.NON_NULL) public class Payload { public Map incoming; public Map outgoing; @@ -78,16 +79,16 @@ public class Payload { /** * Generate VoiceGrant payload. - * - * @param grant VoiceGrant + * + * @param grant VoiceGrant */ public Payload(VoiceGrant grant) { - if (grant.incomingAllow == true) { - this.incoming = new HashMap<>(); - this.incoming.put("allow", true); + if (grant.incomingAllow != null) { + this.incoming = new HashMap<>(); + this.incoming.put("allow", grant.incomingAllow); } - if (!Strings.isNullOrEmpty(grant.outgoingApplicationSid)) { + if (grant.outgoingApplicationSid != null && !grant.outgoingApplicationSid.isEmpty()) { this.outgoing = new HashMap<>(); this.outgoing.put("application_sid", grant.outgoingApplicationSid); @@ -96,14 +97,13 @@ public Payload(VoiceGrant grant) { } } - if (!Strings.isNullOrEmpty(grant.pushCredentialSid)) { + if (grant.pushCredentialSid != null && !grant.pushCredentialSid.isEmpty()) { this.push_credential_sid = grant.pushCredentialSid; } - if (!Strings.isNullOrEmpty(grant.endpointId)) { + if (grant.endpointId != null && !grant.endpointId.isEmpty()) { this.endpoint_id = grant.endpointId; } } } - } diff --git a/src/main/java/com/twilio/jwt/client/ClientCapability.java b/src/main/java/com/twilio/jwt/client/ClientCapability.java index 30c688ea66..8ebf7974e4 100644 --- a/src/main/java/com/twilio/jwt/client/ClientCapability.java +++ b/src/main/java/com/twilio/jwt/client/ClientCapability.java @@ -1,10 +1,8 @@ package com.twilio.jwt.client; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; import com.twilio.jwt.Jwt; import com.twilio.jwt.JwtEncodingException; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.Jwts; import java.io.UnsupportedEncodingException; import java.util.ArrayList; @@ -23,7 +21,7 @@ public class ClientCapability extends Jwt { private ClientCapability(Builder b) { super( - SignatureAlgorithm.HS256, + Jwts.SIG.HS256, b.authToken, b.accountSid, new Date(new Date().getTime() + b.ttl * 1000) @@ -48,7 +46,7 @@ public Map getClaims() { for (Scope scope : this.scopes) { scopes.add(scope.getPayload()); } - payload.put("scope", Joiner.on(' ').join(scopes)); + payload.put("scope", String.join(" ", scopes)); } catch (UnsupportedEncodingException e) { throw new JwtEncodingException(e); } @@ -59,9 +57,9 @@ public Map getClaims() { /** Builder used to construct a Client Capability. */ public static class Builder { private String accountSid; - private String authToken; + private byte[] authToken; private int ttl = 3600; - private List scopes = Lists.newArrayList(); + private List scopes = new ArrayList<>(); /** * Create a new builder for a Client Capability. @@ -69,7 +67,7 @@ public static class Builder { * @param accountSid account to use * @param authToken auth token */ - public Builder(String accountSid, String authToken) { + public Builder(String accountSid, byte[] authToken) { this.accountSid = accountSid; this.authToken = authToken; } diff --git a/src/main/java/com/twilio/jwt/client/EventStreamScope.java b/src/main/java/com/twilio/jwt/client/EventStreamScope.java index b592a5ba09..7b2605a599 100644 --- a/src/main/java/com/twilio/jwt/client/EventStreamScope.java +++ b/src/main/java/com/twilio/jwt/client/EventStreamScope.java @@ -1,7 +1,5 @@ package com.twilio.jwt.client; -import com.google.common.base.Joiner; - import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; @@ -14,7 +12,7 @@ */ public class EventStreamScope implements Scope { - private static final String SCOPE = Joiner.on(':').join("scope", "stream", "subscribe"); + private static final String SCOPE = String.join(":", "scope", "stream", "subscribe"); private final Map filters; @@ -28,25 +26,25 @@ public String getPayload() throws UnsupportedEncodingException { queryArgs.add("path=/2010-04-01/Events"); if (!this.filters.isEmpty()) { - queryArgs.add(Joiner.on('=').join( - URLEncoder.encode("appParams", "UTF-8"), + queryArgs.add(String.join("=", + URLEncoder.encode("appParams", "UTF-8"), URLEncoder.encode(this.getFilterParams(), "UTF-8") )); } - String queryString = Joiner.on('&').join(queryArgs); - return Joiner.on('?').join(SCOPE, queryString); + String queryString = String.join("&", queryArgs); + return String.join("?", SCOPE, queryString); } private String getFilterParams() throws UnsupportedEncodingException { List queryParams = new ArrayList<>(); for (Map.Entry param : filters.entrySet()) { - queryParams.add(Joiner.on('=').join( - URLEncoder.encode(param.getKey(), "UTF-8"), + queryParams.add(String.join("=", + URLEncoder.encode(param.getKey(), "UTF-8"), URLEncoder.encode(param.getValue(), "UTF-8") )); } - return Joiner.on('&').join(queryParams); + return String.join("&", queryParams); } public static class Builder { diff --git a/src/main/java/com/twilio/jwt/client/IncomingClientScope.java b/src/main/java/com/twilio/jwt/client/IncomingClientScope.java index 507e6700c9..d166411e6f 100644 --- a/src/main/java/com/twilio/jwt/client/IncomingClientScope.java +++ b/src/main/java/com/twilio/jwt/client/IncomingClientScope.java @@ -1,7 +1,5 @@ package com.twilio.jwt.client; -import com.google.common.base.Joiner; - import java.io.UnsupportedEncodingException; /** @@ -9,7 +7,7 @@ */ public class IncomingClientScope implements Scope { - private static final String SCOPE = Joiner.on(':').join("scope", "client", "incoming"); + private static final String SCOPE = String.join(":", "scope", "client", "incoming"); private final String clientName; @@ -19,7 +17,7 @@ public IncomingClientScope(String clientName) { @Override public String getPayload() throws UnsupportedEncodingException { - String query = Joiner.on('=').join("clientName", this.clientName); - return Joiner.on('?').join(SCOPE, query); + String query = String.join("=", "clientName", this.clientName); + return String.join("?", SCOPE, query); } } diff --git a/src/main/java/com/twilio/jwt/client/OutgoingClientScope.java b/src/main/java/com/twilio/jwt/client/OutgoingClientScope.java index cba82ca79e..b941339718 100644 --- a/src/main/java/com/twilio/jwt/client/OutgoingClientScope.java +++ b/src/main/java/com/twilio/jwt/client/OutgoingClientScope.java @@ -1,7 +1,5 @@ package com.twilio.jwt.client; -import com.google.common.base.Joiner; - import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; @@ -14,7 +12,7 @@ */ public class OutgoingClientScope implements Scope { - private static final String SCOPE = Joiner.on(':').join("scope", "client", "outgoing"); + private static final String SCOPE = String.join(":", "scope", "client", "outgoing"); private final String applicationSid; private final String clientName; @@ -29,38 +27,38 @@ private OutgoingClientScope(Builder b) { @Override public String getPayload() throws UnsupportedEncodingException { List queryArgs = new ArrayList<>(); - queryArgs.add(Joiner.on('=').join( - URLEncoder.encode("appSid", "UTF-8"), + queryArgs.add(String.join("=", + URLEncoder.encode("appSid", "UTF-8"), URLEncoder.encode(this.applicationSid, "UTF-8") )); if (this.clientName != null) { - queryArgs.add(Joiner.on('=').join( - URLEncoder.encode("clientName", "UTF-8"), + queryArgs.add(String.join("=", + URLEncoder.encode("clientName", "UTF-8"), URLEncoder.encode(this.clientName, "UTF-8") )); } if (!this.params.isEmpty()) { - queryArgs.add(Joiner.on('=').join( - URLEncoder.encode("appParams", "UTF-8"), + queryArgs.add(String.join("=", + URLEncoder.encode("appParams", "UTF-8"), URLEncoder.encode(this.getAppParams(), "UTF-8") )); } - String queryString = Joiner.on('&').join(queryArgs); - return Joiner.on('?').join(SCOPE, queryString); + String queryString = String.join("&", queryArgs); + return String.join("?", SCOPE, queryString); } private String getAppParams() throws UnsupportedEncodingException { List queryParams = new ArrayList<>(); for (Map.Entry param : params.entrySet()) { - queryParams.add(Joiner.on('=').join( - URLEncoder.encode(param.getKey(), "UTF-8"), + queryParams.add(String.join("=", + URLEncoder.encode(param.getKey(), "UTF-8"), URLEncoder.encode(param.getValue(), "UTF-8") )); } - return Joiner.on('&').join(queryParams); + return String.join("&", queryParams); } public static class Builder { diff --git a/src/main/java/com/twilio/jwt/taskrouter/Policy.java b/src/main/java/com/twilio/jwt/taskrouter/Policy.java index 254464ca38..d7969eb28a 100644 --- a/src/main/java/com/twilio/jwt/taskrouter/Policy.java +++ b/src/main/java/com/twilio/jwt/taskrouter/Policy.java @@ -4,18 +4,22 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.google.common.base.Objects; import com.twilio.http.HttpMethod; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Map; +import java.util.Objects; + +import lombok.ToString; @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) +@JsonPropertyOrder(alphabetic = true) +@ToString public class Policy { @JsonProperty("url") @@ -88,25 +92,14 @@ public boolean equals(Object o) { Policy policy = (Policy) o; return allowed == policy.allowed && method == policy.method && - Objects.equal(url, policy.url) && - Objects.equal(queryFilter, policy.queryFilter) && - Objects.equal(postFilter, policy.postFilter); + Objects.equals(url, policy.url) && + Objects.equals(queryFilter, policy.queryFilter) && + Objects.equals(postFilter, policy.postFilter); } @Override public int hashCode() { - return Objects.hashCode(url, method, queryFilter, postFilter, allowed); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("url", url) - .add("method", method) - .add("queryFilter", queryFilter) - .add("postFilter", postFilter) - .add("allowed", allowed) - .toString(); + return Objects.hash(url, method, queryFilter, postFilter, allowed); } public static class Builder { diff --git a/src/main/java/com/twilio/jwt/taskrouter/PolicyUtils.java b/src/main/java/com/twilio/jwt/taskrouter/PolicyUtils.java index 3a11feedfb..23577faa79 100644 --- a/src/main/java/com/twilio/jwt/taskrouter/PolicyUtils.java +++ b/src/main/java/com/twilio/jwt/taskrouter/PolicyUtils.java @@ -1,9 +1,8 @@ package com.twilio.jwt.taskrouter; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; import com.twilio.http.HttpMethod; +import java.util.ArrayList; import java.util.List; public class PolicyUtils { @@ -16,50 +15,54 @@ private PolicyUtils() {} * Build the default Polices for a Worker. * * @param workspaceSid Workspace sid of the worker - * @param workerSid Worker sid + * @param workerSid Worker sid * @return generated Policies */ public static List defaultWorkerPolicies(String workspaceSid, String workerSid) { - Policy activities = new Policy.Builder() + final List policies = new ArrayList<>(); + + policies.add(new Policy.Builder() .url(UrlUtils.activities(workspaceSid)) .method(HttpMethod.GET) .allowed(true) - .build(); + .build()); - Policy tasks = new Policy.Builder() + policies.add(new Policy.Builder() .url(UrlUtils.allTasks(workspaceSid)) .method(HttpMethod.GET) .allowed(true) - .build(); + .build()); - Policy reservations = new Policy.Builder() + policies.add(new Policy.Builder() .url(UrlUtils.allReservations(workspaceSid, workerSid)) .method(HttpMethod.GET) .allowed(true) - .build(); - - Policy workerFetch = new Policy.Builder() + .build()); + + policies.add(new Policy.Builder() .url(UrlUtils.worker(workspaceSid, workerSid)) .method(HttpMethod.GET) .allowed(true) - .build(); + .build()); - return Lists.newArrayList(activities, tasks, reservations, workerFetch); + return policies; } /** * Build the default Event Bridge Policies. * * @param accountSid account sid - * @param channelId channel id + * @param channelId channel id * @return generated Policies */ public static List defaultEventBridgePolicies(String accountSid, String channelId) { - String url = Joiner.on('/').join(TASKROUTER_EVENT_URL, accountSid, channelId); + final List policies = new ArrayList<>(); + + String url = String.join("/", TASKROUTER_EVENT_URL, accountSid, channelId); - Policy get = new Policy.Builder().url(url).method(HttpMethod.GET).allowed(true).build(); - Policy post = new Policy.Builder().url(url).method(HttpMethod.POST).allowed(true).build(); + policies.add(new Policy.Builder().url(url).method(HttpMethod.GET).allowed(true).build()); + policies.add(new Policy.Builder().url(url).method(HttpMethod.POST).allowed(true).build()); - return Lists.newArrayList(get, post); + return policies; } } diff --git a/src/main/java/com/twilio/jwt/taskrouter/TaskRouterCapability.java b/src/main/java/com/twilio/jwt/taskrouter/TaskRouterCapability.java index 78799138d4..a43c2905c9 100644 --- a/src/main/java/com/twilio/jwt/taskrouter/TaskRouterCapability.java +++ b/src/main/java/com/twilio/jwt/taskrouter/TaskRouterCapability.java @@ -1,9 +1,9 @@ package com.twilio.jwt.taskrouter; -import com.google.common.collect.Lists; import com.twilio.jwt.Jwt; -import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.Jwts; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -22,7 +22,7 @@ public class TaskRouterCapability extends Jwt { private TaskRouterCapability(Builder b) { super( - SignatureAlgorithm.HS256, + Jwts.SIG.HS256, b.authToken, b.accountSid, new Date(new Date().getTime() + b.ttl * 1000) @@ -57,7 +57,7 @@ public Map getClaims() { payload.put("taskqueue_sid", this.channelId); } - List payloadPolicies = Lists.newArrayList(this.policies); + List payloadPolicies = new ArrayList<>(this.policies); payloadPolicies.addAll(PolicyUtils.defaultEventBridgePolicies(accountSid, channelId)); payload.put("policies", payloadPolicies); return payload; @@ -66,22 +66,22 @@ public Map getClaims() { public static class Builder { private String accountSid; - private String authToken; + private byte[] authToken; private String workspaceSid; private String channelId; private String friendlyName; private int ttl = 3600; - private List policies = Lists.newArrayList(); + private List policies = new ArrayList<>(); /** * Create a new builder for a TaskRouter Capability. - * - * @param accountSid account to use - * @param authToken auth token for account - * @param workspaceSid workspace sid to use - * @param channelId channel ID to use + * + * @param accountSid account to use + * @param authToken auth token for account + * @param workspaceSid workspace sid to use + * @param channelId channel ID to use */ - public Builder(String accountSid, String authToken, String workspaceSid, String channelId) { + public Builder(String accountSid, byte[] authToken, String workspaceSid, String channelId) { this.accountSid = accountSid; this.authToken = authToken; this.workspaceSid = workspaceSid; diff --git a/src/main/java/com/twilio/jwt/taskrouter/UrlUtils.java b/src/main/java/com/twilio/jwt/taskrouter/UrlUtils.java index e8cb98e0a6..2e2ce7c869 100644 --- a/src/main/java/com/twilio/jwt/taskrouter/UrlUtils.java +++ b/src/main/java/com/twilio/jwt/taskrouter/UrlUtils.java @@ -1,7 +1,5 @@ package com.twilio.jwt.taskrouter; -import com.google.common.base.Joiner; - /** * Utility functions for generating TaskRouter related URLs. */ @@ -13,75 +11,75 @@ public class UrlUtils { private UrlUtils() {} public static String workspaces() { - return Joiner.on('/').join(TASKROUTER_BASE_URL, TASKROUTER_VERSION, "Workspaces"); + return String.join("/", TASKROUTER_BASE_URL, TASKROUTER_VERSION, "Workspaces"); } public static String allWorkspaces() { - return Joiner.on('/').join(TASKROUTER_BASE_URL, TASKROUTER_VERSION, "Workspaces", "**"); + return String.join("/", TASKROUTER_BASE_URL, TASKROUTER_VERSION, "Workspaces", "**"); } public static String workspace(String workspaceSid) { - return Joiner.on('/').join(TASKROUTER_BASE_URL, TASKROUTER_VERSION, "Workspaces", workspaceSid); + return String.join("/", TASKROUTER_BASE_URL, TASKROUTER_VERSION, "Workspaces", workspaceSid); } public static String taskQueues(String workspaceSid) { - return Joiner.on('/').join(workspace(workspaceSid), "TaskQueues"); + return String.join("/", workspace(workspaceSid), "TaskQueues"); } public static String allTaskQueues(String workspaceSid) { - return Joiner.on('/').join(workspace(workspaceSid), "TaskQueues", "**"); + return String.join("/", workspace(workspaceSid), "TaskQueues", "**"); } public static String taskQueue(String workspaceSid, String taskQueueSid) { - return Joiner.on('/').join(workspace(workspaceSid), "TaskQueues", taskQueueSid); + return String.join("/", workspace(workspaceSid), "TaskQueues", taskQueueSid); } public static String tasks(String workspaceSid) { - return Joiner.on('/').join(workspace(workspaceSid), "Tasks"); + return String.join("/", workspace(workspaceSid), "Tasks"); } public static String allTasks(String workspaceSid) { - return Joiner.on('/').join(workspace(workspaceSid), "Tasks", "**"); + return String.join("/", workspace(workspaceSid), "Tasks", "**"); } public static String task(String workspaceSid, String taskSid) { - return Joiner.on('/').join(workspace(workspaceSid), "Tasks", taskSid); + return String.join("/", workspace(workspaceSid), "Tasks", taskSid); } public static String activities(String workspaceSid) { - return Joiner.on('/').join(workspace(workspaceSid), "Activities"); + return String.join("/", workspace(workspaceSid), "Activities"); } public static String allActivities(String workspaceSid) { - return Joiner.on('/').join(workspace(workspaceSid), "Activities", "**"); + return String.join("/", workspace(workspaceSid), "Activities", "**"); } public static String activity(String workspaceSid, String activitySid) { - return Joiner.on('/').join(workspace(workspaceSid), "Activities", activitySid); + return String.join("/", workspace(workspaceSid), "Activities", activitySid); } public static String workers(String workspaceSid) { - return Joiner.on('/').join(workspace(workspaceSid), "Workers"); + return String.join("/", workspace(workspaceSid), "Workers"); } public static String allWorkers(String workspaceSid) { - return Joiner.on('/').join(workspace(workspaceSid), "Workers", "**"); + return String.join("/", workspace(workspaceSid), "Workers", "**"); } public static String worker(String workspaceSid, String workerSid) { - return Joiner.on('/').join(workspace(workspaceSid), "Workers", workerSid); + return String.join("/", workspace(workspaceSid), "Workers", workerSid); } public static String reservations(String workspaceSid, String workerSid) { - return Joiner.on('/').join(worker(workspaceSid, workerSid), "Reservations"); + return String.join("/", worker(workspaceSid, workerSid), "Reservations"); } public static String allReservations(String workspaceSid, String workerSid) { - return Joiner.on('/').join(worker(workspaceSid, workerSid), "Reservations", "**"); + return String.join("/", worker(workspaceSid, workerSid), "Reservations", "**"); } public static String reservation(String workspaceSid, String workerSid, String reservationSid) { - return Joiner.on('/').join(worker(workspaceSid, workerSid), "Reservations", reservationSid); + return String.join("/", worker(workspaceSid, workerSid), "Reservations", reservationSid); } } diff --git a/src/main/java/com/twilio/jwt/validation/RequestCanonicalizer.java b/src/main/java/com/twilio/jwt/validation/RequestCanonicalizer.java index bf45fb3a91..2c34f385bf 100644 --- a/src/main/java/com/twilio/jwt/validation/RequestCanonicalizer.java +++ b/src/main/java/com/twilio/jwt/validation/RequestCanonicalizer.java @@ -1,28 +1,18 @@ package com.twilio.jwt.validation; import com.twilio.exception.InvalidRequestException; - -import com.google.common.base.Charsets; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.base.Strings; -import com.google.common.collect.Lists; -import com.google.common.hash.HashFunction; - -import org.apache.http.Header; -import org.apache.http.message.BasicHeader; +import org.apache.commons.codec.digest.DigestUtils; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.message.BasicHeader; /** * Creates a canonical string out of HTTP request components. @@ -35,7 +25,7 @@ class RequestCanonicalizer { private static final String NEW_LINE = "\n"; private static final Pattern TOKEN_REPLACE_PATTERN = - Pattern.compile(String.format("%s|\\%s|\\%s|%s", "%7E", "+", "*", "%2F")); + Pattern.compile(String.format("%s|\\%s|\\%s|%s", "%7E", "+", "*", "%2F")); private final String method; private final String uri; @@ -55,10 +45,9 @@ public RequestCanonicalizer(String method, String uri, String queryString, Strin * Creates a canonical request string out of HTTP request components. * * @param sortedIncludedHeaders the headers that should be included into canonical request string - * @param hashFunction the hashing function applied to request payload * @return a string representing the canonical request */ - public String create(List sortedIncludedHeaders, HashFunction hashFunction) { + public String create(List sortedIncludedHeaders) { // Add the method and uri StringBuilder canonicalRequest = new StringBuilder(); canonicalRequest.append(method).append(NEW_LINE); @@ -82,39 +71,36 @@ public String create(List sortedIncludedHeaders, HashFunction hashFuncti Collections.sort(values); canonicalRequest.append(lowercase) - .append(":") - .append(Joiner.on(',').join(values)) - .append(NEW_LINE); + .append(":") + .append(String.join(",", values)) + .append(NEW_LINE); } } canonicalRequest.append(NEW_LINE); // Mark the headers that we care about - canonicalRequest.append(Joiner.on(";").join(sortedIncludedHeaders)).append(NEW_LINE); + canonicalRequest.append(String.join(";", sortedIncludedHeaders)).append(NEW_LINE); // Hash and hex the request payload - if (!Strings.isNullOrEmpty(requestBody)) { - String hashedPayload = hashFunction.hashString(requestBody, Charsets.UTF_8).toString(); + if (requestBody != null && !requestBody.isEmpty()) { + String hashedPayload = DigestUtils.sha256Hex(requestBody); canonicalRequest.append(hashedPayload); } return canonicalRequest.toString(); } - private static Function>> COMBINE_HEADERS = new Function>>() { - @Override - public Map> apply(Header[] headers) { - Map> combinedHeaders = new HashMap<>(); - - for (Header header : headers) { - if (combinedHeaders.containsKey(header.getName())) { - combinedHeaders.get(header.getName()).add(header.getValue()); - } else { - combinedHeaders.put(header.getName(), Lists.newArrayList(header.getValue())); - } - } + private static final Function>> COMBINE_HEADERS = headers -> { + Map> combinedHeaders = new HashMap<>(); - return combinedHeaders; + for (Header header : headers) { + if (combinedHeaders.containsKey(header.getName())) { + combinedHeaders.get(header.getName()).add(header.getValue()); + } else { + combinedHeaders.put(header.getName(), new ArrayList<>(Arrays.asList(header.getValue()))); + } } + + return combinedHeaders; }; /** @@ -127,22 +113,19 @@ public Map> apply(Header[] headers) { *
  • When no path is provided, returns '/' * */ - private static Function CANONICALIZE_PATH = new Function() { - @Override - public String apply(String string) { - if (Strings.isNullOrEmpty(string)) { - return "/"; - } + private static final Function CANONICALIZE_PATH = string -> { + if (string == null || string.isEmpty()) { + return "/"; + } - try { - URI normalizedUri = new URI(string).normalize(); - String encoded = URLEncoder.encode(normalizedUri.getPath(), "UTF-8"); - return replace(encoded, true); - } catch (URISyntaxException e) { - throw new InvalidRequestException("Bad URI path: '" + string + "'", string, e); - } catch (UnsupportedEncodingException e) { - throw new InvalidRequestException("It must be possible to encode request path as ascii", string, e); - } + try { + URI normalizedUri = new URI(string).normalize(); + String encoded = URLEncoder.encode(normalizedUri.getPath(), "UTF-8"); + return replace(encoded, true); + } catch (URISyntaxException e) { + throw new InvalidRequestException("Bad URI path: '" + string + "'", string, e); + } catch (UnsupportedEncodingException e) { + throw new InvalidRequestException("It must be possible to encode request path as ascii", string, e); } }; @@ -155,37 +138,31 @@ public String apply(String string) { *
  • Join all key/value pairs with a ‘&’ in between * */ - private static Function CANONICALIZE_QUERY = new Function() { - @Override - public String apply(String string) { - String replacedQueryString = replace(string, false); - String[] queryArgs = replacedQueryString.split("&"); - Arrays.sort(queryArgs); - - return Joiner.on("&").join(queryArgs); - } + private static final Function CANONICALIZE_QUERY = string -> { + String replacedQueryString = replace(string, false); + String[] queryArgs = replacedQueryString.split("&"); + Arrays.sort(queryArgs); + + return String.join("&", queryArgs); }; /** * Normalizes the headers by setting all of the header keys to lower case and removing default ports from the host. */ - private static Function NORMALIZE_HEADERS = new Function() { - @Override - public Header[] apply(Header[] headers) { - Header[] normalizedHeaders = new Header[headers.length]; - for (int i = 0; i < headers.length; i++) { - String headerName = headers[i].getName().toLowerCase(); - String headerValue = headers[i].getValue(); - - if (headerName.equals("host") && (headerValue.endsWith(":443") || headerValue.endsWith(":80"))) { - headerValue = headerValue.split(":")[0]; - } - - normalizedHeaders[i] = new BasicHeader(headerName, headerValue); + private static final Function NORMALIZE_HEADERS = headers -> { + Header[] normalizedHeaders = new Header[headers.length]; + for (int i = 0; i < headers.length; i++) { + String headerName = headers[i].getName().toLowerCase(); + String headerValue = headers[i].getValue(); + + if (headerName.equals("host") && (headerValue.endsWith(":443") || headerValue.endsWith(":80"))) { + headerValue = headerValue.split(":")[0]; } - return normalizedHeaders; + normalizedHeaders[i] = new BasicHeader(headerName, headerValue); } + + return normalizedHeaders; }; /** @@ -193,12 +170,12 @@ public Header[] apply(Header[] headers) { * * Partially copied from https://github.com/aws/aws-sdk-java: com.amazonaws.util.SdkHttpUtils (2017-05-19) * - * @param string the string to replace characters in + * @param string the string to replace characters in * @param replaceSlash whether the encoded '/' should be replaced * @return the string after replacements */ private static String replace(String string, boolean replaceSlash) { - if (Strings.isNullOrEmpty(string)) { + if (string == null || string.isEmpty()) { return string; } StringBuffer buffer = new StringBuffer(string.length()); diff --git a/src/main/java/com/twilio/jwt/validation/ValidationToken.java b/src/main/java/com/twilio/jwt/validation/ValidationToken.java index 6930ccdc12..c2214079f5 100644 --- a/src/main/java/com/twilio/jwt/validation/ValidationToken.java +++ b/src/main/java/com/twilio/jwt/validation/ValidationToken.java @@ -1,33 +1,29 @@ package com.twilio.jwt.validation; -import com.google.common.base.Charsets; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; -import com.google.common.hash.HashFunction; -import com.google.common.hash.Hashing; -import com.google.common.io.CharStreams; -import com.twilio.http.HttpMethod; import com.twilio.jwt.Jwt; -import io.jsonwebtoken.SignatureAlgorithm; -import org.apache.http.Header; -import org.apache.http.HttpEntity; -import org.apache.http.HttpEntityEnclosingRequest; -import org.apache.http.HttpRequest; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.security.SecureDigestAlgorithm; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.io.IOUtils; import java.io.IOException; -import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.security.PrivateKey; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import java.util.*; +import java.util.function.Function; +import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase; +import org.apache.hc.core5.http.ClassicHttpRequest; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpRequest; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.message.BasicClassicHttpRequest; + +import java.security.Key; public class ValidationToken extends Jwt { - private static final HashFunction HASH_FUNCTION = Hashing.sha256(); private static final String CTY = "twilio-pkrv;v=1"; private final String accountSid; @@ -40,9 +36,12 @@ public class ValidationToken extends Jwt { private final List signedHeaders; private final String requestBody; + private static final Set> supportedAlgorithms + = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(Jwts.SIG.PS256, Jwts.SIG.RS256))); + private ValidationToken(Builder b) { super( - SignatureAlgorithm.RS256, + b.algorithm, b.privateKey, b.credentialSid, new Date(new Date().getTime() + b.ttl * 1000) @@ -75,16 +74,15 @@ public Map getClaims() { // Sort the signed headers Collections.sort(signedHeaders); - List lowercaseSignedHeaders = Lists.transform(signedHeaders, LOWERCASE_STRING); - String includedHeaders = Joiner.on(";").join(lowercaseSignedHeaders); + signedHeaders.replaceAll(String::toLowerCase); + String includedHeaders = String.join(";", signedHeaders); payload.put("hrh", includedHeaders); String canonicalRequest = - new RequestCanonicalizer(method, uri, queryString, requestBody, headers).create( - lowercaseSignedHeaders, HASH_FUNCTION); + new RequestCanonicalizer(method, uri, queryString, requestBody, headers).create(signedHeaders); // Hash and hex the canonical request - String hashedSignature = HASH_FUNCTION.hashString(canonicalRequest, Charsets.UTF_8).toString(); + String hashedSignature = DigestUtils.sha256Hex(canonicalRequest); payload.put("rqh", hashedSignature); return payload; @@ -92,16 +90,15 @@ public Map getClaims() { /** * Create a ValidationToken from an HTTP Request. - * - * @param accountSid Twilio Account SID - * @param credentialSid Twilio Credential SID - * @param signingKeySid Twilio Signing Key SID - * @param privateKey Private Key - * @param request HTTP Request - * @param signedHeaders Headers to sign - * - * @throws IOException when unable to generate + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Credential SID + * @param signingKeySid Twilio Signing Key SID + * @param privateKey Private Key + * @param request HTTP Request + * @param signedHeaders Headers to sign * @return The ValidationToken generated from the HttpRequest + * @throws IOException when unable to generate */ public static ValidationToken fromHttpRequest( String accountSid, @@ -110,13 +107,40 @@ public static ValidationToken fromHttpRequest( PrivateKey privateKey, HttpRequest request, List signedHeaders - ) throws IOException { + ) throws IOException, ParseException { + + return fromHttpRequest(accountSid, credentialSid, signingKeySid, privateKey, request, signedHeaders, Jwts.SIG.RS256); + } + + /** + * Create a ValidationToken from an HTTP Request. + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Credential SID + * @param signingKeySid Twilio Signing Key SID + * @param privateKey Private Key + * @param request HTTP Request + * @param signedHeaders Headers to sign + * @param algorithm Client validation algorithm + * @return The ValidationToken generated from the HttpRequest + * @throws IOException when unable to generate + */ + public static ValidationToken fromHttpRequest( + String accountSid, + String credentialSid, + String signingKeySid, + PrivateKey privateKey, + HttpRequest request, + List signedHeaders, + SecureDigestAlgorithm algorithm + ) throws IOException, ParseException { Builder builder = new Builder(accountSid, credentialSid, signingKeySid, privateKey); - String method = request.getRequestLine().getMethod(); + String method = request.getMethod(); builder.method(method); + builder.algorithm(algorithm); - String uri = request.getRequestLine().getUri(); + String uri = request.getRequestUri(); if (uri.contains("?")) { String[] uriParts = uri.split("\\?"); builder.uri(uriParts[0]); @@ -125,12 +149,18 @@ public static ValidationToken fromHttpRequest( builder.uri(uri); } - builder.headers(request.getAllHeaders()); + builder.headers(request.getHeaders()); builder.signedHeaders(signedHeaders); - if (HttpMethod.POST.toString().equals(method.toUpperCase())) { - HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity(); - builder.requestBody(CharStreams.toString(new InputStreamReader(entity.getContent(), Charsets.UTF_8))); + /** + * If the request encloses an "entity", use it for the body. Note that this is dependent on several factors + * during request building and is not solely based on the specified method. + * + * @see org.apache.http.client.methods.RequestBuilder#build + */ + if (request instanceof BasicClassicHttpRequest && ((BasicClassicHttpRequest) request).getEntity() != null) { + HttpEntity entity = ((BasicClassicHttpRequest) request).getEntity(); + builder.requestBody(EntityUtils.toString(entity, StandardCharsets.UTF_8)); } return builder.build(); @@ -157,13 +187,15 @@ public static class Builder { private String requestBody = ""; private int ttl = 300; + private SecureDigestAlgorithm algorithm = Jwts.SIG.RS256; + /** * Create a new ValidationToken Builder. - * - * @param accountSid Twilio Account SID - * @param credentialSid Twilio Crednetial SID - * @param signingKeySid Twilio Signing Key SID - * @param privateKey Private Key + * + * @param accountSid Twilio Account SID + * @param credentialSid Twilio Crednetial SID + * @param signingKeySid Twilio Signing Key SID + * @param privateKey Private Key */ public Builder(String accountSid, String credentialSid, String signingKeySid, PrivateKey privateKey) { this.accountSid = accountSid; @@ -193,7 +225,12 @@ public Builder headers(Header[] headers) { } public Builder signedHeaders(List signedHeaders) { - this.signedHeaders = signedHeaders; + if (signedHeaders == null) { + this.signedHeaders = Collections.emptyList(); + } else { + this.signedHeaders = new ArrayList<>(signedHeaders); + } + return this; } @@ -207,6 +244,13 @@ public Builder ttl(int ttl) { return this; } + public Builder algorithm(SecureDigestAlgorithm algorithm) { + if (!supportedAlgorithms.contains(algorithm)) { + throw new IllegalArgumentException("Signature Algorithm Not supported!"); + } + this.algorithm = algorithm; + return this; + } public ValidationToken build() { return new ValidationToken(this); } diff --git a/src/main/java/com/twilio/rest/Domains.java b/src/main/java/com/twilio/rest/Domains.java deleted file mode 100644 index c8ac323842..0000000000 --- a/src/main/java/com/twilio/rest/Domains.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest; - -public enum Domains { - ACCOUNTS("accounts"), - API("api"), - CHAT("chat"), - FAX("fax"), - IPMESSAGING("chat"), - LOOKUPS("lookups"), - MONITOR("monitor"), - NOTIFY("notify"), - PREVIEW("preview"), - PRICING("pricing"), - PROXY("proxy"), - TASKROUTER("taskrouter"), - TRUNKING("trunking"), - VIDEO("video"), - MESSAGING("messaging"), - WIRELESS("wireless"), - SYNC("sync"), - STUDIO("studio"); - - private final String value; - - private Domains(final String value) { - this.value = value; - } - - public String toString() { - return value; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotion.java b/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotion.java new file mode 100644 index 0000000000..688bbe96de --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotion.java @@ -0,0 +1,174 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AuthTokenPromotion extends Resource { + + public static AuthTokenPromotionUpdater updater() { + return new AuthTokenPromotionUpdater(); + } + + /** + * Converts a JSON String into a AuthTokenPromotion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthTokenPromotion object represented by the provided JSON + */ + public static AuthTokenPromotion fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AuthTokenPromotion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AuthTokenPromotion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthTokenPromotion object represented by the provided JSON + */ + public static AuthTokenPromotion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AuthTokenPromotion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String authToken; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final URI url; + + @JsonCreator + private AuthTokenPromotion( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("auth_token") final String authToken, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.authToken = authToken; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AuthTokenPromotion other = (AuthTokenPromotion) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(authToken, other.authToken) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + authToken, + dateCreated, + dateUpdated, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotionUpdater.java b/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotionUpdater.java new file mode 100644 index 0000000000..7a4db7e339 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/AuthTokenPromotionUpdater.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthTokenPromotionUpdater extends Updater { + + private Boolean suppressEmailNotification; + + public AuthTokenPromotionUpdater() {} + + public AuthTokenPromotionUpdater setSuppressEmailNotification( + final Boolean suppressEmailNotification + ) { + this.suppressEmailNotification = suppressEmailNotification; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/AuthTokens/Promote"; + + Request request = new Request( + HttpMethod.POST, + Domains.ACCOUNTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthTokenPromotion update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthTokenPromotion update(final TwilioRestClient client) { + Response response = makeRequest(client); + return AuthTokenPromotion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthTokenPromotion content = AuthTokenPromotion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (suppressEmailNotification != null) { + Serializer.toString( + request, + "SuppressEmailNotification", + suppressEmailNotification, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/BulkConsents.java b/src/main/java/com/twilio/rest/accounts/v1/BulkConsents.java new file mode 100644 index 0000000000..cfb50bb5bf --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/BulkConsents.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BulkConsents extends Resource { + + public static BulkConsentsCreator creator(final List items) { + return new BulkConsentsCreator(items); + } + + /** + * Converts a JSON String into a BulkConsents object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BulkConsents object represented by the provided JSON + */ + public static BulkConsents fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkConsents.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BulkConsents object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BulkConsents object represented by the provided JSON + */ + public static BulkConsents fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkConsents.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object items; + + @JsonCreator + private BulkConsents(@JsonProperty("items") final Object items) { + this.items = items; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BulkConsents other = (BulkConsents) o; + return (Objects.equals(items, other.items)); + } + + @Override + public int hashCode() { + return Objects.hash(items); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/BulkConsentsCreator.java b/src/main/java/com/twilio/rest/accounts/v1/BulkConsentsCreator.java new file mode 100644 index 0000000000..70c7b5e71a --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/BulkConsentsCreator.java @@ -0,0 +1,123 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class BulkConsentsCreator extends Creator { + + private List items; + + public BulkConsentsCreator(final List items) { + this.items = items; + } + + public BulkConsentsCreator setItems(final List items) { + this.items = items; + return this; + } + + public BulkConsentsCreator setItems(final Object items) { + return setItems(Promoter.listOfOne(items)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Consents/Bulk"; + + Request request = new Request( + HttpMethod.POST, + Domains.ACCOUNTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BulkConsents creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BulkConsents create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BulkConsents.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BulkConsents content = BulkConsents.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (items != null) { + for (Object param : items) { + Serializer.toString( + request, + "Items", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/BulkContacts.java b/src/main/java/com/twilio/rest/accounts/v1/BulkContacts.java new file mode 100644 index 0000000000..17aac42f43 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/BulkContacts.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BulkContacts extends Resource { + + public static BulkContactsCreator creator(final List items) { + return new BulkContactsCreator(items); + } + + /** + * Converts a JSON String into a BulkContacts object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BulkContacts object represented by the provided JSON + */ + public static BulkContacts fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkContacts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BulkContacts object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BulkContacts object represented by the provided JSON + */ + public static BulkContacts fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkContacts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object items; + + @JsonCreator + private BulkContacts(@JsonProperty("items") final Object items) { + this.items = items; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BulkContacts other = (BulkContacts) o; + return (Objects.equals(items, other.items)); + } + + @Override + public int hashCode() { + return Objects.hash(items); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/BulkContactsCreator.java b/src/main/java/com/twilio/rest/accounts/v1/BulkContactsCreator.java new file mode 100644 index 0000000000..cb7aa108f2 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/BulkContactsCreator.java @@ -0,0 +1,123 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class BulkContactsCreator extends Creator { + + private List items; + + public BulkContactsCreator(final List items) { + this.items = items; + } + + public BulkContactsCreator setItems(final List items) { + this.items = items; + return this; + } + + public BulkContactsCreator setItems(final Object items) { + return setItems(Promoter.listOfOne(items)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Contacts/Bulk"; + + Request request = new Request( + HttpMethod.POST, + Domains.ACCOUNTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BulkContacts creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BulkContacts create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BulkContacts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BulkContacts content = BulkContacts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (items != null) { + for (Object param : items) { + Serializer.toString( + request, + "Items", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/ComplianceSignalsCheck.java b/src/main/java/com/twilio/rest/accounts/v1/ComplianceSignalsCheck.java new file mode 100644 index 0000000000..2a83efa04a --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/ComplianceSignalsCheck.java @@ -0,0 +1,816 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ComplianceSignalsCheck extends Resource { + + public static ComplianceSignalsCheckCreator creator() { + return new ComplianceSignalsCheckCreator(); + } + + public enum EvaluatedUseCase { + ESSENTIAL("ESSENTIAL"), + NON_ESSENTIAL("NON_ESSENTIAL"); + + private final String value; + + private EvaluatedUseCase(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EvaluatedUseCase forValue(final String value) { + return Promoter.enumFromString(value, EvaluatedUseCase.values()); + } + } + + public enum Reason { + OUTSIDE_QUIET_HOURS("OUTSIDE_QUIET_HOURS"), + EXEMPT_USE_CASE("EXEMPT_USE_CASE"), + STATE_QUIET_HOURS("STATE_QUIET_HOURS"), + FEDERAL_QUIET_HOURS("FEDERAL_QUIET_HOURS"); + + private final String value; + + private Reason(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Reason forValue(final String value) { + return Promoter.enumFromString(value, Reason.values()); + } + } + + @JsonDeserialize( + builder = CreateComplianceSignalsCheckRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateComplianceSignalsCheckRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("signals") + @Getter + private final List signals; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + @Getter + private final String to; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCase") + @Getter + private final String useCase; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final String channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("countryIsoCode") + @Getter + private final String countryIsoCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("zipCode") + @Getter + private final String zipCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sendAt") + @Getter + private final String sendAt; + + private CreateComplianceSignalsCheckRequest(Builder builder) { + this.signals = builder.signals; + this.to = builder.to; + this.body = builder.body; + this.useCase = builder.useCase; + this.channel = builder.channel; + this.countryIsoCode = builder.countryIsoCode; + this.zipCode = builder.zipCode; + this.sendAt = builder.sendAt; + } + + public static Builder builder( + final List signals, + final String to, + final String countryIsoCode + ) { + return new Builder(signals, to, countryIsoCode); + } + + public static CreateComplianceSignalsCheckRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateComplianceSignalsCheckRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("signals") + private List signals; + + @JsonProperty("to") + private String to; + + @JsonProperty("body") + private String body; + + @JsonProperty("useCase") + private String useCase; + + @JsonProperty("channel") + private String channel; + + @JsonProperty("countryIsoCode") + private String countryIsoCode; + + @JsonProperty("zipCode") + private String zipCode; + + @JsonProperty("sendAt") + private String sendAt; + + @JsonCreator + public Builder( + @JsonProperty("signals") final List signals, + @JsonProperty("to") final String to, + @JsonProperty("countryIsoCode") final String countryIsoCode + ) { + this.signals = signals; + this.to = to; + this.countryIsoCode = countryIsoCode; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + public Builder body(String body) { + this.body = body; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCase") + public Builder useCase(String useCase) { + this.useCase = useCase; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + public Builder channel(String channel) { + this.channel = channel; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("zipCode") + public Builder zipCode(String zipCode) { + this.zipCode = zipCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sendAt") + public Builder sendAt(String sendAt) { + this.sendAt = sendAt; + return this; + } + + public CreateComplianceSignalsCheckRequest build() { + return new CreateComplianceSignalsCheckRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateComplianceSignalsCheckRequest other = + (CreateComplianceSignalsCheckRequest) o; + return ( + Objects.equals(signals, other.signals) && + Objects.equals(to, other.to) && + Objects.equals(body, other.body) && + Objects.equals(useCase, other.useCase) && + Objects.equals(channel, other.channel) && + Objects.equals(countryIsoCode, other.countryIsoCode) && + Objects.equals(zipCode, other.zipCode) && + Objects.equals(sendAt, other.sendAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + signals, + to, + body, + useCase, + channel, + countryIsoCode, + zipCode, + sendAt + ); + } + } + + @JsonDeserialize( + builder = AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("countryIsoCode") + @Getter + private final String countryIsoCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stateCode") + @Getter + private final String stateCode; + + private AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation( + Builder builder + ) { + this.countryIsoCode = builder.countryIsoCode; + this.stateCode = builder.stateCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("countryIsoCode") + private String countryIsoCode; + + @JsonProperty("stateCode") + private String stateCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("countryIsoCode") + public Builder countryIsoCode(String countryIsoCode) { + this.countryIsoCode = countryIsoCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stateCode") + public Builder stateCode(String stateCode) { + this.stateCode = stateCode; + return this; + } + + public AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation build() { + return new AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation other = + (AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation) o; + return ( + Objects.equals(countryIsoCode, other.countryIsoCode) && + Objects.equals(stateCode, other.stateCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash(countryIsoCode, stateCode); + } + } + + @JsonDeserialize( + builder = AccountsV1ComplianceSignalsCheckSignalsQuietHours.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountsV1ComplianceSignalsCheckSignalsQuietHours { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isActive") + @Getter + private final Boolean isActive; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("reason") + @Getter + private final ComplianceSignalsCheck.Reason reason; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("evaluatedUseCase") + @Getter + private final ComplianceSignalsCheck.EvaluatedUseCase evaluatedUseCase; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("location") + @Getter + private final AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation location; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sendingWindow") + @Getter + private final AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow sendingWindow; + + private AccountsV1ComplianceSignalsCheckSignalsQuietHours( + Builder builder + ) { + this.isActive = builder.isActive; + this.reason = builder.reason; + this.evaluatedUseCase = builder.evaluatedUseCase; + this.location = builder.location; + this.sendingWindow = builder.sendingWindow; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountsV1ComplianceSignalsCheckSignalsQuietHours fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountsV1ComplianceSignalsCheckSignalsQuietHours.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("isActive") + private Boolean isActive; + + @JsonProperty("reason") + private ComplianceSignalsCheck.Reason reason; + + @JsonProperty("evaluatedUseCase") + private ComplianceSignalsCheck.EvaluatedUseCase evaluatedUseCase; + + @JsonProperty("location") + private AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation location; + + @JsonProperty("sendingWindow") + private AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow sendingWindow; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isActive") + public Builder isActive(Boolean isActive) { + this.isActive = isActive; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("reason") + public Builder reason(ComplianceSignalsCheck.Reason reason) { + this.reason = reason; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("evaluatedUseCase") + public Builder evaluatedUseCase( + ComplianceSignalsCheck.EvaluatedUseCase evaluatedUseCase + ) { + this.evaluatedUseCase = evaluatedUseCase; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("location") + public Builder location( + AccountsV1ComplianceSignalsCheckSignalsQuietHoursLocation location + ) { + this.location = location; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sendingWindow") + public Builder sendingWindow( + AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow sendingWindow + ) { + this.sendingWindow = sendingWindow; + return this; + } + + public AccountsV1ComplianceSignalsCheckSignalsQuietHours build() { + return new AccountsV1ComplianceSignalsCheckSignalsQuietHours( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountsV1ComplianceSignalsCheckSignalsQuietHours other = + (AccountsV1ComplianceSignalsCheckSignalsQuietHours) o; + return ( + Objects.equals(isActive, other.isActive) && + Objects.equals(reason, other.reason) && + Objects.equals(evaluatedUseCase, other.evaluatedUseCase) && + Objects.equals(location, other.location) && + Objects.equals(sendingWindow, other.sendingWindow) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + isActive, + reason, + evaluatedUseCase, + location, + sendingWindow + ); + } + } + + @JsonDeserialize( + builder = AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("startAt") + @Getter + private final ZonedDateTime startAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("endAt") + @Getter + private final ZonedDateTime endAt; + + private AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow( + Builder builder + ) { + this.startAt = builder.startAt; + this.endAt = builder.endAt; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("startAt") + private ZonedDateTime startAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("endAt") + private ZonedDateTime endAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("startAt") + public Builder startAt(ZonedDateTime startAt) { + this.startAt = startAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("endAt") + public Builder endAt(ZonedDateTime endAt) { + this.endAt = endAt; + return this; + } + + public AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow build() { + return new AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow other = + (AccountsV1ComplianceSignalsCheckSignalsQuietHoursSendingWindow) o; + return ( + Objects.equals(startAt, other.startAt) && + Objects.equals(endAt, other.endAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash(startAt, endAt); + } + } + + @JsonDeserialize( + builder = AccountsV1ComplianceSignalsCheckSignals.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountsV1ComplianceSignalsCheckSignals { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("quietHours") + @Getter + private final AccountsV1ComplianceSignalsCheckSignalsQuietHours quietHours; + + private AccountsV1ComplianceSignalsCheckSignals(Builder builder) { + this.quietHours = builder.quietHours; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountsV1ComplianceSignalsCheckSignals fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountsV1ComplianceSignalsCheckSignals.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("quietHours") + private AccountsV1ComplianceSignalsCheckSignalsQuietHours quietHours; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("quietHours") + public Builder quietHours( + AccountsV1ComplianceSignalsCheckSignalsQuietHours quietHours + ) { + this.quietHours = quietHours; + return this; + } + + public AccountsV1ComplianceSignalsCheckSignals build() { + return new AccountsV1ComplianceSignalsCheckSignals(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountsV1ComplianceSignalsCheckSignals other = + (AccountsV1ComplianceSignalsCheckSignals) o; + return (Objects.equals(quietHours, other.quietHours)); + } + + @Override + public int hashCode() { + return Objects.hash(quietHours); + } + } + + /** + * Converts a JSON String into a ComplianceSignalsCheck object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ComplianceSignalsCheck object represented by the provided JSON + */ + public static ComplianceSignalsCheck fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ComplianceSignalsCheck.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ComplianceSignalsCheck object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ComplianceSignalsCheck object represented by the provided JSON + */ + public static ComplianceSignalsCheck fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ComplianceSignalsCheck.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final AccountsV1ComplianceSignalsCheckSignals signals; + + @JsonCreator + private ComplianceSignalsCheck( + @JsonProperty( + "signals" + ) final AccountsV1ComplianceSignalsCheckSignals signals + ) { + this.signals = signals; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ComplianceSignalsCheck other = (ComplianceSignalsCheck) o; + return (Objects.equals(signals, other.signals)); + } + + @Override + public int hashCode() { + return Objects.hash(signals); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/ComplianceSignalsCheckCreator.java b/src/main/java/com/twilio/rest/accounts/v1/ComplianceSignalsCheckCreator.java new file mode 100644 index 0000000000..df1586c3af --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/ComplianceSignalsCheckCreator.java @@ -0,0 +1,117 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ComplianceSignalsCheckCreator + extends Creator { + + private ComplianceSignalsCheck.CreateComplianceSignalsCheckRequest createComplianceSignalsCheckRequest; + + public ComplianceSignalsCheckCreator() {} + + public ComplianceSignalsCheckCreator setCreateComplianceSignalsCheckRequest( + final ComplianceSignalsCheck.CreateComplianceSignalsCheckRequest createComplianceSignalsCheckRequest + ) { + this.createComplianceSignalsCheckRequest = + createComplianceSignalsCheckRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ComplianceSignals/Check"; + + Request request = new Request( + HttpMethod.POST, + Domains.ACCOUNTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ComplianceSignalsCheck creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ComplianceSignalsCheck create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ComplianceSignalsCheck.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ComplianceSignalsCheck content = ComplianceSignalsCheck.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createComplianceSignalsCheckRequest != null) { + request.setBody( + ComplianceSignalsCheck.toJson( + createComplianceSignalsCheckRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissions.java b/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissions.java new file mode 100644 index 0000000000..8e251a30da --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissions.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class MessagingGeopermissions extends Resource { + + public static MessagingGeopermissionsFetcher fetcher() { + return new MessagingGeopermissionsFetcher(); + } + + public static MessagingGeopermissionsUpdater updater( + final List permissions + ) { + return new MessagingGeopermissionsUpdater(permissions); + } + + /** + * Converts a JSON String into a MessagingGeopermissions object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return MessagingGeopermissions object represented by the provided JSON + */ + public static MessagingGeopermissions fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, MessagingGeopermissions.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a MessagingGeopermissions object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return MessagingGeopermissions object represented by the provided JSON + */ + public static MessagingGeopermissions fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, MessagingGeopermissions.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object permissions; + + @JsonCreator + private MessagingGeopermissions( + @JsonProperty("permissions") final Object permissions + ) { + this.permissions = permissions; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingGeopermissions other = (MessagingGeopermissions) o; + return (Objects.equals(permissions, other.permissions)); + } + + @Override + public int hashCode() { + return Objects.hash(permissions); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissionsFetcher.java b/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissionsFetcher.java new file mode 100644 index 0000000000..5148f87d1f --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissionsFetcher.java @@ -0,0 +1,114 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MessagingGeopermissionsFetcher + extends Fetcher { + + private String countryCode; + + public MessagingGeopermissionsFetcher() {} + + public MessagingGeopermissionsFetcher setCountryCode( + final String countryCode + ) { + this.countryCode = countryCode; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Messaging/GeoPermissions"; + + Request request = new Request( + HttpMethod.GET, + Domains.ACCOUNTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "MessagingGeopermissions fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public MessagingGeopermissions fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return MessagingGeopermissions.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + MessagingGeopermissions content = MessagingGeopermissions.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (countryCode != null) { + Serializer.toString( + request, + "CountryCode", + countryCode, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissionsUpdater.java b/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissionsUpdater.java new file mode 100644 index 0000000000..036662b522 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/MessagingGeopermissionsUpdater.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class MessagingGeopermissionsUpdater + extends Updater { + + private List permissions; + + public MessagingGeopermissionsUpdater(final List permissions) { + this.permissions = permissions; + } + + public MessagingGeopermissionsUpdater setPermissions( + final List permissions + ) { + this.permissions = permissions; + return this; + } + + public MessagingGeopermissionsUpdater setPermissions( + final Object permissions + ) { + return setPermissions(Promoter.listOfOne(permissions)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Messaging/GeoPermissions"; + + Request request = new Request( + HttpMethod.PATCH, + Domains.ACCOUNTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "MessagingGeopermissions update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public MessagingGeopermissions update(final TwilioRestClient client) { + Response response = makeRequest(client); + return MessagingGeopermissions.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + MessagingGeopermissions content = MessagingGeopermissions.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (permissions != null) { + for (Object param : permissions) { + Serializer.toString( + request, + "Permissions", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/Safelist.java b/src/main/java/com/twilio/rest/accounts/v1/Safelist.java new file mode 100644 index 0000000000..b76aaadd5e --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/Safelist.java @@ -0,0 +1,144 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Safelist extends Resource { + + public static SafelistCreator creator(final String phoneNumber) { + return new SafelistCreator(phoneNumber); + } + + public static SafelistDeleter deleter() { + return new SafelistDeleter(); + } + + public static SafelistFetcher fetcher() { + return new SafelistFetcher(); + } + + /** + * Converts a JSON String into a Safelist object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Safelist object represented by the provided JSON + */ + public static Safelist fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Safelist.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Safelist object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Safelist object represented by the provided JSON + */ + public static Safelist fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Safelist.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String phoneNumber; + + @Getter + private final String sid; + + @JsonCreator + private Safelist( + @JsonProperty("phone_number") final String phoneNumber, + @JsonProperty("sid") final String sid + ) { + this.phoneNumber = phoneNumber; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Safelist other = (Safelist) o; + return ( + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash(phoneNumber, sid); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/SafelistCreator.java b/src/main/java/com/twilio/rest/accounts/v1/SafelistCreator.java new file mode 100644 index 0000000000..69e0c96054 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/SafelistCreator.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SafelistCreator extends Creator { + + private String phoneNumber; + + public SafelistCreator(final String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public SafelistCreator setPhoneNumber(final String phoneNumber) { + this.phoneNumber = phoneNumber; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SafeList/Numbers"; + + Request request = new Request( + HttpMethod.POST, + Domains.ACCOUNTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Safelist creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Safelist create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Safelist content = Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (phoneNumber != null) { + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/SafelistDeleter.java b/src/main/java/com/twilio/rest/accounts/v1/SafelistDeleter.java new file mode 100644 index 0000000000..1bad6feade --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/SafelistDeleter.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class SafelistDeleter extends Deleter { + + private String phoneNumber; + + public SafelistDeleter() {} + + public SafelistDeleter setPhoneNumber(final String phoneNumber) { + this.phoneNumber = phoneNumber; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SafeList/Numbers"; + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.ACCOUNTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Safelist delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (phoneNumber != null) { + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/SafelistFetcher.java b/src/main/java/com/twilio/rest/accounts/v1/SafelistFetcher.java new file mode 100644 index 0000000000..73b4d7c10e --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/SafelistFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SafelistFetcher extends Fetcher { + + private String phoneNumber; + + public SafelistFetcher() {} + + public SafelistFetcher setPhoneNumber(final String phoneNumber) { + this.phoneNumber = phoneNumber; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SafeList/Numbers"; + + Request request = new Request( + HttpMethod.GET, + Domains.ACCOUNTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Safelist fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Safelist fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Safelist content = Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (phoneNumber != null) { + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthToken.java b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthToken.java new file mode 100644 index 0000000000..18e94fbde1 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthToken.java @@ -0,0 +1,178 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SecondaryAuthToken extends Resource { + + public static SecondaryAuthTokenCreator creator() { + return new SecondaryAuthTokenCreator(); + } + + public static SecondaryAuthTokenDeleter deleter() { + return new SecondaryAuthTokenDeleter(); + } + + /** + * Converts a JSON String into a SecondaryAuthToken object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SecondaryAuthToken object represented by the provided JSON + */ + public static SecondaryAuthToken fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SecondaryAuthToken.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SecondaryAuthToken object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SecondaryAuthToken object represented by the provided JSON + */ + public static SecondaryAuthToken fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SecondaryAuthToken.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String secondaryAuthToken; + + @Getter + private final URI url; + + @JsonCreator + private SecondaryAuthToken( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("secondary_auth_token") final String secondaryAuthToken, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.secondaryAuthToken = secondaryAuthToken; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SecondaryAuthToken other = (SecondaryAuthToken) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(secondaryAuthToken, other.secondaryAuthToken) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + secondaryAuthToken, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenCreator.java b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenCreator.java new file mode 100644 index 0000000000..2521786507 --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenCreator.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SecondaryAuthTokenCreator extends Creator { + + private Boolean suppressEmailNotification; + + public SecondaryAuthTokenCreator() {} + + public SecondaryAuthTokenCreator setSuppressEmailNotification( + final Boolean suppressEmailNotification + ) { + this.suppressEmailNotification = suppressEmailNotification; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/AuthTokens/Secondary"; + + Request request = new Request( + HttpMethod.POST, + Domains.ACCOUNTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SecondaryAuthToken creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SecondaryAuthToken create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SecondaryAuthToken.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SecondaryAuthToken content = SecondaryAuthToken.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (suppressEmailNotification != null) { + Serializer.toString( + request, + "SuppressEmailNotification", + suppressEmailNotification, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenDeleter.java b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenDeleter.java new file mode 100644 index 0000000000..21c915ee1a --- /dev/null +++ b/src/main/java/com/twilio/rest/accounts/v1/SecondaryAuthTokenDeleter.java @@ -0,0 +1,114 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.accounts.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class SecondaryAuthTokenDeleter extends Deleter { + + private Boolean suppressEmailNotification; + + public SecondaryAuthTokenDeleter() {} + + public SecondaryAuthTokenDeleter setSuppressEmailNotification( + final Boolean suppressEmailNotification + ) { + this.suppressEmailNotification = suppressEmailNotification; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/AuthTokens/Secondary"; + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.ACCOUNTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SecondaryAuthToken delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (suppressEmailNotification != null) { + Serializer.toString( + request, + "SuppressEmailNotification", + suppressEmailNotification, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/Aws.java b/src/main/java/com/twilio/rest/accounts/v1/credential/Aws.java index 112b5cf420..c8d87938cd 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/Aws.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/Aws.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; @@ -11,88 +18,61 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Aws extends Resource { - private static final long serialVersionUID = 108884981918794L; - - /** - * Create a AwsReader to execute read. - * - * @return AwsReader capable of executing the read - */ - public static AwsReader reader() { - return new AwsReader(); - } - /** - * Create a AwsCreator to execute create. - * - * @param credentials The credentials - * @return AwsCreator capable of executing the create - */ public static AwsCreator creator(final String credentials) { return new AwsCreator(credentials); } - /** - * Create a AwsFetcher to execute fetch. - * - * @param pathSid The sid - * @return AwsFetcher capable of executing the fetch - */ + public static AwsDeleter deleter(final String pathSid) { + return new AwsDeleter(pathSid); + } + public static AwsFetcher fetcher(final String pathSid) { return new AwsFetcher(pathSid); } - /** - * Create a AwsUpdater to execute update. - * - * @param pathSid The sid - * @return AwsUpdater capable of executing the update - */ - public static AwsUpdater updater(final String pathSid) { - return new AwsUpdater(pathSid); + public static AwsReader reader() { + return new AwsReader(); } - /** - * Create a AwsDeleter to execute delete. - * - * @param pathSid The sid - * @return AwsDeleter capable of executing the delete - */ - public static AwsDeleter deleter(final String pathSid) { - return new AwsDeleter(pathSid); + public static AwsUpdater updater(final String pathSid) { + return new AwsUpdater(pathSid); } /** * Converts a JSON String into a Aws object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Aws object represented by the provided JSON */ - public static Aws fromJson(final String json, final ObjectMapper objectMapper) { + public static Aws fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Aws.class); @@ -106,12 +86,15 @@ public static Aws fromJson(final String json, final ObjectMapper objectMapper) { /** * Converts a JSON InputStream into a Aws object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Aws object represented by the provided JSON */ - public static Aws fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Aws fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Aws.class); @@ -122,88 +105,63 @@ public static Aws fromJson(final InputStream json, final ObjectMapper objectMapp } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private Aws(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Aws( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.sid = sid; this.url = url; } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -215,34 +173,25 @@ public boolean equals(final Object o) { } Aws other = (Aws) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsCreator.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsCreator.java index 186e14698f..d5532e4bc9 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsCreator.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,98 +27,116 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AwsCreator extends Creator { - private final String credentials; + + private String credentials; private String friendlyName; private String accountSid; - /** - * Construct a new AwsCreator. - * - * @param credentials The credentials - */ public AwsCreator(final String credentials) { this.credentials = credentials; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ + public AwsCreator setCredentials(final String credentials) { + this.credentials = credentials; + return this; + } + public AwsCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The account_sid. - * - * @param accountSid The account_sid - * @return this - */ public AwsCreator setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Aws - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Aws create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/AWS"; + Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), - "/v1/Credentials/AWS", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Aws creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Aws create(final TwilioRestClient client) { + Response response = makeRequest(client); return Aws.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Aws content = Aws.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (credentials != null) { - request.addPostParam("Credentials", credentials.toString()); + Serializer.toString( + request, + "Credentials", + credentials, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (accountSid != null) { - request.addPostParam("AccountSid", accountSid); + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsDeleter.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsDeleter.java index 4330c3bfa7..fd9ca09044 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsDeleter.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class AwsDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new AwsDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public AwsDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/AWS/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.ACCOUNTS.toString(), - "/v1/Credentials/AWS/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Aws delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsFetcher.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsFetcher.java index 669c0d7057..82ce68242b 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsFetcher.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AwsFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new AwsFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public AwsFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Aws - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Aws fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/AWS/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.ACCOUNTS.toString(), - "/v1/Credentials/AWS/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Aws fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Aws fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Aws.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Aws content = Aws.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsReader.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsReader.java index 16d553eb8f..e513717b5f 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsReader.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; @@ -10,148 +17,182 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AwsReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Aws ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public AwsReader() {} + + public AwsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Aws ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Aws.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/AWS"; + Request request = new Request( HttpMethod.GET, Domains.ACCOUNTS.toString(), - "/v1/Credentials/AWS", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Aws ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Aws.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Aws read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + Aws.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.ACCOUNTS.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.ACCOUNTS.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Aws Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Aws read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credentials", - response.getContent(), - Aws.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsUpdater.java b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsUpdater.java index 22afea4cf1..5559f62139 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/AwsUpdater.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/AwsUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,78 +27,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AwsUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; - /** - * Construct a new AwsUpdater. - * - * @param pathSid The sid - */ public AwsUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public AwsUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Aws - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Aws update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/AWS/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), - "/v1/Credentials/AWS/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Aws update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Aws update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Aws update(final TwilioRestClient client) { + Response response = makeRequest(client); return Aws.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Aws content = Aws.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKey.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKey.java index 7cc2045348..482ca689fb 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKey.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKey.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; @@ -11,89 +18,61 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class PublicKey extends Resource { - private static final long serialVersionUID = 108884981918794L; - - /** - * Create a PublicKeyReader to execute read. - * - * @return PublicKeyReader capable of executing the read - */ - public static PublicKeyReader reader() { - return new PublicKeyReader(); - } - /** - * Create a PublicKeyCreator to execute create. - * - * @param publicKey URL encoded representation of the public key - * @return PublicKeyCreator capable of executing the create - */ public static PublicKeyCreator creator(final String publicKey) { return new PublicKeyCreator(publicKey); } - /** - * Create a PublicKeyFetcher to execute fetch. - * - * @param pathSid Fetch by unique Credential Sid - * @return PublicKeyFetcher capable of executing the fetch - */ + public static PublicKeyDeleter deleter(final String pathSid) { + return new PublicKeyDeleter(pathSid); + } + public static PublicKeyFetcher fetcher(final String pathSid) { return new PublicKeyFetcher(pathSid); } - /** - * Create a PublicKeyUpdater to execute update. - * - * @param pathSid Fetch by unique Credential Sid - * @return PublicKeyUpdater capable of executing the update - */ - public static PublicKeyUpdater updater(final String pathSid) { - return new PublicKeyUpdater(pathSid); + public static PublicKeyReader reader() { + return new PublicKeyReader(); } - /** - * Create a PublicKeyDeleter to execute delete. - * - * @param pathSid A 34 character string that uniquely identifies this resource. - * @return PublicKeyDeleter capable of executing the delete - */ - public static PublicKeyDeleter deleter(final String pathSid) { - return new PublicKeyDeleter(pathSid); + public static PublicKeyUpdater updater(final String pathSid) { + return new PublicKeyUpdater(pathSid); } /** - * Converts a JSON String into a PublicKey object using the provided - * ObjectMapper. - * + * Converts a JSON String into a PublicKey object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return PublicKey object represented by the provided JSON */ - public static PublicKey fromJson(final String json, final ObjectMapper objectMapper) { + public static PublicKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PublicKey.class); @@ -107,12 +86,15 @@ public static PublicKey fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a PublicKey object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return PublicKey object represented by the provided JSON */ - public static PublicKey fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static PublicKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PublicKey.class); @@ -123,89 +105,63 @@ public static PublicKey fromJson(final InputStream json, final ObjectMapper obje } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private PublicKey(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private PublicKey( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The AccountSid the Credential resource belongs to. - * - * @return AccountSid the Credential resource belongs to - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The A human readable description of this resource. - * - * @return A human readable description of this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URI for this resource, relative to - * `https://accounts.twilio.com`. - * - * @return The URI for this resource, relative to `https://accounts.twilio.com` - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -217,34 +173,25 @@ public boolean equals(final Object o) { } PublicKey other = (PublicKey) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyCreator.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyCreator.java index 3019f1a06a..cf717afadf 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyCreator.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,99 +27,119 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PublicKeyCreator extends Creator { - private final String publicKey; + + private String publicKey; private String friendlyName; private String accountSid; - /** - * Construct a new PublicKeyCreator. - * - * @param publicKey URL encoded representation of the public key - */ public PublicKeyCreator(final String publicKey) { this.publicKey = publicKey; } - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ + public PublicKeyCreator setPublicKey(final String publicKey) { + this.publicKey = publicKey; + return this; + } + public PublicKeyCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The Subaccount this Credential should be associated with. Needs to be a valid - * Subaccount of the account issuing the request. - * - * @param accountSid The Subaccount this Credential should be associated with. - * @return this - */ public PublicKeyCreator setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created PublicKey - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PublicKey create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/PublicKeys"; + Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), - "/v1/Credentials/PublicKeys", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PublicKey creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return PublicKey.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public PublicKey create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PublicKey content = PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (publicKey != null) { - request.addPostParam("PublicKey", publicKey.toString()); + Serializer.toString( + request, + "PublicKey", + publicKey, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (accountSid != null) { - request.addPostParam("AccountSid", accountSid); + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyDeleter.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyDeleter.java index 20761e3c60..05023c3286 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyDeleter.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class PublicKeyDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new PublicKeyDeleter. - * - * @param pathSid A 34 character string that uniquely identifies this resource. - */ + private String pathSid; + public PublicKeyDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/PublicKeys/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.ACCOUNTS.toString(), - "/v1/Credentials/PublicKeys/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PublicKey delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyFetcher.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyFetcher.java index 3250835ac6..1251a8119f 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyFetcher.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PublicKeyFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new PublicKeyFetcher. - * - * @param pathSid Fetch by unique Credential Sid - */ + private String pathSid; + public PublicKeyFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched PublicKey - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PublicKey fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/PublicKeys/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.ACCOUNTS.toString(), - "/v1/Credentials/PublicKeys/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PublicKey fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return PublicKey.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public PublicKey fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PublicKey content = PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyReader.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyReader.java index b7df616b2c..cac6e02779 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyReader.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PublicKeyReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PublicKey ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public PublicKeyReader() {} + + public PublicKeyReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PublicKey ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + PublicKey.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/PublicKeys"; + Request request = new Request( HttpMethod.GET, Domains.ACCOUNTS.toString(), - "/v1/Credentials/PublicKeys", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return PublicKey ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + PublicKey.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PublicKey read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + PublicKey.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.ACCOUNTS.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.ACCOUNTS.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of PublicKey Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("PublicKey read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credentials", - response.getContent(), - PublicKey.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyUpdater.java b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyUpdater.java index 59b19cd6f0..04dcc1dd0a 100644 --- a/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyUpdater.java +++ b/src/main/java/com/twilio/rest/accounts/v1/credential/PublicKeyUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Accounts + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.accounts.v1.credential; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,78 +27,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PublicKeyUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; - /** - * Construct a new PublicKeyUpdater. - * - * @param pathSid Fetch by unique Credential Sid - */ public PublicKeyUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ public PublicKeyUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated PublicKey - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PublicKey update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/PublicKeys/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.ACCOUNTS.toString(), - "/v1/Credentials/PublicKeys/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PublicKey update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PublicKey update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public PublicKey update(final TwilioRestClient client) { + Response response = makeRequest(client); + return PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return PublicKey.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PublicKey content = PublicKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/Account.java b/src/main/java/com/twilio/rest/api/v2010/Account.java index e358e3d350..f3d71bc4e9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/Account.java +++ b/src/main/java/com/twilio/rest/api/v2010/Account.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010; @@ -10,31 +17,55 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Account extends Resource { - private static final long serialVersionUID = 82837000699633L; + + public static AccountCreator creator() { + return new AccountCreator(); + } + + public static AccountFetcher fetcher() { + return new AccountFetcher(); + } + + public static AccountFetcher fetcher(final String pathSid) { + return new AccountFetcher(pathSid); + } + + public static AccountReader reader() { + return new AccountReader(); + } + + public static AccountUpdater updater() { + return new AccountUpdater(); + } + + public static AccountUpdater updater(final String pathSid) { + return new AccountUpdater(pathSid); + } public enum Status { ACTIVE("active"), @@ -47,15 +78,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -72,85 +99,28 @@ private Type(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Type from a string. - * @param value string value - * @return generated Type - */ @JsonCreator public static Type forValue(final String value) { return Promoter.enumFromString(value, Type.values()); } } - /** - * Create a AccountCreator to execute create. - * - * @return AccountCreator capable of executing the create - */ - public static AccountCreator creator() { - return new AccountCreator(); - } - - /** - * Create a AccountFetcher to execute fetch. - * - * @param pathSid Fetch by unique Account Sid - * @return AccountFetcher capable of executing the fetch - */ - public static AccountFetcher fetcher(final String pathSid) { - return new AccountFetcher(pathSid); - } - - /** - * Create a AccountFetcher to execute fetch. - * - * @return AccountFetcher capable of executing the fetch - */ - public static AccountFetcher fetcher() { - return new AccountFetcher(); - } - - /** - * Create a AccountReader to execute read. - * - * @return AccountReader capable of executing the read - */ - public static AccountReader reader() { - return new AccountReader(); - } - - /** - * Create a AccountUpdater to execute update. - * - * @param pathSid The sid - * @return AccountUpdater capable of executing the update - */ - public static AccountUpdater updater(final String pathSid) { - return new AccountUpdater(pathSid); - } - - /** - * Create a AccountUpdater to execute update. - * - * @return AccountUpdater capable of executing the update - */ - public static AccountUpdater updater() { - return new AccountUpdater(); - } - /** * Converts a JSON String into a Account object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Account object represented by the provided JSON */ - public static Account fromJson(final String json, final ObjectMapper objectMapper) { + public static Account fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Account.class); @@ -164,12 +134,15 @@ public static Account fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Account object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Account object represented by the provided JSON */ - public static Account fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Account fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Account.class); @@ -180,41 +153,71 @@ public static Account fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String authToken; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter private final String ownerAccountSid; + + @Getter private final String sid; + + @Getter private final Account.Status status; + + @Getter private final Map subresourceUris; + + @Getter private final Account.Type type; + + @Getter private final String uri; @JsonCreator - private Account(@JsonProperty("auth_token") - final String authToken, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("owner_account_sid") - final String ownerAccountSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("status") - final Account.Status status, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("type") - final Account.Type type, - @JsonProperty("uri") - final String uri) { + private Account( + @JsonProperty("auth_token") final String authToken, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("owner_account_sid") final String ownerAccountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Account.Status status, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("type") final Account.Type type, + @JsonProperty("uri") final String uri + ) { this.authToken = authToken; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; this.ownerAccountSid = ownerAccountSid; this.sid = sid; @@ -224,97 +227,6 @@ private Account(@JsonProperty("auth_token") this.uri = uri; } - /** - * Returns The The authorization token for this account. - * - * @return The authorization token for this account - */ - public final String getAuthToken() { - return this.authToken; - } - - /** - * Returns The The date this account was created. - * - * @return The date this account was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this account was last updated. - * - * @return The date this account was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human readable description of this account. - * - * @return A human readable description of this account - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique 34 character id representing the parent of this - * account. - * - * @return The unique 34 character id representing the parent of this account - */ - public final String getOwnerAccountSid() { - return this.ownerAccountSid; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The status of this account. - * - * @return The status of this account - */ - public final Account.Status getStatus() { - return this.status; - } - - /** - * Returns The Account Instance Subresources. - * - * @return Account Instance Subresources - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The type of this account. - * - * @return The type of this account - */ - public final Account.Type getType() { - return this.type; - } - - /** - * Returns The The URI for this resource, relative to `https://api.twilio.com`. - * - * @return The URI for this resource, relative to `https://api.twilio.com` - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -326,46 +238,33 @@ public boolean equals(final Object o) { } Account other = (Account) o; - - return Objects.equals(authToken, other.authToken) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(ownerAccountSid, other.ownerAccountSid) && - Objects.equals(sid, other.sid) && - Objects.equals(status, other.status) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(type, other.type) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(authToken, other.authToken) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(ownerAccountSid, other.ownerAccountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(type, other.type) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(authToken, - dateCreated, - dateUpdated, - friendlyName, - ownerAccountSid, - sid, - status, - subresourceUris, - type, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("authToken", authToken) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("ownerAccountSid", ownerAccountSid) - .add("sid", sid) - .add("status", status) - .add("subresourceUris", subresourceUris) - .add("type", type) - .add("uri", uri) - .toString(); + return Objects.hash( + authToken, + dateCreated, + dateUpdated, + friendlyName, + ownerAccountSid, + sid, + status, + subresourceUris, + type, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java b/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java index 512dc69612..8eab565dee 100644 --- a/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/AccountCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,69 +27,84 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AccountCreator extends Creator { + private String friendlyName; - /** - * A human readable description of the account to create, defaults to - * `SubAccount Created at {YYYY-MM-DD HH:MM meridian}`. - * - * @param friendlyName A human readable description of the account - * @return this - */ + public AccountCreator() {} + public AccountCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Account - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Account create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts.json"; + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Account creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Account creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Account create(final TwilioRestClient client) { + Response response = makeRequest(client); return Account.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Account content = Account.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java b/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java index 3203f62d49..4ea5cfbbe7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/AccountFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AccountFetcher extends Fetcher { + private String pathSid; - /** - * Construct a new AccountFetcher. - */ - public AccountFetcher() { - } + public AccountFetcher() {} - /** - * Construct a new AccountFetcher. - * - * @param pathSid Fetch by unique Account Sid - */ public AccountFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Account - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Account fetch(final TwilioRestClient client) { - this.pathSid = this.pathSid == null ? client.getAccountSid() : this.pathSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{Sid}.json"; + + this.pathSid = + this.pathSid == null ? client.getAccountSid() : this.pathSid; + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Account fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Account fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Account fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Account.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Account content = Account.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/AccountReader.java b/src/main/java/com/twilio/rest/api/v2010/AccountReader.java index 0b2b393a3d..6a621341e8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/AccountReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/AccountReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010; @@ -10,183 +17,211 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AccountReader extends Reader { + private String friendlyName; private Account.Status status; + private Long pageSize; + + public AccountReader() {} - /** - * Only return the Account resources with friendly names that exactly match this - * name.. - * - * @param friendlyName FriendlyName to filter on - * @return this - */ public AccountReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Only return Account resources with the given status. Can be `closed`, - * `suspended` or `active`.. - * - * @param status Status to filter on - * @return this - */ public AccountReader setStatus(final Account.Status status) { this.status = status; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Account ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AccountReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Account ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "accounts", + response.getContent(), + Account.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts.json"; + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Account ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "accounts", + response.getContent(), + Account.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Account read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "accounts", + response.getContent(), + Account.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Account Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Account read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "accounts", - response.getContent(), - Account.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (status != null) { - request.addQueryParam("Status", status.toString()); + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java b/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java index e1ce46b90d..6fe8824cb2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/AccountUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,103 +27,108 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AccountUpdater extends Updater { + private String pathSid; private String friendlyName; private Account.Status status; - /** - * Construct a new AccountUpdater. - */ - public AccountUpdater() { - } + public AccountUpdater() {} - /** - * Construct a new AccountUpdater. - * - * @param pathSid The sid - */ public AccountUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Update the human-readable description of this Account. - * - * @param friendlyName FriendlyName to update - * @return this - */ public AccountUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Alter the status of this account: use `closed` to irreversibly close this - * account, `suspended` to temporarily suspend it, or `active` to reactivate - * it.. - * - * @param status Status to update the Account with - * @return this - */ public AccountUpdater setStatus(final Account.Status status) { this.status = status; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Account - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Account update(final TwilioRestClient client) { - this.pathSid = this.pathSid == null ? client.getAccountSid() : this.pathSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{Sid}.json"; + + this.pathSid = + this.pathSid == null ? client.getAccountSid() : this.pathSid; + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Account update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Account update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Account update(final TwilioRestClient client) { + Response response = makeRequest(client); return Account.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Account content = Account.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (status != null) { - request.addPostParam("Status", status.toString()); + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Address.java b/src/main/java/com/twilio/rest/api/v2010/account/Address.java index a2d1c43af1..ac3bb3da99 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Address.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Address.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,167 +18,118 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Address extends Resource { - private static final long serialVersionUID = 205717359907857L; - /** - * Create a AddressCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param customerName Your name or business name, or that of your customer. - * @param street The number and street address where you or your customer is - * located. - * @param city The city in which you or your customer is located. - * @param region The state or region in which you or your customer is located. - * @param postalCode The postal code in which you or your customer is located. - * @param isoCountry The ISO country code of your or your customer's address. - * @return AddressCreator capable of executing the create - */ - public static AddressCreator creator(final String pathAccountSid, - final String customerName, - final String street, - final String city, - final String region, - final String postalCode, - final String isoCountry) { - return new AddressCreator(pathAccountSid, customerName, street, city, region, postalCode, isoCountry); + public static AddressCreator creator( + final String customerName, + final String street, + final String city, + final String region, + final String postalCode, + final String isoCountry + ) { + return new AddressCreator( + customerName, + street, + city, + region, + postalCode, + isoCountry + ); } - /** - * Create a AddressCreator to execute create. - * - * @param customerName Your name or business name, or that of your customer. - * @param street The number and street address where you or your customer is - * located. - * @param city The city in which you or your customer is located. - * @param region The state or region in which you or your customer is located. - * @param postalCode The postal code in which you or your customer is located. - * @param isoCountry The ISO country code of your or your customer's address. - * @return AddressCreator capable of executing the create - */ - public static AddressCreator creator(final String customerName, - final String street, - final String city, - final String region, - final String postalCode, - final String isoCountry) { - return new AddressCreator(customerName, street, city, region, postalCode, isoCountry); + public static AddressCreator creator( + final String pathAccountSid, + final String customerName, + final String street, + final String city, + final String region, + final String postalCode, + final String isoCountry + ) { + return new AddressCreator( + pathAccountSid, + customerName, + street, + city, + region, + postalCode, + isoCountry + ); } - /** - * Create a AddressDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return AddressDeleter capable of executing the delete - */ - public static AddressDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new AddressDeleter(pathAccountSid, pathSid); - } - - /** - * Create a AddressDeleter to execute delete. - * - * @param pathSid The sid - * @return AddressDeleter capable of executing the delete - */ public static AddressDeleter deleter(final String pathSid) { return new AddressDeleter(pathSid); } - /** - * Create a AddressFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return AddressFetcher capable of executing the fetch - */ - public static AddressFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new AddressFetcher(pathAccountSid, pathSid); + public static AddressDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new AddressDeleter(pathAccountSid, pathSid); } - /** - * Create a AddressFetcher to execute fetch. - * - * @param pathSid The sid - * @return AddressFetcher capable of executing the fetch - */ public static AddressFetcher fetcher(final String pathSid) { return new AddressFetcher(pathSid); } - /** - * Create a AddressUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return AddressUpdater capable of executing the update - */ - public static AddressUpdater updater(final String pathAccountSid, - final String pathSid) { - return new AddressUpdater(pathAccountSid, pathSid); + public static AddressFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new AddressFetcher(pathAccountSid, pathSid); } - /** - * Create a AddressUpdater to execute update. - * - * @param pathSid The sid - * @return AddressUpdater capable of executing the update - */ - public static AddressUpdater updater(final String pathSid) { - return new AddressUpdater(pathSid); + public static AddressReader reader() { + return new AddressReader(); } - /** - * Create a AddressReader to execute read. - * - * @param pathAccountSid The account_sid - * @return AddressReader capable of executing the read - */ public static AddressReader reader(final String pathAccountSid) { return new AddressReader(pathAccountSid); } - /** - * Create a AddressReader to execute read. - * - * @return AddressReader capable of executing the read - */ - public static AddressReader reader() { - return new AddressReader(); + public static AddressUpdater updater(final String pathSid) { + return new AddressUpdater(pathSid); + } + + public static AddressUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new AddressUpdater(pathAccountSid, pathSid); } /** * Converts a JSON String into a Address object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Address object represented by the provided JSON */ - public static Address fromJson(final String json, final ObjectMapper objectMapper) { + public static Address fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Address.class); @@ -185,12 +143,15 @@ public static Address fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Address object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Address object represented by the provided JSON */ - public static Address fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Address fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Address.class); @@ -201,195 +162,105 @@ public static Address fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String city; + + @Getter private final String customerName; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Boolean emergencyEnabled; + + @Getter private final String friendlyName; + + @Getter private final String isoCountry; + + @Getter private final String postalCode; + + @Getter private final String region; + + @Getter private final String sid; + + @Getter private final String street; + + @Getter + private final String streetSecondary; + + @Getter private final String uri; - private final Boolean emergencyEnabled; + + @Getter private final Boolean validated; + @Getter + private final Boolean verified; + @JsonCreator - private Address(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("city") - final String city, - @JsonProperty("customer_name") - final String customerName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("postal_code") - final String postalCode, - @JsonProperty("region") - final String region, - @JsonProperty("sid") - final String sid, - @JsonProperty("street") - final String street, - @JsonProperty("uri") - final String uri, - @JsonProperty("emergency_enabled") - final Boolean emergencyEnabled, - @JsonProperty("validated") - final Boolean validated) { + private Address( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("city") final String city, + @JsonProperty("customer_name") final String customerName, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("emergency_enabled") final Boolean emergencyEnabled, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("region") final String region, + @JsonProperty("sid") final String sid, + @JsonProperty("street") final String street, + @JsonProperty("street_secondary") final String streetSecondary, + @JsonProperty("uri") final String uri, + @JsonProperty("validated") final Boolean validated, + @JsonProperty("verified") final Boolean verified + ) { this.accountSid = accountSid; this.city = city; this.customerName = customerName; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.emergencyEnabled = emergencyEnabled; this.friendlyName = friendlyName; this.isoCountry = isoCountry; this.postalCode = postalCode; this.region = region; this.sid = sid; this.street = street; + this.streetSecondary = streetSecondary; this.uri = uri; - this.emergencyEnabled = emergencyEnabled; this.validated = validated; - } - - /** - * Returns The The unique id of the Account responsible for this address.. - * - * @return The unique id of the Account responsible for this address. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The city in which you or your customer is located.. - * - * @return The city in which you or your customer is located. - */ - public final String getCity() { - return this.city; - } - - /** - * Returns The Your name or business name, or that of your customer.. - * - * @return Your name or business name, or that of your customer. - */ - public final String getCustomerName() { - return this.customerName; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human-readable description of the address.. - * - * @return A human-readable description of the address. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The ISO country code of your or your customer's address.. - * - * @return The ISO country code of your or your customer's address. - */ - public final String getIsoCountry() { - return this.isoCountry; - } - - /** - * Returns The The postal code in which you or your customer is located.. - * - * @return The postal code in which you or your customer is located. - */ - public final String getPostalCode() { - return this.postalCode; - } - - /** - * Returns The The state or region in which you or your customer is located.. - * - * @return The state or region in which you or your customer is located. - */ - public final String getRegion() { - return this.region; - } - - /** - * Returns The A 34 character string that uniquely identifies this address.. - * - * @return A 34 character string that uniquely identifies this address. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The number and street address where you or your customer is - * located.. - * - * @return The number and street address where you or your customer is located. - */ - public final String getStreet() { - return this.street; - } - - /** - * Returns The The URI for this resource, relative to https://api.. - * - * @return The URI for this resource, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The This is a value that indicates if emergency calling has been - * enabled on this number.. - * - * @return This is a value that indicates if emergency calling has been enabled - * on this number. - */ - public final Boolean getEmergencyEnabled() { - return this.emergencyEnabled; - } - - /** - * Returns The In some countries, addresses are validated to comply with local - * regulation.. - * - * @return In some countries, addresses are validated to comply with local - * regulation. - */ - public final Boolean getValidated() { - return this.validated; + this.verified = verified; } @Override @@ -403,58 +274,45 @@ public boolean equals(final Object o) { } Address other = (Address) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(city, other.city) && - Objects.equals(customerName, other.customerName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(postalCode, other.postalCode) && - Objects.equals(region, other.region) && - Objects.equals(sid, other.sid) && - Objects.equals(street, other.street) && - Objects.equals(uri, other.uri) && - Objects.equals(emergencyEnabled, other.emergencyEnabled) && - Objects.equals(validated, other.validated); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(city, other.city) && + Objects.equals(customerName, other.customerName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(emergencyEnabled, other.emergencyEnabled) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(region, other.region) && + Objects.equals(sid, other.sid) && + Objects.equals(street, other.street) && + Objects.equals(streetSecondary, other.streetSecondary) && + Objects.equals(uri, other.uri) && + Objects.equals(validated, other.validated) && + Objects.equals(verified, other.verified) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - city, - customerName, - dateCreated, - dateUpdated, - friendlyName, - isoCountry, - postalCode, - region, - sid, - street, - uri, - emergencyEnabled, - validated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("city", city) - .add("customerName", customerName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("isoCountry", isoCountry) - .add("postalCode", postalCode) - .add("region", region) - .add("sid", sid) - .add("street", street) - .add("uri", uri) - .add("emergencyEnabled", emergencyEnabled) - .add("validated", validated) - .toString(); + return Objects.hash( + accountSid, + city, + customerName, + dateCreated, + dateUpdated, + emergencyEnabled, + friendlyName, + isoCountry, + postalCode, + region, + sid, + street, + streetSecondary, + uri, + validated, + verified + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressCreator.java index 8ef41bbbc9..8244662207 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,36 +27,31 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AddressCreator extends Creator
    { + private String pathAccountSid; - private final String customerName; - private final String street; - private final String city; - private final String region; - private final String postalCode; - private final String isoCountry; + private String customerName; + private String street; + private String city; + private String region; + private String postalCode; + private String isoCountry; private String friendlyName; private Boolean emergencyEnabled; private Boolean autoCorrectAddress; + private String streetSecondary; - /** - * Construct a new AddressCreator. - * - * @param customerName Your name or business name, or that of your customer. - * @param street The number and street address where you or your customer is - * located. - * @param city The city in which you or your customer is located. - * @param region The state or region in which you or your customer is located. - * @param postalCode The postal code in which you or your customer is located. - * @param isoCountry The ISO country code of your or your customer's address. - */ - public AddressCreator(final String customerName, - final String street, - final String city, - final String region, - final String postalCode, - final String isoCountry) { + public AddressCreator( + final String customerName, + final String street, + final String city, + final String region, + final String postalCode, + final String isoCountry + ) { this.customerName = customerName; this.street = street; this.city = city; @@ -54,25 +60,15 @@ public AddressCreator(final String customerName, this.isoCountry = isoCountry; } - /** - * Construct a new AddressCreator. - * - * @param pathAccountSid The account_sid - * @param customerName Your name or business name, or that of your customer. - * @param street The number and street address where you or your customer is - * located. - * @param city The city in which you or your customer is located. - * @param region The state or region in which you or your customer is located. - * @param postalCode The postal code in which you or your customer is located. - * @param isoCountry The ISO country code of your or your customer's address. - */ - public AddressCreator(final String pathAccountSid, - final String customerName, - final String street, - final String city, - final String region, - final String postalCode, - final String isoCountry) { + public AddressCreator( + final String pathAccountSid, + final String customerName, + final String street, + final String city, + final String region, + final String postalCode, + final String isoCountry + ) { this.pathAccountSid = pathAccountSid; this.customerName = customerName; this.street = street; @@ -82,124 +78,213 @@ public AddressCreator(final String pathAccountSid, this.isoCountry = isoCountry; } - /** - * A human-readable description of the new address. Maximum 64 characters.. - * - * @param friendlyName A human-readable description of the new address. - * @return this - */ + public AddressCreator setCustomerName(final String customerName) { + this.customerName = customerName; + return this; + } + + public AddressCreator setStreet(final String street) { + this.street = street; + return this; + } + + public AddressCreator setCity(final String city) { + this.city = city; + return this; + } + + public AddressCreator setRegion(final String region) { + this.region = region; + return this; + } + + public AddressCreator setPostalCode(final String postalCode) { + this.postalCode = postalCode; + return this; + } + + public AddressCreator setIsoCountry(final String isoCountry) { + this.isoCountry = isoCountry; + return this; + } + public AddressCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The emergency_enabled. - * - * @param emergencyEnabled The emergency_enabled - * @return this - */ public AddressCreator setEmergencyEnabled(final Boolean emergencyEnabled) { this.emergencyEnabled = emergencyEnabled; return this; } - /** - * If you don't set a value for this parameter, or if you set it to `true`, then - * the system will, if necessary, auto-correct the address you provide. If you - * don't want the system to auto-correct the address, you will explicitly need - * to set this value to `false`.. - * - * @param autoCorrectAddress If you don't set a value for this parameter, or if - * you set it to true, then the system will, if - * necessary, auto-correct the address you provide. - * @return this - */ - public AddressCreator setAutoCorrectAddress(final Boolean autoCorrectAddress) { + public AddressCreator setAutoCorrectAddress( + final Boolean autoCorrectAddress + ) { this.autoCorrectAddress = autoCorrectAddress; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Address - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Address create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public AddressCreator setStreetSecondary(final String streetSecondary) { + this.streetSecondary = streetSecondary; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Addresses.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Addresses.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Address creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Address create(final TwilioRestClient client) { + Response response = makeRequest(client); return Address.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse
    createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Address content = Address.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (customerName != null) { - request.addPostParam("CustomerName", customerName); + Serializer.toString( + request, + "CustomerName", + customerName, + ParameterType.URLENCODED + ); } if (street != null) { - request.addPostParam("Street", street); + Serializer.toString( + request, + "Street", + street, + ParameterType.URLENCODED + ); } if (city != null) { - request.addPostParam("City", city); + Serializer.toString( + request, + "City", + city, + ParameterType.URLENCODED + ); } if (region != null) { - request.addPostParam("Region", region); + Serializer.toString( + request, + "Region", + region, + ParameterType.URLENCODED + ); } if (postalCode != null) { - request.addPostParam("PostalCode", postalCode); + Serializer.toString( + request, + "PostalCode", + postalCode, + ParameterType.URLENCODED + ); } if (isoCountry != null) { - request.addPostParam("IsoCountry", isoCountry); + Serializer.toString( + request, + "IsoCountry", + isoCountry, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (emergencyEnabled != null) { - request.addPostParam("EmergencyEnabled", emergencyEnabled.toString()); + Serializer.toString( + request, + "EmergencyEnabled", + emergencyEnabled, + ParameterType.URLENCODED + ); } if (autoCorrectAddress != null) { - request.addPostParam("AutoCorrectAddress", autoCorrectAddress.toString()); + Serializer.toString( + request, + "AutoCorrectAddress", + autoCorrectAddress, + ParameterType.URLENCODED + ); + } + + if (streetSecondary != null) { + Serializer.toString( + request, + "StreetSecondary", + streetSecondary, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressDeleter.java index b8e13aa45d..c11cd3a409 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class AddressDeleter extends Deleter
    { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new AddressDeleter. - * - * @param pathSid The sid - */ public AddressDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new AddressDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public AddressDeleter(final String pathAccountSid, - final String pathSid) { + public AddressDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Addresses/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Address delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressFetcher.java index c02f0d67ce..2941bc6d0c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,85 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AddressFetcher extends Fetcher
    { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new AddressFetcher. - * - * @param pathSid The sid - */ public AddressFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new AddressFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public AddressFetcher(final String pathAccountSid, - final String pathSid) { + public AddressFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Address - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Address fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Addresses/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Address fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Address fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Address.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse
    fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Address content = Address.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressReader.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressReader.java index 3afc8a867b..80548b8066 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,219 +17,261 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AddressReader extends Reader
    { + private String pathAccountSid; private String customerName; private String friendlyName; + private Boolean emergencyEnabled; private String isoCountry; + private Long pageSize; - /** - * Construct a new AddressReader. - */ - public AddressReader() { - } + public AddressReader() {} - /** - * Construct a new AddressReader. - * - * @param pathAccountSid The account_sid - */ public AddressReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only return the Address resources with customer names that exactly match this - * name.. - * - * @param customerName Only return the Address resources with customer names - * that exactly match this name. - * @return this - */ public AddressReader setCustomerName(final String customerName) { this.customerName = customerName; return this; } - /** - * Only return the Address resources with friendly names that exactly match this - * name.. - * - * @param friendlyName Only return the Address resources with friendly names - * that exactly match this name. - * @return this - */ public AddressReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Only return the Address resources in this country.. - * - * @param isoCountry Only return the Address resources in this country. - * @return this - */ + public AddressReader setEmergencyEnabled(final Boolean emergencyEnabled) { + this.emergencyEnabled = emergencyEnabled; + return this; + } + public AddressReader setIsoCountry(final String isoCountry) { this.isoCountry = isoCountry; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Address ResourceSet - */ - @Override - public ResourceSet
    read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AddressReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Address ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page
    firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse
    readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page
    page = Page.fromJson( + "addresses", + response.getContent(), + Address.class, + client.getObjectMapper() + ); + ResourceSet
    resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Addresses.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Addresses.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Address ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page
    getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet
    read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page
    firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page
    page = Page.fromJson( + "addresses", + response.getContent(), + Address.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Address read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page
    pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "addresses", + response.getContent(), + Address.class, + client.getObjectMapper() + ); + } + @Override - public Page
    nextPage(final Page
    page, - final TwilioRestClient client) { + public Page
    previousPage( + final Page
    page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page
    previousPage(final Page
    page, - final TwilioRestClient client) { + public Page
    nextPage( + final Page
    page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Address Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page
    pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Address read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page
    getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "addresses", - response.getContent(), - Address.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (customerName != null) { - request.addQueryParam("CustomerName", customerName); + Serializer.toString( + request, + "CustomerName", + customerName, + ParameterType.QUERY + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (emergencyEnabled != null) { + Serializer.toString( + request, + "EmergencyEnabled", + emergencyEnabled, + ParameterType.QUERY + ); } if (isoCountry != null) { - request.addQueryParam("IsoCountry", isoCountry); + Serializer.toString( + request, + "IsoCountry", + isoCountry, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AddressUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/AddressUpdater.java index f2ef0105e7..fc2fd472d9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AddressUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AddressUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,10 +27,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AddressUpdater extends Updater
    { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private String friendlyName; private String customerName; private String street; @@ -28,198 +42,211 @@ public class AddressUpdater extends Updater
    { private String postalCode; private Boolean emergencyEnabled; private Boolean autoCorrectAddress; + private String streetSecondary; - /** - * Construct a new AddressUpdater. - * - * @param pathSid The sid - */ public AddressUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new AddressUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public AddressUpdater(final String pathAccountSid, - final String pathSid) { + public AddressUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * A human-readable description of the address. Maximum 64 characters.. - * - * @param friendlyName A human-readable description of the address. - * @return this - */ public AddressUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Your name or business name, or that of your customer.. - * - * @param customerName Your name or business name, or that of your customer. - * @return this - */ public AddressUpdater setCustomerName(final String customerName) { this.customerName = customerName; return this; } - /** - * The number and street address where you or your customer is located.. - * - * @param street The number and street address where you or your customer is - * located. - * @return this - */ public AddressUpdater setStreet(final String street) { this.street = street; return this; } - /** - * The city in which you or your customer is located.. - * - * @param city The city in which you or your customer is located. - * @return this - */ public AddressUpdater setCity(final String city) { this.city = city; return this; } - /** - * The state or region in which you or your customer is located.. - * - * @param region The state or region in which you or your customer is located. - * @return this - */ public AddressUpdater setRegion(final String region) { this.region = region; return this; } - /** - * The postal code in which you or your customer is located.. - * - * @param postalCode The postal code in which you or your customer is located. - * @return this - */ public AddressUpdater setPostalCode(final String postalCode) { this.postalCode = postalCode; return this; } - /** - * The emergency_enabled. - * - * @param emergencyEnabled The emergency_enabled - * @return this - */ public AddressUpdater setEmergencyEnabled(final Boolean emergencyEnabled) { this.emergencyEnabled = emergencyEnabled; return this; } - /** - * If you don't set a value for this parameter, or if you set it to `true`, then - * the system will, if necessary, auto-correct the address you provide. If you - * don't want the system to auto-correct the address, you will explicitly need - * to set this value to `false`.. - * - * @param autoCorrectAddress If you don't set a value for this parameter, or if - * you set it to true, then the system will, if - * necessary, auto-correct the address you provide. - * @return this - */ - public AddressUpdater setAutoCorrectAddress(final Boolean autoCorrectAddress) { + public AddressUpdater setAutoCorrectAddress( + final Boolean autoCorrectAddress + ) { this.autoCorrectAddress = autoCorrectAddress; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Address - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Address update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public AddressUpdater setStreetSecondary(final String streetSecondary) { + this.streetSecondary = streetSecondary; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Addresses/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Addresses/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Address update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Address update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Address update(final TwilioRestClient client) { + Response response = makeRequest(client); return Address.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse
    updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Address content = Address.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (customerName != null) { - request.addPostParam("CustomerName", customerName); + Serializer.toString( + request, + "CustomerName", + customerName, + ParameterType.URLENCODED + ); } if (street != null) { - request.addPostParam("Street", street); + Serializer.toString( + request, + "Street", + street, + ParameterType.URLENCODED + ); } if (city != null) { - request.addPostParam("City", city); + Serializer.toString( + request, + "City", + city, + ParameterType.URLENCODED + ); } if (region != null) { - request.addPostParam("Region", region); + Serializer.toString( + request, + "Region", + region, + ParameterType.URLENCODED + ); } if (postalCode != null) { - request.addPostParam("PostalCode", postalCode); + Serializer.toString( + request, + "PostalCode", + postalCode, + ParameterType.URLENCODED + ); } if (emergencyEnabled != null) { - request.addPostParam("EmergencyEnabled", emergencyEnabled.toString()); + Serializer.toString( + request, + "EmergencyEnabled", + emergencyEnabled, + ParameterType.URLENCODED + ); } if (autoCorrectAddress != null) { - request.addPostParam("AutoCorrectAddress", autoCorrectAddress.toString()); + Serializer.toString( + request, + "AutoCorrectAddress", + autoCorrectAddress, + ParameterType.URLENCODED + ); + } + + if (streetSecondary != null) { + Serializer.toString( + request, + "StreetSecondary", + streetSecondary, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Application.java b/src/main/java/com/twilio/rest/api/v2010/account/Application.java index 313c3e6e90..0d580b1776 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Application.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Application.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,147 +18,90 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Application extends Resource { - private static final long serialVersionUID = 30273898590025L; - /** - * Create a ApplicationCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param friendlyName A human readable description of the application - * @return ApplicationCreator capable of executing the create - */ - public static ApplicationCreator creator(final String pathAccountSid, - final String friendlyName) { - return new ApplicationCreator(pathAccountSid, friendlyName); + public static ApplicationCreator creator() { + return new ApplicationCreator(); } - /** - * Create a ApplicationCreator to execute create. - * - * @param friendlyName A human readable description of the application - * @return ApplicationCreator capable of executing the create - */ - public static ApplicationCreator creator(final String friendlyName) { - return new ApplicationCreator(friendlyName); + public static ApplicationCreator creator(final String pathAccountSid) { + return new ApplicationCreator(pathAccountSid); } - /** - * Create a ApplicationDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid The application sid to delete - * @return ApplicationDeleter capable of executing the delete - */ - public static ApplicationDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new ApplicationDeleter(pathAccountSid, pathSid); - } - - /** - * Create a ApplicationDeleter to execute delete. - * - * @param pathSid The application sid to delete - * @return ApplicationDeleter capable of executing the delete - */ public static ApplicationDeleter deleter(final String pathSid) { return new ApplicationDeleter(pathSid); } - /** - * Create a ApplicationFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique Application Sid - * @return ApplicationFetcher capable of executing the fetch - */ - public static ApplicationFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new ApplicationFetcher(pathAccountSid, pathSid); + public static ApplicationDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new ApplicationDeleter(pathAccountSid, pathSid); } - /** - * Create a ApplicationFetcher to execute fetch. - * - * @param pathSid Fetch by unique Application Sid - * @return ApplicationFetcher capable of executing the fetch - */ public static ApplicationFetcher fetcher(final String pathSid) { return new ApplicationFetcher(pathSid); } - /** - * Create a ApplicationReader to execute read. - * - * @param pathAccountSid The account_sid - * @return ApplicationReader capable of executing the read - */ - public static ApplicationReader reader(final String pathAccountSid) { - return new ApplicationReader(pathAccountSid); + public static ApplicationFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new ApplicationFetcher(pathAccountSid, pathSid); } - /** - * Create a ApplicationReader to execute read. - * - * @return ApplicationReader capable of executing the read - */ public static ApplicationReader reader() { return new ApplicationReader(); } - /** - * Create a ApplicationUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return ApplicationUpdater capable of executing the update - */ - public static ApplicationUpdater updater(final String pathAccountSid, - final String pathSid) { - return new ApplicationUpdater(pathAccountSid, pathSid); + public static ApplicationReader reader(final String pathAccountSid) { + return new ApplicationReader(pathAccountSid); } - /** - * Create a ApplicationUpdater to execute update. - * - * @param pathSid The sid - * @return ApplicationUpdater capable of executing the update - */ public static ApplicationUpdater updater(final String pathSid) { return new ApplicationUpdater(pathSid); } + public static ApplicationUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new ApplicationUpdater(pathAccountSid, pathSid); + } + /** - * Converts a JSON String into a Application object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Application object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Application object represented by the provided JSON */ - public static Application fromJson(final String json, final ObjectMapper objectMapper) { + public static Application fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Application.class); @@ -165,12 +115,15 @@ public static Application fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a Application object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Application object represented by the provided JSON */ - public static Application fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Application fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Application.class); @@ -181,74 +134,126 @@ public static Application fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter private final URI messageStatusCallback; + + @Getter + private final Boolean publicApplicationConnectEnabled; + + @Getter private final String sid; + + @Getter private final HttpMethod smsFallbackMethod; + + @Getter private final URI smsFallbackUrl; + + @Getter private final HttpMethod smsMethod; + + @Getter private final URI smsStatusCallback; + + @Getter private final URI smsUrl; + + @Getter private final URI statusCallback; + + @Getter private final HttpMethod statusCallbackMethod; + + @Getter private final String uri; + + @Getter private final Boolean voiceCallerIdLookup; + + @Getter private final HttpMethod voiceFallbackMethod; + + @Getter private final URI voiceFallbackUrl; + + @Getter private final HttpMethod voiceMethod; + + @Getter private final URI voiceUrl; @JsonCreator - private Application(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("message_status_callback") - final URI messageStatusCallback, - @JsonProperty("sid") - final String sid, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_status_callback") - final URI smsStatusCallback, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("status_callback") - final URI statusCallback, - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - @JsonProperty("uri") - final String uri, - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_url") - final URI voiceUrl) { + private Application( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "message_status_callback" + ) final URI messageStatusCallback, + @JsonProperty( + "public_application_connect_enabled" + ) final Boolean publicApplicationConnectEnabled, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_status_callback") final URI smsStatusCallback, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("uri") final String uri, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; this.messageStatusCallback = messageStatusCallback; + this.publicApplicationConnectEnabled = publicApplicationConnectEnabled; this.sid = sid; this.smsFallbackMethod = smsFallbackMethod; this.smsFallbackUrl = smsFallbackUrl; @@ -265,186 +270,6 @@ private Application(@JsonProperty("account_sid") this.voiceUrl = voiceUrl; } - /** - * Returns The A string that uniquely identifies this resource. - * - * @return A string that uniquely identifies this resource - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The API version to use. - * - * @return The API version to use - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The Date this resource was created. - * - * @return Date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The Date this resource was last updated. - * - * @return Date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Human readable description of this resource. - * - * @return Human readable description of this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The URL to make requests to with status updates. - * - * @return URL to make requests to with status updates - */ - public final URI getMessageStatusCallback() { - return this.messageStatusCallback; - } - - /** - * Returns The A string that uniquely identifies this resource. - * - * @return A string that uniquely identifies this resource - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The HTTP method to use with sms_fallback_method. - * - * @return HTTP method to use with sms_fallback_method - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - - /** - * Returns The Fallback URL if there's an error parsing TwiML. - * - * @return Fallback URL if there's an error parsing TwiML - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - - /** - * Returns The HTTP method to use with sms_url. - * - * @return HTTP method to use with sms_url - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - - /** - * Returns The URL Twilio with request with status updates. - * - * @return URL Twilio with request with status updates - */ - public final URI getSmsStatusCallback() { - return this.smsStatusCallback; - } - - /** - * Returns The URL Twilio will request when receiving an SMS. - * - * @return URL Twilio will request when receiving an SMS - */ - public final URI getSmsUrl() { - return this.smsUrl; - } - - /** - * Returns The URL to hit with status updates. - * - * @return URL to hit with status updates - */ - public final URI getStatusCallback() { - return this.statusCallback; - } - - /** - * Returns The HTTP method to use with the status callback. - * - * @return HTTP method to use with the status callback - */ - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - - /** - * Returns The URI for this resource. - * - * @return URI for this resource - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The True or False. - * - * @return True or False - */ - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - - /** - * Returns The HTTP method to use with the fallback url. - * - * @return HTTP method to use with the fallback url - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - - /** - * Returns The Fallback URL. - * - * @return Fallback URL - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - - /** - * Returns The HTTP method to use with the URL. - * - * @return HTTP method to use with the URL - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - - /** - * Returns The URL Twilio will make requests to when relieving a call. - * - * @return URL Twilio will make requests to when relieving a call - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -456,76 +281,61 @@ public boolean equals(final Object o) { } Application other = (Application) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(messageStatusCallback, other.messageStatusCallback) && - Objects.equals(sid, other.sid) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsStatusCallback, other.smsStatusCallback) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(statusCallback, other.statusCallback) && - Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && - Objects.equals(uri, other.uri) && - Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceUrl, other.voiceUrl); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + messageStatusCallback, + other.messageStatusCallback + ) && + Objects.equals( + publicApplicationConnectEnabled, + other.publicApplicationConnectEnabled + ) && + Objects.equals(sid, other.sid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsStatusCallback, other.smsStatusCallback) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - dateCreated, - dateUpdated, - friendlyName, - messageStatusCallback, - sid, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsStatusCallback, - smsUrl, - statusCallback, - statusCallbackMethod, - uri, - voiceCallerIdLookup, - voiceFallbackMethod, - voiceFallbackUrl, - voiceMethod, - voiceUrl); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("messageStatusCallback", messageStatusCallback) - .add("sid", sid) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsStatusCallback", smsStatusCallback) - .add("smsUrl", smsUrl) - .add("statusCallback", statusCallback) - .add("statusCallbackMethod", statusCallbackMethod) - .add("uri", uri) - .add("voiceCallerIdLookup", voiceCallerIdLookup) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceMethod", voiceMethod) - .add("voiceUrl", voiceUrl) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + dateCreated, + dateUpdated, + friendlyName, + messageStatusCallback, + publicApplicationConnectEnabled, + sid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsStatusCallback, + smsUrl, + statusCallback, + statusCallbackMethod, + uri, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationCreator.java index f3d3281ed4..c5b773f21c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class ApplicationCreator extends Creator { + private String pathAccountSid; - private final String friendlyName; private String apiVersion; private URI voiceUrl; private HttpMethod voiceMethod; @@ -37,386 +49,357 @@ public class ApplicationCreator extends Creator { private HttpMethod smsFallbackMethod; private URI smsStatusCallback; private URI messageStatusCallback; + private String friendlyName; + private Boolean publicApplicationConnectEnabled; - /** - * Construct a new ApplicationCreator. - * - * @param friendlyName A human readable description of the application - */ - public ApplicationCreator(final String friendlyName) { - this.friendlyName = friendlyName; - } + public ApplicationCreator() {} - /** - * Construct a new ApplicationCreator. - * - * @param pathAccountSid The account_sid - * @param friendlyName A human readable description of the application - */ - public ApplicationCreator(final String pathAccountSid, - final String friendlyName) { + public ApplicationCreator(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; - this.friendlyName = friendlyName; } - /** - * Requests to this application's URLs will start a new TwiML session with this - * API version. Either `2010-04-01` or `2008-08-01`. Defaults to your account's - * default API version.. - * - * @param apiVersion The API version to use - * @return this - */ public ApplicationCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - /** - * The URL that Twilio should request when somebody dials a phone number - * assigned to this application.. - * - * @param voiceUrl URL Twilio will make requests to when relieving a call - * @return this - */ public ApplicationCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The URL that Twilio should request when somebody dials a phone number - * assigned to this application.. - * - * @param voiceUrl URL Twilio will make requests to when relieving a call - * @return this - */ public ApplicationCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The HTTP method that should be used to request the `VoiceUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceMethod HTTP method to use with the URL - * @return this - */ public ApplicationCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - /** - * The URL that Twilio will request if an error occurs retrieving or executing - * the TwiML requested by `Url`.. - * - * @param voiceFallbackUrl Fallback URL - * @return this - */ public ApplicationCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * The URL that Twilio will request if an error occurs retrieving or executing - * the TwiML requested by `Url`.. - * - * @param voiceFallbackUrl Fallback URL - * @return this - */ - public ApplicationCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { + public ApplicationCreator setVoiceFallbackUrl( + final String voiceFallbackUrl + ) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method that should be used to request the `VoiceFallbackUrl`. Either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceFallbackMethod HTTP method to use with the fallback url - * @return this - */ - public ApplicationCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public ApplicationCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback URL to hit with status updates - * @return this - */ public ApplicationCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback URL to hit with status updates - * @return this - */ public ApplicationCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio will use to make requests to the `StatusCallback` URL. - * Either `GET` or `POST`. Defaults to `POST`.. - * - * @param statusCallbackMethod HTTP method to use with the status callback - * @return this - */ - public ApplicationCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public ApplicationCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * Do a lookup of a caller's name from the CNAM database and post it to your - * app. Either `true` or `false`. Defaults to `false`.. - * - * @param voiceCallerIdLookup True or False - * @return this - */ - public ApplicationCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup) { + public ApplicationCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - /** - * The URL Twilio will request when a phone number assigned to this application - * receives an incoming SMS message.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public ApplicationCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL Twilio will request when a phone number assigned to this application - * receives an incoming SMS message.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public ApplicationCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The HTTP method that should be used to request the `SmsUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param smsMethod HTTP method to use with sms_url - * @return this - */ public ApplicationCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl Fallback URL if there's an error parsing TwiML - * @return this - */ public ApplicationCreator setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl Fallback URL if there's an error parsing TwiML - * @return this - */ public ApplicationCreator setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method that should be used to request the `SmsFallbackUrl`. Must be - * either `GET` or `POST`. Defaults to `POST`.. - * - * @param smsFallbackMethod HTTP method to use with sms_fallback_method - * @return this - */ - public ApplicationCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public ApplicationCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * Twilio will make a `POST` request to this URL to pass status parameters (such - * as sent or failed) to your application if you specify this application's - * `Sid` as the `ApplicationSid` on an [outgoing SMS - * request](https://www.twilio.com/docs/sms/send-messages).. - * - * @param smsStatusCallback URL Twilio with request with status updates - * @return this - */ - public ApplicationCreator setSmsStatusCallback(final URI smsStatusCallback) { + public ApplicationCreator setSmsStatusCallback( + final URI smsStatusCallback + ) { this.smsStatusCallback = smsStatusCallback; return this; } - /** - * Twilio will make a `POST` request to this URL to pass status parameters (such - * as sent or failed) to your application if you specify this application's - * `Sid` as the `ApplicationSid` on an [outgoing SMS - * request](https://www.twilio.com/docs/sms/send-messages).. - * - * @param smsStatusCallback URL Twilio with request with status updates - * @return this - */ - public ApplicationCreator setSmsStatusCallback(final String smsStatusCallback) { + public ApplicationCreator setSmsStatusCallback( + final String smsStatusCallback + ) { return setSmsStatusCallback(Promoter.uriFromString(smsStatusCallback)); } - /** - * Twilio will make a `POST` request to this URL to pass status parameters (such - * as sent or failed) to your application if you use the `/Messages` endpoint to - * send the message and specify this application's `Sid` as the `ApplicationSid` - * on an [outgoing SMS request](https://www.twilio.com/docs/sms/send-messages).. - * - * @param messageStatusCallback URL to make requests to with status updates - * @return this - */ - public ApplicationCreator setMessageStatusCallback(final URI messageStatusCallback) { + public ApplicationCreator setMessageStatusCallback( + final URI messageStatusCallback + ) { this.messageStatusCallback = messageStatusCallback; return this; } - /** - * Twilio will make a `POST` request to this URL to pass status parameters (such - * as sent or failed) to your application if you use the `/Messages` endpoint to - * send the message and specify this application's `Sid` as the `ApplicationSid` - * on an [outgoing SMS request](https://www.twilio.com/docs/sms/send-messages).. - * - * @param messageStatusCallback URL to make requests to with status updates - * @return this - */ - public ApplicationCreator setMessageStatusCallback(final String messageStatusCallback) { - return setMessageStatusCallback(Promoter.uriFromString(messageStatusCallback)); + public ApplicationCreator setMessageStatusCallback( + final String messageStatusCallback + ) { + return setMessageStatusCallback( + Promoter.uriFromString(messageStatusCallback) + ); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Application - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Application create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ApplicationCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ApplicationCreator setPublicApplicationConnectEnabled( + final Boolean publicApplicationConnectEnabled + ) { + this.publicApplicationConnectEnabled = publicApplicationConnectEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Applications.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Applications.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Application creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Application.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Application create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Application content = Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (apiVersion != null) { - request.addPostParam("ApiVersion", apiVersion); + Serializer.toString( + request, + "ApiVersion", + apiVersion, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); + Serializer.toString( + request, + "VoiceCallerIdLookup", + voiceCallerIdLookup, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (smsStatusCallback != null) { - request.addPostParam("SmsStatusCallback", smsStatusCallback.toString()); + Serializer.toString( + request, + "SmsStatusCallback", + smsStatusCallback, + ParameterType.URLENCODED + ); } if (messageStatusCallback != null) { - request.addPostParam("MessageStatusCallback", messageStatusCallback.toString()); + Serializer.toString( + request, + "MessageStatusCallback", + messageStatusCallback, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (publicApplicationConnectEnabled != null) { + Serializer.toString( + request, + "PublicApplicationConnectEnabled", + publicApplicationConnectEnabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationDeleter.java index 7714971cae..ee95efad24 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ApplicationDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new ApplicationDeleter. - * - * @param pathSid The application sid to delete - */ public ApplicationDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ApplicationDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid The application sid to delete - */ - public ApplicationDeleter(final String pathAccountSid, - final String pathSid) { + public ApplicationDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Applications/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Application delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationFetcher.java index e66877f7ad..6a55d5615c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ApplicationFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new ApplicationFetcher. - * - * @param pathSid Fetch by unique Application Sid - */ public ApplicationFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ApplicationFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique Application Sid - */ - public ApplicationFetcher(final String pathAccountSid, - final String pathSid) { + public ApplicationFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Application - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Application fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Applications/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Application fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Application.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Application fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Application content = Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationReader.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationReader.java index 9cd254cbe2..5e826da305 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,184 +17,216 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ApplicationReader extends Reader { + private String pathAccountSid; private String friendlyName; + private Long pageSize; - /** - * Construct a new ApplicationReader. - */ - public ApplicationReader() { - } + public ApplicationReader() {} - /** - * Construct a new ApplicationReader. - * - * @param pathAccountSid The account_sid - */ public ApplicationReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only return application resources with friendly names that match exactly with - * this name. - * - * @param friendlyName Filter by friendly name - * @return this - */ public ApplicationReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Application ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ApplicationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Application ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "applications", + response.getContent(), + Application.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Applications.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Applications.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Application ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "applications", + response.getContent(), + Application.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Application read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "applications", + response.getContent(), + Application.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Application Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Application read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "applications", - response.getContent(), - Application.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationUpdater.java index ea703664c0..54e1954ac5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ApplicationUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ApplicationUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class ApplicationUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private String friendlyName; private String apiVersion; private URI voiceUrl; @@ -38,395 +51,364 @@ public class ApplicationUpdater extends Updater { private HttpMethod smsFallbackMethod; private URI smsStatusCallback; private URI messageStatusCallback; + private Boolean publicApplicationConnectEnabled; - /** - * Construct a new ApplicationUpdater. - * - * @param pathSid The sid - */ public ApplicationUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ApplicationUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public ApplicationUpdater(final String pathAccountSid, - final String pathSid) { + public ApplicationUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * A human readable description of the application, with maximum length 64 - * characters.. - * - * @param friendlyName Human readable description of this resource - * @return this - */ public ApplicationUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Requests to this application's URLs will start a new TwiML session with this - * API version. Either `2010-04-01` or `2008-08-01`.. - * - * @param apiVersion The API version to use - * @return this - */ public ApplicationUpdater setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - /** - * The URL that Twilio should request when somebody dials a phone number - * assigned to this application.. - * - * @param voiceUrl URL Twilio will make requests to when relieving a call - * @return this - */ public ApplicationUpdater setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The URL that Twilio should request when somebody dials a phone number - * assigned to this application.. - * - * @param voiceUrl URL Twilio will make requests to when relieving a call - * @return this - */ public ApplicationUpdater setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The HTTP method Twilio will use when requesting the above `Url`. Either `GET` - * or `POST`.. - * - * @param voiceMethod HTTP method to use with the URL - * @return this - */ public ApplicationUpdater setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `VoiceUrl`.. - * - * @param voiceFallbackUrl Fallback URL - * @return this - */ public ApplicationUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `VoiceUrl`.. - * - * @param voiceFallbackUrl Fallback URL - * @return this - */ - public ApplicationUpdater setVoiceFallbackUrl(final String voiceFallbackUrl) { + public ApplicationUpdater setVoiceFallbackUrl( + final String voiceFallbackUrl + ) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method Twilio will use when requesting the `VoiceFallbackUrl`. - * Either `GET` or `POST`.. - * - * @param voiceFallbackMethod HTTP method to use with the fallback url - * @return this - */ - public ApplicationUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public ApplicationUpdater setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback URL to hit with status updates - * @return this - */ public ApplicationUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback URL to hit with status updates - * @return this - */ public ApplicationUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio will use to make requests to the `StatusCallback` URL. - * Either `GET` or `POST`.. - * - * @param statusCallbackMethod HTTP method to use with the status callback - * @return this - */ - public ApplicationUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public ApplicationUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * Look up the caller's caller-ID name from the CNAM database (additional - * charges apply). Either `true` or `false`.. - * - * @param voiceCallerIdLookup True or False - * @return this - */ - public ApplicationUpdater setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup) { + public ApplicationUpdater setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - /** - * The URL Twilio will request when a phone number assigned to this application - * receives an incoming SMS message.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public ApplicationUpdater setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL Twilio will request when a phone number assigned to this application - * receives an incoming SMS message.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public ApplicationUpdater setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The HTTP method Twilio will use when making requests to the `SmsUrl`. Either - * `GET` or `POST`.. - * - * @param smsMethod HTTP method to use with sms_url - * @return this - */ public ApplicationUpdater setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl Fallback URL if there's an error parsing TwiML - * @return this - */ public ApplicationUpdater setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl Fallback URL if there's an error parsing TwiML - * @return this - */ public ApplicationUpdater setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method that should be used to request the `SmsFallbackUrl`. Either - * `GET` or `POST`.. - * - * @param smsFallbackMethod HTTP method to use with sms_fallback_method - * @return this - */ - public ApplicationUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public ApplicationUpdater setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * The URL that Twilio will `POST` to when a message is sent via the - * `/SMS/Messages` endpoint if you specify the `Sid` of this application on an - * [outgoing SMS request](https://www.twilio.com/docs/sms/send-messages).. - * - * @param smsStatusCallback URL Twilio with request with status updates - * @return this - */ - public ApplicationUpdater setSmsStatusCallback(final URI smsStatusCallback) { + public ApplicationUpdater setSmsStatusCallback( + final URI smsStatusCallback + ) { this.smsStatusCallback = smsStatusCallback; return this; } - /** - * The URL that Twilio will `POST` to when a message is sent via the - * `/SMS/Messages` endpoint if you specify the `Sid` of this application on an - * [outgoing SMS request](https://www.twilio.com/docs/sms/send-messages).. - * - * @param smsStatusCallback URL Twilio with request with status updates - * @return this - */ - public ApplicationUpdater setSmsStatusCallback(final String smsStatusCallback) { + public ApplicationUpdater setSmsStatusCallback( + final String smsStatusCallback + ) { return setSmsStatusCallback(Promoter.uriFromString(smsStatusCallback)); } - /** - * Twilio will make a `POST` request to this URL to pass status parameters (such - * as sent or failed) to your application if you use the `/Messages` endpoint to - * send the message and specify this application's `Sid` as the `ApplicationSid` - * on an [outgoing SMS request](https://www.twilio.com/docs/sms/send-messages).. - * - * @param messageStatusCallback URL to make requests to with status updates - * @return this - */ - public ApplicationUpdater setMessageStatusCallback(final URI messageStatusCallback) { + public ApplicationUpdater setMessageStatusCallback( + final URI messageStatusCallback + ) { this.messageStatusCallback = messageStatusCallback; return this; } - /** - * Twilio will make a `POST` request to this URL to pass status parameters (such - * as sent or failed) to your application if you use the `/Messages` endpoint to - * send the message and specify this application's `Sid` as the `ApplicationSid` - * on an [outgoing SMS request](https://www.twilio.com/docs/sms/send-messages).. - * - * @param messageStatusCallback URL to make requests to with status updates - * @return this - */ - public ApplicationUpdater setMessageStatusCallback(final String messageStatusCallback) { - return setMessageStatusCallback(Promoter.uriFromString(messageStatusCallback)); + public ApplicationUpdater setMessageStatusCallback( + final String messageStatusCallback + ) { + return setMessageStatusCallback( + Promoter.uriFromString(messageStatusCallback) + ); } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Application - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Application update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ApplicationUpdater setPublicApplicationConnectEnabled( + final Boolean publicApplicationConnectEnabled + ) { + this.publicApplicationConnectEnabled = publicApplicationConnectEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Applications/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Applications/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Application update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Application update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Application.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Application update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Application content = Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (apiVersion != null) { - request.addPostParam("ApiVersion", apiVersion); + Serializer.toString( + request, + "ApiVersion", + apiVersion, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); + Serializer.toString( + request, + "VoiceCallerIdLookup", + voiceCallerIdLookup, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (smsStatusCallback != null) { - request.addPostParam("SmsStatusCallback", smsStatusCallback.toString()); + Serializer.toString( + request, + "SmsStatusCallback", + smsStatusCallback, + ParameterType.URLENCODED + ); } if (messageStatusCallback != null) { - request.addPostParam("MessageStatusCallback", messageStatusCallback.toString()); + Serializer.toString( + request, + "MessageStatusCallback", + messageStatusCallback, + ParameterType.URLENCODED + ); + } + + if (publicApplicationConnectEnabled != null) { + Serializer.toString( + request, + "PublicApplicationConnectEnabled", + publicApplicationConnectEnabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectApp.java b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectApp.java index 1aa3cc52fd..51db2fc032 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectApp.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectApp.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,33 +17,56 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AuthorizedConnectApp extends Resource { - private static final long serialVersionUID = 67218777245125L; + + public static AuthorizedConnectAppFetcher fetcher( + final String pathConnectAppSid + ) { + return new AuthorizedConnectAppFetcher(pathConnectAppSid); + } + + public static AuthorizedConnectAppFetcher fetcher( + final String pathAccountSid, + final String pathConnectAppSid + ) { + return new AuthorizedConnectAppFetcher( + pathAccountSid, + pathConnectAppSid + ); + } + + public static AuthorizedConnectAppReader reader() { + return new AuthorizedConnectAppReader(); + } + + public static AuthorizedConnectAppReader reader( + final String pathAccountSid + ) { + return new AuthorizedConnectAppReader(pathAccountSid); + } public enum Permission { GET_ALL("get-all"), @@ -48,71 +78,54 @@ private Permission(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Permission from a string. - * @param value string value - * @return generated Permission - */ @JsonCreator public static Permission forValue(final String value) { return Promoter.enumFromString(value, Permission.values()); } } - /** - * Create a AuthorizedConnectAppFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathConnectAppSid The connect_app_sid - * @return AuthorizedConnectAppFetcher capable of executing the fetch - */ - public static AuthorizedConnectAppFetcher fetcher(final String pathAccountSid, - final String pathConnectAppSid) { - return new AuthorizedConnectAppFetcher(pathAccountSid, pathConnectAppSid); - } + public enum AuthorizedConnectAppPermission { + GET_ALL("get-all"), + POST_ALL("post-all"); - /** - * Create a AuthorizedConnectAppFetcher to execute fetch. - * - * @param pathConnectAppSid The connect_app_sid - * @return AuthorizedConnectAppFetcher capable of executing the fetch - */ - public static AuthorizedConnectAppFetcher fetcher(final String pathConnectAppSid) { - return new AuthorizedConnectAppFetcher(pathConnectAppSid); - } + private final String value; - /** - * Create a AuthorizedConnectAppReader to execute read. - * - * @param pathAccountSid The account_sid - * @return AuthorizedConnectAppReader capable of executing the read - */ - public static AuthorizedConnectAppReader reader(final String pathAccountSid) { - return new AuthorizedConnectAppReader(pathAccountSid); - } + private AuthorizedConnectAppPermission(final String value) { + this.value = value; + } - /** - * Create a AuthorizedConnectAppReader to execute read. - * - * @return AuthorizedConnectAppReader capable of executing the read - */ - public static AuthorizedConnectAppReader reader() { - return new AuthorizedConnectAppReader(); + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static AuthorizedConnectAppPermission forValue( + final String value + ) { + return Promoter.enumFromString( + value, + AuthorizedConnectAppPermission.values() + ); + } } /** - * Converts a JSON String into a AuthorizedConnectApp object using the provided - * ObjectMapper. - * + * Converts a JSON String into a AuthorizedConnectApp object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AuthorizedConnectApp object represented by the provided JSON */ - public static AuthorizedConnectApp fromJson(final String json, final ObjectMapper objectMapper) { + public static AuthorizedConnectApp fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizedConnectApp.class); @@ -124,14 +137,17 @@ public static AuthorizedConnectApp fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a AuthorizedConnectApp object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a AuthorizedConnectApp object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AuthorizedConnectApp object represented by the provided JSON */ - public static AuthorizedConnectApp fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AuthorizedConnectApp fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizedConnectApp.class); @@ -142,140 +158,73 @@ public static AuthorizedConnectApp fromJson(final InputStream json, final Object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String connectAppCompanyName; + + @Getter private final String connectAppDescription; + + @Getter private final String connectAppFriendlyName; + + @Getter private final URI connectAppHomepageUrl; + + @Getter private final String connectAppSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final List permissions; + + @Getter private final String uri; @JsonCreator - private AuthorizedConnectApp(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("connect_app_company_name") - final String connectAppCompanyName, - @JsonProperty("connect_app_description") - final String connectAppDescription, - @JsonProperty("connect_app_friendly_name") - final String connectAppFriendlyName, - @JsonProperty("connect_app_homepage_url") - final URI connectAppHomepageUrl, - @JsonProperty("connect_app_sid") - final String connectAppSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("permissions") - final List permissions, - @JsonProperty("uri") - final String uri) { + private AuthorizedConnectApp( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "connect_app_company_name" + ) final String connectAppCompanyName, + @JsonProperty( + "connect_app_description" + ) final String connectAppDescription, + @JsonProperty( + "connect_app_friendly_name" + ) final String connectAppFriendlyName, + @JsonProperty( + "connect_app_homepage_url" + ) final URI connectAppHomepageUrl, + @JsonProperty("connect_app_sid") final String connectAppSid, + @JsonProperty("permissions") final List< + AuthorizedConnectApp.Permission + > permissions, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.connectAppCompanyName = connectAppCompanyName; this.connectAppDescription = connectAppDescription; this.connectAppFriendlyName = connectAppFriendlyName; this.connectAppHomepageUrl = connectAppHomepageUrl; this.connectAppSid = connectAppSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); this.permissions = permissions; this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The company name set for this Connect App.. - * - * @return The company name set for this Connect App. - */ - public final String getConnectAppCompanyName() { - return this.connectAppCompanyName; - } - - /** - * Returns The Human readable description of the app. - * - * @return Human readable description of the app - */ - public final String getConnectAppDescription() { - return this.connectAppDescription; - } - - /** - * Returns The A human readable name for the Connect App.. - * - * @return A human readable name for the Connect App. - */ - public final String getConnectAppFriendlyName() { - return this.connectAppFriendlyName; - } - - /** - * Returns The The public URL for this Connect App.. - * - * @return The public URL for this Connect App. - */ - public final URI getConnectAppHomepageUrl() { - return this.connectAppHomepageUrl; - } - - /** - * Returns The A string that uniquely identifies this app. - * - * @return A string that uniquely identifies this app - */ - public final String getConnectAppSid() { - return this.connectAppSid; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Permissions authorized to this app. - * - * @return Permissions authorized to this app - */ - public final List getPermissions() { - return this.permissions; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -287,46 +236,41 @@ public boolean equals(final Object o) { } AuthorizedConnectApp other = (AuthorizedConnectApp) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(connectAppCompanyName, other.connectAppCompanyName) && - Objects.equals(connectAppDescription, other.connectAppDescription) && - Objects.equals(connectAppFriendlyName, other.connectAppFriendlyName) && - Objects.equals(connectAppHomepageUrl, other.connectAppHomepageUrl) && - Objects.equals(connectAppSid, other.connectAppSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(permissions, other.permissions) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + connectAppCompanyName, + other.connectAppCompanyName + ) && + Objects.equals( + connectAppDescription, + other.connectAppDescription + ) && + Objects.equals( + connectAppFriendlyName, + other.connectAppFriendlyName + ) && + Objects.equals( + connectAppHomepageUrl, + other.connectAppHomepageUrl + ) && + Objects.equals(connectAppSid, other.connectAppSid) && + Objects.equals(permissions, other.permissions) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - connectAppCompanyName, - connectAppDescription, - connectAppFriendlyName, - connectAppHomepageUrl, - connectAppSid, - dateCreated, - dateUpdated, - permissions, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("connectAppCompanyName", connectAppCompanyName) - .add("connectAppDescription", connectAppDescription) - .add("connectAppFriendlyName", connectAppFriendlyName) - .add("connectAppHomepageUrl", connectAppHomepageUrl) - .add("connectAppSid", connectAppSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("permissions", permissions) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + connectAppCompanyName, + connectAppDescription, + connectAppFriendlyName, + connectAppHomepageUrl, + connectAppSid, + permissions, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppFetcher.java index 141ff59778..6c7be1f852 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,96 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AuthorizedConnectAppFetcher extends Fetcher { + private String pathAccountSid; - private final String pathConnectAppSid; + private String pathConnectAppSid; - /** - * Construct a new AuthorizedConnectAppFetcher. - * - * @param pathConnectAppSid The connect_app_sid - */ public AuthorizedConnectAppFetcher(final String pathConnectAppSid) { this.pathConnectAppSid = pathConnectAppSid; } - /** - * Construct a new AuthorizedConnectAppFetcher. - * - * @param pathAccountSid The account_sid - * @param pathConnectAppSid The connect_app_sid - */ - public AuthorizedConnectAppFetcher(final String pathAccountSid, - final String pathConnectAppSid) { + public AuthorizedConnectAppFetcher( + final String pathAccountSid, + final String pathConnectAppSid + ) { this.pathAccountSid = pathAccountSid; this.pathConnectAppSid = pathConnectAppSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AuthorizedConnectApp - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AuthorizedConnectApp fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps/{ConnectAppSid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConnectAppSid" + "}", + this.pathConnectAppSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AuthorizedConnectApps/" + this.pathConnectAppSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizedConnectApp fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AuthorizedConnectApp fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public AuthorizedConnectApp fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AuthorizedConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return AuthorizedConnectApp.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthorizedConnectApp content = AuthorizedConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppReader.java b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppReader.java index fb9464eb00..25e51edeb4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AuthorizedConnectAppReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,167 +17,204 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AuthorizedConnectAppReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new AuthorizedConnectAppReader. - */ - public AuthorizedConnectAppReader() { - } + public AuthorizedConnectAppReader() {} - /** - * Construct a new AuthorizedConnectAppReader. - * - * @param pathAccountSid The account_sid - */ public AuthorizedConnectAppReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AuthorizedConnectApp ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AuthorizedConnectAppReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AuthorizedConnectApp ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "authorized_connect_apps", + response.getContent(), + AuthorizedConnectApp.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AuthorizedConnectApps.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AuthorizedConnectApps.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AuthorizedConnectApp ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "authorized_connect_apps", + response.getContent(), + AuthorizedConnectApp.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AuthorizedConnectApp read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "authorized_connect_apps", + response.getContent(), + AuthorizedConnectApp.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AuthorizedConnectApp Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AuthorizedConnectApp read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "authorized_connect_apps", - response.getContent(), - AuthorizedConnectApp.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountry.java b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountry.java index 0c4dce1d82..c89e4a31c0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountry.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountry.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,83 +18,71 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AvailablePhoneNumberCountry extends Resource { - private static final long serialVersionUID = 118317602820324L; - /** - * Create a AvailablePhoneNumberCountryReader to execute read. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @return AvailablePhoneNumberCountryReader capable of executing the read - */ - public static AvailablePhoneNumberCountryReader reader(final String pathAccountSid) { - return new AvailablePhoneNumberCountryReader(pathAccountSid); + public static AvailablePhoneNumberCountryFetcher fetcher( + final String pathCountryCode + ) { + return new AvailablePhoneNumberCountryFetcher(pathCountryCode); } - /** - * Create a AvailablePhoneNumberCountryReader to execute read. - * - * @return AvailablePhoneNumberCountryReader capable of executing the read - */ - public static AvailablePhoneNumberCountryReader reader() { - return new AvailablePhoneNumberCountryReader(); + public static AvailablePhoneNumberCountryFetcher fetcher( + final String pathAccountSid, + final String pathCountryCode + ) { + return new AvailablePhoneNumberCountryFetcher( + pathAccountSid, + pathCountryCode + ); } - /** - * Create a AvailablePhoneNumberCountryFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathCountryCode The country_code - * @return AvailablePhoneNumberCountryFetcher capable of executing the fetch - */ - public static AvailablePhoneNumberCountryFetcher fetcher(final String pathAccountSid, - final String pathCountryCode) { - return new AvailablePhoneNumberCountryFetcher(pathAccountSid, pathCountryCode); + public static AvailablePhoneNumberCountryReader reader() { + return new AvailablePhoneNumberCountryReader(); } - /** - * Create a AvailablePhoneNumberCountryFetcher to execute fetch. - * - * @param pathCountryCode The country_code - * @return AvailablePhoneNumberCountryFetcher capable of executing the fetch - */ - public static AvailablePhoneNumberCountryFetcher fetcher(final String pathCountryCode) { - return new AvailablePhoneNumberCountryFetcher(pathCountryCode); + public static AvailablePhoneNumberCountryReader reader( + final String pathAccountSid + ) { + return new AvailablePhoneNumberCountryReader(pathAccountSid); } /** - * Converts a JSON String into a AvailablePhoneNumberCountry object using the - * provided ObjectMapper. - * + * Converts a JSON String into a AvailablePhoneNumberCountry object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AvailablePhoneNumberCountry object represented by the provided JSON */ - public static AvailablePhoneNumberCountry fromJson(final String json, final ObjectMapper objectMapper) { + public static AvailablePhoneNumberCountry fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AvailablePhoneNumberCountry.class); + return objectMapper.readValue( + json, + AvailablePhoneNumberCountry.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -96,17 +91,23 @@ public static AvailablePhoneNumberCountry fromJson(final String json, final Obje } /** - * Converts a JSON InputStream into a AvailablePhoneNumberCountry object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a AvailablePhoneNumberCountry object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AvailablePhoneNumberCountry object represented by the provided JSON */ - public static AvailablePhoneNumberCountry fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AvailablePhoneNumberCountry fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, AvailablePhoneNumberCountry.class); + return objectMapper.readValue( + json, + AvailablePhoneNumberCountry.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -114,73 +115,49 @@ public static AvailablePhoneNumberCountry fromJson(final InputStream json, final } } - private final String countryCode; - private final String country; - private final URI uri; - private final Boolean beta; - private final Map subresourceUris; - - @JsonCreator - private AvailablePhoneNumberCountry(@JsonProperty("country_code") - final String countryCode, - @JsonProperty("country") - final String country, - @JsonProperty("uri") - final URI uri, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("subresource_uris") - final Map subresourceUris) { - this.countryCode = countryCode; - this.country = country; - this.uri = uri; - this.beta = beta; - this.subresourceUris = subresourceUris; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The ISO Country code to lookup phone numbers for.. - * - * @return The ISO Country code to lookup phone numbers for. - */ - public final String getCountryCode() { - return this.countryCode; - } + @Getter + private final Boolean beta; - /** - * Returns The The country. - * - * @return The country - */ - public final String getCountry() { - return this.country; - } + @Getter + private final String country; - /** - * Returns The The uri. - * - * @return The uri - */ - public final URI getUri() { - return this.uri; - } + @Getter + private final String countryCode; - /** - * Returns The True if new to Twilio platform.. - * - * @return True if new to Twilio platform. - */ - public final Boolean getBeta() { - return this.beta; - } + @Getter + private final Map subresourceUris; - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; + @Getter + private final URI uri; + + @JsonCreator + private AvailablePhoneNumberCountry( + @JsonProperty("beta") final Boolean beta, + @JsonProperty("country") final String country, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final URI uri + ) { + this.beta = beta; + this.country = country; + this.countryCode = countryCode; + this.subresourceUris = subresourceUris; + this.uri = uri; } @Override @@ -194,31 +171,17 @@ public boolean equals(final Object o) { } AvailablePhoneNumberCountry other = (AvailablePhoneNumberCountry) o; - - return Objects.equals(countryCode, other.countryCode) && - Objects.equals(country, other.country) && - Objects.equals(uri, other.uri) && - Objects.equals(beta, other.beta) && - Objects.equals(subresourceUris, other.subresourceUris); + return ( + Objects.equals(beta, other.beta) && + Objects.equals(country, other.country) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(countryCode, - country, - uri, - beta, - subresourceUris); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("countryCode", countryCode) - .add("country", country) - .add("uri", uri) - .add("beta", beta) - .add("subresourceUris", subresourceUris) - .toString(); + return Objects.hash(beta, country, countryCode, subresourceUris, uri); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryFetcher.java index 3d4f964067..9fe20484e1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,98 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AvailablePhoneNumberCountryFetcher + extends Fetcher { -public class AvailablePhoneNumberCountryFetcher extends Fetcher { private String pathAccountSid; - private final String pathCountryCode; + private String pathCountryCode; - /** - * Construct a new AvailablePhoneNumberCountryFetcher. - * - * @param pathCountryCode The country_code - */ public AvailablePhoneNumberCountryFetcher(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - /** - * Construct a new AvailablePhoneNumberCountryFetcher. - * - * @param pathAccountSid The account_sid - * @param pathCountryCode The country_code - */ - public AvailablePhoneNumberCountryFetcher(final String pathAccountSid, - final String pathCountryCode) { + public AvailablePhoneNumberCountryFetcher( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AvailablePhoneNumberCountry - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AvailablePhoneNumberCountry fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers/" + this.pathCountryCode + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailablePhoneNumberCountry fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AvailablePhoneNumberCountry fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public AvailablePhoneNumberCountry fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AvailablePhoneNumberCountry.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return AvailablePhoneNumberCountry.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AvailablePhoneNumberCountry content = + AvailablePhoneNumberCountry.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryReader.java b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryReader.java index 7d2352ed4a..3be6a31e78 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/AvailablePhoneNumberCountryReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,168 +17,204 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AvailablePhoneNumberCountryReader + extends Reader { -public class AvailablePhoneNumberCountryReader extends Reader { private String pathAccountSid; + private Long pageSize; - /** - * Construct a new AvailablePhoneNumberCountryReader. - */ - public AvailablePhoneNumberCountryReader() { - } + public AvailablePhoneNumberCountryReader() {} - /** - * Construct a new AvailablePhoneNumberCountryReader. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - */ public AvailablePhoneNumberCountryReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AvailablePhoneNumberCountry ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AvailablePhoneNumberCountryReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AvailablePhoneNumberCountry ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + AvailablePhoneNumberCountry.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AvailablePhoneNumberCountry ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + AvailablePhoneNumberCountry.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AvailablePhoneNumberCountry read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "countries", + response.getContent(), + AvailablePhoneNumberCountry.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AvailablePhoneNumberCountry Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AvailablePhoneNumberCountry read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "countries", - response.getContent(), - AvailablePhoneNumberCountry.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Balance.java b/src/main/java/com/twilio/rest/api/v2010/account/Balance.java new file mode 100644 index 0000000000..5589ec5de9 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/Balance.java @@ -0,0 +1,146 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Balance extends Resource { + + public static BalanceFetcher fetcher() { + return new BalanceFetcher(); + } + + public static BalanceFetcher fetcher(final String pathAccountSid) { + return new BalanceFetcher(pathAccountSid); + } + + /** + * Converts a JSON String into a Balance object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Balance object represented by the provided JSON + */ + public static Balance fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Balance.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Balance object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Balance object represented by the provided JSON + */ + public static Balance fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Balance.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String balance; + + @Getter + private final String currency; + + @JsonCreator + private Balance( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("balance") final String balance, + @JsonProperty("currency") final String currency + ) { + this.accountSid = accountSid; + this.balance = balance; + this.currency = currency; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Balance other = (Balance) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(balance, other.balance) && + Objects.equals(currency, other.currency) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, balance, currency); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/BalanceFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/BalanceFetcher.java new file mode 100644 index 0000000000..44f4f4ffdf --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/BalanceFetcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BalanceFetcher extends Fetcher { + + private String pathAccountSid; + + public BalanceFetcher() {} + + public BalanceFetcher(final String pathAccountSid) { + this.pathAccountSid = pathAccountSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Balance.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Balance fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Balance fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Balance.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Balance content = Balance.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Call.java b/src/main/java/com/twilio/rest/api/v2010/account/Call.java index 57601ce83a..a41339d47a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Call.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Call.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,62 +17,124 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import com.twilio.type.Endpoint; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.math.BigDecimal; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Call extends Resource { - private static final long serialVersionUID = 194998930798610L; - public enum Event { - INITIATED("initiated"), - RINGING("ringing"), - ANSWERED("answered"), - COMPLETED("completed"); + public static CallCreator creator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final URI url + ) { + return new CallCreator(to, from, url); + } - private final String value; + public static CallCreator creator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final URI url + ) { + return new CallCreator(pathAccountSid, to, from, url); + } - private Event(final String value) { - this.value = value; - } + public static CallCreator creator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final com.twilio.type.Twiml twiml + ) { + return new CallCreator(to, from, twiml); + } - public String toString() { - return value; - } + public static CallCreator creator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final com.twilio.type.Twiml twiml + ) { + return new CallCreator(pathAccountSid, to, from, twiml); + } - /** - * Generate a Event from a string. - * @param value string value - * @return generated Event - */ - @JsonCreator - public static Event forValue(final String value) { - return Promoter.enumFromString(value, Event.values()); - } + public static CallCreator creator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final String applicationSid + ) { + return new CallCreator(to, from, applicationSid); + } + + public static CallCreator creator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final String applicationSid + ) { + return new CallCreator(pathAccountSid, to, from, applicationSid); + } + + public static CallDeleter deleter(final String pathSid) { + return new CallDeleter(pathSid); + } + + public static CallDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new CallDeleter(pathAccountSid, pathSid); + } + + public static CallFetcher fetcher(final String pathSid) { + return new CallFetcher(pathSid); + } + + public static CallFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new CallFetcher(pathAccountSid, pathSid); + } + + public static CallReader reader() { + return new CallReader(); + } + + public static CallReader reader(final String pathAccountSid) { + return new CallReader(pathAccountSid); + } + + public static CallUpdater updater(final String pathSid) { + return new CallUpdater(pathSid); + } + + public static CallUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new CallUpdater(pathAccountSid, pathSid); } public enum Status { @@ -84,15 +153,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -109,176 +174,28 @@ private UpdateStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a UpdateStatus from a string. - * @param value string value - * @return generated UpdateStatus - */ @JsonCreator public static UpdateStatus forValue(final String value) { return Promoter.enumFromString(value, UpdateStatus.values()); } } - /** - * Create a CallCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param to Phone number, SIP address, or client identifier to call - * @param from Twilio number from which to originate the call - * @param url Url from which to fetch TwiML - * @return CallCreator capable of executing the create - */ - public static CallCreator creator(final String pathAccountSid, - final com.twilio.type.Endpoint to, - final com.twilio.type.PhoneNumber from, - final URI url) { - return new CallCreator(pathAccountSid, to, from, url); - } - - /** - * Create a CallCreator to execute create. - * - * @param to Phone number, SIP address, or client identifier to call - * @param from Twilio number from which to originate the call - * @param url Url from which to fetch TwiML - * @return CallCreator capable of executing the create - */ - public static CallCreator creator(final com.twilio.type.Endpoint to, - final com.twilio.type.PhoneNumber from, - final URI url) { - return new CallCreator(to, from, url); - } - - /** - * Create a CallCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param to Phone number, SIP address, or client identifier to call - * @param from Twilio number from which to originate the call - * @param applicationSid ApplicationSid that configures from where to fetch - * TwiML - * @return CallCreator capable of executing the create - */ - public static CallCreator creator(final String pathAccountSid, - final com.twilio.type.Endpoint to, - final com.twilio.type.PhoneNumber from, - final String applicationSid) { - return new CallCreator(pathAccountSid, to, from, applicationSid); - } - - /** - * Create a CallCreator to execute create. - * - * @param to Phone number, SIP address, or client identifier to call - * @param from Twilio number from which to originate the call - * @param applicationSid ApplicationSid that configures from where to fetch - * TwiML - * @return CallCreator capable of executing the create - */ - public static CallCreator creator(final com.twilio.type.Endpoint to, - final com.twilio.type.PhoneNumber from, - final String applicationSid) { - return new CallCreator(to, from, applicationSid); - } - - /** - * Create a CallDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Call Sid that uniquely identifies the Call to delete - * @return CallDeleter capable of executing the delete - */ - public static CallDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new CallDeleter(pathAccountSid, pathSid); - } - - /** - * Create a CallDeleter to execute delete. - * - * @param pathSid Call Sid that uniquely identifies the Call to delete - * @return CallDeleter capable of executing the delete - */ - public static CallDeleter deleter(final String pathSid) { - return new CallDeleter(pathSid); - } - - /** - * Create a CallFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Call Sid that uniquely identifies the Call to fetch - * @return CallFetcher capable of executing the fetch - */ - public static CallFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new CallFetcher(pathAccountSid, pathSid); - } - - /** - * Create a CallFetcher to execute fetch. - * - * @param pathSid Call Sid that uniquely identifies the Call to fetch - * @return CallFetcher capable of executing the fetch - */ - public static CallFetcher fetcher(final String pathSid) { - return new CallFetcher(pathSid); - } - - /** - * Create a CallReader to execute read. - * - * @param pathAccountSid The account_sid - * @return CallReader capable of executing the read - */ - public static CallReader reader(final String pathAccountSid) { - return new CallReader(pathAccountSid); - } - - /** - * Create a CallReader to execute read. - * - * @return CallReader capable of executing the read - */ - public static CallReader reader() { - return new CallReader(); - } - - /** - * Create a CallUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid Call Sid that uniquely identifies the Call to update - * @return CallUpdater capable of executing the update - */ - public static CallUpdater updater(final String pathAccountSid, - final String pathSid) { - return new CallUpdater(pathAccountSid, pathSid); - } - - /** - * Create a CallUpdater to execute update. - * - * @param pathSid Call Sid that uniquely identifies the Call to update - * @return CallUpdater capable of executing the update - */ - public static CallUpdater updater(final String pathSid) { - return new CallUpdater(pathSid); - } - /** * Converts a JSON String into a Call object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Call object represented by the provided JSON */ - public static Call fromJson(final String json, final ObjectMapper objectMapper) { + public static Call fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Call.class); @@ -292,12 +209,15 @@ public static Call fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Call object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Call object represented by the provided JSON */ - public static Call fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Call fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Call.class); @@ -308,94 +228,151 @@ public static Call fromJson(final InputStream json, final ObjectMapper objectMap } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String annotation; + + @Getter private final String answeredBy; + + @Getter private final String apiVersion; + + @Getter private final String callerName; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String direction; + + @Getter private final String duration; - private final DateTime endTime; + + @Getter + private final ZonedDateTime endTime; + + @Getter private final String forwardedFrom; + + @Getter private final String from; + + @Getter private final String fromFormatted; + + @Getter private final String groupSid; + + @Getter private final String parentCallSid; + + @Getter private final String phoneNumberSid; - private final BigDecimal price; + + @Getter + private final String price; + + @Getter private final Currency priceUnit; + + @Getter + private final String queueTime; + + @Getter private final String sid; - private final DateTime startTime; + + @Getter + private final ZonedDateTime startTime; + + @Getter private final Call.Status status; + + @Getter + private final String stirVerstat; + + @Getter private final Map subresourceUris; + + @Getter private final String to; + + @Getter private final String toFormatted; + + @Getter + private final String trunkSid; + + @Getter private final String uri; @JsonCreator - private Call(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("annotation") - final String annotation, - @JsonProperty("answered_by") - final String answeredBy, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("caller_name") - final String callerName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("direction") - final String direction, - @JsonProperty("duration") - final String duration, - @JsonProperty("end_time") - final String endTime, - @JsonProperty("forwarded_from") - final String forwardedFrom, - @JsonProperty("from") - final String from, - @JsonProperty("from_formatted") - final String fromFormatted, - @JsonProperty("group_sid") - final String groupSid, - @JsonProperty("parent_call_sid") - final String parentCallSid, - @JsonProperty("phone_number_sid") - final String phoneNumberSid, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("sid") - final String sid, - @JsonProperty("start_time") - final String startTime, - @JsonProperty("status") - final Call.Status status, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("to") - final String to, - @JsonProperty("to_formatted") - final String toFormatted, - @JsonProperty("uri") - final String uri) { + private Call( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("answered_by") final String answeredBy, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("caller_name") final String callerName, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("direction") final String direction, + @JsonProperty("duration") final String duration, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime endTime, + @JsonProperty("forwarded_from") final String forwardedFrom, + @JsonProperty("from") final String from, + @JsonProperty("from_formatted") final String fromFormatted, + @JsonProperty("group_sid") final String groupSid, + @JsonProperty("parent_call_sid") final String parentCallSid, + @JsonProperty("phone_number_sid") final String phoneNumberSid, + @JsonProperty("price") final String price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("queue_time") final String queueTime, + @JsonProperty("sid") final String sid, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime startTime, + @JsonProperty("status") final Call.Status status, + @JsonProperty("stir_verstat") final String stirVerstat, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("to") final String to, + @JsonProperty("to_formatted") final String toFormatted, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; - this.annotation = annotation; this.answeredBy = answeredBy; this.apiVersion = apiVersion; this.callerName = callerName; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.direction = direction; this.duration = duration; - this.endTime = DateConverter.rfc2822DateTimeFromString(endTime); + this.endTime = endTime; this.forwardedFrom = forwardedFrom; this.from = from; this.fromFormatted = fromFormatted; @@ -404,285 +381,18 @@ private Call(@JsonProperty("account_sid") this.phoneNumberSid = phoneNumberSid; this.price = price; this.priceUnit = priceUnit; + this.queueTime = queueTime; this.sid = sid; - this.startTime = DateConverter.rfc2822DateTimeFromString(startTime); + this.startTime = startTime; this.status = status; + this.stirVerstat = stirVerstat; this.subresourceUris = subresourceUris; this.to = to; this.toFormatted = toFormatted; + this.trunkSid = trunkSid; this.uri = uri; } - /** - * Returns The The unique id of the Account responsible for creating this Call. - * - * @return The unique id of the Account responsible for creating this Call - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The annotation provided for the Call. - * - * @return The annotation provided for the Call - */ - public final String getAnnotation() { - return this.annotation; - } - - /** - * Returns The Either `human` or `machine` if this Call was initiated with - * answering machine detection. Empty otherwise.. - * - * @return Either `human` or `machine` if this Call was initiated with - * answering machine detection. Empty otherwise. - */ - public final String getAnsweredBy() { - return this.answeredBy; - } - - /** - * Returns The The API Version used to create the Call. - * - * @return The API Version used to create the Call - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The caller's name if this Call was an incoming call to a phone - * number with Caller ID Lookup enabled. Empty otherwise.. - * - * @return The caller's name if this Call was an incoming call to a phone - * number with Caller ID Lookup enabled. Empty otherwise. - */ - public final String getCallerName() { - return this.callerName; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A string describing the direction of the Call. `inbound` for - * inbound calls, `outbound-api` for calls initiated via the REST API or - * `outbound-dial` for calls initiated by a `Dial` verb.. - * - * @return A string describing the direction of the Call. `inbound` for inbound - * calls, `outbound-api` for calls initiated via the REST API or - * `outbound-dial` for calls initiated by a `Dial` verb. - */ - public final String getDirection() { - return this.direction; - } - - /** - * Returns The The length of the Call in seconds.. - * - * @return The length of the Call in seconds. - */ - public final String getDuration() { - return this.duration; - } - - /** - * Returns The The end time of the Call. Null if the call did not complete - * successfully.. - * - * @return The end time of the Call. Null if the call did not complete - * successfully. - */ - public final DateTime getEndTime() { - return this.endTime; - } - - /** - * Returns The The forwarding phone number if this Call was an incoming call - * forwarded from another number (depends on carrier supporting forwarding). - * Empty otherwise.. - * - * @return The forwarding phone number if this Call was an incoming call - * forwarded from another number (depends on carrier supporting - * forwarding). Empty otherwise. - */ - public final String getForwardedFrom() { - return this.forwardedFrom; - } - - /** - * Returns The The phone number, SIP address or Client identifier that made this - * Call. Phone numbers are in E.164 format (e.g., +16175551212). SIP addresses - * are formatted as `name@company.com`. Client identifiers are formatted - * `client:name`.. - * - * @return The phone number, SIP address or Client identifier that made this - * Call. Phone numbers are in E.164 format (e.g., +16175551212). SIP - * addresses are formatted as `name@company.com`. Client identifiers are - * formatted `client:name`. - */ - public final String getFrom() { - return this.from; - } - - /** - * Returns The The phone number, SIP address or Client identifier that made this - * Call. Formatted for display.. - * - * @return The phone number, SIP address or Client identifier that made this - * Call. Formatted for display. - */ - public final String getFromFormatted() { - return this.fromFormatted; - } - - /** - * Returns The A 34-character Group Sid associated with this Call. Empty if no - * Group is associated with the Call.. - * - * @return A 34-character Group Sid associated with this Call. Empty if no - * Group is associated with the Call. - */ - public final String getGroupSid() { - return this.groupSid; - } - - /** - * Returns The A 34-character string that uniquely identifies the Call that - * created this leg.. - * - * @return A 34-character string that uniquely identifies the Call that created - * this leg. - */ - public final String getParentCallSid() { - return this.parentCallSid; - } - - /** - * Returns The If the call was inbound, this is the Sid of the - * `IncomingPhoneNumber` that received the call. If the call was outbound, it is - * the Sid of the `OutgoingCallerId` from which the call was placed.. - * - * @return If the call was inbound, this is the Sid of the - * `IncomingPhoneNumber` that received the call. If the call was - * outbound, it is the Sid of the `OutgoingCallerId` from which the call - * was placed. - */ - public final String getPhoneNumberSid() { - return this.phoneNumberSid; - } - - /** - * Returns The The charge for this Call, in the currency associated with the - * account. Populated after the call is completed. May not be immediately - * available.. - * - * @return The charge for this Call, in the currency associated with the - * account. Populated after the call is completed. May not be - * immediately available. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which `Price` is measured.. - * - * @return The currency in which `Price` is measured. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The A 34-character string that uniquely identifies the Call - * resource.. - * - * @return A 34-character string that uniquely identifies the Call resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The start time of the Call. Null if the call has not yet been - * dialed.. - * - * @return The start time of the Call. Null if the call has not yet been dialed. - */ - public final DateTime getStartTime() { - return this.startTime; - } - - /** - * Returns The A string representing the status of the Call.. - * - * @return A string representing the status of the Call. - */ - public final Call.Status getStatus() { - return this.status; - } - - /** - * Returns The Call Instance Subresources. - * - * @return Call Instance Subresources - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The phone number, SIP address or Client identifier that received - * this Call. Phone numbers are in E.164 format (e.g., +16175551212). SIP - * addresses are formatted as `name@company.com`. Client identifiers are - * formatted `client:name`.. - * - * @return The phone number, SIP address or Client identifier that received - * this Call. Phone numbers are in E.164 format (e.g., +16175551212). - * SIP addresses are formatted as `name@company.com`. Client identifiers - * are formatted `client:name`. - */ - public final String getTo() { - return this.to; - } - - /** - * Returns The The phone number, SIP address or Client identifier that received - * this Call. Formatted for display.. - * - * @return The phone number, SIP address or Client identifier that received - * this Call. Formatted for display. - */ - public final String getToFormatted() { - return this.toFormatted; - } - - /** - * Returns The The URI for this resource, relative to `https://api.twilio.com`. - * - * @return The URI for this resource, relative to `https://api.twilio.com` - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -694,91 +404,67 @@ public boolean equals(final Object o) { } Call other = (Call) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(annotation, other.annotation) && - Objects.equals(answeredBy, other.answeredBy) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(callerName, other.callerName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(direction, other.direction) && - Objects.equals(duration, other.duration) && - Objects.equals(endTime, other.endTime) && - Objects.equals(forwardedFrom, other.forwardedFrom) && - Objects.equals(from, other.from) && - Objects.equals(fromFormatted, other.fromFormatted) && - Objects.equals(groupSid, other.groupSid) && - Objects.equals(parentCallSid, other.parentCallSid) && - Objects.equals(phoneNumberSid, other.phoneNumberSid) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(sid, other.sid) && - Objects.equals(startTime, other.startTime) && - Objects.equals(status, other.status) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(to, other.to) && - Objects.equals(toFormatted, other.toFormatted) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(answeredBy, other.answeredBy) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callerName, other.callerName) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(direction, other.direction) && + Objects.equals(duration, other.duration) && + Objects.equals(endTime, other.endTime) && + Objects.equals(forwardedFrom, other.forwardedFrom) && + Objects.equals(from, other.from) && + Objects.equals(fromFormatted, other.fromFormatted) && + Objects.equals(groupSid, other.groupSid) && + Objects.equals(parentCallSid, other.parentCallSid) && + Objects.equals(phoneNumberSid, other.phoneNumberSid) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(queueTime, other.queueTime) && + Objects.equals(sid, other.sid) && + Objects.equals(startTime, other.startTime) && + Objects.equals(status, other.status) && + Objects.equals(stirVerstat, other.stirVerstat) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(to, other.to) && + Objects.equals(toFormatted, other.toFormatted) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - annotation, - answeredBy, - apiVersion, - callerName, - dateCreated, - dateUpdated, - direction, - duration, - endTime, - forwardedFrom, - from, - fromFormatted, - groupSid, - parentCallSid, - phoneNumberSid, - price, - priceUnit, - sid, - startTime, - status, - subresourceUris, - to, - toFormatted, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("annotation", annotation) - .add("answeredBy", answeredBy) - .add("apiVersion", apiVersion) - .add("callerName", callerName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("direction", direction) - .add("duration", duration) - .add("endTime", endTime) - .add("forwardedFrom", forwardedFrom) - .add("from", from) - .add("fromFormatted", fromFormatted) - .add("groupSid", groupSid) - .add("parentCallSid", parentCallSid) - .add("phoneNumberSid", phoneNumberSid) - .add("price", price) - .add("priceUnit", priceUnit) - .add("sid", sid) - .add("startTime", startTime) - .add("status", status) - .add("subresourceUris", subresourceUris) - .add("to", to) - .add("toFormatted", toFormatted) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + answeredBy, + apiVersion, + callerName, + dateCreated, + dateUpdated, + direction, + duration, + endTime, + forwardedFrom, + from, + fromFormatted, + groupSid, + parentCallSid, + phoneNumberSid, + price, + priceUnit, + queueTime, + sid, + startTime, + status, + stirVerstat, + subresourceUris, + to, + toFormatted, + trunkSid, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java index d3eb9fcd3d..6ef355b6ee 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,17 +28,16 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import com.twilio.type.Endpoint; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class CallCreator extends Creator { + private String pathAccountSid; - private final com.twilio.type.Endpoint to; - private final com.twilio.type.PhoneNumber from; - private URI url; - private String applicationSid; + private com.twilio.type.Endpoint to; + private com.twilio.type.Endpoint from; private HttpMethod method; private URI fallbackUrl; private HttpMethod fallbackMethod; @@ -35,12 +45,12 @@ public class CallCreator extends Creator { private List statusCallbackEvent; private HttpMethod statusCallbackMethod; private String sendDigits; - private String ifMachine; private Integer timeout; private Boolean record; private String recordingChannels; private String recordingStatusCallback; private HttpMethod recordingStatusCallbackMethod; + private String recordingConfigurationId; private String sipAuthUsername; private String sipAuthPassword; private String machineDetection; @@ -48,605 +58,753 @@ public class CallCreator extends Creator { private List recordingStatusCallbackEvent; private String trim; private String callerId; + private Integer machineDetectionSpeechThreshold; + private Integer machineDetectionSpeechEndThreshold; + private Integer machineDetectionSilenceTimeout; + private String asyncAmd; + private URI asyncAmdStatusCallback; + private HttpMethod asyncAmdStatusCallbackMethod; + private String passports; + private String byoc; + private String callReason; + private String callToken; + private String recordingTrack; + private Integer timeLimit; + private URI clientNotificationUrl; + private URI url; + private com.twilio.type.Twiml twiml; + private String applicationSid; - /** - * Construct a new CallCreator. - * - * @param to Phone number, SIP address, or client identifier to call - * @param from Twilio number from which to originate the call - * @param url Url from which to fetch TwiML - */ - public CallCreator(final com.twilio.type.Endpoint to, - final com.twilio.type.PhoneNumber from, - final URI url) { + public CallCreator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final URI url + ) { this.to = to; this.from = from; this.url = url; } - /** - * Construct a new CallCreator. - * - * @param pathAccountSid The account_sid - * @param to Phone number, SIP address, or client identifier to call - * @param from Twilio number from which to originate the call - * @param url Url from which to fetch TwiML - */ - public CallCreator(final String pathAccountSid, - final com.twilio.type.Endpoint to, - final com.twilio.type.PhoneNumber from, - final URI url) { + public CallCreator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final URI url + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.url = url; } - /** - * Construct a new CallCreator. - * - * @param to Phone number, SIP address, or client identifier to call - * @param from Twilio number from which to originate the call - * @param applicationSid ApplicationSid that configures from where to fetch - * TwiML - */ - public CallCreator(final com.twilio.type.Endpoint to, - final com.twilio.type.PhoneNumber from, - final String applicationSid) { + public CallCreator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final com.twilio.type.Twiml twiml + ) { + this.to = to; + this.from = from; + this.twiml = twiml; + } + + public CallCreator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final com.twilio.type.Twiml twiml + ) { + this.pathAccountSid = pathAccountSid; + this.to = to; + this.from = from; + this.twiml = twiml; + } + + public CallCreator( + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final String applicationSid + ) { this.to = to; this.from = from; this.applicationSid = applicationSid; } - /** - * Construct a new CallCreator. - * - * @param pathAccountSid The account_sid - * @param to Phone number, SIP address, or client identifier to call - * @param from Twilio number from which to originate the call - * @param applicationSid ApplicationSid that configures from where to fetch - * TwiML - */ - public CallCreator(final String pathAccountSid, - final com.twilio.type.Endpoint to, - final com.twilio.type.PhoneNumber from, - final String applicationSid) { + public CallCreator( + final String pathAccountSid, + final com.twilio.type.Endpoint to, + final com.twilio.type.Endpoint from, + final String applicationSid + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.applicationSid = applicationSid; } - /** - * The HTTP method Twilio should use when making its request to the `Url` - * parameter's value. Defaults to `POST`. If an `ApplicationSid` parameter is - * present, this parameter is ignored.. - * - * @param method HTTP method to use to fetch TwiML - * @return this - */ + public CallCreator setTo(final com.twilio.type.Endpoint to) { + this.to = to; + return this; + } + + public CallCreator setFrom(final com.twilio.type.Endpoint from) { + this.from = from; + return this; + } + public CallCreator setMethod(final HttpMethod method) { this.method = method; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML at `Url`. If an `ApplicationSid` parameter is present, this parameter - * is ignored.. - * - * @param fallbackUrl Fallback URL in case of error - * @return this - */ public CallCreator setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML at `Url`. If an `ApplicationSid` parameter is present, this parameter - * is ignored.. - * - * @param fallbackUrl Fallback URL in case of error - * @return this - */ public CallCreator setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - /** - * The HTTP method that Twilio should use to request the `FallbackUrl`. Must be - * either `GET` or `POST`. Defaults to `POST`. If an `ApplicationSid` parameter - * is present, this parameter is ignored.. - * - * @param fallbackMethod HTTP Method to use with FallbackUrl - * @return this - */ public CallCreator setFallbackMethod(final HttpMethod fallbackMethod) { this.fallbackMethod = fallbackMethod; return this; } - /** - * A URL that Twilio will send asynchronous webhook requests to on every call - * event specified in the `StatusCallbackEvent` parameter. If no event is - * specified, Twilio will send `completed` by default. If an `ApplicationSid` - * parameter is present, this parameter is ignored. URLs must contain a valid - * hostname (underscores are not permitted).. - * - * @param statusCallback Status Callback URL - * @return this - */ public CallCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * A URL that Twilio will send asynchronous webhook requests to on every call - * event specified in the `StatusCallbackEvent` parameter. If no event is - * specified, Twilio will send `completed` by default. If an `ApplicationSid` - * parameter is present, this parameter is ignored. URLs must contain a valid - * hostname (underscores are not permitted).. - * - * @param statusCallback Status Callback URL - * @return this - */ public CallCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The call progress events that will trigger a webhook from Twilio. Available - * values are `initiated`, `ringing`, `answered`, and `completed`. If no event - * is specified, defaults to `completed`. If you want to receive multiple - * events, please provide multiple `StatusCallbackEvent` values as individual - * parameters in the `POST` request. See the code sample for [monitoring call - * progress](https://www.twilio.com/docs/voice/api/call?code-sample=code-create-a-call-and-specify-a-statuscallbackevent). If an `ApplicationSid` is present, this parameter is ignored.. - * - * @param statusCallbackEvent The call progress events that Twilio will send - * webhooks on. - * @return this - */ - public CallCreator setStatusCallbackEvent(final List statusCallbackEvent) { + public CallCreator setStatusCallbackEvent( + final List statusCallbackEvent + ) { this.statusCallbackEvent = statusCallbackEvent; return this; } - /** - * The call progress events that will trigger a webhook from Twilio. Available - * values are `initiated`, `ringing`, `answered`, and `completed`. If no event - * is specified, defaults to `completed`. If you want to receive multiple - * events, please provide multiple `StatusCallbackEvent` values as individual - * parameters in the `POST` request. See the code sample for [monitoring call - * progress](https://www.twilio.com/docs/voice/api/call?code-sample=code-create-a-call-and-specify-a-statuscallbackevent). If an `ApplicationSid` is present, this parameter is ignored.. - * - * @param statusCallbackEvent The call progress events that Twilio will send - * webhooks on. - * @return this - */ - public CallCreator setStatusCallbackEvent(final String statusCallbackEvent) { + public CallCreator setStatusCallbackEvent( + final String statusCallbackEvent + ) { return setStatusCallbackEvent(Promoter.listOfOne(statusCallbackEvent)); } - /** - * The HTTP method Twilio should use when requesting the `StatusCallback` URL. - * Defaults to `POST`. If an `ApplicationSid` parameter is present, this - * parameter is ignored.. - * - * @param statusCallbackMethod HTTP Method to use with StatusCallback - * @return this - */ - public CallCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public CallCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * A string of keys to dial after connecting to the number, maximum of 32 - * digits. Valid digits in the string include: any digit (`0`-`9`), '`#`', '`*`' - * and '`w`' (to insert a half second pause). For example, if you connected to a - * company phone number and wanted to pause for one second, dial extension 1234, - * and then the pound key, use `SendDigits=ww1234#`. Remember to URL-encode this - * string, since the '`#`' character has special meaning in a URL. If both - * `SendDigits` and `MachineDetection` parameters are provided, then - * `MachineDetection` will be ignored.. - * - * @param sendDigits Digits to send - * @return this - */ public CallCreator setSendDigits(final String sendDigits) { this.sendDigits = sendDigits; return this; } - /** - * The if_machine. - * - * @param ifMachine The if_machine - * @return this - */ - public CallCreator setIfMachine(final String ifMachine) { - this.ifMachine = ifMachine; - return this; - } - - /** - * The integer number of seconds that Twilio should allow the phone to ring - * before assuming there is no answer. Default is `60` seconds, the maximum is - * `600` seconds. For some call flows, Twilio will add a 5-second buffer to the - * timeout value provided, so if you enter a timeout value of 10 seconds, you - * could see actual timeout closer to 15 seconds. Note, you could set this to a - * low value like `15` to hang up before reaching an answering machine or - * voicemail.. - * - * @param timeout Number of seconds to wait for an answer - * @return this - */ public CallCreator setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - /** - * Set this parameter to `true` to record the entirety of a phone call. The - * `RecordingUrl` will be sent to the `StatusCallback` URL. Defaults to false.. - * - * @param record Whether or not to record the Call - * @return this - */ public CallCreator setRecord(final Boolean record) { this.record = record; return this; } - /** - * `mono` or `dual` – defaults to `mono`. Set this parameter to specify the - * number of channels in the final recording. In a mono-channel recording, both - * legs of the call are mixed down into a single channel within a single - * recording file. With dual-channel recording, both legs use separate channels - * within a single recording file. In dual-channel recordings, the parent call - * will always be in the first channel, and the child call will always be in the - * second channel.. - * - * @param recordingChannels mono or dualSet this parameter to specify the - * number of channels in the final recording. - * @return this - */ public CallCreator setRecordingChannels(final String recordingChannels) { this.recordingChannels = recordingChannels; return this; } - /** - * A URL that Twilio will send a webhook request to when the recording is - * available for access.. - * - * @param recordingStatusCallback A URL that Twilio will send a webhook request - * to when the recording is available for access. - * @return this - */ - public CallCreator setRecordingStatusCallback(final String recordingStatusCallback) { + public CallCreator setRecordingStatusCallback( + final String recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - /** - * The HTTP method Twilio should use when requesting the - * `RecordingStatusCallback` URL. Defaults to `POST`.. - * - * @param recordingStatusCallbackMethod The HTTP method Twilio should use when - * requesting the `RecordingStatusCallback` - * URL. - * @return this - */ - public CallCreator setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod) { + public CallCreator setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - /** - * The sip_auth_username. - * - * @param sipAuthUsername The sip_auth_username - * @return this - */ + public CallCreator setRecordingConfigurationId( + final String recordingConfigurationId + ) { + this.recordingConfigurationId = recordingConfigurationId; + return this; + } + public CallCreator setSipAuthUsername(final String sipAuthUsername) { this.sipAuthUsername = sipAuthUsername; return this; } - /** - * The sip_auth_password. - * - * @param sipAuthPassword The sip_auth_password - * @return this - */ public CallCreator setSipAuthPassword(final String sipAuthPassword) { this.sipAuthPassword = sipAuthPassword; return this; } - /** - * Detect if a human, answering machine, or fax has picked up the call. Use - * `Enable` if you would like Twilio to return an `AnsweredBy` value as soon as - * it identifies the called party. If you would like to leave a message on an - * answering machine, specify `DetectMessageEnd`. If both `SendDigits` and - * `MachineDetection` parameters are provided, then MachineDetection will be - * ignored. [Detailed documentation is - * here](https://www.twilio.com/docs/voice/answering-machine-detection).. - * - * @param machineDetection Enable machine detection or end of greeting detection - * @return this - */ public CallCreator setMachineDetection(final String machineDetection) { this.machineDetection = machineDetection; return this; } - /** - * The number of seconds that Twilio should attempt to perform answering machine - * detection before timing out and firing a voice request with `AnsweredBy` of - * `unknown`. Defaults to 30 seconds.. - * - * @param machineDetectionTimeout Number of miliseconds to wait for machine - * detection - * @return this - */ - public CallCreator setMachineDetectionTimeout(final Integer machineDetectionTimeout) { + public CallCreator setMachineDetectionTimeout( + final Integer machineDetectionTimeout + ) { this.machineDetectionTimeout = machineDetectionTimeout; return this; } - /** - * The recording status events that will trigger Twilio to send webhooks on to - * the URL specified in `RecordingStatusCallback`. The available values are - * `in-progress`, `completed`, and `failed`. Defaults are `completed` and - * `failed`. To specify multiple values, separate them with a space. If any - * values are specified, the defaults are no longer applicable.. - * - * @param recordingStatusCallbackEvent The recording status changes that Twilio - * will send webhooks on to the URL - * specified in RecordingStatusCallback. - * @return this - */ - public CallCreator setRecordingStatusCallbackEvent(final List recordingStatusCallbackEvent) { + public CallCreator setRecordingStatusCallbackEvent( + final List recordingStatusCallbackEvent + ) { this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; } - /** - * The recording status events that will trigger Twilio to send webhooks on to - * the URL specified in `RecordingStatusCallback`. The available values are - * `in-progress`, `completed`, and `failed`. Defaults are `completed` and - * `failed`. To specify multiple values, separate them with a space. If any - * values are specified, the defaults are no longer applicable.. - * - * @param recordingStatusCallbackEvent The recording status changes that Twilio - * will send webhooks on to the URL - * specified in RecordingStatusCallback. - * @return this - */ - public CallCreator setRecordingStatusCallbackEvent(final String recordingStatusCallbackEvent) { - return setRecordingStatusCallbackEvent(Promoter.listOfOne(recordingStatusCallbackEvent)); - } - - /** - * `trim-silence` or `do-not-trim`. Set this parameter to define whether leading - * and trailing silence is trimmed from the recording. Defaults to - * `trim-silence`.. - * - * @param trim Set this parameter to control trimming of silence on the - * recording. - * @return this - */ + public CallCreator setRecordingStatusCallbackEvent( + final String recordingStatusCallbackEvent + ) { + return setRecordingStatusCallbackEvent( + Promoter.listOfOne(recordingStatusCallbackEvent) + ); + } + public CallCreator setTrim(final String trim) { this.trim = trim; return this; } - /** - * The phone number, SIP address, or Client identifier that made this Call. - * Phone numbers are in [E.164 - * format](https://www.twilio.com/docs/glossary/what-e164) (e.g., +16175551212). - * SIP addresses are formatted as `name@company.com`.. - * - * @param callerId The phone number, SIP address, or Client identifier that - * made this Call. Phone numbers are in E.164 format (e.g., - * +16175551212). SIP addresses are formatted as - * `name@company.com`. - * @return this - */ public CallCreator setCallerId(final String callerId) { this.callerId = callerId; return this; } - /** - * The fully qualified URL that hosts instructions for the call. Twilio will - * consult this URL when the call connects. See the [Url - * Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) details in [Making Calls](https://www.twilio.com/docs/voice/make-calls) for more details.. - * - * @param url Url from which to fetch TwiML - * @return this - */ + public CallCreator setMachineDetectionSpeechThreshold( + final Integer machineDetectionSpeechThreshold + ) { + this.machineDetectionSpeechThreshold = machineDetectionSpeechThreshold; + return this; + } + + public CallCreator setMachineDetectionSpeechEndThreshold( + final Integer machineDetectionSpeechEndThreshold + ) { + this.machineDetectionSpeechEndThreshold = + machineDetectionSpeechEndThreshold; + return this; + } + + public CallCreator setMachineDetectionSilenceTimeout( + final Integer machineDetectionSilenceTimeout + ) { + this.machineDetectionSilenceTimeout = machineDetectionSilenceTimeout; + return this; + } + + public CallCreator setAsyncAmd(final String asyncAmd) { + this.asyncAmd = asyncAmd; + return this; + } + + public CallCreator setAsyncAmdStatusCallback( + final URI asyncAmdStatusCallback + ) { + this.asyncAmdStatusCallback = asyncAmdStatusCallback; + return this; + } + + public CallCreator setAsyncAmdStatusCallback( + final String asyncAmdStatusCallback + ) { + return setAsyncAmdStatusCallback( + Promoter.uriFromString(asyncAmdStatusCallback) + ); + } + + public CallCreator setAsyncAmdStatusCallbackMethod( + final HttpMethod asyncAmdStatusCallbackMethod + ) { + this.asyncAmdStatusCallbackMethod = asyncAmdStatusCallbackMethod; + return this; + } + + public CallCreator setPassports(final String passports) { + this.passports = passports; + return this; + } + + public CallCreator setByoc(final String byoc) { + this.byoc = byoc; + return this; + } + + public CallCreator setCallReason(final String callReason) { + this.callReason = callReason; + return this; + } + + public CallCreator setCallToken(final String callToken) { + this.callToken = callToken; + return this; + } + + public CallCreator setRecordingTrack(final String recordingTrack) { + this.recordingTrack = recordingTrack; + return this; + } + + public CallCreator setTimeLimit(final Integer timeLimit) { + this.timeLimit = timeLimit; + return this; + } + + public CallCreator setClientNotificationUrl( + final URI clientNotificationUrl + ) { + this.clientNotificationUrl = clientNotificationUrl; + return this; + } + + public CallCreator setClientNotificationUrl( + final String clientNotificationUrl + ) { + return setClientNotificationUrl( + Promoter.uriFromString(clientNotificationUrl) + ); + } + public CallCreator setUrl(final URI url) { this.url = url; return this; } - /** - * The fully qualified URL that hosts instructions for the call. Twilio will - * consult this URL when the call connects. See the [Url - * Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) details in [Making Calls](https://www.twilio.com/docs/voice/make-calls) for more details.. - * - * @param url Url from which to fetch TwiML - * @return this - */ public CallCreator setUrl(final String url) { return setUrl(Promoter.uriFromString(url)); } - /** - * The 34-character SID of the application Twilio should use to handle this - * phone call. If this parameter is present, Twilio will ignore all of the voice - * URLs passed and use the URLs set on the application. See the [ApplicationSid - * Parameter](https://www.twilio.com/docs/voice/make-calls#specify-an-applicationsid-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls) for more details.. - * - * @param applicationSid ApplicationSid that configures from where to fetch - * TwiML - * @return this - */ + public CallCreator setTwiml(final com.twilio.type.Twiml twiml) { + this.twiml = twiml; + return this; + } + + public CallCreator setTwiml(final String twiml) { + return setTwiml(Promoter.twimlFromString(twiml)); + } + public CallCreator setApplicationSid(final String applicationSid) { this.applicationSid = applicationSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Call - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Call create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Calls.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Call creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Call create(final TwilioRestClient client) { + Response response = makeRequest(client); return Call.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Call content = Call.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (to != null) { - request.addPostParam("To", to.getEndpoint()); + Serializer.toString(request, "To", to, ParameterType.URLENCODED); } if (from != null) { - request.addPostParam("From", from.toString()); - } - - if (url != null) { - request.addPostParam("Url", url.toString()); - } - - if (applicationSid != null) { - request.addPostParam("ApplicationSid", applicationSid); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (method != null) { - request.addPostParam("Method", method.toString()); + Serializer.toString( + request, + "Method", + method, + ParameterType.URLENCODED + ); } if (fallbackUrl != null) { - request.addPostParam("FallbackUrl", fallbackUrl.toString()); + Serializer.toString( + request, + "FallbackUrl", + fallbackUrl, + ParameterType.URLENCODED + ); } if (fallbackMethod != null) { - request.addPostParam("FallbackMethod", fallbackMethod.toString()); + Serializer.toString( + request, + "FallbackMethod", + fallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackEvent != null) { - for (String prop : statusCallbackEvent) { - request.addPostParam("StatusCallbackEvent", prop); + for (String param : statusCallbackEvent) { + Serializer.toString( + request, + "StatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (sendDigits != null) { - request.addPostParam("SendDigits", sendDigits); - } - - if (ifMachine != null) { - request.addPostParam("IfMachine", ifMachine); + Serializer.toString( + request, + "SendDigits", + sendDigits, + ParameterType.URLENCODED + ); } if (timeout != null) { - request.addPostParam("Timeout", timeout.toString()); + Serializer.toString( + request, + "Timeout", + timeout, + ParameterType.URLENCODED + ); } if (record != null) { - request.addPostParam("Record", record.toString()); + Serializer.toString( + request, + "Record", + record, + ParameterType.URLENCODED + ); } if (recordingChannels != null) { - request.addPostParam("RecordingChannels", recordingChannels); + Serializer.toString( + request, + "RecordingChannels", + recordingChannels, + ParameterType.URLENCODED + ); } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback); + Serializer.toString( + request, + "RecordingStatusCallback", + recordingStatusCallback, + ParameterType.URLENCODED + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); + Serializer.toString( + request, + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (recordingConfigurationId != null) { + Serializer.toString( + request, + "RecordingConfigurationId", + recordingConfigurationId, + ParameterType.URLENCODED + ); } if (sipAuthUsername != null) { - request.addPostParam("SipAuthUsername", sipAuthUsername); + Serializer.toString( + request, + "SipAuthUsername", + sipAuthUsername, + ParameterType.URLENCODED + ); } if (sipAuthPassword != null) { - request.addPostParam("SipAuthPassword", sipAuthPassword); + Serializer.toString( + request, + "SipAuthPassword", + sipAuthPassword, + ParameterType.URLENCODED + ); } if (machineDetection != null) { - request.addPostParam("MachineDetection", machineDetection); + Serializer.toString( + request, + "MachineDetection", + machineDetection, + ParameterType.URLENCODED + ); } if (machineDetectionTimeout != null) { - request.addPostParam("MachineDetectionTimeout", machineDetectionTimeout.toString()); + Serializer.toString( + request, + "MachineDetectionTimeout", + machineDetectionTimeout, + ParameterType.URLENCODED + ); } if (recordingStatusCallbackEvent != null) { - for (String prop : recordingStatusCallbackEvent) { - request.addPostParam("RecordingStatusCallbackEvent", prop); + for (String param : recordingStatusCallbackEvent) { + Serializer.toString( + request, + "RecordingStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (trim != null) { - request.addPostParam("Trim", trim); + Serializer.toString( + request, + "Trim", + trim, + ParameterType.URLENCODED + ); } if (callerId != null) { - request.addPostParam("CallerId", callerId); + Serializer.toString( + request, + "CallerId", + callerId, + ParameterType.URLENCODED + ); + } + + if (machineDetectionSpeechThreshold != null) { + Serializer.toString( + request, + "MachineDetectionSpeechThreshold", + machineDetectionSpeechThreshold, + ParameterType.URLENCODED + ); + } + + if (machineDetectionSpeechEndThreshold != null) { + Serializer.toString( + request, + "MachineDetectionSpeechEndThreshold", + machineDetectionSpeechEndThreshold, + ParameterType.URLENCODED + ); + } + + if (machineDetectionSilenceTimeout != null) { + Serializer.toString( + request, + "MachineDetectionSilenceTimeout", + machineDetectionSilenceTimeout, + ParameterType.URLENCODED + ); + } + + if (asyncAmd != null) { + Serializer.toString( + request, + "AsyncAmd", + asyncAmd, + ParameterType.URLENCODED + ); + } + + if (asyncAmdStatusCallback != null) { + Serializer.toString( + request, + "AsyncAmdStatusCallback", + asyncAmdStatusCallback, + ParameterType.URLENCODED + ); + } + + if (asyncAmdStatusCallbackMethod != null) { + Serializer.toString( + request, + "AsyncAmdStatusCallbackMethod", + asyncAmdStatusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (passports != null) { + Serializer.toString( + request, + "Passports", + passports, + ParameterType.URLENCODED + ); + } + + if (byoc != null) { + Serializer.toString( + request, + "Byoc", + byoc, + ParameterType.URLENCODED + ); + } + + if (callReason != null) { + Serializer.toString( + request, + "CallReason", + callReason, + ParameterType.URLENCODED + ); + } + + if (callToken != null) { + Serializer.toString( + request, + "CallToken", + callToken, + ParameterType.URLENCODED + ); + } + + if (recordingTrack != null) { + Serializer.toString( + request, + "RecordingTrack", + recordingTrack, + ParameterType.URLENCODED + ); + } + + if (timeLimit != null) { + Serializer.toString( + request, + "TimeLimit", + timeLimit, + ParameterType.URLENCODED + ); + } + + if (clientNotificationUrl != null) { + Serializer.toString( + request, + "ClientNotificationUrl", + clientNotificationUrl, + ParameterType.URLENCODED + ); + } + + if (url != null) { + Serializer.toString(request, "Url", url, ParameterType.URLENCODED); + } + + if (twiml != null) { + Serializer.toString( + request, + "Twiml", + twiml, + ParameterType.URLENCODED + ); + } + + if (applicationSid != null) { + Serializer.toString( + request, + "ApplicationSid", + applicationSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java index 10aac053bd..b39753d912 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class CallDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new CallDeleter. - * - * @param pathSid Call Sid that uniquely identifies the Call to delete - */ public CallDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new CallDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Call Sid that uniquely identifies the Call to delete - */ - public CallDeleter(final String pathAccountSid, - final String pathSid) { + public CallDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Call delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java index 5cf47741f3..136f156b34 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,85 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CallFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new CallFetcher. - * - * @param pathSid Call Sid that uniquely identifies the Call to fetch - */ public CallFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new CallFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Call Sid that uniquely identifies the Call to fetch - */ - public CallFetcher(final String pathAccountSid, - final String pathSid) { + public CallFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Call - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Call fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Call fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Call fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Call.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Call content = Call.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallReader.java b/src/main/java/com/twilio/rest/api/v2010/account/CallReader.java index b7a37e0112..31510edebd 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallReader.java @@ -1,340 +1,320 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; -import com.google.common.collect.Range; import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class CallReader extends Reader { + private String pathAccountSid; private com.twilio.type.PhoneNumber to; private com.twilio.type.PhoneNumber from; private String parentCallSid; private Call.Status status; - private DateTime absoluteStartTime; - private Range rangeStartTime; - private DateTime absoluteEndTime; - private Range rangeEndTime; - - /** - * Construct a new CallReader. - */ - public CallReader() { - } + private ZonedDateTime startTime; + private ZonedDateTime startTimeBefore; + private ZonedDateTime startTimeAfter; + private ZonedDateTime endTime; + private ZonedDateTime endTimeBefore; + private ZonedDateTime endTimeAfter; + private Long pageSize; + + public CallReader() {} - /** - * Construct a new CallReader. - * - * @param pathAccountSid The account_sid - */ public CallReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only show calls to this phone number, SIP address, Client identifier or SIM - * SID.. - * - * @param to Phone number or Client identifier to filter `to` on - * @return this - */ public CallReader setTo(final com.twilio.type.PhoneNumber to) { this.to = to; return this; } - /** - * Only show calls to this phone number, SIP address, Client identifier or SIM - * SID.. - * - * @param to Phone number or Client identifier to filter `to` on - * @return this - */ public CallReader setTo(final String to) { return setTo(Promoter.phoneNumberFromString(to)); } - /** - * Only show calls from this phone number, SIP address, Client identifier or SIM - * SID.. - * - * @param from Phone number or Client identifier to filter `from` on - * @return this - */ public CallReader setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - /** - * Only show calls from this phone number, SIP address, Client identifier or SIM - * SID.. - * - * @param from Phone number or Client identifier to filter `from` on - * @return this - */ public CallReader setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - /** - * Only show calls spawned by the Call with this SID.. - * - * @param parentCallSid Parent Call Sid to filter on - * @return this - */ public CallReader setParentCallSid(final String parentCallSid) { this.parentCallSid = parentCallSid; return this; } - /** - * Only show calls currently in the specified status. May be `queued`, - * `ringing`, `in-progress`, `canceled`, `completed`, `failed`, `busy`, or - * `no-answer`.. - * - * @param status Status to filter on - * @return this - */ public CallReader setStatus(final Call.Status status) { this.status = status; return this; } - /** - * Only show calls that started on this date, given as `YYYY-MM-DD`. Also - * supports inequalities, such as `StartTime<=YYYY-MM-DD` for calls that - * started at or before midnight on a date, and `StartTime>=YYYY-MM-DD` for - * calls that started at or after midnight on a date.. - * - * @param absoluteStartTime StartTime to filter on - * @return this - */ - public CallReader setStartTime(final DateTime absoluteStartTime) { - this.rangeStartTime = null; - this.absoluteStartTime = absoluteStartTime; + public CallReader setStartTime(final ZonedDateTime startTime) { + this.startTime = startTime; return this; } - /** - * Only show calls that started on this date, given as `YYYY-MM-DD`. Also - * supports inequalities, such as `StartTime<=YYYY-MM-DD` for calls that - * started at or before midnight on a date, and `StartTime>=YYYY-MM-DD` for - * calls that started at or after midnight on a date.. - * - * @param rangeStartTime StartTime to filter on - * @return this - */ - public CallReader setStartTime(final Range rangeStartTime) { - this.absoluteStartTime = null; - this.rangeStartTime = rangeStartTime; + public CallReader setStartTimeBefore(final ZonedDateTime startTimeBefore) { + this.startTimeBefore = startTimeBefore; return this; } - /** - * Only show calls that ended on this date. - * - * @param absoluteEndTime EndTime to filter on - * @return this - */ - public CallReader setEndTime(final DateTime absoluteEndTime) { - this.rangeEndTime = null; - this.absoluteEndTime = absoluteEndTime; + public CallReader setStartTimeAfter(final ZonedDateTime startTimeAfter) { + this.startTimeAfter = startTimeAfter; return this; } - /** - * Only show calls that ended on this date. - * - * @param rangeEndTime EndTime to filter on - * @return this - */ - public CallReader setEndTime(final Range rangeEndTime) { - this.absoluteEndTime = null; - this.rangeEndTime = rangeEndTime; + public CallReader setEndTime(final ZonedDateTime endTime) { + this.endTime = endTime; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Call ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public CallReader setEndTimeBefore(final ZonedDateTime endTimeBefore) { + this.endTimeBefore = endTimeBefore; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Call ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public CallReader setEndTimeAfter(final ZonedDateTime endTimeAfter) { + this.endTimeAfter = endTimeAfter; + return this; + } + + public CallReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "calls", + response.getContent(), + Call.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Calls.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Call ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "calls", + response.getContent(), + Call.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Call read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "calls", + response.getContent(), + Call.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Call Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Call read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "calls", - response.getContent(), - Call.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (to != null) { - request.addQueryParam("To", to.toString()); + Serializer.toString(request, "To", to, ParameterType.QUERY); } if (from != null) { - request.addQueryParam("From", from.toString()); + Serializer.toString(request, "From", from, ParameterType.QUERY); } if (parentCallSid != null) { - request.addQueryParam("ParentCallSid", parentCallSid); + Serializer.toString( + request, + "ParentCallSid", + parentCallSid, + ParameterType.QUERY + ); } if (status != null) { - request.addQueryParam("Status", status.toString()); + Serializer.toString(request, "Status", status, ParameterType.QUERY); } - if (absoluteStartTime != null) { - request.addQueryParam("StartTime", absoluteStartTime.toString(Request.QUERY_STRING_DATE_TIME_FORMAT)); - } else if (rangeStartTime != null) { - request.addQueryDateTimeRange("StartTime", rangeStartTime); - } + Serializer.toString( + request, + "StartTime", + startTime, + startTimeBefore, + startTimeAfter + ); - if (absoluteEndTime != null) { - request.addQueryParam("EndTime", absoluteEndTime.toString(Request.QUERY_STRING_DATE_TIME_FORMAT)); - } else if (rangeEndTime != null) { - request.addQueryDateTimeRange("EndTime", rangeEndTime); + Serializer.toString( + request, + "EndTime", + endTime, + endTimeBefore, + endTimeAfter + ); + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/CallUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/CallUpdater.java index 95d939c49b..3115e188c8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/CallUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/CallUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class CallUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private URI url; private HttpMethod method; private Call.UpdateStatus status; @@ -30,232 +43,223 @@ public class CallUpdater extends Updater { private HttpMethod fallbackMethod; private URI statusCallback; private HttpMethod statusCallbackMethod; + private com.twilio.type.Twiml twiml; + private Integer timeLimit; - /** - * Construct a new CallUpdater. - * - * @param pathSid Call Sid that uniquely identifies the Call to update - */ public CallUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new CallUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid Call Sid that uniquely identifies the Call to update - */ - public CallUpdater(final String pathAccountSid, - final String pathSid) { + public CallUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * that hosts instructions for the call. Twilio will consult this URL when the - * call connects. See the [Url - * Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls) for more details.. - * - * @param url URL that returns TwiML - * @return this - */ public CallUpdater setUrl(final URI url) { this.url = url; return this; } - /** - * that hosts instructions for the call. Twilio will consult this URL when the - * call connects. See the [Url - * Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls) for more details.. - * - * @param url URL that returns TwiML - * @return this - */ public CallUpdater setUrl(final String url) { return setUrl(Promoter.uriFromString(url)); } - /** - * The HTTP method Twilio should use when making its request to the `Url` - * parameter's value. Defaults to `POST`. If an `ApplicationSid` parameter is - * present, this parameter is ignored.. - * - * @param method HTTP method to use to fetch TwiML - * @return this - */ public CallUpdater setMethod(final HttpMethod method) { this.method = method; return this; } - /** - * Either `canceled` or `completed`. Specifying `canceled` will attempt to hang - * up calls that are queued or ringing, but will not affect calls already in - * progress. Specifying `completed` will attempt to hang up a call even if it's - * already in progress.. - * - * @param status Status to update the Call with - * @return this - */ public CallUpdater setStatus(final Call.UpdateStatus status) { this.status = status; return this; } - /** - * A URL that Twilio will request if an error occurs when requesting or - * executing the TwiML at `Url`. If an `ApplicationSid` parameter is present, - * this parameter is ignored.. - * - * @param fallbackUrl Fallback URL in case of error - * @return this - */ public CallUpdater setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs when requesting or - * executing the TwiML at `Url`. If an `ApplicationSid` parameter is present, - * this parameter is ignored.. - * - * @param fallbackUrl Fallback URL in case of error - * @return this - */ public CallUpdater setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - /** - * The HTTP method that Twilio should use to request the `FallbackUrl`. Must be - * either `GET` or `POST`. Defaults to `POST`. If an `ApplicationSid` parameter - * is present, this parameter is ignored.. - * - * @param fallbackMethod HTTP Method to use with FallbackUrl - * @return this - */ public CallUpdater setFallbackMethod(final HttpMethod fallbackMethod) { this.fallbackMethod = fallbackMethod; return this; } - /** - * A URL that Twilio will send asynchronous webhook requests to on every call - * event specified in the `StatusCallbackEvent` parameter. If no event is - * specified, Twilio will send `completed` by default. If an `ApplicationSid` - * parameter is present, this parameter is ignored. URLs must contain a valid - * hostname (underscores are not permitted).. - * - * @param statusCallback Status Callback URL - * @return this - */ public CallUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * A URL that Twilio will send asynchronous webhook requests to on every call - * event specified in the `StatusCallbackEvent` parameter. If no event is - * specified, Twilio will send `completed` by default. If an `ApplicationSid` - * parameter is present, this parameter is ignored. URLs must contain a valid - * hostname (underscores are not permitted).. - * - * @param statusCallback Status Callback URL - * @return this - */ public CallUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio should use when requesting the `StatusCallback` URL. - * Defaults to `POST`. If an `ApplicationSid` parameter is present, this - * parameter is ignored.. - * - * @param statusCallbackMethod HTTP Method to use with StatusCallback - * @return this - */ - public CallUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public CallUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Call - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Call update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public CallUpdater setTwiml(final com.twilio.type.Twiml twiml) { + this.twiml = twiml; + return this; + } + + public CallUpdater setTwiml(final String twiml) { + return setTwiml(Promoter.twimlFromString(twiml)); + } + + public CallUpdater setTimeLimit(final Integer timeLimit) { + this.timeLimit = timeLimit; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Call update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Call update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Call update(final TwilioRestClient client) { + Response response = makeRequest(client); return Call.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Call content = Call.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (url != null) { - request.addPostParam("Url", url.toString()); + Serializer.toString(request, "Url", url, ParameterType.URLENCODED); } if (method != null) { - request.addPostParam("Method", method.toString()); + Serializer.toString( + request, + "Method", + method, + ParameterType.URLENCODED + ); } if (status != null) { - request.addPostParam("Status", status.toString()); + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); } if (fallbackUrl != null) { - request.addPostParam("FallbackUrl", fallbackUrl.toString()); + Serializer.toString( + request, + "FallbackUrl", + fallbackUrl, + ParameterType.URLENCODED + ); } if (fallbackMethod != null) { - request.addPostParam("FallbackMethod", fallbackMethod.toString()); + Serializer.toString( + request, + "FallbackMethod", + fallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (twiml != null) { + Serializer.toString( + request, + "Twiml", + twiml, + ParameterType.URLENCODED + ); + } + + if (timeLimit != null) { + Serializer.toString( + request, + "TimeLimit", + timeLimit, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Conference.java b/src/main/java/com/twilio/rest/api/v2010/account/Conference.java index 6c1c981cd0..93dca341a8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Conference.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Conference.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,31 +17,61 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Conference extends Resource { - private static final long serialVersionUID = 81655469535043L; + + public static ConferenceFetcher fetcher(final String pathSid) { + return new ConferenceFetcher(pathSid); + } + + public static ConferenceFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new ConferenceFetcher(pathAccountSid, pathSid); + } + + public static ConferenceReader reader() { + return new ConferenceReader(); + } + + public static ConferenceReader reader(final String pathAccountSid) { + return new ConferenceReader(pathAccountSid); + } + + public static ConferenceUpdater updater(final String pathSid) { + return new ConferenceUpdater(pathSid); + } + + public static ConferenceUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new ConferenceUpdater(pathAccountSid, pathSid); + } public enum Status { INIT("init"), @@ -47,15 +84,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -71,93 +104,59 @@ private UpdateStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a UpdateStatus from a string. - * @param value string value - * @return generated UpdateStatus - */ @JsonCreator public static UpdateStatus forValue(final String value) { return Promoter.enumFromString(value, UpdateStatus.values()); } } - /** - * Create a ConferenceFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique conference Sid - * @return ConferenceFetcher capable of executing the fetch - */ - public static ConferenceFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new ConferenceFetcher(pathAccountSid, pathSid); - } + public enum ReasonConferenceEnded { + CONFERENCE_ENDED_VIA_API("conference-ended-via-api"), + PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_LEFT( + "participant-with-end-conference-on-exit-left" + ), + PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_KICKED( + "participant-with-end-conference-on-exit-kicked" + ), + LAST_PARTICIPANT_KICKED("last-participant-kicked"), + LAST_PARTICIPANT_LEFT("last-participant-left"); - /** - * Create a ConferenceFetcher to execute fetch. - * - * @param pathSid Fetch by unique conference Sid - * @return ConferenceFetcher capable of executing the fetch - */ - public static ConferenceFetcher fetcher(final String pathSid) { - return new ConferenceFetcher(pathSid); - } - - /** - * Create a ConferenceReader to execute read. - * - * @param pathAccountSid The account_sid - * @return ConferenceReader capable of executing the read - */ - public static ConferenceReader reader(final String pathAccountSid) { - return new ConferenceReader(pathAccountSid); - } + private final String value; - /** - * Create a ConferenceReader to execute read. - * - * @return ConferenceReader capable of executing the read - */ - public static ConferenceReader reader() { - return new ConferenceReader(); - } + private ReasonConferenceEnded(final String value) { + this.value = value; + } - /** - * Create a ConferenceUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return ConferenceUpdater capable of executing the update - */ - public static ConferenceUpdater updater(final String pathAccountSid, - final String pathSid) { - return new ConferenceUpdater(pathAccountSid, pathSid); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a ConferenceUpdater to execute update. - * - * @param pathSid The sid - * @return ConferenceUpdater capable of executing the update - */ - public static ConferenceUpdater updater(final String pathSid) { - return new ConferenceUpdater(pathSid); + @JsonCreator + public static ReasonConferenceEnded forValue(final String value) { + return Promoter.enumFromString( + value, + ReasonConferenceEnded.values() + ); + } } /** - * Converts a JSON String into a Conference object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Conference object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Conference object represented by the provided JSON */ - public static Conference fromJson(final String json, final ObjectMapper objectMapper) { + public static Conference fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conference.class); @@ -171,12 +170,15 @@ public static Conference fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a Conference object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Conference object represented by the provided JSON */ - public static Conference fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Conference fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Conference.class); @@ -187,140 +189,92 @@ public static Conference fromJson(final InputStream json, final ObjectMapper obj } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final String apiVersion; + + @Getter + private final String callSidEndingConference; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter + private final Conference.ReasonConferenceEnded reasonConferenceEnded; + + @Getter private final String region; + + @Getter private final String sid; + + @Getter private final Conference.Status status; - private final String uri; + + @Getter private final Map subresourceUris; + @Getter + private final String uri; + @JsonCreator - private Conference(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("region") - final String region, - @JsonProperty("sid") - final String sid, - @JsonProperty("status") - final Conference.Status status, - @JsonProperty("uri") - final String uri, - @JsonProperty("subresource_uris") - final Map subresourceUris) { + private Conference( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty( + "call_sid_ending_conference" + ) final String callSidEndingConference, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "reason_conference_ended" + ) final Conference.ReasonConferenceEnded reasonConferenceEnded, + @JsonProperty("region") final String region, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Conference.Status status, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); this.apiVersion = apiVersion; + this.callSidEndingConference = callSidEndingConference; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; + this.reasonConferenceEnded = reasonConferenceEnded; this.region = region; this.sid = sid; this.status = status; - this.uri = uri; this.subresourceUris = subresourceUris; - } - - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The A human readable description of this resource. - * - * @return A human readable description of this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The A string representing the Twilio Region where the conference was - * mixed.. - * - * @return A string representing the Twilio Region where the conference was - * mixed. - */ - public final String getRegion() { - return this.region; - } - - /** - * Returns The A string that uniquely identifies this conference. - * - * @return A string that uniquely identifies this conference - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The status of the conference. - * - * @return The status of the conference - */ - public final Conference.Status getStatus() { - return this.status; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; + this.uri = uri; } @Override @@ -334,46 +288,43 @@ public boolean equals(final Object o) { } Conference other = (Conference) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(region, other.region) && - Objects.equals(sid, other.sid) && - Objects.equals(status, other.status) && - Objects.equals(uri, other.uri) && - Objects.equals(subresourceUris, other.subresourceUris); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals( + callSidEndingConference, + other.callSidEndingConference + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + reasonConferenceEnded, + other.reasonConferenceEnded + ) && + Objects.equals(region, other.region) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - apiVersion, - friendlyName, - region, - sid, - status, - uri, - subresourceUris); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("apiVersion", apiVersion) - .add("friendlyName", friendlyName) - .add("region", region) - .add("sid", sid) - .add("status", status) - .add("uri", uri) - .add("subresourceUris", subresourceUris) - .toString(); + return Objects.hash( + accountSid, + apiVersion, + callSidEndingConference, + dateCreated, + dateUpdated, + friendlyName, + reasonConferenceEnded, + region, + sid, + status, + subresourceUris, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceFetcher.java index 374d4163ea..c89f9e82b9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ConferenceFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new ConferenceFetcher. - * - * @param pathSid Fetch by unique conference Sid - */ public ConferenceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ConferenceFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique conference Sid - */ - public ConferenceFetcher(final String pathAccountSid, - final String pathSid) { + public ConferenceFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Conference - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Conference fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Conferences/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conference fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Conference fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Conference.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Conference fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conference content = Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceReader.java b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceReader.java index 576299e727..e6f671096f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceReader.java @@ -1,292 +1,303 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; -import com.google.common.collect.Range; import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class ConferenceReader extends Reader { + private String pathAccountSid; - private LocalDate absoluteDateCreated; - private Range rangeDateCreated; - private LocalDate absoluteDateUpdated; - private Range rangeDateUpdated; + private LocalDate dateCreated; + private LocalDate dateCreatedBefore; + private LocalDate dateCreatedAfter; + private LocalDate dateUpdated; + private LocalDate dateUpdatedBefore; + private LocalDate dateUpdatedAfter; private String friendlyName; private Conference.Status status; + private Long pageSize; - /** - * Construct a new ConferenceReader. - */ - public ConferenceReader() { - } + public ConferenceReader() {} - /** - * Construct a new ConferenceReader. - * - * @param pathAccountSid The account_sid - */ public ConferenceReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only show conferences that started on this date, given as `YYYY-MM-DD`. You - * can also specify inequality, such as `DateCreated<=YYYY-MM-DD` for - * conferences that started at or before midnight on a date, and - * `DateCreated>=YYYY-MM-DD` for conferences that started at or after - * midnight on a date.. - * - * @param absoluteDateCreated Filter by date created - * @return this - */ - public ConferenceReader setDateCreated(final LocalDate absoluteDateCreated) { - this.rangeDateCreated = null; - this.absoluteDateCreated = absoluteDateCreated; + public ConferenceReader setDateCreated(final LocalDate dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ConferenceReader setDateCreatedBefore( + final LocalDate dateCreatedBefore + ) { + this.dateCreatedBefore = dateCreatedBefore; return this; } - /** - * Only show conferences that started on this date, given as `YYYY-MM-DD`. You - * can also specify inequality, such as `DateCreated<=YYYY-MM-DD` for - * conferences that started at or before midnight on a date, and - * `DateCreated>=YYYY-MM-DD` for conferences that started at or after - * midnight on a date.. - * - * @param rangeDateCreated Filter by date created - * @return this - */ - public ConferenceReader setDateCreated(final Range rangeDateCreated) { - this.absoluteDateCreated = null; - this.rangeDateCreated = rangeDateCreated; + public ConferenceReader setDateCreatedAfter( + final LocalDate dateCreatedAfter + ) { + this.dateCreatedAfter = dateCreatedAfter; return this; } - /** - * Only show conferences that were last updated on this date, given as - * `YYYY-MM-DD`. You can also specify inequality, such as - * `DateUpdated<=YYYY-MM-DD` for conferences that were last updated at or - * before midnight on a date, and `DateUpdated>=YYYY-MM-DD` for conferences - * that were updated at or after midnight on a date.. - * - * @param absoluteDateUpdated Filter by date updated - * @return this - */ - public ConferenceReader setDateUpdated(final LocalDate absoluteDateUpdated) { - this.rangeDateUpdated = null; - this.absoluteDateUpdated = absoluteDateUpdated; + public ConferenceReader setDateUpdated(final LocalDate dateUpdated) { + this.dateUpdated = dateUpdated; return this; } - /** - * Only show conferences that were last updated on this date, given as - * `YYYY-MM-DD`. You can also specify inequality, such as - * `DateUpdated<=YYYY-MM-DD` for conferences that were last updated at or - * before midnight on a date, and `DateUpdated>=YYYY-MM-DD` for conferences - * that were updated at or after midnight on a date.. - * - * @param rangeDateUpdated Filter by date updated - * @return this - */ - public ConferenceReader setDateUpdated(final Range rangeDateUpdated) { - this.absoluteDateUpdated = null; - this.rangeDateUpdated = rangeDateUpdated; + public ConferenceReader setDateUpdatedBefore( + final LocalDate dateUpdatedBefore + ) { + this.dateUpdatedBefore = dateUpdatedBefore; + return this; + } + + public ConferenceReader setDateUpdatedAfter( + final LocalDate dateUpdatedAfter + ) { + this.dateUpdatedAfter = dateUpdatedAfter; return this; } - /** - * Only show results who's friendly name exactly matches the string. - * - * @param friendlyName Filter by friendly name - * @return this - */ public ConferenceReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A string representing the status of the conference. May be `init`, - * `in-progress`, or `completed`.. - * - * @param status The status of the conference - * @return this - */ public ConferenceReader setStatus(final Conference.Status status) { this.status = status; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Conference ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ConferenceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Conference ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conferences", + response.getContent(), + Conference.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Conferences.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Conferences.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Conference ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conferences", + response.getContent(), + Conference.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Conference read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conferences", + response.getContent(), + Conference.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Conference Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Conference read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "conferences", - response.getContent(), - Conference.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { - if (absoluteDateCreated != null) { - request.addQueryParam("DateCreated", absoluteDateCreated.toString(Request.QUERY_STRING_DATE_FORMAT)); - } else if (rangeDateCreated != null) { - request.addQueryDateRange("DateCreated", rangeDateCreated); - } + Serializer.toString( + request, + "DateCreated", + dateCreated, + dateCreatedBefore, + dateCreatedAfter + ); - if (absoluteDateUpdated != null) { - request.addQueryParam("DateUpdated", absoluteDateUpdated.toString(Request.QUERY_STRING_DATE_FORMAT)); - } else if (rangeDateUpdated != null) { - request.addQueryDateRange("DateUpdated", rangeDateUpdated); - } + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + dateUpdatedBefore, + dateUpdatedAfter + ); if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (status != null) { - request.addQueryParam("Status", status.toString()); + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceUpdater.java index 670a3fca8a..4640e820d6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConferenceUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConferenceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,137 +28,148 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class ConferenceUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private Conference.UpdateStatus status; private URI announceUrl; private HttpMethod announceMethod; - /** - * Construct a new ConferenceUpdater. - * - * @param pathSid The sid - */ public ConferenceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ConferenceUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public ConferenceUpdater(final String pathAccountSid, - final String pathSid) { + public ConferenceUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Specifying `completed` will end the conference and kick all participants. - * - * @param status Specifying completed will end the conference and kick all - * participants - * @return this - */ public ConferenceUpdater setStatus(final Conference.UpdateStatus status) { this.status = status; return this; } - /** - * The announce_url. - * - * @param announceUrl The announce_url - * @return this - */ public ConferenceUpdater setAnnounceUrl(final URI announceUrl) { this.announceUrl = announceUrl; return this; } - /** - * The announce_url. - * - * @param announceUrl The announce_url - * @return this - */ public ConferenceUpdater setAnnounceUrl(final String announceUrl) { return setAnnounceUrl(Promoter.uriFromString(announceUrl)); } - /** - * The announce_method. - * - * @param announceMethod The announce_method - * @return this - */ - public ConferenceUpdater setAnnounceMethod(final HttpMethod announceMethod) { + public ConferenceUpdater setAnnounceMethod( + final HttpMethod announceMethod + ) { this.announceMethod = announceMethod; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Conference - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Conference update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Conferences/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Conference update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Conference update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Conference update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Conference.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conference content = Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (status != null) { - request.addPostParam("Status", status.toString()); + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); } if (announceUrl != null) { - request.addPostParam("AnnounceUrl", announceUrl.toString()); + Serializer.toString( + request, + "AnnounceUrl", + announceUrl, + ParameterType.URLENCODED + ); } if (announceMethod != null) { - request.addPostParam("AnnounceMethod", announceMethod.toString()); + Serializer.toString( + request, + "AnnounceMethod", + announceMethod, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectApp.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectApp.java index 2a6a9b1578..9425b42cf8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectApp.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectApp.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,129 +17,129 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class ConnectApp extends Resource { - private static final long serialVersionUID = 269497828076419L; - public enum Permission { + public static ConnectAppDeleter deleter(final String pathSid) { + return new ConnectAppDeleter(pathSid); + } + + public static ConnectAppDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new ConnectAppDeleter(pathAccountSid, pathSid); + } + + public static ConnectAppFetcher fetcher(final String pathSid) { + return new ConnectAppFetcher(pathSid); + } + + public static ConnectAppFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new ConnectAppFetcher(pathAccountSid, pathSid); + } + + public static ConnectAppReader reader() { + return new ConnectAppReader(); + } + + public static ConnectAppReader reader(final String pathAccountSid) { + return new ConnectAppReader(pathAccountSid); + } + + public static ConnectAppUpdater updater(final String pathSid) { + return new ConnectAppUpdater(pathSid); + } + + public static ConnectAppUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new ConnectAppUpdater(pathAccountSid, pathSid); + } + + public enum ConnectAppPermission { GET_ALL("get-all"), POST_ALL("post-all"); private final String value; - private Permission(final String value) { + private ConnectAppPermission(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Permission from a string. - * @param value string value - * @return generated Permission - */ @JsonCreator - public static Permission forValue(final String value) { - return Promoter.enumFromString(value, Permission.values()); + public static ConnectAppPermission forValue(final String value) { + return Promoter.enumFromString( + value, + ConnectAppPermission.values() + ); } } - /** - * Create a ConnectAppFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique connect-app Sid - * @return ConnectAppFetcher capable of executing the fetch - */ - public static ConnectAppFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new ConnectAppFetcher(pathAccountSid, pathSid); - } - - /** - * Create a ConnectAppFetcher to execute fetch. - * - * @param pathSid Fetch by unique connect-app Sid - * @return ConnectAppFetcher capable of executing the fetch - */ - public static ConnectAppFetcher fetcher(final String pathSid) { - return new ConnectAppFetcher(pathSid); - } + public enum Permission { + GET_ALL("get-all"), + POST_ALL("post-all"); - /** - * Create a ConnectAppUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return ConnectAppUpdater capable of executing the update - */ - public static ConnectAppUpdater updater(final String pathAccountSid, - final String pathSid) { - return new ConnectAppUpdater(pathAccountSid, pathSid); - } + private final String value; - /** - * Create a ConnectAppUpdater to execute update. - * - * @param pathSid The sid - * @return ConnectAppUpdater capable of executing the update - */ - public static ConnectAppUpdater updater(final String pathSid) { - return new ConnectAppUpdater(pathSid); - } + private Permission(final String value) { + this.value = value; + } - /** - * Create a ConnectAppReader to execute read. - * - * @param pathAccountSid The account_sid - * @return ConnectAppReader capable of executing the read - */ - public static ConnectAppReader reader(final String pathAccountSid) { - return new ConnectAppReader(pathAccountSid); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a ConnectAppReader to execute read. - * - * @return ConnectAppReader capable of executing the read - */ - public static ConnectAppReader reader() { - return new ConnectAppReader(); + @JsonCreator + public static Permission forValue(final String value) { + return Promoter.enumFromString(value, Permission.values()); + } } /** - * Converts a JSON String into a ConnectApp object using the provided - * ObjectMapper. - * + * Converts a JSON String into a ConnectApp object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return ConnectApp object represented by the provided JSON */ - public static ConnectApp fromJson(final String json, final ObjectMapper objectMapper) { + public static ConnectApp fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ConnectApp.class); @@ -146,12 +153,15 @@ public static ConnectApp fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a ConnectApp object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return ConnectApp object represented by the provided JSON */ - public static ConnectApp fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static ConnectApp fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ConnectApp.class); @@ -162,41 +172,71 @@ public static ConnectApp fromJson(final InputStream json, final ObjectMapper obj } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final URI authorizeRedirectUrl; + + @Getter private final String companyName; + + @Getter private final HttpMethod deauthorizeCallbackMethod; + + @Getter private final URI deauthorizeCallbackUrl; + + @Getter private final String description; + + @Getter private final String friendlyName; + + @Getter private final URI homepageUrl; + + @Getter private final List permissions; + + @Getter private final String sid; + + @Getter private final String uri; @JsonCreator - private ConnectApp(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("authorize_redirect_url") - final URI authorizeRedirectUrl, - @JsonProperty("company_name") - final String companyName, - @JsonProperty("deauthorize_callback_method") - final HttpMethod deauthorizeCallbackMethod, - @JsonProperty("deauthorize_callback_url") - final URI deauthorizeCallbackUrl, - @JsonProperty("description") - final String description, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("homepage_url") - final URI homepageUrl, - @JsonProperty("permissions") - final List permissions, - @JsonProperty("sid") - final String sid, - @JsonProperty("uri") - final String uri) { + private ConnectApp( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("authorize_redirect_url") final URI authorizeRedirectUrl, + @JsonProperty("company_name") final String companyName, + @JsonProperty( + "deauthorize_callback_method" + ) final HttpMethod deauthorizeCallbackMethod, + @JsonProperty( + "deauthorize_callback_url" + ) final URI deauthorizeCallbackUrl, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("homepage_url") final URI homepageUrl, + @JsonProperty("permissions") final List< + ConnectApp.Permission + > permissions, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.authorizeRedirectUrl = authorizeRedirectUrl; this.companyName = companyName; @@ -210,106 +250,6 @@ private ConnectApp(@JsonProperty("account_sid") this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The URIL Twilio sends requests when users authorize. - * - * @return URIL Twilio sends requests when users authorize - */ - public final URI getAuthorizeRedirectUrl() { - return this.authorizeRedirectUrl; - } - - /** - * Returns The The company name set for this Connect App.. - * - * @return The company name set for this Connect App. - */ - public final String getCompanyName() { - return this.companyName; - } - - /** - * Returns The HTTP method Twilio will use making requests to the url. - * - * @return HTTP method Twilio will use making requests to the url - */ - public final HttpMethod getDeauthorizeCallbackMethod() { - return this.deauthorizeCallbackMethod; - } - - /** - * Returns The URL Twilio will send a request when a user de-authorizes this - * app. - * - * @return URL Twilio will send a request when a user de-authorizes this app - */ - public final URI getDeauthorizeCallbackUrl() { - return this.deauthorizeCallbackUrl; - } - - /** - * Returns The A more detailed human readable description. - * - * @return A more detailed human readable description - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The A human readable name for the Connect App.. - * - * @return A human readable name for the Connect App. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The URL users can obtain more information. - * - * @return The URL users can obtain more information - */ - public final URI getHomepageUrl() { - return this.homepageUrl; - } - - /** - * Returns The The set of permissions that your ConnectApp requests.. - * - * @return The set of permissions that your ConnectApp requests. - */ - public final List getPermissions() { - return this.permissions; - } - - /** - * Returns The A string that uniquely identifies this connect-apps. - * - * @return A string that uniquely identifies this connect-apps - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -321,49 +261,41 @@ public boolean equals(final Object o) { } ConnectApp other = (ConnectApp) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(authorizeRedirectUrl, other.authorizeRedirectUrl) && - Objects.equals(companyName, other.companyName) && - Objects.equals(deauthorizeCallbackMethod, other.deauthorizeCallbackMethod) && - Objects.equals(deauthorizeCallbackUrl, other.deauthorizeCallbackUrl) && - Objects.equals(description, other.description) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(homepageUrl, other.homepageUrl) && - Objects.equals(permissions, other.permissions) && - Objects.equals(sid, other.sid) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(authorizeRedirectUrl, other.authorizeRedirectUrl) && + Objects.equals(companyName, other.companyName) && + Objects.equals( + deauthorizeCallbackMethod, + other.deauthorizeCallbackMethod + ) && + Objects.equals( + deauthorizeCallbackUrl, + other.deauthorizeCallbackUrl + ) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(homepageUrl, other.homepageUrl) && + Objects.equals(permissions, other.permissions) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - authorizeRedirectUrl, - companyName, - deauthorizeCallbackMethod, - deauthorizeCallbackUrl, - description, - friendlyName, - homepageUrl, - permissions, - sid, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("authorizeRedirectUrl", authorizeRedirectUrl) - .add("companyName", companyName) - .add("deauthorizeCallbackMethod", deauthorizeCallbackMethod) - .add("deauthorizeCallbackUrl", deauthorizeCallbackUrl) - .add("description", description) - .add("friendlyName", friendlyName) - .add("homepageUrl", homepageUrl) - .add("permissions", permissions) - .add("sid", sid) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + authorizeRedirectUrl, + companyName, + deauthorizeCallbackMethod, + deauthorizeCallbackUrl, + description, + friendlyName, + homepageUrl, + permissions, + sid, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppDeleter.java new file mode 100644 index 0000000000..c408f65804 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppDeleter.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ConnectAppDeleter extends Deleter { + + private String pathAccountSid; + private String pathSid; + + public ConnectAppDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + public ConnectAppDeleter( + final String pathAccountSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConnectApp delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppFetcher.java index b0f3d53dff..7d9a7cdff6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ConnectAppFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new ConnectAppFetcher. - * - * @param pathSid Fetch by unique connect-app Sid - */ public ConnectAppFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ConnectAppFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique connect-app Sid - */ - public ConnectAppFetcher(final String pathAccountSid, - final String pathSid) { + public ConnectAppFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched ConnectApp - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ConnectApp fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/ConnectApps/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ConnectApp fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "ConnectApp fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return ConnectApp.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public ConnectApp fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ConnectApp content = ConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppReader.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppReader.java index c8e5b61eea..5667518e51 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,167 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ConnectAppReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new ConnectAppReader. - */ - public ConnectAppReader() { - } + public ConnectAppReader() {} - /** - * Construct a new ConnectAppReader. - * - * @param pathAccountSid The account_sid - */ public ConnectAppReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ConnectApp ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ConnectAppReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ConnectApp ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "connect_apps", + response.getContent(), + ConnectApp.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/ConnectApps.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/ConnectApps.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return ConnectApp ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "connect_apps", + response.getContent(), + ConnectApp.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ConnectApp read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "connect_apps", + response.getContent(), + ConnectApp.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of ConnectApp Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ConnectApp read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "connect_apps", - response.getContent(), - ConnectApp.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppUpdater.java index bef3c75273..b83e38b156 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ConnectAppUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,13 +28,15 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class ConnectAppUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private URI authorizeRedirectUrl; private String companyName; private HttpMethod deauthorizeCallbackMethod; @@ -33,246 +46,236 @@ public class ConnectAppUpdater extends Updater { private URI homepageUrl; private List permissions; - /** - * Construct a new ConnectAppUpdater. - * - * @param pathSid The sid - */ public ConnectAppUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ConnectAppUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public ConnectAppUpdater(final String pathAccountSid, - final String pathSid) { + public ConnectAppUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * The URL the user's browser will redirect to after Twilio authenticates the - * user and obtains authorization for this Connect App.. - * - * @param authorizeRedirectUrl URIL Twilio sends requests when users authorize - * @return this - */ - public ConnectAppUpdater setAuthorizeRedirectUrl(final URI authorizeRedirectUrl) { + public ConnectAppUpdater setAuthorizeRedirectUrl( + final URI authorizeRedirectUrl + ) { this.authorizeRedirectUrl = authorizeRedirectUrl; return this; } - /** - * The URL the user's browser will redirect to after Twilio authenticates the - * user and obtains authorization for this Connect App.. - * - * @param authorizeRedirectUrl URIL Twilio sends requests when users authorize - * @return this - */ - public ConnectAppUpdater setAuthorizeRedirectUrl(final String authorizeRedirectUrl) { - return setAuthorizeRedirectUrl(Promoter.uriFromString(authorizeRedirectUrl)); + public ConnectAppUpdater setAuthorizeRedirectUrl( + final String authorizeRedirectUrl + ) { + return setAuthorizeRedirectUrl( + Promoter.uriFromString(authorizeRedirectUrl) + ); } - /** - * The company name set for this Connect App.. - * - * @param companyName The company name set for this Connect App. - * @return this - */ public ConnectAppUpdater setCompanyName(final String companyName) { this.companyName = companyName; return this; } - /** - * The HTTP method to be used when making a request to the - * `DeauthorizeCallbackUrl`. Either `GET` or `POST`.. - * - * @param deauthorizeCallbackMethod HTTP method Twilio WIll use making requests - * to the url - * @return this - */ - public ConnectAppUpdater setDeauthorizeCallbackMethod(final HttpMethod deauthorizeCallbackMethod) { + public ConnectAppUpdater setDeauthorizeCallbackMethod( + final HttpMethod deauthorizeCallbackMethod + ) { this.deauthorizeCallbackMethod = deauthorizeCallbackMethod; return this; } - /** - * The URL to which Twilio will send a request when a user de-authorizes this - * Connect App.. - * - * @param deauthorizeCallbackUrl URL Twilio will send a request when a user - * de-authorizes this app - * @return this - */ - public ConnectAppUpdater setDeauthorizeCallbackUrl(final URI deauthorizeCallbackUrl) { + public ConnectAppUpdater setDeauthorizeCallbackUrl( + final URI deauthorizeCallbackUrl + ) { this.deauthorizeCallbackUrl = deauthorizeCallbackUrl; return this; } - /** - * The URL to which Twilio will send a request when a user de-authorizes this - * Connect App.. - * - * @param deauthorizeCallbackUrl URL Twilio will send a request when a user - * de-authorizes this app - * @return this - */ - public ConnectAppUpdater setDeauthorizeCallbackUrl(final String deauthorizeCallbackUrl) { - return setDeauthorizeCallbackUrl(Promoter.uriFromString(deauthorizeCallbackUrl)); + public ConnectAppUpdater setDeauthorizeCallbackUrl( + final String deauthorizeCallbackUrl + ) { + return setDeauthorizeCallbackUrl( + Promoter.uriFromString(deauthorizeCallbackUrl) + ); } - /** - * A more detailed human readable description of the Connect App.. - * - * @param description A more detailed human readable description - * @return this - */ public ConnectAppUpdater setDescription(final String description) { this.description = description; return this; } - /** - * A human readable description of the Connect App, with maximum length 64 - * characters.. - * - * @param friendlyName A human readable name for the Connect App. - * @return this - */ public ConnectAppUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The public URL where users can obtain more information about this Connect - * App.. - * - * @param homepageUrl The URL users can obtain more information - * @return this - */ public ConnectAppUpdater setHomepageUrl(final URI homepageUrl) { this.homepageUrl = homepageUrl; return this; } - /** - * The public URL where users can obtain more information about this Connect - * App.. - * - * @param homepageUrl The URL users can obtain more information - * @return this - */ public ConnectAppUpdater setHomepageUrl(final String homepageUrl) { return setHomepageUrl(Promoter.uriFromString(homepageUrl)); } - /** - * A comma-separated list of permssions you will request from users of this - * ConnectApp. Valid permssions are `get-all` or `post-all`.. - * - * @param permissions The set of permissions that your ConnectApp requests. - * @return this - */ - public ConnectAppUpdater setPermissions(final List permissions) { + public ConnectAppUpdater setPermissions( + final List permissions + ) { this.permissions = permissions; return this; } - /** - * A comma-separated list of permssions you will request from users of this - * ConnectApp. Valid permssions are `get-all` or `post-all`.. - * - * @param permissions The set of permissions that your ConnectApp requests. - * @return this - */ - public ConnectAppUpdater setPermissions(final ConnectApp.Permission permissions) { + public ConnectAppUpdater setPermissions( + final ConnectApp.Permission permissions + ) { return setPermissions(Promoter.listOfOne(permissions)); } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated ConnectApp - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ConnectApp update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/ConnectApps/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/ConnectApps/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ConnectApp update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "ConnectApp update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return ConnectApp.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public ConnectApp update(final TwilioRestClient client) { + Response response = makeRequest(client); + return ConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ConnectApp content = ConnectApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (authorizeRedirectUrl != null) { - request.addPostParam("AuthorizeRedirectUrl", authorizeRedirectUrl.toString()); + Serializer.toString( + request, + "AuthorizeRedirectUrl", + authorizeRedirectUrl, + ParameterType.URLENCODED + ); } if (companyName != null) { - request.addPostParam("CompanyName", companyName); + Serializer.toString( + request, + "CompanyName", + companyName, + ParameterType.URLENCODED + ); } if (deauthorizeCallbackMethod != null) { - request.addPostParam("DeauthorizeCallbackMethod", deauthorizeCallbackMethod.toString()); + Serializer.toString( + request, + "DeauthorizeCallbackMethod", + deauthorizeCallbackMethod, + ParameterType.URLENCODED + ); } if (deauthorizeCallbackUrl != null) { - request.addPostParam("DeauthorizeCallbackUrl", deauthorizeCallbackUrl.toString()); + Serializer.toString( + request, + "DeauthorizeCallbackUrl", + deauthorizeCallbackUrl, + ParameterType.URLENCODED + ); } if (description != null) { - request.addPostParam("Description", description); + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (homepageUrl != null) { - request.addPostParam("HomepageUrl", homepageUrl.toString()); + Serializer.toString( + request, + "HomepageUrl", + homepageUrl, + ParameterType.URLENCODED + ); } if (permissions != null) { - for (ConnectApp.Permission prop : permissions) { - request.addPostParam("Permissions", prop.toString()); + for (ConnectApp.Permission param : permissions) { + Serializer.toString( + request, + "Permissions", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumber.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumber.java index 965fe4adb6..a8d8f42fd8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumber.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumber.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,83 +17,126 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class IncomingPhoneNumber extends Resource { - private static final long serialVersionUID = 145062524051297L; - public enum AddressRequirement { - NONE("none"), - ANY("any"), - LOCAL("local"), - FOREIGN("foreign"); + public static IncomingPhoneNumberCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new IncomingPhoneNumberCreator(phoneNumber); + } - private final String value; + public static IncomingPhoneNumberCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new IncomingPhoneNumberCreator(pathAccountSid, phoneNumber); + } - private AddressRequirement(final String value) { - this.value = value; - } + public static IncomingPhoneNumberCreator creator(final String areaCode) { + return new IncomingPhoneNumberCreator(areaCode); + } - public String toString() { - return value; - } + public static IncomingPhoneNumberCreator creator( + final String pathAccountSid, + final String areaCode + ) { + return new IncomingPhoneNumberCreator(pathAccountSid, areaCode); + } - /** - * Generate a AddressRequirement from a string. - * @param value string value - * @return generated AddressRequirement - */ - @JsonCreator - public static AddressRequirement forValue(final String value) { - return Promoter.enumFromString(value, AddressRequirement.values()); - } + public static IncomingPhoneNumberDeleter deleter(final String pathSid) { + return new IncomingPhoneNumberDeleter(pathSid); } - public enum EmergencyStatus { - ACTIVE("Active"), - INACTIVE("Inactive"); + public static IncomingPhoneNumberDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new IncomingPhoneNumberDeleter(pathAccountSid, pathSid); + } + + public static IncomingPhoneNumberFetcher fetcher(final String pathSid) { + return new IncomingPhoneNumberFetcher(pathSid); + } + + public static IncomingPhoneNumberFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new IncomingPhoneNumberFetcher(pathAccountSid, pathSid); + } + + public static IncomingPhoneNumberReader reader() { + return new IncomingPhoneNumberReader(); + } + + public static IncomingPhoneNumberReader reader( + final String pathAccountSid + ) { + return new IncomingPhoneNumberReader(pathAccountSid); + } + + public static IncomingPhoneNumberUpdater updater(final String pathSid) { + return new IncomingPhoneNumberUpdater(pathSid); + } + + public static IncomingPhoneNumberUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new IncomingPhoneNumberUpdater(pathAccountSid, pathSid); + } + + public enum EmergencyAddressStatus { + REGISTERED("registered"), + UNREGISTERED("unregistered"), + PENDING_REGISTRATION("pending-registration"), + REGISTRATION_FAILURE("registration-failure"), + PENDING_UNREGISTRATION("pending-unregistration"), + UNREGISTRATION_FAILURE("unregistration-failure"); private final String value; - private EmergencyStatus(final String value) { + private EmergencyAddressStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a EmergencyStatus from a string. - * @param value string value - * @return generated EmergencyStatus - */ @JsonCreator - public static EmergencyStatus forValue(final String value) { - return Promoter.enumFromString(value, EmergencyStatus.values()); + public static EmergencyAddressStatus forValue(final String value) { + return Promoter.enumFromString( + value, + EmergencyAddressStatus.values() + ); } } @@ -100,159 +150,72 @@ private VoiceReceiveMode(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a VoiceReceiveMode from a string. - * @param value string value - * @return generated VoiceReceiveMode - */ @JsonCreator public static VoiceReceiveMode forValue(final String value) { return Promoter.enumFromString(value, VoiceReceiveMode.values()); } } - /** - * Create a IncomingPhoneNumberUpdater to execute update. - * - * @param pathAccountSid The new owner of the phone number - * @param pathSid The sid - * @return IncomingPhoneNumberUpdater capable of executing the update - */ - public static IncomingPhoneNumberUpdater updater(final String pathAccountSid, - final String pathSid) { - return new IncomingPhoneNumberUpdater(pathAccountSid, pathSid); - } - - /** - * Create a IncomingPhoneNumberUpdater to execute update. - * - * @param pathSid The sid - * @return IncomingPhoneNumberUpdater capable of executing the update - */ - public static IncomingPhoneNumberUpdater updater(final String pathSid) { - return new IncomingPhoneNumberUpdater(pathSid); - } - - /** - * Create a IncomingPhoneNumberFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique incoming-phone-number Sid - * @return IncomingPhoneNumberFetcher capable of executing the fetch - */ - public static IncomingPhoneNumberFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new IncomingPhoneNumberFetcher(pathAccountSid, pathSid); - } + public enum EmergencyStatus { + ACTIVE("Active"), + INACTIVE("Inactive"); - /** - * Create a IncomingPhoneNumberFetcher to execute fetch. - * - * @param pathSid Fetch by unique incoming-phone-number Sid - * @return IncomingPhoneNumberFetcher capable of executing the fetch - */ - public static IncomingPhoneNumberFetcher fetcher(final String pathSid) { - return new IncomingPhoneNumberFetcher(pathSid); - } + private final String value; - /** - * Create a IncomingPhoneNumberDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique phone-number Sid - * @return IncomingPhoneNumberDeleter capable of executing the delete - */ - public static IncomingPhoneNumberDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new IncomingPhoneNumberDeleter(pathAccountSid, pathSid); - } + private EmergencyStatus(final String value) { + this.value = value; + } - /** - * Create a IncomingPhoneNumberDeleter to execute delete. - * - * @param pathSid Delete by unique phone-number Sid - * @return IncomingPhoneNumberDeleter capable of executing the delete - */ - public static IncomingPhoneNumberDeleter deleter(final String pathSid) { - return new IncomingPhoneNumberDeleter(pathSid); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a IncomingPhoneNumberReader to execute read. - * - * @param pathAccountSid The account_sid - * @return IncomingPhoneNumberReader capable of executing the read - */ - public static IncomingPhoneNumberReader reader(final String pathAccountSid) { - return new IncomingPhoneNumberReader(pathAccountSid); + @JsonCreator + public static EmergencyStatus forValue(final String value) { + return Promoter.enumFromString(value, EmergencyStatus.values()); + } } - /** - * Create a IncomingPhoneNumberReader to execute read. - * - * @return IncomingPhoneNumberReader capable of executing the read - */ - public static IncomingPhoneNumberReader reader() { - return new IncomingPhoneNumberReader(); - } + public enum AddressRequirement { + NONE("none"), + ANY("any"), + LOCAL("local"), + FOREIGN("foreign"); - /** - * Create a IncomingPhoneNumberCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number - * @return IncomingPhoneNumberCreator capable of executing the create - */ - public static IncomingPhoneNumberCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { - return new IncomingPhoneNumberCreator(pathAccountSid, phoneNumber); - } + private final String value; - /** - * Create a IncomingPhoneNumberCreator to execute create. - * - * @param phoneNumber The phone number - * @return IncomingPhoneNumberCreator capable of executing the create - */ - public static IncomingPhoneNumberCreator creator(final com.twilio.type.PhoneNumber phoneNumber) { - return new IncomingPhoneNumberCreator(phoneNumber); - } + private AddressRequirement(final String value) { + this.value = value; + } - /** - * Create a IncomingPhoneNumberCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param areaCode The desired area code for the new number - * @return IncomingPhoneNumberCreator capable of executing the create - */ - public static IncomingPhoneNumberCreator creator(final String pathAccountSid, - final String areaCode) { - return new IncomingPhoneNumberCreator(pathAccountSid, areaCode); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a IncomingPhoneNumberCreator to execute create. - * - * @param areaCode The desired area code for the new number - * @return IncomingPhoneNumberCreator capable of executing the create - */ - public static IncomingPhoneNumberCreator creator(final String areaCode) { - return new IncomingPhoneNumberCreator(areaCode); + @JsonCreator + public static AddressRequirement forValue(final String value) { + return Promoter.enumFromString(value, AddressRequirement.values()); + } } /** - * Converts a JSON String into a IncomingPhoneNumber object using the provided - * ObjectMapper. - * + * Converts a JSON String into a IncomingPhoneNumber object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return IncomingPhoneNumber object represented by the provided JSON */ - public static IncomingPhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + public static IncomingPhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IncomingPhoneNumber.class); @@ -264,14 +227,17 @@ public static IncomingPhoneNumber fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a IncomingPhoneNumber object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a IncomingPhoneNumber object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return IncomingPhoneNumber object represented by the provided JSON */ - public static IncomingPhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static IncomingPhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IncomingPhoneNumber.class); @@ -282,401 +248,218 @@ public static IncomingPhoneNumber fromJson(final InputStream json, final ObjectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String addressSid; + + @Getter private final IncomingPhoneNumber.AddressRequirement addressRequirements; + + @Getter + private final String addressSid; + + @Getter private final String apiVersion; + + @Getter private final Boolean beta; + + @Getter + private final String bundleSid; + + @Getter private final PhoneNumberCapabilities capabilities; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String emergencyAddressSid; + + @Getter + private final IncomingPhoneNumber.EmergencyAddressStatus emergencyAddressStatus; + + @Getter + private final IncomingPhoneNumber.EmergencyStatus emergencyStatus; + + @Getter private final String friendlyName; + + @Getter private final String identitySid; - private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String origin; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String sid; + + @Getter private final String smsApplicationSid; + + @Getter private final HttpMethod smsFallbackMethod; + + @Getter private final URI smsFallbackUrl; + + @Getter private final HttpMethod smsMethod; + + @Getter private final URI smsUrl; + + @Getter + private final String status; + + @Getter private final URI statusCallback; + + @Getter private final HttpMethod statusCallbackMethod; + + @Getter private final String trunkSid; + + @Getter + private final String type; + + @Getter private final String uri; + + @Getter private final String voiceApplicationSid; + + @Getter private final Boolean voiceCallerIdLookup; + + @Getter private final HttpMethod voiceFallbackMethod; + + @Getter private final URI voiceFallbackUrl; + + @Getter private final HttpMethod voiceMethod; + + @Getter + private final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode; + + @Getter private final URI voiceUrl; - private final IncomingPhoneNumber.EmergencyStatus emergencyStatus; - private final String emergencyAddressSid; @JsonCreator - private IncomingPhoneNumber(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("address_sid") - final String addressSid, - @JsonProperty("address_requirements") - final IncomingPhoneNumber.AddressRequirement addressRequirements, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("identity_sid") - final String identitySid, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("origin") - final String origin, - @JsonProperty("sid") - final String sid, - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("status_callback") - final URI statusCallback, - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("uri") - final String uri, - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_url") - final URI voiceUrl, - @JsonProperty("emergency_status") - final IncomingPhoneNumber.EmergencyStatus emergencyStatus, - @JsonProperty("emergency_address_sid") - final String emergencyAddressSid) { + private IncomingPhoneNumber( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "address_requirements" + ) final IncomingPhoneNumber.AddressRequirement addressRequirements, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_address_status" + ) final IncomingPhoneNumber.EmergencyAddressStatus emergencyAddressStatus, + @JsonProperty( + "emergency_status" + ) final IncomingPhoneNumber.EmergencyStatus emergencyStatus, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity_sid") final String identitySid, + @JsonProperty("origin") final String origin, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status") final String status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("type") final String type, + @JsonProperty("uri") final String uri, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty( + "voice_receive_mode" + ) final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode, + @JsonProperty("voice_url") final URI voiceUrl + ) { this.accountSid = accountSid; - this.addressSid = addressSid; this.addressRequirements = addressRequirements; + this.addressSid = addressSid; this.apiVersion = apiVersion; this.beta = beta; + this.bundleSid = bundleSid; this.capabilities = capabilities; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.emergencyAddressSid = emergencyAddressSid; + this.emergencyAddressStatus = emergencyAddressStatus; + this.emergencyStatus = emergencyStatus; this.friendlyName = friendlyName; this.identitySid = identitySid; - this.phoneNumber = phoneNumber; this.origin = origin; + this.phoneNumber = phoneNumber; this.sid = sid; this.smsApplicationSid = smsApplicationSid; this.smsFallbackMethod = smsFallbackMethod; this.smsFallbackUrl = smsFallbackUrl; this.smsMethod = smsMethod; this.smsUrl = smsUrl; + this.status = status; this.statusCallback = statusCallback; this.statusCallbackMethod = statusCallbackMethod; this.trunkSid = trunkSid; + this.type = type; this.uri = uri; this.voiceApplicationSid = voiceApplicationSid; this.voiceCallerIdLookup = voiceCallerIdLookup; this.voiceFallbackMethod = voiceFallbackMethod; this.voiceFallbackUrl = voiceFallbackUrl; this.voiceMethod = voiceMethod; + this.voiceReceiveMode = voiceReceiveMode; this.voiceUrl = voiceUrl; - this.emergencyStatus = emergencyStatus; - this.emergencyAddressSid = emergencyAddressSid; - } - - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Unique string that identifies the address associated with number. - * - * @return Unique string that identifies the address associated with number - */ - public final String getAddressSid() { - return this.addressSid; - } - - /** - * Returns The Indicates if the customer requires an address. - * - * @return Indicates if the customer requires an address - */ - public final IncomingPhoneNumber.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - - /** - * Returns The The Twilio REST API version to use. - * - * @return The Twilio REST API version to use - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The Indicates if the phone number is a beta number. - * - * @return Indicates if the phone number is a beta number - */ - public final Boolean getBeta() { - return this.beta; - } - - /** - * Returns The Indicate if a phone can receive calls or messages. - * - * @return Indicate if a phone can receive calls or messages - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human readable description of this resouce. - * - * @return A human readable description of this resouce - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The Unique string that identifies the identity associated with - * number. - * - * @return Unique string that identifies the identity associated with number - */ - public final String getIdentitySid() { - return this.identitySid; - } - - /** - * Returns The The incoming phone number. - * - * @return The incoming phone number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - - /** - * Returns The Twilio owned phone numbers are marked as twilio while hosted - * phone numbers are marked as hosted.. - * - * @return Twilio owned phone numbers are marked as twilio while hosted phone - * numbers are marked as hosted. - */ - public final String getOrigin() { - return this.origin; - } - - /** - * Returns The A string that uniquely identifies this resource. - * - * @return A string that uniquely identifies this resource - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Unique string that identifies the application. - * - * @return Unique string that identifies the application - */ - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - - /** - * Returns The HTTP method used with sms fallback url. - * - * @return HTTP method used with sms fallback url - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - - /** - * Returns The URL Twilio will request if an error occurs in executing TwiML. - * - * @return URL Twilio will request if an error occurs in executing TwiML - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - - /** - * Returns The HTTP method to use with sms url. - * - * @return HTTP method to use with sms url - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - - /** - * Returns The URL Twilio will request when receiving an SMS. - * - * @return URL Twilio will request when receiving an SMS - */ - public final URI getSmsUrl() { - return this.smsUrl; - } - - /** - * Returns The URL Twilio will use to pass status parameters. - * - * @return URL Twilio will use to pass status parameters - */ - public final URI getStatusCallback() { - return this.statusCallback; - } - - /** - * Returns The HTTP method twilio will use with status callback. - * - * @return HTTP method twilio will use with status callback - */ - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - - /** - * Returns The Unique string to identify the trunk. - * - * @return Unique string to identify the trunk - */ - public final String getTrunkSid() { - return this.trunkSid; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The unique sid of the application to handle this number. - * - * @return The unique sid of the application to handle this number - */ - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - - /** - * Returns The Look up the caller's caller-ID. - * - * @return Look up the caller's caller-ID - */ - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - - /** - * Returns The HTTP method used with fallback_url. - * - * @return HTTP method used with fallback_url - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - - /** - * Returns The URL Twilio will request when an error occurs in TwiML. - * - * @return URL Twilio will request when an error occurs in TwiML - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - - /** - * Returns The HTTP method used with the voice url. - * - * @return HTTP method used with the voice url - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - - /** - * Returns The URL Twilio will request when receiving a call. - * - * @return URL Twilio will request when receiving a call - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } - - /** - * Returns The The emergency_status. - * - * @return The emergency_status - */ - public final IncomingPhoneNumber.EmergencyStatus getEmergencyStatus() { - return this.emergencyStatus; - } - - /** - * Returns The The emergency_address_sid. - * - * @return The emergency_address_sid - */ - public final String getEmergencyAddressSid() { - return this.emergencyAddressSid; } @Override @@ -690,106 +473,86 @@ public boolean equals(final Object o) { } IncomingPhoneNumber other = (IncomingPhoneNumber) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(addressSid, other.addressSid) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(identitySid, other.identitySid) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(origin, other.origin) && - Objects.equals(sid, other.sid) && - Objects.equals(smsApplicationSid, other.smsApplicationSid) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(statusCallback, other.statusCallback) && - Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(uri, other.uri) && - Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && - Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceUrl, other.voiceUrl) && - Objects.equals(emergencyStatus, other.emergencyStatus) && - Objects.equals(emergencyAddressSid, other.emergencyAddressSid); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals( + emergencyAddressStatus, + other.emergencyAddressStatus + ) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identitySid, other.identitySid) && + Objects.equals(origin, other.origin) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(type, other.type) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - addressSid, - addressRequirements, - apiVersion, - beta, - capabilities, - dateCreated, - dateUpdated, - friendlyName, - identitySid, - phoneNumber, - origin, - sid, - smsApplicationSid, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsUrl, - statusCallback, - statusCallbackMethod, - trunkSid, - uri, - voiceApplicationSid, - voiceCallerIdLookup, - voiceFallbackMethod, - voiceFallbackUrl, - voiceMethod, - voiceUrl, - emergencyStatus, - emergencyAddressSid); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("addressSid", addressSid) - .add("addressRequirements", addressRequirements) - .add("apiVersion", apiVersion) - .add("beta", beta) - .add("capabilities", capabilities) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("identitySid", identitySid) - .add("phoneNumber", phoneNumber) - .add("origin", origin) - .add("sid", sid) - .add("smsApplicationSid", smsApplicationSid) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsUrl", smsUrl) - .add("statusCallback", statusCallback) - .add("statusCallbackMethod", statusCallbackMethod) - .add("trunkSid", trunkSid) - .add("uri", uri) - .add("voiceApplicationSid", voiceApplicationSid) - .add("voiceCallerIdLookup", voiceCallerIdLookup) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceMethod", voiceMethod) - .add("voiceUrl", voiceUrl) - .add("emergencyStatus", emergencyStatus) - .add("emergencyAddressSid", emergencyAddressSid) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + addressRequirements, + addressSid, + apiVersion, + beta, + bundleSid, + capabilities, + dateCreated, + dateUpdated, + emergencyAddressSid, + emergencyAddressStatus, + emergencyStatus, + friendlyName, + identitySid, + origin, + phoneNumber, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + status, + statusCallback, + statusCallbackMethod, + trunkSid, + type, + uri, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceReceiveMode, + voiceUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberCreator.java index f2a32d2ed7..457d8266a1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,13 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class IncomingPhoneNumberCreator extends Creator { + private String pathAccountSid; - private com.twilio.type.PhoneNumber phoneNumber; - private String areaCode; private String apiVersion; private String friendlyName; private String smsApplicationSid; @@ -44,532 +55,502 @@ public class IncomingPhoneNumberCreator extends Creator { private String trunkSid; private String identitySid; private String addressSid; + private IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode; + private String bundleSid; + private com.twilio.type.PhoneNumber phoneNumber; + private String areaCode; - /** - * Construct a new IncomingPhoneNumberCreator. - * - * @param phoneNumber The phone number - */ - public IncomingPhoneNumberCreator(final com.twilio.type.PhoneNumber phoneNumber) { + public IncomingPhoneNumberCreator( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; } - /** - * Construct a new IncomingPhoneNumberCreator. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number - */ - public IncomingPhoneNumberCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { + public IncomingPhoneNumberCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - /** - * Construct a new IncomingPhoneNumberCreator. - * - * @param areaCode The desired area code for the new number - */ public IncomingPhoneNumberCreator(final String areaCode) { this.areaCode = areaCode; } - /** - * Construct a new IncomingPhoneNumberCreator. - * - * @param pathAccountSid The account_sid - * @param areaCode The desired area code for the new number - */ - public IncomingPhoneNumberCreator(final String pathAccountSid, - final String areaCode) { + public IncomingPhoneNumberCreator( + final String pathAccountSid, + final String areaCode + ) { this.pathAccountSid = pathAccountSid; this.areaCode = areaCode; } - /** - * The Twilio REST API version to use for incoming calls made to this number. If - * omitted, uses `2010-04-01`.. - * - * @param apiVersion The Twilio Rest API version to use - * @return this - */ public IncomingPhoneNumberCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - /** - * A human readable descriptive text for this resource, up to 64 characters - * long. By default, the `FriendlyName` is a nicely formatted version of the - * phone number.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ - public IncomingPhoneNumberCreator setFriendlyName(final String friendlyName) { + public IncomingPhoneNumberCreator setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - /** - * The 34 character sid of the application Twilio should use to handle SMSs sent - * to the new number. If a `SmsApplicationSid` is present, Twilio will ignore - * all of the SMS urls above and use those set on the application.. - * - * @param smsApplicationSid Unique string that identifies the application - * @return this - */ - public IncomingPhoneNumberCreator setSmsApplicationSid(final String smsApplicationSid) { + public IncomingPhoneNumberCreator setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - /** - * The HTTP method that should be used to request the `SmsFallbackUrl`. Must be - * either `GET` or `POST`. Defaults to `POST`.. - * - * @param smsFallbackMethod HTTP method used with sms fallback url - * @return this - */ - public IncomingPhoneNumberCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public IncomingPhoneNumberCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl URL Twilio will request if an error occurs in - * executing TwiML - * @return this - */ - public IncomingPhoneNumberCreator setSmsFallbackUrl(final URI smsFallbackUrl) { + public IncomingPhoneNumberCreator setSmsFallbackUrl( + final URI smsFallbackUrl + ) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl URL Twilio will request if an error occurs in - * executing TwiML - * @return this - */ - public IncomingPhoneNumberCreator setSmsFallbackUrl(final String smsFallbackUrl) { + public IncomingPhoneNumberCreator setSmsFallbackUrl( + final String smsFallbackUrl + ) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method that should be used to request the `SmsUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param smsMethod HTTP method to use with sms url - * @return this - */ public IncomingPhoneNumberCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * The URL Twilio will request when receiving an incoming SMS message to this - * number.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public IncomingPhoneNumberCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL Twilio will request when receiving an incoming SMS message to this - * number.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public IncomingPhoneNumberCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback URL Twilio will use to pass status parameters - * @return this - */ - public IncomingPhoneNumberCreator setStatusCallback(final URI statusCallback) { + public IncomingPhoneNumberCreator setStatusCallback( + final URI statusCallback + ) { this.statusCallback = statusCallback; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback URL Twilio will use to pass status parameters - * @return this - */ - public IncomingPhoneNumberCreator setStatusCallback(final String statusCallback) { + public IncomingPhoneNumberCreator setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio will use to make requests to the `StatusCallback` URL. - * Either `GET` or `POST`. Defaults to `POST`.. - * - * @param statusCallbackMethod HTTP method twilio will use with status callback - * @return this - */ - public IncomingPhoneNumberCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public IncomingPhoneNumberCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * The 34 character sid of the application Twilio should use to handle phone - * calls to the new number. If a `VoiceApplicationSid` is present, Twilio will - * ignore all of the voice urls above and use those set on the application. - * Setting a `VoiceApplicationSid` will automatically delete your `TrunkSid` and - * vice versa.. - * - * @param voiceApplicationSid The unique sid of the application to handle this - * number - * @return this - */ - public IncomingPhoneNumberCreator setVoiceApplicationSid(final String voiceApplicationSid) { + public IncomingPhoneNumberCreator setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - /** - * Do a lookup of a caller's name from the CNAM database and post it to your - * app. Either `true` or `false`. Defaults to `false`.. - * - * @param voiceCallerIdLookup Look up the caller's caller-ID - * @return this - */ - public IncomingPhoneNumberCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup) { + public IncomingPhoneNumberCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - /** - * The HTTP method that should be used to request the `VoiceFallbackUrl`. Either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceFallbackMethod HTTP method used with fallback_url - * @return this - */ - public IncomingPhoneNumberCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public IncomingPhoneNumberCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * The URL that Twilio will request if an error occurs retrieving or executing - * the TwiML requested by `Url`.. - * - * @param voiceFallbackUrl URL Twilio will request when an error occurs in TwiML - * @return this - */ - public IncomingPhoneNumberCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { + public IncomingPhoneNumberCreator setVoiceFallbackUrl( + final URI voiceFallbackUrl + ) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * The URL that Twilio will request if an error occurs retrieving or executing - * the TwiML requested by `Url`.. - * - * @param voiceFallbackUrl URL Twilio will request when an error occurs in TwiML - * @return this - */ - public IncomingPhoneNumberCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { + public IncomingPhoneNumberCreator setVoiceFallbackUrl( + final String voiceFallbackUrl + ) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method that should be used to request the `VoiceUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceMethod HTTP method used with the voice url - * @return this - */ - public IncomingPhoneNumberCreator setVoiceMethod(final HttpMethod voiceMethod) { + public IncomingPhoneNumberCreator setVoiceMethod( + final HttpMethod voiceMethod + ) { this.voiceMethod = voiceMethod; return this; } - /** - * The URL that Twilio should request when somebody dials the new phone number. - * The VoiceURL will no longer be used if a `VoiceApplicationSid` or a - * `TrunkSid` is set.. - * - * @param voiceUrl URL Twilio will request when receiving a call - * @return this - */ public IncomingPhoneNumberCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The URL that Twilio should request when somebody dials the new phone number. - * The VoiceURL will no longer be used if a `VoiceApplicationSid` or a - * `TrunkSid` is set.. - * - * @param voiceUrl URL Twilio will request when receiving a call - * @return this - */ public IncomingPhoneNumberCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The emergency_status. - * - * @param emergencyStatus The emergency_status - * @return this - */ - public IncomingPhoneNumberCreator setEmergencyStatus(final IncomingPhoneNumber.EmergencyStatus emergencyStatus) { + public IncomingPhoneNumberCreator setEmergencyStatus( + final IncomingPhoneNumber.EmergencyStatus emergencyStatus + ) { this.emergencyStatus = emergencyStatus; return this; } - /** - * The emergency_address_sid. - * - * @param emergencyAddressSid The emergency_address_sid - * @return this - */ - public IncomingPhoneNumberCreator setEmergencyAddressSid(final String emergencyAddressSid) { + public IncomingPhoneNumberCreator setEmergencyAddressSid( + final String emergencyAddressSid + ) { this.emergencyAddressSid = emergencyAddressSid; return this; } - /** - * The 34 character sid of the Trunk Twilio should use to handle phone calls to - * this number. If a `TrunkSid` is present, Twilio will ignore all of the voice - * urls and voice applications above and use those set on the Trunk. Setting a - * `TrunkSid` will automatically delete your `VoiceApplicationSid` and vice - * versa.. - * - * @param trunkSid Unique string to identify the trunk - * @return this - */ public IncomingPhoneNumberCreator setTrunkSid(final String trunkSid) { this.trunkSid = trunkSid; return this; } - /** - * The 34 character sid of the identity Twilio should use to associate with the - * number. Identities are required in some regions to meet local regulations. - * - * @param identitySid Unique string that identifies the identity associated - * with number - * @return this - */ public IncomingPhoneNumberCreator setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - /** - * The 34 character sid of the address Twilio should use to associate with the - * number. Addresses are required in some regions to meet local regulations. - * - * @param addressSid Unique string that identifies the address associated with - * number - * @return this - */ public IncomingPhoneNumberCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - /** - * The phone number you want to purchase. The number should be formatted - * starting with a '+' followed by the country code and the number in - * [E.164](http://en.wikipedia.org/wiki/E.164) format e.g., '+15105555555'. - * **You must include either this or an `AreaCode` parameter to have your POST - * succeed.**. - * - * @param phoneNumber The phone number - * @return this - */ - public IncomingPhoneNumberCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public IncomingPhoneNumberCreator setVoiceReceiveMode( + final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode + ) { + this.voiceReceiveMode = voiceReceiveMode; + return this; + } + + public IncomingPhoneNumberCreator setBundleSid(final String bundleSid) { + this.bundleSid = bundleSid; + return this; + } + + public IncomingPhoneNumberCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * The phone number you want to purchase. The number should be formatted - * starting with a '+' followed by the country code and the number in - * [E.164](http://en.wikipedia.org/wiki/E.164) format e.g., '+15105555555'. - * **You must include either this or an `AreaCode` parameter to have your POST - * succeed.**. - * - * @param phoneNumber The phone number - * @return this - */ public IncomingPhoneNumberCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * The desired area code for your new incoming phone number. Any three digit, US - * or Canada area code is valid. Twilio will provision a random phone number - * within this area code for you. **You must include either this or a - * `PhoneNumber` parameter to have your POST succeed.** (US and Canada only). - * - * @param areaCode The desired area code for the new number - * @return this - */ public IncomingPhoneNumberCreator setAreaCode(final String areaCode) { this.areaCode = areaCode; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created IncomingPhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IncomingPhoneNumber create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IncomingPhoneNumber creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } - - return IncomingPhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + return response; } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (phoneNumber != null) { - request.addPostParam("PhoneNumber", phoneNumber.toString()); - } + @Override + public IncomingPhoneNumber create(final TwilioRestClient client) { + Response response = makeRequest(client); + return IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - if (areaCode != null) { - request.addPostParam("AreaCode", areaCode); - } + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IncomingPhoneNumber content = IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (apiVersion != null) { - request.addPostParam("ApiVersion", apiVersion); + Serializer.toString( + request, + "ApiVersion", + apiVersion, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (smsApplicationSid != null) { - request.addPostParam("SmsApplicationSid", smsApplicationSid); + Serializer.toString( + request, + "SmsApplicationSid", + smsApplicationSid, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (voiceApplicationSid != null) { - request.addPostParam("VoiceApplicationSid", voiceApplicationSid); + Serializer.toString( + request, + "VoiceApplicationSid", + voiceApplicationSid, + ParameterType.URLENCODED + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); + Serializer.toString( + request, + "VoiceCallerIdLookup", + voiceCallerIdLookup, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (emergencyStatus != null) { - request.addPostParam("EmergencyStatus", emergencyStatus.toString()); + Serializer.toString( + request, + "EmergencyStatus", + emergencyStatus, + ParameterType.URLENCODED + ); } if (emergencyAddressSid != null) { - request.addPostParam("EmergencyAddressSid", emergencyAddressSid); + Serializer.toString( + request, + "EmergencyAddressSid", + emergencyAddressSid, + ParameterType.URLENCODED + ); } if (trunkSid != null) { - request.addPostParam("TrunkSid", trunkSid); + Serializer.toString( + request, + "TrunkSid", + trunkSid, + ParameterType.URLENCODED + ); } if (identitySid != null) { - request.addPostParam("IdentitySid", identitySid); + Serializer.toString( + request, + "IdentitySid", + identitySid, + ParameterType.URLENCODED + ); } if (addressSid != null) { - request.addPostParam("AddressSid", addressSid); + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); + } + + if (voiceReceiveMode != null) { + Serializer.toString( + request, + "VoiceReceiveMode", + voiceReceiveMode, + ParameterType.URLENCODED + ); + } + + if (bundleSid != null) { + Serializer.toString( + request, + "BundleSid", + bundleSid, + ParameterType.URLENCODED + ); + } + + if (phoneNumber != null) { + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); + } + + if (areaCode != null) { + Serializer.toString( + request, + "AreaCode", + areaCode, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberDeleter.java index ad12511159..d4f81bf039 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class IncomingPhoneNumberDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new IncomingPhoneNumberDeleter. - * - * @param pathSid Delete by unique phone-number Sid - */ public IncomingPhoneNumberDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new IncomingPhoneNumberDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique phone-number Sid - */ - public IncomingPhoneNumberDeleter(final String pathAccountSid, - final String pathSid) { + public IncomingPhoneNumberDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IncomingPhoneNumber delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberFetcher.java index 10a6d9f622..60e5a1cf3e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IncomingPhoneNumberFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new IncomingPhoneNumberFetcher. - * - * @param pathSid Fetch by unique incoming-phone-number Sid - */ public IncomingPhoneNumberFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new IncomingPhoneNumberFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique incoming-phone-number Sid - */ - public IncomingPhoneNumberFetcher(final String pathAccountSid, - final String pathSid) { + public IncomingPhoneNumberFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched IncomingPhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IncomingPhoneNumber fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IncomingPhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return IncomingPhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public IncomingPhoneNumber fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IncomingPhoneNumber content = IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberReader.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberReader.java index 71baca918c..90c9928b0d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,248 +17,263 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IncomingPhoneNumberReader extends Reader { + private String pathAccountSid; private Boolean beta; private String friendlyName; private com.twilio.type.PhoneNumber phoneNumber; private String origin; + private Long pageSize; - /** - * Construct a new IncomingPhoneNumberReader. - */ - public IncomingPhoneNumberReader() { - } + public IncomingPhoneNumberReader() {} - /** - * Construct a new IncomingPhoneNumberReader. - * - * @param pathAccountSid The account_sid - */ public IncomingPhoneNumberReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Include phone numbers new to the Twilio platform. Possible values are either - * `true` or `false`. Default is `true`.. - * - * @param beta Include new phone numbers - * @return this - */ public IncomingPhoneNumberReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * Only show the incoming phone number resources with friendly names that - * exactly match this name.. - * - * @param friendlyName Filter by friendly name - * @return this - */ - public IncomingPhoneNumberReader setFriendlyName(final String friendlyName) { + public IncomingPhoneNumberReader setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - /** - * Only show the incoming phone number resources that match this pattern. You - * can specify partial numbers and use '*' as a wildcard for any digit.. - * - * @param phoneNumber Filter by incoming phone number - * @return this - */ - public IncomingPhoneNumberReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public IncomingPhoneNumberReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * Only show the incoming phone number resources that match this pattern. You - * can specify partial numbers and use '*' as a wildcard for any digit.. - * - * @param phoneNumber Filter by incoming phone number - * @return this - */ public IncomingPhoneNumberReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * Include phone numbers based on the origin, by default, phone numbers of all - * origin are included. Possible values are either `twilio` or `hosted`.. - * - * @param origin Include phone numbers based on the origin, by default, phone - * numbers of all origin are included. - * @return this - */ public IncomingPhoneNumberReader setOrigin(final String origin) { this.origin = origin; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IncomingPhoneNumber ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public IncomingPhoneNumberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IncomingPhoneNumber ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + IncomingPhoneNumber.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return IncomingPhoneNumber ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + IncomingPhoneNumber.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "IncomingPhoneNumber read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + IncomingPhoneNumber.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of IncomingPhoneNumber Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "incoming_phone_numbers", - response.getContent(), - IncomingPhoneNumber.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); } if (origin != null) { - request.addQueryParam("Origin", origin); + Serializer.toString(request, "Origin", origin, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberUpdater.java index f706b9fbea..4d7915d0f1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/IncomingPhoneNumberUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class IncomingPhoneNumberUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private String accountSid; private String apiVersion; private String friendlyName; @@ -45,493 +58,466 @@ public class IncomingPhoneNumberUpdater extends Updater { private IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode; private String identitySid; private String addressSid; + private String bundleSid; - /** - * Construct a new IncomingPhoneNumberUpdater. - * - * @param pathSid The sid - */ public IncomingPhoneNumberUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new IncomingPhoneNumberUpdater. - * - * @param pathAccountSid The new owner of the phone number - * @param pathSid The sid - */ - public IncomingPhoneNumberUpdater(final String pathAccountSid, - final String pathSid) { + public IncomingPhoneNumberUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * The unique 34 character id of the account to which you wish to transfer this - * phone number. See [Exchanging Numbers Between - * Subaccounts](https://www.twilio.com/docs/iam/api/subaccounts#exchanging-numbers).. - * - * @param accountSid The new owner of the phone number - * @return this - */ public IncomingPhoneNumberUpdater setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } - /** - * Calls to this phone number will start a new TwiML session with this API - * version. Either `2010-04-01` or `2008-08-01`.. - * - * @param apiVersion The Twilio REST API version to use - * @return this - */ public IncomingPhoneNumberUpdater setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - /** - * A human readable descriptive text for this resource, up to 64 characters - * long. By default, the `FriendlyName` is a nicely formatted version of the - * phone number.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ - public IncomingPhoneNumberUpdater setFriendlyName(final String friendlyName) { + public IncomingPhoneNumberUpdater setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - /** - * The 34 character sid of the application Twilio should use to handle SMSs sent - * to this number. If a `SmsApplicationSid` is present, Twilio will ignore all - * of the SMS urls above and use those set on the application instead.. - * - * @param smsApplicationSid Unique string that identifies the application - * @return this - */ - public IncomingPhoneNumberUpdater setSmsApplicationSid(final String smsApplicationSid) { + public IncomingPhoneNumberUpdater setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - /** - * The HTTP method that should be used to request the `SmsFallbackUrl`. Either - * `GET` or `POST`.. - * - * @param smsFallbackMethod HTTP method used with sms fallback url - * @return this - */ - public IncomingPhoneNumberUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public IncomingPhoneNumberUpdater setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl URL Twilio will request if an error occurs in - * executing TwiML - * @return this - */ - public IncomingPhoneNumberUpdater setSmsFallbackUrl(final URI smsFallbackUrl) { + public IncomingPhoneNumberUpdater setSmsFallbackUrl( + final URI smsFallbackUrl + ) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl URL Twilio will request if an error occurs in - * executing TwiML - * @return this - */ - public IncomingPhoneNumberUpdater setSmsFallbackUrl(final String smsFallbackUrl) { + public IncomingPhoneNumberUpdater setSmsFallbackUrl( + final String smsFallbackUrl + ) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method Twilio will use when making requests to the `SmsUrl`. Either - * `GET` or `POST`.. - * - * @param smsMethod HTTP method to use with sms url - * @return this - */ public IncomingPhoneNumberUpdater setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the new - * phone number.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public IncomingPhoneNumberUpdater setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the new - * phone number.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public IncomingPhoneNumberUpdater setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback URL Twilio will use to pass status parameters - * @return this - */ - public IncomingPhoneNumberUpdater setStatusCallback(final URI statusCallback) { + public IncomingPhoneNumberUpdater setStatusCallback( + final URI statusCallback + ) { this.statusCallback = statusCallback; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback URL Twilio will use to pass status parameters - * @return this - */ - public IncomingPhoneNumberUpdater setStatusCallback(final String statusCallback) { + public IncomingPhoneNumberUpdater setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio will use to make requests to the `StatusCallback` URL. - * Either `GET` or `POST`.. - * - * @param statusCallbackMethod HTTP method twilio will use with status callback - * @return this - */ - public IncomingPhoneNumberUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public IncomingPhoneNumberUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * The 34 character sid of the application Twilio should use to handle phone - * calls to this number. If a `VoiceApplicationSid` is present, Twilio will - * ignore all of the voice urls above and use those set on the application - * instead. Setting a `VoiceApplicationSid` will automatically delete your - * `TrunkSid` and vice versa.. - * - * @param voiceApplicationSid The unique sid of the application to handle this - * number - * @return this - */ - public IncomingPhoneNumberUpdater setVoiceApplicationSid(final String voiceApplicationSid) { + public IncomingPhoneNumberUpdater setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - /** - * Look up the caller's caller-ID name from the CNAM database ($0.01 per look - * up). Either `true` or `false`.. - * - * @param voiceCallerIdLookup Look up the caller's caller-ID - * @return this - */ - public IncomingPhoneNumberUpdater setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup) { + public IncomingPhoneNumberUpdater setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - /** - * The HTTP method Twilio will use when requesting the `VoiceFallbackUrl`. - * Either `GET` or `POST`.. - * - * @param voiceFallbackMethod HTTP method used with fallback_url - * @return this - */ - public IncomingPhoneNumberUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public IncomingPhoneNumberUpdater setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `VoiceUrl`.. - * - * @param voiceFallbackUrl URL Twilio will request when an error occurs in TwiML - * @return this - */ - public IncomingPhoneNumberUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl) { + public IncomingPhoneNumberUpdater setVoiceFallbackUrl( + final URI voiceFallbackUrl + ) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `VoiceUrl`.. - * - * @param voiceFallbackUrl URL Twilio will request when an error occurs in TwiML - * @return this - */ - public IncomingPhoneNumberUpdater setVoiceFallbackUrl(final String voiceFallbackUrl) { + public IncomingPhoneNumberUpdater setVoiceFallbackUrl( + final String voiceFallbackUrl + ) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method Twilio will use when requesting the above `Url`. Either `GET` - * or `POST`.. - * - * @param voiceMethod HTTP method used with the voice url - * @return this - */ - public IncomingPhoneNumberUpdater setVoiceMethod(final HttpMethod voiceMethod) { + public IncomingPhoneNumberUpdater setVoiceMethod( + final HttpMethod voiceMethod + ) { this.voiceMethod = voiceMethod; return this; } - /** - * The URL that Twilio should request when somebody dials the phone number. The - * VoiceURL will no longer be used if a `VoiceApplicationSid` or a `TrunkSid` - * is set.. - * - * @param voiceUrl URL Twilio will request when receiving a call - * @return this - */ public IncomingPhoneNumberUpdater setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The URL that Twilio should request when somebody dials the phone number. The - * VoiceURL will no longer be used if a `VoiceApplicationSid` or a `TrunkSid` - * is set.. - * - * @param voiceUrl URL Twilio will request when receiving a call - * @return this - */ public IncomingPhoneNumberUpdater setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The emergency_status. - * - * @param emergencyStatus The emergency_status - * @return this - */ - public IncomingPhoneNumberUpdater setEmergencyStatus(final IncomingPhoneNumber.EmergencyStatus emergencyStatus) { + public IncomingPhoneNumberUpdater setEmergencyStatus( + final IncomingPhoneNumber.EmergencyStatus emergencyStatus + ) { this.emergencyStatus = emergencyStatus; return this; } - /** - * The emergency_address_sid. - * - * @param emergencyAddressSid The emergency_address_sid - * @return this - */ - public IncomingPhoneNumberUpdater setEmergencyAddressSid(final String emergencyAddressSid) { + public IncomingPhoneNumberUpdater setEmergencyAddressSid( + final String emergencyAddressSid + ) { this.emergencyAddressSid = emergencyAddressSid; return this; } - /** - * The 34 character sid of the Trunk Twilio should use to handle phone calls to - * this number. If a `TrunkSid` is present, Twilio will ignore all of the voice - * urls and voice applications above and use those set on the Trunk. Setting a - * `TrunkSid` will automatically delete your `VoiceApplicationSid` and vice - * versa.. - * - * @param trunkSid Unique string to identify the trunk - * @return this - */ public IncomingPhoneNumberUpdater setTrunkSid(final String trunkSid) { this.trunkSid = trunkSid; return this; } - /** - * The voice_receive_mode. - * - * @param voiceReceiveMode The voice_receive_mode - * @return this - */ - public IncomingPhoneNumberUpdater setVoiceReceiveMode(final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode) { + public IncomingPhoneNumberUpdater setVoiceReceiveMode( + final IncomingPhoneNumber.VoiceReceiveMode voiceReceiveMode + ) { this.voiceReceiveMode = voiceReceiveMode; return this; } - /** - * The 34 character sid of the identity Twilio should use to associate with the - * number. Identities are required in some regions to meet local regulations. - * - * @param identitySid Unique string that identifies the identity associated - * with number - * @return this - */ public IncomingPhoneNumberUpdater setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - /** - * The 34 character sid of the address Twilio should associate with the number. - * If the number has address restrictions, only another address that satisfies - * the requirement can replace the existing one.. - * - * @param addressSid Unique string that identifies the address associated with - * number - * @return this - */ public IncomingPhoneNumberUpdater setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated IncomingPhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IncomingPhoneNumber update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public IncomingPhoneNumberUpdater setBundleSid(final String bundleSid) { + this.bundleSid = bundleSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IncomingPhoneNumber update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IncomingPhoneNumber update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public IncomingPhoneNumber update(final TwilioRestClient client) { + Response response = makeRequest(client); + return IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return IncomingPhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IncomingPhoneNumber content = IncomingPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (accountSid != null) { - request.addPostParam("AccountSid", accountSid); + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.URLENCODED + ); } if (apiVersion != null) { - request.addPostParam("ApiVersion", apiVersion); + Serializer.toString( + request, + "ApiVersion", + apiVersion, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (smsApplicationSid != null) { - request.addPostParam("SmsApplicationSid", smsApplicationSid); + Serializer.toString( + request, + "SmsApplicationSid", + smsApplicationSid, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (voiceApplicationSid != null) { - request.addPostParam("VoiceApplicationSid", voiceApplicationSid); + Serializer.toString( + request, + "VoiceApplicationSid", + voiceApplicationSid, + ParameterType.URLENCODED + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); + Serializer.toString( + request, + "VoiceCallerIdLookup", + voiceCallerIdLookup, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (emergencyStatus != null) { - request.addPostParam("EmergencyStatus", emergencyStatus.toString()); + Serializer.toString( + request, + "EmergencyStatus", + emergencyStatus, + ParameterType.URLENCODED + ); } if (emergencyAddressSid != null) { - request.addPostParam("EmergencyAddressSid", emergencyAddressSid); + Serializer.toString( + request, + "EmergencyAddressSid", + emergencyAddressSid, + ParameterType.URLENCODED + ); } if (trunkSid != null) { - request.addPostParam("TrunkSid", trunkSid); + Serializer.toString( + request, + "TrunkSid", + trunkSid, + ParameterType.URLENCODED + ); } if (voiceReceiveMode != null) { - request.addPostParam("VoiceReceiveMode", voiceReceiveMode.toString()); + Serializer.toString( + request, + "VoiceReceiveMode", + voiceReceiveMode, + ParameterType.URLENCODED + ); } if (identitySid != null) { - request.addPostParam("IdentitySid", identitySid); + Serializer.toString( + request, + "IdentitySid", + identitySid, + ParameterType.URLENCODED + ); } if (addressSid != null) { - request.addPostParam("AddressSid", addressSid); + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); + } + + if (bundleSid != null) { + Serializer.toString( + request, + "BundleSid", + bundleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Key.java b/src/main/java/com/twilio/rest/api/v2010/account/Key.java index 73a72c5633..3990de5aee 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Key.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Key.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,123 +18,80 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Key extends Resource { - private static final long serialVersionUID = 96350302686036L; - - /** - * Create a KeyFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return KeyFetcher capable of executing the fetch - */ - public static KeyFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new KeyFetcher(pathAccountSid, pathSid); - } - /** - * Create a KeyFetcher to execute fetch. - * - * @param pathSid The sid - * @return KeyFetcher capable of executing the fetch - */ - public static KeyFetcher fetcher(final String pathSid) { - return new KeyFetcher(pathSid); + public static KeyDeleter deleter(final String pathSid) { + return new KeyDeleter(pathSid); } - /** - * Create a KeyUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return KeyUpdater capable of executing the update - */ - public static KeyUpdater updater(final String pathAccountSid, - final String pathSid) { - return new KeyUpdater(pathAccountSid, pathSid); + public static KeyDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new KeyDeleter(pathAccountSid, pathSid); } - /** - * Create a KeyUpdater to execute update. - * - * @param pathSid The sid - * @return KeyUpdater capable of executing the update - */ - public static KeyUpdater updater(final String pathSid) { - return new KeyUpdater(pathSid); + public static KeyFetcher fetcher(final String pathSid) { + return new KeyFetcher(pathSid); } - /** - * Create a KeyDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return KeyDeleter capable of executing the delete - */ - public static KeyDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new KeyDeleter(pathAccountSid, pathSid); + public static KeyFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new KeyFetcher(pathAccountSid, pathSid); } - /** - * Create a KeyDeleter to execute delete. - * - * @param pathSid The sid - * @return KeyDeleter capable of executing the delete - */ - public static KeyDeleter deleter(final String pathSid) { - return new KeyDeleter(pathSid); + public static KeyReader reader() { + return new KeyReader(); } - /** - * Create a KeyReader to execute read. - * - * @param pathAccountSid The account_sid - * @return KeyReader capable of executing the read - */ public static KeyReader reader(final String pathAccountSid) { return new KeyReader(pathAccountSid); } - /** - * Create a KeyReader to execute read. - * - * @return KeyReader capable of executing the read - */ - public static KeyReader reader() { - return new KeyReader(); + public static KeyUpdater updater(final String pathSid) { + return new KeyUpdater(pathSid); + } + + public static KeyUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new KeyUpdater(pathAccountSid, pathSid); } /** * Converts a JSON String into a Key object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Key object represented by the provided JSON */ - public static Key fromJson(final String json, final ObjectMapper objectMapper) { + public static Key fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Key.class); @@ -141,12 +105,15 @@ public static Key fromJson(final String json, final ObjectMapper objectMapper) { /** * Converts a JSON InputStream into a Key object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Key object represented by the provided JSON */ - public static Key fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Key fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Key.class); @@ -157,66 +124,45 @@ public static Key fromJson(final InputStream json, final ObjectMapper objectMapp } } - private final String sid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private Key(@JsonProperty("sid") - final String sid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this API Key.. - * - * @return A 34 character string that uniquely identifies this API Key. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The A descriptive string for this resource, chosen by your - * application, up to 64 characters long.. - * - * @return A descriptive string for this resource, chosen by your application, - * up to 64 characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date-time this API Key was created, given as a RFC 2822 - * Timestamp.. - * - * @return The date-time this API Key was created, given as a RFC 2822 - * Timestamp. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String friendlyName; - /** - * Returns The The date-time this API Key was most recently updated, given as a - * RFC 2822 Timestamp.. - * - * @return The date-time this API Key was most recently updated, given as a - * RFC 2822 Timestamp. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; + @Getter + private final String sid; + + @JsonCreator + private Key( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; } @Override @@ -230,28 +176,16 @@ public boolean equals(final Object o) { } Key other = (Key) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(sid, - friendlyName, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); + return Objects.hash(dateCreated, dateUpdated, friendlyName, sid); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/KeyDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/KeyDeleter.java index a0f7a5ff76..2c2d119cb8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/KeyDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/KeyDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class KeyDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new KeyDeleter. - * - * @param pathSid The sid - */ public KeyDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new KeyDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public KeyDeleter(final String pathAccountSid, - final String pathSid) { + public KeyDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Keys/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Key delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/KeyFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/KeyFetcher.java index 9740ac6fd7..ea13ba4db3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/KeyFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/KeyFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,85 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class KeyFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new KeyFetcher. - * - * @param pathSid The sid - */ public KeyFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new KeyFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public KeyFetcher(final String pathAccountSid, - final String pathSid) { + public KeyFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Key - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Key fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Keys/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Key fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Key fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Key.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Key content = Key.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/KeyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/KeyReader.java index a6f3e25536..9e357edd54 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/KeyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/KeyReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,167 +17,197 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class KeyReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new KeyReader. - */ - public KeyReader() { - } + public KeyReader() {} - /** - * Construct a new KeyReader. - * - * @param pathAccountSid The account_sid - */ public KeyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Key ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public KeyReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Key ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "keys", + response.getContent(), + Key.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Keys.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Keys.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Key ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "keys", + response.getContent(), + Key.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Key read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "keys", + response.getContent(), + Key.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Key Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Key read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "keys", - response.getContent(), - Key.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/KeyUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/KeyUpdater.java index cf553b01f9..02f23abe51 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/KeyUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/KeyUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,94 +27,104 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class KeyUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private String friendlyName; - /** - * Construct a new KeyUpdater. - * - * @param pathSid The sid - */ public KeyUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new KeyUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public KeyUpdater(final String pathAccountSid, - final String pathSid) { + public KeyUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * A descriptive string for this resource, chosen by your application, up to 64 - * characters long.. - * - * @param friendlyName A descriptive string for this resource, chosen by your - * application, up to 64 characters long. - * @return this - */ public KeyUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Key - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Key update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Keys/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Keys/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Key update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Key update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Key update(final TwilioRestClient client) { + Response response = makeRequest(client); return Key.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Key content = Key.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Message.java b/src/main/java/com/twilio/rest/api/v2010/account/Message.java index c570f3ac5a..e4b9a00da5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Message.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Message.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,36 +17,153 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.math.BigDecimal; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Currency; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Message extends Resource { - private static final long serialVersionUID = 61377418909039L; + + public static MessageCreator creator( + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final String body + ) { + return new MessageCreator(to, from, body); + } + + public static MessageCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final String body + ) { + return new MessageCreator(pathAccountSid, to, from, body); + } + + public static MessageCreator creator( + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final List mediaUrl + ) { + return new MessageCreator(to, from, mediaUrl); + } + + public static MessageCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final List mediaUrl + ) { + return new MessageCreator(pathAccountSid, to, from, mediaUrl); + } + + public static MessageCreator creator( + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final String body + ) { + return new MessageCreator(to, messagingServiceSid, body); + } + + public static MessageCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final String body + ) { + return new MessageCreator( + pathAccountSid, + to, + messagingServiceSid, + body + ); + } + + public static MessageCreator creator( + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final List mediaUrl + ) { + return new MessageCreator(to, messagingServiceSid, mediaUrl); + } + + public static MessageCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final List mediaUrl + ) { + return new MessageCreator( + pathAccountSid, + to, + messagingServiceSid, + mediaUrl + ); + } + + public static MessageDeleter deleter(final String pathSid) { + return new MessageDeleter(pathSid); + } + + public static MessageDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new MessageDeleter(pathAccountSid, pathSid); + } + + public static MessageFetcher fetcher(final String pathSid) { + return new MessageFetcher(pathSid); + } + + public static MessageFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new MessageFetcher(pathAccountSid, pathSid); + } + + public static MessageReader reader() { + return new MessageReader(); + } + + public static MessageReader reader(final String pathAccountSid) { + return new MessageReader(pathAccountSid); + } + + public static MessageUpdater updater(final String pathSid) { + return new MessageUpdater(pathSid); + } + + public static MessageUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new MessageUpdater(pathAccountSid, pathSid); + } public enum Status { QUEUED("queued"), @@ -50,7 +174,11 @@ public enum Status { UNDELIVERED("undelivered"), RECEIVING("receiving"), RECEIVED("received"), - ACCEPTED("accepted"); + ACCEPTED("accepted"), + SCHEDULED("scheduled"), + READ("read"), + PARTIALLY_DELIVERED("partially_delivered"), + CANCELED("canceled"); private final String value; @@ -58,45 +186,75 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } - public enum Direction { - INBOUND("inbound"), - OUTBOUND_API("outbound-api"), - OUTBOUND_CALL("outbound-call"), - OUTBOUND_REPLY("outbound-reply"); + public enum ScheduleType { + FIXED("fixed"); private final String value; - private Direction(final String value) { + private ScheduleType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Direction from a string. - * @param value string value - * @return generated Direction - */ @JsonCreator - public static Direction forValue(final String value) { - return Promoter.enumFromString(value, Direction.values()); + public static ScheduleType forValue(final String value) { + return Promoter.enumFromString(value, ScheduleType.values()); + } + } + + public enum RiskCheck { + ENABLE("enable"), + DISABLE("disable"); + + private final String value; + + private RiskCheck(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RiskCheck forValue(final String value) { + return Promoter.enumFromString(value, RiskCheck.values()); + } + } + + public enum UpdateStatus { + CANCELED("canceled"); + + private final String value; + + private UpdateStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static UpdateStatus forValue(final String value) { + return Promoter.enumFromString(value, UpdateStatus.values()); } } @@ -110,15 +268,11 @@ private ContentRetention(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ContentRetention from a string. - * @param value string value - * @return generated ContentRetention - */ @JsonCreator public static ContentRetention forValue(final String value) { return Promoter.enumFromString(value, ContentRetention.values()); @@ -127,7 +281,7 @@ public static ContentRetention forValue(final String value) { public enum AddressRetention { RETAIN("retain"), - DISCARD("discard"); + OBFUSCATE("obfuscate"); private final String value; @@ -135,248 +289,71 @@ private AddressRetention(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a AddressRetention from a string. - * @param value string value - * @return generated AddressRetention - */ @JsonCreator public static AddressRetention forValue(final String value) { return Promoter.enumFromString(value, AddressRetention.values()); } } - /** - * Create a MessageCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param to The phone number to receive the message - * @param from The phone number that initiated the message - * @param body The text of the message you want to send, limited to 1600 - * characters. - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from, - final String body) { - return new MessageCreator(pathAccountSid, to, from, body); - } - - /** - * Create a MessageCreator to execute create. - * - * @param to The phone number to receive the message - * @param from The phone number that initiated the message - * @param body The text of the message you want to send, limited to 1600 - * characters. - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from, - final String body) { - return new MessageCreator(to, from, body); - } - - /** - * Create a MessageCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param to The phone number to receive the message - * @param from The phone number that initiated the message - * @param mediaUrl The URL of the media you wish to send out with the message. - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from, - final List mediaUrl) { - return new MessageCreator(pathAccountSid, to, from, mediaUrl); - } - - /** - * Create a MessageCreator to execute create. - * - * @param to The phone number to receive the message - * @param from The phone number that initiated the message - * @param mediaUrl The URL of the media you wish to send out with the message. - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from, - final List mediaUrl) { - return new MessageCreator(to, from, mediaUrl); - } - - /** - * Create a MessageCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param to The phone number to receive the message - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @param body The text of the message you want to send, limited to 1600 - * characters. - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber to, - final String messagingServiceSid, - final String body) { - return new MessageCreator(pathAccountSid, to, messagingServiceSid, body); - } - - /** - * Create a MessageCreator to execute create. - * - * @param to The phone number to receive the message - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @param body The text of the message you want to send, limited to 1600 - * characters. - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final com.twilio.type.PhoneNumber to, - final String messagingServiceSid, - final String body) { - return new MessageCreator(to, messagingServiceSid, body); - } - - /** - * Create a MessageCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param to The phone number to receive the message - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @param mediaUrl The URL of the media you wish to send out with the message. - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber to, - final String messagingServiceSid, - final List mediaUrl) { - return new MessageCreator(pathAccountSid, to, messagingServiceSid, mediaUrl); - } + public enum Direction { + INBOUND("inbound"), + OUTBOUND_API("outbound-api"), + OUTBOUND_CALL("outbound-call"), + OUTBOUND_REPLY("outbound-reply"); - /** - * Create a MessageCreator to execute create. - * - * @param to The phone number to receive the message - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @param mediaUrl The URL of the media you wish to send out with the message. - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final com.twilio.type.PhoneNumber to, - final String messagingServiceSid, - final List mediaUrl) { - return new MessageCreator(to, messagingServiceSid, mediaUrl); - } + private final String value; - /** - * Create a MessageDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid The message to delete - * @return MessageDeleter capable of executing the delete - */ - public static MessageDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new MessageDeleter(pathAccountSid, pathSid); - } + private Direction(final String value) { + this.value = value; + } - /** - * Create a MessageDeleter to execute delete. - * - * @param pathSid The message to delete - * @return MessageDeleter capable of executing the delete - */ - public static MessageDeleter deleter(final String pathSid) { - return new MessageDeleter(pathSid); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a MessageFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique message Sid - * @return MessageFetcher capable of executing the fetch - */ - public static MessageFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new MessageFetcher(pathAccountSid, pathSid); + @JsonCreator + public static Direction forValue(final String value) { + return Promoter.enumFromString(value, Direction.values()); + } } - /** - * Create a MessageFetcher to execute fetch. - * - * @param pathSid Fetch by unique message Sid - * @return MessageFetcher capable of executing the fetch - */ - public static MessageFetcher fetcher(final String pathSid) { - return new MessageFetcher(pathSid); - } + public enum TrafficType { + FREE("free"); - /** - * Create a MessageReader to execute read. - * - * @param pathAccountSid The account_sid - * @return MessageReader capable of executing the read - */ - public static MessageReader reader(final String pathAccountSid) { - return new MessageReader(pathAccountSid); - } + private final String value; - /** - * Create a MessageReader to execute read. - * - * @return MessageReader capable of executing the read - */ - public static MessageReader reader() { - return new MessageReader(); - } + private TrafficType(final String value) { + this.value = value; + } - /** - * Create a MessageUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The message to redact - * @param body The text of the message you want to send, limited to 1600 - * characters. - * @return MessageUpdater capable of executing the update - */ - public static MessageUpdater updater(final String pathAccountSid, - final String pathSid, - final String body) { - return new MessageUpdater(pathAccountSid, pathSid, body); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a MessageUpdater to execute update. - * - * @param pathSid The message to redact - * @param body The text of the message you want to send, limited to 1600 - * characters. - * @return MessageUpdater capable of executing the update - */ - public static MessageUpdater updater(final String pathSid, - final String body) { - return new MessageUpdater(pathSid, body); + @JsonCreator + public static TrafficType forValue(final String value) { + return Promoter.enumFromString(value, TrafficType.values()); + } } /** * Converts a JSON String into a Message object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -390,12 +367,15 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Message object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -406,75 +386,118 @@ public static Message fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; + + @Getter private final String body; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final DateTime dateSent; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateSent; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final Message.Direction direction; + + @Getter private final Integer errorCode; + + @Getter private final String errorMessage; + + @Getter private final com.twilio.type.PhoneNumber from; + + @Getter private final String messagingServiceSid; + + @Getter private final String numMedia; + + @Getter private final String numSegments; - private final BigDecimal price; + + @Getter + private final String price; + + @Getter private final Currency priceUnit; + + @Getter private final String sid; + + @Getter private final Message.Status status; + + @Getter private final Map subresourceUris; + + @Getter private final String to; + + @Getter private final String uri; @JsonCreator - private Message(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("body") - final String body, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("date_sent") - final String dateSent, - @JsonProperty("direction") - final Message.Direction direction, - @JsonProperty("error_code") - final Integer errorCode, - @JsonProperty("error_message") - final String errorMessage, - @JsonProperty("from") - final com.twilio.type.PhoneNumber from, - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - @JsonProperty("num_media") - final String numMedia, - @JsonProperty("num_segments") - final String numSegments, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("sid") - final String sid, - @JsonProperty("status") - final Message.Status status, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("to") - final String to, - @JsonProperty("uri") - final String uri) { + private Message( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("body") final String body, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_sent") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateSent, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("direction") final Message.Direction direction, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("error_message") final String errorMessage, + @JsonProperty("from") final com.twilio.type.PhoneNumber from, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("num_media") final String numMedia, + @JsonProperty("num_segments") final String numSegments, + @JsonProperty("price") final String price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Message.Status status, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("to") final String to, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; this.body = body; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.dateSent = DateConverter.rfc2822DateTimeFromString(dateSent); + this.dateCreated = dateCreated; + this.dateSent = dateSent; + this.dateUpdated = dateUpdated; this.direction = direction; this.errorCode = errorCode; this.errorMessage = errorMessage; @@ -491,186 +514,6 @@ private Message(@JsonProperty("account_sid") this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The version of the Twilio API used to process the message.. - * - * @return The version of the Twilio API used to process the message. - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The text body of the message. Up to 1600 characters long.. - * - * @return The text body of the message. Up to 1600 characters long. - */ - public final String getBody() { - return this.body; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The date the message was sent. - * - * @return The date the message was sent - */ - public final DateTime getDateSent() { - return this.dateSent; - } - - /** - * Returns The The direction of the message. - * - * @return The direction of the message - */ - public final Message.Direction getDirection() { - return this.direction; - } - - /** - * Returns The The error code associated with the message. - * - * @return The error code associated with the message - */ - public final Integer getErrorCode() { - return this.errorCode; - } - - /** - * Returns The Human readable description of the ErrorCode. - * - * @return Human readable description of the ErrorCode - */ - public final String getErrorMessage() { - return this.errorMessage; - } - - /** - * Returns The The phone number that initiated the message. - * - * @return The phone number that initiated the message - */ - public final com.twilio.type.PhoneNumber getFrom() { - return this.from; - } - - /** - * Returns The The unique id of the Messaging Service used with the message.. - * - * @return The unique id of the Messaging Service used with the message. - */ - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } - - /** - * Returns The Number of media files associated with the message. - * - * @return Number of media files associated with the message - */ - public final String getNumMedia() { - return this.numMedia; - } - - /** - * Returns The Indicates number of messages used to delivery the body. - * - * @return Indicates number of messages used to delivery the body - */ - public final String getNumSegments() { - return this.numSegments; - } - - /** - * Returns The The amount billed for the message. - * - * @return The amount billed for the message - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured. - * - * @return The currency in which Price is measured - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The A string that uniquely identifies this message. - * - * @return A string that uniquely identifies this message - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The status of this message. - * - * @return The status of this message - */ - public final Message.Status getStatus() { - return this.status; - } - - /** - * Returns The The URI for any subresources. - * - * @return The URI for any subresources - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The phone number that received the message. - * - * @return The phone number that received the message - */ - public final String getTo() { - return this.to; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -682,76 +525,53 @@ public boolean equals(final Object o) { } Message other = (Message) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(body, other.body) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(dateSent, other.dateSent) && - Objects.equals(direction, other.direction) && - Objects.equals(errorCode, other.errorCode) && - Objects.equals(errorMessage, other.errorMessage) && - Objects.equals(from, other.from) && - Objects.equals(messagingServiceSid, other.messagingServiceSid) && - Objects.equals(numMedia, other.numMedia) && - Objects.equals(numSegments, other.numSegments) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(sid, other.sid) && - Objects.equals(status, other.status) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(to, other.to) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(body, other.body) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateSent, other.dateSent) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(direction, other.direction) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorMessage, other.errorMessage) && + Objects.equals(from, other.from) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(numMedia, other.numMedia) && + Objects.equals(numSegments, other.numSegments) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(to, other.to) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - body, - dateCreated, - dateUpdated, - dateSent, - direction, - errorCode, - errorMessage, - from, - messagingServiceSid, - numMedia, - numSegments, - price, - priceUnit, - sid, - status, - subresourceUris, - to, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("body", body) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("dateSent", dateSent) - .add("direction", direction) - .add("errorCode", errorCode) - .add("errorMessage", errorMessage) - .add("from", from) - .add("messagingServiceSid", messagingServiceSid) - .add("numMedia", numMedia) - .add("numSegments", numSegments) - .add("price", price) - .add("priceUnit", priceUnit) - .add("sid", sid) - .add("status", status) - .add("subresourceUris", subresourceUris) - .add("to", to) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + body, + dateCreated, + dateSent, + dateUpdated, + direction, + errorCode, + errorMessage, + from, + messagingServiceSid, + numMedia, + numSegments, + price, + priceUnit, + sid, + status, + subresourceUris, + to, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java index 5783105806..72d2d5a767 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,553 +28,601 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.math.BigDecimal; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; public class MessageCreator extends Creator { + private String pathAccountSid; - private final com.twilio.type.PhoneNumber to; - private com.twilio.type.PhoneNumber from; - private String messagingServiceSid; - private String body; - private List mediaUrl; + private com.twilio.type.PhoneNumber to; private URI statusCallback; private String applicationSid; private BigDecimal maxPrice; private Boolean provideFeedback; + private Integer attempt; private Integer validityPeriod; - private String maxRate; private Boolean forceDelivery; - private String providerSid; private Message.ContentRetention contentRetention; private Message.AddressRetention addressRetention; private Boolean smartEncoded; + private List persistentAction; + private Message.TrafficType trafficType; + private Boolean shortenUrls; + private Message.ScheduleType scheduleType; + private ZonedDateTime sendAt; + private Boolean sendAsMms; + private String contentVariables; + private String messageIntent; + private Message.RiskCheck riskCheck; + private com.twilio.type.PhoneNumber from; + private com.twilio.type.PhoneNumber fallbackFrom; + private String messagingServiceSid; + private String body; + private List mediaUrl; + private String contentSid; - /** - * Construct a new MessageCreator. - * - * @param to The phone number to receive the message - * @param from The phone number that initiated the message - * @param body The text of the message you want to send, limited to 1600 - * characters. - */ - public MessageCreator(final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from, - final String body) { + public MessageCreator( + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final String body + ) { this.to = to; this.from = from; this.body = body; } - /** - * Construct a new MessageCreator. - * - * @param pathAccountSid The account_sid - * @param to The phone number to receive the message - * @param from The phone number that initiated the message - * @param body The text of the message you want to send, limited to 1600 - * characters. - */ - public MessageCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from, - final String body) { + public MessageCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final String body + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.body = body; } - /** - * Construct a new MessageCreator. - * - * @param to The phone number to receive the message - * @param from The phone number that initiated the message - * @param mediaUrl The URL of the media you wish to send out with the message. - */ - public MessageCreator(final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from, - final List mediaUrl) { + public MessageCreator( + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final List mediaUrl + ) { this.to = to; this.from = from; this.mediaUrl = mediaUrl; } - /** - * Construct a new MessageCreator. - * - * @param pathAccountSid The account_sid - * @param to The phone number to receive the message - * @param from The phone number that initiated the message - * @param mediaUrl The URL of the media you wish to send out with the message. - */ - public MessageCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from, - final List mediaUrl) { + public MessageCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from, + final List mediaUrl + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.from = from; this.mediaUrl = mediaUrl; } - /** - * Construct a new MessageCreator. - * - * @param to The phone number to receive the message - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @param body The text of the message you want to send, limited to 1600 - * characters. - */ - public MessageCreator(final com.twilio.type.PhoneNumber to, - final String messagingServiceSid, - final String body) { + public MessageCreator( + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final String body + ) { this.to = to; this.messagingServiceSid = messagingServiceSid; this.body = body; } - /** - * Construct a new MessageCreator. - * - * @param pathAccountSid The account_sid - * @param to The phone number to receive the message - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @param body The text of the message you want to send, limited to 1600 - * characters. - */ - public MessageCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber to, - final String messagingServiceSid, - final String body) { + public MessageCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final String body + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.messagingServiceSid = messagingServiceSid; this.body = body; } - /** - * Construct a new MessageCreator. - * - * @param to The phone number to receive the message - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @param mediaUrl The URL of the media you wish to send out with the message. - */ - public MessageCreator(final com.twilio.type.PhoneNumber to, - final String messagingServiceSid, - final List mediaUrl) { + public MessageCreator( + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final List mediaUrl + ) { this.to = to; this.messagingServiceSid = messagingServiceSid; this.mediaUrl = mediaUrl; } - /** - * Construct a new MessageCreator. - * - * @param pathAccountSid The account_sid - * @param to The phone number to receive the message - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @param mediaUrl The URL of the media you wish to send out with the message. - */ - public MessageCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber to, - final String messagingServiceSid, - final List mediaUrl) { + public MessageCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber to, + final String messagingServiceSid, + final List mediaUrl + ) { this.pathAccountSid = pathAccountSid; this.to = to; this.messagingServiceSid = messagingServiceSid; this.mediaUrl = mediaUrl; } - /** - * A URL where Twilio will POST each time your message status changes to one of - * the following: `queued`, `failed`, `sent`, `delivered`, or `undelivered`. - * Twilio will POST the `MessageSid` along with the other [standard request - * parameters](https://www.twilio.com/docs/api/twiml/sms/twilio_request#request-parameters) as well as `MessageStatus` and `ErrorCode`. If this parameter passed in addition to a `MessagingServiceSid`, Twilio will override the Status Callback URL of the [Messaging Service](https://www.twilio.com/docs/api/messaging/send-messages#messaging-services). URLs must contain a valid hostname (underscores are not allowed).. - * - * @param statusCallback URL Twilio will request when the status changes - * @return this - */ + public MessageCreator setTo(final com.twilio.type.PhoneNumber to) { + this.to = to; + return this; + } + + public MessageCreator setTo(final String to) { + return setTo(Promoter.phoneNumberFromString(to)); + } + public MessageCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * A URL where Twilio will POST each time your message status changes to one of - * the following: `queued`, `failed`, `sent`, `delivered`, or `undelivered`. - * Twilio will POST the `MessageSid` along with the other [standard request - * parameters](https://www.twilio.com/docs/api/twiml/sms/twilio_request#request-parameters) as well as `MessageStatus` and `ErrorCode`. If this parameter passed in addition to a `MessagingServiceSid`, Twilio will override the Status Callback URL of the [Messaging Service](https://www.twilio.com/docs/api/messaging/send-messages#messaging-services). URLs must contain a valid hostname (underscores are not allowed).. - * - * @param statusCallback URL Twilio will request when the status changes - * @return this - */ public MessageCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * Twilio will POST `MessageSid` as well as `MessageStatus=sent` or - * `MessageStatus=failed` to the URL in the `MessageStatusCallback` property of - * this [Application](https://www.twilio.com/docs/api/rest/applications). If the - * `StatusCallback` parameter above is also passed, the Application's - * `MessageStatusCallback` parameter will take precedence.. - * - * @param applicationSid The application to use for callbacks - * @return this - */ public MessageCreator setApplicationSid(final String applicationSid) { this.applicationSid = applicationSid; return this; } - /** - * The total maximum price up to the fourth decimal (0.0001) in US dollars - * acceptable for the message to be delivered. All messages regardless of the - * price point will be queued for delivery. A POST request will later be made to - * your Status Callback URL with a status change of 'Sent' or 'Failed'. When the - * price of the message is above this value the message will fail and not be - * sent. When MaxPrice is not set, all prices for the message is accepted.. - * - * @param maxPrice The total maximum price up to the fourth decimal in US - * dollars acceptable for the message to be delivered. - * @return this - */ public MessageCreator setMaxPrice(final BigDecimal maxPrice) { this.maxPrice = maxPrice; return this; } - /** - * Set this value to `true` if you are sending messages that have a trackable - * user action and you intend to confirm delivery of the message using the - * [Message Feedback - * API](https://www.twilio.com/docs/api/messaging/message-feedback). This - * parameter is set to `false` by default.. - * - * @param provideFeedback Set this value to true if you are sending messages - * that have a trackable user action and you intend to - * confirm delivery of the message using the Message - * Feedback API. - * @return this - */ public MessageCreator setProvideFeedback(final Boolean provideFeedback) { this.provideFeedback = provideFeedback; return this; } - /** - * The number of seconds that the message can remain in a Twilio queue. After - * exceeding this time limit, the message will fail and a POST request will - * later be made to your Status Callback URL. Valid values are between 1 and - * 14400 seconds (the default). Please note that Twilio cannot guarantee that a - * message will not be queued by the carrier after they accept the message. We - * do not recommend setting validity periods of less than 5 seconds.. - * - * @param validityPeriod The number of seconds that the message can remain in a - * Twilio queue. - * @return this - */ - public MessageCreator setValidityPeriod(final Integer validityPeriod) { - this.validityPeriod = validityPeriod; + public MessageCreator setAttempt(final Integer attempt) { + this.attempt = attempt; return this; } - /** - * The max_rate. - * - * @param maxRate The max_rate - * @return this - */ - public MessageCreator setMaxRate(final String maxRate) { - this.maxRate = maxRate; + public MessageCreator setValidityPeriod(final Integer validityPeriod) { + this.validityPeriod = validityPeriod; return this; } - /** - * The force_delivery. - * - * @param forceDelivery The force_delivery - * @return this - */ public MessageCreator setForceDelivery(final Boolean forceDelivery) { this.forceDelivery = forceDelivery; return this; } - /** - * The provider_sid. - * - * @param providerSid The provider_sid - * @return this - */ - public MessageCreator setProviderSid(final String providerSid) { - this.providerSid = providerSid; - return this; - } - - /** - * The content_retention. - * - * @param contentRetention The content_retention - * @return this - */ - public MessageCreator setContentRetention(final Message.ContentRetention contentRetention) { + public MessageCreator setContentRetention( + final Message.ContentRetention contentRetention + ) { this.contentRetention = contentRetention; return this; } - /** - * The address_retention. - * - * @param addressRetention The address_retention - * @return this - */ - public MessageCreator setAddressRetention(final Message.AddressRetention addressRetention) { + public MessageCreator setAddressRetention( + final Message.AddressRetention addressRetention + ) { this.addressRetention = addressRetention; return this; } - /** - * The smart_encoded. - * - * @param smartEncoded The smart_encoded - * @return this - */ public MessageCreator setSmartEncoded(final Boolean smartEncoded) { this.smartEncoded = smartEncoded; return this; } - /** - * A Twilio phone number (in - * [E.164](https://www.twilio.com/docs/glossary/what-e164) format), - * [alphanumeric sender - * ID](https://www.twilio.com/docs/api/messaging/send-messages#alpha-sender-id) - * or a [Channel Endpoint - * address](https://www.twilio.com/docs/api/channels#channel-addresses) enabled - * for the type of message you wish to send. Phone numbers or [short - * codes](https://www.twilio.com/docs/sms/api/short-codes) purchased from Twilio - * work here. You cannot (for example) spoof messages from your own cell phone - * number. *Should not be passed if you are using MessagingServiceSid.*. - * - * @param from The phone number that initiated the message - * @return this - */ + public MessageCreator setPersistentAction( + final List persistentAction + ) { + this.persistentAction = persistentAction; + return this; + } + + public MessageCreator setPersistentAction(final String persistentAction) { + return setPersistentAction(Promoter.listOfOne(persistentAction)); + } + + public MessageCreator setTrafficType( + final Message.TrafficType trafficType + ) { + this.trafficType = trafficType; + return this; + } + + public MessageCreator setShortenUrls(final Boolean shortenUrls) { + this.shortenUrls = shortenUrls; + return this; + } + + public MessageCreator setScheduleType( + final Message.ScheduleType scheduleType + ) { + this.scheduleType = scheduleType; + return this; + } + + public MessageCreator setSendAt(final ZonedDateTime sendAt) { + this.sendAt = sendAt; + return this; + } + + public MessageCreator setSendAsMms(final Boolean sendAsMms) { + this.sendAsMms = sendAsMms; + return this; + } + + public MessageCreator setContentVariables(final String contentVariables) { + this.contentVariables = contentVariables; + return this; + } + + public MessageCreator setMessageIntent(final String messageIntent) { + this.messageIntent = messageIntent; + return this; + } + + public MessageCreator setRiskCheck(final Message.RiskCheck riskCheck) { + this.riskCheck = riskCheck; + return this; + } + public MessageCreator setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - /** - * A Twilio phone number (in - * [E.164](https://www.twilio.com/docs/glossary/what-e164) format), - * [alphanumeric sender - * ID](https://www.twilio.com/docs/api/messaging/send-messages#alpha-sender-id) - * or a [Channel Endpoint - * address](https://www.twilio.com/docs/api/channels#channel-addresses) enabled - * for the type of message you wish to send. Phone numbers or [short - * codes](https://www.twilio.com/docs/sms/api/short-codes) purchased from Twilio - * work here. You cannot (for example) spoof messages from your own cell phone - * number. *Should not be passed if you are using MessagingServiceSid.*. - * - * @param from The phone number that initiated the message - * @return this - */ public MessageCreator setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - /** - * The 34 character unique id of the [Messaging - * Service](https://www.twilio.com/docs/api/messaging/send-messages#messaging-services) you want to associate with this Message. Set this parameter to use the Messaging Service Settings and [Copilot Features](https://www.twilio.com/docs/api/messaging/send-messages-copilot) you have configured. When only this parameter is set, Twilio will use your enabled Copilot Features to select the From phone number for delivery. *Should not be passed if you are using From.*. - * - * @param messagingServiceSid The 34 character unique id of the Messaging - * Service you want to associate with this Message. - * @return this - */ - public MessageCreator setMessagingServiceSid(final String messagingServiceSid) { + public MessageCreator setFallbackFrom( + final com.twilio.type.PhoneNumber fallbackFrom + ) { + this.fallbackFrom = fallbackFrom; + return this; + } + + public MessageCreator setFallbackFrom(final String fallbackFrom) { + return setFallbackFrom(Promoter.phoneNumberFromString(fallbackFrom)); + } + + public MessageCreator setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - /** - * The text of the message you want to send, limited to 1600 characters.. - * - * @param body The text of the message you want to send, limited to 1600 - * characters. - * @return this - */ public MessageCreator setBody(final String body) { this.body = body; return this; } - /** - * The URL of the media you wish to send out with the message. `gif` , `png` and - * `jpeg` content is currently supported and will be formatted correctly on the - * recipient's device. [Other - * types](https://www.twilio.com/docs/api/messaging/accepted-mime-types) are - * also accepted by the API. The media size limit is 5MB. If you wish to send - * more than one image in the message body, please provide multiple MediaUrls - * values in the POST request. You may include up to 10 MediaUrls per message.. - * - * @param mediaUrl The URL of the media you wish to send out with the message. - * @return this - */ public MessageCreator setMediaUrl(final List mediaUrl) { this.mediaUrl = mediaUrl; return this; } - /** - * The URL of the media you wish to send out with the message. `gif` , `png` and - * `jpeg` content is currently supported and will be formatted correctly on the - * recipient's device. [Other - * types](https://www.twilio.com/docs/api/messaging/accepted-mime-types) are - * also accepted by the API. The media size limit is 5MB. If you wish to send - * more than one image in the message body, please provide multiple MediaUrls - * values in the POST request. You may include up to 10 MediaUrls per message.. - * - * @param mediaUrl The URL of the media you wish to send out with the message. - * @return this - */ public MessageCreator setMediaUrl(final URI mediaUrl) { return setMediaUrl(Promoter.listOfOne(mediaUrl)); } - /** - * The URL of the media you wish to send out with the message. `gif` , `png` and - * `jpeg` content is currently supported and will be formatted correctly on the - * recipient's device. [Other - * types](https://www.twilio.com/docs/api/messaging/accepted-mime-types) are - * also accepted by the API. The media size limit is 5MB. If you wish to send - * more than one image in the message body, please provide multiple MediaUrls - * values in the POST request. You may include up to 10 MediaUrls per message.. - * - * @param mediaUrl The URL of the media you wish to send out with the message. - * @return this - */ public MessageCreator setMediaUrl(final String mediaUrl) { return setMediaUrl(Promoter.uriFromString(mediaUrl)); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public MessageCreator setContentSid(final String contentSid) { + this.contentSid = contentSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Messages.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message create(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (to != null) { - request.addPostParam("To", to.toString()); + Serializer.toString(request, "To", to, ParameterType.URLENCODED); } - if (from != null) { - request.addPostParam("From", from.toString()); + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } - if (messagingServiceSid != null) { - request.addPostParam("MessagingServiceSid", messagingServiceSid); + if (applicationSid != null) { + Serializer.toString( + request, + "ApplicationSid", + applicationSid, + ParameterType.URLENCODED + ); } - if (body != null) { - request.addPostParam("Body", body); + if (maxPrice != null) { + Serializer.toString( + request, + "MaxPrice", + maxPrice, + ParameterType.URLENCODED + ); } - if (mediaUrl != null) { - for (URI prop : mediaUrl) { - request.addPostParam("MediaUrl", prop.toString()); + if (provideFeedback != null) { + Serializer.toString( + request, + "ProvideFeedback", + provideFeedback, + ParameterType.URLENCODED + ); + } + + if (attempt != null) { + Serializer.toString( + request, + "Attempt", + attempt, + ParameterType.URLENCODED + ); + } + + if (validityPeriod != null) { + Serializer.toString( + request, + "ValidityPeriod", + validityPeriod, + ParameterType.URLENCODED + ); + } + + if (forceDelivery != null) { + Serializer.toString( + request, + "ForceDelivery", + forceDelivery, + ParameterType.URLENCODED + ); + } + + if (contentRetention != null) { + Serializer.toString( + request, + "ContentRetention", + contentRetention, + ParameterType.URLENCODED + ); + } + + if (addressRetention != null) { + Serializer.toString( + request, + "AddressRetention", + addressRetention, + ParameterType.URLENCODED + ); + } + + if (smartEncoded != null) { + Serializer.toString( + request, + "SmartEncoded", + smartEncoded, + ParameterType.URLENCODED + ); + } + + if (persistentAction != null) { + for (String param : persistentAction) { + Serializer.toString( + request, + "PersistentAction", + param, + ParameterType.URLENCODED + ); } } - if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + if (trafficType != null) { + Serializer.toString( + request, + "TrafficType", + trafficType, + ParameterType.URLENCODED + ); } - if (applicationSid != null) { - request.addPostParam("ApplicationSid", applicationSid); + if (shortenUrls != null) { + Serializer.toString( + request, + "ShortenUrls", + shortenUrls, + ParameterType.URLENCODED + ); } - if (maxPrice != null) { - request.addPostParam("MaxPrice", maxPrice.toString()); + if (scheduleType != null) { + Serializer.toString( + request, + "ScheduleType", + scheduleType, + ParameterType.URLENCODED + ); } - if (provideFeedback != null) { - request.addPostParam("ProvideFeedback", provideFeedback.toString()); + if (sendAt != null) { + Serializer.toString( + request, + "SendAt", + sendAt, + ParameterType.URLENCODED + ); } - if (validityPeriod != null) { - request.addPostParam("ValidityPeriod", validityPeriod.toString()); + if (sendAsMms != null) { + Serializer.toString( + request, + "SendAsMms", + sendAsMms, + ParameterType.URLENCODED + ); } - if (maxRate != null) { - request.addPostParam("MaxRate", maxRate); + if (contentVariables != null) { + Serializer.toString( + request, + "ContentVariables", + contentVariables, + ParameterType.URLENCODED + ); } - if (forceDelivery != null) { - request.addPostParam("ForceDelivery", forceDelivery.toString()); + if (messageIntent != null) { + Serializer.toString( + request, + "MessageIntent", + messageIntent, + ParameterType.URLENCODED + ); } - if (providerSid != null) { - request.addPostParam("ProviderSid", providerSid); + if (riskCheck != null) { + Serializer.toString( + request, + "RiskCheck", + riskCheck, + ParameterType.URLENCODED + ); } - if (contentRetention != null) { - request.addPostParam("ContentRetention", contentRetention.toString()); + if (from != null) { + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } - if (addressRetention != null) { - request.addPostParam("AddressRetention", addressRetention.toString()); + if (fallbackFrom != null) { + Serializer.toString( + request, + "FallbackFrom", + fallbackFrom, + ParameterType.URLENCODED + ); } - if (smartEncoded != null) { - request.addPostParam("SmartEncoded", smartEncoded.toString()); + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (body != null) { + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); + } + + if (mediaUrl != null) { + for (URI param : mediaUrl) { + Serializer.toString( + request, + "MediaUrl", + param, + ParameterType.URLENCODED + ); + } + } + + if (contentSid != null) { + Serializer.toString( + request, + "ContentSid", + contentSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageDeleter.java index 3ddb8e8b47..ec272b92e3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MessageDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new MessageDeleter. - * - * @param pathSid The message to delete - */ public MessageDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new MessageDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid The message to delete - */ - public MessageDeleter(final String pathAccountSid, - final String pathSid) { + public MessageDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageFetcher.java index c293edf179..8dbd359268 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,85 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new MessageFetcher. - * - * @param pathSid Fetch by unique message Sid - */ public MessageFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new MessageFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique message Sid - */ - public MessageFetcher(final String pathAccountSid, - final String pathSid) { + public MessageFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageReader.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageReader.java index 936ecaa015..9c3ed2327c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageReader.java @@ -1,274 +1,273 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; -import com.google.common.collect.Range; import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MessageReader extends Reader { + private String pathAccountSid; private com.twilio.type.PhoneNumber to; private com.twilio.type.PhoneNumber from; - private DateTime absoluteDateSent; - private Range rangeDateSent; + private ZonedDateTime dateSent; + private ZonedDateTime dateSentBefore; + private ZonedDateTime dateSentAfter; + private Long pageSize; - /** - * Construct a new MessageReader. - */ - public MessageReader() { - } + public MessageReader() {} - /** - * Construct a new MessageReader. - * - * @param pathAccountSid The account_sid - */ public MessageReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only show messages to this phone number.. - * - * @param to Filter by messages to this number - * @return this - */ public MessageReader setTo(final com.twilio.type.PhoneNumber to) { this.to = to; return this; } - /** - * Only show messages to this phone number.. - * - * @param to Filter by messages to this number - * @return this - */ public MessageReader setTo(final String to) { return setTo(Promoter.phoneNumberFromString(to)); } - /** - * Only show messages from this phone number or alphanumeric sender ID.. - * - * @param from Filter by from number - * @return this - */ public MessageReader setFrom(final com.twilio.type.PhoneNumber from) { this.from = from; return this; } - /** - * Only show messages from this phone number or alphanumeric sender ID.. - * - * @param from Filter by from number - * @return this - */ public MessageReader setFrom(final String from) { return setFrom(Promoter.phoneNumberFromString(from)); } - /** - * Only show messages sent on this date (in - * [GMT](https://en.wikipedia.org/wiki/Greenwich_Mean_Time) format), given as - * `YYYY-MM-DD`. Example: `DateSent=2009-07-06`. You can also specify - * inequality, such as `DateSent<=YYYY-MM-DD` for messages that were sent on - * or before midnight on a date, and `DateSent>=YYYY-MM-DD` for messages sent - * on or after midnight on a date.. - * - * @param absoluteDateSent Filter by date sent - * @return this - */ - public MessageReader setDateSent(final DateTime absoluteDateSent) { - this.rangeDateSent = null; - this.absoluteDateSent = absoluteDateSent; + public MessageReader setDateSent(final ZonedDateTime dateSent) { + this.dateSent = dateSent; return this; } - /** - * Only show messages sent on this date (in - * [GMT](https://en.wikipedia.org/wiki/Greenwich_Mean_Time) format), given as - * `YYYY-MM-DD`. Example: `DateSent=2009-07-06`. You can also specify - * inequality, such as `DateSent<=YYYY-MM-DD` for messages that were sent on - * or before midnight on a date, and `DateSent>=YYYY-MM-DD` for messages sent - * on or after midnight on a date.. - * - * @param rangeDateSent Filter by date sent - * @return this - */ - public MessageReader setDateSent(final Range rangeDateSent) { - this.absoluteDateSent = null; - this.rangeDateSent = rangeDateSent; + public MessageReader setDateSentBefore(final ZonedDateTime dateSentBefore) { + this.dateSentBefore = dateSentBefore; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MessageReader setDateSentAfter(final ZonedDateTime dateSentAfter) { + this.dateSentAfter = dateSentAfter; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public MessageReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Messages.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Message Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "messages", - response.getContent(), - Message.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (to != null) { - request.addQueryParam("To", to.toString()); + Serializer.toString(request, "To", to, ParameterType.QUERY); } if (from != null) { - request.addQueryParam("From", from.toString()); + Serializer.toString(request, "From", from, ParameterType.QUERY); } - if (absoluteDateSent != null) { - request.addQueryParam("DateSent", absoluteDateSent.toString(Request.QUERY_STRING_DATE_TIME_FORMAT)); - } else if (rangeDateSent != null) { - request.addQueryDateTimeRange("DateSent", rangeDateSent); + Serializer.toString( + request, + "DateSent", + dateSent, + dateSentBefore, + dateSentAfter + ); + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/MessageUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/MessageUpdater.java index 08b767ee28..2eec751308 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/MessageUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,89 +27,119 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; - private final String body; - - /** - * Construct a new MessageUpdater. - * - * @param pathSid The message to redact - * @param body The text of the message you want to send, limited to 1600 - * characters. - */ - public MessageUpdater(final String pathSid, - final String body) { + private String pathSid; + private String body; + private Message.UpdateStatus status; + + public MessageUpdater(final String pathSid) { this.pathSid = pathSid; - this.body = body; } - /** - * Construct a new MessageUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The message to redact - * @param body The text of the message you want to send, limited to 1600 - * characters. - */ - public MessageUpdater(final String pathAccountSid, - final String pathSid, - final String body) { + public MessageUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; + } + + public MessageUpdater setBody(final String body) { this.body = body; + return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public MessageUpdater setStatus(final Message.UpdateStatus status) { + this.status = status; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message update(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); + } + + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NewKey.java b/src/main/java/com/twilio/rest/api/v2010/account/NewKey.java index 34883e4ac5..c155612b6b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NewKey.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NewKey.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,57 +18,47 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class NewKey extends Resource { - private static final long serialVersionUID = 233349476807945L; - - /** - * Create a NewKeyCreator to execute create. - * - * @param pathAccountSid The account_sid - * @return NewKeyCreator capable of executing the create - */ - public static NewKeyCreator creator(final String pathAccountSid) { - return new NewKeyCreator(pathAccountSid); - } - /** - * Create a NewKeyCreator to execute create. - * - * @return NewKeyCreator capable of executing the create - */ public static NewKeyCreator creator() { return new NewKeyCreator(); } + public static NewKeyCreator creator(final String pathAccountSid) { + return new NewKeyCreator(pathAccountSid); + } + /** * Converts a JSON String into a NewKey object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return NewKey object represented by the provided JSON */ - public static NewKey fromJson(final String json, final ObjectMapper objectMapper) { + public static NewKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NewKey.class); @@ -75,12 +72,15 @@ public static NewKey fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a NewKey object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return NewKey object represented by the provided JSON */ - public static NewKey fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static NewKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NewKey.class); @@ -91,73 +91,50 @@ public static NewKey fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String secret; - - @JsonCreator - private NewKey(@JsonProperty("sid") - final String sid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("secret") - final String secret) { - this.sid = sid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.secret = secret; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String friendlyName; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String secret; - /** - * Returns The The secret. - * - * @return The secret - */ - public final String getSecret() { - return this.secret; + @Getter + private final String sid; + + @JsonCreator + private NewKey( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("secret") final String secret, + @JsonProperty("sid") final String sid + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.secret = secret; + this.sid = sid; } @Override @@ -171,31 +148,23 @@ public boolean equals(final Object o) { } NewKey other = (NewKey) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(secret, other.secret); + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(secret, other.secret) && + Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(sid, - friendlyName, - dateCreated, - dateUpdated, - secret); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("secret", secret) - .toString(); + return Objects.hash( + dateCreated, + dateUpdated, + friendlyName, + secret, + sid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NewKeyCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/NewKeyCreator.java index 0a7086b477..1ff9251839 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NewKeyCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NewKeyCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,85 +27,99 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class NewKeyCreator extends Creator { + private String pathAccountSid; private String friendlyName; - /** - * Construct a new NewKeyCreator. - */ - public NewKeyCreator() { - } + public NewKeyCreator() {} - /** - * Construct a new NewKeyCreator. - * - * @param pathAccountSid The account_sid - */ public NewKeyCreator(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public NewKeyCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created NewKey - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public NewKey create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Keys.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Keys.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NewKey creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "NewKey creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public NewKey create(final TwilioRestClient client) { + Response response = makeRequest(client); return NewKey.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + NewKey content = NewKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKey.java b/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKey.java index cb8c98e681..e731c086b5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKey.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKey.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,58 +18,47 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class NewSigningKey extends Resource { - private static final long serialVersionUID = 233349476807945L; - /** - * Create a NewSigningKeyCreator to execute create. - * - * @param pathAccountSid The account_sid - * @return NewSigningKeyCreator capable of executing the create - */ - public static NewSigningKeyCreator creator(final String pathAccountSid) { - return new NewSigningKeyCreator(pathAccountSid); - } - - /** - * Create a NewSigningKeyCreator to execute create. - * - * @return NewSigningKeyCreator capable of executing the create - */ public static NewSigningKeyCreator creator() { return new NewSigningKeyCreator(); } + public static NewSigningKeyCreator creator(final String pathAccountSid) { + return new NewSigningKeyCreator(pathAccountSid); + } + /** - * Converts a JSON String into a NewSigningKey object using the provided - * ObjectMapper. - * + * Converts a JSON String into a NewSigningKey object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return NewSigningKey object represented by the provided JSON */ - public static NewSigningKey fromJson(final String json, final ObjectMapper objectMapper) { + public static NewSigningKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NewSigningKey.class); @@ -76,12 +72,15 @@ public static NewSigningKey fromJson(final String json, final ObjectMapper objec /** * Converts a JSON InputStream into a NewSigningKey object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return NewSigningKey object represented by the provided JSON */ - public static NewSigningKey fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static NewSigningKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, NewSigningKey.class); @@ -92,73 +91,50 @@ public static NewSigningKey fromJson(final InputStream json, final ObjectMapper } } - private final String sid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String secret; - - @JsonCreator - private NewSigningKey(@JsonProperty("sid") - final String sid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("secret") - final String secret) { - this.sid = sid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.secret = secret; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String friendlyName; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String secret; - /** - * Returns The The secret. - * - * @return The secret - */ - public final String getSecret() { - return this.secret; + @Getter + private final String sid; + + @JsonCreator + private NewSigningKey( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("secret") final String secret, + @JsonProperty("sid") final String sid + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.secret = secret; + this.sid = sid; } @Override @@ -172,31 +148,23 @@ public boolean equals(final Object o) { } NewSigningKey other = (NewSigningKey) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(secret, other.secret); + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(secret, other.secret) && + Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(sid, - friendlyName, - dateCreated, - dateUpdated, - secret); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("secret", secret) - .toString(); + return Objects.hash( + dateCreated, + dateUpdated, + friendlyName, + secret, + sid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKeyCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKeyCreator.java index 12a29b7764..9ccb6322b6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKeyCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NewSigningKeyCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,85 +27,102 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class NewSigningKeyCreator extends Creator { + private String pathAccountSid; private String friendlyName; - /** - * Construct a new NewSigningKeyCreator. - */ - public NewSigningKeyCreator() { - } + public NewSigningKeyCreator() {} - /** - * Construct a new NewSigningKeyCreator. - * - * @param pathAccountSid The account_sid - */ public NewSigningKeyCreator(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public NewSigningKeyCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created NewSigningKey - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public NewSigningKey create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SigningKeys.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("NewSigningKey creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "NewSigningKey creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return NewSigningKey.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public NewSigningKey create(final TwilioRestClient client) { + Response response = makeRequest(client); + return NewSigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + NewSigningKey content = NewSigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Notification.java b/src/main/java/com/twilio/rest/api/v2010/account/Notification.java index d8d13c88a3..7385488386 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Notification.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Notification.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,103 +18,60 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Notification extends Resource { - private static final long serialVersionUID = 203437902819777L; - - /** - * Create a NotificationFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique notification Sid - * @return NotificationFetcher capable of executing the fetch - */ - public static NotificationFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new NotificationFetcher(pathAccountSid, pathSid); - } - /** - * Create a NotificationFetcher to execute fetch. - * - * @param pathSid Fetch by unique notification Sid - * @return NotificationFetcher capable of executing the fetch - */ public static NotificationFetcher fetcher(final String pathSid) { return new NotificationFetcher(pathSid); } - /** - * Create a NotificationDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique notification Sid - * @return NotificationDeleter capable of executing the delete - */ - public static NotificationDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new NotificationDeleter(pathAccountSid, pathSid); + public static NotificationFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new NotificationFetcher(pathAccountSid, pathSid); } - /** - * Create a NotificationDeleter to execute delete. - * - * @param pathSid Delete by unique notification Sid - * @return NotificationDeleter capable of executing the delete - */ - public static NotificationDeleter deleter(final String pathSid) { - return new NotificationDeleter(pathSid); + public static NotificationReader reader() { + return new NotificationReader(); } - /** - * Create a NotificationReader to execute read. - * - * @param pathAccountSid The account_sid - * @return NotificationReader capable of executing the read - */ public static NotificationReader reader(final String pathAccountSid) { return new NotificationReader(pathAccountSid); } /** - * Create a NotificationReader to execute read. - * - * @return NotificationReader capable of executing the read - */ - public static NotificationReader reader() { - return new NotificationReader(); - } - - /** - * Converts a JSON String into a Notification object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Notification object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Notification object represented by the provided JSON */ - public static Notification fromJson(final String json, final ObjectMapper objectMapper) { + public static Notification fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -121,12 +85,15 @@ public static Notification fromJson(final String json, final ObjectMapper object /** * Converts a JSON InputStream into a Notification object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Notification object represented by the provided JSON */ - public static Notification fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Notification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -137,67 +104,103 @@ public static Notification fromJson(final InputStream json, final ObjectMapper o } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; + + @Getter private final String callSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String errorCode; + + @Getter private final String log; - private final DateTime messageDate; + + @Getter + private final ZonedDateTime messageDate; + + @Getter private final String messageText; + + @Getter private final URI moreInfo; + + @Getter private final HttpMethod requestMethod; + + @Getter private final URI requestUrl; + + @Getter private final String requestVariables; + + @Getter private final String responseBody; + + @Getter private final String responseHeaders; + + @Getter private final String sid; + + @Getter private final String uri; @JsonCreator - private Notification(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("call_sid") - final String callSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("error_code") - final String errorCode, - @JsonProperty("log") - final String log, - @JsonProperty("message_date") - final String messageDate, - @JsonProperty("message_text") - final String messageText, - @JsonProperty("more_info") - final URI moreInfo, - @JsonProperty("request_method") - final HttpMethod requestMethod, - @JsonProperty("request_url") - final URI requestUrl, - @JsonProperty("request_variables") - final String requestVariables, - @JsonProperty("response_body") - final String responseBody, - @JsonProperty("response_headers") - final String responseHeaders, - @JsonProperty("sid") - final String sid, - @JsonProperty("uri") - final String uri) { + private Notification( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("error_code") final String errorCode, + @JsonProperty("log") final String log, + @JsonProperty("message_date") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime messageDate, + @JsonProperty("message_text") final String messageText, + @JsonProperty("more_info") final URI moreInfo, + @JsonProperty("request_method") final HttpMethod requestMethod, + @JsonProperty("request_url") final URI requestUrl, + @JsonProperty("request_variables") final String requestVariables, + @JsonProperty("response_body") final String responseBody, + @JsonProperty("response_headers") final String responseHeaders, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; this.callSid = callSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.errorCode = errorCode; this.log = log; - this.messageDate = DateConverter.rfc2822DateTimeFromString(messageDate); + this.messageDate = messageDate; this.messageText = messageText; this.moreInfo = moreInfo; this.requestMethod = requestMethod; @@ -209,159 +212,6 @@ private Notification(@JsonProperty("account_sid") this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The version of the Twilio API in use. - * - * @return The version of the Twilio API in use - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The string that uniquely identifies the call. - * - * @return The string that uniquely identifies the call - */ - public final String getCallSid() { - return this.callSid; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A unique error code corresponding to the notification. - * - * @return A unique error code corresponding to the notification - */ - public final String getErrorCode() { - return this.errorCode; - } - - /** - * Returns The An integer log level. - * - * @return An integer log level - */ - public final String getLog() { - return this.log; - } - - /** - * Returns The The date the notification was generated. - * - * @return The date the notification was generated - */ - public final DateTime getMessageDate() { - return this.messageDate; - } - - /** - * Returns The The text of the notification.. - * - * @return The text of the notification. - */ - public final String getMessageText() { - return this.messageText; - } - - /** - * Returns The A URL for more information about the error code. - * - * @return A URL for more information about the error code - */ - public final URI getMoreInfo() { - return this.moreInfo; - } - - /** - * Returns The HTTP method used with the request url. - * - * @return HTTP method used with the request url - */ - public final HttpMethod getRequestMethod() { - return this.requestMethod; - } - - /** - * Returns The URL of the resource that generated the notification. - * - * @return URL of the resource that generated the notification - */ - public final URI getRequestUrl() { - return this.requestUrl; - } - - /** - * Returns The Twilio-generated HTTP variables sent to the server. - * - * @return Twilio-generated HTTP variables sent to the server - */ - public final String getRequestVariables() { - return this.requestVariables; - } - - /** - * Returns The The HTTP body returned by your server.. - * - * @return The HTTP body returned by your server. - */ - public final String getResponseBody() { - return this.responseBody; - } - - /** - * Returns The The HTTP headers returned by your server.. - * - * @return The HTTP headers returned by your server. - */ - public final String getResponseHeaders() { - return this.responseHeaders; - } - - /** - * Returns The A string that uniquely identifies this notification. - * - * @return A string that uniquely identifies this notification - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -373,67 +223,47 @@ public boolean equals(final Object o) { } Notification other = (Notification) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(callSid, other.callSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(errorCode, other.errorCode) && - Objects.equals(log, other.log) && - Objects.equals(messageDate, other.messageDate) && - Objects.equals(messageText, other.messageText) && - Objects.equals(moreInfo, other.moreInfo) && - Objects.equals(requestMethod, other.requestMethod) && - Objects.equals(requestUrl, other.requestUrl) && - Objects.equals(requestVariables, other.requestVariables) && - Objects.equals(responseBody, other.responseBody) && - Objects.equals(responseHeaders, other.responseHeaders) && - Objects.equals(sid, other.sid) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(log, other.log) && + Objects.equals(messageDate, other.messageDate) && + Objects.equals(messageText, other.messageText) && + Objects.equals(moreInfo, other.moreInfo) && + Objects.equals(requestMethod, other.requestMethod) && + Objects.equals(requestUrl, other.requestUrl) && + Objects.equals(requestVariables, other.requestVariables) && + Objects.equals(responseBody, other.responseBody) && + Objects.equals(responseHeaders, other.responseHeaders) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - callSid, - dateCreated, - dateUpdated, - errorCode, - log, - messageDate, - messageText, - moreInfo, - requestMethod, - requestUrl, - requestVariables, - responseBody, - responseHeaders, - sid, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("callSid", callSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("errorCode", errorCode) - .add("log", log) - .add("messageDate", messageDate) - .add("messageText", messageText) - .add("moreInfo", moreInfo) - .add("requestMethod", requestMethod) - .add("requestUrl", requestUrl) - .add("requestVariables", requestVariables) - .add("responseBody", responseBody) - .add("responseHeaders", responseHeaders) - .add("sid", sid) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + apiVersion, + callSid, + dateCreated, + dateUpdated, + errorCode, + log, + messageDate, + messageText, + moreInfo, + requestMethod, + requestUrl, + requestVariables, + responseBody, + responseHeaders, + sid, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NotificationDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/NotificationDeleter.java deleted file mode 100644 index 348c0a2624..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/NotificationDeleter.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -public class NotificationDeleter extends Deleter { - private String pathAccountSid; - private final String pathSid; - - /** - * Construct a new NotificationDeleter. - * - * @param pathSid Delete by unique notification Sid - */ - public NotificationDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Construct a new NotificationDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique notification Sid - */ - public NotificationDeleter(final String pathAccountSid, - final String pathSid) { - this.pathAccountSid = pathAccountSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.DELETE, - Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Notifications/" + this.pathSid + ".json", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Notification delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NotificationFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/NotificationFetcher.java index b70891d9b1..e41c48abdf 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NotificationFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NotificationFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class NotificationFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new NotificationFetcher. - * - * @param pathSid Fetch by unique notification Sid - */ public NotificationFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new NotificationFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique notification Sid - */ - public NotificationFetcher(final String pathAccountSid, - final String pathSid) { + public NotificationFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Notification - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Notification fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Notifications/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Notifications/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Notification fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Notification.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Notification fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Notification content = Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/NotificationReader.java b/src/main/java/com/twilio/rest/api/v2010/account/NotificationReader.java index a3641274ac..2a33c3bb77 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/NotificationReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/NotificationReader.java @@ -1,236 +1,258 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; -import com.google.common.collect.Range; import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class NotificationReader extends Reader { + private String pathAccountSid; private Integer log; - private LocalDate absoluteMessageDate; - private Range rangeMessageDate; + private LocalDate messageDate; + private LocalDate messageDateBefore; + private LocalDate messageDateAfter; + private Long pageSize; - /** - * Construct a new NotificationReader. - */ - public NotificationReader() { - } + public NotificationReader() {} - /** - * Construct a new NotificationReader. - * - * @param pathAccountSid The account_sid - */ public NotificationReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only show notifications for this log, using the integer log values shown - * above.. - * - * @param log Filter by log level - * @return this - */ public NotificationReader setLog(final Integer log) { this.log = log; return this; } - /** - * Only show notifications for this date. Should be formatted as `YYYY-MM-DD`. - * You can also specify inequality, such as `MessageDate<=YYYY-MM-DD` for - * messages logged at or before midnight on a date, and - * `MessageDate>=YYYY-MM-DD` for messages logged at or after midnight on a - * date.. - * - * @param absoluteMessageDate Filter by date - * @return this - */ - public NotificationReader setMessageDate(final LocalDate absoluteMessageDate) { - this.rangeMessageDate = null; - this.absoluteMessageDate = absoluteMessageDate; + public NotificationReader setMessageDate(final LocalDate messageDate) { + this.messageDate = messageDate; return this; } - /** - * Only show notifications for this date. Should be formatted as `YYYY-MM-DD`. - * You can also specify inequality, such as `MessageDate<=YYYY-MM-DD` for - * messages logged at or before midnight on a date, and - * `MessageDate>=YYYY-MM-DD` for messages logged at or after midnight on a - * date.. - * - * @param rangeMessageDate Filter by date - * @return this - */ - public NotificationReader setMessageDate(final Range rangeMessageDate) { - this.absoluteMessageDate = null; - this.rangeMessageDate = rangeMessageDate; + public NotificationReader setMessageDateBefore( + final LocalDate messageDateBefore + ) { + this.messageDateBefore = messageDateBefore; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Notification ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public NotificationReader setMessageDateAfter( + final LocalDate messageDateAfter + ) { + this.messageDateAfter = messageDateAfter; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Notification ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public NotificationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "notifications", + response.getContent(), + Notification.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Notifications.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Notifications.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Notification ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "notifications", + response.getContent(), + Notification.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Notification read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "notifications", + response.getContent(), + Notification.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Notification Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Notification read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "notifications", - response.getContent(), - Notification.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (log != null) { - request.addQueryParam("Log", log.toString()); + Serializer.toString(request, "Log", log, ParameterType.QUERY); } - if (absoluteMessageDate != null) { - request.addQueryParam("MessageDate", absoluteMessageDate.toString(Request.QUERY_STRING_DATE_FORMAT)); - } else if (rangeMessageDate != null) { - request.addQueryDateRange("MessageDate", rangeMessageDate); + Serializer.toString( + request, + "MessageDate", + messageDate, + messageDateBefore, + messageDateAfter + ); + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerId.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerId.java index c33968a2fd..32cc333a82 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerId.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerId.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,124 +18,80 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class OutgoingCallerId extends Resource { - private static final long serialVersionUID = 160246512577628L; - /** - * Create a OutgoingCallerIdFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique outgoing-caller-id Sid - * @return OutgoingCallerIdFetcher capable of executing the fetch - */ - public static OutgoingCallerIdFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new OutgoingCallerIdFetcher(pathAccountSid, pathSid); - } - - /** - * Create a OutgoingCallerIdFetcher to execute fetch. - * - * @param pathSid Fetch by unique outgoing-caller-id Sid - * @return OutgoingCallerIdFetcher capable of executing the fetch - */ - public static OutgoingCallerIdFetcher fetcher(final String pathSid) { - return new OutgoingCallerIdFetcher(pathSid); + public static OutgoingCallerIdDeleter deleter(final String pathSid) { + return new OutgoingCallerIdDeleter(pathSid); } - /** - * Create a OutgoingCallerIdUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid Update by unique outgoing-caller-id Sid - * @return OutgoingCallerIdUpdater capable of executing the update - */ - public static OutgoingCallerIdUpdater updater(final String pathAccountSid, - final String pathSid) { - return new OutgoingCallerIdUpdater(pathAccountSid, pathSid); + public static OutgoingCallerIdDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new OutgoingCallerIdDeleter(pathAccountSid, pathSid); } - /** - * Create a OutgoingCallerIdUpdater to execute update. - * - * @param pathSid Update by unique outgoing-caller-id Sid - * @return OutgoingCallerIdUpdater capable of executing the update - */ - public static OutgoingCallerIdUpdater updater(final String pathSid) { - return new OutgoingCallerIdUpdater(pathSid); + public static OutgoingCallerIdFetcher fetcher(final String pathSid) { + return new OutgoingCallerIdFetcher(pathSid); } - /** - * Create a OutgoingCallerIdDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique outgoing-caller-id Sid - * @return OutgoingCallerIdDeleter capable of executing the delete - */ - public static OutgoingCallerIdDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new OutgoingCallerIdDeleter(pathAccountSid, pathSid); + public static OutgoingCallerIdFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new OutgoingCallerIdFetcher(pathAccountSid, pathSid); } - /** - * Create a OutgoingCallerIdDeleter to execute delete. - * - * @param pathSid Delete by unique outgoing-caller-id Sid - * @return OutgoingCallerIdDeleter capable of executing the delete - */ - public static OutgoingCallerIdDeleter deleter(final String pathSid) { - return new OutgoingCallerIdDeleter(pathSid); + public static OutgoingCallerIdReader reader() { + return new OutgoingCallerIdReader(); } - /** - * Create a OutgoingCallerIdReader to execute read. - * - * @param pathAccountSid The account_sid - * @return OutgoingCallerIdReader capable of executing the read - */ public static OutgoingCallerIdReader reader(final String pathAccountSid) { return new OutgoingCallerIdReader(pathAccountSid); } - /** - * Create a OutgoingCallerIdReader to execute read. - * - * @return OutgoingCallerIdReader capable of executing the read - */ - public static OutgoingCallerIdReader reader() { - return new OutgoingCallerIdReader(); + public static OutgoingCallerIdUpdater updater(final String pathSid) { + return new OutgoingCallerIdUpdater(pathSid); + } + + public static OutgoingCallerIdUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new OutgoingCallerIdUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a OutgoingCallerId object using the provided - * ObjectMapper. - * + * Converts a JSON String into a OutgoingCallerId object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return OutgoingCallerId object represented by the provided JSON */ - public static OutgoingCallerId fromJson(final String json, final ObjectMapper objectMapper) { + public static OutgoingCallerId fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OutgoingCallerId.class); @@ -142,12 +105,15 @@ public static OutgoingCallerId fromJson(final String json, final ObjectMapper ob /** * Converts a JSON InputStream into a OutgoingCallerId object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return OutgoingCallerId object represented by the provided JSON */ - public static OutgoingCallerId fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static OutgoingCallerId fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OutgoingCallerId.class); @@ -158,99 +124,62 @@ public static OutgoingCallerId fromJson(final InputStream json, final ObjectMapp } } - private final String sid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String friendlyName; - private final String accountSid; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String uri; - - @JsonCreator - private OutgoingCallerId(@JsonProperty("sid") - final String sid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("uri") - final String uri) { - this.sid = sid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.friendlyName = friendlyName; - this.accountSid = accountSid; - this.phoneNumber = phoneNumber; - this.uri = uri; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A string that uniquely identifies this outgoing-caller-ids. - * - * @return A string that uniquely identifies this outgoing-caller-ids - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A human readable description for this resource. - * - * @return A human readable description for this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String friendlyName; - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The incoming phone number. - * - * @return The incoming phone number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final String sid; - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; + @Getter + private final String uri; + + @JsonCreator + private OutgoingCallerId( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.phoneNumber = phoneNumber; + this.sid = sid; + this.uri = uri; } @Override @@ -264,37 +193,27 @@ public boolean equals(final Object o) { } OutgoingCallerId other = (OutgoingCallerId) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, - dateCreated, - dateUpdated, - friendlyName, - accountSid, - phoneNumber, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("accountSid", accountSid) - .add("phoneNumber", phoneNumber) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + phoneNumber, + sid, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdDeleter.java index 5ff63c8fa7..5d2e2b23d7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class OutgoingCallerIdDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new OutgoingCallerIdDeleter. - * - * @param pathSid Delete by unique outgoing-caller-id Sid - */ public OutgoingCallerIdDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new OutgoingCallerIdDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique outgoing-caller-id Sid - */ - public OutgoingCallerIdDeleter(final String pathAccountSid, - final String pathSid) { + public OutgoingCallerIdDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/OutgoingCallerIds/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OutgoingCallerId delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "OutgoingCallerId delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdFetcher.java index c5cf9945d4..ec6230e0c5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class OutgoingCallerIdFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new OutgoingCallerIdFetcher. - * - * @param pathSid Fetch by unique outgoing-caller-id Sid - */ public OutgoingCallerIdFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new OutgoingCallerIdFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique outgoing-caller-id Sid - */ - public OutgoingCallerIdFetcher(final String pathAccountSid, - final String pathSid) { + public OutgoingCallerIdFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched OutgoingCallerId - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public OutgoingCallerId fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/OutgoingCallerIds/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OutgoingCallerId fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "OutgoingCallerId fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return OutgoingCallerId.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public OutgoingCallerId fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return OutgoingCallerId.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OutgoingCallerId content = OutgoingCallerId.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdReader.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdReader.java index 4edcb953f4..bf24716ff1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,210 +17,239 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class OutgoingCallerIdReader extends Reader { + private String pathAccountSid; private com.twilio.type.PhoneNumber phoneNumber; private String friendlyName; + private Long pageSize; - /** - * Construct a new OutgoingCallerIdReader. - */ - public OutgoingCallerIdReader() { - } + public OutgoingCallerIdReader() {} - /** - * Construct a new OutgoingCallerIdReader. - * - * @param pathAccountSid The account_sid - */ public OutgoingCallerIdReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only show the caller id resource that exactly matches this phone number.. - * - * @param phoneNumber Filter by phone number - * @return this - */ - public OutgoingCallerIdReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public OutgoingCallerIdReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * Only show the caller id resource that exactly matches this phone number.. - * - * @param phoneNumber Filter by phone number - * @return this - */ public OutgoingCallerIdReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * Only show the caller id resource that exactly matches this name.. - * - * @param friendlyName Filter by friendly name - * @return this - */ public OutgoingCallerIdReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return OutgoingCallerId ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public OutgoingCallerIdReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return OutgoingCallerId ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "outgoing_caller_ids", + response.getContent(), + OutgoingCallerId.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/OutgoingCallerIds.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return OutgoingCallerId ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "outgoing_caller_ids", + response.getContent(), + OutgoingCallerId.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "OutgoingCallerId read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "outgoing_caller_ids", + response.getContent(), + OutgoingCallerId.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of OutgoingCallerId Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("OutgoingCallerId read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "outgoing_caller_ids", - response.getContent(), - OutgoingCallerId.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdUpdater.java index 7ffde67100..eb605aaf97 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/OutgoingCallerIdUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,93 +27,111 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class OutgoingCallerIdUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private String friendlyName; - /** - * Construct a new OutgoingCallerIdUpdater. - * - * @param pathSid Update by unique outgoing-caller-id Sid - */ public OutgoingCallerIdUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new OutgoingCallerIdUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid Update by unique outgoing-caller-id Sid - */ - public OutgoingCallerIdUpdater(final String pathAccountSid, - final String pathSid) { + public OutgoingCallerIdUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * A human readable description of a Caller ID, with maximum length of 64 - * characters. Defaults to a nicely formatted version of the phone number.. - * - * @param friendlyName A human readable description of the caller ID - * @return this - */ public OutgoingCallerIdUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated OutgoingCallerId - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public OutgoingCallerId update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/OutgoingCallerIds/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OutgoingCallerId update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "OutgoingCallerId update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return OutgoingCallerId.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public OutgoingCallerId update(final TwilioRestClient client) { + Response response = makeRequest(client); + return OutgoingCallerId.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OutgoingCallerId content = OutgoingCallerId.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Queue.java b/src/main/java/com/twilio/rest/api/v2010/account/Queue.java index 1c9a34c693..fa7d1cd1f7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Queue.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Queue.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,145 +18,91 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Queue extends Resource { - private static final long serialVersionUID = 51300543687284L; - - /** - * Create a QueueFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique queue Sid - * @return QueueFetcher capable of executing the fetch - */ - public static QueueFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new QueueFetcher(pathAccountSid, pathSid); - } - /** - * Create a QueueFetcher to execute fetch. - * - * @param pathSid Fetch by unique queue Sid - * @return QueueFetcher capable of executing the fetch - */ - public static QueueFetcher fetcher(final String pathSid) { - return new QueueFetcher(pathSid); + public static QueueCreator creator(final String friendlyName) { + return new QueueCreator(friendlyName); } - /** - * Create a QueueUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return QueueUpdater capable of executing the update - */ - public static QueueUpdater updater(final String pathAccountSid, - final String pathSid) { - return new QueueUpdater(pathAccountSid, pathSid); + public static QueueCreator creator( + final String pathAccountSid, + final String friendlyName + ) { + return new QueueCreator(pathAccountSid, friendlyName); } - /** - * Create a QueueUpdater to execute update. - * - * @param pathSid The sid - * @return QueueUpdater capable of executing the update - */ - public static QueueUpdater updater(final String pathSid) { - return new QueueUpdater(pathSid); + public static QueueDeleter deleter(final String pathSid) { + return new QueueDeleter(pathSid); } - /** - * Create a QueueDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique queue Sid - * @return QueueDeleter capable of executing the delete - */ - public static QueueDeleter deleter(final String pathAccountSid, - final String pathSid) { + public static QueueDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { return new QueueDeleter(pathAccountSid, pathSid); } - /** - * Create a QueueDeleter to execute delete. - * - * @param pathSid Delete by unique queue Sid - * @return QueueDeleter capable of executing the delete - */ - public static QueueDeleter deleter(final String pathSid) { - return new QueueDeleter(pathSid); + public static QueueFetcher fetcher(final String pathSid) { + return new QueueFetcher(pathSid); } - /** - * Create a QueueReader to execute read. - * - * @param pathAccountSid The account_sid - * @return QueueReader capable of executing the read - */ - public static QueueReader reader(final String pathAccountSid) { - return new QueueReader(pathAccountSid); + public static QueueFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new QueueFetcher(pathAccountSid, pathSid); } - /** - * Create a QueueReader to execute read. - * - * @return QueueReader capable of executing the read - */ public static QueueReader reader() { return new QueueReader(); } - /** - * Create a QueueCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param friendlyName A user-provided string that identifies this queue. - * @return QueueCreator capable of executing the create - */ - public static QueueCreator creator(final String pathAccountSid, - final String friendlyName) { - return new QueueCreator(pathAccountSid, friendlyName); + public static QueueReader reader(final String pathAccountSid) { + return new QueueReader(pathAccountSid); } - /** - * Create a QueueCreator to execute create. - * - * @param friendlyName A user-provided string that identifies this queue. - * @return QueueCreator capable of executing the create - */ - public static QueueCreator creator(final String friendlyName) { - return new QueueCreator(friendlyName); + public static QueueUpdater updater(final String pathSid) { + return new QueueUpdater(pathSid); + } + + public static QueueUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new QueueUpdater(pathAccountSid, pathSid); } /** * Converts a JSON String into a Queue object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Queue object represented by the provided JSON */ - public static Queue fromJson(final String json, final ObjectMapper objectMapper) { + public static Queue fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Queue.class); @@ -163,12 +116,15 @@ public static Queue fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Queue object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Queue object represented by the provided JSON */ - public static Queue fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Queue fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Queue.class); @@ -179,127 +135,72 @@ public static Queue fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final Integer averageWaitTime; + + @Getter private final Integer currentSize; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter private final Integer maxSize; + + @Getter private final String sid; + + @Getter private final String uri; @JsonCreator - private Queue(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("average_wait_time") - final Integer averageWaitTime, - @JsonProperty("current_size") - final Integer currentSize, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("max_size") - final Integer maxSize, - @JsonProperty("sid") - final String sid, - @JsonProperty("uri") - final String uri) { + private Queue( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("average_wait_time") final Integer averageWaitTime, + @JsonProperty("current_size") final Integer currentSize, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("max_size") final Integer maxSize, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.averageWaitTime = averageWaitTime; this.currentSize = currentSize; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; this.maxSize = maxSize; this.sid = sid; this.uri = uri; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Average wait time of members in the queue. - * - * @return Average wait time of members in the queue - */ - public final Integer getAverageWaitTime() { - return this.averageWaitTime; - } - - /** - * Returns The The count of calls currently in the queue.. - * - * @return The count of calls currently in the queue. - */ - public final Integer getCurrentSize() { - return this.currentSize; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A user-provided string that identifies this queue.. - * - * @return A user-provided string that identifies this queue. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The max number of calls allowed in the queue. - * - * @return The max number of calls allowed in the queue - */ - public final Integer getMaxSize() { - return this.maxSize; - } - - /** - * Returns The A string that uniquely identifies this queue. - * - * @return A string that uniquely identifies this queue - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -311,43 +212,31 @@ public boolean equals(final Object o) { } Queue other = (Queue) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(averageWaitTime, other.averageWaitTime) && - Objects.equals(currentSize, other.currentSize) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(maxSize, other.maxSize) && - Objects.equals(sid, other.sid) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(averageWaitTime, other.averageWaitTime) && + Objects.equals(currentSize, other.currentSize) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(maxSize, other.maxSize) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - averageWaitTime, - currentSize, - dateCreated, - dateUpdated, - friendlyName, - maxSize, - sid, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("averageWaitTime", averageWaitTime) - .add("currentSize", currentSize) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("maxSize", maxSize) - .add("sid", sid) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + averageWaitTime, + currentSize, + dateCreated, + dateUpdated, + friendlyName, + maxSize, + sid, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueCreator.java index 130f7d9044..ca676770fe 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,97 +27,120 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class QueueCreator extends Creator { + private String pathAccountSid; - private final String friendlyName; + private String friendlyName; private Integer maxSize; - /** - * Construct a new QueueCreator. - * - * @param friendlyName A user-provided string that identifies this queue. - */ public QueueCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * Construct a new QueueCreator. - * - * @param pathAccountSid The account_sid - * @param friendlyName A user-provided string that identifies this queue. - */ - public QueueCreator(final String pathAccountSid, - final String friendlyName) { + public QueueCreator( + final String pathAccountSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.friendlyName = friendlyName; } - /** - * The upper limit of calls allowed to be in the queue. The default is 100. The - * maximum is 1000.. - * - * @param maxSize The max number of calls allowed in the queue - * @return this - */ + public QueueCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + public QueueCreator setMaxSize(final Integer maxSize) { this.maxSize = maxSize; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Queue - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Queue create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Queues.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Queues.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Queue creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Queue create(final TwilioRestClient client) { + Response response = makeRequest(client); return Queue.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Queue content = Queue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (maxSize != null) { - request.addPostParam("MaxSize", maxSize.toString()); + Serializer.toString( + request, + "MaxSize", + maxSize, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueDeleter.java index 0f7ffa4236..77068c012a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class QueueDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new QueueDeleter. - * - * @param pathSid Delete by unique queue Sid - */ public QueueDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new QueueDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique queue Sid - */ - public QueueDeleter(final String pathAccountSid, - final String pathSid) { + public QueueDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Queues/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Queue delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueFetcher.java index 5d4a0f83fb..de97303810 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,85 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class QueueFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new QueueFetcher. - * - * @param pathSid Fetch by unique queue Sid - */ public QueueFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new QueueFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique queue Sid - */ - public QueueFetcher(final String pathAccountSid, - final String pathSid) { + public QueueFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Queue - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Queue fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Queues/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Queue fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Queue fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Queue.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Queue content = Queue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueReader.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueReader.java index 75bcea8c27..000d93c5c8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,167 +17,197 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class QueueReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new QueueReader. - */ - public QueueReader() { - } + public QueueReader() {} - /** - * Construct a new QueueReader. - * - * @param pathAccountSid The account_sid - */ public QueueReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Queue ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public QueueReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Queue ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "queues", + response.getContent(), + Queue.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Queues.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Queues.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Queue ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "queues", + response.getContent(), + Queue.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Queue read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "queues", + response.getContent(), + Queue.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Queue Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Queue read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "queues", - response.getContent(), - Queue.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/QueueUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/QueueUpdater.java index 5e395efccf..af13cc0c4b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/QueueUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/QueueUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,108 +27,119 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class QueueUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private String friendlyName; private Integer maxSize; - /** - * Construct a new QueueUpdater. - * - * @param pathSid The sid - */ public QueueUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new QueueUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public QueueUpdater(final String pathAccountSid, - final String pathSid) { + public QueueUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * A human readable description of the queue. - * - * @param friendlyName A human readable description of the queue - * @return this - */ public QueueUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The maximum number of members that can be in the queue at a time. - * - * @param maxSize The max number of members allowed in the queue - * @return this - */ public QueueUpdater setMaxSize(final Integer maxSize) { this.maxSize = maxSize; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Queue - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Queue update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Queues/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Queues/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Queue update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Queue update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Queue update(final TwilioRestClient client) { + Response response = makeRequest(client); return Queue.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Queue content = Queue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (maxSize != null) { - request.addPostParam("MaxSize", maxSize.toString()); + Serializer.toString( + request, + "MaxSize", + maxSize, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Recording.java b/src/main/java/com/twilio/rest/api/v2010/account/Recording.java index 3caa9448c1..778344a32c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Recording.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Recording.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,32 +17,62 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Recording extends Resource { - private static final long serialVersionUID = 243997298277448L; + + public static RecordingDeleter deleter(final String pathSid) { + return new RecordingDeleter(pathSid); + } + + public static RecordingDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new RecordingDeleter(pathAccountSid, pathSid); + } + + public static RecordingFetcher fetcher(final String pathSid) { + return new RecordingFetcher(pathSid); + } + + public static RecordingFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new RecordingFetcher(pathAccountSid, pathSid); + } + + public static RecordingReader reader() { + return new RecordingReader(); + } + + public static RecordingReader reader(final String pathAccountSid) { + return new RecordingReader(pathAccountSid); + } public enum Status { IN_PROGRESS("in-progress"), @@ -43,7 +80,8 @@ public enum Status { STOPPED("stopped"), PROCESSING("processing"), COMPLETED("completed"), - FAILED("failed"); + ABSENT("absent"), + DELETED("deleted"); private final String value; @@ -51,15 +89,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -67,13 +101,13 @@ public static Status forValue(final String value) { } public enum Source { - DIALVERB("DialVerb"), + DIAL_VERB("DialVerb"), CONFERENCE("Conference"), - OUTBOUNDAPI("OutboundAPI"), + OUTBOUND_API("OutboundAPI"), TRUNKING("Trunking"), - RECORDVERB("RecordVerb"), - STARTCALLRECORDINGAPI("StartCallRecordingAPI"), - STARTCONFERENCERECORDINGAPI("StartConferenceRecordingAPI"); + RECORD_VERB("RecordVerb"), + START_CALL_RECORDING_API("StartCallRecordingAPI"), + START_CONFERENCE_RECORDING_API("StartConferenceRecordingAPI"); private final String value; @@ -81,15 +115,11 @@ private Source(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Source from a string. - * @param value string value - * @return generated Source - */ @JsonCreator public static Source forValue(final String value) { return Promoter.enumFromString(value, Source.values()); @@ -97,77 +127,16 @@ public static Source forValue(final String value) { } /** - * Create a RecordingFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique recording Sid - * @return RecordingFetcher capable of executing the fetch - */ - public static RecordingFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new RecordingFetcher(pathAccountSid, pathSid); - } - - /** - * Create a RecordingFetcher to execute fetch. - * - * @param pathSid Fetch by unique recording Sid - * @return RecordingFetcher capable of executing the fetch - */ - public static RecordingFetcher fetcher(final String pathSid) { - return new RecordingFetcher(pathSid); - } - - /** - * Create a RecordingDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique recording Sid - * @return RecordingDeleter capable of executing the delete - */ - public static RecordingDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new RecordingDeleter(pathAccountSid, pathSid); - } - - /** - * Create a RecordingDeleter to execute delete. - * - * @param pathSid Delete by unique recording Sid - * @return RecordingDeleter capable of executing the delete - */ - public static RecordingDeleter deleter(final String pathSid) { - return new RecordingDeleter(pathSid); - } - - /** - * Create a RecordingReader to execute read. - * - * @param pathAccountSid The account_sid - * @return RecordingReader capable of executing the read - */ - public static RecordingReader reader(final String pathAccountSid) { - return new RecordingReader(pathAccountSid); - } - - /** - * Create a RecordingReader to execute read. - * - * @return RecordingReader capable of executing the read - */ - public static RecordingReader reader() { - return new RecordingReader(); - } - - /** - * Converts a JSON String into a Recording object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Recording object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Recording object represented by the provided JSON */ - public static Recording fromJson(final String json, final ObjectMapper objectMapper) { + public static Recording fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -181,12 +150,15 @@ public static Recording fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a Recording object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Recording object represented by the provided JSON */ - public static Recording fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Recording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -197,234 +169,125 @@ public static Recording fromJson(final InputStream json, final ObjectMapper obje } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final String callSid; - private final String conferenceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String duration; - private final String sid; - private final String price; - private final String priceUnit; - private final Recording.Status status; - private final Integer channels; - private final Recording.Source source; - private final Integer errorCode; - private final String uri; - private final Map encryptionDetails; - private final Map subresourceUris; - @JsonCreator - private Recording(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("call_sid") - final String callSid, - @JsonProperty("conference_sid") - final String conferenceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("duration") - final String duration, - @JsonProperty("sid") - final String sid, - @JsonProperty("price") - final String price, - @JsonProperty("price_unit") - final String priceUnit, - @JsonProperty("status") - final Recording.Status status, - @JsonProperty("channels") - final Integer channels, - @JsonProperty("source") - final Recording.Source source, - @JsonProperty("error_code") - final Integer errorCode, - @JsonProperty("uri") - final String uri, - @JsonProperty("encryption_details") - final Map encryptionDetails, - @JsonProperty("subresource_uris") - final Map subresourceUris) { - this.accountSid = accountSid; - this.apiVersion = apiVersion; - this.callSid = callSid; - this.conferenceSid = conferenceSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.duration = duration; - this.sid = sid; - this.price = price; - this.priceUnit = priceUnit; - this.status = status; - this.channels = channels; - this.source = source; - this.errorCode = errorCode; - this.uri = uri; - this.encryptionDetails = encryptionDetails; - this.subresourceUris = subresourceUris; - } + @Getter + private final String callSid; - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Integer channels; - /** - * Returns The The version of the API in use during the recording.. - * - * @return The version of the API in use during the recording. - */ - public final String getApiVersion() { - return this.apiVersion; - } + @Getter + private final String conferenceSid; - /** - * Returns The The unique id for the call leg that corresponds to the - * recording.. - * - * @return The unique id for the call leg that corresponds to the recording. - */ - public final String getCallSid() { - return this.callSid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id for the conference associated with the recording, - * if a conference recording.. - * - * @return The unique id for the conference associated with the recording, if a - * conference recording. - */ - public final String getConferenceSid() { - return this.conferenceSid; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String duration; - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Object encryptionDetails; - /** - * Returns The The length of the recording, in seconds.. - * - * @return The length of the recording, in seconds. - */ - public final String getDuration() { - return this.duration; - } + @Getter + private final Integer errorCode; - /** - * Returns The A string that uniquely identifies this recording. - * - * @return A string that uniquely identifies this recording - */ - public final String getSid() { - return this.sid; - } + @Getter + private final URI mediaUrl; - /** - * Returns The The one-time cost of creating this recording.. - * - * @return The one-time cost of creating this recording. - */ - public final String getPrice() { - return this.price; - } + @Getter + private final String price; - /** - * Returns The The currency used in the Price property.. - * - * @return The currency used in the Price property. - */ - public final String getPriceUnit() { - return this.priceUnit; - } + @Getter + private final String priceUnit; - /** - * Returns The The status of the recording.. - * - * @return The status of the recording. - */ - public final Recording.Status getStatus() { - return this.status; - } + @Getter + private final String sid; - /** - * Returns The The number of channels in the final recording file as an - * integer.. - * - * @return The number of channels in the final recording file as an integer. - */ - public final Integer getChannels() { - return this.channels; - } + @Getter + private final Recording.Source source; - /** - * Returns The The way in which this recording was created.. - * - * @return The way in which this recording was created. - */ - public final Recording.Source getSource() { - return this.source; - } + @Getter + private final ZonedDateTime startTime; - /** - * Returns The More information about the recording failure, if Status is - * failed.. - * - * @return More information about the recording failure, if Status is failed. - */ - public final Integer getErrorCode() { - return this.errorCode; - } + @Getter + private final Recording.Status status; - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } + @Getter + private final Map subresourceUris; - /** - * Returns The Details for how to decrypt the recording.. - * - * @return Details for how to decrypt the recording. - */ - public final Map getEncryptionDetails() { - return this.encryptionDetails; - } + @Getter + private final String uri; - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; + @JsonCreator + private Recording( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("channels") final Integer channels, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("duration") final String duration, + @JsonProperty("encryption_details") final Object encryptionDetails, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("media_url") final URI mediaUrl, + @JsonProperty("price") final String price, + @JsonProperty("price_unit") final String priceUnit, + @JsonProperty("sid") final String sid, + @JsonProperty("source") final Recording.Source source, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime startTime, + @JsonProperty("status") final Recording.Status status, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.apiVersion = apiVersion; + this.callSid = callSid; + this.channels = channels; + this.conferenceSid = conferenceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.duration = duration; + this.encryptionDetails = encryptionDetails; + this.errorCode = errorCode; + this.mediaUrl = mediaUrl; + this.price = price; + this.priceUnit = priceUnit; + this.sid = sid; + this.source = source; + this.startTime = startTime; + this.status = status; + this.subresourceUris = subresourceUris; + this.uri = uri; } @Override @@ -438,67 +301,51 @@ public boolean equals(final Object o) { } Recording other = (Recording) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(callSid, other.callSid) && - Objects.equals(conferenceSid, other.conferenceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(duration, other.duration) && - Objects.equals(sid, other.sid) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(status, other.status) && - Objects.equals(channels, other.channels) && - Objects.equals(source, other.source) && - Objects.equals(errorCode, other.errorCode) && - Objects.equals(uri, other.uri) && - Objects.equals(encryptionDetails, other.encryptionDetails) && - Objects.equals(subresourceUris, other.subresourceUris); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(channels, other.channels) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals(encryptionDetails, other.encryptionDetails) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(mediaUrl, other.mediaUrl) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(sid, other.sid) && + Objects.equals(source, other.source) && + Objects.equals(startTime, other.startTime) && + Objects.equals(status, other.status) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - callSid, - conferenceSid, - dateCreated, - dateUpdated, - duration, - sid, - price, - priceUnit, - status, - channels, - source, - errorCode, - uri, - encryptionDetails, - subresourceUris); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("callSid", callSid) - .add("conferenceSid", conferenceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("duration", duration) - .add("sid", sid) - .add("price", price) - .add("priceUnit", priceUnit) - .add("status", status) - .add("channels", channels) - .add("source", source) - .add("errorCode", errorCode) - .add("uri", uri) - .add("encryptionDetails", encryptionDetails) - .add("subresourceUris", subresourceUris) - .toString(); + return Objects.hash( + accountSid, + apiVersion, + callSid, + channels, + conferenceSid, + dateCreated, + dateUpdated, + duration, + encryptionDetails, + errorCode, + mediaUrl, + price, + priceUnit, + sid, + source, + startTime, + status, + subresourceUris, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/RecordingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/RecordingDeleter.java index 726fa858c1..1fd4f160f9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/RecordingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/RecordingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class RecordingDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new RecordingDeleter. - * - * @param pathSid Delete by unique recording Sid - */ public RecordingDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new RecordingDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique recording Sid - */ - public RecordingDeleter(final String pathAccountSid, - final String pathSid) { + public RecordingDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Recording delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/RecordingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/RecordingFetcher.java index 2cd2545148..e06cffd4ae 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/RecordingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/RecordingFetcher.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +26,108 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RecordingFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; + private Boolean includeSoftDeleted; - /** - * Construct a new RecordingFetcher. - * - * @param pathSid Fetch by unique recording Sid - */ public RecordingFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new RecordingFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique recording Sid - */ - public RecordingFetcher(final String pathAccountSid, - final String pathSid) { + public RecordingFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Recording - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Recording fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public RecordingFetcher setIncludeSoftDeleted( + final Boolean includeSoftDeleted + ) { + this.includeSoftDeleted = includeSoftDeleted; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Recordings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathSid + ".json", - client.getRegion() + path ); + addQueryParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Recording fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public Recording fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recording content = Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (includeSoftDeleted != null) { + Serializer.toString( + request, + "IncludeSoftDeleted", + includeSoftDeleted, + ParameterType.QUERY ); } - - return Recording.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/RecordingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/RecordingReader.java index 680cdedd21..82493abcef 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/RecordingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/RecordingReader.java @@ -1,251 +1,295 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; -import com.google.common.collect.Range; import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class RecordingReader extends Reader { + private String pathAccountSid; - private DateTime absoluteDateCreated; - private Range rangeDateCreated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateCreatedBefore; + private ZonedDateTime dateCreatedAfter; private String callSid; private String conferenceSid; + private Boolean includeSoftDeleted; + private Long pageSize; - /** - * Construct a new RecordingReader. - */ - public RecordingReader() { - } + public RecordingReader() {} - /** - * Construct a new RecordingReader. - * - * @param pathAccountSid The account_sid - */ public RecordingReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only show recordings created on the given date. Should be formatted as - * `YYYY-MM-DD`. You can also specify inequality, such as - * `DateCreated<=YYYY-MM-DD` for recordings generated at or before midnight - * on a date, and `DateCreated>=YYYY-MM-DD` for recordings generated at or - * after midnight on a date.. - * - * @param absoluteDateCreated Filter by date created - * @return this - */ - public RecordingReader setDateCreated(final DateTime absoluteDateCreated) { - this.rangeDateCreated = null; - this.absoluteDateCreated = absoluteDateCreated; + public RecordingReader setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public RecordingReader setDateCreatedBefore( + final ZonedDateTime dateCreatedBefore + ) { + this.dateCreatedBefore = dateCreatedBefore; return this; } - /** - * Only show recordings created on the given date. Should be formatted as - * `YYYY-MM-DD`. You can also specify inequality, such as - * `DateCreated<=YYYY-MM-DD` for recordings generated at or before midnight - * on a date, and `DateCreated>=YYYY-MM-DD` for recordings generated at or - * after midnight on a date.. - * - * @param rangeDateCreated Filter by date created - * @return this - */ - public RecordingReader setDateCreated(final Range rangeDateCreated) { - this.absoluteDateCreated = null; - this.rangeDateCreated = rangeDateCreated; + public RecordingReader setDateCreatedAfter( + final ZonedDateTime dateCreatedAfter + ) { + this.dateCreatedAfter = dateCreatedAfter; return this; } - /** - * Only show recordings made during the call given by the indicated sid. - * - * @param callSid Filter by call_sid - * @return this - */ public RecordingReader setCallSid(final String callSid) { this.callSid = callSid; return this; } - /** - * The conference_sid. - * - * @param conferenceSid The conference_sid - * @return this - */ public RecordingReader setConferenceSid(final String conferenceSid) { this.conferenceSid = conferenceSid; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Recording ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public RecordingReader setIncludeSoftDeleted( + final Boolean includeSoftDeleted + ) { + this.includeSoftDeleted = includeSoftDeleted; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Recording ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public RecordingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Recordings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Recording ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Recording read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Recording Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Recording read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "recordings", - response.getContent(), - Recording.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { - if (absoluteDateCreated != null) { - request.addQueryParam("DateCreated", absoluteDateCreated.toString(Request.QUERY_STRING_DATE_TIME_FORMAT)); - } else if (rangeDateCreated != null) { - request.addQueryDateTimeRange("DateCreated", rangeDateCreated); - } + Serializer.toString( + request, + "DateCreated", + dateCreated, + dateCreatedBefore, + dateCreatedAfter + ); if (callSid != null) { - request.addQueryParam("CallSid", callSid); + Serializer.toString( + request, + "CallSid", + callSid, + ParameterType.QUERY + ); } if (conferenceSid != null) { - request.addQueryParam("ConferenceSid", conferenceSid); + Serializer.toString( + request, + "ConferenceSid", + conferenceSid, + ParameterType.QUERY + ); + } + + if (includeSoftDeleted != null) { + Serializer.toString( + request, + "IncludeSoftDeleted", + includeSoftDeleted, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ShortCode.java b/src/main/java/com/twilio/rest/api/v2010/account/ShortCode.java index b9baf8012a..90b4d24cdc 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ShortCode.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ShortCode.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,103 +18,71 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class ShortCode extends Resource { - private static final long serialVersionUID = 186171326966142L; - - /** - * Create a ShortCodeFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique short-code Sid - * @return ShortCodeFetcher capable of executing the fetch - */ - public static ShortCodeFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new ShortCodeFetcher(pathAccountSid, pathSid); - } - /** - * Create a ShortCodeFetcher to execute fetch. - * - * @param pathSid Fetch by unique short-code Sid - * @return ShortCodeFetcher capable of executing the fetch - */ public static ShortCodeFetcher fetcher(final String pathSid) { return new ShortCodeFetcher(pathSid); } - /** - * Create a ShortCodeUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return ShortCodeUpdater capable of executing the update - */ - public static ShortCodeUpdater updater(final String pathAccountSid, - final String pathSid) { - return new ShortCodeUpdater(pathAccountSid, pathSid); + public static ShortCodeFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new ShortCodeFetcher(pathAccountSid, pathSid); } - /** - * Create a ShortCodeUpdater to execute update. - * - * @param pathSid The sid - * @return ShortCodeUpdater capable of executing the update - */ - public static ShortCodeUpdater updater(final String pathSid) { - return new ShortCodeUpdater(pathSid); + public static ShortCodeReader reader() { + return new ShortCodeReader(); } - /** - * Create a ShortCodeReader to execute read. - * - * @param pathAccountSid The account_sid - * @return ShortCodeReader capable of executing the read - */ public static ShortCodeReader reader(final String pathAccountSid) { return new ShortCodeReader(pathAccountSid); } - /** - * Create a ShortCodeReader to execute read. - * - * @return ShortCodeReader capable of executing the read - */ - public static ShortCodeReader reader() { - return new ShortCodeReader(); + public static ShortCodeUpdater updater(final String pathSid) { + return new ShortCodeUpdater(pathSid); + } + + public static ShortCodeUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new ShortCodeUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a ShortCode object using the provided - * ObjectMapper. - * + * Converts a JSON String into a ShortCode object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return ShortCode object represented by the provided JSON */ - public static ShortCode fromJson(final String json, final ObjectMapper objectMapper) { + public static ShortCode fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -121,12 +96,15 @@ public static ShortCode fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a ShortCode object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return ShortCode object represented by the provided JSON */ - public static ShortCode fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static ShortCode fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -137,48 +115,77 @@ public static ShortCode fromJson(final InputStream json, final ObjectMapper obje } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter private final String shortCode; + + @Getter private final String sid; + + @Getter private final HttpMethod smsFallbackMethod; + + @Getter private final URI smsFallbackUrl; + + @Getter private final HttpMethod smsMethod; + + @Getter private final URI smsUrl; + + @Getter private final String uri; @JsonCreator - private ShortCode(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("short_code") - final String shortCode, - @JsonProperty("sid") - final String sid, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("uri") - final String uri) { + private ShortCode( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("short_code") final String shortCode, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; this.shortCode = shortCode; this.sid = sid; @@ -189,114 +196,6 @@ private ShortCode(@JsonProperty("account_sid") this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The API version to use. - * - * @return The API version to use - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human readable description of this resource. - * - * @return A human readable description of this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The short code. e.g., 894546.. - * - * @return The short code. e.g., 894546. - */ - public final String getShortCode() { - return this.shortCode; - } - - /** - * Returns The A string that uniquely identifies this short-codes. - * - * @return A string that uniquely identifies this short-codes - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The HTTP method Twilio will use with sms fallback url. - * - * @return HTTP method Twilio will use with sms fallback url - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - - /** - * Returns The URL Twilio will request if an error occurs in executing TwiML. - * - * @return URL Twilio will request if an error occurs in executing TwiML - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - - /** - * Returns The HTTP method to use when requesting the sms url. - * - * @return HTTP method to use when requesting the sms url - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - - /** - * Returns The URL Twilio will request when receiving an SMS. - * - * @return URL Twilio will request when receiving an SMS - */ - public final URI getSmsUrl() { - return this.smsUrl; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -308,52 +207,37 @@ public boolean equals(final Object o) { } ShortCode other = (ShortCode) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(shortCode, other.shortCode) && - Objects.equals(sid, other.sid) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(shortCode, other.shortCode) && + Objects.equals(sid, other.sid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - dateCreated, - dateUpdated, - friendlyName, - shortCode, - sid, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsUrl, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("shortCode", shortCode) - .add("sid", sid) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsUrl", smsUrl) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + dateCreated, + dateUpdated, + friendlyName, + shortCode, + sid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeFetcher.java index 3355e04de2..f096eeab69 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ShortCodeFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new ShortCodeFetcher. - * - * @param pathSid Fetch by unique short-code Sid - */ public ShortCodeFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ShortCodeFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique short-code Sid - */ - public ShortCodeFetcher(final String pathAccountSid, - final String pathSid) { + public ShortCodeFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched ShortCode - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ShortCode fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SMS/ShortCodes/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "ShortCode fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public ShortCode fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ShortCode content = ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeReader.java b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeReader.java index 7056b95cd8..3f2d77903d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,201 +17,231 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ShortCodeReader extends Reader { + private String pathAccountSid; private String friendlyName; private String shortCode; + private Long pageSize; - /** - * Construct a new ShortCodeReader. - */ - public ShortCodeReader() { - } + public ShortCodeReader() {} - /** - * Construct a new ShortCodeReader. - * - * @param pathAccountSid The account_sid - */ public ShortCodeReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only show the ShortCode resources with friendly names that exactly match this - * name.. - * - * @param friendlyName Filter by friendly name - * @return this - */ public ShortCodeReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Only show the ShortCode resources that match this pattern. You can specify - * partial numbers and use '*' as a wildcard for any digit.. - * - * @param shortCode Filter by ShortCode - * @return this - */ public ShortCodeReader setShortCode(final String shortCode) { this.shortCode = shortCode; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ShortCodeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "short_codes", + response.getContent(), + ShortCode.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SMS/ShortCodes.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "short_codes", + response.getContent(), + ShortCode.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ShortCode read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "short_codes", + response.getContent(), + ShortCode.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of ShortCode Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "short_codes", - response.getContent(), - ShortCode.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (shortCode != null) { - request.addQueryParam("ShortCode", shortCode); + Serializer.toString( + request, + "ShortCode", + shortCode, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeUpdater.java index e76d047e3a..1948e922c4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ShortCodeUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class ShortCodeUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private String friendlyName; private String apiVersion; private URI smsUrl; @@ -30,191 +43,179 @@ public class ShortCodeUpdater extends Updater { private URI smsFallbackUrl; private HttpMethod smsFallbackMethod; - /** - * Construct a new ShortCodeUpdater. - * - * @param pathSid The sid - */ public ShortCodeUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new ShortCodeUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public ShortCodeUpdater(final String pathAccountSid, - final String pathSid) { + public ShortCodeUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * A human readable descriptive text for this resource, up to 64 characters - * long. By default, the `FriendlyName` is just the short code.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ public ShortCodeUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * SMSs to this short code will start a new TwiML session with this API version. - * Either `2010-04-01` or `2008-08-01`.. - * - * @param apiVersion The API version to use - * @return this - */ public ShortCodeUpdater setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - /** - * The URL Twilio will request when receiving an incoming SMS message to this - * short code.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public ShortCodeUpdater setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL Twilio will request when receiving an incoming SMS message to this - * short code.. - * - * @param smsUrl URL Twilio will request when receiving an SMS - * @return this - */ public ShortCodeUpdater setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The HTTP method Twilio will use when making requests to the `SmsUrl`. Either - * `GET` or `POST`.. - * - * @param smsMethod HTTP method to use when requesting the sms url - * @return this - */ public ShortCodeUpdater setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * The URL that Twilio will request if an error occurs retrieving or executing - * the TwiML from `SmsUrl`.. - * - * @param smsFallbackUrl URL Twilio will request if an error occurs in - * executing TwiML - * @return this - */ public ShortCodeUpdater setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * The URL that Twilio will request if an error occurs retrieving or executing - * the TwiML from `SmsUrl`.. - * - * @param smsFallbackUrl URL Twilio will request if an error occurs in - * executing TwiML - * @return this - */ public ShortCodeUpdater setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method that should be used to request the `SmsFallbackUrl`. Either - * `GET` or `POST`.. - * - * @param smsFallbackMethod HTTP method Twilio will use with sms fallback url - * @return this - */ - public ShortCodeUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public ShortCodeUpdater setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated ShortCode - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ShortCode update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SMS/ShortCodes/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SMS/ShortCodes/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "ShortCode update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public ShortCode update(final TwilioRestClient client) { + Response response = makeRequest(client); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ShortCode content = ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (apiVersion != null) { - request.addPostParam("ApiVersion", apiVersion); + Serializer.toString( + request, + "ApiVersion", + apiVersion, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKey.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKey.java index a952f96da4..4804969a81 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKey.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKey.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,124 +18,80 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SigningKey extends Resource { - private static final long serialVersionUID = 96350302686036L; - - /** - * Create a SigningKeyFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return SigningKeyFetcher capable of executing the fetch - */ - public static SigningKeyFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new SigningKeyFetcher(pathAccountSid, pathSid); - } - /** - * Create a SigningKeyFetcher to execute fetch. - * - * @param pathSid The sid - * @return SigningKeyFetcher capable of executing the fetch - */ - public static SigningKeyFetcher fetcher(final String pathSid) { - return new SigningKeyFetcher(pathSid); + public static SigningKeyDeleter deleter(final String pathSid) { + return new SigningKeyDeleter(pathSid); } - /** - * Create a SigningKeyUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return SigningKeyUpdater capable of executing the update - */ - public static SigningKeyUpdater updater(final String pathAccountSid, - final String pathSid) { - return new SigningKeyUpdater(pathAccountSid, pathSid); + public static SigningKeyDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new SigningKeyDeleter(pathAccountSid, pathSid); } - /** - * Create a SigningKeyUpdater to execute update. - * - * @param pathSid The sid - * @return SigningKeyUpdater capable of executing the update - */ - public static SigningKeyUpdater updater(final String pathSid) { - return new SigningKeyUpdater(pathSid); + public static SigningKeyFetcher fetcher(final String pathSid) { + return new SigningKeyFetcher(pathSid); } - /** - * Create a SigningKeyDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return SigningKeyDeleter capable of executing the delete - */ - public static SigningKeyDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new SigningKeyDeleter(pathAccountSid, pathSid); + public static SigningKeyFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new SigningKeyFetcher(pathAccountSid, pathSid); } - /** - * Create a SigningKeyDeleter to execute delete. - * - * @param pathSid The sid - * @return SigningKeyDeleter capable of executing the delete - */ - public static SigningKeyDeleter deleter(final String pathSid) { - return new SigningKeyDeleter(pathSid); + public static SigningKeyReader reader() { + return new SigningKeyReader(); } - /** - * Create a SigningKeyReader to execute read. - * - * @param pathAccountSid The account_sid - * @return SigningKeyReader capable of executing the read - */ public static SigningKeyReader reader(final String pathAccountSid) { return new SigningKeyReader(pathAccountSid); } - /** - * Create a SigningKeyReader to execute read. - * - * @return SigningKeyReader capable of executing the read - */ - public static SigningKeyReader reader() { - return new SigningKeyReader(); + public static SigningKeyUpdater updater(final String pathSid) { + return new SigningKeyUpdater(pathSid); + } + + public static SigningKeyUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new SigningKeyUpdater(pathAccountSid, pathSid); } /** - * Converts a JSON String into a SigningKey object using the provided - * ObjectMapper. - * + * Converts a JSON String into a SigningKey object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SigningKey object represented by the provided JSON */ - public static SigningKey fromJson(final String json, final ObjectMapper objectMapper) { + public static SigningKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SigningKey.class); @@ -142,12 +105,15 @@ public static SigningKey fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a SigningKey object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SigningKey object represented by the provided JSON */ - public static SigningKey fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SigningKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SigningKey.class); @@ -158,60 +124,45 @@ public static SigningKey fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private SigningKey(@JsonProperty("sid") - final String sid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String friendlyName; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; + @Getter + private final String sid; + + @JsonCreator + private SigningKey( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; } @Override @@ -225,28 +176,16 @@ public boolean equals(final Object o) { } SigningKey other = (SigningKey) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(sid, - friendlyName, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); + return Objects.hash(dateCreated, dateUpdated, friendlyName, sid); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyDeleter.java index 21ec800a4d..412475d6b3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class SigningKeyDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new SigningKeyDeleter. - * - * @param pathSid The sid - */ public SigningKeyDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new SigningKeyDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public SigningKeyDeleter(final String pathAccountSid, - final String pathSid) { + public SigningKeyDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SigningKeys/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SigningKey delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SigningKey delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyFetcher.java index b0a558966e..cfcf671be3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class SigningKeyFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new SigningKeyFetcher. - * - * @param pathSid The sid - */ public SigningKeyFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new SigningKeyFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public SigningKeyFetcher(final String pathAccountSid, - final String pathSid) { + public SigningKeyFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SigningKey - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SigningKey fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SigningKeys/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SigningKey fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SigningKey fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return SigningKey.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public SigningKey fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SigningKey content = SigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyReader.java index 0a56209879..dc7cae9591 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,167 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class SigningKeyReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new SigningKeyReader. - */ - public SigningKeyReader() { - } + public SigningKeyReader() {} - /** - * Construct a new SigningKeyReader. - * - * @param pathAccountSid The account_sid - */ public SigningKeyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SigningKey ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SigningKeyReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SigningKey ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "signing_keys", + response.getContent(), + SigningKey.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/SigningKeys.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SigningKeys.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SigningKey ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "signing_keys", + response.getContent(), + SigningKey.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SigningKey read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "signing_keys", + response.getContent(), + SigningKey.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SigningKey Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SigningKey read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "signing_keys", - response.getContent(), - SigningKey.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyUpdater.java index 712b230889..060b37a3ec 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/SigningKeyUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,92 +27,111 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class SigningKeyUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private String friendlyName; - /** - * Construct a new SigningKeyUpdater. - * - * @param pathSid The sid - */ public SigningKeyUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new SigningKeyUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public SigningKeyUpdater(final String pathAccountSid, - final String pathSid) { + public SigningKeyUpdater( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public SigningKeyUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SigningKey - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SigningKey update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SigningKeys/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SigningKeys/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SigningKey update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SigningKey update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return SigningKey.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public SigningKey update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SigningKey content = SigningKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Token.java b/src/main/java/com/twilio/rest/api/v2010/account/Token.java index 4b5361a8e3..d31bf68e57 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Token.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Token.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,59 +18,49 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.IceServer; -import org.joda.time.DateTime; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Token extends Resource { - private static final long serialVersionUID = 281090396283982L; - - /** - * Create a TokenCreator to execute create. - * - * @param pathAccountSid The account_sid - * @return TokenCreator capable of executing the create - */ - public static TokenCreator creator(final String pathAccountSid) { - return new TokenCreator(pathAccountSid); - } - /** - * Create a TokenCreator to execute create. - * - * @return TokenCreator capable of executing the create - */ public static TokenCreator creator() { return new TokenCreator(); } + public static TokenCreator creator(final String pathAccountSid) { + return new TokenCreator(pathAccountSid); + } + /** * Converts a JSON String into a Token object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Token object represented by the provided JSON */ - public static Token fromJson(final String json, final ObjectMapper objectMapper) { + public static Token fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Token.class); @@ -77,12 +74,15 @@ public static Token fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Token object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Token object represented by the provided JSON */ - public static Token fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Token fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Token.class); @@ -93,101 +93,62 @@ public static Token fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final List iceServers; + + @Getter private final String password; + + @Getter private final String ttl; + + @Getter private final String username; @JsonCreator - private Token(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("ice_servers") - final List iceServers, - @JsonProperty("password") - final String password, - @JsonProperty("ttl") - final String ttl, - @JsonProperty("username") - final String username) { + private Token( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("ice_servers") final List iceServers, + @JsonProperty("password") final String password, + @JsonProperty("ttl") final String ttl, + @JsonProperty("username") final String username + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.iceServers = iceServers; this.password = password; this.ttl = ttl; this.username = username; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The An array representing the ephemeral credentials. - * - * @return An array representing the ephemeral credentials - */ - public final List getIceServers() { - return this.iceServers; - } - - /** - * Returns The The temporary password used for authenticating. - * - * @return The temporary password used for authenticating - */ - public final String getPassword() { - return this.password; - } - - /** - * Returns The The duration in seconds the credentials are valid. - * - * @return The duration in seconds the credentials are valid - */ - public final String getTtl() { - return this.ttl; - } - - /** - * Returns The The temporary username that uniquely identifies a Token.. - * - * @return The temporary username that uniquely identifies a Token. - */ - public final String getUsername() { - return this.username; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -199,37 +160,27 @@ public boolean equals(final Object o) { } Token other = (Token) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(iceServers, other.iceServers) && - Objects.equals(password, other.password) && - Objects.equals(ttl, other.ttl) && - Objects.equals(username, other.username); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(iceServers, other.iceServers) && + Objects.equals(password, other.password) && + Objects.equals(ttl, other.ttl) && + Objects.equals(username, other.username) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - iceServers, - password, - ttl, - username); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("iceServers", iceServers) - .add("password", password) - .add("ttl", ttl) - .add("username", username) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + iceServers, + password, + ttl, + username + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/TokenCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/TokenCreator.java index 9a0654b712..f3ddcf6b3c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/TokenCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/TokenCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,86 +27,94 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TokenCreator extends Creator { + private String pathAccountSid; private Integer ttl; - /** - * Construct a new TokenCreator. - */ - public TokenCreator() { - } + public TokenCreator() {} - /** - * Construct a new TokenCreator. - * - * @param pathAccountSid The account_sid - */ public TokenCreator(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * The duration in seconds for which the generated credentials are valid, the - * default value is 86400 (24 hours).. - * - * @param ttl The duration in seconds the credentials are valid - * @return this - */ public TokenCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Token - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Token create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Tokens.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Tokens.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Token creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Token creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Token create(final TwilioRestClient client) { + Response response = makeRequest(client); return Token.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Token content = Token.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/Transcription.java b/src/main/java/com/twilio/rest/api/v2010/account/Transcription.java index 6993d131bf..bf9510bcb4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/Transcription.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/Transcription.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,34 +17,62 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.ZonedDateTime; import java.util.Currency; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Transcription extends Resource { - private static final long serialVersionUID = 3308072321352L; + + public static TranscriptionDeleter deleter(final String pathSid) { + return new TranscriptionDeleter(pathSid); + } + + public static TranscriptionDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new TranscriptionDeleter(pathAccountSid, pathSid); + } + + public static TranscriptionFetcher fetcher(final String pathSid) { + return new TranscriptionFetcher(pathSid); + } + + public static TranscriptionFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new TranscriptionFetcher(pathAccountSid, pathSid); + } + + public static TranscriptionReader reader() { + return new TranscriptionReader(); + } + + public static TranscriptionReader reader(final String pathAccountSid) { + return new TranscriptionReader(pathAccountSid); + } public enum Status { IN_PROGRESS("in-progress"), @@ -50,15 +85,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -66,77 +97,16 @@ public static Status forValue(final String value) { } /** - * Create a TranscriptionFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique transcription Sid - * @return TranscriptionFetcher capable of executing the fetch - */ - public static TranscriptionFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new TranscriptionFetcher(pathAccountSid, pathSid); - } - - /** - * Create a TranscriptionFetcher to execute fetch. - * - * @param pathSid Fetch by unique transcription Sid - * @return TranscriptionFetcher capable of executing the fetch - */ - public static TranscriptionFetcher fetcher(final String pathSid) { - return new TranscriptionFetcher(pathSid); - } - - /** - * Create a TranscriptionDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique transcription Sid - * @return TranscriptionDeleter capable of executing the delete - */ - public static TranscriptionDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new TranscriptionDeleter(pathAccountSid, pathSid); - } - - /** - * Create a TranscriptionDeleter to execute delete. - * - * @param pathSid Delete by unique transcription Sid - * @return TranscriptionDeleter capable of executing the delete - */ - public static TranscriptionDeleter deleter(final String pathSid) { - return new TranscriptionDeleter(pathSid); - } - - /** - * Create a TranscriptionReader to execute read. - * - * @param pathAccountSid The account_sid - * @return TranscriptionReader capable of executing the read - */ - public static TranscriptionReader reader(final String pathAccountSid) { - return new TranscriptionReader(pathAccountSid); - } - - /** - * Create a TranscriptionReader to execute read. - * - * @return TranscriptionReader capable of executing the read - */ - public static TranscriptionReader reader() { - return new TranscriptionReader(); - } - - /** - * Converts a JSON String into a Transcription object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Transcription object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Transcription object represented by the provided JSON */ - public static Transcription fromJson(final String json, final ObjectMapper objectMapper) { + public static Transcription fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcription.class); @@ -150,12 +120,15 @@ public static Transcription fromJson(final String json, final ObjectMapper objec /** * Converts a JSON InputStream into a Transcription object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Transcription object represented by the provided JSON */ - public static Transcription fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Transcription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcription.class); @@ -166,52 +139,83 @@ public static Transcription fromJson(final InputStream json, final ObjectMapper } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String duration; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final String recordingSid; + + @Getter private final String sid; + + @Getter private final Transcription.Status status; + + @Getter private final String transcriptionText; + + @Getter private final String type; + + @Getter private final String uri; @JsonCreator - private Transcription(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("duration") - final String duration, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("recording_sid") - final String recordingSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("status") - final Transcription.Status status, - @JsonProperty("transcription_text") - final String transcriptionText, - @JsonProperty("type") - final String type, - @JsonProperty("uri") - final String uri) { + private Transcription( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("duration") final String duration, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("recording_sid") final String recordingSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Transcription.Status status, + @JsonProperty("transcription_text") final String transcriptionText, + @JsonProperty("type") final String type, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.duration = duration; this.price = price; this.priceUnit = priceUnit; @@ -223,123 +227,6 @@ private Transcription(@JsonProperty("account_sid") this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The duration of the transcribed audio, in seconds.. - * - * @return The duration of the transcribed audio, in seconds. - */ - public final String getDuration() { - return this.duration; - } - - /** - * Returns The The charge for this transcription. - * - * @return The charge for this transcription - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured. - * - * @return The currency in which Price is measured - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The string that uniquely identifies the recording. - * - * @return The string that uniquely identifies the recording - */ - public final String getRecordingSid() { - return this.recordingSid; - } - - /** - * Returns The A string that uniquely identifies this transcription. - * - * @return A string that uniquely identifies this transcription - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The status of the transcription. - * - * @return The status of the transcription - */ - public final Transcription.Status getStatus() { - return this.status; - } - - /** - * Returns The The text content of the transcription.. - * - * @return The text content of the transcription. - */ - public final String getTranscriptionText() { - return this.transcriptionText; - } - - /** - * Returns The The type. - * - * @return The type - */ - public final String getType() { - return this.type; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -351,55 +238,39 @@ public boolean equals(final Object o) { } Transcription other = (Transcription) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(duration, other.duration) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(recordingSid, other.recordingSid) && - Objects.equals(sid, other.sid) && - Objects.equals(status, other.status) && - Objects.equals(transcriptionText, other.transcriptionText) && - Objects.equals(type, other.type) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(recordingSid, other.recordingSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(transcriptionText, other.transcriptionText) && + Objects.equals(type, other.type) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - dateCreated, - dateUpdated, - duration, - price, - priceUnit, - recordingSid, - sid, - status, - transcriptionText, - type, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("duration", duration) - .add("price", price) - .add("priceUnit", priceUnit) - .add("recordingSid", recordingSid) - .add("sid", sid) - .add("status", status) - .add("transcriptionText", transcriptionText) - .add("type", type) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + apiVersion, + dateCreated, + dateUpdated, + duration, + price, + priceUnit, + recordingSid, + sid, + status, + transcriptionText, + type, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionDeleter.java index a63313a529..f844ea89f9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class TranscriptionDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new TranscriptionDeleter. - * - * @param pathSid Delete by unique transcription Sid - */ public TranscriptionDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new TranscriptionDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique transcription Sid - */ - public TranscriptionDeleter(final String pathAccountSid, - final String pathSid) { + public TranscriptionDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Transcriptions/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Transcription delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionFetcher.java index 0702f4d9a3..b0de7e5985 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TranscriptionFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new TranscriptionFetcher. - * - * @param pathSid Fetch by unique transcription Sid - */ public TranscriptionFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new TranscriptionFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique transcription Sid - */ - public TranscriptionFetcher(final String pathAccountSid, - final String pathSid) { + public TranscriptionFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Transcription - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Transcription fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Transcriptions/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Transcriptions/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Transcription fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Transcription.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Transcription fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Transcription content = Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionReader.java b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionReader.java index 0176c20ab1..a7b8c3d0fb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/TranscriptionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -10,167 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TranscriptionReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new TranscriptionReader. - */ - public TranscriptionReader() { - } + public TranscriptionReader() {} - /** - * Construct a new TranscriptionReader. - * - * @param pathAccountSid The account_sid - */ public TranscriptionReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Transcription ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TranscriptionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Transcription ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "transcriptions", + response.getContent(), + Transcription.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Transcriptions.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Transcriptions.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Transcription ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "transcriptions", + response.getContent(), + Transcription.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Transcription read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "transcriptions", + response.getContent(), + Transcription.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Transcription Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Transcription read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "transcriptions", - response.getContent(), - Transcription.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequest.java b/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequest.java index 77d4ddff62..78e3c59631 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequest.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequest.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; @@ -11,59 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class ValidationRequest extends Resource { - private static final long serialVersionUID = 227253393242231L; - /** - * Create a ValidationRequestCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number to verify. - * @return ValidationRequestCreator capable of executing the create - */ - public static ValidationRequestCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { - return new ValidationRequestCreator(pathAccountSid, phoneNumber); + public static ValidationRequestCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new ValidationRequestCreator(phoneNumber); } - /** - * Create a ValidationRequestCreator to execute create. - * - * @param phoneNumber The phone number to verify. - * @return ValidationRequestCreator capable of executing the create - */ - public static ValidationRequestCreator creator(final com.twilio.type.PhoneNumber phoneNumber) { - return new ValidationRequestCreator(phoneNumber); + public static ValidationRequestCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new ValidationRequestCreator(pathAccountSid, phoneNumber); } /** - * Converts a JSON String into a ValidationRequest object using the provided - * ObjectMapper. - * + * Converts a JSON String into a ValidationRequest object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return ValidationRequest object represented by the provided JSON */ - public static ValidationRequest fromJson(final String json, final ObjectMapper objectMapper) { + public static ValidationRequest fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ValidationRequest.class); @@ -75,14 +73,17 @@ public static ValidationRequest fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a ValidationRequest object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a ValidationRequest object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return ValidationRequest object represented by the provided JSON */ - public static ValidationRequest fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static ValidationRequest fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ValidationRequest.class); @@ -93,77 +94,48 @@ public static ValidationRequest fromJson(final InputStream json, final ObjectMap } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String friendlyName; - private final Integer validationCode; + + @Getter private final String callSid; + @Getter + private final String friendlyName; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter + private final String validationCode; + @JsonCreator - private ValidationRequest(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("validation_code") - final Integer validationCode, - @JsonProperty("call_sid") - final String callSid) { + private ValidationRequest( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("validation_code") final String validationCode + ) { this.accountSid = accountSid; - this.phoneNumber = phoneNumber; + this.callSid = callSid; this.friendlyName = friendlyName; + this.phoneNumber = phoneNumber; this.validationCode = validationCode; - this.callSid = callSid; - } - - /** - * Returns The The unique ID of the Account responsible for this Caller Id.. - * - * @return The unique ID of the Account responsible for this Caller Id. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The incoming phone number.. - * - * @return The incoming phone number. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - - /** - * Returns The A human readable descriptive text for this resource, up to 64 - * characters long.. - * - * @return A human readable descriptive text for this resource, up to 64 - * characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The 6 digit validation code that must be entered via the phone to - * validate this phone number for Caller ID.. - * - * @return The 6 digit validation code that must be entered via the phone to - * validate this phone number for Caller ID. - */ - public final Integer getValidationCode() { - return this.validationCode; - } - - /** - * Returns The The unique id of the Call created for this validation attempt.. - * - * @return The unique id of the Call created for this validation attempt. - */ - public final String getCallSid() { - return this.callSid; } @Override @@ -177,31 +149,23 @@ public boolean equals(final Object o) { } ValidationRequest other = (ValidationRequest) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(validationCode, other.validationCode) && - Objects.equals(callSid, other.callSid); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(validationCode, other.validationCode) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - phoneNumber, - friendlyName, - validationCode, - callSid); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("phoneNumber", phoneNumber) - .add("friendlyName", friendlyName) - .add("validationCode", validationCode) - .add("callSid", callSid) - .toString(); + return Objects.hash( + accountSid, + callSid, + friendlyName, + phoneNumber, + validationCode + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequestCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequestCreator.java index 383903a01f..dfb51e27e8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequestCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/ValidationRequestCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,186 +28,203 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class ValidationRequestCreator extends Creator { + private String pathAccountSid; - private final com.twilio.type.PhoneNumber phoneNumber; + private com.twilio.type.PhoneNumber phoneNumber; private String friendlyName; private Integer callDelay; private String extension; private URI statusCallback; private HttpMethod statusCallbackMethod; - /** - * Construct a new ValidationRequestCreator. - * - * @param phoneNumber The phone number to verify. - */ - public ValidationRequestCreator(final com.twilio.type.PhoneNumber phoneNumber) { + public ValidationRequestCreator( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; } - /** - * Construct a new ValidationRequestCreator. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number to verify. - */ - public ValidationRequestCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { + public ValidationRequestCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - /** - * A human readable description for the new caller ID with maximum length 64 - * characters. Defaults to a nicely formatted version of the number.. - * - * @param friendlyName A human readable description for the new caller ID with - * maximum length 64 characters. - * @return this - */ + public ValidationRequestCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { + this.phoneNumber = phoneNumber; + return this; + } + + public ValidationRequestCreator setPhoneNumber(final String phoneNumber) { + return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); + } + public ValidationRequestCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The number of seconds, between 0 and 60, to delay before initiating the - * verification call. Defaults to 0.. - * - * @param callDelay The number of seconds, between 0 and 60, to delay before - * initiating the verification call. - * @return this - */ public ValidationRequestCreator setCallDelay(final Integer callDelay) { this.callDelay = callDelay; return this; } - /** - * Digits to dial after connecting the verification call.. - * - * @param extension Digits to dial after connecting the verification call. - * @return this - */ public ValidationRequestCreator setExtension(final String extension) { this.extension = extension; return this; } - /** - * A URL that Twilio will request when the verification call ends to notify your - * app if the verification process was successful or not. See [StatusCallback - * parameter](https://www.twilio.com/docs/api/voice/outgoing-caller-ids#statuscallback-parameter) below.. - * - * @param statusCallback A URL that Twilio will request when the verification - * call ends to notify your app if the verification - * process was successful or not. - * @return this - */ - public ValidationRequestCreator setStatusCallback(final URI statusCallback) { + public ValidationRequestCreator setStatusCallback( + final URI statusCallback + ) { this.statusCallback = statusCallback; return this; } - /** - * A URL that Twilio will request when the verification call ends to notify your - * app if the verification process was successful or not. See [StatusCallback - * parameter](https://www.twilio.com/docs/api/voice/outgoing-caller-ids#statuscallback-parameter) below.. - * - * @param statusCallback A URL that Twilio will request when the verification - * call ends to notify your app if the verification - * process was successful or not. - * @return this - */ - public ValidationRequestCreator setStatusCallback(final String statusCallback) { + public ValidationRequestCreator setStatusCallback( + final String statusCallback + ) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio should use when requesting the above URL. Defaults to - * POST.. - * - * @param statusCallbackMethod The HTTP method Twilio should use when - * requesting the above URL. - * @return this - */ - public ValidationRequestCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public ValidationRequestCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created ValidationRequest - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ValidationRequest create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/OutgoingCallerIds.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/OutgoingCallerIds.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ValidationRequest creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "ValidationRequest creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public ValidationRequest create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ValidationRequest.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return ValidationRequest.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ValidationRequest content = ValidationRequest.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (phoneNumber != null) { - request.addPostParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (callDelay != null) { - request.addPostParam("CallDelay", callDelay.toString()); + Serializer.toString( + request, + "CallDelay", + callDelay, + ParameterType.URLENCODED + ); } if (extension != null) { - request.addPostParam("Extension", extension); + Serializer.toString( + request, + "Extension", + extension, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumber.java b/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumber.java index be948b1a8d..9395602a7d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumber.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumber.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.address; @@ -10,117 +17,101 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class DependentPhoneNumber extends Resource { - private static final long serialVersionUID = 25853317680371L; - public enum AddressRequirement { - NONE("none"), - ANY("any"), - LOCAL("local"), - FOREIGN("foreign"); + public static DependentPhoneNumberReader reader( + final String pathAddressSid + ) { + return new DependentPhoneNumberReader(pathAddressSid); + } + + public static DependentPhoneNumberReader reader( + final String pathAccountSid, + final String pathAddressSid + ) { + return new DependentPhoneNumberReader(pathAccountSid, pathAddressSid); + } + + public enum EmergencyStatus { + ACTIVE("Active"), + INACTIVE("Inactive"); private final String value; - private AddressRequirement(final String value) { + private EmergencyStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a AddressRequirement from a string. - * @param value string value - * @return generated AddressRequirement - */ @JsonCreator - public static AddressRequirement forValue(final String value) { - return Promoter.enumFromString(value, AddressRequirement.values()); + public static EmergencyStatus forValue(final String value) { + return Promoter.enumFromString(value, EmergencyStatus.values()); } } - public enum EmergencyStatus { - ACTIVE("Active"), - INACTIVE("Inactive"); + public enum AddressRequirement { + NONE("none"), + ANY("any"), + LOCAL("local"), + FOREIGN("foreign"); private final String value; - private EmergencyStatus(final String value) { + private AddressRequirement(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a EmergencyStatus from a string. - * @param value string value - * @return generated EmergencyStatus - */ @JsonCreator - public static EmergencyStatus forValue(final String value) { - return Promoter.enumFromString(value, EmergencyStatus.values()); + public static AddressRequirement forValue(final String value) { + return Promoter.enumFromString(value, AddressRequirement.values()); } } /** - * Create a DependentPhoneNumberReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathAddressSid The address_sid - * @return DependentPhoneNumberReader capable of executing the read - */ - public static DependentPhoneNumberReader reader(final String pathAccountSid, - final String pathAddressSid) { - return new DependentPhoneNumberReader(pathAccountSid, pathAddressSid); - } - - /** - * Create a DependentPhoneNumberReader to execute read. - * - * @param pathAddressSid The address_sid - * @return DependentPhoneNumberReader capable of executing the read - */ - public static DependentPhoneNumberReader reader(final String pathAddressSid) { - return new DependentPhoneNumberReader(pathAddressSid); - } - - /** - * Converts a JSON String into a DependentPhoneNumber object using the provided - * ObjectMapper. - * + * Converts a JSON String into a DependentPhoneNumber object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return DependentPhoneNumber object represented by the provided JSON */ - public static DependentPhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + public static DependentPhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DependentPhoneNumber.class); @@ -132,14 +123,17 @@ public static DependentPhoneNumber fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a DependentPhoneNumber object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a DependentPhoneNumber object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return DependentPhoneNumber object represented by the provided JSON */ - public static DependentPhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static DependentPhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DependentPhoneNumber.class); @@ -150,346 +144,167 @@ public static DependentPhoneNumber fromJson(final InputStream json, final Object } } - private final String sid; - private final String accountSid; - private final com.twilio.type.PhoneNumber friendlyName; - private final com.twilio.type.PhoneNumber phoneNumber; - private final URI voiceUrl; - private final HttpMethod voiceMethod; - private final HttpMethod voiceFallbackMethod; - private final URI voiceFallbackUrl; - private final Boolean voiceCallerIdLookup; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final HttpMethod smsFallbackMethod; - private final URI smsFallbackUrl; - private final HttpMethod smsMethod; - private final URI smsUrl; - private final DependentPhoneNumber.AddressRequirement addressRequirements; - private final Map capabilities; - private final URI statusCallback; - private final HttpMethod statusCallbackMethod; - private final String apiVersion; - private final String smsApplicationSid; - private final String voiceApplicationSid; - private final String trunkSid; - private final DependentPhoneNumber.EmergencyStatus emergencyStatus; - private final String emergencyAddressSid; - private final String uri; - - @JsonCreator - private DependentPhoneNumber(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("voice_url") - final URI voiceUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("address_requirements") - final DependentPhoneNumber.AddressRequirement addressRequirements, - @JsonProperty("capabilities") - final Map capabilities, - @JsonProperty("status_callback") - final URI statusCallback, - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("emergency_status") - final DependentPhoneNumber.EmergencyStatus emergencyStatus, - @JsonProperty("emergency_address_sid") - final String emergencyAddressSid, - @JsonProperty("uri") - final String uri) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.phoneNumber = phoneNumber; - this.voiceUrl = voiceUrl; - this.voiceMethod = voiceMethod; - this.voiceFallbackMethod = voiceFallbackMethod; - this.voiceFallbackUrl = voiceFallbackUrl; - this.voiceCallerIdLookup = voiceCallerIdLookup; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.smsFallbackMethod = smsFallbackMethod; - this.smsFallbackUrl = smsFallbackUrl; - this.smsMethod = smsMethod; - this.smsUrl = smsUrl; - this.addressRequirements = addressRequirements; - this.capabilities = capabilities; - this.statusCallback = statusCallback; - this.statusCallbackMethod = statusCallbackMethod; - this.apiVersion = apiVersion; - this.smsApplicationSid = smsApplicationSid; - this.voiceApplicationSid = voiceApplicationSid; - this.trunkSid = trunkSid; - this.emergencyStatus = emergencyStatus; - this.emergencyAddressSid = emergencyAddressSid; - this.uri = uri; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final DependentPhoneNumber.AddressRequirement addressRequirements; - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String apiVersion; - /** - * Returns The The phone_number. - * - * @return The phone_number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final Object capabilities; - /** - * Returns The The voice_url. - * - * @return The voice_url - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The voice_method. - * - * @return The voice_method - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The voice_fallback_method. - * - * @return The voice_fallback_method - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } + @Getter + private final String emergencyAddressSid; - /** - * Returns The The voice_fallback_url. - * - * @return The voice_fallback_url - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } + @Getter + private final DependentPhoneNumber.EmergencyStatus emergencyStatus; - /** - * Returns The The voice_caller_id_lookup. - * - * @return The voice_caller_id_lookup - */ - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } + @Getter + private final String friendlyName; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String sid; - /** - * Returns The The sms_fallback_method. - * - * @return The sms_fallback_method - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } + @Getter + private final String smsApplicationSid; - /** - * Returns The The sms_fallback_url. - * - * @return The sms_fallback_url - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } + @Getter + private final HttpMethod smsFallbackMethod; - /** - * Returns The The sms_method. - * - * @return The sms_method - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } + @Getter + private final URI smsFallbackUrl; - /** - * Returns The The sms_url. - * - * @return The sms_url - */ - public final URI getSmsUrl() { - return this.smsUrl; - } + @Getter + private final HttpMethod smsMethod; - /** - * Returns The The address_requirements. - * - * @return The address_requirements - */ - public final DependentPhoneNumber.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } + @Getter + private final URI smsUrl; - /** - * Returns The The capabilities. - * - * @return The capabilities - */ - public final Map getCapabilities() { - return this.capabilities; - } + @Getter + private final URI statusCallback; - /** - * Returns The The status_callback. - * - * @return The status_callback - */ - public final URI getStatusCallback() { - return this.statusCallback; - } + @Getter + private final HttpMethod statusCallbackMethod; - /** - * Returns The The status_callback_method. - * - * @return The status_callback_method - */ - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } + @Getter + private final String trunkSid; - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } + @Getter + private final String uri; - /** - * Returns The The sms_application_sid. - * - * @return The sms_application_sid - */ - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } + @Getter + private final String voiceApplicationSid; - /** - * Returns The The voice_application_sid. - * - * @return The voice_application_sid - */ - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } + @Getter + private final Boolean voiceCallerIdLookup; - /** - * Returns The The trunk_sid. - * - * @return The trunk_sid - */ - public final String getTrunkSid() { - return this.trunkSid; - } + @Getter + private final HttpMethod voiceFallbackMethod; - /** - * Returns The The emergency_status. - * - * @return The emergency_status - */ - public final DependentPhoneNumber.EmergencyStatus getEmergencyStatus() { - return this.emergencyStatus; - } + @Getter + private final URI voiceFallbackUrl; - /** - * Returns The The emergency_address_sid. - * - * @return The emergency_address_sid - */ - public final String getEmergencyAddressSid() { - return this.emergencyAddressSid; - } + @Getter + private final HttpMethod voiceMethod; - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; + @Getter + private final URI voiceUrl; + + @JsonCreator + private DependentPhoneNumber( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "address_requirements" + ) final DependentPhoneNumber.AddressRequirement addressRequirements, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("capabilities") final Object capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_status" + ) final DependentPhoneNumber.EmergencyStatus emergencyStatus, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl + ) { + this.accountSid = accountSid; + this.addressRequirements = addressRequirements; + this.apiVersion = apiVersion; + this.capabilities = capabilities; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.emergencyAddressSid = emergencyAddressSid; + this.emergencyStatus = emergencyStatus; + this.friendlyName = friendlyName; + this.phoneNumber = phoneNumber; + this.sid = sid; + this.smsApplicationSid = smsApplicationSid; + this.smsFallbackMethod = smsFallbackMethod; + this.smsFallbackUrl = smsFallbackUrl; + this.smsMethod = smsMethod; + this.smsUrl = smsUrl; + this.statusCallback = statusCallback; + this.statusCallbackMethod = statusCallbackMethod; + this.trunkSid = trunkSid; + this.uri = uri; + this.voiceApplicationSid = voiceApplicationSid; + this.voiceCallerIdLookup = voiceCallerIdLookup; + this.voiceFallbackMethod = voiceFallbackMethod; + this.voiceFallbackUrl = voiceFallbackUrl; + this.voiceMethod = voiceMethod; + this.voiceUrl = voiceUrl; } @Override @@ -503,94 +318,65 @@ public boolean equals(final Object o) { } DependentPhoneNumber other = (DependentPhoneNumber) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(voiceUrl, other.voiceUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(statusCallback, other.statusCallback) && - Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(smsApplicationSid, other.smsApplicationSid) && - Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(emergencyStatus, other.emergencyStatus) && - Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - phoneNumber, - voiceUrl, - voiceMethod, - voiceFallbackMethod, - voiceFallbackUrl, - voiceCallerIdLookup, - dateCreated, - dateUpdated, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsUrl, - addressRequirements, - capabilities, - statusCallback, - statusCallbackMethod, - apiVersion, - smsApplicationSid, - voiceApplicationSid, - trunkSid, - emergencyStatus, - emergencyAddressSid, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("phoneNumber", phoneNumber) - .add("voiceUrl", voiceUrl) - .add("voiceMethod", voiceMethod) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceCallerIdLookup", voiceCallerIdLookup) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsUrl", smsUrl) - .add("addressRequirements", addressRequirements) - .add("capabilities", capabilities) - .add("statusCallback", statusCallback) - .add("statusCallbackMethod", statusCallbackMethod) - .add("apiVersion", apiVersion) - .add("smsApplicationSid", smsApplicationSid) - .add("voiceApplicationSid", voiceApplicationSid) - .add("trunkSid", trunkSid) - .add("emergencyStatus", emergencyStatus) - .add("emergencyAddressSid", emergencyAddressSid) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + addressRequirements, + apiVersion, + capabilities, + dateCreated, + dateUpdated, + emergencyAddressSid, + emergencyStatus, + friendlyName, + phoneNumber, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + statusCallback, + statusCallbackMethod, + trunkSid, + uri, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumberReader.java b/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumberReader.java index 8222ad6a8b..c10bc7f79b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/address/DependentPhoneNumberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.address; @@ -10,174 +17,216 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class DependentPhoneNumberReader extends Reader { + private String pathAccountSid; - private final String pathAddressSid; + private String pathAddressSid; + private Long pageSize; - /** - * Construct a new DependentPhoneNumberReader. - * - * @param pathAddressSid The address_sid - */ public DependentPhoneNumberReader(final String pathAddressSid) { this.pathAddressSid = pathAddressSid; } - /** - * Construct a new DependentPhoneNumberReader. - * - * @param pathAccountSid The account_sid - * @param pathAddressSid The address_sid - */ - public DependentPhoneNumberReader(final String pathAccountSid, - final String pathAddressSid) { + public DependentPhoneNumberReader( + final String pathAccountSid, + final String pathAddressSid + ) { this.pathAccountSid = pathAccountSid; this.pathAddressSid = pathAddressSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return DependentPhoneNumber ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public DependentPhoneNumberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return DependentPhoneNumber ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "dependent_phone_numbers", + response.getContent(), + DependentPhoneNumber.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Addresses/{AddressSid}/DependentPhoneNumbers.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "AddressSid" + "}", + this.pathAddressSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Addresses/" + this.pathAddressSid + "/DependentPhoneNumbers.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return DependentPhoneNumber ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "dependent_phone_numbers", + response.getContent(), + DependentPhoneNumber.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "DependentPhoneNumber read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "dependent_phone_numbers", + response.getContent(), + DependentPhoneNumber.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of DependentPhoneNumber Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("DependentPhoneNumber read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "dependent_phone_numbers", - response.getContent(), - DependentPhoneNumber.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Local.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Local.java index 20920f62ec..7d944a99da 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Local.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Local.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -11,61 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Local extends Resource { - private static final long serialVersionUID = 16937856072206L; - /** - * Create a LocalReader to execute read. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - * @return LocalReader capable of executing the read - */ - public static LocalReader reader(final String pathAccountSid, - final String pathCountryCode) { - return new LocalReader(pathAccountSid, pathCountryCode); - } - - /** - * Create a LocalReader to execute read. - * - * @param pathCountryCode The country_code - * @return LocalReader capable of executing the read - */ public static LocalReader reader(final String pathCountryCode) { return new LocalReader(pathCountryCode); } + public static LocalReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { + return new LocalReader(pathAccountSid, pathCountryCode); + } + /** * Converts a JSON String into a Local object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Local object represented by the provided JSON */ - public static Local fromJson(final String json, final ObjectMapper objectMapper) { + public static Local fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Local.class); @@ -79,12 +75,15 @@ public static Local fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Local object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Local object represented by the provided JSON */ - public static Local fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Local fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Local.class); @@ -95,182 +94,92 @@ public static Local fromJson(final InputStream json, final ObjectMapper objectMa } } - private final com.twilio.type.PhoneNumber friendlyName; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String lata; - private final String locality; - private final String rateCenter; - private final BigDecimal latitude; - private final BigDecimal longitude; - private final String region; - private final String postalCode; - private final String isoCountry; - private final String addressRequirements; - private final Boolean beta; - private final PhoneNumberCapabilities capabilities; - - @JsonCreator - private Local(@JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("lata") - final String lata, - @JsonProperty("locality") - final String locality, - @JsonProperty("rate_center") - final String rateCenter, - @JsonProperty("latitude") - final BigDecimal latitude, - @JsonProperty("longitude") - final BigDecimal longitude, - @JsonProperty("region") - final String region, - @JsonProperty("postal_code") - final String postalCode, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("address_requirements") - final String addressRequirements, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities) { - this.friendlyName = friendlyName; - this.phoneNumber = phoneNumber; - this.lata = lata; - this.locality = locality; - this.rateCenter = rateCenter; - this.latitude = latitude; - this.longitude = longitude; - this.region = region; - this.postalCode = postalCode; - this.isoCountry = isoCountry; - this.addressRequirements = addressRequirements; - this.beta = beta; - this.capabilities = capabilities; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A nicely-formatted version of the phone number.. - * - * @return A nicely-formatted version of the phone number. - */ - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String addressRequirements; - /** - * Returns The The phone number, in E.. - * - * @return The phone number, in E. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final Boolean beta; - /** - * Returns The The LATA of this phone number.. - * - * @return The LATA of this phone number. - */ - public final String getLata() { - return this.lata; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The The locality/city of this phone number.. - * - * @return The locality/city of this phone number. - */ - public final String getLocality() { - return this.locality; - } + @Getter + private final com.twilio.type.PhoneNumber friendlyName; - /** - * Returns The The rate center of this phone number.. - * - * @return The rate center of this phone number. - */ - public final String getRateCenter() { - return this.rateCenter; - } + @Getter + private final String isoCountry; - /** - * Returns The The latitude coordinate of this phone number.. - * - * @return The latitude coordinate of this phone number. - */ - public final BigDecimal getLatitude() { - return this.latitude; - } + @Getter + private final String lata; - /** - * Returns The The longitude coordinate of this phone number.. - * - * @return The longitude coordinate of this phone number. - */ - public final BigDecimal getLongitude() { - return this.longitude; - } + @Getter + private final BigDecimal latitude; - /** - * Returns The The two-letter state or province abbreviation of this phone - * number.. - * - * @return The two-letter state or province abbreviation of this phone number. - */ - public final String getRegion() { - return this.region; - } + @Getter + private final String locality; - /** - * Returns The The postal code of this phone number.. - * - * @return The postal code of this phone number. - */ - public final String getPostalCode() { - return this.postalCode; - } + @Getter + private final BigDecimal longitude; - /** - * Returns The The ISO country code of this phone number.. - * - * @return The ISO country code of this phone number. - */ - public final String getIsoCountry() { - return this.isoCountry; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio.. - * - * @return This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio. - */ - public final String getAddressRequirements() { - return this.addressRequirements; - } + @Getter + private final String postalCode; - /** - * Returns The Phone numbers new to the Twilio platform are marked as beta.. - * - * @return Phone numbers new to the Twilio platform are marked as beta. - */ - public final Boolean getBeta() { - return this.beta; - } + @Getter + private final String rateCenter; - /** - * Returns The This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages.. - * - * @return This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; + @Getter + private final String region; + + @JsonCreator + private Local( + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("lata") final String lata, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("locality") final String locality, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("region") final String region + ) { + this.addressRequirements = addressRequirements; + this.beta = beta; + this.capabilities = capabilities; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.lata = lata; + this.latitude = latitude; + this.locality = locality; + this.longitude = longitude; + this.phoneNumber = phoneNumber; + this.postalCode = postalCode; + this.rateCenter = rateCenter; + this.region = region; } @Override @@ -284,55 +193,39 @@ public boolean equals(final Object o) { } Local other = (Local) o; - - return Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(lata, other.lata) && - Objects.equals(locality, other.locality) && - Objects.equals(rateCenter, other.rateCenter) && - Objects.equals(latitude, other.latitude) && - Objects.equals(longitude, other.longitude) && - Objects.equals(region, other.region) && - Objects.equals(postalCode, other.postalCode) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities); + return ( + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(lata, other.lata) && + Objects.equals(latitude, other.latitude) && + Objects.equals(locality, other.locality) && + Objects.equals(longitude, other.longitude) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(region, other.region) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, - phoneNumber, - lata, - locality, - rateCenter, - latitude, - longitude, - region, - postalCode, - isoCountry, - addressRequirements, - beta, - capabilities); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("friendlyName", friendlyName) - .add("phoneNumber", phoneNumber) - .add("lata", lata) - .add("locality", locality) - .add("rateCenter", rateCenter) - .add("latitude", latitude) - .add("longitude", longitude) - .add("region", region) - .add("postalCode", postalCode) - .add("isoCountry", isoCountry) - .add("addressRequirements", addressRequirements) - .add("beta", beta) - .add("capabilities", capabilities) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + addressRequirements, + beta, + capabilities, + friendlyName, + isoCountry, + lata, + latitude, + locality, + longitude, + phoneNumber, + postalCode, + rateCenter, + region + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/LocalReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/LocalReader.java index d7b3fd83c6..0e800da128 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/LocalReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/LocalReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -10,19 +17,27 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class LocalReader extends Reader { + private String pathAccountSid; - private final String pathCountryCode; + private String pathCountryCode; private Integer areaCode; private String contains; private Boolean smsEnabled; @@ -41,495 +56,444 @@ public class LocalReader extends Reader { private String inLata; private String inLocality; private Boolean faxEnabled; + private Long pageSize; - /** - * Construct a new LocalReader. - * - * @param pathCountryCode The country_code - */ public LocalReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - /** - * Construct a new LocalReader. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - */ - public LocalReader(final String pathAccountSid, - final String pathCountryCode) { + public LocalReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - /** - * Find phone numbers in the specified area code. (US and Canada only). - * - * @param areaCode Find phone numbers in the specified area code. - * @return this - */ public LocalReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - /** - * A pattern on which to match phone numbers. Valid characters are `'*'` and - * `[0-9a-zA-Z]`. The `'*'` character will match any single digit. See [Example - * 2](https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-2) and [Example 3](https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-3) below. *NOTE:* Patterns must be at least two characters long.. - * - * @param contains A pattern on which to match phone numbers. - * @return this - */ public LocalReader setContains(final String contains) { this.contains = contains; return this; } - /** - * This indicates whether the phone numbers can receive text messages. Possible - * values are `true` or `false`.. - * - * @param smsEnabled This indicates whether the phone numbers can receive text - * messages. - * @return this - */ public LocalReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - /** - * This indicates whether the phone numbers can receive MMS messages. Possible - * values are `true` or `false`.. - * - * @param mmsEnabled This indicates whether the phone numbers can receive MMS - * messages. - * @return this - */ public LocalReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - /** - * This indicates whether the phone numbers can receive calls. Possible values - * are `true` or `false`.. - * - * @param voiceEnabled This indicates whether the phone numbers can receive - * calls. - * @return this - */ public LocalReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - /** - * Indicates whether the response includes phone numbers which require any - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with an Address required.. - * - * @param excludeAllAddressRequired Indicates whether the response includes - * phone numbers which require any Address. - * @return this - */ - public LocalReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired) { + public LocalReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - /** - * Indicates whether the response includes phone numbers which require a local - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with a local Address required.. - * - * @param excludeLocalAddressRequired Indicates whether the response includes - * phone numbers which require a local - * Address. - * @return this - */ - public LocalReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired) { + public LocalReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - /** - * Indicates whether the response includes phone numbers which require a foreign - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with a foreign Address required.. - * - * @param excludeForeignAddressRequired Indicates whether the response includes - * phone numbers which require a foreign - * Address. - * @return this - */ - public LocalReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired) { + public LocalReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - /** - * Include phone numbers new to the Twilio platform. Possible values are either - * `true` or `false`. Default is `true`.. - * - * @param beta Include phone numbers new to the Twilio platform. - * @return this - */ public LocalReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * Given a phone number, find a geographically close number within `Distance` - * miles. Distance defaults to 25 miles. *Limited to US and Canadian phone - * numbers.*. - * - * @param nearNumber Given a phone number, find a geographically close number - * within Distance miles. (US/Canada only) - * @return this - */ - public LocalReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber) { + public LocalReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - /** - * Given a phone number, find a geographically close number within `Distance` - * miles. Distance defaults to 25 miles. *Limited to US and Canadian phone - * numbers.*. - * - * @param nearNumber Given a phone number, find a geographically close number - * within Distance miles. (US/Canada only) - * @return this - */ public LocalReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - /** - * Given a latitude/longitude pair `lat,long` find geographically close numbers - * within `Distance` miles. *Limited to US and Canadian phone numbers.*. - * - * @param nearLatLong Given a latitude/longitude pair lat,long find - * geographically close numbers within Distance miles. - * (US/Canada only) - * @return this - */ public LocalReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - /** - * Specifies the search radius for a `Near-` query in miles. If not specified - * this defaults to 25 miles. Maximum searchable distance is 500 miles. *Limited - * to US and Canadian phone numbers.*. - * - * @param distance Specifies the search radius for a Near- query in miles. - * (US/Canada only) - * @return this - */ public LocalReader setDistance(final Integer distance) { this.distance = distance; return this; } - /** - * Limit results to a particular postal code. Given a phone number, search - * within the same postal code as that number. *Limited to US and Canadian phone - * numbers.*. - * - * @param inPostalCode Limit results to a particular postal code. (US/Canada - * only) - * @return this - */ public LocalReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - /** - * Limit results to a particular region (i.e. State/Province). Given a phone - * number, search within the same Region as that number. *Limited to US and - * Canadian phone numbers.*. - * - * @param inRegion Limit results to a particular region. (US/Canada only) - * @return this - */ public LocalReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - /** - * Limit results to a specific rate center, or given a phone number search - * within the same rate center as that number. Requires InLata to be set as - * well. *Limited to US and Canadian phone numbers.*. - * - * @param inRateCenter Limit results to a specific rate center, or given a - * phone number search within the same rate center as that - * number. (US/Canada only) - * @return this - */ public LocalReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - /** - * Limit results to a specific Local access and transport area - * ([LATA](http://en.wikipedia.org/wiki/Local_access_and_transport_area)). Given - * a phone number, search within the same - * [LATA](http://en.wikipedia.org/wiki/Local_access_and_transport_area) as that - * number. *Limited to US and Canadian phone numbers.*. - * - * @param inLata Limit results to a specific Local access and transport area. - * (US/Canada only) - * @return this - */ public LocalReader setInLata(final String inLata) { this.inLata = inLata; return this; } - /** - * Limit results to a particular locality (i.e. City). Given a phone number, - * search within the same Locality as that number. *Limited to US and Canadian - * phone numbers.*. - * - * @param inLocality Limit results to a particular locality. (US/Canada only) - * @return this - */ public LocalReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - /** - * This indicates whether the phone numbers can receive faxes. Possible values - * are `true` or `false`.. - * - * @param faxEnabled This indicates whether the phone numbers can receive faxes. - * @return this - */ public LocalReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Local ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public LocalReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Local ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + Local.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Local.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers/" + this.pathCountryCode + "/Local.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Local ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + Local.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Local read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_phone_numbers", + response.getContent(), + Local.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Local Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Local read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "available_phone_numbers", - response.getContent(), - Local.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); + Serializer.toString( + request, + "AreaCode", + areaCode, + ParameterType.QUERY + ); } if (contains != null) { - request.addQueryParam("Contains", contains); + Serializer.toString( + request, + "Contains", + contains, + ParameterType.QUERY + ); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); + Serializer.toString( + request, + "SmsEnabled", + smsEnabled, + ParameterType.QUERY + ); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); + Serializer.toString( + request, + "MmsEnabled", + mmsEnabled, + ParameterType.QUERY + ); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); + Serializer.toString( + request, + "VoiceEnabled", + voiceEnabled, + ParameterType.QUERY + ); } if (excludeAllAddressRequired != null) { - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeAllAddressRequired", + excludeAllAddressRequired, + ParameterType.QUERY + ); } if (excludeLocalAddressRequired != null) { - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired, + ParameterType.QUERY + ); } if (excludeForeignAddressRequired != null) { - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired, + ParameterType.QUERY + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); + Serializer.toString( + request, + "NearNumber", + nearNumber, + ParameterType.QUERY + ); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); + Serializer.toString( + request, + "NearLatLong", + nearLatLong, + ParameterType.QUERY + ); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); + Serializer.toString( + request, + "Distance", + distance, + ParameterType.QUERY + ); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); + Serializer.toString( + request, + "InPostalCode", + inPostalCode, + ParameterType.QUERY + ); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); + Serializer.toString( + request, + "InRegion", + inRegion, + ParameterType.QUERY + ); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); + Serializer.toString( + request, + "InRateCenter", + inRateCenter, + ParameterType.QUERY + ); } if (inLata != null) { - request.addQueryParam("InLata", inLata); + Serializer.toString(request, "InLata", inLata, ParameterType.QUERY); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); + Serializer.toString( + request, + "InLocality", + inLocality, + ParameterType.QUERY + ); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); + Serializer.toString( + request, + "FaxEnabled", + faxEnabled, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachine.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachine.java index 95c0e171a3..0b27ffe640 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachine.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachine.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -11,62 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class MachineToMachine extends Resource { - private static final long serialVersionUID = 16937856072206L; - /** - * Create a MachineToMachineReader to execute read. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - * @return MachineToMachineReader capable of executing the read - */ - public static MachineToMachineReader reader(final String pathAccountSid, - final String pathCountryCode) { - return new MachineToMachineReader(pathAccountSid, pathCountryCode); - } - - /** - * Create a MachineToMachineReader to execute read. - * - * @param pathCountryCode The country_code - * @return MachineToMachineReader capable of executing the read - */ public static MachineToMachineReader reader(final String pathCountryCode) { return new MachineToMachineReader(pathCountryCode); } + public static MachineToMachineReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { + return new MachineToMachineReader(pathAccountSid, pathCountryCode); + } + /** - * Converts a JSON String into a MachineToMachine object using the provided - * ObjectMapper. - * + * Converts a JSON String into a MachineToMachine object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return MachineToMachine object represented by the provided JSON */ - public static MachineToMachine fromJson(final String json, final ObjectMapper objectMapper) { + public static MachineToMachine fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MachineToMachine.class); @@ -80,12 +75,15 @@ public static MachineToMachine fromJson(final String json, final ObjectMapper ob /** * Converts a JSON InputStream into a MachineToMachine object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return MachineToMachine object represented by the provided JSON */ - public static MachineToMachine fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static MachineToMachine fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MachineToMachine.class); @@ -96,177 +94,92 @@ public static MachineToMachine fromJson(final InputStream json, final ObjectMapp } } - private final com.twilio.type.PhoneNumber friendlyName; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String lata; - private final String locality; - private final String rateCenter; - private final BigDecimal latitude; - private final BigDecimal longitude; - private final String region; - private final String postalCode; - private final String isoCountry; - private final String addressRequirements; - private final Boolean beta; - private final PhoneNumberCapabilities capabilities; - - @JsonCreator - private MachineToMachine(@JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("lata") - final String lata, - @JsonProperty("locality") - final String locality, - @JsonProperty("rate_center") - final String rateCenter, - @JsonProperty("latitude") - final BigDecimal latitude, - @JsonProperty("longitude") - final BigDecimal longitude, - @JsonProperty("region") - final String region, - @JsonProperty("postal_code") - final String postalCode, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("address_requirements") - final String addressRequirements, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities) { - this.friendlyName = friendlyName; - this.phoneNumber = phoneNumber; - this.lata = lata; - this.locality = locality; - this.rateCenter = rateCenter; - this.latitude = latitude; - this.longitude = longitude; - this.region = region; - this.postalCode = postalCode; - this.isoCountry = isoCountry; - this.addressRequirements = addressRequirements; - this.beta = beta; - this.capabilities = capabilities; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String addressRequirements; - /** - * Returns The The phone_number. - * - * @return The phone_number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final Boolean beta; - /** - * Returns The The lata. - * - * @return The lata - */ - public final String getLata() { - return this.lata; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The The locality. - * - * @return The locality - */ - public final String getLocality() { - return this.locality; - } + @Getter + private final com.twilio.type.PhoneNumber friendlyName; - /** - * Returns The The rate_center. - * - * @return The rate_center - */ - public final String getRateCenter() { - return this.rateCenter; - } + @Getter + private final String isoCountry; - /** - * Returns The The latitude. - * - * @return The latitude - */ - public final BigDecimal getLatitude() { - return this.latitude; - } + @Getter + private final String lata; - /** - * Returns The The longitude. - * - * @return The longitude - */ - public final BigDecimal getLongitude() { - return this.longitude; - } + @Getter + private final BigDecimal latitude; - /** - * Returns The The region. - * - * @return The region - */ - public final String getRegion() { - return this.region; - } + @Getter + private final String locality; - /** - * Returns The The postal_code. - * - * @return The postal_code - */ - public final String getPostalCode() { - return this.postalCode; - } + @Getter + private final BigDecimal longitude; - /** - * Returns The The iso_country. - * - * @return The iso_country - */ - public final String getIsoCountry() { - return this.isoCountry; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The address_requirements. - * - * @return The address_requirements - */ - public final String getAddressRequirements() { - return this.addressRequirements; - } + @Getter + private final String postalCode; - /** - * Returns The The beta. - * - * @return The beta - */ - public final Boolean getBeta() { - return this.beta; - } + @Getter + private final String rateCenter; - /** - * Returns The The capabilities. - * - * @return The capabilities - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; + @Getter + private final String region; + + @JsonCreator + private MachineToMachine( + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("lata") final String lata, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("locality") final String locality, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("region") final String region + ) { + this.addressRequirements = addressRequirements; + this.beta = beta; + this.capabilities = capabilities; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.lata = lata; + this.latitude = latitude; + this.locality = locality; + this.longitude = longitude; + this.phoneNumber = phoneNumber; + this.postalCode = postalCode; + this.rateCenter = rateCenter; + this.region = region; } @Override @@ -280,55 +193,39 @@ public boolean equals(final Object o) { } MachineToMachine other = (MachineToMachine) o; - - return Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(lata, other.lata) && - Objects.equals(locality, other.locality) && - Objects.equals(rateCenter, other.rateCenter) && - Objects.equals(latitude, other.latitude) && - Objects.equals(longitude, other.longitude) && - Objects.equals(region, other.region) && - Objects.equals(postalCode, other.postalCode) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities); + return ( + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(lata, other.lata) && + Objects.equals(latitude, other.latitude) && + Objects.equals(locality, other.locality) && + Objects.equals(longitude, other.longitude) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(region, other.region) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, - phoneNumber, - lata, - locality, - rateCenter, - latitude, - longitude, - region, - postalCode, - isoCountry, - addressRequirements, - beta, - capabilities); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("friendlyName", friendlyName) - .add("phoneNumber", phoneNumber) - .add("lata", lata) - .add("locality", locality) - .add("rateCenter", rateCenter) - .add("latitude", latitude) - .add("longitude", longitude) - .add("region", region) - .add("postalCode", postalCode) - .add("isoCountry", isoCountry) - .add("addressRequirements", addressRequirements) - .add("beta", beta) - .add("capabilities", capabilities) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + addressRequirements, + beta, + capabilities, + friendlyName, + isoCountry, + lata, + latitude, + locality, + longitude, + phoneNumber, + postalCode, + rateCenter, + region + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachineReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachineReader.java index 192e64f3df..1fa6aaef2d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachineReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MachineToMachineReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -10,19 +17,27 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MachineToMachineReader extends Reader { + private String pathAccountSid; - private final String pathCountryCode; + private String pathCountryCode; private Integer areaCode; private String contains; private Boolean smsEnabled; @@ -41,443 +56,448 @@ public class MachineToMachineReader extends Reader { private String inLata; private String inLocality; private Boolean faxEnabled; + private Long pageSize; - /** - * Construct a new MachineToMachineReader. - * - * @param pathCountryCode The country_code - */ public MachineToMachineReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - /** - * Construct a new MachineToMachineReader. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - */ - public MachineToMachineReader(final String pathAccountSid, - final String pathCountryCode) { + public MachineToMachineReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - /** - * The area_code. - * - * @param areaCode The area_code - * @return this - */ public MachineToMachineReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - /** - * The contains. - * - * @param contains The contains - * @return this - */ public MachineToMachineReader setContains(final String contains) { this.contains = contains; return this; } - /** - * The sms_enabled. - * - * @param smsEnabled The sms_enabled - * @return this - */ public MachineToMachineReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - /** - * The mms_enabled. - * - * @param mmsEnabled The mms_enabled - * @return this - */ public MachineToMachineReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - /** - * The voice_enabled. - * - * @param voiceEnabled The voice_enabled - * @return this - */ public MachineToMachineReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - /** - * The exclude_all_address_required. - * - * @param excludeAllAddressRequired The exclude_all_address_required - * @return this - */ - public MachineToMachineReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired) { + public MachineToMachineReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - /** - * The exclude_local_address_required. - * - * @param excludeLocalAddressRequired The exclude_local_address_required - * @return this - */ - public MachineToMachineReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired) { + public MachineToMachineReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - /** - * The exclude_foreign_address_required. - * - * @param excludeForeignAddressRequired The exclude_foreign_address_required - * @return this - */ - public MachineToMachineReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired) { + public MachineToMachineReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - /** - * The beta. - * - * @param beta The beta - * @return this - */ public MachineToMachineReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * The near_number. - * - * @param nearNumber The near_number - * @return this - */ - public MachineToMachineReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber) { + public MachineToMachineReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - /** - * The near_number. - * - * @param nearNumber The near_number - * @return this - */ public MachineToMachineReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - /** - * The near_lat_long. - * - * @param nearLatLong The near_lat_long - * @return this - */ public MachineToMachineReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - /** - * The distance. - * - * @param distance The distance - * @return this - */ public MachineToMachineReader setDistance(final Integer distance) { this.distance = distance; return this; } - /** - * The in_postal_code. - * - * @param inPostalCode The in_postal_code - * @return this - */ public MachineToMachineReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - /** - * The in_region. - * - * @param inRegion The in_region - * @return this - */ public MachineToMachineReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - /** - * The in_rate_center. - * - * @param inRateCenter The in_rate_center - * @return this - */ public MachineToMachineReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - /** - * The in_lata. - * - * @param inLata The in_lata - * @return this - */ public MachineToMachineReader setInLata(final String inLata) { this.inLata = inLata; return this; } - /** - * The in_locality. - * - * @param inLocality The in_locality - * @return this - */ public MachineToMachineReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - /** - * The fax_enabled. - * - * @param faxEnabled The fax_enabled - * @return this - */ public MachineToMachineReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return MachineToMachine ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MachineToMachineReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return MachineToMachine ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + MachineToMachine.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/MachineToMachine.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers/" + this.pathCountryCode + "/MachineToMachine.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return MachineToMachine ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + MachineToMachine.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "MachineToMachine read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_phone_numbers", + response.getContent(), + MachineToMachine.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of MachineToMachine Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("MachineToMachine read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "available_phone_numbers", - response.getContent(), - MachineToMachine.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); + Serializer.toString( + request, + "AreaCode", + areaCode, + ParameterType.QUERY + ); } if (contains != null) { - request.addQueryParam("Contains", contains); + Serializer.toString( + request, + "Contains", + contains, + ParameterType.QUERY + ); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); + Serializer.toString( + request, + "SmsEnabled", + smsEnabled, + ParameterType.QUERY + ); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); + Serializer.toString( + request, + "MmsEnabled", + mmsEnabled, + ParameterType.QUERY + ); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); + Serializer.toString( + request, + "VoiceEnabled", + voiceEnabled, + ParameterType.QUERY + ); } if (excludeAllAddressRequired != null) { - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeAllAddressRequired", + excludeAllAddressRequired, + ParameterType.QUERY + ); } if (excludeLocalAddressRequired != null) { - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired, + ParameterType.QUERY + ); } if (excludeForeignAddressRequired != null) { - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired, + ParameterType.QUERY + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); + Serializer.toString( + request, + "NearNumber", + nearNumber, + ParameterType.QUERY + ); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); + Serializer.toString( + request, + "NearLatLong", + nearLatLong, + ParameterType.QUERY + ); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); + Serializer.toString( + request, + "Distance", + distance, + ParameterType.QUERY + ); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); + Serializer.toString( + request, + "InPostalCode", + inPostalCode, + ParameterType.QUERY + ); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); + Serializer.toString( + request, + "InRegion", + inRegion, + ParameterType.QUERY + ); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); + Serializer.toString( + request, + "InRateCenter", + inRateCenter, + ParameterType.QUERY + ); } if (inLata != null) { - request.addQueryParam("InLata", inLata); + Serializer.toString(request, "InLata", inLata, ParameterType.QUERY); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); + Serializer.toString( + request, + "InLocality", + inLocality, + ParameterType.QUERY + ); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); + Serializer.toString( + request, + "FaxEnabled", + faxEnabled, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Mobile.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Mobile.java index 7e5c5e7d90..202045ad2e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Mobile.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Mobile.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -11,60 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Mobile extends Resource { - private static final long serialVersionUID = 16937856072206L; - /** - * Create a MobileReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathCountryCode The country_code - * @return MobileReader capable of executing the read - */ - public static MobileReader reader(final String pathAccountSid, - final String pathCountryCode) { - return new MobileReader(pathAccountSid, pathCountryCode); - } - - /** - * Create a MobileReader to execute read. - * - * @param pathCountryCode The country_code - * @return MobileReader capable of executing the read - */ public static MobileReader reader(final String pathCountryCode) { return new MobileReader(pathCountryCode); } + public static MobileReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { + return new MobileReader(pathAccountSid, pathCountryCode); + } + /** * Converts a JSON String into a Mobile object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Mobile object represented by the provided JSON */ - public static Mobile fromJson(final String json, final ObjectMapper objectMapper) { + public static Mobile fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Mobile.class); @@ -78,12 +75,15 @@ public static Mobile fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Mobile object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Mobile object represented by the provided JSON */ - public static Mobile fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Mobile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Mobile.class); @@ -94,182 +94,92 @@ public static Mobile fromJson(final InputStream json, final ObjectMapper objectM } } - private final com.twilio.type.PhoneNumber friendlyName; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String lata; - private final String locality; - private final String rateCenter; - private final BigDecimal latitude; - private final BigDecimal longitude; - private final String region; - private final String postalCode; - private final String isoCountry; - private final String addressRequirements; - private final Boolean beta; - private final PhoneNumberCapabilities capabilities; - - @JsonCreator - private Mobile(@JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("lata") - final String lata, - @JsonProperty("locality") - final String locality, - @JsonProperty("rate_center") - final String rateCenter, - @JsonProperty("latitude") - final BigDecimal latitude, - @JsonProperty("longitude") - final BigDecimal longitude, - @JsonProperty("region") - final String region, - @JsonProperty("postal_code") - final String postalCode, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("address_requirements") - final String addressRequirements, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities) { - this.friendlyName = friendlyName; - this.phoneNumber = phoneNumber; - this.lata = lata; - this.locality = locality; - this.rateCenter = rateCenter; - this.latitude = latitude; - this.longitude = longitude; - this.region = region; - this.postalCode = postalCode; - this.isoCountry = isoCountry; - this.addressRequirements = addressRequirements; - this.beta = beta; - this.capabilities = capabilities; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A nicely-formatted version of the phone number.. - * - * @return A nicely-formatted version of the phone number. - */ - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String addressRequirements; - /** - * Returns The The phone number, in E.164 format.. - * - * @return The phone number, in E.164 format. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final Boolean beta; - /** - * Returns The The LATA of this phone number.. - * - * @return The LATA of this phone number. - */ - public final String getLata() { - return this.lata; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The The locality/city of this phone number.. - * - * @return The locality/city of this phone number. - */ - public final String getLocality() { - return this.locality; - } + @Getter + private final com.twilio.type.PhoneNumber friendlyName; - /** - * Returns The The rate center of this phone number.. - * - * @return The rate center of this phone number. - */ - public final String getRateCenter() { - return this.rateCenter; - } + @Getter + private final String isoCountry; - /** - * Returns The The latitude coordinate of this phone number.. - * - * @return The latitude coordinate of this phone number. - */ - public final BigDecimal getLatitude() { - return this.latitude; - } + @Getter + private final String lata; - /** - * Returns The The longitude coordinate of this phone number.. - * - * @return The longitude coordinate of this phone number. - */ - public final BigDecimal getLongitude() { - return this.longitude; - } + @Getter + private final BigDecimal latitude; - /** - * Returns The The two-letter state or province abbreviation of this phone - * number.. - * - * @return The two-letter state or province abbreviation of this phone number. - */ - public final String getRegion() { - return this.region; - } + @Getter + private final String locality; - /** - * Returns The The postal code of this phone number.. - * - * @return The postal code of this phone number. - */ - public final String getPostalCode() { - return this.postalCode; - } + @Getter + private final BigDecimal longitude; - /** - * Returns The The ISO country code of this phone number.. - * - * @return The ISO country code of this phone number. - */ - public final String getIsoCountry() { - return this.isoCountry; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio.. - * - * @return This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio. - */ - public final String getAddressRequirements() { - return this.addressRequirements; - } + @Getter + private final String postalCode; - /** - * Returns The Phone numbers new to the Twilio platform are marked as beta.. - * - * @return Phone numbers new to the Twilio platform are marked as beta. - */ - public final Boolean getBeta() { - return this.beta; - } + @Getter + private final String rateCenter; - /** - * Returns The This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages.. - * - * @return This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; + @Getter + private final String region; + + @JsonCreator + private Mobile( + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("lata") final String lata, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("locality") final String locality, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("region") final String region + ) { + this.addressRequirements = addressRequirements; + this.beta = beta; + this.capabilities = capabilities; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.lata = lata; + this.latitude = latitude; + this.locality = locality; + this.longitude = longitude; + this.phoneNumber = phoneNumber; + this.postalCode = postalCode; + this.rateCenter = rateCenter; + this.region = region; } @Override @@ -283,55 +193,39 @@ public boolean equals(final Object o) { } Mobile other = (Mobile) o; - - return Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(lata, other.lata) && - Objects.equals(locality, other.locality) && - Objects.equals(rateCenter, other.rateCenter) && - Objects.equals(latitude, other.latitude) && - Objects.equals(longitude, other.longitude) && - Objects.equals(region, other.region) && - Objects.equals(postalCode, other.postalCode) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities); + return ( + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(lata, other.lata) && + Objects.equals(latitude, other.latitude) && + Objects.equals(locality, other.locality) && + Objects.equals(longitude, other.longitude) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(region, other.region) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, - phoneNumber, - lata, - locality, - rateCenter, - latitude, - longitude, - region, - postalCode, - isoCountry, - addressRequirements, - beta, - capabilities); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("friendlyName", friendlyName) - .add("phoneNumber", phoneNumber) - .add("lata", lata) - .add("locality", locality) - .add("rateCenter", rateCenter) - .add("latitude", latitude) - .add("longitude", longitude) - .add("region", region) - .add("postalCode", postalCode) - .add("isoCountry", isoCountry) - .add("addressRequirements", addressRequirements) - .add("beta", beta) - .add("capabilities", capabilities) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + addressRequirements, + beta, + capabilities, + friendlyName, + isoCountry, + lata, + latitude, + locality, + longitude, + phoneNumber, + postalCode, + rateCenter, + region + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MobileReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MobileReader.java index 2c34e1636b..ad7ab20f0f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MobileReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/MobileReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -10,19 +17,27 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MobileReader extends Reader { + private String pathAccountSid; - private final String pathCountryCode; + private String pathCountryCode; private Integer areaCode; private String contains; private Boolean smsEnabled; @@ -41,493 +56,444 @@ public class MobileReader extends Reader { private String inLata; private String inLocality; private Boolean faxEnabled; + private Long pageSize; - /** - * Construct a new MobileReader. - * - * @param pathCountryCode The country_code - */ public MobileReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - /** - * Construct a new MobileReader. - * - * @param pathAccountSid The account_sid - * @param pathCountryCode The country_code - */ - public MobileReader(final String pathAccountSid, - final String pathCountryCode) { + public MobileReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - /** - * Find phone numbers in the specified area code. (US and Canada only). - * - * @param areaCode Find phone numbers in the specified area code. - * @return this - */ public MobileReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - /** - * A pattern on which to match phone numbers. Valid characters are `'*'` and - * `[0-9a-zA-Z]`. The `'*'` character will match any single digit. See [Example - * 2](https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-2) and [Example 3](https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-3) below. *NOTE:* Patterns must be at least two characters long.. - * - * @param contains A pattern on which to match phone numbers. - * @return this - */ public MobileReader setContains(final String contains) { this.contains = contains; return this; } - /** - * This indicates whether the phone numbers can receive text messages. Possible - * values are `true` or `false`.. - * - * @param smsEnabled This indicates whether the phone numbers can receive text - * messages. - * @return this - */ public MobileReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - /** - * This indicates whether the phone numbers can receive MMS messages. Possible - * values are `true` or `false`.. - * - * @param mmsEnabled This indicates whether the phone numbers can receive MMS - * messages. - * @return this - */ public MobileReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - /** - * This indicates whether the phone numbers can receive calls. Possible values - * are `true` or `false`.. - * - * @param voiceEnabled This indicates whether the phone numbers can receive - * calls. - * @return this - */ public MobileReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - /** - * Indicates whether the response includes phone numbers which require any - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with an Address required.. - * - * @param excludeAllAddressRequired Indicates whether the response includes - * phone numbers which require any Address. - * @return this - */ - public MobileReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired) { + public MobileReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - /** - * Indicates whether the response includes phone numbers which require a local - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with a local Address required.. - * - * @param excludeLocalAddressRequired Indicates whether the response includes - * phone numbers which require a local - * Address. - * @return this - */ - public MobileReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired) { + public MobileReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - /** - * Indicates whether the response includes phone numbers which require a foreign - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with a foreign Address required.. - * - * @param excludeForeignAddressRequired Indicates whether the response includes - * phone numbers which require a foreign - * Address. - * @return this - */ - public MobileReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired) { + public MobileReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - /** - * Include phone numbers new to the Twilio platform. Possible values are either - * `true` or `false`. Default is `true`.. - * - * @param beta Include phone numbers new to the Twilio platform. - * @return this - */ public MobileReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * Given a phone number, find a geographically close number within `Distance` - * miles. Distance defaults to 25 miles. *Limited to US and Canadian phone - * numbers.*. - * - * @param nearNumber Given a phone number, find a geographically close number - * within Distance miles. (US/Canada only) - * @return this - */ - public MobileReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber) { + public MobileReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - /** - * Given a phone number, find a geographically close number within `Distance` - * miles. Distance defaults to 25 miles. *Limited to US and Canadian phone - * numbers.*. - * - * @param nearNumber Given a phone number, find a geographically close number - * within Distance miles. (US/Canada only) - * @return this - */ public MobileReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - /** - * Given a latitude/longitude pair `lat,long` find geographically close numbers - * within `Distance` miles. *Limited to US and Canadian phone numbers.*. - * - * @param nearLatLong Given a latitude/longitude pair lat,long find - * geographically close numbers within Distance miles. - * (US/Canada only) - * @return this - */ public MobileReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - /** - * Specifies the search radius for a `Near-` query in miles. If not specified - * this defaults to 25 miles. Maximum searchable distance is 500 miles. *Limited - * to US and Canadian phone numbers.*. - * - * @param distance Specifies the search radius for a Near- query in miles. - * (US/Canada only) - * @return this - */ public MobileReader setDistance(final Integer distance) { this.distance = distance; return this; } - /** - * Limit results to a particular postal code. Given a phone number, search - * within the same postal code as that number. *Limited to US and Canadian phone - * numbers.*. - * - * @param inPostalCode Limit results to a particular postal code. (US/Canada - * only) - * @return this - */ public MobileReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - /** - * Limit results to a particular region (i.e. State/Province). Given a phone - * number, search within the same Region as that number. *Limited to US and - * Canadian phone numbers.*. - * - * @param inRegion Limit results to a particular region. (US/Canada only) - * @return this - */ public MobileReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - /** - * Limit results to a specific rate center, or given a phone number search - * within the same rate center as that number. Requires InLata to be set as - * well. *Limited to US and Canadian phone numbers.*. - * - * @param inRateCenter Limit results to a specific rate center, or given a - * phone number search within the same rate center as that - * number. (US/Canada only) - * @return this - */ public MobileReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - /** - * Limit results to a specific Local access and transport area - * ([LATA](http://en.wikipedia.org/wiki/Local_access_and_transport_area)). Given - * a phone number, search within the same - * [LATA](http://en.wikipedia.org/wiki/Local_access_and_transport_area) as that - * number. *Limited to US and Canadian phone numbers.*. - * - * @param inLata Limit results to a specific Local access and transport area. - * (US/Canada only) - * @return this - */ public MobileReader setInLata(final String inLata) { this.inLata = inLata; return this; } - /** - * Limit results to a particular locality (i.e. City). Given a phone number, - * search within the same Locality as that number.. - * - * @param inLocality Limit results to a particular locality. - * @return this - */ public MobileReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - /** - * This indicates whether the phone numbers can receive faxes. Possible values - * are `true` or `false`.. - * - * @param faxEnabled This indicates whether the phone numbers can receive faxes. - * @return this - */ public MobileReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Mobile ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MobileReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Mobile ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + Mobile.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Mobile.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers/" + this.pathCountryCode + "/Mobile.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Mobile ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + Mobile.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Mobile read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_phone_numbers", + response.getContent(), + Mobile.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Mobile Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Mobile read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "available_phone_numbers", - response.getContent(), - Mobile.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); + Serializer.toString( + request, + "AreaCode", + areaCode, + ParameterType.QUERY + ); } if (contains != null) { - request.addQueryParam("Contains", contains); + Serializer.toString( + request, + "Contains", + contains, + ParameterType.QUERY + ); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); + Serializer.toString( + request, + "SmsEnabled", + smsEnabled, + ParameterType.QUERY + ); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); + Serializer.toString( + request, + "MmsEnabled", + mmsEnabled, + ParameterType.QUERY + ); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); + Serializer.toString( + request, + "VoiceEnabled", + voiceEnabled, + ParameterType.QUERY + ); } if (excludeAllAddressRequired != null) { - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeAllAddressRequired", + excludeAllAddressRequired, + ParameterType.QUERY + ); } if (excludeLocalAddressRequired != null) { - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired, + ParameterType.QUERY + ); } if (excludeForeignAddressRequired != null) { - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired, + ParameterType.QUERY + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); + Serializer.toString( + request, + "NearNumber", + nearNumber, + ParameterType.QUERY + ); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); + Serializer.toString( + request, + "NearLatLong", + nearLatLong, + ParameterType.QUERY + ); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); + Serializer.toString( + request, + "Distance", + distance, + ParameterType.QUERY + ); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); + Serializer.toString( + request, + "InPostalCode", + inPostalCode, + ParameterType.QUERY + ); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); + Serializer.toString( + request, + "InRegion", + inRegion, + ParameterType.QUERY + ); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); + Serializer.toString( + request, + "InRateCenter", + inRateCenter, + ParameterType.QUERY + ); } if (inLata != null) { - request.addQueryParam("InLata", inLata); + Serializer.toString(request, "InLata", inLata, ParameterType.QUERY); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); + Serializer.toString( + request, + "InLocality", + inLocality, + ParameterType.QUERY + ); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); + Serializer.toString( + request, + "FaxEnabled", + faxEnabled, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/National.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/National.java index 97a7c6706b..324c571fc6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/National.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/National.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -11,62 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class National extends Resource { - private static final long serialVersionUID = 16937856072206L; - /** - * Create a NationalReader to execute read. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - * @return NationalReader capable of executing the read - */ - public static NationalReader reader(final String pathAccountSid, - final String pathCountryCode) { - return new NationalReader(pathAccountSid, pathCountryCode); - } - - /** - * Create a NationalReader to execute read. - * - * @param pathCountryCode The country_code - * @return NationalReader capable of executing the read - */ public static NationalReader reader(final String pathCountryCode) { return new NationalReader(pathCountryCode); } + public static NationalReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { + return new NationalReader(pathAccountSid, pathCountryCode); + } + /** - * Converts a JSON String into a National object using the provided - * ObjectMapper. - * + * Converts a JSON String into a National object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return National object represented by the provided JSON */ - public static National fromJson(final String json, final ObjectMapper objectMapper) { + public static National fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, National.class); @@ -80,12 +75,15 @@ public static National fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a National object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return National object represented by the provided JSON */ - public static National fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static National fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, National.class); @@ -96,177 +94,92 @@ public static National fromJson(final InputStream json, final ObjectMapper objec } } - private final com.twilio.type.PhoneNumber friendlyName; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String lata; - private final String locality; - private final String rateCenter; - private final BigDecimal latitude; - private final BigDecimal longitude; - private final String region; - private final String postalCode; - private final String isoCountry; - private final String addressRequirements; - private final Boolean beta; - private final PhoneNumberCapabilities capabilities; - - @JsonCreator - private National(@JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("lata") - final String lata, - @JsonProperty("locality") - final String locality, - @JsonProperty("rate_center") - final String rateCenter, - @JsonProperty("latitude") - final BigDecimal latitude, - @JsonProperty("longitude") - final BigDecimal longitude, - @JsonProperty("region") - final String region, - @JsonProperty("postal_code") - final String postalCode, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("address_requirements") - final String addressRequirements, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities) { - this.friendlyName = friendlyName; - this.phoneNumber = phoneNumber; - this.lata = lata; - this.locality = locality; - this.rateCenter = rateCenter; - this.latitude = latitude; - this.longitude = longitude; - this.region = region; - this.postalCode = postalCode; - this.isoCountry = isoCountry; - this.addressRequirements = addressRequirements; - this.beta = beta; - this.capabilities = capabilities; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String addressRequirements; - /** - * Returns The The phone_number. - * - * @return The phone_number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final Boolean beta; - /** - * Returns The The lata. - * - * @return The lata - */ - public final String getLata() { - return this.lata; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The The locality. - * - * @return The locality - */ - public final String getLocality() { - return this.locality; - } + @Getter + private final com.twilio.type.PhoneNumber friendlyName; - /** - * Returns The The rate_center. - * - * @return The rate_center - */ - public final String getRateCenter() { - return this.rateCenter; - } + @Getter + private final String isoCountry; - /** - * Returns The The latitude. - * - * @return The latitude - */ - public final BigDecimal getLatitude() { - return this.latitude; - } + @Getter + private final String lata; - /** - * Returns The The longitude. - * - * @return The longitude - */ - public final BigDecimal getLongitude() { - return this.longitude; - } + @Getter + private final BigDecimal latitude; - /** - * Returns The The region. - * - * @return The region - */ - public final String getRegion() { - return this.region; - } + @Getter + private final String locality; - /** - * Returns The The postal_code. - * - * @return The postal_code - */ - public final String getPostalCode() { - return this.postalCode; - } + @Getter + private final BigDecimal longitude; - /** - * Returns The The iso_country. - * - * @return The iso_country - */ - public final String getIsoCountry() { - return this.isoCountry; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The address_requirements. - * - * @return The address_requirements - */ - public final String getAddressRequirements() { - return this.addressRequirements; - } + @Getter + private final String postalCode; - /** - * Returns The The beta. - * - * @return The beta - */ - public final Boolean getBeta() { - return this.beta; - } + @Getter + private final String rateCenter; - /** - * Returns The The capabilities. - * - * @return The capabilities - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; + @Getter + private final String region; + + @JsonCreator + private National( + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("lata") final String lata, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("locality") final String locality, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("region") final String region + ) { + this.addressRequirements = addressRequirements; + this.beta = beta; + this.capabilities = capabilities; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.lata = lata; + this.latitude = latitude; + this.locality = locality; + this.longitude = longitude; + this.phoneNumber = phoneNumber; + this.postalCode = postalCode; + this.rateCenter = rateCenter; + this.region = region; } @Override @@ -280,55 +193,39 @@ public boolean equals(final Object o) { } National other = (National) o; - - return Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(lata, other.lata) && - Objects.equals(locality, other.locality) && - Objects.equals(rateCenter, other.rateCenter) && - Objects.equals(latitude, other.latitude) && - Objects.equals(longitude, other.longitude) && - Objects.equals(region, other.region) && - Objects.equals(postalCode, other.postalCode) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities); + return ( + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(lata, other.lata) && + Objects.equals(latitude, other.latitude) && + Objects.equals(locality, other.locality) && + Objects.equals(longitude, other.longitude) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(region, other.region) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, - phoneNumber, - lata, - locality, - rateCenter, - latitude, - longitude, - region, - postalCode, - isoCountry, - addressRequirements, - beta, - capabilities); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("friendlyName", friendlyName) - .add("phoneNumber", phoneNumber) - .add("lata", lata) - .add("locality", locality) - .add("rateCenter", rateCenter) - .add("latitude", latitude) - .add("longitude", longitude) - .add("region", region) - .add("postalCode", postalCode) - .add("isoCountry", isoCountry) - .add("addressRequirements", addressRequirements) - .add("beta", beta) - .add("capabilities", capabilities) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + addressRequirements, + beta, + capabilities, + friendlyName, + isoCountry, + lata, + latitude, + locality, + longitude, + phoneNumber, + postalCode, + rateCenter, + region + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/NationalReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/NationalReader.java index aff284ebf1..45b02a0be8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/NationalReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/NationalReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -10,19 +17,27 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class NationalReader extends Reader { + private String pathAccountSid; - private final String pathCountryCode; + private String pathCountryCode; private Integer areaCode; private String contains; private Boolean smsEnabled; @@ -41,443 +56,448 @@ public class NationalReader extends Reader { private String inLata; private String inLocality; private Boolean faxEnabled; + private Long pageSize; - /** - * Construct a new NationalReader. - * - * @param pathCountryCode The country_code - */ public NationalReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - /** - * Construct a new NationalReader. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - */ - public NationalReader(final String pathAccountSid, - final String pathCountryCode) { + public NationalReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - /** - * The area_code. - * - * @param areaCode The area_code - * @return this - */ public NationalReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - /** - * The contains. - * - * @param contains The contains - * @return this - */ public NationalReader setContains(final String contains) { this.contains = contains; return this; } - /** - * The sms_enabled. - * - * @param smsEnabled The sms_enabled - * @return this - */ public NationalReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - /** - * The mms_enabled. - * - * @param mmsEnabled The mms_enabled - * @return this - */ public NationalReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - /** - * The voice_enabled. - * - * @param voiceEnabled The voice_enabled - * @return this - */ public NationalReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - /** - * The exclude_all_address_required. - * - * @param excludeAllAddressRequired The exclude_all_address_required - * @return this - */ - public NationalReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired) { + public NationalReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - /** - * The exclude_local_address_required. - * - * @param excludeLocalAddressRequired The exclude_local_address_required - * @return this - */ - public NationalReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired) { + public NationalReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - /** - * The exclude_foreign_address_required. - * - * @param excludeForeignAddressRequired The exclude_foreign_address_required - * @return this - */ - public NationalReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired) { + public NationalReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - /** - * The beta. - * - * @param beta The beta - * @return this - */ public NationalReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * The near_number. - * - * @param nearNumber The near_number - * @return this - */ - public NationalReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber) { + public NationalReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - /** - * The near_number. - * - * @param nearNumber The near_number - * @return this - */ public NationalReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - /** - * The near_lat_long. - * - * @param nearLatLong The near_lat_long - * @return this - */ public NationalReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - /** - * The distance. - * - * @param distance The distance - * @return this - */ public NationalReader setDistance(final Integer distance) { this.distance = distance; return this; } - /** - * The in_postal_code. - * - * @param inPostalCode The in_postal_code - * @return this - */ public NationalReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - /** - * The in_region. - * - * @param inRegion The in_region - * @return this - */ public NationalReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - /** - * The in_rate_center. - * - * @param inRateCenter The in_rate_center - * @return this - */ public NationalReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - /** - * The in_lata. - * - * @param inLata The in_lata - * @return this - */ public NationalReader setInLata(final String inLata) { this.inLata = inLata; return this; } - /** - * The in_locality. - * - * @param inLocality The in_locality - * @return this - */ public NationalReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - /** - * The fax_enabled. - * - * @param faxEnabled The fax_enabled - * @return this - */ public NationalReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return National ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public NationalReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return National ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + National.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/National.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers/" + this.pathCountryCode + "/National.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return National ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + National.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "National read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_phone_numbers", + response.getContent(), + National.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of National Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("National read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "available_phone_numbers", - response.getContent(), - National.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); + Serializer.toString( + request, + "AreaCode", + areaCode, + ParameterType.QUERY + ); } if (contains != null) { - request.addQueryParam("Contains", contains); + Serializer.toString( + request, + "Contains", + contains, + ParameterType.QUERY + ); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); + Serializer.toString( + request, + "SmsEnabled", + smsEnabled, + ParameterType.QUERY + ); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); + Serializer.toString( + request, + "MmsEnabled", + mmsEnabled, + ParameterType.QUERY + ); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); + Serializer.toString( + request, + "VoiceEnabled", + voiceEnabled, + ParameterType.QUERY + ); } if (excludeAllAddressRequired != null) { - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeAllAddressRequired", + excludeAllAddressRequired, + ParameterType.QUERY + ); } if (excludeLocalAddressRequired != null) { - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired, + ParameterType.QUERY + ); } if (excludeForeignAddressRequired != null) { - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired, + ParameterType.QUERY + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); + Serializer.toString( + request, + "NearNumber", + nearNumber, + ParameterType.QUERY + ); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); + Serializer.toString( + request, + "NearLatLong", + nearLatLong, + ParameterType.QUERY + ); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); + Serializer.toString( + request, + "Distance", + distance, + ParameterType.QUERY + ); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); + Serializer.toString( + request, + "InPostalCode", + inPostalCode, + ParameterType.QUERY + ); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); + Serializer.toString( + request, + "InRegion", + inRegion, + ParameterType.QUERY + ); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); + Serializer.toString( + request, + "InRateCenter", + inRateCenter, + ParameterType.QUERY + ); } if (inLata != null) { - request.addQueryParam("InLata", inLata); + Serializer.toString(request, "InLata", inLata, ParameterType.QUERY); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); + Serializer.toString( + request, + "InLocality", + inLocality, + ParameterType.QUERY + ); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); + Serializer.toString( + request, + "FaxEnabled", + faxEnabled, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCost.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCost.java index d83431ae0d..ebed9d5889 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCost.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCost.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -11,62 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SharedCost extends Resource { - private static final long serialVersionUID = 16937856072206L; - /** - * Create a SharedCostReader to execute read. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - * @return SharedCostReader capable of executing the read - */ - public static SharedCostReader reader(final String pathAccountSid, - final String pathCountryCode) { - return new SharedCostReader(pathAccountSid, pathCountryCode); - } - - /** - * Create a SharedCostReader to execute read. - * - * @param pathCountryCode The country_code - * @return SharedCostReader capable of executing the read - */ public static SharedCostReader reader(final String pathCountryCode) { return new SharedCostReader(pathCountryCode); } + public static SharedCostReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { + return new SharedCostReader(pathAccountSid, pathCountryCode); + } + /** - * Converts a JSON String into a SharedCost object using the provided - * ObjectMapper. - * + * Converts a JSON String into a SharedCost object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SharedCost object represented by the provided JSON */ - public static SharedCost fromJson(final String json, final ObjectMapper objectMapper) { + public static SharedCost fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SharedCost.class); @@ -80,12 +75,15 @@ public static SharedCost fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a SharedCost object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SharedCost object represented by the provided JSON */ - public static SharedCost fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SharedCost fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SharedCost.class); @@ -96,177 +94,92 @@ public static SharedCost fromJson(final InputStream json, final ObjectMapper obj } } - private final com.twilio.type.PhoneNumber friendlyName; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String lata; - private final String locality; - private final String rateCenter; - private final BigDecimal latitude; - private final BigDecimal longitude; - private final String region; - private final String postalCode; - private final String isoCountry; - private final String addressRequirements; - private final Boolean beta; - private final PhoneNumberCapabilities capabilities; - - @JsonCreator - private SharedCost(@JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("lata") - final String lata, - @JsonProperty("locality") - final String locality, - @JsonProperty("rate_center") - final String rateCenter, - @JsonProperty("latitude") - final BigDecimal latitude, - @JsonProperty("longitude") - final BigDecimal longitude, - @JsonProperty("region") - final String region, - @JsonProperty("postal_code") - final String postalCode, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("address_requirements") - final String addressRequirements, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities) { - this.friendlyName = friendlyName; - this.phoneNumber = phoneNumber; - this.lata = lata; - this.locality = locality; - this.rateCenter = rateCenter; - this.latitude = latitude; - this.longitude = longitude; - this.region = region; - this.postalCode = postalCode; - this.isoCountry = isoCountry; - this.addressRequirements = addressRequirements; - this.beta = beta; - this.capabilities = capabilities; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String addressRequirements; - /** - * Returns The The phone_number. - * - * @return The phone_number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final Boolean beta; - /** - * Returns The The lata. - * - * @return The lata - */ - public final String getLata() { - return this.lata; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The The locality. - * - * @return The locality - */ - public final String getLocality() { - return this.locality; - } + @Getter + private final com.twilio.type.PhoneNumber friendlyName; - /** - * Returns The The rate_center. - * - * @return The rate_center - */ - public final String getRateCenter() { - return this.rateCenter; - } + @Getter + private final String isoCountry; - /** - * Returns The The latitude. - * - * @return The latitude - */ - public final BigDecimal getLatitude() { - return this.latitude; - } + @Getter + private final String lata; - /** - * Returns The The longitude. - * - * @return The longitude - */ - public final BigDecimal getLongitude() { - return this.longitude; - } + @Getter + private final BigDecimal latitude; - /** - * Returns The The region. - * - * @return The region - */ - public final String getRegion() { - return this.region; - } + @Getter + private final String locality; - /** - * Returns The The postal_code. - * - * @return The postal_code - */ - public final String getPostalCode() { - return this.postalCode; - } + @Getter + private final BigDecimal longitude; - /** - * Returns The The iso_country. - * - * @return The iso_country - */ - public final String getIsoCountry() { - return this.isoCountry; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The address_requirements. - * - * @return The address_requirements - */ - public final String getAddressRequirements() { - return this.addressRequirements; - } + @Getter + private final String postalCode; - /** - * Returns The The beta. - * - * @return The beta - */ - public final Boolean getBeta() { - return this.beta; - } + @Getter + private final String rateCenter; - /** - * Returns The The capabilities. - * - * @return The capabilities - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; + @Getter + private final String region; + + @JsonCreator + private SharedCost( + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("lata") final String lata, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("locality") final String locality, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("region") final String region + ) { + this.addressRequirements = addressRequirements; + this.beta = beta; + this.capabilities = capabilities; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.lata = lata; + this.latitude = latitude; + this.locality = locality; + this.longitude = longitude; + this.phoneNumber = phoneNumber; + this.postalCode = postalCode; + this.rateCenter = rateCenter; + this.region = region; } @Override @@ -280,55 +193,39 @@ public boolean equals(final Object o) { } SharedCost other = (SharedCost) o; - - return Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(lata, other.lata) && - Objects.equals(locality, other.locality) && - Objects.equals(rateCenter, other.rateCenter) && - Objects.equals(latitude, other.latitude) && - Objects.equals(longitude, other.longitude) && - Objects.equals(region, other.region) && - Objects.equals(postalCode, other.postalCode) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities); + return ( + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(lata, other.lata) && + Objects.equals(latitude, other.latitude) && + Objects.equals(locality, other.locality) && + Objects.equals(longitude, other.longitude) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(region, other.region) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, - phoneNumber, - lata, - locality, - rateCenter, - latitude, - longitude, - region, - postalCode, - isoCountry, - addressRequirements, - beta, - capabilities); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("friendlyName", friendlyName) - .add("phoneNumber", phoneNumber) - .add("lata", lata) - .add("locality", locality) - .add("rateCenter", rateCenter) - .add("latitude", latitude) - .add("longitude", longitude) - .add("region", region) - .add("postalCode", postalCode) - .add("isoCountry", isoCountry) - .add("addressRequirements", addressRequirements) - .add("beta", beta) - .add("capabilities", capabilities) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + addressRequirements, + beta, + capabilities, + friendlyName, + isoCountry, + lata, + latitude, + locality, + longitude, + phoneNumber, + postalCode, + rateCenter, + region + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCostReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCostReader.java index 8e7c2b8a4f..b4a4f1262b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCostReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/SharedCostReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -10,19 +17,27 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class SharedCostReader extends Reader { + private String pathAccountSid; - private final String pathCountryCode; + private String pathCountryCode; private Integer areaCode; private String contains; private Boolean smsEnabled; @@ -41,443 +56,448 @@ public class SharedCostReader extends Reader { private String inLata; private String inLocality; private Boolean faxEnabled; + private Long pageSize; - /** - * Construct a new SharedCostReader. - * - * @param pathCountryCode The country_code - */ public SharedCostReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - /** - * Construct a new SharedCostReader. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - */ - public SharedCostReader(final String pathAccountSid, - final String pathCountryCode) { + public SharedCostReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - /** - * The area_code. - * - * @param areaCode The area_code - * @return this - */ public SharedCostReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - /** - * The contains. - * - * @param contains The contains - * @return this - */ public SharedCostReader setContains(final String contains) { this.contains = contains; return this; } - /** - * The sms_enabled. - * - * @param smsEnabled The sms_enabled - * @return this - */ public SharedCostReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - /** - * The mms_enabled. - * - * @param mmsEnabled The mms_enabled - * @return this - */ public SharedCostReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - /** - * The voice_enabled. - * - * @param voiceEnabled The voice_enabled - * @return this - */ public SharedCostReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - /** - * The exclude_all_address_required. - * - * @param excludeAllAddressRequired The exclude_all_address_required - * @return this - */ - public SharedCostReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired) { + public SharedCostReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - /** - * The exclude_local_address_required. - * - * @param excludeLocalAddressRequired The exclude_local_address_required - * @return this - */ - public SharedCostReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired) { + public SharedCostReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - /** - * The exclude_foreign_address_required. - * - * @param excludeForeignAddressRequired The exclude_foreign_address_required - * @return this - */ - public SharedCostReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired) { + public SharedCostReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - /** - * The beta. - * - * @param beta The beta - * @return this - */ public SharedCostReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * The near_number. - * - * @param nearNumber The near_number - * @return this - */ - public SharedCostReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber) { + public SharedCostReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - /** - * The near_number. - * - * @param nearNumber The near_number - * @return this - */ public SharedCostReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - /** - * The near_lat_long. - * - * @param nearLatLong The near_lat_long - * @return this - */ public SharedCostReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - /** - * The distance. - * - * @param distance The distance - * @return this - */ public SharedCostReader setDistance(final Integer distance) { this.distance = distance; return this; } - /** - * The in_postal_code. - * - * @param inPostalCode The in_postal_code - * @return this - */ public SharedCostReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - /** - * The in_region. - * - * @param inRegion The in_region - * @return this - */ public SharedCostReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - /** - * The in_rate_center. - * - * @param inRateCenter The in_rate_center - * @return this - */ public SharedCostReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - /** - * The in_lata. - * - * @param inLata The in_lata - * @return this - */ public SharedCostReader setInLata(final String inLata) { this.inLata = inLata; return this; } - /** - * The in_locality. - * - * @param inLocality The in_locality - * @return this - */ public SharedCostReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - /** - * The fax_enabled. - * - * @param faxEnabled The fax_enabled - * @return this - */ public SharedCostReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SharedCost ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SharedCostReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SharedCost ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + SharedCost.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/SharedCost.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers/" + this.pathCountryCode + "/SharedCost.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SharedCost ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + SharedCost.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SharedCost read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_phone_numbers", + response.getContent(), + SharedCost.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SharedCost Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SharedCost read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "available_phone_numbers", - response.getContent(), - SharedCost.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); + Serializer.toString( + request, + "AreaCode", + areaCode, + ParameterType.QUERY + ); } if (contains != null) { - request.addQueryParam("Contains", contains); + Serializer.toString( + request, + "Contains", + contains, + ParameterType.QUERY + ); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); + Serializer.toString( + request, + "SmsEnabled", + smsEnabled, + ParameterType.QUERY + ); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); + Serializer.toString( + request, + "MmsEnabled", + mmsEnabled, + ParameterType.QUERY + ); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); + Serializer.toString( + request, + "VoiceEnabled", + voiceEnabled, + ParameterType.QUERY + ); } if (excludeAllAddressRequired != null) { - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeAllAddressRequired", + excludeAllAddressRequired, + ParameterType.QUERY + ); } if (excludeLocalAddressRequired != null) { - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired, + ParameterType.QUERY + ); } if (excludeForeignAddressRequired != null) { - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired, + ParameterType.QUERY + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); + Serializer.toString( + request, + "NearNumber", + nearNumber, + ParameterType.QUERY + ); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); + Serializer.toString( + request, + "NearLatLong", + nearLatLong, + ParameterType.QUERY + ); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); + Serializer.toString( + request, + "Distance", + distance, + ParameterType.QUERY + ); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); + Serializer.toString( + request, + "InPostalCode", + inPostalCode, + ParameterType.QUERY + ); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); + Serializer.toString( + request, + "InRegion", + inRegion, + ParameterType.QUERY + ); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); + Serializer.toString( + request, + "InRateCenter", + inRateCenter, + ParameterType.QUERY + ); } if (inLata != null) { - request.addQueryParam("InLata", inLata); + Serializer.toString(request, "InLata", inLata, ParameterType.QUERY); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); + Serializer.toString( + request, + "InLocality", + inLocality, + ParameterType.QUERY + ); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); + Serializer.toString( + request, + "FaxEnabled", + faxEnabled, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFree.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFree.java index 3d9acf127e..29a2fa2025 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFree.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFree.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -11,61 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class TollFree extends Resource { - private static final long serialVersionUID = 16937856072206L; - /** - * Create a TollFreeReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathCountryCode The country_code - * @return TollFreeReader capable of executing the read - */ - public static TollFreeReader reader(final String pathAccountSid, - final String pathCountryCode) { - return new TollFreeReader(pathAccountSid, pathCountryCode); - } - - /** - * Create a TollFreeReader to execute read. - * - * @param pathCountryCode The country_code - * @return TollFreeReader capable of executing the read - */ public static TollFreeReader reader(final String pathCountryCode) { return new TollFreeReader(pathCountryCode); } + public static TollFreeReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { + return new TollFreeReader(pathAccountSid, pathCountryCode); + } + /** - * Converts a JSON String into a TollFree object using the provided - * ObjectMapper. - * + * Converts a JSON String into a TollFree object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return TollFree object represented by the provided JSON */ - public static TollFree fromJson(final String json, final ObjectMapper objectMapper) { + public static TollFree fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TollFree.class); @@ -79,12 +75,15 @@ public static TollFree fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a TollFree object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return TollFree object represented by the provided JSON */ - public static TollFree fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static TollFree fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TollFree.class); @@ -95,182 +94,92 @@ public static TollFree fromJson(final InputStream json, final ObjectMapper objec } } - private final com.twilio.type.PhoneNumber friendlyName; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String lata; - private final String locality; - private final String rateCenter; - private final BigDecimal latitude; - private final BigDecimal longitude; - private final String region; - private final String postalCode; - private final String isoCountry; - private final String addressRequirements; - private final Boolean beta; - private final PhoneNumberCapabilities capabilities; - - @JsonCreator - private TollFree(@JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("lata") - final String lata, - @JsonProperty("locality") - final String locality, - @JsonProperty("rate_center") - final String rateCenter, - @JsonProperty("latitude") - final BigDecimal latitude, - @JsonProperty("longitude") - final BigDecimal longitude, - @JsonProperty("region") - final String region, - @JsonProperty("postal_code") - final String postalCode, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("address_requirements") - final String addressRequirements, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities) { - this.friendlyName = friendlyName; - this.phoneNumber = phoneNumber; - this.lata = lata; - this.locality = locality; - this.rateCenter = rateCenter; - this.latitude = latitude; - this.longitude = longitude; - this.region = region; - this.postalCode = postalCode; - this.isoCountry = isoCountry; - this.addressRequirements = addressRequirements; - this.beta = beta; - this.capabilities = capabilities; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A nicely-formatted version of the phone number.. - * - * @return A nicely-formatted version of the phone number. - */ - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String addressRequirements; - /** - * Returns The The phone number, in E.. - * - * @return The phone number, in E. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final Boolean beta; - /** - * Returns The The LATA of this phone number.. - * - * @return The LATA of this phone number. - */ - public final String getLata() { - return this.lata; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The The locality/city of this phone number.. - * - * @return The locality/city of this phone number. - */ - public final String getLocality() { - return this.locality; - } + @Getter + private final com.twilio.type.PhoneNumber friendlyName; - /** - * Returns The The rate center of this phone number.. - * - * @return The rate center of this phone number. - */ - public final String getRateCenter() { - return this.rateCenter; - } + @Getter + private final String isoCountry; - /** - * Returns The The latitude coordinate of this phone number.. - * - * @return The latitude coordinate of this phone number. - */ - public final BigDecimal getLatitude() { - return this.latitude; - } + @Getter + private final String lata; - /** - * Returns The The longitude coordinate of this phone number.. - * - * @return The longitude coordinate of this phone number. - */ - public final BigDecimal getLongitude() { - return this.longitude; - } + @Getter + private final BigDecimal latitude; - /** - * Returns The The two-letter state or province abbreviation of this phone - * number.. - * - * @return The two-letter state or province abbreviation of this phone number. - */ - public final String getRegion() { - return this.region; - } + @Getter + private final String locality; - /** - * Returns The The postal code of this phone number.. - * - * @return The postal code of this phone number. - */ - public final String getPostalCode() { - return this.postalCode; - } + @Getter + private final BigDecimal longitude; - /** - * Returns The The ISO country code of this phone number.. - * - * @return The ISO country code of this phone number. - */ - public final String getIsoCountry() { - return this.isoCountry; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio.. - * - * @return This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio. - */ - public final String getAddressRequirements() { - return this.addressRequirements; - } + @Getter + private final String postalCode; - /** - * Returns The Phone numbers new to the Twilio platform are marked as beta.. - * - * @return Phone numbers new to the Twilio platform are marked as beta. - */ - public final Boolean getBeta() { - return this.beta; - } + @Getter + private final String rateCenter; - /** - * Returns The This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages.. - * - * @return This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; + @Getter + private final String region; + + @JsonCreator + private TollFree( + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("lata") final String lata, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("locality") final String locality, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("region") final String region + ) { + this.addressRequirements = addressRequirements; + this.beta = beta; + this.capabilities = capabilities; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.lata = lata; + this.latitude = latitude; + this.locality = locality; + this.longitude = longitude; + this.phoneNumber = phoneNumber; + this.postalCode = postalCode; + this.rateCenter = rateCenter; + this.region = region; } @Override @@ -284,55 +193,39 @@ public boolean equals(final Object o) { } TollFree other = (TollFree) o; - - return Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(lata, other.lata) && - Objects.equals(locality, other.locality) && - Objects.equals(rateCenter, other.rateCenter) && - Objects.equals(latitude, other.latitude) && - Objects.equals(longitude, other.longitude) && - Objects.equals(region, other.region) && - Objects.equals(postalCode, other.postalCode) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities); + return ( + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(lata, other.lata) && + Objects.equals(latitude, other.latitude) && + Objects.equals(locality, other.locality) && + Objects.equals(longitude, other.longitude) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(region, other.region) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, - phoneNumber, - lata, - locality, - rateCenter, - latitude, - longitude, - region, - postalCode, - isoCountry, - addressRequirements, - beta, - capabilities); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("friendlyName", friendlyName) - .add("phoneNumber", phoneNumber) - .add("lata", lata) - .add("locality", locality) - .add("rateCenter", rateCenter) - .add("latitude", latitude) - .add("longitude", longitude) - .add("region", region) - .add("postalCode", postalCode) - .add("isoCountry", isoCountry) - .add("addressRequirements", addressRequirements) - .add("beta", beta) - .add("capabilities", capabilities) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + addressRequirements, + beta, + capabilities, + friendlyName, + isoCountry, + lata, + latitude, + locality, + longitude, + phoneNumber, + postalCode, + rateCenter, + region + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFreeReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFreeReader.java index e07d6e1d2f..ebac9c5bcb 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFreeReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/TollFreeReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -10,19 +17,27 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TollFreeReader extends Reader { + private String pathAccountSid; - private final String pathCountryCode; + private String pathCountryCode; private Integer areaCode; private String contains; private Boolean smsEnabled; @@ -41,493 +56,448 @@ public class TollFreeReader extends Reader { private String inLata; private String inLocality; private Boolean faxEnabled; + private Long pageSize; - /** - * Construct a new TollFreeReader. - * - * @param pathCountryCode The country_code - */ public TollFreeReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - /** - * Construct a new TollFreeReader. - * - * @param pathAccountSid The account_sid - * @param pathCountryCode The country_code - */ - public TollFreeReader(final String pathAccountSid, - final String pathCountryCode) { + public TollFreeReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - /** - * Find phone numbers in the specified area code. (US and Canada only). - * - * @param areaCode Find phone numbers in the specified area code. - * @return this - */ public TollFreeReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - /** - * A pattern on which to match phone numbers. Valid characters are `'*'` and - * `[0-9a-zA-Z]`. The `'*'` character will match any single digit. See [Example - * 2](https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-2) and [Example 3](https://www.twilio.com/docs/api/rest/available-phone-numbers#local-get-basic-example-3) below. *NOTE:* Patterns must be at least two characters long.. - * - * @param contains A pattern on which to match phone numbers. - * @return this - */ public TollFreeReader setContains(final String contains) { this.contains = contains; return this; } - /** - * This indicates whether the phone numbers can receive text messages. Possible - * values are `true` or `false`.. - * - * @param smsEnabled This indicates whether the phone numbers can receive text - * messages. - * @return this - */ public TollFreeReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - /** - * This indicates whether the phone numbers can receive MMS messages. Possible - * values are `true` or `false`.. - * - * @param mmsEnabled This indicates whether the phone numbers can receive MMS - * messages. - * @return this - */ public TollFreeReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - /** - * This indicates whether the phone numbers can receive calls. Possible values - * are `true` or `false`.. - * - * @param voiceEnabled This indicates whether the phone numbers can receive - * calls. - * @return this - */ public TollFreeReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - /** - * Indicates whether the response includes phone numbers which require any - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with an Address required.. - * - * @param excludeAllAddressRequired Indicates whether the response includes - * phone numbers which require any Address. - * @return this - */ - public TollFreeReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired) { + public TollFreeReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - /** - * Indicates whether the response includes phone numbers which require a local - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with a local Address required.. - * - * @param excludeLocalAddressRequired Indicates whether the response includes - * phone numbers which require a local - * Address. - * @return this - */ - public TollFreeReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired) { + public TollFreeReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - /** - * Indicates whether the response includes phone numbers which require a foreign - * [Address](https://www.twilio.com/docs/usage/api/addresses). Possible values - * are `true` or `false`. If not specified, the default is `false`, and results - * could include phone numbers with a foreign Address required.. - * - * @param excludeForeignAddressRequired Indicates whether the response includes - * phone numbers which require a foreign - * Address. - * @return this - */ - public TollFreeReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired) { + public TollFreeReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - /** - * Include phone numbers new to the Twilio platform. Possible values are either - * `true` or `false`. Default is `true`.. - * - * @param beta Include phone numbers new to the Twilio platform. - * @return this - */ public TollFreeReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * Given a phone number, find a geographically close number within `Distance` - * miles. Distance defaults to 25 miles. *Limited to US and Canadian phone - * numbers.*. - * - * @param nearNumber Given a phone number, find a geographically close number - * within Distance miles. (US/Canada only) - * @return this - */ - public TollFreeReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber) { + public TollFreeReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - /** - * Given a phone number, find a geographically close number within `Distance` - * miles. Distance defaults to 25 miles. *Limited to US and Canadian phone - * numbers.*. - * - * @param nearNumber Given a phone number, find a geographically close number - * within Distance miles. (US/Canada only) - * @return this - */ public TollFreeReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - /** - * Given a latitude/longitude pair `lat,long` find geographically close numbers - * within `Distance` miles. *Limited to US and Canadian phone numbers.*. - * - * @param nearLatLong Given a latitude/longitude pair lat,long find - * geographically close numbers within Distance miles. - * (US/Canada only) - * @return this - */ public TollFreeReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - /** - * Specifies the search radius for a `Near-` query in miles. If not specified - * this defaults to 25 miles. Maximum searchable distance is 500 miles. *Limited - * to US and Canadian phone numbers.*. - * - * @param distance Specifies the search radius for a Near- query in miles. - * (US/Canada only) - * @return this - */ public TollFreeReader setDistance(final Integer distance) { this.distance = distance; return this; } - /** - * Limit results to a particular postal code. Given a phone number, search - * within the same postal code as that number. *Limited to US and Canadian phone - * numbers.*. - * - * @param inPostalCode Limit results to a particular postal code. (US/Canada - * only) - * @return this - */ public TollFreeReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - /** - * Limit results to a particular region (i.e. State/Province). Given a phone - * number, search within the same Region as that number. *Limited to US and - * Canadian phone numbers.*. - * - * @param inRegion Limit results to a particular region. (US/Canada only) - * @return this - */ public TollFreeReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - /** - * Limit results to a specific rate center, or given a phone number search - * within the same rate center as that number. Requires InLata to be set as - * well. *Limited to US and Canadian phone numbers.*. - * - * @param inRateCenter Limit results to a specific rate center, or given a - * phone number search within the same rate center as that - * number. (US/Canada only) - * @return this - */ public TollFreeReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - /** - * Limit results to a specific Local access and transport area - * ([LATA](http://en.wikipedia.org/wiki/Local_access_and_transport_area)). Given - * a phone number, search within the same - * [LATA](http://en.wikipedia.org/wiki/Local_access_and_transport_area) as that - * number. *Limited to US and Canadian phone numbers.*. - * - * @param inLata Limit results to a specific Local access and transport area. - * (US/Canada only) - * @return this - */ public TollFreeReader setInLata(final String inLata) { this.inLata = inLata; return this; } - /** - * Limit results to a particular locality (i.e. City). Given a phone number, - * search within the same Locality as that number.. - * - * @param inLocality Limit results to a particular locality. - * @return this - */ public TollFreeReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - /** - * This indicates whether the phone numbers can receive faxes. Possible values - * are `true` or `false`.. - * - * @param faxEnabled This indicates whether the phone numbers can receive faxes. - * @return this - */ public TollFreeReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TollFree ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TollFreeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TollFree ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + TollFree.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/TollFree.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers/" + this.pathCountryCode + "/TollFree.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return TollFree ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + TollFree.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TollFree read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_phone_numbers", + response.getContent(), + TollFree.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of TollFree Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("TollFree read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "available_phone_numbers", - response.getContent(), - TollFree.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); + Serializer.toString( + request, + "AreaCode", + areaCode, + ParameterType.QUERY + ); } if (contains != null) { - request.addQueryParam("Contains", contains); + Serializer.toString( + request, + "Contains", + contains, + ParameterType.QUERY + ); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); + Serializer.toString( + request, + "SmsEnabled", + smsEnabled, + ParameterType.QUERY + ); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); + Serializer.toString( + request, + "MmsEnabled", + mmsEnabled, + ParameterType.QUERY + ); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); + Serializer.toString( + request, + "VoiceEnabled", + voiceEnabled, + ParameterType.QUERY + ); } if (excludeAllAddressRequired != null) { - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeAllAddressRequired", + excludeAllAddressRequired, + ParameterType.QUERY + ); } if (excludeLocalAddressRequired != null) { - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired, + ParameterType.QUERY + ); } if (excludeForeignAddressRequired != null) { - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired, + ParameterType.QUERY + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); + Serializer.toString( + request, + "NearNumber", + nearNumber, + ParameterType.QUERY + ); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); + Serializer.toString( + request, + "NearLatLong", + nearLatLong, + ParameterType.QUERY + ); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); + Serializer.toString( + request, + "Distance", + distance, + ParameterType.QUERY + ); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); + Serializer.toString( + request, + "InPostalCode", + inPostalCode, + ParameterType.QUERY + ); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); + Serializer.toString( + request, + "InRegion", + inRegion, + ParameterType.QUERY + ); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); + Serializer.toString( + request, + "InRateCenter", + inRateCenter, + ParameterType.QUERY + ); } if (inLata != null) { - request.addQueryParam("InLata", inLata); + Serializer.toString(request, "InLata", inLata, ParameterType.QUERY); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); + Serializer.toString( + request, + "InLocality", + inLocality, + ParameterType.QUERY + ); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); + Serializer.toString( + request, + "FaxEnabled", + faxEnabled, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Voip.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Voip.java index acdaf00c5a..c973cb1291 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Voip.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/Voip.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -11,61 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Voip extends Resource { - private static final long serialVersionUID = 16937856072206L; - /** - * Create a VoipReader to execute read. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - * @return VoipReader capable of executing the read - */ - public static VoipReader reader(final String pathAccountSid, - final String pathCountryCode) { - return new VoipReader(pathAccountSid, pathCountryCode); - } - - /** - * Create a VoipReader to execute read. - * - * @param pathCountryCode The country_code - * @return VoipReader capable of executing the read - */ public static VoipReader reader(final String pathCountryCode) { return new VoipReader(pathCountryCode); } + public static VoipReader reader( + final String pathAccountSid, + final String pathCountryCode + ) { + return new VoipReader(pathAccountSid, pathCountryCode); + } + /** * Converts a JSON String into a Voip object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Voip object represented by the provided JSON */ - public static Voip fromJson(final String json, final ObjectMapper objectMapper) { + public static Voip fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Voip.class); @@ -79,12 +75,15 @@ public static Voip fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Voip object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Voip object represented by the provided JSON */ - public static Voip fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Voip fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Voip.class); @@ -95,177 +94,92 @@ public static Voip fromJson(final InputStream json, final ObjectMapper objectMap } } - private final com.twilio.type.PhoneNumber friendlyName; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String lata; - private final String locality; - private final String rateCenter; - private final BigDecimal latitude; - private final BigDecimal longitude; - private final String region; - private final String postalCode; - private final String isoCountry; - private final String addressRequirements; - private final Boolean beta; - private final PhoneNumberCapabilities capabilities; - - @JsonCreator - private Voip(@JsonProperty("friendly_name") - final com.twilio.type.PhoneNumber friendlyName, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("lata") - final String lata, - @JsonProperty("locality") - final String locality, - @JsonProperty("rate_center") - final String rateCenter, - @JsonProperty("latitude") - final BigDecimal latitude, - @JsonProperty("longitude") - final BigDecimal longitude, - @JsonProperty("region") - final String region, - @JsonProperty("postal_code") - final String postalCode, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("address_requirements") - final String addressRequirements, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities) { - this.friendlyName = friendlyName; - this.phoneNumber = phoneNumber; - this.lata = lata; - this.locality = locality; - this.rateCenter = rateCenter; - this.latitude = latitude; - this.longitude = longitude; - this.region = region; - this.postalCode = postalCode; - this.isoCountry = isoCountry; - this.addressRequirements = addressRequirements; - this.beta = beta; - this.capabilities = capabilities; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final com.twilio.type.PhoneNumber getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String addressRequirements; - /** - * Returns The The phone_number. - * - * @return The phone_number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final Boolean beta; - /** - * Returns The The lata. - * - * @return The lata - */ - public final String getLata() { - return this.lata; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The The locality. - * - * @return The locality - */ - public final String getLocality() { - return this.locality; - } + @Getter + private final com.twilio.type.PhoneNumber friendlyName; - /** - * Returns The The rate_center. - * - * @return The rate_center - */ - public final String getRateCenter() { - return this.rateCenter; - } + @Getter + private final String isoCountry; - /** - * Returns The The latitude. - * - * @return The latitude - */ - public final BigDecimal getLatitude() { - return this.latitude; - } + @Getter + private final String lata; - /** - * Returns The The longitude. - * - * @return The longitude - */ - public final BigDecimal getLongitude() { - return this.longitude; - } + @Getter + private final BigDecimal latitude; - /** - * Returns The The region. - * - * @return The region - */ - public final String getRegion() { - return this.region; - } + @Getter + private final String locality; - /** - * Returns The The postal_code. - * - * @return The postal_code - */ - public final String getPostalCode() { - return this.postalCode; - } + @Getter + private final BigDecimal longitude; - /** - * Returns The The iso_country. - * - * @return The iso_country - */ - public final String getIsoCountry() { - return this.isoCountry; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The address_requirements. - * - * @return The address_requirements - */ - public final String getAddressRequirements() { - return this.addressRequirements; - } + @Getter + private final String postalCode; - /** - * Returns The The beta. - * - * @return The beta - */ - public final Boolean getBeta() { - return this.beta; - } + @Getter + private final String rateCenter; - /** - * Returns The The capabilities. - * - * @return The capabilities - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; + @Getter + private final String region; + + @JsonCreator + private Voip( + @JsonProperty("address_requirements") final String addressRequirements, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty( + "friendly_name" + ) final com.twilio.type.PhoneNumber friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("lata") final String lata, + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("locality") final String locality, + @JsonProperty("longitude") final BigDecimal longitude, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("postal_code") final String postalCode, + @JsonProperty("rate_center") final String rateCenter, + @JsonProperty("region") final String region + ) { + this.addressRequirements = addressRequirements; + this.beta = beta; + this.capabilities = capabilities; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.lata = lata; + this.latitude = latitude; + this.locality = locality; + this.longitude = longitude; + this.phoneNumber = phoneNumber; + this.postalCode = postalCode; + this.rateCenter = rateCenter; + this.region = region; } @Override @@ -279,55 +193,39 @@ public boolean equals(final Object o) { } Voip other = (Voip) o; - - return Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(lata, other.lata) && - Objects.equals(locality, other.locality) && - Objects.equals(rateCenter, other.rateCenter) && - Objects.equals(latitude, other.latitude) && - Objects.equals(longitude, other.longitude) && - Objects.equals(region, other.region) && - Objects.equals(postalCode, other.postalCode) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities); + return ( + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(lata, other.lata) && + Objects.equals(latitude, other.latitude) && + Objects.equals(locality, other.locality) && + Objects.equals(longitude, other.longitude) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(rateCenter, other.rateCenter) && + Objects.equals(region, other.region) + ); } @Override public int hashCode() { - return Objects.hash(friendlyName, - phoneNumber, - lata, - locality, - rateCenter, - latitude, - longitude, - region, - postalCode, - isoCountry, - addressRequirements, - beta, - capabilities); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("friendlyName", friendlyName) - .add("phoneNumber", phoneNumber) - .add("lata", lata) - .add("locality", locality) - .add("rateCenter", rateCenter) - .add("latitude", latitude) - .add("longitude", longitude) - .add("region", region) - .add("postalCode", postalCode) - .add("isoCountry", isoCountry) - .add("addressRequirements", addressRequirements) - .add("beta", beta) - .add("capabilities", capabilities) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + addressRequirements, + beta, + capabilities, + friendlyName, + isoCountry, + lata, + latitude, + locality, + longitude, + phoneNumber, + postalCode, + rateCenter, + region + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/VoipReader.java b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/VoipReader.java index fdf1a2f51b..4ed2f671be 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/VoipReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/availablephonenumbercountry/VoipReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.availablephonenumbercountry; @@ -10,19 +17,27 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class VoipReader extends Reader { + private String pathAccountSid; - private final String pathCountryCode; + private String pathCountryCode; private Integer areaCode; private String contains; private Boolean smsEnabled; @@ -41,443 +56,444 @@ public class VoipReader extends Reader { private String inLata; private String inLocality; private Boolean faxEnabled; + private Long pageSize; - /** - * Construct a new VoipReader. - * - * @param pathCountryCode The country_code - */ public VoipReader(final String pathCountryCode) { this.pathCountryCode = pathCountryCode; } - /** - * Construct a new VoipReader. - * - * @param pathAccountSid The 34 character string that uniquely identifies your - * account. - * @param pathCountryCode The country_code - */ - public VoipReader(final String pathAccountSid, - final String pathCountryCode) { + public VoipReader( + final String pathAccountSid, + final String pathCountryCode + ) { this.pathAccountSid = pathAccountSid; this.pathCountryCode = pathCountryCode; } - /** - * The area_code. - * - * @param areaCode The area_code - * @return this - */ public VoipReader setAreaCode(final Integer areaCode) { this.areaCode = areaCode; return this; } - /** - * The contains. - * - * @param contains The contains - * @return this - */ public VoipReader setContains(final String contains) { this.contains = contains; return this; } - /** - * The sms_enabled. - * - * @param smsEnabled The sms_enabled - * @return this - */ public VoipReader setSmsEnabled(final Boolean smsEnabled) { this.smsEnabled = smsEnabled; return this; } - /** - * The mms_enabled. - * - * @param mmsEnabled The mms_enabled - * @return this - */ public VoipReader setMmsEnabled(final Boolean mmsEnabled) { this.mmsEnabled = mmsEnabled; return this; } - /** - * The voice_enabled. - * - * @param voiceEnabled The voice_enabled - * @return this - */ public VoipReader setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - /** - * The exclude_all_address_required. - * - * @param excludeAllAddressRequired The exclude_all_address_required - * @return this - */ - public VoipReader setExcludeAllAddressRequired(final Boolean excludeAllAddressRequired) { + public VoipReader setExcludeAllAddressRequired( + final Boolean excludeAllAddressRequired + ) { this.excludeAllAddressRequired = excludeAllAddressRequired; return this; } - /** - * The exclude_local_address_required. - * - * @param excludeLocalAddressRequired The exclude_local_address_required - * @return this - */ - public VoipReader setExcludeLocalAddressRequired(final Boolean excludeLocalAddressRequired) { + public VoipReader setExcludeLocalAddressRequired( + final Boolean excludeLocalAddressRequired + ) { this.excludeLocalAddressRequired = excludeLocalAddressRequired; return this; } - /** - * The exclude_foreign_address_required. - * - * @param excludeForeignAddressRequired The exclude_foreign_address_required - * @return this - */ - public VoipReader setExcludeForeignAddressRequired(final Boolean excludeForeignAddressRequired) { + public VoipReader setExcludeForeignAddressRequired( + final Boolean excludeForeignAddressRequired + ) { this.excludeForeignAddressRequired = excludeForeignAddressRequired; return this; } - /** - * The beta. - * - * @param beta The beta - * @return this - */ public VoipReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * The near_number. - * - * @param nearNumber The near_number - * @return this - */ - public VoipReader setNearNumber(final com.twilio.type.PhoneNumber nearNumber) { + public VoipReader setNearNumber( + final com.twilio.type.PhoneNumber nearNumber + ) { this.nearNumber = nearNumber; return this; } - /** - * The near_number. - * - * @param nearNumber The near_number - * @return this - */ public VoipReader setNearNumber(final String nearNumber) { return setNearNumber(Promoter.phoneNumberFromString(nearNumber)); } - /** - * The near_lat_long. - * - * @param nearLatLong The near_lat_long - * @return this - */ public VoipReader setNearLatLong(final String nearLatLong) { this.nearLatLong = nearLatLong; return this; } - /** - * The distance. - * - * @param distance The distance - * @return this - */ public VoipReader setDistance(final Integer distance) { this.distance = distance; return this; } - /** - * The in_postal_code. - * - * @param inPostalCode The in_postal_code - * @return this - */ public VoipReader setInPostalCode(final String inPostalCode) { this.inPostalCode = inPostalCode; return this; } - /** - * The in_region. - * - * @param inRegion The in_region - * @return this - */ public VoipReader setInRegion(final String inRegion) { this.inRegion = inRegion; return this; } - /** - * The in_rate_center. - * - * @param inRateCenter The in_rate_center - * @return this - */ public VoipReader setInRateCenter(final String inRateCenter) { this.inRateCenter = inRateCenter; return this; } - /** - * The in_lata. - * - * @param inLata The in_lata - * @return this - */ public VoipReader setInLata(final String inLata) { this.inLata = inLata; return this; } - /** - * The in_locality. - * - * @param inLocality The in_locality - * @return this - */ public VoipReader setInLocality(final String inLocality) { this.inLocality = inLocality; return this; } - /** - * The fax_enabled. - * - * @param faxEnabled The fax_enabled - * @return this - */ public VoipReader setFaxEnabled(final Boolean faxEnabled) { this.faxEnabled = faxEnabled; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Voip ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public VoipReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Voip ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + Voip.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/Voip.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CountryCode" + "}", + this.pathCountryCode.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/AvailablePhoneNumbers/" + this.pathCountryCode + "/Voip.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Voip ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_phone_numbers", + response.getContent(), + Voip.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Voip read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_phone_numbers", + response.getContent(), + Voip.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Voip Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Voip read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "available_phone_numbers", - response.getContent(), - Voip.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (areaCode != null) { - request.addQueryParam("AreaCode", areaCode.toString()); + Serializer.toString( + request, + "AreaCode", + areaCode, + ParameterType.QUERY + ); } if (contains != null) { - request.addQueryParam("Contains", contains); + Serializer.toString( + request, + "Contains", + contains, + ParameterType.QUERY + ); } if (smsEnabled != null) { - request.addQueryParam("SmsEnabled", smsEnabled.toString()); + Serializer.toString( + request, + "SmsEnabled", + smsEnabled, + ParameterType.QUERY + ); } if (mmsEnabled != null) { - request.addQueryParam("MmsEnabled", mmsEnabled.toString()); + Serializer.toString( + request, + "MmsEnabled", + mmsEnabled, + ParameterType.QUERY + ); } if (voiceEnabled != null) { - request.addQueryParam("VoiceEnabled", voiceEnabled.toString()); + Serializer.toString( + request, + "VoiceEnabled", + voiceEnabled, + ParameterType.QUERY + ); } if (excludeAllAddressRequired != null) { - request.addQueryParam("ExcludeAllAddressRequired", excludeAllAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeAllAddressRequired", + excludeAllAddressRequired, + ParameterType.QUERY + ); } if (excludeLocalAddressRequired != null) { - request.addQueryParam("ExcludeLocalAddressRequired", excludeLocalAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeLocalAddressRequired", + excludeLocalAddressRequired, + ParameterType.QUERY + ); } if (excludeForeignAddressRequired != null) { - request.addQueryParam("ExcludeForeignAddressRequired", excludeForeignAddressRequired.toString()); + Serializer.toString( + request, + "ExcludeForeignAddressRequired", + excludeForeignAddressRequired, + ParameterType.QUERY + ); } if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (nearNumber != null) { - request.addQueryParam("NearNumber", nearNumber.toString()); + Serializer.toString( + request, + "NearNumber", + nearNumber, + ParameterType.QUERY + ); } if (nearLatLong != null) { - request.addQueryParam("NearLatLong", nearLatLong); + Serializer.toString( + request, + "NearLatLong", + nearLatLong, + ParameterType.QUERY + ); } if (distance != null) { - request.addQueryParam("Distance", distance.toString()); + Serializer.toString( + request, + "Distance", + distance, + ParameterType.QUERY + ); } if (inPostalCode != null) { - request.addQueryParam("InPostalCode", inPostalCode); + Serializer.toString( + request, + "InPostalCode", + inPostalCode, + ParameterType.QUERY + ); } if (inRegion != null) { - request.addQueryParam("InRegion", inRegion); + Serializer.toString( + request, + "InRegion", + inRegion, + ParameterType.QUERY + ); } if (inRateCenter != null) { - request.addQueryParam("InRateCenter", inRateCenter); + Serializer.toString( + request, + "InRateCenter", + inRateCenter, + ParameterType.QUERY + ); } if (inLata != null) { - request.addQueryParam("InLata", inLata); + Serializer.toString(request, "InLata", inLata, ParameterType.QUERY); } if (inLocality != null) { - request.addQueryParam("InLocality", inLocality); + Serializer.toString( + request, + "InLocality", + inLocality, + ParameterType.QUERY + ); } if (faxEnabled != null) { - request.addQueryParam("FaxEnabled", faxEnabled.toString()); + Serializer.toString( + request, + "FaxEnabled", + faxEnabled, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Event.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Event.java new file mode 100644 index 0000000000..546357a2f0 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Event.java @@ -0,0 +1,143 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Event extends Resource { + + public static EventReader reader(final String pathCallSid) { + return new EventReader(pathCallSid); + } + + public static EventReader reader( + final String pathAccountSid, + final String pathCallSid + ) { + return new EventReader(pathAccountSid, pathCallSid); + } + + /** + * Converts a JSON String into a Event object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Event.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Event object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Event.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object request; + + @Getter + private final Object response; + + @JsonCreator + private Event( + @JsonProperty("request") final Object request, + @JsonProperty("response") final Object response + ) { + this.request = request; + this.response = response; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Event other = (Event) o; + return ( + Objects.equals(request, other.request) && + Objects.equals(response, other.response) + ); + } + + @Override + public int hashCode() { + return Objects.hash(request, response); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/EventReader.java b/src/main/java/com/twilio/rest/api/v2010/account/call/EventReader.java new file mode 100644 index 0000000000..40282d8bd7 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/EventReader.java @@ -0,0 +1,219 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EventReader extends Reader { + + private String pathAccountSid; + private String pathCallSid; + private Long pageSize; + + public EventReader(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + public EventReader(final String pathAccountSid, final String pathCallSid) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + } + + public EventReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Events.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Event read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Feedback.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Feedback.java deleted file mode 100644 index bfdb3a4f8a..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Feedback.java +++ /dev/null @@ -1,306 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class Feedback extends Resource { - private static final long serialVersionUID = 172313514850197L; - - public enum Issues { - AUDIO_LATENCY("audio-latency"), - DIGITS_NOT_CAPTURED("digits-not-captured"), - DROPPED_CALL("dropped-call"), - IMPERFECT_AUDIO("imperfect-audio"), - INCORRECT_CALLER_ID("incorrect-caller-id"), - ONE_WAY_AUDIO("one-way-audio"), - POST_DIAL_DELAY("post-dial-delay"), - UNSOLICITED_CALL("unsolicited-call"); - - private final String value; - - private Issues(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Issues from a string. - * @param value string value - * @return generated Issues - */ - @JsonCreator - public static Issues forValue(final String value) { - return Promoter.enumFromString(value, Issues.values()); - } - } - - /** - * Create a FeedbackCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param qualityScore An integer from 1 to 5 - * @return FeedbackCreator capable of executing the create - */ - public static FeedbackCreator creator(final String pathAccountSid, - final String pathCallSid, - final Integer qualityScore) { - return new FeedbackCreator(pathAccountSid, pathCallSid, qualityScore); - } - - /** - * Create a FeedbackCreator to execute create. - * - * @param pathCallSid The call_sid - * @param qualityScore An integer from 1 to 5 - * @return FeedbackCreator capable of executing the create - */ - public static FeedbackCreator creator(final String pathCallSid, - final Integer qualityScore) { - return new FeedbackCreator(pathCallSid, qualityScore); - } - - /** - * Create a FeedbackFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call sid that uniquely identifies the call - * @return FeedbackFetcher capable of executing the fetch - */ - public static FeedbackFetcher fetcher(final String pathAccountSid, - final String pathCallSid) { - return new FeedbackFetcher(pathAccountSid, pathCallSid); - } - - /** - * Create a FeedbackFetcher to execute fetch. - * - * @param pathCallSid The call sid that uniquely identifies the call - * @return FeedbackFetcher capable of executing the fetch - */ - public static FeedbackFetcher fetcher(final String pathCallSid) { - return new FeedbackFetcher(pathCallSid); - } - - /** - * Create a FeedbackUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param qualityScore An integer from 1 to 5 - * @return FeedbackUpdater capable of executing the update - */ - public static FeedbackUpdater updater(final String pathAccountSid, - final String pathCallSid, - final Integer qualityScore) { - return new FeedbackUpdater(pathAccountSid, pathCallSid, qualityScore); - } - - /** - * Create a FeedbackUpdater to execute update. - * - * @param pathCallSid The call_sid - * @param qualityScore An integer from 1 to 5 - * @return FeedbackUpdater capable of executing the update - */ - public static FeedbackUpdater updater(final String pathCallSid, - final Integer qualityScore) { - return new FeedbackUpdater(pathCallSid, qualityScore); - } - - /** - * Converts a JSON String into a Feedback object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Feedback object represented by the provided JSON - */ - public static Feedback fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Feedback.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Feedback object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Feedback object represented by the provided JSON - */ - public static Feedback fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Feedback.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final List issues; - private final Integer qualityScore; - private final String sid; - - @JsonCreator - private Feedback(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("issues") - final List issues, - @JsonProperty("quality_score") - final Integer qualityScore, - @JsonProperty("sid") - final String sid) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.issues = issues; - this.qualityScore = qualityScore; - this.sid = sid; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The issues. - * - * @return The issues - */ - public final List getIssues() { - return this.issues; - } - - /** - * Returns The 1 to 5 quality score. - * - * @return 1 to 5 quality score - */ - public final Integer getQualityScore() { - return this.qualityScore; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Feedback other = (Feedback) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(issues, other.issues) && - Objects.equals(qualityScore, other.qualityScore) && - Objects.equals(sid, other.sid); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - issues, - qualityScore, - sid); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("issues", issues) - .add("qualityScore", qualityScore) - .add("sid", sid) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackCreator.java deleted file mode 100644 index 021564baa6..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackCreator.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.List; - -public class FeedbackCreator extends Creator { - private String pathAccountSid; - private final String pathCallSid; - private final Integer qualityScore; - private List issue; - - /** - * Construct a new FeedbackCreator. - * - * @param pathCallSid The call_sid - * @param qualityScore An integer from 1 to 5 - */ - public FeedbackCreator(final String pathCallSid, - final Integer qualityScore) { - this.pathCallSid = pathCallSid; - this.qualityScore = qualityScore; - } - - /** - * Construct a new FeedbackCreator. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param qualityScore An integer from 1 to 5 - */ - public FeedbackCreator(final String pathAccountSid, - final String pathCallSid, - final Integer qualityScore) { - this.pathAccountSid = pathAccountSid; - this.pathCallSid = pathCallSid; - this.qualityScore = qualityScore; - } - - /** - * One or more issues experienced during the call. The issues can be: - * `imperfect-audio`, `dropped-call`, `incorrect-caller-id`, `post-dial-delay`, - * `digits-not-captured`, `audio-latency`, or `one-way-audio`.. - * - * @param issue Issues experienced during the call - * @return this - */ - public FeedbackCreator setIssue(final List issue) { - this.issue = issue; - return this; - } - - /** - * One or more issues experienced during the call. The issues can be: - * `imperfect-audio`, `dropped-call`, `incorrect-caller-id`, `post-dial-delay`, - * `digits-not-captured`, `audio-latency`, or `one-way-audio`.. - * - * @param issue Issues experienced during the call - * @return this - */ - public FeedbackCreator setIssue(final Feedback.Issues issue) { - return setIssue(Promoter.listOfOne(issue)); - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Feedback - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Feedback create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.POST, - Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Feedback.json", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Feedback creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Feedback.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (qualityScore != null) { - request.addPostParam("QualityScore", qualityScore.toString()); - } - - if (issue != null) { - for (Feedback.Issues prop : issue) { - request.addPostParam("Issue", prop.toString()); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackFetcher.java deleted file mode 100644 index 856d2d9f50..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackFetcher.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -public class FeedbackFetcher extends Fetcher { - private String pathAccountSid; - private final String pathCallSid; - - /** - * Construct a new FeedbackFetcher. - * - * @param pathCallSid The call sid that uniquely identifies the call - */ - public FeedbackFetcher(final String pathCallSid) { - this.pathCallSid = pathCallSid; - } - - /** - * Construct a new FeedbackFetcher. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call sid that uniquely identifies the call - */ - public FeedbackFetcher(final String pathAccountSid, - final String pathCallSid) { - this.pathAccountSid = pathAccountSid; - this.pathCallSid = pathCallSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Feedback - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Feedback fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Feedback.json", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Feedback fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Feedback.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummary.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummary.java deleted file mode 100644 index ac2a84ca0a..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummary.java +++ /dev/null @@ -1,429 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import com.twilio.type.FeedbackIssue; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; - -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class FeedbackSummary extends Resource { - private static final long serialVersionUID = 164951485289659L; - - public enum Status { - QUEUED("queued"), - IN_PROGRESS("in-progress"), - COMPLETED("completed"), - FAILED("failed"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - - /** - * Create a FeedbackSummaryCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param startDate Only include usage that has occurred on or after this date. - * @param endDate Only include usage that has occurred on or before this date. - * @return FeedbackSummaryCreator capable of executing the create - */ - public static FeedbackSummaryCreator creator(final String pathAccountSid, - final LocalDate startDate, - final LocalDate endDate) { - return new FeedbackSummaryCreator(pathAccountSid, startDate, endDate); - } - - /** - * Create a FeedbackSummaryCreator to execute create. - * - * @param startDate Only include usage that has occurred on or after this date. - * @param endDate Only include usage that has occurred on or before this date. - * @return FeedbackSummaryCreator capable of executing the create - */ - public static FeedbackSummaryCreator creator(final LocalDate startDate, - final LocalDate endDate) { - return new FeedbackSummaryCreator(startDate, endDate); - } - - /** - * Create a FeedbackSummaryFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return FeedbackSummaryFetcher capable of executing the fetch - */ - public static FeedbackSummaryFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new FeedbackSummaryFetcher(pathAccountSid, pathSid); - } - - /** - * Create a FeedbackSummaryFetcher to execute fetch. - * - * @param pathSid The sid - * @return FeedbackSummaryFetcher capable of executing the fetch - */ - public static FeedbackSummaryFetcher fetcher(final String pathSid) { - return new FeedbackSummaryFetcher(pathSid); - } - - /** - * Create a FeedbackSummaryDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return FeedbackSummaryDeleter capable of executing the delete - */ - public static FeedbackSummaryDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new FeedbackSummaryDeleter(pathAccountSid, pathSid); - } - - /** - * Create a FeedbackSummaryDeleter to execute delete. - * - * @param pathSid The sid - * @return FeedbackSummaryDeleter capable of executing the delete - */ - public static FeedbackSummaryDeleter deleter(final String pathSid) { - return new FeedbackSummaryDeleter(pathSid); - } - - /** - * Converts a JSON String into a FeedbackSummary object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FeedbackSummary object represented by the provided JSON - */ - public static FeedbackSummary fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, FeedbackSummary.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a FeedbackSummary object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FeedbackSummary object represented by the provided JSON - */ - public static FeedbackSummary fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, FeedbackSummary.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final Integer callCount; - private final Integer callFeedbackCount; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final DateTime endDate; - private final Boolean includeSubaccounts; - private final List issues; - private final BigDecimal qualityScoreAverage; - private final BigDecimal qualityScoreMedian; - private final BigDecimal qualityScoreStandardDeviation; - private final String sid; - private final DateTime startDate; - private final FeedbackSummary.Status status; - - @JsonCreator - private FeedbackSummary(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("call_count") - final Integer callCount, - @JsonProperty("call_feedback_count") - final Integer callFeedbackCount, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("include_subaccounts") - final Boolean includeSubaccounts, - @JsonProperty("issues") - final List issues, - @JsonProperty("quality_score_average") - final BigDecimal qualityScoreAverage, - @JsonProperty("quality_score_median") - final BigDecimal qualityScoreMedian, - @JsonProperty("quality_score_standard_deviation") - final BigDecimal qualityScoreStandardDeviation, - @JsonProperty("sid") - final String sid, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("status") - final FeedbackSummary.Status status) { - this.accountSid = accountSid; - this.callCount = callCount; - this.callFeedbackCount = callFeedbackCount; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.endDate = DateConverter.iso8601DateTimeFromString(endDate); - this.includeSubaccounts = includeSubaccounts; - this.issues = issues; - this.qualityScoreAverage = qualityScoreAverage; - this.qualityScoreMedian = qualityScoreMedian; - this.qualityScoreStandardDeviation = qualityScoreStandardDeviation; - this.sid = sid; - this.startDate = DateConverter.iso8601DateTimeFromString(startDate); - this.status = status; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The call_count. - * - * @return The call_count - */ - public final Integer getCallCount() { - return this.callCount; - } - - /** - * Returns The The call_feedback_count. - * - * @return The call_feedback_count - */ - public final Integer getCallFeedbackCount() { - return this.callFeedbackCount; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The end_date. - * - * @return The end_date - */ - public final DateTime getEndDate() { - return this.endDate; - } - - /** - * Returns The The include_subaccounts. - * - * @return The include_subaccounts - */ - public final Boolean getIncludeSubaccounts() { - return this.includeSubaccounts; - } - - /** - * Returns The The issues. - * - * @return The issues - */ - public final List getIssues() { - return this.issues; - } - - /** - * Returns The The quality_score_average. - * - * @return The quality_score_average - */ - public final BigDecimal getQualityScoreAverage() { - return this.qualityScoreAverage; - } - - /** - * Returns The The quality_score_median. - * - * @return The quality_score_median - */ - public final BigDecimal getQualityScoreMedian() { - return this.qualityScoreMedian; - } - - /** - * Returns The The quality_score_standard_deviation. - * - * @return The quality_score_standard_deviation - */ - public final BigDecimal getQualityScoreStandardDeviation() { - return this.qualityScoreStandardDeviation; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The start_date. - * - * @return The start_date - */ - public final DateTime getStartDate() { - return this.startDate; - } - - /** - * Returns The The status. - * - * @return The status - */ - public final FeedbackSummary.Status getStatus() { - return this.status; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - FeedbackSummary other = (FeedbackSummary) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(callCount, other.callCount) && - Objects.equals(callFeedbackCount, other.callFeedbackCount) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(endDate, other.endDate) && - Objects.equals(includeSubaccounts, other.includeSubaccounts) && - Objects.equals(issues, other.issues) && - Objects.equals(qualityScoreAverage, other.qualityScoreAverage) && - Objects.equals(qualityScoreMedian, other.qualityScoreMedian) && - Objects.equals(qualityScoreStandardDeviation, other.qualityScoreStandardDeviation) && - Objects.equals(sid, other.sid) && - Objects.equals(startDate, other.startDate) && - Objects.equals(status, other.status); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - callCount, - callFeedbackCount, - dateCreated, - dateUpdated, - endDate, - includeSubaccounts, - issues, - qualityScoreAverage, - qualityScoreMedian, - qualityScoreStandardDeviation, - sid, - startDate, - status); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("callCount", callCount) - .add("callFeedbackCount", callFeedbackCount) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("endDate", endDate) - .add("includeSubaccounts", includeSubaccounts) - .add("issues", issues) - .add("qualityScoreAverage", qualityScoreAverage) - .add("qualityScoreMedian", qualityScoreMedian) - .add("qualityScoreStandardDeviation", qualityScoreStandardDeviation) - .add("sid", sid) - .add("startDate", startDate) - .add("status", status) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryCreator.java deleted file mode 100644 index ee1cd823ae..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryCreator.java +++ /dev/null @@ -1,176 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.twilio.base.Creator; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - -import java.net.URI; - -public class FeedbackSummaryCreator extends Creator { - private String pathAccountSid; - private final LocalDate startDate; - private final LocalDate endDate; - private Boolean includeSubaccounts; - private URI statusCallback; - private HttpMethod statusCallbackMethod; - - /** - * Construct a new FeedbackSummaryCreator. - * - * @param startDate Only include usage that has occurred on or after this date. - * @param endDate Only include usage that has occurred on or before this date. - */ - public FeedbackSummaryCreator(final LocalDate startDate, - final LocalDate endDate) { - this.startDate = startDate; - this.endDate = endDate; - } - - /** - * Construct a new FeedbackSummaryCreator. - * - * @param pathAccountSid The account_sid - * @param startDate Only include usage that has occurred on or after this date. - * @param endDate Only include usage that has occurred on or before this date. - */ - public FeedbackSummaryCreator(final String pathAccountSid, - final LocalDate startDate, - final LocalDate endDate) { - this.pathAccountSid = pathAccountSid; - this.startDate = startDate; - this.endDate = endDate; - } - - /** - * true to include feedback entries for the master account and all subaccounts. - * false to include feedback entries for the specified account. - * IncludeSubaccounts is false by default.. - * - * @param includeSubaccounts true to include feedback entries for the master - * account and all subaccounts. - * @return this - */ - public FeedbackSummaryCreator setIncludeSubaccounts(final Boolean includeSubaccounts) { - this.includeSubaccounts = includeSubaccounts; - return this; - } - - /** - * The URL that Twilio will request when the Feedback Summary is completed.. - * - * @param statusCallback The URL that Twilio will request when the Feedback - * Summary is completed. - * @return this - */ - public FeedbackSummaryCreator setStatusCallback(final URI statusCallback) { - this.statusCallback = statusCallback; - return this; - } - - /** - * The URL that Twilio will request when the Feedback Summary is completed.. - * - * @param statusCallback The URL that Twilio will request when the Feedback - * Summary is completed. - * @return this - */ - public FeedbackSummaryCreator setStatusCallback(final String statusCallback) { - return setStatusCallback(Promoter.uriFromString(statusCallback)); - } - - /** - * The HTTP method Twilio will use to make requests to the StatusCallback URL. - * Either GET or POST.. - * - * @param statusCallbackMethod The HTTP method Twilio will use to make requests - * to the StatusCallback URL. - * @return this - */ - public FeedbackSummaryCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { - this.statusCallbackMethod = statusCallbackMethod; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created FeedbackSummary - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public FeedbackSummary create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.POST, - Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/FeedbackSummary.json", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FeedbackSummary creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return FeedbackSummary.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (startDate != null) { - request.addPostParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); - } - - if (endDate != null) { - request.addPostParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); - } - - if (includeSubaccounts != null) { - request.addPostParam("IncludeSubaccounts", includeSubaccounts.toString()); - } - - if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); - } - - if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryDeleter.java deleted file mode 100644 index f188153236..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryDeleter.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -public class FeedbackSummaryDeleter extends Deleter { - private String pathAccountSid; - private final String pathSid; - - /** - * Construct a new FeedbackSummaryDeleter. - * - * @param pathSid The sid - */ - public FeedbackSummaryDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Construct a new FeedbackSummaryDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public FeedbackSummaryDeleter(final String pathAccountSid, - final String pathSid) { - this.pathAccountSid = pathAccountSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.DELETE, - Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/FeedbackSummary/" + this.pathSid + ".json", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FeedbackSummary delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryFetcher.java deleted file mode 100644 index 1e5d596639..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackSummaryFetcher.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -public class FeedbackSummaryFetcher extends Fetcher { - private String pathAccountSid; - private final String pathSid; - - /** - * Construct a new FeedbackSummaryFetcher. - * - * @param pathSid The sid - */ - public FeedbackSummaryFetcher(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Construct a new FeedbackSummaryFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public FeedbackSummaryFetcher(final String pathAccountSid, - final String pathSid) { - this.pathAccountSid = pathAccountSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched FeedbackSummary - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public FeedbackSummary fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/FeedbackSummary/" + this.pathSid + ".json", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FeedbackSummary fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return FeedbackSummary.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackUpdater.java deleted file mode 100644 index 04eaa520c8..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/FeedbackUpdater.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.twilio.base.Updater; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.List; - -public class FeedbackUpdater extends Updater { - private String pathAccountSid; - private final String pathCallSid; - private final Integer qualityScore; - private List issue; - - /** - * Construct a new FeedbackUpdater. - * - * @param pathCallSid The call_sid - * @param qualityScore An integer from 1 to 5 - */ - public FeedbackUpdater(final String pathCallSid, - final Integer qualityScore) { - this.pathCallSid = pathCallSid; - this.qualityScore = qualityScore; - } - - /** - * Construct a new FeedbackUpdater. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param qualityScore An integer from 1 to 5 - */ - public FeedbackUpdater(final String pathAccountSid, - final String pathCallSid, - final Integer qualityScore) { - this.pathAccountSid = pathAccountSid; - this.pathCallSid = pathCallSid; - this.qualityScore = qualityScore; - } - - /** - * One or more issues experienced during the call. The issues can be: - * `imperfect-audio`, `dropped-call`, `incorrect-caller-id`, `post-dial-delay`, - * `digits-not-captured`, `audio-latency`, or `one-way-audio`.. - * - * @param issue Issues experienced during the call - * @return this - */ - public FeedbackUpdater setIssue(final List issue) { - this.issue = issue; - return this; - } - - /** - * One or more issues experienced during the call. The issues can be: - * `imperfect-audio`, `dropped-call`, `incorrect-caller-id`, `post-dial-delay`, - * `digits-not-captured`, `audio-latency`, or `one-way-audio`.. - * - * @param issue Issues experienced during the call - * @return this - */ - public FeedbackUpdater setIssue(final Feedback.Issues issue) { - return setIssue(Promoter.listOfOne(issue)); - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Feedback - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Feedback update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.POST, - Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Feedback.json", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Feedback update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Feedback.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (qualityScore != null) { - request.addPostParam("QualityScore", qualityScore.toString()); - } - - if (issue != null) { - for (Feedback.Issues prop : issue) { - request.addPostParam("Issue", prop.toString()); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Notification.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Notification.java index 972c020ce5..67a339b296 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Notification.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Notification.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.call; @@ -11,114 +18,67 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Notification extends Resource { - private static final long serialVersionUID = 203437902819777L; - - /** - * Create a NotificationFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param pathSid The sid - * @return NotificationFetcher capable of executing the fetch - */ - public static NotificationFetcher fetcher(final String pathAccountSid, - final String pathCallSid, - final String pathSid) { - return new NotificationFetcher(pathAccountSid, pathCallSid, pathSid); - } - /** - * Create a NotificationFetcher to execute fetch. - * - * @param pathCallSid The call_sid - * @param pathSid The sid - * @return NotificationFetcher capable of executing the fetch - */ - public static NotificationFetcher fetcher(final String pathCallSid, - final String pathSid) { + public static NotificationFetcher fetcher( + final String pathCallSid, + final String pathSid + ) { return new NotificationFetcher(pathCallSid, pathSid); } - /** - * Create a NotificationDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param pathSid The sid - * @return NotificationDeleter capable of executing the delete - */ - public static NotificationDeleter deleter(final String pathAccountSid, - final String pathCallSid, - final String pathSid) { - return new NotificationDeleter(pathAccountSid, pathCallSid, pathSid); + public static NotificationFetcher fetcher( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { + return new NotificationFetcher(pathAccountSid, pathCallSid, pathSid); } - /** - * Create a NotificationDeleter to execute delete. - * - * @param pathCallSid The call_sid - * @param pathSid The sid - * @return NotificationDeleter capable of executing the delete - */ - public static NotificationDeleter deleter(final String pathCallSid, - final String pathSid) { - return new NotificationDeleter(pathCallSid, pathSid); + public static NotificationReader reader(final String pathCallSid) { + return new NotificationReader(pathCallSid); } - /** - * Create a NotificationReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @return NotificationReader capable of executing the read - */ - public static NotificationReader reader(final String pathAccountSid, - final String pathCallSid) { + public static NotificationReader reader( + final String pathAccountSid, + final String pathCallSid + ) { return new NotificationReader(pathAccountSid, pathCallSid); } /** - * Create a NotificationReader to execute read. - * - * @param pathCallSid The call_sid - * @return NotificationReader capable of executing the read - */ - public static NotificationReader reader(final String pathCallSid) { - return new NotificationReader(pathCallSid); - } - - /** - * Converts a JSON String into a Notification object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Notification object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Notification object represented by the provided JSON */ - public static Notification fromJson(final String json, final ObjectMapper objectMapper) { + public static Notification fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -132,12 +92,15 @@ public static Notification fromJson(final String json, final ObjectMapper object /** * Converts a JSON InputStream into a Notification object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Notification object represented by the provided JSON */ - public static Notification fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Notification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -148,67 +111,103 @@ public static Notification fromJson(final InputStream json, final ObjectMapper o } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; + + @Getter private final String callSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String errorCode; + + @Getter private final String log; - private final DateTime messageDate; + + @Getter + private final ZonedDateTime messageDate; + + @Getter private final String messageText; + + @Getter private final URI moreInfo; + + @Getter private final HttpMethod requestMethod; + + @Getter private final URI requestUrl; + + @Getter private final String requestVariables; + + @Getter private final String responseBody; + + @Getter private final String responseHeaders; + + @Getter private final String sid; + + @Getter private final String uri; @JsonCreator - private Notification(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("call_sid") - final String callSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("error_code") - final String errorCode, - @JsonProperty("log") - final String log, - @JsonProperty("message_date") - final String messageDate, - @JsonProperty("message_text") - final String messageText, - @JsonProperty("more_info") - final URI moreInfo, - @JsonProperty("request_method") - final HttpMethod requestMethod, - @JsonProperty("request_url") - final URI requestUrl, - @JsonProperty("request_variables") - final String requestVariables, - @JsonProperty("response_body") - final String responseBody, - @JsonProperty("response_headers") - final String responseHeaders, - @JsonProperty("sid") - final String sid, - @JsonProperty("uri") - final String uri) { + private Notification( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("error_code") final String errorCode, + @JsonProperty("log") final String log, + @JsonProperty("message_date") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime messageDate, + @JsonProperty("message_text") final String messageText, + @JsonProperty("more_info") final URI moreInfo, + @JsonProperty("request_method") final HttpMethod requestMethod, + @JsonProperty("request_url") final URI requestUrl, + @JsonProperty("request_variables") final String requestVariables, + @JsonProperty("response_body") final String responseBody, + @JsonProperty("response_headers") final String responseHeaders, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; this.callSid = callSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.errorCode = errorCode; this.log = log; - this.messageDate = DateConverter.rfc2822DateTimeFromString(messageDate); + this.messageDate = messageDate; this.messageText = messageText; this.moreInfo = moreInfo; this.requestMethod = requestMethod; @@ -220,159 +219,6 @@ private Notification(@JsonProperty("account_sid") this.uri = uri; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The call_sid. - * - * @return The call_sid - */ - public final String getCallSid() { - return this.callSid; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The error_code. - * - * @return The error_code - */ - public final String getErrorCode() { - return this.errorCode; - } - - /** - * Returns The The log. - * - * @return The log - */ - public final String getLog() { - return this.log; - } - - /** - * Returns The The message_date. - * - * @return The message_date - */ - public final DateTime getMessageDate() { - return this.messageDate; - } - - /** - * Returns The The message_text. - * - * @return The message_text - */ - public final String getMessageText() { - return this.messageText; - } - - /** - * Returns The The more_info. - * - * @return The more_info - */ - public final URI getMoreInfo() { - return this.moreInfo; - } - - /** - * Returns The The request_method. - * - * @return The request_method - */ - public final HttpMethod getRequestMethod() { - return this.requestMethod; - } - - /** - * Returns The The request_url. - * - * @return The request_url - */ - public final URI getRequestUrl() { - return this.requestUrl; - } - - /** - * Returns The The request_variables. - * - * @return The request_variables - */ - public final String getRequestVariables() { - return this.requestVariables; - } - - /** - * Returns The The response_body. - * - * @return The response_body - */ - public final String getResponseBody() { - return this.responseBody; - } - - /** - * Returns The The response_headers. - * - * @return The response_headers - */ - public final String getResponseHeaders() { - return this.responseHeaders; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -384,67 +230,47 @@ public boolean equals(final Object o) { } Notification other = (Notification) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(callSid, other.callSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(errorCode, other.errorCode) && - Objects.equals(log, other.log) && - Objects.equals(messageDate, other.messageDate) && - Objects.equals(messageText, other.messageText) && - Objects.equals(moreInfo, other.moreInfo) && - Objects.equals(requestMethod, other.requestMethod) && - Objects.equals(requestUrl, other.requestUrl) && - Objects.equals(requestVariables, other.requestVariables) && - Objects.equals(responseBody, other.responseBody) && - Objects.equals(responseHeaders, other.responseHeaders) && - Objects.equals(sid, other.sid) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(log, other.log) && + Objects.equals(messageDate, other.messageDate) && + Objects.equals(messageText, other.messageText) && + Objects.equals(moreInfo, other.moreInfo) && + Objects.equals(requestMethod, other.requestMethod) && + Objects.equals(requestUrl, other.requestUrl) && + Objects.equals(requestVariables, other.requestVariables) && + Objects.equals(responseBody, other.responseBody) && + Objects.equals(responseHeaders, other.responseHeaders) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - callSid, - dateCreated, - dateUpdated, - errorCode, - log, - messageDate, - messageText, - moreInfo, - requestMethod, - requestUrl, - requestVariables, - responseBody, - responseHeaders, - sid, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("callSid", callSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("errorCode", errorCode) - .add("log", log) - .add("messageDate", messageDate) - .add("messageText", messageText) - .add("moreInfo", moreInfo) - .add("requestMethod", requestMethod) - .add("requestUrl", requestUrl) - .add("requestVariables", requestVariables) - .add("responseBody", responseBody) - .add("responseHeaders", responseHeaders) - .add("sid", sid) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + apiVersion, + callSid, + dateCreated, + dateUpdated, + errorCode, + log, + messageDate, + messageText, + moreInfo, + requestMethod, + requestUrl, + requestVariables, + responseBody, + responseHeaders, + sid, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationDeleter.java deleted file mode 100644 index 7e5aadc5c7..0000000000 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationDeleter.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.api.v2010.account.call; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -public class NotificationDeleter extends Deleter { - private String pathAccountSid; - private final String pathCallSid; - private final String pathSid; - - /** - * Construct a new NotificationDeleter. - * - * @param pathCallSid The call_sid - * @param pathSid The sid - */ - public NotificationDeleter(final String pathCallSid, - final String pathSid) { - this.pathCallSid = pathCallSid; - this.pathSid = pathSid; - } - - /** - * Construct a new NotificationDeleter. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param pathSid The sid - */ - public NotificationDeleter(final String pathAccountSid, - final String pathCallSid, - final String pathSid) { - this.pathAccountSid = pathAccountSid; - this.pathCallSid = pathCallSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.DELETE, - Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Notifications/" + this.pathSid + ".json", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Notification delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationFetcher.java index 160a9b3c0a..c2617c1a08 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,97 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class NotificationFetcher extends Fetcher { + private String pathAccountSid; - private final String pathCallSid; - private final String pathSid; + private String pathCallSid; + private String pathSid; - /** - * Construct a new NotificationFetcher. - * - * @param pathCallSid The call_sid - * @param pathSid The sid - */ - public NotificationFetcher(final String pathCallSid, - final String pathSid) { + public NotificationFetcher(final String pathCallSid, final String pathSid) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - /** - * Construct a new NotificationFetcher. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param pathSid The sid - */ - public NotificationFetcher(final String pathAccountSid, - final String pathCallSid, - final String pathSid) { + public NotificationFetcher( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Notification - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Notification fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Notifications/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Notification fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Notification.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Notification fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Notification content = Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationReader.java b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationReader.java index 0260dd049b..bf546c3db2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/NotificationReader.java @@ -1,234 +1,267 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.call; -import com.google.common.collect.Range; import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class NotificationReader extends Reader { + private String pathAccountSid; - private final String pathCallSid; + private String pathCallSid; private Integer log; - private LocalDate absoluteMessageDate; - private Range rangeMessageDate; - - /** - * Construct a new NotificationReader. - * - * @param pathCallSid The call_sid - */ + private LocalDate messageDate; + private LocalDate messageDateBefore; + private LocalDate messageDateAfter; + private Long pageSize; + public NotificationReader(final String pathCallSid) { this.pathCallSid = pathCallSid; } - /** - * Construct a new NotificationReader. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - */ - public NotificationReader(final String pathAccountSid, - final String pathCallSid) { + public NotificationReader( + final String pathAccountSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - /** - * The log. - * - * @param log The log - * @return this - */ public NotificationReader setLog(final Integer log) { this.log = log; return this; } - /** - * The absolute_message_date. - * - * @param absoluteMessageDate The absolute_message_date - * @return this - */ - public NotificationReader setMessageDate(final LocalDate absoluteMessageDate) { - this.rangeMessageDate = null; - this.absoluteMessageDate = absoluteMessageDate; + public NotificationReader setMessageDate(final LocalDate messageDate) { + this.messageDate = messageDate; return this; } - /** - * The range_message_date. - * - * @param rangeMessageDate The range_message_date - * @return this - */ - public NotificationReader setMessageDate(final Range rangeMessageDate) { - this.absoluteMessageDate = null; - this.rangeMessageDate = rangeMessageDate; + public NotificationReader setMessageDateBefore( + final LocalDate messageDateBefore + ) { + this.messageDateBefore = messageDateBefore; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Notification ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public NotificationReader setMessageDateAfter( + final LocalDate messageDateAfter + ) { + this.messageDateAfter = messageDateAfter; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Notification ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public NotificationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "notifications", + response.getContent(), + Notification.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Notifications.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Notifications.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Notification ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "notifications", + response.getContent(), + Notification.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Notification read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "notifications", + response.getContent(), + Notification.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Notification Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Notification read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "notifications", - response.getContent(), - Notification.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (log != null) { - request.addQueryParam("Log", log.toString()); + Serializer.toString(request, "Log", log, ParameterType.QUERY); } - if (absoluteMessageDate != null) { - request.addQueryParam("MessageDate", absoluteMessageDate.toString(Request.QUERY_STRING_DATE_FORMAT)); - } else if (rangeMessageDate != null) { - request.addQueryDateRange("MessageDate", rangeMessageDate); + Serializer.toString( + request, + "MessageDate", + messageDate, + messageDateBefore, + messageDateAfter + ); + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Payment.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Payment.java new file mode 100644 index 0000000000..f3352dc0c3 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Payment.java @@ -0,0 +1,360 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Payment extends Resource { + + public static PaymentCreator creator( + final String pathCallSid, + final String idempotencyKey, + final URI statusCallback + ) { + return new PaymentCreator(pathCallSid, idempotencyKey, statusCallback); + } + + public static PaymentCreator creator( + final String pathAccountSid, + final String pathCallSid, + final String idempotencyKey, + final URI statusCallback + ) { + return new PaymentCreator( + pathAccountSid, + pathCallSid, + idempotencyKey, + statusCallback + ); + } + + public static PaymentUpdater updater( + final String pathCallSid, + final String pathSid, + final String idempotencyKey, + final URI statusCallback + ) { + return new PaymentUpdater( + pathCallSid, + pathSid, + idempotencyKey, + statusCallback + ); + } + + public static PaymentUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final String idempotencyKey, + final URI statusCallback + ) { + return new PaymentUpdater( + pathAccountSid, + pathCallSid, + pathSid, + idempotencyKey, + statusCallback + ); + } + + public enum Status { + COMPLETE("complete"), + CANCEL("cancel"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum TokenType { + ONE_TIME("one-time"), + REUSABLE("reusable"), + PAYMENT_METHOD("payment-method"); + + private final String value; + + private TokenType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TokenType forValue(final String value) { + return Promoter.enumFromString(value, TokenType.values()); + } + } + + public enum BankAccountType { + CONSUMER_CHECKING("consumer-checking"), + CONSUMER_SAVINGS("consumer-savings"), + COMMERCIAL_CHECKING("commercial-checking"); + + private final String value; + + private BankAccountType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BankAccountType forValue(final String value) { + return Promoter.enumFromString(value, BankAccountType.values()); + } + } + + public enum PaymentMethod { + CREDIT_CARD("credit-card"), + ACH_DEBIT("ach-debit"); + + private final String value; + + private PaymentMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static PaymentMethod forValue(final String value) { + return Promoter.enumFromString(value, PaymentMethod.values()); + } + } + + public enum Confirmation { + TRUE("true"), + FALSE("false"); + + private final String value; + + private Confirmation(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Confirmation forValue(final String value) { + return Promoter.enumFromString(value, Confirmation.values()); + } + } + + public enum Capture { + PAYMENT_CARD_NUMBER("payment-card-number"), + EXPIRATION_DATE("expiration-date"), + SECURITY_CODE("security-code"), + POSTAL_CODE("postal-code"), + BANK_ROUTING_NUMBER("bank-routing-number"), + BANK_ACCOUNT_NUMBER("bank-account-number"), + PAYMENT_CARD_NUMBER_MATCHER("payment-card-number-matcher"), + EXPIRATION_DATE_MATCHER("expiration-date-matcher"), + SECURITY_CODE_MATCHER("security-code-matcher"), + POSTAL_CODE_MATCHER("postal-code-matcher"); + + private final String value; + + private Capture(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Capture forValue(final String value) { + return Promoter.enumFromString(value, Capture.values()); + } + } + + /** + * Converts a JSON String into a Payment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Payment object represented by the provided JSON + */ + public static Payment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Payment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Payment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Payment object represented by the provided JSON + */ + public static Payment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Payment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final String uri; + + @JsonCreator + private Payment( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.sid = sid; + this.uri = uri; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Payment other = (Payment) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + callSid, + dateCreated, + dateUpdated, + sid, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentCreator.java new file mode 100644 index 0000000000..46e2c11a91 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentCreator.java @@ -0,0 +1,417 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.util.Currency; + +public class PaymentCreator extends Creator { + + private String pathAccountSid; + private String pathCallSid; + private String idempotencyKey; + private URI statusCallback; + private Payment.BankAccountType bankAccountType; + private BigDecimal chargeAmount; + private String currency; + private String description; + private String input; + private Integer minPostalCodeLength; + private Object parameter; + private String paymentConnector; + private Payment.PaymentMethod paymentMethod; + private Boolean postalCode; + private Boolean securityCode; + private Integer timeout; + private Payment.TokenType tokenType; + private String validCardTypes; + private String requireMatchingInputs; + private Payment.Confirmation confirmation; + + public PaymentCreator( + final String pathCallSid, + final String idempotencyKey, + final URI statusCallback + ) { + this.pathCallSid = pathCallSid; + this.idempotencyKey = idempotencyKey; + this.statusCallback = statusCallback; + } + + public PaymentCreator( + final String pathAccountSid, + final String pathCallSid, + final String idempotencyKey, + final URI statusCallback + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.idempotencyKey = idempotencyKey; + this.statusCallback = statusCallback; + } + + public PaymentCreator setIdempotencyKey(final String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + return this; + } + + public PaymentCreator setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public PaymentCreator setStatusCallback(final String statusCallback) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + public PaymentCreator setBankAccountType( + final Payment.BankAccountType bankAccountType + ) { + this.bankAccountType = bankAccountType; + return this; + } + + public PaymentCreator setChargeAmount(final BigDecimal chargeAmount) { + this.chargeAmount = chargeAmount; + return this; + } + + public PaymentCreator setCurrency(final String currency) { + this.currency = currency; + return this; + } + + public PaymentCreator setDescription(final String description) { + this.description = description; + return this; + } + + public PaymentCreator setInput(final String input) { + this.input = input; + return this; + } + + public PaymentCreator setMinPostalCodeLength( + final Integer minPostalCodeLength + ) { + this.minPostalCodeLength = minPostalCodeLength; + return this; + } + + public PaymentCreator setParameter(final Object parameter) { + this.parameter = parameter; + return this; + } + + public PaymentCreator setPaymentConnector(final String paymentConnector) { + this.paymentConnector = paymentConnector; + return this; + } + + public PaymentCreator setPaymentMethod( + final Payment.PaymentMethod paymentMethod + ) { + this.paymentMethod = paymentMethod; + return this; + } + + public PaymentCreator setPostalCode(final Boolean postalCode) { + this.postalCode = postalCode; + return this; + } + + public PaymentCreator setSecurityCode(final Boolean securityCode) { + this.securityCode = securityCode; + return this; + } + + public PaymentCreator setTimeout(final Integer timeout) { + this.timeout = timeout; + return this; + } + + public PaymentCreator setTokenType(final Payment.TokenType tokenType) { + this.tokenType = tokenType; + return this; + } + + public PaymentCreator setValidCardTypes(final String validCardTypes) { + this.validCardTypes = validCardTypes; + return this; + } + + public PaymentCreator setRequireMatchingInputs( + final String requireMatchingInputs + ) { + this.requireMatchingInputs = requireMatchingInputs; + return this; + } + + public PaymentCreator setConfirmation( + final Payment.Confirmation confirmation + ) { + this.confirmation = confirmation; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Payment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Payment create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Payment.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Payment content = Payment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (idempotencyKey != null) { + Serializer.toString( + request, + "IdempotencyKey", + idempotencyKey, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + + if (bankAccountType != null) { + Serializer.toString( + request, + "BankAccountType", + bankAccountType, + ParameterType.URLENCODED + ); + } + + if (chargeAmount != null) { + Serializer.toString( + request, + "ChargeAmount", + chargeAmount, + ParameterType.URLENCODED + ); + } + + if (currency != null) { + Serializer.toString( + request, + "Currency", + currency, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (input != null) { + Serializer.toString( + request, + "Input", + input, + ParameterType.URLENCODED + ); + } + + if (minPostalCodeLength != null) { + Serializer.toString( + request, + "MinPostalCodeLength", + minPostalCodeLength, + ParameterType.URLENCODED + ); + } + + if (parameter != null) { + Serializer.toString( + request, + "Parameter", + parameter, + ParameterType.URLENCODED + ); + } + + if (paymentConnector != null) { + Serializer.toString( + request, + "PaymentConnector", + paymentConnector, + ParameterType.URLENCODED + ); + } + + if (paymentMethod != null) { + Serializer.toString( + request, + "PaymentMethod", + paymentMethod, + ParameterType.URLENCODED + ); + } + + if (postalCode != null) { + Serializer.toString( + request, + "PostalCode", + postalCode, + ParameterType.URLENCODED + ); + } + + if (securityCode != null) { + Serializer.toString( + request, + "SecurityCode", + securityCode, + ParameterType.URLENCODED + ); + } + + if (timeout != null) { + Serializer.toString( + request, + "Timeout", + timeout, + ParameterType.URLENCODED + ); + } + + if (tokenType != null) { + Serializer.toString( + request, + "TokenType", + tokenType, + ParameterType.URLENCODED + ); + } + + if (validCardTypes != null) { + Serializer.toString( + request, + "ValidCardTypes", + validCardTypes, + ParameterType.URLENCODED + ); + } + + if (requireMatchingInputs != null) { + Serializer.toString( + request, + "RequireMatchingInputs", + requireMatchingInputs, + ParameterType.URLENCODED + ); + } + + if (confirmation != null) { + Serializer.toString( + request, + "Confirmation", + confirmation, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentUpdater.java new file mode 100644 index 0000000000..7072a02685 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/PaymentUpdater.java @@ -0,0 +1,201 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class PaymentUpdater extends Updater { + + private String pathAccountSid; + private String pathCallSid; + private String pathSid; + private String idempotencyKey; + private URI statusCallback; + private Payment.Capture capture; + private Payment.Status status; + + public PaymentUpdater( + final String pathCallSid, + final String pathSid, + final String idempotencyKey, + final URI statusCallback + ) { + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.idempotencyKey = idempotencyKey; + this.statusCallback = statusCallback; + } + + public PaymentUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final String idempotencyKey, + final URI statusCallback + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.idempotencyKey = idempotencyKey; + this.statusCallback = statusCallback; + } + + public PaymentUpdater setIdempotencyKey(final String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + return this; + } + + public PaymentUpdater setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public PaymentUpdater setStatusCallback(final String statusCallback) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + public PaymentUpdater setCapture(final Payment.Capture capture) { + this.capture = capture; + return this; + } + + public PaymentUpdater setStatus(final Payment.Status status) { + this.status = status; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Payments/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Payment update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Payment update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Payment.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Payment content = Payment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (idempotencyKey != null) { + Serializer.toString( + request, + "IdempotencyKey", + idempotencyKey, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + + if (capture != null) { + Serializer.toString( + request, + "Capture", + capture, + ParameterType.URLENCODED + ); + } + + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Recording.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Recording.java index b81a6a5653..5837760ce1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/Recording.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Recording.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.call; @@ -10,35 +17,106 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; +import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.ZonedDateTime; import java.util.Currency; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Recording extends Resource { - private static final long serialVersionUID = 231172714460621L; + + public static RecordingCreator creator(final String pathCallSid) { + return new RecordingCreator(pathCallSid); + } + + public static RecordingCreator creator( + final String pathAccountSid, + final String pathCallSid + ) { + return new RecordingCreator(pathAccountSid, pathCallSid); + } + + public static RecordingDeleter deleter( + final String pathCallSid, + final String pathSid + ) { + return new RecordingDeleter(pathCallSid, pathSid); + } + + public static RecordingDeleter deleter( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { + return new RecordingDeleter(pathAccountSid, pathCallSid, pathSid); + } + + public static RecordingFetcher fetcher( + final String pathCallSid, + final String pathSid + ) { + return new RecordingFetcher(pathCallSid, pathSid); + } + + public static RecordingFetcher fetcher( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { + return new RecordingFetcher(pathAccountSid, pathCallSid, pathSid); + } + + public static RecordingReader reader(final String pathCallSid) { + return new RecordingReader(pathCallSid); + } + + public static RecordingReader reader( + final String pathAccountSid, + final String pathCallSid + ) { + return new RecordingReader(pathAccountSid, pathCallSid); + } + + public static RecordingUpdater updater( + final String pathCallSid, + final String pathSid, + final Recording.Status status + ) { + return new RecordingUpdater(pathCallSid, pathSid, status); + } + + public static RecordingUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Recording.Status status + ) { + return new RecordingUpdater( + pathAccountSid, + pathCallSid, + pathSid, + status + ); + } public enum Status { IN_PROGRESS("in-progress"), @@ -46,7 +124,7 @@ public enum Status { STOPPED("stopped"), PROCESSING("processing"), COMPLETED("completed"), - FAILED("failed"); + ABSENT("absent"); private final String value; @@ -54,15 +132,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -70,13 +144,13 @@ public static Status forValue(final String value) { } public enum Source { - DIALVERB("DialVerb"), + DIAL_VERB("DialVerb"), CONFERENCE("Conference"), - OUTBOUNDAPI("OutboundAPI"), + OUTBOUND_API("OutboundAPI"), TRUNKING("Trunking"), - RECORDVERB("RecordVerb"), - STARTCALLRECORDINGAPI("StartCallRecordingAPI"), - STARTCONFERENCERECORDINGAPI("StartConferenceRecordingAPI"); + RECORD_VERB("RecordVerb"), + START_CALL_RECORDING_API("StartCallRecordingAPI"), + START_CONFERENCE_RECORDING_API("StartConferenceRecordingAPI"); private final String value; @@ -84,15 +158,11 @@ private Source(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Source from a string. - * @param value string value - * @return generated Source - */ @JsonCreator public static Source forValue(final String value) { return Promoter.enumFromString(value, Source.values()); @@ -100,88 +170,16 @@ public static Source forValue(final String value) { } /** - * Create a RecordingFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param pathSid The sid - * @return RecordingFetcher capable of executing the fetch - */ - public static RecordingFetcher fetcher(final String pathAccountSid, - final String pathCallSid, - final String pathSid) { - return new RecordingFetcher(pathAccountSid, pathCallSid, pathSid); - } - - /** - * Create a RecordingFetcher to execute fetch. - * - * @param pathCallSid The call_sid - * @param pathSid The sid - * @return RecordingFetcher capable of executing the fetch - */ - public static RecordingFetcher fetcher(final String pathCallSid, - final String pathSid) { - return new RecordingFetcher(pathCallSid, pathSid); - } - - /** - * Create a RecordingDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param pathSid The sid - * @return RecordingDeleter capable of executing the delete - */ - public static RecordingDeleter deleter(final String pathAccountSid, - final String pathCallSid, - final String pathSid) { - return new RecordingDeleter(pathAccountSid, pathCallSid, pathSid); - } - - /** - * Create a RecordingDeleter to execute delete. - * - * @param pathCallSid The call_sid - * @param pathSid The sid - * @return RecordingDeleter capable of executing the delete - */ - public static RecordingDeleter deleter(final String pathCallSid, - final String pathSid) { - return new RecordingDeleter(pathCallSid, pathSid); - } - - /** - * Create a RecordingReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @return RecordingReader capable of executing the read - */ - public static RecordingReader reader(final String pathAccountSid, - final String pathCallSid) { - return new RecordingReader(pathAccountSid, pathCallSid); - } - - /** - * Create a RecordingReader to execute read. - * - * @param pathCallSid The call_sid - * @return RecordingReader capable of executing the read - */ - public static RecordingReader reader(final String pathCallSid) { - return new RecordingReader(pathCallSid); - } - - /** - * Converts a JSON String into a Recording object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Recording object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Recording object represented by the provided JSON */ - public static Recording fromJson(final String json, final ObjectMapper objectMapper) { + public static Recording fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -195,12 +193,15 @@ public static Recording fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a Recording object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Recording object represented by the provided JSON */ - public static Recording fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Recording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Recording.class); @@ -211,217 +212,119 @@ public static Recording fromJson(final InputStream json, final ObjectMapper obje } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final String callSid; - private final String conferenceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String duration; - private final String sid; - private final BigDecimal price; - private final String uri; - private final Map encryptionDetails; - private final Currency priceUnit; - private final Recording.Status status; - private final Integer channels; - private final Recording.Source source; - private final Integer errorCode; - @JsonCreator - private Recording(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("call_sid") - final String callSid, - @JsonProperty("conference_sid") - final String conferenceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("duration") - final String duration, - @JsonProperty("sid") - final String sid, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("uri") - final String uri, - @JsonProperty("encryption_details") - final Map encryptionDetails, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("status") - final Recording.Status status, - @JsonProperty("channels") - final Integer channels, - @JsonProperty("source") - final Recording.Source source, - @JsonProperty("error_code") - final Integer errorCode) { - this.accountSid = accountSid; - this.apiVersion = apiVersion; - this.callSid = callSid; - this.conferenceSid = conferenceSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.duration = duration; - this.sid = sid; - this.price = price; - this.uri = uri; - this.encryptionDetails = encryptionDetails; - this.priceUnit = priceUnit; - this.status = status; - this.channels = channels; - this.source = source; - this.errorCode = errorCode; - } + @Getter + private final String callSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Integer channels; - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } + @Getter + private final String conferenceSid; - /** - * Returns The The call_sid. - * - * @return The call_sid - */ - public final String getCallSid() { - return this.callSid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The conference_sid. - * - * @return The conference_sid - */ - public final String getConferenceSid() { - return this.conferenceSid; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String duration; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Object encryptionDetails; - /** - * Returns The The duration. - * - * @return The duration - */ - public final String getDuration() { - return this.duration; - } + @Getter + private final Integer errorCode; - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final BigDecimal price; - /** - * Returns The The price. - * - * @return The price - */ - public final BigDecimal getPrice() { - return this.price; - } + @Getter + private final Currency priceUnit; - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; - } + @Getter + private final String sid; - /** - * Returns The The encryption_details. - * - * @return The encryption_details - */ - public final Map getEncryptionDetails() { - return this.encryptionDetails; - } + @Getter + private final Recording.Source source; - /** - * Returns The The price_unit. - * - * @return The price_unit - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } + @Getter + private final ZonedDateTime startTime; - /** - * Returns The The status. - * - * @return The status - */ - public final Recording.Status getStatus() { - return this.status; - } + @Getter + private final Recording.Status status; - /** - * Returns The The channels. - * - * @return The channels - */ - public final Integer getChannels() { - return this.channels; - } + @Getter + private final String track; - /** - * Returns The The source. - * - * @return The source - */ - public final Recording.Source getSource() { - return this.source; - } + @Getter + private final String uri; - /** - * Returns The The error_code. - * - * @return The error_code - */ - public final Integer getErrorCode() { - return this.errorCode; + @JsonCreator + private Recording( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("channels") final Integer channels, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("duration") final String duration, + @JsonProperty("encryption_details") final Object encryptionDetails, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("sid") final String sid, + @JsonProperty("source") final Recording.Source source, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime startTime, + @JsonProperty("status") final Recording.Status status, + @JsonProperty("track") final String track, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.apiVersion = apiVersion; + this.callSid = callSid; + this.channels = channels; + this.conferenceSid = conferenceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.duration = duration; + this.encryptionDetails = encryptionDetails; + this.errorCode = errorCode; + this.price = price; + this.priceUnit = priceUnit; + this.sid = sid; + this.source = source; + this.startTime = startTime; + this.status = status; + this.track = track; + this.uri = uri; } @Override @@ -435,64 +338,49 @@ public boolean equals(final Object o) { } Recording other = (Recording) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(callSid, other.callSid) && - Objects.equals(conferenceSid, other.conferenceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(duration, other.duration) && - Objects.equals(sid, other.sid) && - Objects.equals(price, other.price) && - Objects.equals(uri, other.uri) && - Objects.equals(encryptionDetails, other.encryptionDetails) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(status, other.status) && - Objects.equals(channels, other.channels) && - Objects.equals(source, other.source) && - Objects.equals(errorCode, other.errorCode); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(channels, other.channels) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals(encryptionDetails, other.encryptionDetails) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(sid, other.sid) && + Objects.equals(source, other.source) && + Objects.equals(startTime, other.startTime) && + Objects.equals(status, other.status) && + Objects.equals(track, other.track) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - callSid, - conferenceSid, - dateCreated, - dateUpdated, - duration, - sid, - price, - uri, - encryptionDetails, - priceUnit, - status, - channels, - source, - errorCode); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("callSid", callSid) - .add("conferenceSid", conferenceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("duration", duration) - .add("sid", sid) - .add("price", price) - .add("uri", uri) - .add("encryptionDetails", encryptionDetails) - .add("priceUnit", priceUnit) - .add("status", status) - .add("channels", channels) - .add("source", source) - .add("errorCode", errorCode) - .toString(); + return Objects.hash( + accountSid, + apiVersion, + callSid, + channels, + conferenceSid, + dateCreated, + dateUpdated, + duration, + encryptionDetails, + errorCode, + price, + priceUnit, + sid, + source, + startTime, + status, + track, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingCreator.java new file mode 100644 index 0000000000..6432c4b34c --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingCreator.java @@ -0,0 +1,258 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; +import java.util.List; + +public class RecordingCreator extends Creator { + + private String pathAccountSid; + private String pathCallSid; + private List recordingStatusCallbackEvent; + private URI recordingStatusCallback; + private HttpMethod recordingStatusCallbackMethod; + private String trim; + private String recordingChannels; + private String recordingTrack; + private String recordingConfigurationId; + + public RecordingCreator(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + public RecordingCreator( + final String pathAccountSid, + final String pathCallSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + } + + public RecordingCreator setRecordingStatusCallbackEvent( + final List recordingStatusCallbackEvent + ) { + this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; + return this; + } + + public RecordingCreator setRecordingStatusCallbackEvent( + final String recordingStatusCallbackEvent + ) { + return setRecordingStatusCallbackEvent( + Promoter.listOfOne(recordingStatusCallbackEvent) + ); + } + + public RecordingCreator setRecordingStatusCallback( + final URI recordingStatusCallback + ) { + this.recordingStatusCallback = recordingStatusCallback; + return this; + } + + public RecordingCreator setRecordingStatusCallback( + final String recordingStatusCallback + ) { + return setRecordingStatusCallback( + Promoter.uriFromString(recordingStatusCallback) + ); + } + + public RecordingCreator setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { + this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; + return this; + } + + public RecordingCreator setTrim(final String trim) { + this.trim = trim; + return this; + } + + public RecordingCreator setRecordingChannels( + final String recordingChannels + ) { + this.recordingChannels = recordingChannels; + return this; + } + + public RecordingCreator setRecordingTrack(final String recordingTrack) { + this.recordingTrack = recordingTrack; + return this; + } + + public RecordingCreator setRecordingConfigurationId( + final String recordingConfigurationId + ) { + this.recordingConfigurationId = recordingConfigurationId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Recording creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Recording create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recording content = Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (recordingStatusCallbackEvent != null) { + for (String param : recordingStatusCallbackEvent) { + Serializer.toString( + request, + "RecordingStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); + } + } + + if (recordingStatusCallback != null) { + Serializer.toString( + request, + "RecordingStatusCallback", + recordingStatusCallback, + ParameterType.URLENCODED + ); + } + + if (recordingStatusCallbackMethod != null) { + Serializer.toString( + request, + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (trim != null) { + Serializer.toString( + request, + "Trim", + trim, + ParameterType.URLENCODED + ); + } + + if (recordingChannels != null) { + Serializer.toString( + request, + "RecordingChannels", + recordingChannels, + ParameterType.URLENCODED + ); + } + + if (recordingTrack != null) { + Serializer.toString( + request, + "RecordingTrack", + recordingTrack, + ParameterType.URLENCODED + ); + } + + if (recordingConfigurationId != null) { + Serializer.toString( + request, + "RecordingConfigurationId", + recordingConfigurationId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingDeleter.java index e4e9509b23..a46e4b2e59 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,98 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class RecordingDeleter extends Deleter { + private String pathAccountSid; - private final String pathCallSid; - private final String pathSid; + private String pathCallSid; + private String pathSid; - /** - * Construct a new RecordingDeleter. - * - * @param pathCallSid The call_sid - * @param pathSid The sid - */ - public RecordingDeleter(final String pathCallSid, - final String pathSid) { + public RecordingDeleter(final String pathCallSid, final String pathSid) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - /** - * Construct a new RecordingDeleter. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param pathSid The sid - */ - public RecordingDeleter(final String pathAccountSid, - final String pathCallSid, - final String pathSid) { + public RecordingDeleter( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Recordings/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Recording delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingFetcher.java index bcd5de83c1..4d40e893c6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.call; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,97 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RecordingFetcher extends Fetcher { + private String pathAccountSid; - private final String pathCallSid; - private final String pathSid; + private String pathCallSid; + private String pathSid; - /** - * Construct a new RecordingFetcher. - * - * @param pathCallSid The call_sid - * @param pathSid The sid - */ - public RecordingFetcher(final String pathCallSid, - final String pathSid) { + public RecordingFetcher(final String pathCallSid, final String pathSid) { this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - /** - * Construct a new RecordingFetcher. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - * @param pathSid The sid - */ - public RecordingFetcher(final String pathAccountSid, - final String pathCallSid, - final String pathSid) { + public RecordingFetcher( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Recording - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Recording fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Recordings/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Recording fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Recording fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Recording.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Recording fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recording content = Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingReader.java index 65eca179db..941948b024 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingReader.java @@ -1,218 +1,257 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.call; -import com.google.common.collect.Range; import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class RecordingReader extends Reader { + private String pathAccountSid; - private final String pathCallSid; - private LocalDate absoluteDateCreated; - private Range rangeDateCreated; - - /** - * Construct a new RecordingReader. - * - * @param pathCallSid The call_sid - */ + private String pathCallSid; + private LocalDate dateCreated; + private LocalDate dateCreatedBefore; + private LocalDate dateCreatedAfter; + private Long pageSize; + public RecordingReader(final String pathCallSid) { this.pathCallSid = pathCallSid; } - /** - * Construct a new RecordingReader. - * - * @param pathAccountSid The account_sid - * @param pathCallSid The call_sid - */ - public RecordingReader(final String pathAccountSid, - final String pathCallSid) { + public RecordingReader( + final String pathAccountSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathCallSid = pathCallSid; } - /** - * The absolute_date_created. - * - * @param absoluteDateCreated The absolute_date_created - * @return this - */ - public RecordingReader setDateCreated(final LocalDate absoluteDateCreated) { - this.rangeDateCreated = null; - this.absoluteDateCreated = absoluteDateCreated; + public RecordingReader setDateCreated(final LocalDate dateCreated) { + this.dateCreated = dateCreated; return this; } - /** - * The range_date_created. - * - * @param rangeDateCreated The range_date_created - * @return this - */ - public RecordingReader setDateCreated(final Range rangeDateCreated) { - this.absoluteDateCreated = null; - this.rangeDateCreated = rangeDateCreated; + public RecordingReader setDateCreatedBefore( + final LocalDate dateCreatedBefore + ) { + this.dateCreatedBefore = dateCreatedBefore; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Recording ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public RecordingReader setDateCreatedAfter( + final LocalDate dateCreatedAfter + ) { + this.dateCreatedAfter = dateCreatedAfter; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Recording ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public RecordingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Calls/" + this.pathCallSid + "/Recordings.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Recording ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Recording read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Recording Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Recording read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "recordings", - response.getContent(), - Recording.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { - if (absoluteDateCreated != null) { - request.addQueryParam("DateCreated", absoluteDateCreated.toString(Request.QUERY_STRING_DATE_FORMAT)); - } else if (rangeDateCreated != null) { - request.addQueryDateRange("DateCreated", rangeDateCreated); + Serializer.toString( + request, + "DateCreated", + dateCreated, + dateCreatedBefore, + dateCreatedAfter + ); + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingUpdater.java new file mode 100644 index 0000000000..81d47b1aa5 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/RecordingUpdater.java @@ -0,0 +1,164 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RecordingUpdater extends Updater { + + private String pathAccountSid; + private String pathCallSid; + private String pathSid; + private Recording.Status status; + private String pauseBehavior; + + public RecordingUpdater( + final String pathCallSid, + final String pathSid, + final Recording.Status status + ) { + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.status = status; + } + + public RecordingUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Recording.Status status + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.status = status; + } + + public RecordingUpdater setStatus(final Recording.Status status) { + this.status = status; + return this; + } + + public RecordingUpdater setPauseBehavior(final String pauseBehavior) { + this.pauseBehavior = pauseBehavior; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Recordings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Recording update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Recording update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recording content = Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (pauseBehavior != null) { + Serializer.toString( + request, + "PauseBehavior", + pauseBehavior, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Siprec.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Siprec.java new file mode 100644 index 0000000000..c937528253 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Siprec.java @@ -0,0 +1,267 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Siprec extends Resource { + + public static SiprecCreator creator(final String pathCallSid) { + return new SiprecCreator(pathCallSid); + } + + public static SiprecCreator creator( + final String pathAccountSid, + final String pathCallSid + ) { + return new SiprecCreator(pathAccountSid, pathCallSid); + } + + public static SiprecUpdater updater( + final String pathCallSid, + final String pathSid, + final Siprec.UpdateStatus status + ) { + return new SiprecUpdater(pathCallSid, pathSid, status); + } + + public static SiprecUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Siprec.UpdateStatus status + ) { + return new SiprecUpdater(pathAccountSid, pathCallSid, pathSid, status); + } + + public enum Status { + IN_PROGRESS("in-progress"), + STOPPED("stopped"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum UpdateStatus { + STOPPED("stopped"); + + private final String value; + + private UpdateStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static UpdateStatus forValue(final String value) { + return Promoter.enumFromString(value, UpdateStatus.values()); + } + } + + public enum Track { + INBOUND_TRACK("inbound_track"), + OUTBOUND_TRACK("outbound_track"), + BOTH_TRACKS("both_tracks"); + + private final String value; + + private Track(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Track forValue(final String value) { + return Promoter.enumFromString(value, Track.values()); + } + } + + /** + * Converts a JSON String into a Siprec object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Siprec object represented by the provided JSON + */ + public static Siprec fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Siprec.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Siprec object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Siprec object represented by the provided JSON + */ + public static Siprec fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Siprec.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String name; + + @Getter + private final String sid; + + @Getter + private final Siprec.Status status; + + @Getter + private final String uri; + + @JsonCreator + private Siprec( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("name") final String name, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Siprec.Status status, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.dateUpdated = dateUpdated; + this.name = name; + this.sid = sid; + this.status = status; + this.uri = uri; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Siprec other = (Siprec) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(name, other.name) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(uri, other.uri) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + callSid, + dateUpdated, + name, + sid, + status, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecCreator.java new file mode 100644 index 0000000000..ff89062bcb --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecCreator.java @@ -0,0 +1,3172 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class SiprecCreator extends Creator { + + private String pathAccountSid; + private String pathCallSid; + private String name; + private String connectorName; + private Siprec.Track track; + private URI statusCallback; + private HttpMethod statusCallbackMethod; + private String parameter1Name; + private String parameter1Value; + private String parameter2Name; + private String parameter2Value; + private String parameter3Name; + private String parameter3Value; + private String parameter4Name; + private String parameter4Value; + private String parameter5Name; + private String parameter5Value; + private String parameter6Name; + private String parameter6Value; + private String parameter7Name; + private String parameter7Value; + private String parameter8Name; + private String parameter8Value; + private String parameter9Name; + private String parameter9Value; + private String parameter10Name; + private String parameter10Value; + private String parameter11Name; + private String parameter11Value; + private String parameter12Name; + private String parameter12Value; + private String parameter13Name; + private String parameter13Value; + private String parameter14Name; + private String parameter14Value; + private String parameter15Name; + private String parameter15Value; + private String parameter16Name; + private String parameter16Value; + private String parameter17Name; + private String parameter17Value; + private String parameter18Name; + private String parameter18Value; + private String parameter19Name; + private String parameter19Value; + private String parameter20Name; + private String parameter20Value; + private String parameter21Name; + private String parameter21Value; + private String parameter22Name; + private String parameter22Value; + private String parameter23Name; + private String parameter23Value; + private String parameter24Name; + private String parameter24Value; + private String parameter25Name; + private String parameter25Value; + private String parameter26Name; + private String parameter26Value; + private String parameter27Name; + private String parameter27Value; + private String parameter28Name; + private String parameter28Value; + private String parameter29Name; + private String parameter29Value; + private String parameter30Name; + private String parameter30Value; + private String parameter31Name; + private String parameter31Value; + private String parameter32Name; + private String parameter32Value; + private String parameter33Name; + private String parameter33Value; + private String parameter34Name; + private String parameter34Value; + private String parameter35Name; + private String parameter35Value; + private String parameter36Name; + private String parameter36Value; + private String parameter37Name; + private String parameter37Value; + private String parameter38Name; + private String parameter38Value; + private String parameter39Name; + private String parameter39Value; + private String parameter40Name; + private String parameter40Value; + private String parameter41Name; + private String parameter41Value; + private String parameter42Name; + private String parameter42Value; + private String parameter43Name; + private String parameter43Value; + private String parameter44Name; + private String parameter44Value; + private String parameter45Name; + private String parameter45Value; + private String parameter46Name; + private String parameter46Value; + private String parameter47Name; + private String parameter47Value; + private String parameter48Name; + private String parameter48Value; + private String parameter49Name; + private String parameter49Value; + private String parameter50Name; + private String parameter50Value; + private String parameter51Name; + private String parameter51Value; + private String parameter52Name; + private String parameter52Value; + private String parameter53Name; + private String parameter53Value; + private String parameter54Name; + private String parameter54Value; + private String parameter55Name; + private String parameter55Value; + private String parameter56Name; + private String parameter56Value; + private String parameter57Name; + private String parameter57Value; + private String parameter58Name; + private String parameter58Value; + private String parameter59Name; + private String parameter59Value; + private String parameter60Name; + private String parameter60Value; + private String parameter61Name; + private String parameter61Value; + private String parameter62Name; + private String parameter62Value; + private String parameter63Name; + private String parameter63Value; + private String parameter64Name; + private String parameter64Value; + private String parameter65Name; + private String parameter65Value; + private String parameter66Name; + private String parameter66Value; + private String parameter67Name; + private String parameter67Value; + private String parameter68Name; + private String parameter68Value; + private String parameter69Name; + private String parameter69Value; + private String parameter70Name; + private String parameter70Value; + private String parameter71Name; + private String parameter71Value; + private String parameter72Name; + private String parameter72Value; + private String parameter73Name; + private String parameter73Value; + private String parameter74Name; + private String parameter74Value; + private String parameter75Name; + private String parameter75Value; + private String parameter76Name; + private String parameter76Value; + private String parameter77Name; + private String parameter77Value; + private String parameter78Name; + private String parameter78Value; + private String parameter79Name; + private String parameter79Value; + private String parameter80Name; + private String parameter80Value; + private String parameter81Name; + private String parameter81Value; + private String parameter82Name; + private String parameter82Value; + private String parameter83Name; + private String parameter83Value; + private String parameter84Name; + private String parameter84Value; + private String parameter85Name; + private String parameter85Value; + private String parameter86Name; + private String parameter86Value; + private String parameter87Name; + private String parameter87Value; + private String parameter88Name; + private String parameter88Value; + private String parameter89Name; + private String parameter89Value; + private String parameter90Name; + private String parameter90Value; + private String parameter91Name; + private String parameter91Value; + private String parameter92Name; + private String parameter92Value; + private String parameter93Name; + private String parameter93Value; + private String parameter94Name; + private String parameter94Value; + private String parameter95Name; + private String parameter95Value; + private String parameter96Name; + private String parameter96Value; + private String parameter97Name; + private String parameter97Value; + private String parameter98Name; + private String parameter98Value; + private String parameter99Name; + private String parameter99Value; + + public SiprecCreator(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + public SiprecCreator( + final String pathAccountSid, + final String pathCallSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + } + + public SiprecCreator setName(final String name) { + this.name = name; + return this; + } + + public SiprecCreator setConnectorName(final String connectorName) { + this.connectorName = connectorName; + return this; + } + + public SiprecCreator setTrack(final Siprec.Track track) { + this.track = track; + return this; + } + + public SiprecCreator setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public SiprecCreator setStatusCallback(final String statusCallback) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + public SiprecCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + public SiprecCreator setParameter1Name(final String parameter1Name) { + this.parameter1Name = parameter1Name; + return this; + } + + public SiprecCreator setParameter1Value(final String parameter1Value) { + this.parameter1Value = parameter1Value; + return this; + } + + public SiprecCreator setParameter2Name(final String parameter2Name) { + this.parameter2Name = parameter2Name; + return this; + } + + public SiprecCreator setParameter2Value(final String parameter2Value) { + this.parameter2Value = parameter2Value; + return this; + } + + public SiprecCreator setParameter3Name(final String parameter3Name) { + this.parameter3Name = parameter3Name; + return this; + } + + public SiprecCreator setParameter3Value(final String parameter3Value) { + this.parameter3Value = parameter3Value; + return this; + } + + public SiprecCreator setParameter4Name(final String parameter4Name) { + this.parameter4Name = parameter4Name; + return this; + } + + public SiprecCreator setParameter4Value(final String parameter4Value) { + this.parameter4Value = parameter4Value; + return this; + } + + public SiprecCreator setParameter5Name(final String parameter5Name) { + this.parameter5Name = parameter5Name; + return this; + } + + public SiprecCreator setParameter5Value(final String parameter5Value) { + this.parameter5Value = parameter5Value; + return this; + } + + public SiprecCreator setParameter6Name(final String parameter6Name) { + this.parameter6Name = parameter6Name; + return this; + } + + public SiprecCreator setParameter6Value(final String parameter6Value) { + this.parameter6Value = parameter6Value; + return this; + } + + public SiprecCreator setParameter7Name(final String parameter7Name) { + this.parameter7Name = parameter7Name; + return this; + } + + public SiprecCreator setParameter7Value(final String parameter7Value) { + this.parameter7Value = parameter7Value; + return this; + } + + public SiprecCreator setParameter8Name(final String parameter8Name) { + this.parameter8Name = parameter8Name; + return this; + } + + public SiprecCreator setParameter8Value(final String parameter8Value) { + this.parameter8Value = parameter8Value; + return this; + } + + public SiprecCreator setParameter9Name(final String parameter9Name) { + this.parameter9Name = parameter9Name; + return this; + } + + public SiprecCreator setParameter9Value(final String parameter9Value) { + this.parameter9Value = parameter9Value; + return this; + } + + public SiprecCreator setParameter10Name(final String parameter10Name) { + this.parameter10Name = parameter10Name; + return this; + } + + public SiprecCreator setParameter10Value(final String parameter10Value) { + this.parameter10Value = parameter10Value; + return this; + } + + public SiprecCreator setParameter11Name(final String parameter11Name) { + this.parameter11Name = parameter11Name; + return this; + } + + public SiprecCreator setParameter11Value(final String parameter11Value) { + this.parameter11Value = parameter11Value; + return this; + } + + public SiprecCreator setParameter12Name(final String parameter12Name) { + this.parameter12Name = parameter12Name; + return this; + } + + public SiprecCreator setParameter12Value(final String parameter12Value) { + this.parameter12Value = parameter12Value; + return this; + } + + public SiprecCreator setParameter13Name(final String parameter13Name) { + this.parameter13Name = parameter13Name; + return this; + } + + public SiprecCreator setParameter13Value(final String parameter13Value) { + this.parameter13Value = parameter13Value; + return this; + } + + public SiprecCreator setParameter14Name(final String parameter14Name) { + this.parameter14Name = parameter14Name; + return this; + } + + public SiprecCreator setParameter14Value(final String parameter14Value) { + this.parameter14Value = parameter14Value; + return this; + } + + public SiprecCreator setParameter15Name(final String parameter15Name) { + this.parameter15Name = parameter15Name; + return this; + } + + public SiprecCreator setParameter15Value(final String parameter15Value) { + this.parameter15Value = parameter15Value; + return this; + } + + public SiprecCreator setParameter16Name(final String parameter16Name) { + this.parameter16Name = parameter16Name; + return this; + } + + public SiprecCreator setParameter16Value(final String parameter16Value) { + this.parameter16Value = parameter16Value; + return this; + } + + public SiprecCreator setParameter17Name(final String parameter17Name) { + this.parameter17Name = parameter17Name; + return this; + } + + public SiprecCreator setParameter17Value(final String parameter17Value) { + this.parameter17Value = parameter17Value; + return this; + } + + public SiprecCreator setParameter18Name(final String parameter18Name) { + this.parameter18Name = parameter18Name; + return this; + } + + public SiprecCreator setParameter18Value(final String parameter18Value) { + this.parameter18Value = parameter18Value; + return this; + } + + public SiprecCreator setParameter19Name(final String parameter19Name) { + this.parameter19Name = parameter19Name; + return this; + } + + public SiprecCreator setParameter19Value(final String parameter19Value) { + this.parameter19Value = parameter19Value; + return this; + } + + public SiprecCreator setParameter20Name(final String parameter20Name) { + this.parameter20Name = parameter20Name; + return this; + } + + public SiprecCreator setParameter20Value(final String parameter20Value) { + this.parameter20Value = parameter20Value; + return this; + } + + public SiprecCreator setParameter21Name(final String parameter21Name) { + this.parameter21Name = parameter21Name; + return this; + } + + public SiprecCreator setParameter21Value(final String parameter21Value) { + this.parameter21Value = parameter21Value; + return this; + } + + public SiprecCreator setParameter22Name(final String parameter22Name) { + this.parameter22Name = parameter22Name; + return this; + } + + public SiprecCreator setParameter22Value(final String parameter22Value) { + this.parameter22Value = parameter22Value; + return this; + } + + public SiprecCreator setParameter23Name(final String parameter23Name) { + this.parameter23Name = parameter23Name; + return this; + } + + public SiprecCreator setParameter23Value(final String parameter23Value) { + this.parameter23Value = parameter23Value; + return this; + } + + public SiprecCreator setParameter24Name(final String parameter24Name) { + this.parameter24Name = parameter24Name; + return this; + } + + public SiprecCreator setParameter24Value(final String parameter24Value) { + this.parameter24Value = parameter24Value; + return this; + } + + public SiprecCreator setParameter25Name(final String parameter25Name) { + this.parameter25Name = parameter25Name; + return this; + } + + public SiprecCreator setParameter25Value(final String parameter25Value) { + this.parameter25Value = parameter25Value; + return this; + } + + public SiprecCreator setParameter26Name(final String parameter26Name) { + this.parameter26Name = parameter26Name; + return this; + } + + public SiprecCreator setParameter26Value(final String parameter26Value) { + this.parameter26Value = parameter26Value; + return this; + } + + public SiprecCreator setParameter27Name(final String parameter27Name) { + this.parameter27Name = parameter27Name; + return this; + } + + public SiprecCreator setParameter27Value(final String parameter27Value) { + this.parameter27Value = parameter27Value; + return this; + } + + public SiprecCreator setParameter28Name(final String parameter28Name) { + this.parameter28Name = parameter28Name; + return this; + } + + public SiprecCreator setParameter28Value(final String parameter28Value) { + this.parameter28Value = parameter28Value; + return this; + } + + public SiprecCreator setParameter29Name(final String parameter29Name) { + this.parameter29Name = parameter29Name; + return this; + } + + public SiprecCreator setParameter29Value(final String parameter29Value) { + this.parameter29Value = parameter29Value; + return this; + } + + public SiprecCreator setParameter30Name(final String parameter30Name) { + this.parameter30Name = parameter30Name; + return this; + } + + public SiprecCreator setParameter30Value(final String parameter30Value) { + this.parameter30Value = parameter30Value; + return this; + } + + public SiprecCreator setParameter31Name(final String parameter31Name) { + this.parameter31Name = parameter31Name; + return this; + } + + public SiprecCreator setParameter31Value(final String parameter31Value) { + this.parameter31Value = parameter31Value; + return this; + } + + public SiprecCreator setParameter32Name(final String parameter32Name) { + this.parameter32Name = parameter32Name; + return this; + } + + public SiprecCreator setParameter32Value(final String parameter32Value) { + this.parameter32Value = parameter32Value; + return this; + } + + public SiprecCreator setParameter33Name(final String parameter33Name) { + this.parameter33Name = parameter33Name; + return this; + } + + public SiprecCreator setParameter33Value(final String parameter33Value) { + this.parameter33Value = parameter33Value; + return this; + } + + public SiprecCreator setParameter34Name(final String parameter34Name) { + this.parameter34Name = parameter34Name; + return this; + } + + public SiprecCreator setParameter34Value(final String parameter34Value) { + this.parameter34Value = parameter34Value; + return this; + } + + public SiprecCreator setParameter35Name(final String parameter35Name) { + this.parameter35Name = parameter35Name; + return this; + } + + public SiprecCreator setParameter35Value(final String parameter35Value) { + this.parameter35Value = parameter35Value; + return this; + } + + public SiprecCreator setParameter36Name(final String parameter36Name) { + this.parameter36Name = parameter36Name; + return this; + } + + public SiprecCreator setParameter36Value(final String parameter36Value) { + this.parameter36Value = parameter36Value; + return this; + } + + public SiprecCreator setParameter37Name(final String parameter37Name) { + this.parameter37Name = parameter37Name; + return this; + } + + public SiprecCreator setParameter37Value(final String parameter37Value) { + this.parameter37Value = parameter37Value; + return this; + } + + public SiprecCreator setParameter38Name(final String parameter38Name) { + this.parameter38Name = parameter38Name; + return this; + } + + public SiprecCreator setParameter38Value(final String parameter38Value) { + this.parameter38Value = parameter38Value; + return this; + } + + public SiprecCreator setParameter39Name(final String parameter39Name) { + this.parameter39Name = parameter39Name; + return this; + } + + public SiprecCreator setParameter39Value(final String parameter39Value) { + this.parameter39Value = parameter39Value; + return this; + } + + public SiprecCreator setParameter40Name(final String parameter40Name) { + this.parameter40Name = parameter40Name; + return this; + } + + public SiprecCreator setParameter40Value(final String parameter40Value) { + this.parameter40Value = parameter40Value; + return this; + } + + public SiprecCreator setParameter41Name(final String parameter41Name) { + this.parameter41Name = parameter41Name; + return this; + } + + public SiprecCreator setParameter41Value(final String parameter41Value) { + this.parameter41Value = parameter41Value; + return this; + } + + public SiprecCreator setParameter42Name(final String parameter42Name) { + this.parameter42Name = parameter42Name; + return this; + } + + public SiprecCreator setParameter42Value(final String parameter42Value) { + this.parameter42Value = parameter42Value; + return this; + } + + public SiprecCreator setParameter43Name(final String parameter43Name) { + this.parameter43Name = parameter43Name; + return this; + } + + public SiprecCreator setParameter43Value(final String parameter43Value) { + this.parameter43Value = parameter43Value; + return this; + } + + public SiprecCreator setParameter44Name(final String parameter44Name) { + this.parameter44Name = parameter44Name; + return this; + } + + public SiprecCreator setParameter44Value(final String parameter44Value) { + this.parameter44Value = parameter44Value; + return this; + } + + public SiprecCreator setParameter45Name(final String parameter45Name) { + this.parameter45Name = parameter45Name; + return this; + } + + public SiprecCreator setParameter45Value(final String parameter45Value) { + this.parameter45Value = parameter45Value; + return this; + } + + public SiprecCreator setParameter46Name(final String parameter46Name) { + this.parameter46Name = parameter46Name; + return this; + } + + public SiprecCreator setParameter46Value(final String parameter46Value) { + this.parameter46Value = parameter46Value; + return this; + } + + public SiprecCreator setParameter47Name(final String parameter47Name) { + this.parameter47Name = parameter47Name; + return this; + } + + public SiprecCreator setParameter47Value(final String parameter47Value) { + this.parameter47Value = parameter47Value; + return this; + } + + public SiprecCreator setParameter48Name(final String parameter48Name) { + this.parameter48Name = parameter48Name; + return this; + } + + public SiprecCreator setParameter48Value(final String parameter48Value) { + this.parameter48Value = parameter48Value; + return this; + } + + public SiprecCreator setParameter49Name(final String parameter49Name) { + this.parameter49Name = parameter49Name; + return this; + } + + public SiprecCreator setParameter49Value(final String parameter49Value) { + this.parameter49Value = parameter49Value; + return this; + } + + public SiprecCreator setParameter50Name(final String parameter50Name) { + this.parameter50Name = parameter50Name; + return this; + } + + public SiprecCreator setParameter50Value(final String parameter50Value) { + this.parameter50Value = parameter50Value; + return this; + } + + public SiprecCreator setParameter51Name(final String parameter51Name) { + this.parameter51Name = parameter51Name; + return this; + } + + public SiprecCreator setParameter51Value(final String parameter51Value) { + this.parameter51Value = parameter51Value; + return this; + } + + public SiprecCreator setParameter52Name(final String parameter52Name) { + this.parameter52Name = parameter52Name; + return this; + } + + public SiprecCreator setParameter52Value(final String parameter52Value) { + this.parameter52Value = parameter52Value; + return this; + } + + public SiprecCreator setParameter53Name(final String parameter53Name) { + this.parameter53Name = parameter53Name; + return this; + } + + public SiprecCreator setParameter53Value(final String parameter53Value) { + this.parameter53Value = parameter53Value; + return this; + } + + public SiprecCreator setParameter54Name(final String parameter54Name) { + this.parameter54Name = parameter54Name; + return this; + } + + public SiprecCreator setParameter54Value(final String parameter54Value) { + this.parameter54Value = parameter54Value; + return this; + } + + public SiprecCreator setParameter55Name(final String parameter55Name) { + this.parameter55Name = parameter55Name; + return this; + } + + public SiprecCreator setParameter55Value(final String parameter55Value) { + this.parameter55Value = parameter55Value; + return this; + } + + public SiprecCreator setParameter56Name(final String parameter56Name) { + this.parameter56Name = parameter56Name; + return this; + } + + public SiprecCreator setParameter56Value(final String parameter56Value) { + this.parameter56Value = parameter56Value; + return this; + } + + public SiprecCreator setParameter57Name(final String parameter57Name) { + this.parameter57Name = parameter57Name; + return this; + } + + public SiprecCreator setParameter57Value(final String parameter57Value) { + this.parameter57Value = parameter57Value; + return this; + } + + public SiprecCreator setParameter58Name(final String parameter58Name) { + this.parameter58Name = parameter58Name; + return this; + } + + public SiprecCreator setParameter58Value(final String parameter58Value) { + this.parameter58Value = parameter58Value; + return this; + } + + public SiprecCreator setParameter59Name(final String parameter59Name) { + this.parameter59Name = parameter59Name; + return this; + } + + public SiprecCreator setParameter59Value(final String parameter59Value) { + this.parameter59Value = parameter59Value; + return this; + } + + public SiprecCreator setParameter60Name(final String parameter60Name) { + this.parameter60Name = parameter60Name; + return this; + } + + public SiprecCreator setParameter60Value(final String parameter60Value) { + this.parameter60Value = parameter60Value; + return this; + } + + public SiprecCreator setParameter61Name(final String parameter61Name) { + this.parameter61Name = parameter61Name; + return this; + } + + public SiprecCreator setParameter61Value(final String parameter61Value) { + this.parameter61Value = parameter61Value; + return this; + } + + public SiprecCreator setParameter62Name(final String parameter62Name) { + this.parameter62Name = parameter62Name; + return this; + } + + public SiprecCreator setParameter62Value(final String parameter62Value) { + this.parameter62Value = parameter62Value; + return this; + } + + public SiprecCreator setParameter63Name(final String parameter63Name) { + this.parameter63Name = parameter63Name; + return this; + } + + public SiprecCreator setParameter63Value(final String parameter63Value) { + this.parameter63Value = parameter63Value; + return this; + } + + public SiprecCreator setParameter64Name(final String parameter64Name) { + this.parameter64Name = parameter64Name; + return this; + } + + public SiprecCreator setParameter64Value(final String parameter64Value) { + this.parameter64Value = parameter64Value; + return this; + } + + public SiprecCreator setParameter65Name(final String parameter65Name) { + this.parameter65Name = parameter65Name; + return this; + } + + public SiprecCreator setParameter65Value(final String parameter65Value) { + this.parameter65Value = parameter65Value; + return this; + } + + public SiprecCreator setParameter66Name(final String parameter66Name) { + this.parameter66Name = parameter66Name; + return this; + } + + public SiprecCreator setParameter66Value(final String parameter66Value) { + this.parameter66Value = parameter66Value; + return this; + } + + public SiprecCreator setParameter67Name(final String parameter67Name) { + this.parameter67Name = parameter67Name; + return this; + } + + public SiprecCreator setParameter67Value(final String parameter67Value) { + this.parameter67Value = parameter67Value; + return this; + } + + public SiprecCreator setParameter68Name(final String parameter68Name) { + this.parameter68Name = parameter68Name; + return this; + } + + public SiprecCreator setParameter68Value(final String parameter68Value) { + this.parameter68Value = parameter68Value; + return this; + } + + public SiprecCreator setParameter69Name(final String parameter69Name) { + this.parameter69Name = parameter69Name; + return this; + } + + public SiprecCreator setParameter69Value(final String parameter69Value) { + this.parameter69Value = parameter69Value; + return this; + } + + public SiprecCreator setParameter70Name(final String parameter70Name) { + this.parameter70Name = parameter70Name; + return this; + } + + public SiprecCreator setParameter70Value(final String parameter70Value) { + this.parameter70Value = parameter70Value; + return this; + } + + public SiprecCreator setParameter71Name(final String parameter71Name) { + this.parameter71Name = parameter71Name; + return this; + } + + public SiprecCreator setParameter71Value(final String parameter71Value) { + this.parameter71Value = parameter71Value; + return this; + } + + public SiprecCreator setParameter72Name(final String parameter72Name) { + this.parameter72Name = parameter72Name; + return this; + } + + public SiprecCreator setParameter72Value(final String parameter72Value) { + this.parameter72Value = parameter72Value; + return this; + } + + public SiprecCreator setParameter73Name(final String parameter73Name) { + this.parameter73Name = parameter73Name; + return this; + } + + public SiprecCreator setParameter73Value(final String parameter73Value) { + this.parameter73Value = parameter73Value; + return this; + } + + public SiprecCreator setParameter74Name(final String parameter74Name) { + this.parameter74Name = parameter74Name; + return this; + } + + public SiprecCreator setParameter74Value(final String parameter74Value) { + this.parameter74Value = parameter74Value; + return this; + } + + public SiprecCreator setParameter75Name(final String parameter75Name) { + this.parameter75Name = parameter75Name; + return this; + } + + public SiprecCreator setParameter75Value(final String parameter75Value) { + this.parameter75Value = parameter75Value; + return this; + } + + public SiprecCreator setParameter76Name(final String parameter76Name) { + this.parameter76Name = parameter76Name; + return this; + } + + public SiprecCreator setParameter76Value(final String parameter76Value) { + this.parameter76Value = parameter76Value; + return this; + } + + public SiprecCreator setParameter77Name(final String parameter77Name) { + this.parameter77Name = parameter77Name; + return this; + } + + public SiprecCreator setParameter77Value(final String parameter77Value) { + this.parameter77Value = parameter77Value; + return this; + } + + public SiprecCreator setParameter78Name(final String parameter78Name) { + this.parameter78Name = parameter78Name; + return this; + } + + public SiprecCreator setParameter78Value(final String parameter78Value) { + this.parameter78Value = parameter78Value; + return this; + } + + public SiprecCreator setParameter79Name(final String parameter79Name) { + this.parameter79Name = parameter79Name; + return this; + } + + public SiprecCreator setParameter79Value(final String parameter79Value) { + this.parameter79Value = parameter79Value; + return this; + } + + public SiprecCreator setParameter80Name(final String parameter80Name) { + this.parameter80Name = parameter80Name; + return this; + } + + public SiprecCreator setParameter80Value(final String parameter80Value) { + this.parameter80Value = parameter80Value; + return this; + } + + public SiprecCreator setParameter81Name(final String parameter81Name) { + this.parameter81Name = parameter81Name; + return this; + } + + public SiprecCreator setParameter81Value(final String parameter81Value) { + this.parameter81Value = parameter81Value; + return this; + } + + public SiprecCreator setParameter82Name(final String parameter82Name) { + this.parameter82Name = parameter82Name; + return this; + } + + public SiprecCreator setParameter82Value(final String parameter82Value) { + this.parameter82Value = parameter82Value; + return this; + } + + public SiprecCreator setParameter83Name(final String parameter83Name) { + this.parameter83Name = parameter83Name; + return this; + } + + public SiprecCreator setParameter83Value(final String parameter83Value) { + this.parameter83Value = parameter83Value; + return this; + } + + public SiprecCreator setParameter84Name(final String parameter84Name) { + this.parameter84Name = parameter84Name; + return this; + } + + public SiprecCreator setParameter84Value(final String parameter84Value) { + this.parameter84Value = parameter84Value; + return this; + } + + public SiprecCreator setParameter85Name(final String parameter85Name) { + this.parameter85Name = parameter85Name; + return this; + } + + public SiprecCreator setParameter85Value(final String parameter85Value) { + this.parameter85Value = parameter85Value; + return this; + } + + public SiprecCreator setParameter86Name(final String parameter86Name) { + this.parameter86Name = parameter86Name; + return this; + } + + public SiprecCreator setParameter86Value(final String parameter86Value) { + this.parameter86Value = parameter86Value; + return this; + } + + public SiprecCreator setParameter87Name(final String parameter87Name) { + this.parameter87Name = parameter87Name; + return this; + } + + public SiprecCreator setParameter87Value(final String parameter87Value) { + this.parameter87Value = parameter87Value; + return this; + } + + public SiprecCreator setParameter88Name(final String parameter88Name) { + this.parameter88Name = parameter88Name; + return this; + } + + public SiprecCreator setParameter88Value(final String parameter88Value) { + this.parameter88Value = parameter88Value; + return this; + } + + public SiprecCreator setParameter89Name(final String parameter89Name) { + this.parameter89Name = parameter89Name; + return this; + } + + public SiprecCreator setParameter89Value(final String parameter89Value) { + this.parameter89Value = parameter89Value; + return this; + } + + public SiprecCreator setParameter90Name(final String parameter90Name) { + this.parameter90Name = parameter90Name; + return this; + } + + public SiprecCreator setParameter90Value(final String parameter90Value) { + this.parameter90Value = parameter90Value; + return this; + } + + public SiprecCreator setParameter91Name(final String parameter91Name) { + this.parameter91Name = parameter91Name; + return this; + } + + public SiprecCreator setParameter91Value(final String parameter91Value) { + this.parameter91Value = parameter91Value; + return this; + } + + public SiprecCreator setParameter92Name(final String parameter92Name) { + this.parameter92Name = parameter92Name; + return this; + } + + public SiprecCreator setParameter92Value(final String parameter92Value) { + this.parameter92Value = parameter92Value; + return this; + } + + public SiprecCreator setParameter93Name(final String parameter93Name) { + this.parameter93Name = parameter93Name; + return this; + } + + public SiprecCreator setParameter93Value(final String parameter93Value) { + this.parameter93Value = parameter93Value; + return this; + } + + public SiprecCreator setParameter94Name(final String parameter94Name) { + this.parameter94Name = parameter94Name; + return this; + } + + public SiprecCreator setParameter94Value(final String parameter94Value) { + this.parameter94Value = parameter94Value; + return this; + } + + public SiprecCreator setParameter95Name(final String parameter95Name) { + this.parameter95Name = parameter95Name; + return this; + } + + public SiprecCreator setParameter95Value(final String parameter95Value) { + this.parameter95Value = parameter95Value; + return this; + } + + public SiprecCreator setParameter96Name(final String parameter96Name) { + this.parameter96Name = parameter96Name; + return this; + } + + public SiprecCreator setParameter96Value(final String parameter96Value) { + this.parameter96Value = parameter96Value; + return this; + } + + public SiprecCreator setParameter97Name(final String parameter97Name) { + this.parameter97Name = parameter97Name; + return this; + } + + public SiprecCreator setParameter97Value(final String parameter97Value) { + this.parameter97Value = parameter97Value; + return this; + } + + public SiprecCreator setParameter98Name(final String parameter98Name) { + this.parameter98Name = parameter98Name; + return this; + } + + public SiprecCreator setParameter98Value(final String parameter98Value) { + this.parameter98Value = parameter98Value; + return this; + } + + public SiprecCreator setParameter99Name(final String parameter99Name) { + this.parameter99Name = parameter99Name; + return this; + } + + public SiprecCreator setParameter99Value(final String parameter99Value) { + this.parameter99Value = parameter99Value; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Siprec creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Siprec create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Siprec.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Siprec content = Siprec.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (name != null) { + Serializer.toString( + request, + "Name", + name, + ParameterType.URLENCODED + ); + } + + if (connectorName != null) { + Serializer.toString( + request, + "ConnectorName", + connectorName, + ParameterType.URLENCODED + ); + } + + if (track != null) { + Serializer.toString( + request, + "Track", + track, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + + if (statusCallbackMethod != null) { + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (parameter1Name != null) { + Serializer.toString( + request, + "Parameter1.Name", + parameter1Name, + ParameterType.URLENCODED + ); + } + + if (parameter1Value != null) { + Serializer.toString( + request, + "Parameter1.Value", + parameter1Value, + ParameterType.URLENCODED + ); + } + + if (parameter2Name != null) { + Serializer.toString( + request, + "Parameter2.Name", + parameter2Name, + ParameterType.URLENCODED + ); + } + + if (parameter2Value != null) { + Serializer.toString( + request, + "Parameter2.Value", + parameter2Value, + ParameterType.URLENCODED + ); + } + + if (parameter3Name != null) { + Serializer.toString( + request, + "Parameter3.Name", + parameter3Name, + ParameterType.URLENCODED + ); + } + + if (parameter3Value != null) { + Serializer.toString( + request, + "Parameter3.Value", + parameter3Value, + ParameterType.URLENCODED + ); + } + + if (parameter4Name != null) { + Serializer.toString( + request, + "Parameter4.Name", + parameter4Name, + ParameterType.URLENCODED + ); + } + + if (parameter4Value != null) { + Serializer.toString( + request, + "Parameter4.Value", + parameter4Value, + ParameterType.URLENCODED + ); + } + + if (parameter5Name != null) { + Serializer.toString( + request, + "Parameter5.Name", + parameter5Name, + ParameterType.URLENCODED + ); + } + + if (parameter5Value != null) { + Serializer.toString( + request, + "Parameter5.Value", + parameter5Value, + ParameterType.URLENCODED + ); + } + + if (parameter6Name != null) { + Serializer.toString( + request, + "Parameter6.Name", + parameter6Name, + ParameterType.URLENCODED + ); + } + + if (parameter6Value != null) { + Serializer.toString( + request, + "Parameter6.Value", + parameter6Value, + ParameterType.URLENCODED + ); + } + + if (parameter7Name != null) { + Serializer.toString( + request, + "Parameter7.Name", + parameter7Name, + ParameterType.URLENCODED + ); + } + + if (parameter7Value != null) { + Serializer.toString( + request, + "Parameter7.Value", + parameter7Value, + ParameterType.URLENCODED + ); + } + + if (parameter8Name != null) { + Serializer.toString( + request, + "Parameter8.Name", + parameter8Name, + ParameterType.URLENCODED + ); + } + + if (parameter8Value != null) { + Serializer.toString( + request, + "Parameter8.Value", + parameter8Value, + ParameterType.URLENCODED + ); + } + + if (parameter9Name != null) { + Serializer.toString( + request, + "Parameter9.Name", + parameter9Name, + ParameterType.URLENCODED + ); + } + + if (parameter9Value != null) { + Serializer.toString( + request, + "Parameter9.Value", + parameter9Value, + ParameterType.URLENCODED + ); + } + + if (parameter10Name != null) { + Serializer.toString( + request, + "Parameter10.Name", + parameter10Name, + ParameterType.URLENCODED + ); + } + + if (parameter10Value != null) { + Serializer.toString( + request, + "Parameter10.Value", + parameter10Value, + ParameterType.URLENCODED + ); + } + + if (parameter11Name != null) { + Serializer.toString( + request, + "Parameter11.Name", + parameter11Name, + ParameterType.URLENCODED + ); + } + + if (parameter11Value != null) { + Serializer.toString( + request, + "Parameter11.Value", + parameter11Value, + ParameterType.URLENCODED + ); + } + + if (parameter12Name != null) { + Serializer.toString( + request, + "Parameter12.Name", + parameter12Name, + ParameterType.URLENCODED + ); + } + + if (parameter12Value != null) { + Serializer.toString( + request, + "Parameter12.Value", + parameter12Value, + ParameterType.URLENCODED + ); + } + + if (parameter13Name != null) { + Serializer.toString( + request, + "Parameter13.Name", + parameter13Name, + ParameterType.URLENCODED + ); + } + + if (parameter13Value != null) { + Serializer.toString( + request, + "Parameter13.Value", + parameter13Value, + ParameterType.URLENCODED + ); + } + + if (parameter14Name != null) { + Serializer.toString( + request, + "Parameter14.Name", + parameter14Name, + ParameterType.URLENCODED + ); + } + + if (parameter14Value != null) { + Serializer.toString( + request, + "Parameter14.Value", + parameter14Value, + ParameterType.URLENCODED + ); + } + + if (parameter15Name != null) { + Serializer.toString( + request, + "Parameter15.Name", + parameter15Name, + ParameterType.URLENCODED + ); + } + + if (parameter15Value != null) { + Serializer.toString( + request, + "Parameter15.Value", + parameter15Value, + ParameterType.URLENCODED + ); + } + + if (parameter16Name != null) { + Serializer.toString( + request, + "Parameter16.Name", + parameter16Name, + ParameterType.URLENCODED + ); + } + + if (parameter16Value != null) { + Serializer.toString( + request, + "Parameter16.Value", + parameter16Value, + ParameterType.URLENCODED + ); + } + + if (parameter17Name != null) { + Serializer.toString( + request, + "Parameter17.Name", + parameter17Name, + ParameterType.URLENCODED + ); + } + + if (parameter17Value != null) { + Serializer.toString( + request, + "Parameter17.Value", + parameter17Value, + ParameterType.URLENCODED + ); + } + + if (parameter18Name != null) { + Serializer.toString( + request, + "Parameter18.Name", + parameter18Name, + ParameterType.URLENCODED + ); + } + + if (parameter18Value != null) { + Serializer.toString( + request, + "Parameter18.Value", + parameter18Value, + ParameterType.URLENCODED + ); + } + + if (parameter19Name != null) { + Serializer.toString( + request, + "Parameter19.Name", + parameter19Name, + ParameterType.URLENCODED + ); + } + + if (parameter19Value != null) { + Serializer.toString( + request, + "Parameter19.Value", + parameter19Value, + ParameterType.URLENCODED + ); + } + + if (parameter20Name != null) { + Serializer.toString( + request, + "Parameter20.Name", + parameter20Name, + ParameterType.URLENCODED + ); + } + + if (parameter20Value != null) { + Serializer.toString( + request, + "Parameter20.Value", + parameter20Value, + ParameterType.URLENCODED + ); + } + + if (parameter21Name != null) { + Serializer.toString( + request, + "Parameter21.Name", + parameter21Name, + ParameterType.URLENCODED + ); + } + + if (parameter21Value != null) { + Serializer.toString( + request, + "Parameter21.Value", + parameter21Value, + ParameterType.URLENCODED + ); + } + + if (parameter22Name != null) { + Serializer.toString( + request, + "Parameter22.Name", + parameter22Name, + ParameterType.URLENCODED + ); + } + + if (parameter22Value != null) { + Serializer.toString( + request, + "Parameter22.Value", + parameter22Value, + ParameterType.URLENCODED + ); + } + + if (parameter23Name != null) { + Serializer.toString( + request, + "Parameter23.Name", + parameter23Name, + ParameterType.URLENCODED + ); + } + + if (parameter23Value != null) { + Serializer.toString( + request, + "Parameter23.Value", + parameter23Value, + ParameterType.URLENCODED + ); + } + + if (parameter24Name != null) { + Serializer.toString( + request, + "Parameter24.Name", + parameter24Name, + ParameterType.URLENCODED + ); + } + + if (parameter24Value != null) { + Serializer.toString( + request, + "Parameter24.Value", + parameter24Value, + ParameterType.URLENCODED + ); + } + + if (parameter25Name != null) { + Serializer.toString( + request, + "Parameter25.Name", + parameter25Name, + ParameterType.URLENCODED + ); + } + + if (parameter25Value != null) { + Serializer.toString( + request, + "Parameter25.Value", + parameter25Value, + ParameterType.URLENCODED + ); + } + + if (parameter26Name != null) { + Serializer.toString( + request, + "Parameter26.Name", + parameter26Name, + ParameterType.URLENCODED + ); + } + + if (parameter26Value != null) { + Serializer.toString( + request, + "Parameter26.Value", + parameter26Value, + ParameterType.URLENCODED + ); + } + + if (parameter27Name != null) { + Serializer.toString( + request, + "Parameter27.Name", + parameter27Name, + ParameterType.URLENCODED + ); + } + + if (parameter27Value != null) { + Serializer.toString( + request, + "Parameter27.Value", + parameter27Value, + ParameterType.URLENCODED + ); + } + + if (parameter28Name != null) { + Serializer.toString( + request, + "Parameter28.Name", + parameter28Name, + ParameterType.URLENCODED + ); + } + + if (parameter28Value != null) { + Serializer.toString( + request, + "Parameter28.Value", + parameter28Value, + ParameterType.URLENCODED + ); + } + + if (parameter29Name != null) { + Serializer.toString( + request, + "Parameter29.Name", + parameter29Name, + ParameterType.URLENCODED + ); + } + + if (parameter29Value != null) { + Serializer.toString( + request, + "Parameter29.Value", + parameter29Value, + ParameterType.URLENCODED + ); + } + + if (parameter30Name != null) { + Serializer.toString( + request, + "Parameter30.Name", + parameter30Name, + ParameterType.URLENCODED + ); + } + + if (parameter30Value != null) { + Serializer.toString( + request, + "Parameter30.Value", + parameter30Value, + ParameterType.URLENCODED + ); + } + + if (parameter31Name != null) { + Serializer.toString( + request, + "Parameter31.Name", + parameter31Name, + ParameterType.URLENCODED + ); + } + + if (parameter31Value != null) { + Serializer.toString( + request, + "Parameter31.Value", + parameter31Value, + ParameterType.URLENCODED + ); + } + + if (parameter32Name != null) { + Serializer.toString( + request, + "Parameter32.Name", + parameter32Name, + ParameterType.URLENCODED + ); + } + + if (parameter32Value != null) { + Serializer.toString( + request, + "Parameter32.Value", + parameter32Value, + ParameterType.URLENCODED + ); + } + + if (parameter33Name != null) { + Serializer.toString( + request, + "Parameter33.Name", + parameter33Name, + ParameterType.URLENCODED + ); + } + + if (parameter33Value != null) { + Serializer.toString( + request, + "Parameter33.Value", + parameter33Value, + ParameterType.URLENCODED + ); + } + + if (parameter34Name != null) { + Serializer.toString( + request, + "Parameter34.Name", + parameter34Name, + ParameterType.URLENCODED + ); + } + + if (parameter34Value != null) { + Serializer.toString( + request, + "Parameter34.Value", + parameter34Value, + ParameterType.URLENCODED + ); + } + + if (parameter35Name != null) { + Serializer.toString( + request, + "Parameter35.Name", + parameter35Name, + ParameterType.URLENCODED + ); + } + + if (parameter35Value != null) { + Serializer.toString( + request, + "Parameter35.Value", + parameter35Value, + ParameterType.URLENCODED + ); + } + + if (parameter36Name != null) { + Serializer.toString( + request, + "Parameter36.Name", + parameter36Name, + ParameterType.URLENCODED + ); + } + + if (parameter36Value != null) { + Serializer.toString( + request, + "Parameter36.Value", + parameter36Value, + ParameterType.URLENCODED + ); + } + + if (parameter37Name != null) { + Serializer.toString( + request, + "Parameter37.Name", + parameter37Name, + ParameterType.URLENCODED + ); + } + + if (parameter37Value != null) { + Serializer.toString( + request, + "Parameter37.Value", + parameter37Value, + ParameterType.URLENCODED + ); + } + + if (parameter38Name != null) { + Serializer.toString( + request, + "Parameter38.Name", + parameter38Name, + ParameterType.URLENCODED + ); + } + + if (parameter38Value != null) { + Serializer.toString( + request, + "Parameter38.Value", + parameter38Value, + ParameterType.URLENCODED + ); + } + + if (parameter39Name != null) { + Serializer.toString( + request, + "Parameter39.Name", + parameter39Name, + ParameterType.URLENCODED + ); + } + + if (parameter39Value != null) { + Serializer.toString( + request, + "Parameter39.Value", + parameter39Value, + ParameterType.URLENCODED + ); + } + + if (parameter40Name != null) { + Serializer.toString( + request, + "Parameter40.Name", + parameter40Name, + ParameterType.URLENCODED + ); + } + + if (parameter40Value != null) { + Serializer.toString( + request, + "Parameter40.Value", + parameter40Value, + ParameterType.URLENCODED + ); + } + + if (parameter41Name != null) { + Serializer.toString( + request, + "Parameter41.Name", + parameter41Name, + ParameterType.URLENCODED + ); + } + + if (parameter41Value != null) { + Serializer.toString( + request, + "Parameter41.Value", + parameter41Value, + ParameterType.URLENCODED + ); + } + + if (parameter42Name != null) { + Serializer.toString( + request, + "Parameter42.Name", + parameter42Name, + ParameterType.URLENCODED + ); + } + + if (parameter42Value != null) { + Serializer.toString( + request, + "Parameter42.Value", + parameter42Value, + ParameterType.URLENCODED + ); + } + + if (parameter43Name != null) { + Serializer.toString( + request, + "Parameter43.Name", + parameter43Name, + ParameterType.URLENCODED + ); + } + + if (parameter43Value != null) { + Serializer.toString( + request, + "Parameter43.Value", + parameter43Value, + ParameterType.URLENCODED + ); + } + + if (parameter44Name != null) { + Serializer.toString( + request, + "Parameter44.Name", + parameter44Name, + ParameterType.URLENCODED + ); + } + + if (parameter44Value != null) { + Serializer.toString( + request, + "Parameter44.Value", + parameter44Value, + ParameterType.URLENCODED + ); + } + + if (parameter45Name != null) { + Serializer.toString( + request, + "Parameter45.Name", + parameter45Name, + ParameterType.URLENCODED + ); + } + + if (parameter45Value != null) { + Serializer.toString( + request, + "Parameter45.Value", + parameter45Value, + ParameterType.URLENCODED + ); + } + + if (parameter46Name != null) { + Serializer.toString( + request, + "Parameter46.Name", + parameter46Name, + ParameterType.URLENCODED + ); + } + + if (parameter46Value != null) { + Serializer.toString( + request, + "Parameter46.Value", + parameter46Value, + ParameterType.URLENCODED + ); + } + + if (parameter47Name != null) { + Serializer.toString( + request, + "Parameter47.Name", + parameter47Name, + ParameterType.URLENCODED + ); + } + + if (parameter47Value != null) { + Serializer.toString( + request, + "Parameter47.Value", + parameter47Value, + ParameterType.URLENCODED + ); + } + + if (parameter48Name != null) { + Serializer.toString( + request, + "Parameter48.Name", + parameter48Name, + ParameterType.URLENCODED + ); + } + + if (parameter48Value != null) { + Serializer.toString( + request, + "Parameter48.Value", + parameter48Value, + ParameterType.URLENCODED + ); + } + + if (parameter49Name != null) { + Serializer.toString( + request, + "Parameter49.Name", + parameter49Name, + ParameterType.URLENCODED + ); + } + + if (parameter49Value != null) { + Serializer.toString( + request, + "Parameter49.Value", + parameter49Value, + ParameterType.URLENCODED + ); + } + + if (parameter50Name != null) { + Serializer.toString( + request, + "Parameter50.Name", + parameter50Name, + ParameterType.URLENCODED + ); + } + + if (parameter50Value != null) { + Serializer.toString( + request, + "Parameter50.Value", + parameter50Value, + ParameterType.URLENCODED + ); + } + + if (parameter51Name != null) { + Serializer.toString( + request, + "Parameter51.Name", + parameter51Name, + ParameterType.URLENCODED + ); + } + + if (parameter51Value != null) { + Serializer.toString( + request, + "Parameter51.Value", + parameter51Value, + ParameterType.URLENCODED + ); + } + + if (parameter52Name != null) { + Serializer.toString( + request, + "Parameter52.Name", + parameter52Name, + ParameterType.URLENCODED + ); + } + + if (parameter52Value != null) { + Serializer.toString( + request, + "Parameter52.Value", + parameter52Value, + ParameterType.URLENCODED + ); + } + + if (parameter53Name != null) { + Serializer.toString( + request, + "Parameter53.Name", + parameter53Name, + ParameterType.URLENCODED + ); + } + + if (parameter53Value != null) { + Serializer.toString( + request, + "Parameter53.Value", + parameter53Value, + ParameterType.URLENCODED + ); + } + + if (parameter54Name != null) { + Serializer.toString( + request, + "Parameter54.Name", + parameter54Name, + ParameterType.URLENCODED + ); + } + + if (parameter54Value != null) { + Serializer.toString( + request, + "Parameter54.Value", + parameter54Value, + ParameterType.URLENCODED + ); + } + + if (parameter55Name != null) { + Serializer.toString( + request, + "Parameter55.Name", + parameter55Name, + ParameterType.URLENCODED + ); + } + + if (parameter55Value != null) { + Serializer.toString( + request, + "Parameter55.Value", + parameter55Value, + ParameterType.URLENCODED + ); + } + + if (parameter56Name != null) { + Serializer.toString( + request, + "Parameter56.Name", + parameter56Name, + ParameterType.URLENCODED + ); + } + + if (parameter56Value != null) { + Serializer.toString( + request, + "Parameter56.Value", + parameter56Value, + ParameterType.URLENCODED + ); + } + + if (parameter57Name != null) { + Serializer.toString( + request, + "Parameter57.Name", + parameter57Name, + ParameterType.URLENCODED + ); + } + + if (parameter57Value != null) { + Serializer.toString( + request, + "Parameter57.Value", + parameter57Value, + ParameterType.URLENCODED + ); + } + + if (parameter58Name != null) { + Serializer.toString( + request, + "Parameter58.Name", + parameter58Name, + ParameterType.URLENCODED + ); + } + + if (parameter58Value != null) { + Serializer.toString( + request, + "Parameter58.Value", + parameter58Value, + ParameterType.URLENCODED + ); + } + + if (parameter59Name != null) { + Serializer.toString( + request, + "Parameter59.Name", + parameter59Name, + ParameterType.URLENCODED + ); + } + + if (parameter59Value != null) { + Serializer.toString( + request, + "Parameter59.Value", + parameter59Value, + ParameterType.URLENCODED + ); + } + + if (parameter60Name != null) { + Serializer.toString( + request, + "Parameter60.Name", + parameter60Name, + ParameterType.URLENCODED + ); + } + + if (parameter60Value != null) { + Serializer.toString( + request, + "Parameter60.Value", + parameter60Value, + ParameterType.URLENCODED + ); + } + + if (parameter61Name != null) { + Serializer.toString( + request, + "Parameter61.Name", + parameter61Name, + ParameterType.URLENCODED + ); + } + + if (parameter61Value != null) { + Serializer.toString( + request, + "Parameter61.Value", + parameter61Value, + ParameterType.URLENCODED + ); + } + + if (parameter62Name != null) { + Serializer.toString( + request, + "Parameter62.Name", + parameter62Name, + ParameterType.URLENCODED + ); + } + + if (parameter62Value != null) { + Serializer.toString( + request, + "Parameter62.Value", + parameter62Value, + ParameterType.URLENCODED + ); + } + + if (parameter63Name != null) { + Serializer.toString( + request, + "Parameter63.Name", + parameter63Name, + ParameterType.URLENCODED + ); + } + + if (parameter63Value != null) { + Serializer.toString( + request, + "Parameter63.Value", + parameter63Value, + ParameterType.URLENCODED + ); + } + + if (parameter64Name != null) { + Serializer.toString( + request, + "Parameter64.Name", + parameter64Name, + ParameterType.URLENCODED + ); + } + + if (parameter64Value != null) { + Serializer.toString( + request, + "Parameter64.Value", + parameter64Value, + ParameterType.URLENCODED + ); + } + + if (parameter65Name != null) { + Serializer.toString( + request, + "Parameter65.Name", + parameter65Name, + ParameterType.URLENCODED + ); + } + + if (parameter65Value != null) { + Serializer.toString( + request, + "Parameter65.Value", + parameter65Value, + ParameterType.URLENCODED + ); + } + + if (parameter66Name != null) { + Serializer.toString( + request, + "Parameter66.Name", + parameter66Name, + ParameterType.URLENCODED + ); + } + + if (parameter66Value != null) { + Serializer.toString( + request, + "Parameter66.Value", + parameter66Value, + ParameterType.URLENCODED + ); + } + + if (parameter67Name != null) { + Serializer.toString( + request, + "Parameter67.Name", + parameter67Name, + ParameterType.URLENCODED + ); + } + + if (parameter67Value != null) { + Serializer.toString( + request, + "Parameter67.Value", + parameter67Value, + ParameterType.URLENCODED + ); + } + + if (parameter68Name != null) { + Serializer.toString( + request, + "Parameter68.Name", + parameter68Name, + ParameterType.URLENCODED + ); + } + + if (parameter68Value != null) { + Serializer.toString( + request, + "Parameter68.Value", + parameter68Value, + ParameterType.URLENCODED + ); + } + + if (parameter69Name != null) { + Serializer.toString( + request, + "Parameter69.Name", + parameter69Name, + ParameterType.URLENCODED + ); + } + + if (parameter69Value != null) { + Serializer.toString( + request, + "Parameter69.Value", + parameter69Value, + ParameterType.URLENCODED + ); + } + + if (parameter70Name != null) { + Serializer.toString( + request, + "Parameter70.Name", + parameter70Name, + ParameterType.URLENCODED + ); + } + + if (parameter70Value != null) { + Serializer.toString( + request, + "Parameter70.Value", + parameter70Value, + ParameterType.URLENCODED + ); + } + + if (parameter71Name != null) { + Serializer.toString( + request, + "Parameter71.Name", + parameter71Name, + ParameterType.URLENCODED + ); + } + + if (parameter71Value != null) { + Serializer.toString( + request, + "Parameter71.Value", + parameter71Value, + ParameterType.URLENCODED + ); + } + + if (parameter72Name != null) { + Serializer.toString( + request, + "Parameter72.Name", + parameter72Name, + ParameterType.URLENCODED + ); + } + + if (parameter72Value != null) { + Serializer.toString( + request, + "Parameter72.Value", + parameter72Value, + ParameterType.URLENCODED + ); + } + + if (parameter73Name != null) { + Serializer.toString( + request, + "Parameter73.Name", + parameter73Name, + ParameterType.URLENCODED + ); + } + + if (parameter73Value != null) { + Serializer.toString( + request, + "Parameter73.Value", + parameter73Value, + ParameterType.URLENCODED + ); + } + + if (parameter74Name != null) { + Serializer.toString( + request, + "Parameter74.Name", + parameter74Name, + ParameterType.URLENCODED + ); + } + + if (parameter74Value != null) { + Serializer.toString( + request, + "Parameter74.Value", + parameter74Value, + ParameterType.URLENCODED + ); + } + + if (parameter75Name != null) { + Serializer.toString( + request, + "Parameter75.Name", + parameter75Name, + ParameterType.URLENCODED + ); + } + + if (parameter75Value != null) { + Serializer.toString( + request, + "Parameter75.Value", + parameter75Value, + ParameterType.URLENCODED + ); + } + + if (parameter76Name != null) { + Serializer.toString( + request, + "Parameter76.Name", + parameter76Name, + ParameterType.URLENCODED + ); + } + + if (parameter76Value != null) { + Serializer.toString( + request, + "Parameter76.Value", + parameter76Value, + ParameterType.URLENCODED + ); + } + + if (parameter77Name != null) { + Serializer.toString( + request, + "Parameter77.Name", + parameter77Name, + ParameterType.URLENCODED + ); + } + + if (parameter77Value != null) { + Serializer.toString( + request, + "Parameter77.Value", + parameter77Value, + ParameterType.URLENCODED + ); + } + + if (parameter78Name != null) { + Serializer.toString( + request, + "Parameter78.Name", + parameter78Name, + ParameterType.URLENCODED + ); + } + + if (parameter78Value != null) { + Serializer.toString( + request, + "Parameter78.Value", + parameter78Value, + ParameterType.URLENCODED + ); + } + + if (parameter79Name != null) { + Serializer.toString( + request, + "Parameter79.Name", + parameter79Name, + ParameterType.URLENCODED + ); + } + + if (parameter79Value != null) { + Serializer.toString( + request, + "Parameter79.Value", + parameter79Value, + ParameterType.URLENCODED + ); + } + + if (parameter80Name != null) { + Serializer.toString( + request, + "Parameter80.Name", + parameter80Name, + ParameterType.URLENCODED + ); + } + + if (parameter80Value != null) { + Serializer.toString( + request, + "Parameter80.Value", + parameter80Value, + ParameterType.URLENCODED + ); + } + + if (parameter81Name != null) { + Serializer.toString( + request, + "Parameter81.Name", + parameter81Name, + ParameterType.URLENCODED + ); + } + + if (parameter81Value != null) { + Serializer.toString( + request, + "Parameter81.Value", + parameter81Value, + ParameterType.URLENCODED + ); + } + + if (parameter82Name != null) { + Serializer.toString( + request, + "Parameter82.Name", + parameter82Name, + ParameterType.URLENCODED + ); + } + + if (parameter82Value != null) { + Serializer.toString( + request, + "Parameter82.Value", + parameter82Value, + ParameterType.URLENCODED + ); + } + + if (parameter83Name != null) { + Serializer.toString( + request, + "Parameter83.Name", + parameter83Name, + ParameterType.URLENCODED + ); + } + + if (parameter83Value != null) { + Serializer.toString( + request, + "Parameter83.Value", + parameter83Value, + ParameterType.URLENCODED + ); + } + + if (parameter84Name != null) { + Serializer.toString( + request, + "Parameter84.Name", + parameter84Name, + ParameterType.URLENCODED + ); + } + + if (parameter84Value != null) { + Serializer.toString( + request, + "Parameter84.Value", + parameter84Value, + ParameterType.URLENCODED + ); + } + + if (parameter85Name != null) { + Serializer.toString( + request, + "Parameter85.Name", + parameter85Name, + ParameterType.URLENCODED + ); + } + + if (parameter85Value != null) { + Serializer.toString( + request, + "Parameter85.Value", + parameter85Value, + ParameterType.URLENCODED + ); + } + + if (parameter86Name != null) { + Serializer.toString( + request, + "Parameter86.Name", + parameter86Name, + ParameterType.URLENCODED + ); + } + + if (parameter86Value != null) { + Serializer.toString( + request, + "Parameter86.Value", + parameter86Value, + ParameterType.URLENCODED + ); + } + + if (parameter87Name != null) { + Serializer.toString( + request, + "Parameter87.Name", + parameter87Name, + ParameterType.URLENCODED + ); + } + + if (parameter87Value != null) { + Serializer.toString( + request, + "Parameter87.Value", + parameter87Value, + ParameterType.URLENCODED + ); + } + + if (parameter88Name != null) { + Serializer.toString( + request, + "Parameter88.Name", + parameter88Name, + ParameterType.URLENCODED + ); + } + + if (parameter88Value != null) { + Serializer.toString( + request, + "Parameter88.Value", + parameter88Value, + ParameterType.URLENCODED + ); + } + + if (parameter89Name != null) { + Serializer.toString( + request, + "Parameter89.Name", + parameter89Name, + ParameterType.URLENCODED + ); + } + + if (parameter89Value != null) { + Serializer.toString( + request, + "Parameter89.Value", + parameter89Value, + ParameterType.URLENCODED + ); + } + + if (parameter90Name != null) { + Serializer.toString( + request, + "Parameter90.Name", + parameter90Name, + ParameterType.URLENCODED + ); + } + + if (parameter90Value != null) { + Serializer.toString( + request, + "Parameter90.Value", + parameter90Value, + ParameterType.URLENCODED + ); + } + + if (parameter91Name != null) { + Serializer.toString( + request, + "Parameter91.Name", + parameter91Name, + ParameterType.URLENCODED + ); + } + + if (parameter91Value != null) { + Serializer.toString( + request, + "Parameter91.Value", + parameter91Value, + ParameterType.URLENCODED + ); + } + + if (parameter92Name != null) { + Serializer.toString( + request, + "Parameter92.Name", + parameter92Name, + ParameterType.URLENCODED + ); + } + + if (parameter92Value != null) { + Serializer.toString( + request, + "Parameter92.Value", + parameter92Value, + ParameterType.URLENCODED + ); + } + + if (parameter93Name != null) { + Serializer.toString( + request, + "Parameter93.Name", + parameter93Name, + ParameterType.URLENCODED + ); + } + + if (parameter93Value != null) { + Serializer.toString( + request, + "Parameter93.Value", + parameter93Value, + ParameterType.URLENCODED + ); + } + + if (parameter94Name != null) { + Serializer.toString( + request, + "Parameter94.Name", + parameter94Name, + ParameterType.URLENCODED + ); + } + + if (parameter94Value != null) { + Serializer.toString( + request, + "Parameter94.Value", + parameter94Value, + ParameterType.URLENCODED + ); + } + + if (parameter95Name != null) { + Serializer.toString( + request, + "Parameter95.Name", + parameter95Name, + ParameterType.URLENCODED + ); + } + + if (parameter95Value != null) { + Serializer.toString( + request, + "Parameter95.Value", + parameter95Value, + ParameterType.URLENCODED + ); + } + + if (parameter96Name != null) { + Serializer.toString( + request, + "Parameter96.Name", + parameter96Name, + ParameterType.URLENCODED + ); + } + + if (parameter96Value != null) { + Serializer.toString( + request, + "Parameter96.Value", + parameter96Value, + ParameterType.URLENCODED + ); + } + + if (parameter97Name != null) { + Serializer.toString( + request, + "Parameter97.Name", + parameter97Name, + ParameterType.URLENCODED + ); + } + + if (parameter97Value != null) { + Serializer.toString( + request, + "Parameter97.Value", + parameter97Value, + ParameterType.URLENCODED + ); + } + + if (parameter98Name != null) { + Serializer.toString( + request, + "Parameter98.Name", + parameter98Name, + ParameterType.URLENCODED + ); + } + + if (parameter98Value != null) { + Serializer.toString( + request, + "Parameter98.Value", + parameter98Value, + ParameterType.URLENCODED + ); + } + + if (parameter99Name != null) { + Serializer.toString( + request, + "Parameter99.Name", + parameter99Name, + ParameterType.URLENCODED + ); + } + + if (parameter99Value != null) { + Serializer.toString( + request, + "Parameter99.Value", + parameter99Value, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecUpdater.java new file mode 100644 index 0000000000..d0ea566c15 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/SiprecUpdater.java @@ -0,0 +1,146 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SiprecUpdater extends Updater { + + private String pathAccountSid; + private String pathCallSid; + private String pathSid; + private Siprec.UpdateStatus status; + + public SiprecUpdater( + final String pathCallSid, + final String pathSid, + final Siprec.UpdateStatus status + ) { + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.status = status; + } + + public SiprecUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Siprec.UpdateStatus status + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.status = status; + } + + public SiprecUpdater setStatus(final Siprec.UpdateStatus status) { + this.status = status; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Siprec/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Siprec update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Siprec update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Siprec.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Siprec content = Siprec.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Stream.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Stream.java new file mode 100644 index 0000000000..eebdd39780 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Stream.java @@ -0,0 +1,272 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Stream extends Resource { + + public static StreamCreator creator( + final String pathCallSid, + final URI url + ) { + return new StreamCreator(pathCallSid, url); + } + + public static StreamCreator creator( + final String pathAccountSid, + final String pathCallSid, + final URI url + ) { + return new StreamCreator(pathAccountSid, pathCallSid, url); + } + + public static StreamUpdater updater( + final String pathCallSid, + final String pathSid, + final Stream.UpdateStatus status + ) { + return new StreamUpdater(pathCallSid, pathSid, status); + } + + public static StreamUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Stream.UpdateStatus status + ) { + return new StreamUpdater(pathAccountSid, pathCallSid, pathSid, status); + } + + public enum Status { + IN_PROGRESS("in-progress"), + STOPPED("stopped"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum UpdateStatus { + STOPPED("stopped"); + + private final String value; + + private UpdateStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static UpdateStatus forValue(final String value) { + return Promoter.enumFromString(value, UpdateStatus.values()); + } + } + + public enum Track { + INBOUND_TRACK("inbound_track"), + OUTBOUND_TRACK("outbound_track"), + BOTH_TRACKS("both_tracks"); + + private final String value; + + private Track(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Track forValue(final String value) { + return Promoter.enumFromString(value, Track.values()); + } + } + + /** + * Converts a JSON String into a Stream object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Stream object represented by the provided JSON + */ + public static Stream fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Stream.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Stream object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Stream object represented by the provided JSON + */ + public static Stream fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Stream.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String name; + + @Getter + private final String sid; + + @Getter + private final Stream.Status status; + + @Getter + private final String uri; + + @JsonCreator + private Stream( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("name") final String name, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Stream.Status status, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.dateUpdated = dateUpdated; + this.name = name; + this.sid = sid; + this.status = status; + this.uri = uri; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Stream other = (Stream) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(name, other.name) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(uri, other.uri) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + callSid, + dateUpdated, + name, + sid, + status, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/StreamCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/StreamCreator.java new file mode 100644 index 0000000000..9f79947850 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/StreamCreator.java @@ -0,0 +1,3174 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class StreamCreator extends Creator { + + private String pathAccountSid; + private String pathCallSid; + private URI url; + private String name; + private Stream.Track track; + private URI statusCallback; + private HttpMethod statusCallbackMethod; + private String parameter1Name; + private String parameter1Value; + private String parameter2Name; + private String parameter2Value; + private String parameter3Name; + private String parameter3Value; + private String parameter4Name; + private String parameter4Value; + private String parameter5Name; + private String parameter5Value; + private String parameter6Name; + private String parameter6Value; + private String parameter7Name; + private String parameter7Value; + private String parameter8Name; + private String parameter8Value; + private String parameter9Name; + private String parameter9Value; + private String parameter10Name; + private String parameter10Value; + private String parameter11Name; + private String parameter11Value; + private String parameter12Name; + private String parameter12Value; + private String parameter13Name; + private String parameter13Value; + private String parameter14Name; + private String parameter14Value; + private String parameter15Name; + private String parameter15Value; + private String parameter16Name; + private String parameter16Value; + private String parameter17Name; + private String parameter17Value; + private String parameter18Name; + private String parameter18Value; + private String parameter19Name; + private String parameter19Value; + private String parameter20Name; + private String parameter20Value; + private String parameter21Name; + private String parameter21Value; + private String parameter22Name; + private String parameter22Value; + private String parameter23Name; + private String parameter23Value; + private String parameter24Name; + private String parameter24Value; + private String parameter25Name; + private String parameter25Value; + private String parameter26Name; + private String parameter26Value; + private String parameter27Name; + private String parameter27Value; + private String parameter28Name; + private String parameter28Value; + private String parameter29Name; + private String parameter29Value; + private String parameter30Name; + private String parameter30Value; + private String parameter31Name; + private String parameter31Value; + private String parameter32Name; + private String parameter32Value; + private String parameter33Name; + private String parameter33Value; + private String parameter34Name; + private String parameter34Value; + private String parameter35Name; + private String parameter35Value; + private String parameter36Name; + private String parameter36Value; + private String parameter37Name; + private String parameter37Value; + private String parameter38Name; + private String parameter38Value; + private String parameter39Name; + private String parameter39Value; + private String parameter40Name; + private String parameter40Value; + private String parameter41Name; + private String parameter41Value; + private String parameter42Name; + private String parameter42Value; + private String parameter43Name; + private String parameter43Value; + private String parameter44Name; + private String parameter44Value; + private String parameter45Name; + private String parameter45Value; + private String parameter46Name; + private String parameter46Value; + private String parameter47Name; + private String parameter47Value; + private String parameter48Name; + private String parameter48Value; + private String parameter49Name; + private String parameter49Value; + private String parameter50Name; + private String parameter50Value; + private String parameter51Name; + private String parameter51Value; + private String parameter52Name; + private String parameter52Value; + private String parameter53Name; + private String parameter53Value; + private String parameter54Name; + private String parameter54Value; + private String parameter55Name; + private String parameter55Value; + private String parameter56Name; + private String parameter56Value; + private String parameter57Name; + private String parameter57Value; + private String parameter58Name; + private String parameter58Value; + private String parameter59Name; + private String parameter59Value; + private String parameter60Name; + private String parameter60Value; + private String parameter61Name; + private String parameter61Value; + private String parameter62Name; + private String parameter62Value; + private String parameter63Name; + private String parameter63Value; + private String parameter64Name; + private String parameter64Value; + private String parameter65Name; + private String parameter65Value; + private String parameter66Name; + private String parameter66Value; + private String parameter67Name; + private String parameter67Value; + private String parameter68Name; + private String parameter68Value; + private String parameter69Name; + private String parameter69Value; + private String parameter70Name; + private String parameter70Value; + private String parameter71Name; + private String parameter71Value; + private String parameter72Name; + private String parameter72Value; + private String parameter73Name; + private String parameter73Value; + private String parameter74Name; + private String parameter74Value; + private String parameter75Name; + private String parameter75Value; + private String parameter76Name; + private String parameter76Value; + private String parameter77Name; + private String parameter77Value; + private String parameter78Name; + private String parameter78Value; + private String parameter79Name; + private String parameter79Value; + private String parameter80Name; + private String parameter80Value; + private String parameter81Name; + private String parameter81Value; + private String parameter82Name; + private String parameter82Value; + private String parameter83Name; + private String parameter83Value; + private String parameter84Name; + private String parameter84Value; + private String parameter85Name; + private String parameter85Value; + private String parameter86Name; + private String parameter86Value; + private String parameter87Name; + private String parameter87Value; + private String parameter88Name; + private String parameter88Value; + private String parameter89Name; + private String parameter89Value; + private String parameter90Name; + private String parameter90Value; + private String parameter91Name; + private String parameter91Value; + private String parameter92Name; + private String parameter92Value; + private String parameter93Name; + private String parameter93Value; + private String parameter94Name; + private String parameter94Value; + private String parameter95Name; + private String parameter95Value; + private String parameter96Name; + private String parameter96Value; + private String parameter97Name; + private String parameter97Value; + private String parameter98Name; + private String parameter98Value; + private String parameter99Name; + private String parameter99Value; + + public StreamCreator(final String pathCallSid, final URI url) { + this.pathCallSid = pathCallSid; + this.url = url; + } + + public StreamCreator( + final String pathAccountSid, + final String pathCallSid, + final URI url + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.url = url; + } + + public StreamCreator setUrl(final URI url) { + this.url = url; + return this; + } + + public StreamCreator setUrl(final String url) { + return setUrl(Promoter.uriFromString(url)); + } + + public StreamCreator setName(final String name) { + this.name = name; + return this; + } + + public StreamCreator setTrack(final Stream.Track track) { + this.track = track; + return this; + } + + public StreamCreator setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public StreamCreator setStatusCallback(final String statusCallback) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + public StreamCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + public StreamCreator setParameter1Name(final String parameter1Name) { + this.parameter1Name = parameter1Name; + return this; + } + + public StreamCreator setParameter1Value(final String parameter1Value) { + this.parameter1Value = parameter1Value; + return this; + } + + public StreamCreator setParameter2Name(final String parameter2Name) { + this.parameter2Name = parameter2Name; + return this; + } + + public StreamCreator setParameter2Value(final String parameter2Value) { + this.parameter2Value = parameter2Value; + return this; + } + + public StreamCreator setParameter3Name(final String parameter3Name) { + this.parameter3Name = parameter3Name; + return this; + } + + public StreamCreator setParameter3Value(final String parameter3Value) { + this.parameter3Value = parameter3Value; + return this; + } + + public StreamCreator setParameter4Name(final String parameter4Name) { + this.parameter4Name = parameter4Name; + return this; + } + + public StreamCreator setParameter4Value(final String parameter4Value) { + this.parameter4Value = parameter4Value; + return this; + } + + public StreamCreator setParameter5Name(final String parameter5Name) { + this.parameter5Name = parameter5Name; + return this; + } + + public StreamCreator setParameter5Value(final String parameter5Value) { + this.parameter5Value = parameter5Value; + return this; + } + + public StreamCreator setParameter6Name(final String parameter6Name) { + this.parameter6Name = parameter6Name; + return this; + } + + public StreamCreator setParameter6Value(final String parameter6Value) { + this.parameter6Value = parameter6Value; + return this; + } + + public StreamCreator setParameter7Name(final String parameter7Name) { + this.parameter7Name = parameter7Name; + return this; + } + + public StreamCreator setParameter7Value(final String parameter7Value) { + this.parameter7Value = parameter7Value; + return this; + } + + public StreamCreator setParameter8Name(final String parameter8Name) { + this.parameter8Name = parameter8Name; + return this; + } + + public StreamCreator setParameter8Value(final String parameter8Value) { + this.parameter8Value = parameter8Value; + return this; + } + + public StreamCreator setParameter9Name(final String parameter9Name) { + this.parameter9Name = parameter9Name; + return this; + } + + public StreamCreator setParameter9Value(final String parameter9Value) { + this.parameter9Value = parameter9Value; + return this; + } + + public StreamCreator setParameter10Name(final String parameter10Name) { + this.parameter10Name = parameter10Name; + return this; + } + + public StreamCreator setParameter10Value(final String parameter10Value) { + this.parameter10Value = parameter10Value; + return this; + } + + public StreamCreator setParameter11Name(final String parameter11Name) { + this.parameter11Name = parameter11Name; + return this; + } + + public StreamCreator setParameter11Value(final String parameter11Value) { + this.parameter11Value = parameter11Value; + return this; + } + + public StreamCreator setParameter12Name(final String parameter12Name) { + this.parameter12Name = parameter12Name; + return this; + } + + public StreamCreator setParameter12Value(final String parameter12Value) { + this.parameter12Value = parameter12Value; + return this; + } + + public StreamCreator setParameter13Name(final String parameter13Name) { + this.parameter13Name = parameter13Name; + return this; + } + + public StreamCreator setParameter13Value(final String parameter13Value) { + this.parameter13Value = parameter13Value; + return this; + } + + public StreamCreator setParameter14Name(final String parameter14Name) { + this.parameter14Name = parameter14Name; + return this; + } + + public StreamCreator setParameter14Value(final String parameter14Value) { + this.parameter14Value = parameter14Value; + return this; + } + + public StreamCreator setParameter15Name(final String parameter15Name) { + this.parameter15Name = parameter15Name; + return this; + } + + public StreamCreator setParameter15Value(final String parameter15Value) { + this.parameter15Value = parameter15Value; + return this; + } + + public StreamCreator setParameter16Name(final String parameter16Name) { + this.parameter16Name = parameter16Name; + return this; + } + + public StreamCreator setParameter16Value(final String parameter16Value) { + this.parameter16Value = parameter16Value; + return this; + } + + public StreamCreator setParameter17Name(final String parameter17Name) { + this.parameter17Name = parameter17Name; + return this; + } + + public StreamCreator setParameter17Value(final String parameter17Value) { + this.parameter17Value = parameter17Value; + return this; + } + + public StreamCreator setParameter18Name(final String parameter18Name) { + this.parameter18Name = parameter18Name; + return this; + } + + public StreamCreator setParameter18Value(final String parameter18Value) { + this.parameter18Value = parameter18Value; + return this; + } + + public StreamCreator setParameter19Name(final String parameter19Name) { + this.parameter19Name = parameter19Name; + return this; + } + + public StreamCreator setParameter19Value(final String parameter19Value) { + this.parameter19Value = parameter19Value; + return this; + } + + public StreamCreator setParameter20Name(final String parameter20Name) { + this.parameter20Name = parameter20Name; + return this; + } + + public StreamCreator setParameter20Value(final String parameter20Value) { + this.parameter20Value = parameter20Value; + return this; + } + + public StreamCreator setParameter21Name(final String parameter21Name) { + this.parameter21Name = parameter21Name; + return this; + } + + public StreamCreator setParameter21Value(final String parameter21Value) { + this.parameter21Value = parameter21Value; + return this; + } + + public StreamCreator setParameter22Name(final String parameter22Name) { + this.parameter22Name = parameter22Name; + return this; + } + + public StreamCreator setParameter22Value(final String parameter22Value) { + this.parameter22Value = parameter22Value; + return this; + } + + public StreamCreator setParameter23Name(final String parameter23Name) { + this.parameter23Name = parameter23Name; + return this; + } + + public StreamCreator setParameter23Value(final String parameter23Value) { + this.parameter23Value = parameter23Value; + return this; + } + + public StreamCreator setParameter24Name(final String parameter24Name) { + this.parameter24Name = parameter24Name; + return this; + } + + public StreamCreator setParameter24Value(final String parameter24Value) { + this.parameter24Value = parameter24Value; + return this; + } + + public StreamCreator setParameter25Name(final String parameter25Name) { + this.parameter25Name = parameter25Name; + return this; + } + + public StreamCreator setParameter25Value(final String parameter25Value) { + this.parameter25Value = parameter25Value; + return this; + } + + public StreamCreator setParameter26Name(final String parameter26Name) { + this.parameter26Name = parameter26Name; + return this; + } + + public StreamCreator setParameter26Value(final String parameter26Value) { + this.parameter26Value = parameter26Value; + return this; + } + + public StreamCreator setParameter27Name(final String parameter27Name) { + this.parameter27Name = parameter27Name; + return this; + } + + public StreamCreator setParameter27Value(final String parameter27Value) { + this.parameter27Value = parameter27Value; + return this; + } + + public StreamCreator setParameter28Name(final String parameter28Name) { + this.parameter28Name = parameter28Name; + return this; + } + + public StreamCreator setParameter28Value(final String parameter28Value) { + this.parameter28Value = parameter28Value; + return this; + } + + public StreamCreator setParameter29Name(final String parameter29Name) { + this.parameter29Name = parameter29Name; + return this; + } + + public StreamCreator setParameter29Value(final String parameter29Value) { + this.parameter29Value = parameter29Value; + return this; + } + + public StreamCreator setParameter30Name(final String parameter30Name) { + this.parameter30Name = parameter30Name; + return this; + } + + public StreamCreator setParameter30Value(final String parameter30Value) { + this.parameter30Value = parameter30Value; + return this; + } + + public StreamCreator setParameter31Name(final String parameter31Name) { + this.parameter31Name = parameter31Name; + return this; + } + + public StreamCreator setParameter31Value(final String parameter31Value) { + this.parameter31Value = parameter31Value; + return this; + } + + public StreamCreator setParameter32Name(final String parameter32Name) { + this.parameter32Name = parameter32Name; + return this; + } + + public StreamCreator setParameter32Value(final String parameter32Value) { + this.parameter32Value = parameter32Value; + return this; + } + + public StreamCreator setParameter33Name(final String parameter33Name) { + this.parameter33Name = parameter33Name; + return this; + } + + public StreamCreator setParameter33Value(final String parameter33Value) { + this.parameter33Value = parameter33Value; + return this; + } + + public StreamCreator setParameter34Name(final String parameter34Name) { + this.parameter34Name = parameter34Name; + return this; + } + + public StreamCreator setParameter34Value(final String parameter34Value) { + this.parameter34Value = parameter34Value; + return this; + } + + public StreamCreator setParameter35Name(final String parameter35Name) { + this.parameter35Name = parameter35Name; + return this; + } + + public StreamCreator setParameter35Value(final String parameter35Value) { + this.parameter35Value = parameter35Value; + return this; + } + + public StreamCreator setParameter36Name(final String parameter36Name) { + this.parameter36Name = parameter36Name; + return this; + } + + public StreamCreator setParameter36Value(final String parameter36Value) { + this.parameter36Value = parameter36Value; + return this; + } + + public StreamCreator setParameter37Name(final String parameter37Name) { + this.parameter37Name = parameter37Name; + return this; + } + + public StreamCreator setParameter37Value(final String parameter37Value) { + this.parameter37Value = parameter37Value; + return this; + } + + public StreamCreator setParameter38Name(final String parameter38Name) { + this.parameter38Name = parameter38Name; + return this; + } + + public StreamCreator setParameter38Value(final String parameter38Value) { + this.parameter38Value = parameter38Value; + return this; + } + + public StreamCreator setParameter39Name(final String parameter39Name) { + this.parameter39Name = parameter39Name; + return this; + } + + public StreamCreator setParameter39Value(final String parameter39Value) { + this.parameter39Value = parameter39Value; + return this; + } + + public StreamCreator setParameter40Name(final String parameter40Name) { + this.parameter40Name = parameter40Name; + return this; + } + + public StreamCreator setParameter40Value(final String parameter40Value) { + this.parameter40Value = parameter40Value; + return this; + } + + public StreamCreator setParameter41Name(final String parameter41Name) { + this.parameter41Name = parameter41Name; + return this; + } + + public StreamCreator setParameter41Value(final String parameter41Value) { + this.parameter41Value = parameter41Value; + return this; + } + + public StreamCreator setParameter42Name(final String parameter42Name) { + this.parameter42Name = parameter42Name; + return this; + } + + public StreamCreator setParameter42Value(final String parameter42Value) { + this.parameter42Value = parameter42Value; + return this; + } + + public StreamCreator setParameter43Name(final String parameter43Name) { + this.parameter43Name = parameter43Name; + return this; + } + + public StreamCreator setParameter43Value(final String parameter43Value) { + this.parameter43Value = parameter43Value; + return this; + } + + public StreamCreator setParameter44Name(final String parameter44Name) { + this.parameter44Name = parameter44Name; + return this; + } + + public StreamCreator setParameter44Value(final String parameter44Value) { + this.parameter44Value = parameter44Value; + return this; + } + + public StreamCreator setParameter45Name(final String parameter45Name) { + this.parameter45Name = parameter45Name; + return this; + } + + public StreamCreator setParameter45Value(final String parameter45Value) { + this.parameter45Value = parameter45Value; + return this; + } + + public StreamCreator setParameter46Name(final String parameter46Name) { + this.parameter46Name = parameter46Name; + return this; + } + + public StreamCreator setParameter46Value(final String parameter46Value) { + this.parameter46Value = parameter46Value; + return this; + } + + public StreamCreator setParameter47Name(final String parameter47Name) { + this.parameter47Name = parameter47Name; + return this; + } + + public StreamCreator setParameter47Value(final String parameter47Value) { + this.parameter47Value = parameter47Value; + return this; + } + + public StreamCreator setParameter48Name(final String parameter48Name) { + this.parameter48Name = parameter48Name; + return this; + } + + public StreamCreator setParameter48Value(final String parameter48Value) { + this.parameter48Value = parameter48Value; + return this; + } + + public StreamCreator setParameter49Name(final String parameter49Name) { + this.parameter49Name = parameter49Name; + return this; + } + + public StreamCreator setParameter49Value(final String parameter49Value) { + this.parameter49Value = parameter49Value; + return this; + } + + public StreamCreator setParameter50Name(final String parameter50Name) { + this.parameter50Name = parameter50Name; + return this; + } + + public StreamCreator setParameter50Value(final String parameter50Value) { + this.parameter50Value = parameter50Value; + return this; + } + + public StreamCreator setParameter51Name(final String parameter51Name) { + this.parameter51Name = parameter51Name; + return this; + } + + public StreamCreator setParameter51Value(final String parameter51Value) { + this.parameter51Value = parameter51Value; + return this; + } + + public StreamCreator setParameter52Name(final String parameter52Name) { + this.parameter52Name = parameter52Name; + return this; + } + + public StreamCreator setParameter52Value(final String parameter52Value) { + this.parameter52Value = parameter52Value; + return this; + } + + public StreamCreator setParameter53Name(final String parameter53Name) { + this.parameter53Name = parameter53Name; + return this; + } + + public StreamCreator setParameter53Value(final String parameter53Value) { + this.parameter53Value = parameter53Value; + return this; + } + + public StreamCreator setParameter54Name(final String parameter54Name) { + this.parameter54Name = parameter54Name; + return this; + } + + public StreamCreator setParameter54Value(final String parameter54Value) { + this.parameter54Value = parameter54Value; + return this; + } + + public StreamCreator setParameter55Name(final String parameter55Name) { + this.parameter55Name = parameter55Name; + return this; + } + + public StreamCreator setParameter55Value(final String parameter55Value) { + this.parameter55Value = parameter55Value; + return this; + } + + public StreamCreator setParameter56Name(final String parameter56Name) { + this.parameter56Name = parameter56Name; + return this; + } + + public StreamCreator setParameter56Value(final String parameter56Value) { + this.parameter56Value = parameter56Value; + return this; + } + + public StreamCreator setParameter57Name(final String parameter57Name) { + this.parameter57Name = parameter57Name; + return this; + } + + public StreamCreator setParameter57Value(final String parameter57Value) { + this.parameter57Value = parameter57Value; + return this; + } + + public StreamCreator setParameter58Name(final String parameter58Name) { + this.parameter58Name = parameter58Name; + return this; + } + + public StreamCreator setParameter58Value(final String parameter58Value) { + this.parameter58Value = parameter58Value; + return this; + } + + public StreamCreator setParameter59Name(final String parameter59Name) { + this.parameter59Name = parameter59Name; + return this; + } + + public StreamCreator setParameter59Value(final String parameter59Value) { + this.parameter59Value = parameter59Value; + return this; + } + + public StreamCreator setParameter60Name(final String parameter60Name) { + this.parameter60Name = parameter60Name; + return this; + } + + public StreamCreator setParameter60Value(final String parameter60Value) { + this.parameter60Value = parameter60Value; + return this; + } + + public StreamCreator setParameter61Name(final String parameter61Name) { + this.parameter61Name = parameter61Name; + return this; + } + + public StreamCreator setParameter61Value(final String parameter61Value) { + this.parameter61Value = parameter61Value; + return this; + } + + public StreamCreator setParameter62Name(final String parameter62Name) { + this.parameter62Name = parameter62Name; + return this; + } + + public StreamCreator setParameter62Value(final String parameter62Value) { + this.parameter62Value = parameter62Value; + return this; + } + + public StreamCreator setParameter63Name(final String parameter63Name) { + this.parameter63Name = parameter63Name; + return this; + } + + public StreamCreator setParameter63Value(final String parameter63Value) { + this.parameter63Value = parameter63Value; + return this; + } + + public StreamCreator setParameter64Name(final String parameter64Name) { + this.parameter64Name = parameter64Name; + return this; + } + + public StreamCreator setParameter64Value(final String parameter64Value) { + this.parameter64Value = parameter64Value; + return this; + } + + public StreamCreator setParameter65Name(final String parameter65Name) { + this.parameter65Name = parameter65Name; + return this; + } + + public StreamCreator setParameter65Value(final String parameter65Value) { + this.parameter65Value = parameter65Value; + return this; + } + + public StreamCreator setParameter66Name(final String parameter66Name) { + this.parameter66Name = parameter66Name; + return this; + } + + public StreamCreator setParameter66Value(final String parameter66Value) { + this.parameter66Value = parameter66Value; + return this; + } + + public StreamCreator setParameter67Name(final String parameter67Name) { + this.parameter67Name = parameter67Name; + return this; + } + + public StreamCreator setParameter67Value(final String parameter67Value) { + this.parameter67Value = parameter67Value; + return this; + } + + public StreamCreator setParameter68Name(final String parameter68Name) { + this.parameter68Name = parameter68Name; + return this; + } + + public StreamCreator setParameter68Value(final String parameter68Value) { + this.parameter68Value = parameter68Value; + return this; + } + + public StreamCreator setParameter69Name(final String parameter69Name) { + this.parameter69Name = parameter69Name; + return this; + } + + public StreamCreator setParameter69Value(final String parameter69Value) { + this.parameter69Value = parameter69Value; + return this; + } + + public StreamCreator setParameter70Name(final String parameter70Name) { + this.parameter70Name = parameter70Name; + return this; + } + + public StreamCreator setParameter70Value(final String parameter70Value) { + this.parameter70Value = parameter70Value; + return this; + } + + public StreamCreator setParameter71Name(final String parameter71Name) { + this.parameter71Name = parameter71Name; + return this; + } + + public StreamCreator setParameter71Value(final String parameter71Value) { + this.parameter71Value = parameter71Value; + return this; + } + + public StreamCreator setParameter72Name(final String parameter72Name) { + this.parameter72Name = parameter72Name; + return this; + } + + public StreamCreator setParameter72Value(final String parameter72Value) { + this.parameter72Value = parameter72Value; + return this; + } + + public StreamCreator setParameter73Name(final String parameter73Name) { + this.parameter73Name = parameter73Name; + return this; + } + + public StreamCreator setParameter73Value(final String parameter73Value) { + this.parameter73Value = parameter73Value; + return this; + } + + public StreamCreator setParameter74Name(final String parameter74Name) { + this.parameter74Name = parameter74Name; + return this; + } + + public StreamCreator setParameter74Value(final String parameter74Value) { + this.parameter74Value = parameter74Value; + return this; + } + + public StreamCreator setParameter75Name(final String parameter75Name) { + this.parameter75Name = parameter75Name; + return this; + } + + public StreamCreator setParameter75Value(final String parameter75Value) { + this.parameter75Value = parameter75Value; + return this; + } + + public StreamCreator setParameter76Name(final String parameter76Name) { + this.parameter76Name = parameter76Name; + return this; + } + + public StreamCreator setParameter76Value(final String parameter76Value) { + this.parameter76Value = parameter76Value; + return this; + } + + public StreamCreator setParameter77Name(final String parameter77Name) { + this.parameter77Name = parameter77Name; + return this; + } + + public StreamCreator setParameter77Value(final String parameter77Value) { + this.parameter77Value = parameter77Value; + return this; + } + + public StreamCreator setParameter78Name(final String parameter78Name) { + this.parameter78Name = parameter78Name; + return this; + } + + public StreamCreator setParameter78Value(final String parameter78Value) { + this.parameter78Value = parameter78Value; + return this; + } + + public StreamCreator setParameter79Name(final String parameter79Name) { + this.parameter79Name = parameter79Name; + return this; + } + + public StreamCreator setParameter79Value(final String parameter79Value) { + this.parameter79Value = parameter79Value; + return this; + } + + public StreamCreator setParameter80Name(final String parameter80Name) { + this.parameter80Name = parameter80Name; + return this; + } + + public StreamCreator setParameter80Value(final String parameter80Value) { + this.parameter80Value = parameter80Value; + return this; + } + + public StreamCreator setParameter81Name(final String parameter81Name) { + this.parameter81Name = parameter81Name; + return this; + } + + public StreamCreator setParameter81Value(final String parameter81Value) { + this.parameter81Value = parameter81Value; + return this; + } + + public StreamCreator setParameter82Name(final String parameter82Name) { + this.parameter82Name = parameter82Name; + return this; + } + + public StreamCreator setParameter82Value(final String parameter82Value) { + this.parameter82Value = parameter82Value; + return this; + } + + public StreamCreator setParameter83Name(final String parameter83Name) { + this.parameter83Name = parameter83Name; + return this; + } + + public StreamCreator setParameter83Value(final String parameter83Value) { + this.parameter83Value = parameter83Value; + return this; + } + + public StreamCreator setParameter84Name(final String parameter84Name) { + this.parameter84Name = parameter84Name; + return this; + } + + public StreamCreator setParameter84Value(final String parameter84Value) { + this.parameter84Value = parameter84Value; + return this; + } + + public StreamCreator setParameter85Name(final String parameter85Name) { + this.parameter85Name = parameter85Name; + return this; + } + + public StreamCreator setParameter85Value(final String parameter85Value) { + this.parameter85Value = parameter85Value; + return this; + } + + public StreamCreator setParameter86Name(final String parameter86Name) { + this.parameter86Name = parameter86Name; + return this; + } + + public StreamCreator setParameter86Value(final String parameter86Value) { + this.parameter86Value = parameter86Value; + return this; + } + + public StreamCreator setParameter87Name(final String parameter87Name) { + this.parameter87Name = parameter87Name; + return this; + } + + public StreamCreator setParameter87Value(final String parameter87Value) { + this.parameter87Value = parameter87Value; + return this; + } + + public StreamCreator setParameter88Name(final String parameter88Name) { + this.parameter88Name = parameter88Name; + return this; + } + + public StreamCreator setParameter88Value(final String parameter88Value) { + this.parameter88Value = parameter88Value; + return this; + } + + public StreamCreator setParameter89Name(final String parameter89Name) { + this.parameter89Name = parameter89Name; + return this; + } + + public StreamCreator setParameter89Value(final String parameter89Value) { + this.parameter89Value = parameter89Value; + return this; + } + + public StreamCreator setParameter90Name(final String parameter90Name) { + this.parameter90Name = parameter90Name; + return this; + } + + public StreamCreator setParameter90Value(final String parameter90Value) { + this.parameter90Value = parameter90Value; + return this; + } + + public StreamCreator setParameter91Name(final String parameter91Name) { + this.parameter91Name = parameter91Name; + return this; + } + + public StreamCreator setParameter91Value(final String parameter91Value) { + this.parameter91Value = parameter91Value; + return this; + } + + public StreamCreator setParameter92Name(final String parameter92Name) { + this.parameter92Name = parameter92Name; + return this; + } + + public StreamCreator setParameter92Value(final String parameter92Value) { + this.parameter92Value = parameter92Value; + return this; + } + + public StreamCreator setParameter93Name(final String parameter93Name) { + this.parameter93Name = parameter93Name; + return this; + } + + public StreamCreator setParameter93Value(final String parameter93Value) { + this.parameter93Value = parameter93Value; + return this; + } + + public StreamCreator setParameter94Name(final String parameter94Name) { + this.parameter94Name = parameter94Name; + return this; + } + + public StreamCreator setParameter94Value(final String parameter94Value) { + this.parameter94Value = parameter94Value; + return this; + } + + public StreamCreator setParameter95Name(final String parameter95Name) { + this.parameter95Name = parameter95Name; + return this; + } + + public StreamCreator setParameter95Value(final String parameter95Value) { + this.parameter95Value = parameter95Value; + return this; + } + + public StreamCreator setParameter96Name(final String parameter96Name) { + this.parameter96Name = parameter96Name; + return this; + } + + public StreamCreator setParameter96Value(final String parameter96Value) { + this.parameter96Value = parameter96Value; + return this; + } + + public StreamCreator setParameter97Name(final String parameter97Name) { + this.parameter97Name = parameter97Name; + return this; + } + + public StreamCreator setParameter97Value(final String parameter97Value) { + this.parameter97Value = parameter97Value; + return this; + } + + public StreamCreator setParameter98Name(final String parameter98Name) { + this.parameter98Name = parameter98Name; + return this; + } + + public StreamCreator setParameter98Value(final String parameter98Value) { + this.parameter98Value = parameter98Value; + return this; + } + + public StreamCreator setParameter99Name(final String parameter99Name) { + this.parameter99Name = parameter99Name; + return this; + } + + public StreamCreator setParameter99Value(final String parameter99Value) { + this.parameter99Value = parameter99Value; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Stream creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Stream create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Stream.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Stream content = Stream.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (url != null) { + Serializer.toString(request, "Url", url, ParameterType.URLENCODED); + } + + if (name != null) { + Serializer.toString( + request, + "Name", + name, + ParameterType.URLENCODED + ); + } + + if (track != null) { + Serializer.toString( + request, + "Track", + track, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + + if (statusCallbackMethod != null) { + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (parameter1Name != null) { + Serializer.toString( + request, + "Parameter1.Name", + parameter1Name, + ParameterType.URLENCODED + ); + } + + if (parameter1Value != null) { + Serializer.toString( + request, + "Parameter1.Value", + parameter1Value, + ParameterType.URLENCODED + ); + } + + if (parameter2Name != null) { + Serializer.toString( + request, + "Parameter2.Name", + parameter2Name, + ParameterType.URLENCODED + ); + } + + if (parameter2Value != null) { + Serializer.toString( + request, + "Parameter2.Value", + parameter2Value, + ParameterType.URLENCODED + ); + } + + if (parameter3Name != null) { + Serializer.toString( + request, + "Parameter3.Name", + parameter3Name, + ParameterType.URLENCODED + ); + } + + if (parameter3Value != null) { + Serializer.toString( + request, + "Parameter3.Value", + parameter3Value, + ParameterType.URLENCODED + ); + } + + if (parameter4Name != null) { + Serializer.toString( + request, + "Parameter4.Name", + parameter4Name, + ParameterType.URLENCODED + ); + } + + if (parameter4Value != null) { + Serializer.toString( + request, + "Parameter4.Value", + parameter4Value, + ParameterType.URLENCODED + ); + } + + if (parameter5Name != null) { + Serializer.toString( + request, + "Parameter5.Name", + parameter5Name, + ParameterType.URLENCODED + ); + } + + if (parameter5Value != null) { + Serializer.toString( + request, + "Parameter5.Value", + parameter5Value, + ParameterType.URLENCODED + ); + } + + if (parameter6Name != null) { + Serializer.toString( + request, + "Parameter6.Name", + parameter6Name, + ParameterType.URLENCODED + ); + } + + if (parameter6Value != null) { + Serializer.toString( + request, + "Parameter6.Value", + parameter6Value, + ParameterType.URLENCODED + ); + } + + if (parameter7Name != null) { + Serializer.toString( + request, + "Parameter7.Name", + parameter7Name, + ParameterType.URLENCODED + ); + } + + if (parameter7Value != null) { + Serializer.toString( + request, + "Parameter7.Value", + parameter7Value, + ParameterType.URLENCODED + ); + } + + if (parameter8Name != null) { + Serializer.toString( + request, + "Parameter8.Name", + parameter8Name, + ParameterType.URLENCODED + ); + } + + if (parameter8Value != null) { + Serializer.toString( + request, + "Parameter8.Value", + parameter8Value, + ParameterType.URLENCODED + ); + } + + if (parameter9Name != null) { + Serializer.toString( + request, + "Parameter9.Name", + parameter9Name, + ParameterType.URLENCODED + ); + } + + if (parameter9Value != null) { + Serializer.toString( + request, + "Parameter9.Value", + parameter9Value, + ParameterType.URLENCODED + ); + } + + if (parameter10Name != null) { + Serializer.toString( + request, + "Parameter10.Name", + parameter10Name, + ParameterType.URLENCODED + ); + } + + if (parameter10Value != null) { + Serializer.toString( + request, + "Parameter10.Value", + parameter10Value, + ParameterType.URLENCODED + ); + } + + if (parameter11Name != null) { + Serializer.toString( + request, + "Parameter11.Name", + parameter11Name, + ParameterType.URLENCODED + ); + } + + if (parameter11Value != null) { + Serializer.toString( + request, + "Parameter11.Value", + parameter11Value, + ParameterType.URLENCODED + ); + } + + if (parameter12Name != null) { + Serializer.toString( + request, + "Parameter12.Name", + parameter12Name, + ParameterType.URLENCODED + ); + } + + if (parameter12Value != null) { + Serializer.toString( + request, + "Parameter12.Value", + parameter12Value, + ParameterType.URLENCODED + ); + } + + if (parameter13Name != null) { + Serializer.toString( + request, + "Parameter13.Name", + parameter13Name, + ParameterType.URLENCODED + ); + } + + if (parameter13Value != null) { + Serializer.toString( + request, + "Parameter13.Value", + parameter13Value, + ParameterType.URLENCODED + ); + } + + if (parameter14Name != null) { + Serializer.toString( + request, + "Parameter14.Name", + parameter14Name, + ParameterType.URLENCODED + ); + } + + if (parameter14Value != null) { + Serializer.toString( + request, + "Parameter14.Value", + parameter14Value, + ParameterType.URLENCODED + ); + } + + if (parameter15Name != null) { + Serializer.toString( + request, + "Parameter15.Name", + parameter15Name, + ParameterType.URLENCODED + ); + } + + if (parameter15Value != null) { + Serializer.toString( + request, + "Parameter15.Value", + parameter15Value, + ParameterType.URLENCODED + ); + } + + if (parameter16Name != null) { + Serializer.toString( + request, + "Parameter16.Name", + parameter16Name, + ParameterType.URLENCODED + ); + } + + if (parameter16Value != null) { + Serializer.toString( + request, + "Parameter16.Value", + parameter16Value, + ParameterType.URLENCODED + ); + } + + if (parameter17Name != null) { + Serializer.toString( + request, + "Parameter17.Name", + parameter17Name, + ParameterType.URLENCODED + ); + } + + if (parameter17Value != null) { + Serializer.toString( + request, + "Parameter17.Value", + parameter17Value, + ParameterType.URLENCODED + ); + } + + if (parameter18Name != null) { + Serializer.toString( + request, + "Parameter18.Name", + parameter18Name, + ParameterType.URLENCODED + ); + } + + if (parameter18Value != null) { + Serializer.toString( + request, + "Parameter18.Value", + parameter18Value, + ParameterType.URLENCODED + ); + } + + if (parameter19Name != null) { + Serializer.toString( + request, + "Parameter19.Name", + parameter19Name, + ParameterType.URLENCODED + ); + } + + if (parameter19Value != null) { + Serializer.toString( + request, + "Parameter19.Value", + parameter19Value, + ParameterType.URLENCODED + ); + } + + if (parameter20Name != null) { + Serializer.toString( + request, + "Parameter20.Name", + parameter20Name, + ParameterType.URLENCODED + ); + } + + if (parameter20Value != null) { + Serializer.toString( + request, + "Parameter20.Value", + parameter20Value, + ParameterType.URLENCODED + ); + } + + if (parameter21Name != null) { + Serializer.toString( + request, + "Parameter21.Name", + parameter21Name, + ParameterType.URLENCODED + ); + } + + if (parameter21Value != null) { + Serializer.toString( + request, + "Parameter21.Value", + parameter21Value, + ParameterType.URLENCODED + ); + } + + if (parameter22Name != null) { + Serializer.toString( + request, + "Parameter22.Name", + parameter22Name, + ParameterType.URLENCODED + ); + } + + if (parameter22Value != null) { + Serializer.toString( + request, + "Parameter22.Value", + parameter22Value, + ParameterType.URLENCODED + ); + } + + if (parameter23Name != null) { + Serializer.toString( + request, + "Parameter23.Name", + parameter23Name, + ParameterType.URLENCODED + ); + } + + if (parameter23Value != null) { + Serializer.toString( + request, + "Parameter23.Value", + parameter23Value, + ParameterType.URLENCODED + ); + } + + if (parameter24Name != null) { + Serializer.toString( + request, + "Parameter24.Name", + parameter24Name, + ParameterType.URLENCODED + ); + } + + if (parameter24Value != null) { + Serializer.toString( + request, + "Parameter24.Value", + parameter24Value, + ParameterType.URLENCODED + ); + } + + if (parameter25Name != null) { + Serializer.toString( + request, + "Parameter25.Name", + parameter25Name, + ParameterType.URLENCODED + ); + } + + if (parameter25Value != null) { + Serializer.toString( + request, + "Parameter25.Value", + parameter25Value, + ParameterType.URLENCODED + ); + } + + if (parameter26Name != null) { + Serializer.toString( + request, + "Parameter26.Name", + parameter26Name, + ParameterType.URLENCODED + ); + } + + if (parameter26Value != null) { + Serializer.toString( + request, + "Parameter26.Value", + parameter26Value, + ParameterType.URLENCODED + ); + } + + if (parameter27Name != null) { + Serializer.toString( + request, + "Parameter27.Name", + parameter27Name, + ParameterType.URLENCODED + ); + } + + if (parameter27Value != null) { + Serializer.toString( + request, + "Parameter27.Value", + parameter27Value, + ParameterType.URLENCODED + ); + } + + if (parameter28Name != null) { + Serializer.toString( + request, + "Parameter28.Name", + parameter28Name, + ParameterType.URLENCODED + ); + } + + if (parameter28Value != null) { + Serializer.toString( + request, + "Parameter28.Value", + parameter28Value, + ParameterType.URLENCODED + ); + } + + if (parameter29Name != null) { + Serializer.toString( + request, + "Parameter29.Name", + parameter29Name, + ParameterType.URLENCODED + ); + } + + if (parameter29Value != null) { + Serializer.toString( + request, + "Parameter29.Value", + parameter29Value, + ParameterType.URLENCODED + ); + } + + if (parameter30Name != null) { + Serializer.toString( + request, + "Parameter30.Name", + parameter30Name, + ParameterType.URLENCODED + ); + } + + if (parameter30Value != null) { + Serializer.toString( + request, + "Parameter30.Value", + parameter30Value, + ParameterType.URLENCODED + ); + } + + if (parameter31Name != null) { + Serializer.toString( + request, + "Parameter31.Name", + parameter31Name, + ParameterType.URLENCODED + ); + } + + if (parameter31Value != null) { + Serializer.toString( + request, + "Parameter31.Value", + parameter31Value, + ParameterType.URLENCODED + ); + } + + if (parameter32Name != null) { + Serializer.toString( + request, + "Parameter32.Name", + parameter32Name, + ParameterType.URLENCODED + ); + } + + if (parameter32Value != null) { + Serializer.toString( + request, + "Parameter32.Value", + parameter32Value, + ParameterType.URLENCODED + ); + } + + if (parameter33Name != null) { + Serializer.toString( + request, + "Parameter33.Name", + parameter33Name, + ParameterType.URLENCODED + ); + } + + if (parameter33Value != null) { + Serializer.toString( + request, + "Parameter33.Value", + parameter33Value, + ParameterType.URLENCODED + ); + } + + if (parameter34Name != null) { + Serializer.toString( + request, + "Parameter34.Name", + parameter34Name, + ParameterType.URLENCODED + ); + } + + if (parameter34Value != null) { + Serializer.toString( + request, + "Parameter34.Value", + parameter34Value, + ParameterType.URLENCODED + ); + } + + if (parameter35Name != null) { + Serializer.toString( + request, + "Parameter35.Name", + parameter35Name, + ParameterType.URLENCODED + ); + } + + if (parameter35Value != null) { + Serializer.toString( + request, + "Parameter35.Value", + parameter35Value, + ParameterType.URLENCODED + ); + } + + if (parameter36Name != null) { + Serializer.toString( + request, + "Parameter36.Name", + parameter36Name, + ParameterType.URLENCODED + ); + } + + if (parameter36Value != null) { + Serializer.toString( + request, + "Parameter36.Value", + parameter36Value, + ParameterType.URLENCODED + ); + } + + if (parameter37Name != null) { + Serializer.toString( + request, + "Parameter37.Name", + parameter37Name, + ParameterType.URLENCODED + ); + } + + if (parameter37Value != null) { + Serializer.toString( + request, + "Parameter37.Value", + parameter37Value, + ParameterType.URLENCODED + ); + } + + if (parameter38Name != null) { + Serializer.toString( + request, + "Parameter38.Name", + parameter38Name, + ParameterType.URLENCODED + ); + } + + if (parameter38Value != null) { + Serializer.toString( + request, + "Parameter38.Value", + parameter38Value, + ParameterType.URLENCODED + ); + } + + if (parameter39Name != null) { + Serializer.toString( + request, + "Parameter39.Name", + parameter39Name, + ParameterType.URLENCODED + ); + } + + if (parameter39Value != null) { + Serializer.toString( + request, + "Parameter39.Value", + parameter39Value, + ParameterType.URLENCODED + ); + } + + if (parameter40Name != null) { + Serializer.toString( + request, + "Parameter40.Name", + parameter40Name, + ParameterType.URLENCODED + ); + } + + if (parameter40Value != null) { + Serializer.toString( + request, + "Parameter40.Value", + parameter40Value, + ParameterType.URLENCODED + ); + } + + if (parameter41Name != null) { + Serializer.toString( + request, + "Parameter41.Name", + parameter41Name, + ParameterType.URLENCODED + ); + } + + if (parameter41Value != null) { + Serializer.toString( + request, + "Parameter41.Value", + parameter41Value, + ParameterType.URLENCODED + ); + } + + if (parameter42Name != null) { + Serializer.toString( + request, + "Parameter42.Name", + parameter42Name, + ParameterType.URLENCODED + ); + } + + if (parameter42Value != null) { + Serializer.toString( + request, + "Parameter42.Value", + parameter42Value, + ParameterType.URLENCODED + ); + } + + if (parameter43Name != null) { + Serializer.toString( + request, + "Parameter43.Name", + parameter43Name, + ParameterType.URLENCODED + ); + } + + if (parameter43Value != null) { + Serializer.toString( + request, + "Parameter43.Value", + parameter43Value, + ParameterType.URLENCODED + ); + } + + if (parameter44Name != null) { + Serializer.toString( + request, + "Parameter44.Name", + parameter44Name, + ParameterType.URLENCODED + ); + } + + if (parameter44Value != null) { + Serializer.toString( + request, + "Parameter44.Value", + parameter44Value, + ParameterType.URLENCODED + ); + } + + if (parameter45Name != null) { + Serializer.toString( + request, + "Parameter45.Name", + parameter45Name, + ParameterType.URLENCODED + ); + } + + if (parameter45Value != null) { + Serializer.toString( + request, + "Parameter45.Value", + parameter45Value, + ParameterType.URLENCODED + ); + } + + if (parameter46Name != null) { + Serializer.toString( + request, + "Parameter46.Name", + parameter46Name, + ParameterType.URLENCODED + ); + } + + if (parameter46Value != null) { + Serializer.toString( + request, + "Parameter46.Value", + parameter46Value, + ParameterType.URLENCODED + ); + } + + if (parameter47Name != null) { + Serializer.toString( + request, + "Parameter47.Name", + parameter47Name, + ParameterType.URLENCODED + ); + } + + if (parameter47Value != null) { + Serializer.toString( + request, + "Parameter47.Value", + parameter47Value, + ParameterType.URLENCODED + ); + } + + if (parameter48Name != null) { + Serializer.toString( + request, + "Parameter48.Name", + parameter48Name, + ParameterType.URLENCODED + ); + } + + if (parameter48Value != null) { + Serializer.toString( + request, + "Parameter48.Value", + parameter48Value, + ParameterType.URLENCODED + ); + } + + if (parameter49Name != null) { + Serializer.toString( + request, + "Parameter49.Name", + parameter49Name, + ParameterType.URLENCODED + ); + } + + if (parameter49Value != null) { + Serializer.toString( + request, + "Parameter49.Value", + parameter49Value, + ParameterType.URLENCODED + ); + } + + if (parameter50Name != null) { + Serializer.toString( + request, + "Parameter50.Name", + parameter50Name, + ParameterType.URLENCODED + ); + } + + if (parameter50Value != null) { + Serializer.toString( + request, + "Parameter50.Value", + parameter50Value, + ParameterType.URLENCODED + ); + } + + if (parameter51Name != null) { + Serializer.toString( + request, + "Parameter51.Name", + parameter51Name, + ParameterType.URLENCODED + ); + } + + if (parameter51Value != null) { + Serializer.toString( + request, + "Parameter51.Value", + parameter51Value, + ParameterType.URLENCODED + ); + } + + if (parameter52Name != null) { + Serializer.toString( + request, + "Parameter52.Name", + parameter52Name, + ParameterType.URLENCODED + ); + } + + if (parameter52Value != null) { + Serializer.toString( + request, + "Parameter52.Value", + parameter52Value, + ParameterType.URLENCODED + ); + } + + if (parameter53Name != null) { + Serializer.toString( + request, + "Parameter53.Name", + parameter53Name, + ParameterType.URLENCODED + ); + } + + if (parameter53Value != null) { + Serializer.toString( + request, + "Parameter53.Value", + parameter53Value, + ParameterType.URLENCODED + ); + } + + if (parameter54Name != null) { + Serializer.toString( + request, + "Parameter54.Name", + parameter54Name, + ParameterType.URLENCODED + ); + } + + if (parameter54Value != null) { + Serializer.toString( + request, + "Parameter54.Value", + parameter54Value, + ParameterType.URLENCODED + ); + } + + if (parameter55Name != null) { + Serializer.toString( + request, + "Parameter55.Name", + parameter55Name, + ParameterType.URLENCODED + ); + } + + if (parameter55Value != null) { + Serializer.toString( + request, + "Parameter55.Value", + parameter55Value, + ParameterType.URLENCODED + ); + } + + if (parameter56Name != null) { + Serializer.toString( + request, + "Parameter56.Name", + parameter56Name, + ParameterType.URLENCODED + ); + } + + if (parameter56Value != null) { + Serializer.toString( + request, + "Parameter56.Value", + parameter56Value, + ParameterType.URLENCODED + ); + } + + if (parameter57Name != null) { + Serializer.toString( + request, + "Parameter57.Name", + parameter57Name, + ParameterType.URLENCODED + ); + } + + if (parameter57Value != null) { + Serializer.toString( + request, + "Parameter57.Value", + parameter57Value, + ParameterType.URLENCODED + ); + } + + if (parameter58Name != null) { + Serializer.toString( + request, + "Parameter58.Name", + parameter58Name, + ParameterType.URLENCODED + ); + } + + if (parameter58Value != null) { + Serializer.toString( + request, + "Parameter58.Value", + parameter58Value, + ParameterType.URLENCODED + ); + } + + if (parameter59Name != null) { + Serializer.toString( + request, + "Parameter59.Name", + parameter59Name, + ParameterType.URLENCODED + ); + } + + if (parameter59Value != null) { + Serializer.toString( + request, + "Parameter59.Value", + parameter59Value, + ParameterType.URLENCODED + ); + } + + if (parameter60Name != null) { + Serializer.toString( + request, + "Parameter60.Name", + parameter60Name, + ParameterType.URLENCODED + ); + } + + if (parameter60Value != null) { + Serializer.toString( + request, + "Parameter60.Value", + parameter60Value, + ParameterType.URLENCODED + ); + } + + if (parameter61Name != null) { + Serializer.toString( + request, + "Parameter61.Name", + parameter61Name, + ParameterType.URLENCODED + ); + } + + if (parameter61Value != null) { + Serializer.toString( + request, + "Parameter61.Value", + parameter61Value, + ParameterType.URLENCODED + ); + } + + if (parameter62Name != null) { + Serializer.toString( + request, + "Parameter62.Name", + parameter62Name, + ParameterType.URLENCODED + ); + } + + if (parameter62Value != null) { + Serializer.toString( + request, + "Parameter62.Value", + parameter62Value, + ParameterType.URLENCODED + ); + } + + if (parameter63Name != null) { + Serializer.toString( + request, + "Parameter63.Name", + parameter63Name, + ParameterType.URLENCODED + ); + } + + if (parameter63Value != null) { + Serializer.toString( + request, + "Parameter63.Value", + parameter63Value, + ParameterType.URLENCODED + ); + } + + if (parameter64Name != null) { + Serializer.toString( + request, + "Parameter64.Name", + parameter64Name, + ParameterType.URLENCODED + ); + } + + if (parameter64Value != null) { + Serializer.toString( + request, + "Parameter64.Value", + parameter64Value, + ParameterType.URLENCODED + ); + } + + if (parameter65Name != null) { + Serializer.toString( + request, + "Parameter65.Name", + parameter65Name, + ParameterType.URLENCODED + ); + } + + if (parameter65Value != null) { + Serializer.toString( + request, + "Parameter65.Value", + parameter65Value, + ParameterType.URLENCODED + ); + } + + if (parameter66Name != null) { + Serializer.toString( + request, + "Parameter66.Name", + parameter66Name, + ParameterType.URLENCODED + ); + } + + if (parameter66Value != null) { + Serializer.toString( + request, + "Parameter66.Value", + parameter66Value, + ParameterType.URLENCODED + ); + } + + if (parameter67Name != null) { + Serializer.toString( + request, + "Parameter67.Name", + parameter67Name, + ParameterType.URLENCODED + ); + } + + if (parameter67Value != null) { + Serializer.toString( + request, + "Parameter67.Value", + parameter67Value, + ParameterType.URLENCODED + ); + } + + if (parameter68Name != null) { + Serializer.toString( + request, + "Parameter68.Name", + parameter68Name, + ParameterType.URLENCODED + ); + } + + if (parameter68Value != null) { + Serializer.toString( + request, + "Parameter68.Value", + parameter68Value, + ParameterType.URLENCODED + ); + } + + if (parameter69Name != null) { + Serializer.toString( + request, + "Parameter69.Name", + parameter69Name, + ParameterType.URLENCODED + ); + } + + if (parameter69Value != null) { + Serializer.toString( + request, + "Parameter69.Value", + parameter69Value, + ParameterType.URLENCODED + ); + } + + if (parameter70Name != null) { + Serializer.toString( + request, + "Parameter70.Name", + parameter70Name, + ParameterType.URLENCODED + ); + } + + if (parameter70Value != null) { + Serializer.toString( + request, + "Parameter70.Value", + parameter70Value, + ParameterType.URLENCODED + ); + } + + if (parameter71Name != null) { + Serializer.toString( + request, + "Parameter71.Name", + parameter71Name, + ParameterType.URLENCODED + ); + } + + if (parameter71Value != null) { + Serializer.toString( + request, + "Parameter71.Value", + parameter71Value, + ParameterType.URLENCODED + ); + } + + if (parameter72Name != null) { + Serializer.toString( + request, + "Parameter72.Name", + parameter72Name, + ParameterType.URLENCODED + ); + } + + if (parameter72Value != null) { + Serializer.toString( + request, + "Parameter72.Value", + parameter72Value, + ParameterType.URLENCODED + ); + } + + if (parameter73Name != null) { + Serializer.toString( + request, + "Parameter73.Name", + parameter73Name, + ParameterType.URLENCODED + ); + } + + if (parameter73Value != null) { + Serializer.toString( + request, + "Parameter73.Value", + parameter73Value, + ParameterType.URLENCODED + ); + } + + if (parameter74Name != null) { + Serializer.toString( + request, + "Parameter74.Name", + parameter74Name, + ParameterType.URLENCODED + ); + } + + if (parameter74Value != null) { + Serializer.toString( + request, + "Parameter74.Value", + parameter74Value, + ParameterType.URLENCODED + ); + } + + if (parameter75Name != null) { + Serializer.toString( + request, + "Parameter75.Name", + parameter75Name, + ParameterType.URLENCODED + ); + } + + if (parameter75Value != null) { + Serializer.toString( + request, + "Parameter75.Value", + parameter75Value, + ParameterType.URLENCODED + ); + } + + if (parameter76Name != null) { + Serializer.toString( + request, + "Parameter76.Name", + parameter76Name, + ParameterType.URLENCODED + ); + } + + if (parameter76Value != null) { + Serializer.toString( + request, + "Parameter76.Value", + parameter76Value, + ParameterType.URLENCODED + ); + } + + if (parameter77Name != null) { + Serializer.toString( + request, + "Parameter77.Name", + parameter77Name, + ParameterType.URLENCODED + ); + } + + if (parameter77Value != null) { + Serializer.toString( + request, + "Parameter77.Value", + parameter77Value, + ParameterType.URLENCODED + ); + } + + if (parameter78Name != null) { + Serializer.toString( + request, + "Parameter78.Name", + parameter78Name, + ParameterType.URLENCODED + ); + } + + if (parameter78Value != null) { + Serializer.toString( + request, + "Parameter78.Value", + parameter78Value, + ParameterType.URLENCODED + ); + } + + if (parameter79Name != null) { + Serializer.toString( + request, + "Parameter79.Name", + parameter79Name, + ParameterType.URLENCODED + ); + } + + if (parameter79Value != null) { + Serializer.toString( + request, + "Parameter79.Value", + parameter79Value, + ParameterType.URLENCODED + ); + } + + if (parameter80Name != null) { + Serializer.toString( + request, + "Parameter80.Name", + parameter80Name, + ParameterType.URLENCODED + ); + } + + if (parameter80Value != null) { + Serializer.toString( + request, + "Parameter80.Value", + parameter80Value, + ParameterType.URLENCODED + ); + } + + if (parameter81Name != null) { + Serializer.toString( + request, + "Parameter81.Name", + parameter81Name, + ParameterType.URLENCODED + ); + } + + if (parameter81Value != null) { + Serializer.toString( + request, + "Parameter81.Value", + parameter81Value, + ParameterType.URLENCODED + ); + } + + if (parameter82Name != null) { + Serializer.toString( + request, + "Parameter82.Name", + parameter82Name, + ParameterType.URLENCODED + ); + } + + if (parameter82Value != null) { + Serializer.toString( + request, + "Parameter82.Value", + parameter82Value, + ParameterType.URLENCODED + ); + } + + if (parameter83Name != null) { + Serializer.toString( + request, + "Parameter83.Name", + parameter83Name, + ParameterType.URLENCODED + ); + } + + if (parameter83Value != null) { + Serializer.toString( + request, + "Parameter83.Value", + parameter83Value, + ParameterType.URLENCODED + ); + } + + if (parameter84Name != null) { + Serializer.toString( + request, + "Parameter84.Name", + parameter84Name, + ParameterType.URLENCODED + ); + } + + if (parameter84Value != null) { + Serializer.toString( + request, + "Parameter84.Value", + parameter84Value, + ParameterType.URLENCODED + ); + } + + if (parameter85Name != null) { + Serializer.toString( + request, + "Parameter85.Name", + parameter85Name, + ParameterType.URLENCODED + ); + } + + if (parameter85Value != null) { + Serializer.toString( + request, + "Parameter85.Value", + parameter85Value, + ParameterType.URLENCODED + ); + } + + if (parameter86Name != null) { + Serializer.toString( + request, + "Parameter86.Name", + parameter86Name, + ParameterType.URLENCODED + ); + } + + if (parameter86Value != null) { + Serializer.toString( + request, + "Parameter86.Value", + parameter86Value, + ParameterType.URLENCODED + ); + } + + if (parameter87Name != null) { + Serializer.toString( + request, + "Parameter87.Name", + parameter87Name, + ParameterType.URLENCODED + ); + } + + if (parameter87Value != null) { + Serializer.toString( + request, + "Parameter87.Value", + parameter87Value, + ParameterType.URLENCODED + ); + } + + if (parameter88Name != null) { + Serializer.toString( + request, + "Parameter88.Name", + parameter88Name, + ParameterType.URLENCODED + ); + } + + if (parameter88Value != null) { + Serializer.toString( + request, + "Parameter88.Value", + parameter88Value, + ParameterType.URLENCODED + ); + } + + if (parameter89Name != null) { + Serializer.toString( + request, + "Parameter89.Name", + parameter89Name, + ParameterType.URLENCODED + ); + } + + if (parameter89Value != null) { + Serializer.toString( + request, + "Parameter89.Value", + parameter89Value, + ParameterType.URLENCODED + ); + } + + if (parameter90Name != null) { + Serializer.toString( + request, + "Parameter90.Name", + parameter90Name, + ParameterType.URLENCODED + ); + } + + if (parameter90Value != null) { + Serializer.toString( + request, + "Parameter90.Value", + parameter90Value, + ParameterType.URLENCODED + ); + } + + if (parameter91Name != null) { + Serializer.toString( + request, + "Parameter91.Name", + parameter91Name, + ParameterType.URLENCODED + ); + } + + if (parameter91Value != null) { + Serializer.toString( + request, + "Parameter91.Value", + parameter91Value, + ParameterType.URLENCODED + ); + } + + if (parameter92Name != null) { + Serializer.toString( + request, + "Parameter92.Name", + parameter92Name, + ParameterType.URLENCODED + ); + } + + if (parameter92Value != null) { + Serializer.toString( + request, + "Parameter92.Value", + parameter92Value, + ParameterType.URLENCODED + ); + } + + if (parameter93Name != null) { + Serializer.toString( + request, + "Parameter93.Name", + parameter93Name, + ParameterType.URLENCODED + ); + } + + if (parameter93Value != null) { + Serializer.toString( + request, + "Parameter93.Value", + parameter93Value, + ParameterType.URLENCODED + ); + } + + if (parameter94Name != null) { + Serializer.toString( + request, + "Parameter94.Name", + parameter94Name, + ParameterType.URLENCODED + ); + } + + if (parameter94Value != null) { + Serializer.toString( + request, + "Parameter94.Value", + parameter94Value, + ParameterType.URLENCODED + ); + } + + if (parameter95Name != null) { + Serializer.toString( + request, + "Parameter95.Name", + parameter95Name, + ParameterType.URLENCODED + ); + } + + if (parameter95Value != null) { + Serializer.toString( + request, + "Parameter95.Value", + parameter95Value, + ParameterType.URLENCODED + ); + } + + if (parameter96Name != null) { + Serializer.toString( + request, + "Parameter96.Name", + parameter96Name, + ParameterType.URLENCODED + ); + } + + if (parameter96Value != null) { + Serializer.toString( + request, + "Parameter96.Value", + parameter96Value, + ParameterType.URLENCODED + ); + } + + if (parameter97Name != null) { + Serializer.toString( + request, + "Parameter97.Name", + parameter97Name, + ParameterType.URLENCODED + ); + } + + if (parameter97Value != null) { + Serializer.toString( + request, + "Parameter97.Value", + parameter97Value, + ParameterType.URLENCODED + ); + } + + if (parameter98Name != null) { + Serializer.toString( + request, + "Parameter98.Name", + parameter98Name, + ParameterType.URLENCODED + ); + } + + if (parameter98Value != null) { + Serializer.toString( + request, + "Parameter98.Value", + parameter98Value, + ParameterType.URLENCODED + ); + } + + if (parameter99Name != null) { + Serializer.toString( + request, + "Parameter99.Name", + parameter99Name, + ParameterType.URLENCODED + ); + } + + if (parameter99Value != null) { + Serializer.toString( + request, + "Parameter99.Value", + parameter99Value, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/StreamUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/StreamUpdater.java new file mode 100644 index 0000000000..efbbc971dc --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/StreamUpdater.java @@ -0,0 +1,146 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class StreamUpdater extends Updater { + + private String pathAccountSid; + private String pathCallSid; + private String pathSid; + private Stream.UpdateStatus status; + + public StreamUpdater( + final String pathCallSid, + final String pathSid, + final Stream.UpdateStatus status + ) { + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.status = status; + } + + public StreamUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Stream.UpdateStatus status + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.status = status; + } + + public StreamUpdater setStatus(final Stream.UpdateStatus status) { + this.status = status; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Streams/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Stream update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Stream update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Stream.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Stream content = Stream.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/Transcription.java b/src/main/java/com/twilio/rest/api/v2010/account/call/Transcription.java new file mode 100644 index 0000000000..b69fbf3640 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/Transcription.java @@ -0,0 +1,272 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Transcription extends Resource { + + public static TranscriptionCreator creator(final String pathCallSid) { + return new TranscriptionCreator(pathCallSid); + } + + public static TranscriptionCreator creator( + final String pathAccountSid, + final String pathCallSid + ) { + return new TranscriptionCreator(pathAccountSid, pathCallSid); + } + + public static TranscriptionUpdater updater( + final String pathCallSid, + final String pathSid, + final Transcription.UpdateStatus status + ) { + return new TranscriptionUpdater(pathCallSid, pathSid, status); + } + + public static TranscriptionUpdater updater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Transcription.UpdateStatus status + ) { + return new TranscriptionUpdater( + pathAccountSid, + pathCallSid, + pathSid, + status + ); + } + + public enum Status { + IN_PROGRESS("in-progress"), + STOPPED("stopped"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum UpdateStatus { + STOPPED("stopped"); + + private final String value; + + private UpdateStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static UpdateStatus forValue(final String value) { + return Promoter.enumFromString(value, UpdateStatus.values()); + } + } + + public enum Track { + INBOUND_TRACK("inbound_track"), + OUTBOUND_TRACK("outbound_track"), + BOTH_TRACKS("both_tracks"); + + private final String value; + + private Track(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Track forValue(final String value) { + return Promoter.enumFromString(value, Track.values()); + } + } + + /** + * Converts a JSON String into a Transcription object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Transcription object represented by the provided JSON + */ + public static Transcription fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Transcription.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Transcription object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Transcription object represented by the provided JSON + */ + public static Transcription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Transcription.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String name; + + @Getter + private final String sid; + + @Getter + private final Transcription.Status status; + + @Getter + private final String uri; + + @JsonCreator + private Transcription( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("name") final String name, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Transcription.Status status, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.dateUpdated = dateUpdated; + this.name = name; + this.sid = sid; + this.status = status; + this.uri = uri; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Transcription other = (Transcription) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(name, other.name) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(uri, other.uri) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + callSid, + dateUpdated, + name, + sid, + status, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/TranscriptionCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/TranscriptionCreator.java new file mode 100644 index 0000000000..4549086f29 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/TranscriptionCreator.java @@ -0,0 +1,424 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class TranscriptionCreator extends Creator { + + private String pathAccountSid; + private String pathCallSid; + private String name; + private Transcription.Track track; + private URI statusCallbackUrl; + private HttpMethod statusCallbackMethod; + private String inboundTrackLabel; + private String outboundTrackLabel; + private Boolean partialResults; + private String languageCode; + private String transcriptionEngine; + private Boolean profanityFilter; + private String speechModel; + private String hints; + private Boolean enableAutomaticPunctuation; + private String intelligenceService; + private String conversationConfiguration; + private String conversationId; + private String transcriptionConfigurationId; + private Boolean enableProviderData; + + public TranscriptionCreator(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + public TranscriptionCreator( + final String pathAccountSid, + final String pathCallSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + } + + public TranscriptionCreator setName(final String name) { + this.name = name; + return this; + } + + public TranscriptionCreator setTrack(final Transcription.Track track) { + this.track = track; + return this; + } + + public TranscriptionCreator setStatusCallbackUrl( + final URI statusCallbackUrl + ) { + this.statusCallbackUrl = statusCallbackUrl; + return this; + } + + public TranscriptionCreator setStatusCallbackUrl( + final String statusCallbackUrl + ) { + return setStatusCallbackUrl(Promoter.uriFromString(statusCallbackUrl)); + } + + public TranscriptionCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + public TranscriptionCreator setInboundTrackLabel( + final String inboundTrackLabel + ) { + this.inboundTrackLabel = inboundTrackLabel; + return this; + } + + public TranscriptionCreator setOutboundTrackLabel( + final String outboundTrackLabel + ) { + this.outboundTrackLabel = outboundTrackLabel; + return this; + } + + public TranscriptionCreator setPartialResults( + final Boolean partialResults + ) { + this.partialResults = partialResults; + return this; + } + + public TranscriptionCreator setLanguageCode(final String languageCode) { + this.languageCode = languageCode; + return this; + } + + public TranscriptionCreator setTranscriptionEngine( + final String transcriptionEngine + ) { + this.transcriptionEngine = transcriptionEngine; + return this; + } + + public TranscriptionCreator setProfanityFilter( + final Boolean profanityFilter + ) { + this.profanityFilter = profanityFilter; + return this; + } + + public TranscriptionCreator setSpeechModel(final String speechModel) { + this.speechModel = speechModel; + return this; + } + + public TranscriptionCreator setHints(final String hints) { + this.hints = hints; + return this; + } + + public TranscriptionCreator setEnableAutomaticPunctuation( + final Boolean enableAutomaticPunctuation + ) { + this.enableAutomaticPunctuation = enableAutomaticPunctuation; + return this; + } + + public TranscriptionCreator setIntelligenceService( + final String intelligenceService + ) { + this.intelligenceService = intelligenceService; + return this; + } + + public TranscriptionCreator setConversationConfiguration( + final String conversationConfiguration + ) { + this.conversationConfiguration = conversationConfiguration; + return this; + } + + public TranscriptionCreator setConversationId(final String conversationId) { + this.conversationId = conversationId; + return this; + } + + public TranscriptionCreator setTranscriptionConfigurationId( + final String transcriptionConfigurationId + ) { + this.transcriptionConfigurationId = transcriptionConfigurationId; + return this; + } + + public TranscriptionCreator setEnableProviderData( + final Boolean enableProviderData + ) { + this.enableProviderData = enableProviderData; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Transcriptions.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Transcription creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Transcription create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Transcription content = Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (name != null) { + Serializer.toString( + request, + "Name", + name, + ParameterType.URLENCODED + ); + } + + if (track != null) { + Serializer.toString( + request, + "Track", + track, + ParameterType.URLENCODED + ); + } + + if (statusCallbackUrl != null) { + Serializer.toString( + request, + "StatusCallbackUrl", + statusCallbackUrl, + ParameterType.URLENCODED + ); + } + + if (statusCallbackMethod != null) { + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (inboundTrackLabel != null) { + Serializer.toString( + request, + "InboundTrackLabel", + inboundTrackLabel, + ParameterType.URLENCODED + ); + } + + if (outboundTrackLabel != null) { + Serializer.toString( + request, + "OutboundTrackLabel", + outboundTrackLabel, + ParameterType.URLENCODED + ); + } + + if (partialResults != null) { + Serializer.toString( + request, + "PartialResults", + partialResults, + ParameterType.URLENCODED + ); + } + + if (languageCode != null) { + Serializer.toString( + request, + "LanguageCode", + languageCode, + ParameterType.URLENCODED + ); + } + + if (transcriptionEngine != null) { + Serializer.toString( + request, + "TranscriptionEngine", + transcriptionEngine, + ParameterType.URLENCODED + ); + } + + if (profanityFilter != null) { + Serializer.toString( + request, + "ProfanityFilter", + profanityFilter, + ParameterType.URLENCODED + ); + } + + if (speechModel != null) { + Serializer.toString( + request, + "SpeechModel", + speechModel, + ParameterType.URLENCODED + ); + } + + if (hints != null) { + Serializer.toString( + request, + "Hints", + hints, + ParameterType.URLENCODED + ); + } + + if (enableAutomaticPunctuation != null) { + Serializer.toString( + request, + "EnableAutomaticPunctuation", + enableAutomaticPunctuation, + ParameterType.URLENCODED + ); + } + + if (intelligenceService != null) { + Serializer.toString( + request, + "IntelligenceService", + intelligenceService, + ParameterType.URLENCODED + ); + } + + if (conversationConfiguration != null) { + Serializer.toString( + request, + "ConversationConfiguration", + conversationConfiguration, + ParameterType.URLENCODED + ); + } + + if (conversationId != null) { + Serializer.toString( + request, + "ConversationId", + conversationId, + ParameterType.URLENCODED + ); + } + + if (transcriptionConfigurationId != null) { + Serializer.toString( + request, + "TranscriptionConfigurationId", + transcriptionConfigurationId, + ParameterType.URLENCODED + ); + } + + if (enableProviderData != null) { + Serializer.toString( + request, + "EnableProviderData", + enableProviderData, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/TranscriptionUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/call/TranscriptionUpdater.java new file mode 100644 index 0000000000..1d70a443ad --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/TranscriptionUpdater.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TranscriptionUpdater extends Updater { + + private String pathAccountSid; + private String pathCallSid; + private String pathSid; + private Transcription.UpdateStatus status; + + public TranscriptionUpdater( + final String pathCallSid, + final String pathSid, + final Transcription.UpdateStatus status + ) { + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.status = status; + } + + public TranscriptionUpdater( + final String pathAccountSid, + final String pathCallSid, + final String pathSid, + final Transcription.UpdateStatus status + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + this.status = status; + } + + public TranscriptionUpdater setStatus( + final Transcription.UpdateStatus status + ) { + this.status = status; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/Transcriptions/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Transcription update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Transcription update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Transcription content = Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessage.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessage.java new file mode 100644 index 0000000000..709c3bf029 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessage.java @@ -0,0 +1,167 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class UserDefinedMessage extends Resource { + + public static UserDefinedMessageCreator creator( + final String pathCallSid, + final String content + ) { + return new UserDefinedMessageCreator(pathCallSid, content); + } + + public static UserDefinedMessageCreator creator( + final String pathAccountSid, + final String pathCallSid, + final String content + ) { + return new UserDefinedMessageCreator( + pathAccountSid, + pathCallSid, + content + ); + } + + /** + * Converts a JSON String into a UserDefinedMessage object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserDefinedMessage object represented by the provided JSON + */ + public static UserDefinedMessage fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UserDefinedMessage.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a UserDefinedMessage object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserDefinedMessage object represented by the provided JSON + */ + public static UserDefinedMessage fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UserDefinedMessage.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String sid; + + @JsonCreator + private UserDefinedMessage( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("sid") final String sid + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.dateCreated = dateCreated; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UserDefinedMessage other = (UserDefinedMessage) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, callSid, dateCreated, sid); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageCreator.java new file mode 100644 index 0000000000..8604b6266b --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageCreator.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserDefinedMessageCreator extends Creator { + + private String pathAccountSid; + private String pathCallSid; + private String content; + private String idempotencyKey; + + public UserDefinedMessageCreator( + final String pathCallSid, + final String content + ) { + this.pathCallSid = pathCallSid; + this.content = content; + } + + public UserDefinedMessageCreator( + final String pathAccountSid, + final String pathCallSid, + final String content + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.content = content; + } + + public UserDefinedMessageCreator setContent(final String content) { + this.content = content; + return this; + } + + public UserDefinedMessageCreator setIdempotencyKey( + final String idempotencyKey + ) { + this.idempotencyKey = idempotencyKey; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessages.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserDefinedMessage creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserDefinedMessage create(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserDefinedMessage.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserDefinedMessage content = UserDefinedMessage.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (content != null) { + Serializer.toString( + request, + "Content", + content, + ParameterType.URLENCODED + ); + } + + if (idempotencyKey != null) { + Serializer.toString( + request, + "IdempotencyKey", + idempotencyKey, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscription.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscription.java new file mode 100644 index 0000000000..b6f959a8d2 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscription.java @@ -0,0 +1,200 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class UserDefinedMessageSubscription extends Resource { + + public static UserDefinedMessageSubscriptionCreator creator( + final String pathCallSid, + final URI callback + ) { + return new UserDefinedMessageSubscriptionCreator(pathCallSid, callback); + } + + public static UserDefinedMessageSubscriptionCreator creator( + final String pathAccountSid, + final String pathCallSid, + final URI callback + ) { + return new UserDefinedMessageSubscriptionCreator( + pathAccountSid, + pathCallSid, + callback + ); + } + + public static UserDefinedMessageSubscriptionDeleter deleter( + final String pathCallSid, + final String pathSid + ) { + return new UserDefinedMessageSubscriptionDeleter(pathCallSid, pathSid); + } + + public static UserDefinedMessageSubscriptionDeleter deleter( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { + return new UserDefinedMessageSubscriptionDeleter( + pathAccountSid, + pathCallSid, + pathSid + ); + } + + /** + * Converts a JSON String into a UserDefinedMessageSubscription object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserDefinedMessageSubscription object represented by the provided JSON + */ + public static UserDefinedMessageSubscription fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UserDefinedMessageSubscription.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a UserDefinedMessageSubscription object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserDefinedMessageSubscription object represented by the provided JSON + */ + public static UserDefinedMessageSubscription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UserDefinedMessageSubscription.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String sid; + + @Getter + private final String uri; + + @JsonCreator + private UserDefinedMessageSubscription( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.dateCreated = dateCreated; + this.sid = sid; + this.uri = uri; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UserDefinedMessageSubscription other = + (UserDefinedMessageSubscription) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, callSid, dateCreated, sid, uri); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionCreator.java new file mode 100644 index 0000000000..72c1115491 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionCreator.java @@ -0,0 +1,191 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class UserDefinedMessageSubscriptionCreator + extends Creator { + + private String pathAccountSid; + private String pathCallSid; + private URI callback; + private String idempotencyKey; + private HttpMethod method; + + public UserDefinedMessageSubscriptionCreator( + final String pathCallSid, + final URI callback + ) { + this.pathCallSid = pathCallSid; + this.callback = callback; + } + + public UserDefinedMessageSubscriptionCreator( + final String pathAccountSid, + final String pathCallSid, + final URI callback + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.callback = callback; + } + + public UserDefinedMessageSubscriptionCreator setCallback( + final URI callback + ) { + this.callback = callback; + return this; + } + + public UserDefinedMessageSubscriptionCreator setCallback( + final String callback + ) { + return setCallback(Promoter.uriFromString(callback)); + } + + public UserDefinedMessageSubscriptionCreator setIdempotencyKey( + final String idempotencyKey + ) { + this.idempotencyKey = idempotencyKey; + return this; + } + + public UserDefinedMessageSubscriptionCreator setMethod( + final HttpMethod method + ) { + this.method = method; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserDefinedMessageSubscription creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserDefinedMessageSubscription create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return UserDefinedMessageSubscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserDefinedMessageSubscription content = + UserDefinedMessageSubscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (callback != null) { + Serializer.toString( + request, + "Callback", + callback, + ParameterType.URLENCODED + ); + } + + if (idempotencyKey != null) { + Serializer.toString( + request, + "IdempotencyKey", + idempotencyKey, + ParameterType.URLENCODED + ); + } + + if (method != null) { + Serializer.toString( + request, + "Method", + method, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionDeleter.java new file mode 100644 index 0000000000..45348e8948 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/call/UserDefinedMessageSubscriptionDeleter.java @@ -0,0 +1,125 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.call; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UserDefinedMessageSubscriptionDeleter + extends Deleter { + + private String pathAccountSid; + private String pathCallSid; + private String pathSid; + + public UserDefinedMessageSubscriptionDeleter( + final String pathCallSid, + final String pathSid + ) { + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + } + + public UserDefinedMessageSubscriptionDeleter( + final String pathAccountSid, + final String pathCallSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathCallSid = pathCallSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Calls/{CallSid}/UserDefinedMessageSubscriptions/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserDefinedMessageSubscription delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/Participant.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/Participant.java index 6f30be45ef..f236cda05b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/Participant.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/Participant.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.conference; @@ -10,31 +17,120 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Participant extends Resource { - private static final long serialVersionUID = 203274866801868L; + + public static ParticipantCreator creator( + final String pathConferenceSid, + final com.twilio.type.Endpoint from, + final com.twilio.type.Endpoint to + ) { + return new ParticipantCreator(pathConferenceSid, from, to); + } + + public static ParticipantCreator creator( + final String pathAccountSid, + final String pathConferenceSid, + final com.twilio.type.Endpoint from, + final com.twilio.type.Endpoint to + ) { + return new ParticipantCreator( + pathAccountSid, + pathConferenceSid, + from, + to + ); + } + + public static ParticipantDeleter deleter( + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantDeleter(pathConferenceSid, pathCallSid); + } + + public static ParticipantDeleter deleter( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantDeleter( + pathAccountSid, + pathConferenceSid, + pathCallSid + ); + } + + public static ParticipantFetcher fetcher( + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantFetcher(pathConferenceSid, pathCallSid); + } + + public static ParticipantFetcher fetcher( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantFetcher( + pathAccountSid, + pathConferenceSid, + pathCallSid + ); + } + + public static ParticipantReader reader(final String pathConferenceSid) { + return new ParticipantReader(pathConferenceSid); + } + + public static ParticipantReader reader( + final String pathAccountSid, + final String pathConferenceSid + ) { + return new ParticipantReader(pathAccountSid, pathConferenceSid); + } + + public static ParticipantUpdater updater( + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantUpdater(pathConferenceSid, pathCallSid); + } + + public static ParticipantUpdater updater( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { + return new ParticipantUpdater( + pathAccountSid, + pathConferenceSid, + pathCallSid + ); + } public enum Status { QUEUED("queued"), @@ -50,15 +146,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -66,144 +158,16 @@ public static Status forValue(final String value) { } /** - * Create a ParticipantFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - * @return ParticipantFetcher capable of executing the fetch - */ - public static ParticipantFetcher fetcher(final String pathAccountSid, - final String pathConferenceSid, - final String pathCallSid) { - return new ParticipantFetcher(pathAccountSid, pathConferenceSid, pathCallSid); - } - - /** - * Create a ParticipantFetcher to execute fetch. - * - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - * @return ParticipantFetcher capable of executing the fetch - */ - public static ParticipantFetcher fetcher(final String pathConferenceSid, - final String pathCallSid) { - return new ParticipantFetcher(pathConferenceSid, pathCallSid); - } - - /** - * Create a ParticipantUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - * @return ParticipantUpdater capable of executing the update - */ - public static ParticipantUpdater updater(final String pathAccountSid, - final String pathConferenceSid, - final String pathCallSid) { - return new ParticipantUpdater(pathAccountSid, pathConferenceSid, pathCallSid); - } - - /** - * Create a ParticipantUpdater to execute update. - * - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - * @return ParticipantUpdater capable of executing the update - */ - public static ParticipantUpdater updater(final String pathConferenceSid, - final String pathCallSid) { - return new ParticipantUpdater(pathConferenceSid, pathCallSid); - } - - /** - * Create a ParticipantCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The conference_sid - * @param from number, client id - * @param to number, client id, sip address - * @return ParticipantCreator capable of executing the create - */ - public static ParticipantCreator creator(final String pathAccountSid, - final String pathConferenceSid, - final com.twilio.type.PhoneNumber from, - final com.twilio.type.PhoneNumber to) { - return new ParticipantCreator(pathAccountSid, pathConferenceSid, from, to); - } - - /** - * Create a ParticipantCreator to execute create. - * - * @param pathConferenceSid The conference_sid - * @param from number, client id - * @param to number, client id, sip address - * @return ParticipantCreator capable of executing the create - */ - public static ParticipantCreator creator(final String pathConferenceSid, - final com.twilio.type.PhoneNumber from, - final com.twilio.type.PhoneNumber to) { - return new ParticipantCreator(pathConferenceSid, from, to); - } - - /** - * Create a ParticipantDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - * @return ParticipantDeleter capable of executing the delete - */ - public static ParticipantDeleter deleter(final String pathAccountSid, - final String pathConferenceSid, - final String pathCallSid) { - return new ParticipantDeleter(pathAccountSid, pathConferenceSid, pathCallSid); - } - - /** - * Create a ParticipantDeleter to execute delete. - * - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - * @return ParticipantDeleter capable of executing the delete - */ - public static ParticipantDeleter deleter(final String pathConferenceSid, - final String pathCallSid) { - return new ParticipantDeleter(pathConferenceSid, pathCallSid); - } - - /** - * Create a ParticipantReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The string that uniquely identifies this conference - * @return ParticipantReader capable of executing the read - */ - public static ParticipantReader reader(final String pathAccountSid, - final String pathConferenceSid) { - return new ParticipantReader(pathAccountSid, pathConferenceSid); - } - - /** - * Create a ParticipantReader to execute read. - * - * @param pathConferenceSid The string that uniquely identifies this conference - * @return ParticipantReader capable of executing the read - */ - public static ParticipantReader reader(final String pathConferenceSid) { - return new ParticipantReader(pathConferenceSid); - } - - /** - * Converts a JSON String into a Participant object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Participant object represented by the provided JSON */ - public static Participant fromJson(final String json, final ObjectMapper objectMapper) { + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -217,12 +181,15 @@ public static Participant fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a Participant object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Participant object represented by the provided JSON */ - public static Participant fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -233,153 +200,106 @@ public static Participant fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String callSid; + + @Getter + private final String callSidToCoach; + + @Getter + private final Boolean coaching; + + @Getter private final String conferenceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final Boolean endConferenceOnExit; - private final Boolean muted; + + @Getter private final Boolean hold; + + @Getter + private final String label; + + @Getter + private final Boolean muted; + + @Getter + private final String queueTime; + + @Getter private final Boolean startConferenceOnEnter; + + @Getter private final Participant.Status status; + + @Getter private final String uri; @JsonCreator - private Participant(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("call_sid") - final String callSid, - @JsonProperty("conference_sid") - final String conferenceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("end_conference_on_exit") - final Boolean endConferenceOnExit, - @JsonProperty("muted") - final Boolean muted, - @JsonProperty("hold") - final Boolean hold, - @JsonProperty("start_conference_on_enter") - final Boolean startConferenceOnEnter, - @JsonProperty("status") - final Participant.Status status, - @JsonProperty("uri") - final String uri) { + private Participant( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("call_sid_to_coach") final String callSidToCoach, + @JsonProperty("coaching") final Boolean coaching, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "end_conference_on_exit" + ) final Boolean endConferenceOnExit, + @JsonProperty("hold") final Boolean hold, + @JsonProperty("label") final String label, + @JsonProperty("muted") final Boolean muted, + @JsonProperty("queue_time") final String queueTime, + @JsonProperty( + "start_conference_on_enter" + ) final Boolean startConferenceOnEnter, + @JsonProperty("status") final Participant.Status status, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.callSid = callSid; + this.callSidToCoach = callSidToCoach; + this.coaching = coaching; this.conferenceSid = conferenceSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.endConferenceOnExit = endConferenceOnExit; - this.muted = muted; this.hold = hold; + this.label = label; + this.muted = muted; + this.queueTime = queueTime; this.startConferenceOnEnter = startConferenceOnEnter; this.status = status; this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The A string that uniquely identifies this call. - * - * @return A string that uniquely identifies this call - */ - public final String getCallSid() { - return this.callSid; - } - - /** - * Returns The A string that uniquely identifies this conference. - * - * @return A string that uniquely identifies this conference - */ - public final String getConferenceSid() { - return this.conferenceSid; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Indicates if the endConferenceOnExit was set. - * - * @return Indicates if the endConferenceOnExit was set - */ - public final Boolean getEndConferenceOnExit() { - return this.endConferenceOnExit; - } - - /** - * Returns The Indicates if the participant is muted. - * - * @return Indicates if the participant is muted - */ - public final Boolean getMuted() { - return this.muted; - } - - /** - * Returns The true if this participant is currently held.. - * - * @return true if this participant is currently held. - */ - public final Boolean getHold() { - return this.hold; - } - - /** - * Returns The Indicates if the startConferenceOnEnter attribute was set. - * - * @return Indicates if the startConferenceOnEnter attribute was set - */ - public final Boolean getStartConferenceOnEnter() { - return this.startConferenceOnEnter; - } - - /** - * Returns The The status. - * - * @return The status - */ - public final Participant.Status getStatus() { - return this.status; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -391,49 +311,46 @@ public boolean equals(final Object o) { } Participant other = (Participant) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(callSid, other.callSid) && - Objects.equals(conferenceSid, other.conferenceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(endConferenceOnExit, other.endConferenceOnExit) && - Objects.equals(muted, other.muted) && - Objects.equals(hold, other.hold) && - Objects.equals(startConferenceOnEnter, other.startConferenceOnEnter) && - Objects.equals(status, other.status) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(callSidToCoach, other.callSidToCoach) && + Objects.equals(coaching, other.coaching) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endConferenceOnExit, other.endConferenceOnExit) && + Objects.equals(hold, other.hold) && + Objects.equals(label, other.label) && + Objects.equals(muted, other.muted) && + Objects.equals(queueTime, other.queueTime) && + Objects.equals( + startConferenceOnEnter, + other.startConferenceOnEnter + ) && + Objects.equals(status, other.status) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - callSid, - conferenceSid, - dateCreated, - dateUpdated, - endConferenceOnExit, - muted, - hold, - startConferenceOnEnter, - status, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("callSid", callSid) - .add("conferenceSid", conferenceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("endConferenceOnExit", endConferenceOnExit) - .add("muted", muted) - .add("hold", hold) - .add("startConferenceOnEnter", startConferenceOnEnter) - .add("status", status) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + callSid, + callSidToCoach, + coaching, + conferenceSid, + dateCreated, + dateUpdated, + endConferenceOnExit, + hold, + label, + muted, + queueTime, + startConferenceOnEnter, + status, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantCreator.java index cb6f6870a7..c2d3744d4c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.conference; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,18 +28,21 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class ParticipantCreator extends Creator { + private String pathAccountSid; - private final String pathConferenceSid; - private final com.twilio.type.PhoneNumber from; - private final com.twilio.type.PhoneNumber to; + private String pathConferenceSid; + private com.twilio.type.Endpoint from; + private com.twilio.type.Endpoint to; private URI statusCallback; private HttpMethod statusCallbackMethod; private List statusCallbackEvent; + private String label; private Integer timeout; private Boolean record; private Boolean muted; @@ -54,612 +68,1119 @@ public class ParticipantCreator extends Creator { private HttpMethod conferenceRecordingStatusCallbackMethod; private List recordingStatusCallbackEvent; private List conferenceRecordingStatusCallbackEvent; - - /** - * Construct a new ParticipantCreator. - * - * @param pathConferenceSid The conference_sid - * @param from number, client id - * @param to number, client id, sip address - */ - public ParticipantCreator(final String pathConferenceSid, - final com.twilio.type.PhoneNumber from, - final com.twilio.type.PhoneNumber to) { + private Boolean coaching; + private String callSidToCoach; + private String jitterBufferSize; + private String byoc; + private String callerId; + private String callReason; + private String recordingTrack; + private String recordingConfigurationId; + private Integer timeLimit; + private String machineDetection; + private Integer machineDetectionTimeout; + private Integer machineDetectionSpeechThreshold; + private Integer machineDetectionSpeechEndThreshold; + private Integer machineDetectionSilenceTimeout; + private URI amdStatusCallback; + private HttpMethod amdStatusCallbackMethod; + private String trim; + private String callToken; + private String passports; + private URI clientNotificationUrl; + private String callerDisplayName; + private String emergencyCallerPosition; + private String emergencyCallerLocation; + private String emergencyName; + private String emergencyAddress; + private String emergencyZipCode; + private String emergencyCity; + private String emergencyState; + private String emergencyCountry; + + public ParticipantCreator( + final String pathConferenceSid, + final com.twilio.type.Endpoint from, + final com.twilio.type.Endpoint to + ) { this.pathConferenceSid = pathConferenceSid; this.from = from; this.to = to; } - /** - * Construct a new ParticipantCreator. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The conference_sid - * @param from number, client id - * @param to number, client id, sip address - */ - public ParticipantCreator(final String pathAccountSid, - final String pathConferenceSid, - final com.twilio.type.PhoneNumber from, - final com.twilio.type.PhoneNumber to) { + public ParticipantCreator( + final String pathAccountSid, + final String pathConferenceSid, + final com.twilio.type.Endpoint from, + final com.twilio.type.Endpoint to + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.from = from; this.to = to; } - /** - * absolute url. - * - * @param statusCallback absolute url - * @return this - */ + public ParticipantCreator setFrom(final com.twilio.type.Endpoint from) { + this.from = from; + return this; + } + + public ParticipantCreator setTo(final com.twilio.type.Endpoint to) { + this.to = to; + return this; + } + public ParticipantCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * absolute url. - * - * @param statusCallback absolute url - * @return this - */ public ParticipantCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * GET, POST. - * - * @param statusCallbackMethod GET, POST - * @return this - */ - public ParticipantCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public ParticipantCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * initiated, ringing, answered, completed. - * - * @param statusCallbackEvent initiated, ringing, answered, completed - * @return this - */ - public ParticipantCreator setStatusCallbackEvent(final List statusCallbackEvent) { + public ParticipantCreator setStatusCallbackEvent( + final List statusCallbackEvent + ) { this.statusCallbackEvent = statusCallbackEvent; return this; } - /** - * initiated, ringing, answered, completed. - * - * @param statusCallbackEvent initiated, ringing, answered, completed - * @return this - */ - public ParticipantCreator setStatusCallbackEvent(final String statusCallbackEvent) { + public ParticipantCreator setStatusCallbackEvent( + final String statusCallbackEvent + ) { return setStatusCallbackEvent(Promoter.listOfOne(statusCallbackEvent)); } - /** - * 5-600. - * - * @param timeout 5-600 - * @return this - */ + public ParticipantCreator setLabel(final String label) { + this.label = label; + return this; + } + public ParticipantCreator setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - /** - * true, false. - * - * @param record true, false - * @return this - */ public ParticipantCreator setRecord(final Boolean record) { this.record = record; return this; } - /** - * true, false. - * - * @param muted true, false - * @return this - */ public ParticipantCreator setMuted(final Boolean muted) { this.muted = muted; return this; } - /** - * true, false, onEnter, onExit. - * - * @param beep true, false, onEnter, onExit - * @return this - */ public ParticipantCreator setBeep(final String beep) { this.beep = beep; return this; } - /** - * true, false. - * - * @param startConferenceOnEnter true, false - * @return this - */ - public ParticipantCreator setStartConferenceOnEnter(final Boolean startConferenceOnEnter) { + public ParticipantCreator setStartConferenceOnEnter( + final Boolean startConferenceOnEnter + ) { this.startConferenceOnEnter = startConferenceOnEnter; return this; } - /** - * true, false. - * - * @param endConferenceOnExit true, false - * @return this - */ - public ParticipantCreator setEndConferenceOnExit(final Boolean endConferenceOnExit) { + public ParticipantCreator setEndConferenceOnExit( + final Boolean endConferenceOnExit + ) { this.endConferenceOnExit = endConferenceOnExit; return this; } - /** - * absolute url. - * - * @param waitUrl absolute url - * @return this - */ public ParticipantCreator setWaitUrl(final URI waitUrl) { this.waitUrl = waitUrl; return this; } - /** - * absolute url. - * - * @param waitUrl absolute url - * @return this - */ public ParticipantCreator setWaitUrl(final String waitUrl) { return setWaitUrl(Promoter.uriFromString(waitUrl)); } - /** - * GET, POST. - * - * @param waitMethod GET, POST - * @return this - */ public ParticipantCreator setWaitMethod(final HttpMethod waitMethod) { this.waitMethod = waitMethod; return this; } - /** - * true, false. - * - * @param earlyMedia true, false - * @return this - */ public ParticipantCreator setEarlyMedia(final Boolean earlyMedia) { this.earlyMedia = earlyMedia; return this; } - /** - * 2-10. - * - * @param maxParticipants 2-10 - * @return this - */ - public ParticipantCreator setMaxParticipants(final Integer maxParticipants) { + public ParticipantCreator setMaxParticipants( + final Integer maxParticipants + ) { this.maxParticipants = maxParticipants; return this; } - /** - * true, false, record-from-start, do-not-record. - * - * @param conferenceRecord true, false, record-from-start, do-not-record - * @return this - */ - public ParticipantCreator setConferenceRecord(final String conferenceRecord) { + public ParticipantCreator setConferenceRecord( + final String conferenceRecord + ) { this.conferenceRecord = conferenceRecord; return this; } - /** - * trim-silence or do-not-trim. - * - * @param conferenceTrim trim-silence or do-not-trim - * @return this - */ public ParticipantCreator setConferenceTrim(final String conferenceTrim) { this.conferenceTrim = conferenceTrim; return this; } - /** - * absolute url. - * - * @param conferenceStatusCallback absolute url - * @return this - */ - public ParticipantCreator setConferenceStatusCallback(final URI conferenceStatusCallback) { + public ParticipantCreator setConferenceStatusCallback( + final URI conferenceStatusCallback + ) { this.conferenceStatusCallback = conferenceStatusCallback; return this; } - /** - * absolute url. - * - * @param conferenceStatusCallback absolute url - * @return this - */ - public ParticipantCreator setConferenceStatusCallback(final String conferenceStatusCallback) { - return setConferenceStatusCallback(Promoter.uriFromString(conferenceStatusCallback)); + public ParticipantCreator setConferenceStatusCallback( + final String conferenceStatusCallback + ) { + return setConferenceStatusCallback( + Promoter.uriFromString(conferenceStatusCallback) + ); } - /** - * GET, POST. - * - * @param conferenceStatusCallbackMethod GET, POST - * @return this - */ - public ParticipantCreator setConferenceStatusCallbackMethod(final HttpMethod conferenceStatusCallbackMethod) { + public ParticipantCreator setConferenceStatusCallbackMethod( + final HttpMethod conferenceStatusCallbackMethod + ) { this.conferenceStatusCallbackMethod = conferenceStatusCallbackMethod; return this; } - /** - * start end join leave mute hold speaker. - * - * @param conferenceStatusCallbackEvent start end join leave mute hold speaker - * @return this - */ - public ParticipantCreator setConferenceStatusCallbackEvent(final List conferenceStatusCallbackEvent) { + public ParticipantCreator setConferenceStatusCallbackEvent( + final List conferenceStatusCallbackEvent + ) { this.conferenceStatusCallbackEvent = conferenceStatusCallbackEvent; return this; } - /** - * start end join leave mute hold speaker. - * - * @param conferenceStatusCallbackEvent start end join leave mute hold speaker - * @return this - */ - public ParticipantCreator setConferenceStatusCallbackEvent(final String conferenceStatusCallbackEvent) { - return setConferenceStatusCallbackEvent(Promoter.listOfOne(conferenceStatusCallbackEvent)); + public ParticipantCreator setConferenceStatusCallbackEvent( + final String conferenceStatusCallbackEvent + ) { + return setConferenceStatusCallbackEvent( + Promoter.listOfOne(conferenceStatusCallbackEvent) + ); } - /** - * mono, dual. - * - * @param recordingChannels mono, dual - * @return this - */ - public ParticipantCreator setRecordingChannels(final String recordingChannels) { + public ParticipantCreator setRecordingChannels( + final String recordingChannels + ) { this.recordingChannels = recordingChannels; return this; } - /** - * absolute url. - * - * @param recordingStatusCallback absolute url - * @return this - */ - public ParticipantCreator setRecordingStatusCallback(final URI recordingStatusCallback) { + public ParticipantCreator setRecordingStatusCallback( + final URI recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - /** - * absolute url. - * - * @param recordingStatusCallback absolute url - * @return this - */ - public ParticipantCreator setRecordingStatusCallback(final String recordingStatusCallback) { - return setRecordingStatusCallback(Promoter.uriFromString(recordingStatusCallback)); + public ParticipantCreator setRecordingStatusCallback( + final String recordingStatusCallback + ) { + return setRecordingStatusCallback( + Promoter.uriFromString(recordingStatusCallback) + ); } - /** - * GET, POST. - * - * @param recordingStatusCallbackMethod GET, POST - * @return this - */ - public ParticipantCreator setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod) { + public ParticipantCreator setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - /** - * sip username. - * - * @param sipAuthUsername sip username - * @return this - */ public ParticipantCreator setSipAuthUsername(final String sipAuthUsername) { this.sipAuthUsername = sipAuthUsername; return this; } - /** - * sip password. - * - * @param sipAuthPassword sip password - * @return this - */ public ParticipantCreator setSipAuthPassword(final String sipAuthPassword) { this.sipAuthPassword = sipAuthPassword; return this; } - /** - * us1, ie1, de1, sg1, br1, au1, jp1. - * - * @param region us1, ie1, de1, sg1, br1, au1, jp1 - * @return this - */ public ParticipantCreator setRegion(final String region) { this.region = region; return this; } - /** - * absolute url. - * - * @param conferenceRecordingStatusCallback absolute url - * @return this - */ - public ParticipantCreator setConferenceRecordingStatusCallback(final URI conferenceRecordingStatusCallback) { - this.conferenceRecordingStatusCallback = conferenceRecordingStatusCallback; + public ParticipantCreator setConferenceRecordingStatusCallback( + final URI conferenceRecordingStatusCallback + ) { + this.conferenceRecordingStatusCallback = + conferenceRecordingStatusCallback; return this; } - /** - * absolute url. - * - * @param conferenceRecordingStatusCallback absolute url - * @return this - */ - public ParticipantCreator setConferenceRecordingStatusCallback(final String conferenceRecordingStatusCallback) { - return setConferenceRecordingStatusCallback(Promoter.uriFromString(conferenceRecordingStatusCallback)); + public ParticipantCreator setConferenceRecordingStatusCallback( + final String conferenceRecordingStatusCallback + ) { + return setConferenceRecordingStatusCallback( + Promoter.uriFromString(conferenceRecordingStatusCallback) + ); } - /** - * GET, POST. - * - * @param conferenceRecordingStatusCallbackMethod GET, POST - * @return this - */ - public ParticipantCreator setConferenceRecordingStatusCallbackMethod(final HttpMethod conferenceRecordingStatusCallbackMethod) { - this.conferenceRecordingStatusCallbackMethod = conferenceRecordingStatusCallbackMethod; + public ParticipantCreator setConferenceRecordingStatusCallbackMethod( + final HttpMethod conferenceRecordingStatusCallbackMethod + ) { + this.conferenceRecordingStatusCallbackMethod = + conferenceRecordingStatusCallbackMethod; return this; } - /** - * The recording_status_callback_event. - * - * @param recordingStatusCallbackEvent The recording_status_callback_event - * @return this - */ - public ParticipantCreator setRecordingStatusCallbackEvent(final List recordingStatusCallbackEvent) { + public ParticipantCreator setRecordingStatusCallbackEvent( + final List recordingStatusCallbackEvent + ) { this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; } - /** - * The recording_status_callback_event. - * - * @param recordingStatusCallbackEvent The recording_status_callback_event - * @return this - */ - public ParticipantCreator setRecordingStatusCallbackEvent(final String recordingStatusCallbackEvent) { - return setRecordingStatusCallbackEvent(Promoter.listOfOne(recordingStatusCallbackEvent)); + public ParticipantCreator setRecordingStatusCallbackEvent( + final String recordingStatusCallbackEvent + ) { + return setRecordingStatusCallbackEvent( + Promoter.listOfOne(recordingStatusCallbackEvent) + ); } - /** - * The conference_recording_status_callback_event. - * - * @param conferenceRecordingStatusCallbackEvent The - * conference_recording_status_callback_event - * @return this - */ - public ParticipantCreator setConferenceRecordingStatusCallbackEvent(final List conferenceRecordingStatusCallbackEvent) { - this.conferenceRecordingStatusCallbackEvent = conferenceRecordingStatusCallbackEvent; + public ParticipantCreator setConferenceRecordingStatusCallbackEvent( + final List conferenceRecordingStatusCallbackEvent + ) { + this.conferenceRecordingStatusCallbackEvent = + conferenceRecordingStatusCallbackEvent; return this; } - /** - * The conference_recording_status_callback_event. - * - * @param conferenceRecordingStatusCallbackEvent The - * conference_recording_status_callback_event - * @return this - */ - public ParticipantCreator setConferenceRecordingStatusCallbackEvent(final String conferenceRecordingStatusCallbackEvent) { - return setConferenceRecordingStatusCallbackEvent(Promoter.listOfOne(conferenceRecordingStatusCallbackEvent)); + public ParticipantCreator setConferenceRecordingStatusCallbackEvent( + final String conferenceRecordingStatusCallbackEvent + ) { + return setConferenceRecordingStatusCallbackEvent( + Promoter.listOfOne(conferenceRecordingStatusCallbackEvent) + ); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ParticipantCreator setCoaching(final Boolean coaching) { + this.coaching = coaching; + return this; + } + + public ParticipantCreator setCallSidToCoach(final String callSidToCoach) { + this.callSidToCoach = callSidToCoach; + return this; + } + + public ParticipantCreator setJitterBufferSize( + final String jitterBufferSize + ) { + this.jitterBufferSize = jitterBufferSize; + return this; + } + + public ParticipantCreator setByoc(final String byoc) { + this.byoc = byoc; + return this; + } + + public ParticipantCreator setCallerId(final String callerId) { + this.callerId = callerId; + return this; + } + + public ParticipantCreator setCallReason(final String callReason) { + this.callReason = callReason; + return this; + } + + public ParticipantCreator setRecordingTrack(final String recordingTrack) { + this.recordingTrack = recordingTrack; + return this; + } + + public ParticipantCreator setRecordingConfigurationId( + final String recordingConfigurationId + ) { + this.recordingConfigurationId = recordingConfigurationId; + return this; + } + + public ParticipantCreator setTimeLimit(final Integer timeLimit) { + this.timeLimit = timeLimit; + return this; + } + + public ParticipantCreator setMachineDetection( + final String machineDetection + ) { + this.machineDetection = machineDetection; + return this; + } + + public ParticipantCreator setMachineDetectionTimeout( + final Integer machineDetectionTimeout + ) { + this.machineDetectionTimeout = machineDetectionTimeout; + return this; + } + + public ParticipantCreator setMachineDetectionSpeechThreshold( + final Integer machineDetectionSpeechThreshold + ) { + this.machineDetectionSpeechThreshold = machineDetectionSpeechThreshold; + return this; + } + + public ParticipantCreator setMachineDetectionSpeechEndThreshold( + final Integer machineDetectionSpeechEndThreshold + ) { + this.machineDetectionSpeechEndThreshold = + machineDetectionSpeechEndThreshold; + return this; + } + + public ParticipantCreator setMachineDetectionSilenceTimeout( + final Integer machineDetectionSilenceTimeout + ) { + this.machineDetectionSilenceTimeout = machineDetectionSilenceTimeout; + return this; + } + + public ParticipantCreator setAmdStatusCallback( + final URI amdStatusCallback + ) { + this.amdStatusCallback = amdStatusCallback; + return this; + } + + public ParticipantCreator setAmdStatusCallback( + final String amdStatusCallback + ) { + return setAmdStatusCallback(Promoter.uriFromString(amdStatusCallback)); + } + + public ParticipantCreator setAmdStatusCallbackMethod( + final HttpMethod amdStatusCallbackMethod + ) { + this.amdStatusCallbackMethod = amdStatusCallbackMethod; + return this; + } + + public ParticipantCreator setTrim(final String trim) { + this.trim = trim; + return this; + } + + public ParticipantCreator setCallToken(final String callToken) { + this.callToken = callToken; + return this; + } + + public ParticipantCreator setPassports(final String passports) { + this.passports = passports; + return this; + } + + public ParticipantCreator setClientNotificationUrl( + final URI clientNotificationUrl + ) { + this.clientNotificationUrl = clientNotificationUrl; + return this; + } + + public ParticipantCreator setClientNotificationUrl( + final String clientNotificationUrl + ) { + return setClientNotificationUrl( + Promoter.uriFromString(clientNotificationUrl) + ); + } + + public ParticipantCreator setCallerDisplayName( + final String callerDisplayName + ) { + this.callerDisplayName = callerDisplayName; + return this; + } + + public ParticipantCreator setEmergencyCallerPosition( + final String emergencyCallerPosition + ) { + this.emergencyCallerPosition = emergencyCallerPosition; + return this; + } + + public ParticipantCreator setEmergencyCallerLocation( + final String emergencyCallerLocation + ) { + this.emergencyCallerLocation = emergencyCallerLocation; + return this; + } + + public ParticipantCreator setEmergencyName(final String emergencyName) { + this.emergencyName = emergencyName; + return this; + } + + public ParticipantCreator setEmergencyAddress( + final String emergencyAddress + ) { + this.emergencyAddress = emergencyAddress; + return this; + } + + public ParticipantCreator setEmergencyZipCode( + final String emergencyZipCode + ) { + this.emergencyZipCode = emergencyZipCode; + return this; + } + + public ParticipantCreator setEmergencyCity(final String emergencyCity) { + this.emergencyCity = emergencyCity; + return this; + } + + public ParticipantCreator setEmergencyState(final String emergencyState) { + this.emergencyState = emergencyState; + return this; + } + + public ParticipantCreator setEmergencyCountry( + final String emergencyCountry + ) { + this.emergencyCountry = emergencyCountry; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Conferences/" + this.pathConferenceSid + "/Participants.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Participant create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (from != null) { - request.addPostParam("From", from.toString()); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (to != null) { - request.addPostParam("To", to.toString()); + Serializer.toString(request, "To", to, ParameterType.URLENCODED); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallbackEvent != null) { - for (String prop : statusCallbackEvent) { - request.addPostParam("StatusCallbackEvent", prop); + for (String param : statusCallbackEvent) { + Serializer.toString( + request, + "StatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } + if (label != null) { + Serializer.toString( + request, + "Label", + label, + ParameterType.URLENCODED + ); + } + if (timeout != null) { - request.addPostParam("Timeout", timeout.toString()); + Serializer.toString( + request, + "Timeout", + timeout, + ParameterType.URLENCODED + ); } if (record != null) { - request.addPostParam("Record", record.toString()); + Serializer.toString( + request, + "Record", + record, + ParameterType.URLENCODED + ); } if (muted != null) { - request.addPostParam("Muted", muted.toString()); + Serializer.toString( + request, + "Muted", + muted, + ParameterType.URLENCODED + ); } if (beep != null) { - request.addPostParam("Beep", beep); + Serializer.toString( + request, + "Beep", + beep, + ParameterType.URLENCODED + ); } if (startConferenceOnEnter != null) { - request.addPostParam("StartConferenceOnEnter", startConferenceOnEnter.toString()); + Serializer.toString( + request, + "StartConferenceOnEnter", + startConferenceOnEnter, + ParameterType.URLENCODED + ); } if (endConferenceOnExit != null) { - request.addPostParam("EndConferenceOnExit", endConferenceOnExit.toString()); + Serializer.toString( + request, + "EndConferenceOnExit", + endConferenceOnExit, + ParameterType.URLENCODED + ); } if (waitUrl != null) { - request.addPostParam("WaitUrl", waitUrl.toString()); + Serializer.toString( + request, + "WaitUrl", + waitUrl, + ParameterType.URLENCODED + ); } if (waitMethod != null) { - request.addPostParam("WaitMethod", waitMethod.toString()); + Serializer.toString( + request, + "WaitMethod", + waitMethod, + ParameterType.URLENCODED + ); } if (earlyMedia != null) { - request.addPostParam("EarlyMedia", earlyMedia.toString()); + Serializer.toString( + request, + "EarlyMedia", + earlyMedia, + ParameterType.URLENCODED + ); } if (maxParticipants != null) { - request.addPostParam("MaxParticipants", maxParticipants.toString()); + Serializer.toString( + request, + "MaxParticipants", + maxParticipants, + ParameterType.URLENCODED + ); } if (conferenceRecord != null) { - request.addPostParam("ConferenceRecord", conferenceRecord); + Serializer.toString( + request, + "ConferenceRecord", + conferenceRecord, + ParameterType.URLENCODED + ); } if (conferenceTrim != null) { - request.addPostParam("ConferenceTrim", conferenceTrim); + Serializer.toString( + request, + "ConferenceTrim", + conferenceTrim, + ParameterType.URLENCODED + ); } if (conferenceStatusCallback != null) { - request.addPostParam("ConferenceStatusCallback", conferenceStatusCallback.toString()); + Serializer.toString( + request, + "ConferenceStatusCallback", + conferenceStatusCallback, + ParameterType.URLENCODED + ); } if (conferenceStatusCallbackMethod != null) { - request.addPostParam("ConferenceStatusCallbackMethod", conferenceStatusCallbackMethod.toString()); + Serializer.toString( + request, + "ConferenceStatusCallbackMethod", + conferenceStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (conferenceStatusCallbackEvent != null) { - for (String prop : conferenceStatusCallbackEvent) { - request.addPostParam("ConferenceStatusCallbackEvent", prop); + for (String param : conferenceStatusCallbackEvent) { + Serializer.toString( + request, + "ConferenceStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (recordingChannels != null) { - request.addPostParam("RecordingChannels", recordingChannels); + Serializer.toString( + request, + "RecordingChannels", + recordingChannels, + ParameterType.URLENCODED + ); } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback.toString()); + Serializer.toString( + request, + "RecordingStatusCallback", + recordingStatusCallback, + ParameterType.URLENCODED + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); + Serializer.toString( + request, + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (sipAuthUsername != null) { - request.addPostParam("SipAuthUsername", sipAuthUsername); + Serializer.toString( + request, + "SipAuthUsername", + sipAuthUsername, + ParameterType.URLENCODED + ); } if (sipAuthPassword != null) { - request.addPostParam("SipAuthPassword", sipAuthPassword); + Serializer.toString( + request, + "SipAuthPassword", + sipAuthPassword, + ParameterType.URLENCODED + ); } if (region != null) { - request.addPostParam("Region", region); + Serializer.toString( + request, + "Region", + region, + ParameterType.URLENCODED + ); } if (conferenceRecordingStatusCallback != null) { - request.addPostParam("ConferenceRecordingStatusCallback", conferenceRecordingStatusCallback.toString()); + Serializer.toString( + request, + "ConferenceRecordingStatusCallback", + conferenceRecordingStatusCallback, + ParameterType.URLENCODED + ); } if (conferenceRecordingStatusCallbackMethod != null) { - request.addPostParam("ConferenceRecordingStatusCallbackMethod", conferenceRecordingStatusCallbackMethod.toString()); + Serializer.toString( + request, + "ConferenceRecordingStatusCallbackMethod", + conferenceRecordingStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (recordingStatusCallbackEvent != null) { - for (String prop : recordingStatusCallbackEvent) { - request.addPostParam("RecordingStatusCallbackEvent", prop); + for (String param : recordingStatusCallbackEvent) { + Serializer.toString( + request, + "RecordingStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (conferenceRecordingStatusCallbackEvent != null) { - for (String prop : conferenceRecordingStatusCallbackEvent) { - request.addPostParam("ConferenceRecordingStatusCallbackEvent", prop); + for (String param : conferenceRecordingStatusCallbackEvent) { + Serializer.toString( + request, + "ConferenceRecordingStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } + + if (coaching != null) { + Serializer.toString( + request, + "Coaching", + coaching, + ParameterType.URLENCODED + ); + } + + if (callSidToCoach != null) { + Serializer.toString( + request, + "CallSidToCoach", + callSidToCoach, + ParameterType.URLENCODED + ); + } + + if (jitterBufferSize != null) { + Serializer.toString( + request, + "JitterBufferSize", + jitterBufferSize, + ParameterType.URLENCODED + ); + } + + if (byoc != null) { + Serializer.toString( + request, + "Byoc", + byoc, + ParameterType.URLENCODED + ); + } + + if (callerId != null) { + Serializer.toString( + request, + "CallerId", + callerId, + ParameterType.URLENCODED + ); + } + + if (callReason != null) { + Serializer.toString( + request, + "CallReason", + callReason, + ParameterType.URLENCODED + ); + } + + if (recordingTrack != null) { + Serializer.toString( + request, + "RecordingTrack", + recordingTrack, + ParameterType.URLENCODED + ); + } + + if (recordingConfigurationId != null) { + Serializer.toString( + request, + "RecordingConfigurationId", + recordingConfigurationId, + ParameterType.URLENCODED + ); + } + + if (timeLimit != null) { + Serializer.toString( + request, + "TimeLimit", + timeLimit, + ParameterType.URLENCODED + ); + } + + if (machineDetection != null) { + Serializer.toString( + request, + "MachineDetection", + machineDetection, + ParameterType.URLENCODED + ); + } + + if (machineDetectionTimeout != null) { + Serializer.toString( + request, + "MachineDetectionTimeout", + machineDetectionTimeout, + ParameterType.URLENCODED + ); + } + + if (machineDetectionSpeechThreshold != null) { + Serializer.toString( + request, + "MachineDetectionSpeechThreshold", + machineDetectionSpeechThreshold, + ParameterType.URLENCODED + ); + } + + if (machineDetectionSpeechEndThreshold != null) { + Serializer.toString( + request, + "MachineDetectionSpeechEndThreshold", + machineDetectionSpeechEndThreshold, + ParameterType.URLENCODED + ); + } + + if (machineDetectionSilenceTimeout != null) { + Serializer.toString( + request, + "MachineDetectionSilenceTimeout", + machineDetectionSilenceTimeout, + ParameterType.URLENCODED + ); + } + + if (amdStatusCallback != null) { + Serializer.toString( + request, + "AmdStatusCallback", + amdStatusCallback, + ParameterType.URLENCODED + ); + } + + if (amdStatusCallbackMethod != null) { + Serializer.toString( + request, + "AmdStatusCallbackMethod", + amdStatusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (trim != null) { + Serializer.toString( + request, + "Trim", + trim, + ParameterType.URLENCODED + ); + } + + if (callToken != null) { + Serializer.toString( + request, + "CallToken", + callToken, + ParameterType.URLENCODED + ); + } + + if (passports != null) { + Serializer.toString( + request, + "Passports", + passports, + ParameterType.URLENCODED + ); + } + + if (clientNotificationUrl != null) { + Serializer.toString( + request, + "ClientNotificationUrl", + clientNotificationUrl, + ParameterType.URLENCODED + ); + } + + if (callerDisplayName != null) { + Serializer.toString( + request, + "CallerDisplayName", + callerDisplayName, + ParameterType.URLENCODED + ); + } + + if (emergencyCallerPosition != null) { + Serializer.toString( + request, + "EmergencyCallerPosition", + emergencyCallerPosition, + ParameterType.URLENCODED + ); + } + + if (emergencyCallerLocation != null) { + Serializer.toString( + request, + "EmergencyCallerLocation", + emergencyCallerLocation, + ParameterType.URLENCODED + ); + } + + if (emergencyName != null) { + Serializer.toString( + request, + "EmergencyName", + emergencyName, + ParameterType.URLENCODED + ); + } + + if (emergencyAddress != null) { + Serializer.toString( + request, + "EmergencyAddress", + emergencyAddress, + ParameterType.URLENCODED + ); + } + + if (emergencyZipCode != null) { + Serializer.toString( + request, + "EmergencyZipCode", + emergencyZipCode, + ParameterType.URLENCODED + ); + } + + if (emergencyCity != null) { + Serializer.toString( + request, + "EmergencyCity", + emergencyCity, + ParameterType.URLENCODED + ); + } + + if (emergencyState != null) { + Serializer.toString( + request, + "EmergencyState", + emergencyState, + ParameterType.URLENCODED + ); + } + + if (emergencyCountry != null) { + Serializer.toString( + request, + "EmergencyCountry", + emergencyCountry, + ParameterType.URLENCODED + ); + } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantDeleter.java index 0a9d0c1375..c5973d1f20 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.conference; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,105 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ParticipantDeleter extends Deleter { + private String pathAccountSid; - private final String pathConferenceSid; - private final String pathCallSid; + private String pathConferenceSid; + private String pathCallSid; - /** - * Construct a new ParticipantDeleter. - * - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - */ - public ParticipantDeleter(final String pathConferenceSid, - final String pathCallSid) { + public ParticipantDeleter( + final String pathConferenceSid, + final String pathCallSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - /** - * Construct a new ParticipantDeleter. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - */ - public ParticipantDeleter(final String pathAccountSid, - final String pathConferenceSid, - final String pathCallSid) { + public ParticipantDeleter( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Conferences/" + this.pathConferenceSid + "/Participants/" + this.pathCallSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Participant delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantFetcher.java index 694b8cdbc6..7502bea975 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.conference; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,104 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ParticipantFetcher extends Fetcher { + private String pathAccountSid; - private final String pathConferenceSid; - private final String pathCallSid; + private String pathConferenceSid; + private String pathCallSid; - /** - * Construct a new ParticipantFetcher. - * - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - */ - public ParticipantFetcher(final String pathConferenceSid, - final String pathCallSid) { + public ParticipantFetcher( + final String pathConferenceSid, + final String pathCallSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - /** - * Construct a new ParticipantFetcher. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - */ - public ParticipantFetcher(final String pathAccountSid, - final String pathConferenceSid, - final String pathCallSid) { + public ParticipantFetcher( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Conferences/" + this.pathConferenceSid + "/Participants/" + this.pathCallSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Participant fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantReader.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantReader.java index a3cb8d2cb7..9caf958924 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.conference; @@ -10,206 +17,249 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ParticipantReader extends Reader { + private String pathAccountSid; - private final String pathConferenceSid; + private String pathConferenceSid; private Boolean muted; private Boolean hold; + private Boolean coaching; + private Long pageSize; - /** - * Construct a new ParticipantReader. - * - * @param pathConferenceSid The string that uniquely identifies this conference - */ public ParticipantReader(final String pathConferenceSid) { this.pathConferenceSid = pathConferenceSid; } - /** - * Construct a new ParticipantReader. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The string that uniquely identifies this conference - */ - public ParticipantReader(final String pathAccountSid, - final String pathConferenceSid) { + public ParticipantReader( + final String pathAccountSid, + final String pathConferenceSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; } - /** - * Only show participants that are muted or unmuted. Either `true` or `false`.. - * - * @param muted Filter by muted participants - * @return this - */ public ParticipantReader setMuted(final Boolean muted) { this.muted = muted; return this; } - /** - * Only show participants that are held or unheld. Either `true` or `false`.. - * - * @param hold Only show participants that are held or unheld. - * @return this - */ public ParticipantReader setHold(final Boolean hold) { this.hold = hold; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ParticipantReader setCoaching(final Boolean coaching) { + this.coaching = coaching; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ParticipantReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Conferences/" + this.pathConferenceSid + "/Participants.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Participant Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Participant read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "participants", - response.getContent(), - Participant.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (muted != null) { - request.addQueryParam("Muted", muted.toString()); + Serializer.toString(request, "Muted", muted, ParameterType.QUERY); } if (hold != null) { - request.addQueryParam("Hold", hold.toString()); + Serializer.toString(request, "Hold", hold, ParameterType.QUERY); + } + + if (coaching != null) { + Serializer.toString( + request, + "Coaching", + coaching, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantUpdater.java index c40cc5f150..7de6473e27 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/ParticipantUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.conference; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,209 +28,305 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class ParticipantUpdater extends Updater { + private String pathAccountSid; - private final String pathConferenceSid; - private final String pathCallSid; + private String pathConferenceSid; + private String pathCallSid; private Boolean muted; private Boolean hold; private URI holdUrl; private HttpMethod holdMethod; private URI announceUrl; private HttpMethod announceMethod; + private URI waitUrl; + private HttpMethod waitMethod; + private Boolean beepOnExit; + private Boolean endConferenceOnExit; + private Boolean coaching; + private String callSidToCoach; - /** - * Construct a new ParticipantUpdater. - * - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - */ - public ParticipantUpdater(final String pathConferenceSid, - final String pathCallSid) { + public ParticipantUpdater( + final String pathConferenceSid, + final String pathCallSid + ) { this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - /** - * Construct a new ParticipantUpdater. - * - * @param pathAccountSid The account_sid - * @param pathConferenceSid The string that uniquely identifies this conference - * @param pathCallSid The call_sid - */ - public ParticipantUpdater(final String pathAccountSid, - final String pathConferenceSid, - final String pathCallSid) { + public ParticipantUpdater( + final String pathAccountSid, + final String pathConferenceSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathConferenceSid = pathConferenceSid; this.pathCallSid = pathCallSid; } - /** - * Specifying `true` will mute the participant, while `false` will un-mute. - * Anything other than `true` or `false` is interpreted as `false`.. - * - * @param muted Indicates if the participant should be muted - * @return this - */ public ParticipantUpdater setMuted(final Boolean muted) { this.muted = muted; return this; } - /** - * Specifying `true` will hold the participant, while `false` will un-hold.. - * - * @param hold Specifying true will hold the participant, while false will - * un-hold. - * @return this - */ public ParticipantUpdater setHold(final Boolean hold) { this.hold = hold; return this; } - /** - * The 'HoldUrl' attribute lets you specify a URL for music that plays when a - * participant is held. The URL may be an MP3, a WAV or a TwiML document that - * uses `<Play>`, `<Say>` or `<Redirect>`.. - * - * @param holdUrl The 'HoldUrl' attribute lets you specify a URL for music that - * plays when a participant is held. - * @return this - */ public ParticipantUpdater setHoldUrl(final URI holdUrl) { this.holdUrl = holdUrl; return this; } - /** - * The 'HoldUrl' attribute lets you specify a URL for music that plays when a - * participant is held. The URL may be an MP3, a WAV or a TwiML document that - * uses `<Play>`, `<Say>` or `<Redirect>`.. - * - * @param holdUrl The 'HoldUrl' attribute lets you specify a URL for music that - * plays when a participant is held. - * @return this - */ public ParticipantUpdater setHoldUrl(final String holdUrl) { return setHoldUrl(Promoter.uriFromString(holdUrl)); } - /** - * Specify GET or POST, defaults to GET. - * - * @param holdMethod Specify GET or POST, defaults to GET - * @return this - */ public ParticipantUpdater setHoldMethod(final HttpMethod holdMethod) { this.holdMethod = holdMethod; return this; } - /** - * The announce_url. - * - * @param announceUrl The announce_url - * @return this - */ public ParticipantUpdater setAnnounceUrl(final URI announceUrl) { this.announceUrl = announceUrl; return this; } - /** - * The announce_url. - * - * @param announceUrl The announce_url - * @return this - */ public ParticipantUpdater setAnnounceUrl(final String announceUrl) { return setAnnounceUrl(Promoter.uriFromString(announceUrl)); } - /** - * The announce_method. - * - * @param announceMethod The announce_method - * @return this - */ - public ParticipantUpdater setAnnounceMethod(final HttpMethod announceMethod) { + public ParticipantUpdater setAnnounceMethod( + final HttpMethod announceMethod + ) { this.announceMethod = announceMethod; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ParticipantUpdater setWaitUrl(final URI waitUrl) { + this.waitUrl = waitUrl; + return this; + } + + public ParticipantUpdater setWaitUrl(final String waitUrl) { + return setWaitUrl(Promoter.uriFromString(waitUrl)); + } + + public ParticipantUpdater setWaitMethod(final HttpMethod waitMethod) { + this.waitMethod = waitMethod; + return this; + } + + public ParticipantUpdater setBeepOnExit(final Boolean beepOnExit) { + this.beepOnExit = beepOnExit; + return this; + } + + public ParticipantUpdater setEndConferenceOnExit( + final Boolean endConferenceOnExit + ) { + this.endConferenceOnExit = endConferenceOnExit; + return this; + } + + public ParticipantUpdater setCoaching(final Boolean coaching) { + this.coaching = coaching; + return this; + } + + public ParticipantUpdater setCallSidToCoach(final String callSidToCoach) { + this.callSidToCoach = callSidToCoach; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Participants/{CallSid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Conferences/" + this.pathConferenceSid + "/Participants/" + this.pathCallSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Participant update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Participant update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (muted != null) { - request.addPostParam("Muted", muted.toString()); + Serializer.toString( + request, + "Muted", + muted, + ParameterType.URLENCODED + ); } if (hold != null) { - request.addPostParam("Hold", hold.toString()); + Serializer.toString( + request, + "Hold", + hold, + ParameterType.URLENCODED + ); } if (holdUrl != null) { - request.addPostParam("HoldUrl", holdUrl.toString()); + Serializer.toString( + request, + "HoldUrl", + holdUrl, + ParameterType.URLENCODED + ); } if (holdMethod != null) { - request.addPostParam("HoldMethod", holdMethod.toString()); + Serializer.toString( + request, + "HoldMethod", + holdMethod, + ParameterType.URLENCODED + ); } if (announceUrl != null) { - request.addPostParam("AnnounceUrl", announceUrl.toString()); + Serializer.toString( + request, + "AnnounceUrl", + announceUrl, + ParameterType.URLENCODED + ); } if (announceMethod != null) { - request.addPostParam("AnnounceMethod", announceMethod.toString()); + Serializer.toString( + request, + "AnnounceMethod", + announceMethod, + ParameterType.URLENCODED + ); + } + + if (waitUrl != null) { + Serializer.toString( + request, + "WaitUrl", + waitUrl, + ParameterType.URLENCODED + ); + } + + if (waitMethod != null) { + Serializer.toString( + request, + "WaitMethod", + waitMethod, + ParameterType.URLENCODED + ); + } + + if (beepOnExit != null) { + Serializer.toString( + request, + "BeepOnExit", + beepOnExit, + ParameterType.URLENCODED + ); + } + + if (endConferenceOnExit != null) { + Serializer.toString( + request, + "EndConferenceOnExit", + endConferenceOnExit, + ParameterType.URLENCODED + ); + } + + if (coaching != null) { + Serializer.toString( + request, + "Coaching", + coaching, + ParameterType.URLENCODED + ); + } + + if (callSidToCoach != null) { + Serializer.toString( + request, + "CallSidToCoach", + callSidToCoach, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/Recording.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/Recording.java new file mode 100644 index 0000000000..c6cb93d43d --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/Recording.java @@ -0,0 +1,367 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.conference; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Currency; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Recording extends Resource { + + public static RecordingDeleter deleter( + final String pathConferenceSid, + final String pathSid + ) { + return new RecordingDeleter(pathConferenceSid, pathSid); + } + + public static RecordingDeleter deleter( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid + ) { + return new RecordingDeleter(pathAccountSid, pathConferenceSid, pathSid); + } + + public static RecordingFetcher fetcher( + final String pathConferenceSid, + final String pathSid + ) { + return new RecordingFetcher(pathConferenceSid, pathSid); + } + + public static RecordingFetcher fetcher( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid + ) { + return new RecordingFetcher(pathAccountSid, pathConferenceSid, pathSid); + } + + public static RecordingReader reader(final String pathConferenceSid) { + return new RecordingReader(pathConferenceSid); + } + + public static RecordingReader reader( + final String pathAccountSid, + final String pathConferenceSid + ) { + return new RecordingReader(pathAccountSid, pathConferenceSid); + } + + public static RecordingUpdater updater( + final String pathConferenceSid, + final String pathSid, + final Recording.Status status + ) { + return new RecordingUpdater(pathConferenceSid, pathSid, status); + } + + public static RecordingUpdater updater( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid, + final Recording.Status status + ) { + return new RecordingUpdater( + pathAccountSid, + pathConferenceSid, + pathSid, + status + ); + } + + public enum Status { + IN_PROGRESS("in-progress"), + PAUSED("paused"), + STOPPED("stopped"), + PROCESSING("processing"), + COMPLETED("completed"), + ABSENT("absent"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Source { + DIAL_VERB("DialVerb"), + CONFERENCE("Conference"), + OUTBOUND_API("OutboundAPI"), + TRUNKING("Trunking"), + RECORD_VERB("RecordVerb"), + START_CALL_RECORDING_API("StartCallRecordingAPI"), + START_CONFERENCE_RECORDING_API("StartConferenceRecordingAPI"); + + private final String value; + + private Source(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Source forValue(final String value) { + return Promoter.enumFromString(value, Source.values()); + } + } + + /** + * Converts a JSON String into a Recording object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Recording.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Recording object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Recording.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String apiVersion; + + @Getter + private final String callSid; + + @Getter + private final Integer channels; + + @Getter + private final String conferenceSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String duration; + + @Getter + private final Object encryptionDetails; + + @Getter + private final Integer errorCode; + + @Getter + private final String price; + + @Getter + private final Currency priceUnit; + + @Getter + private final String sid; + + @Getter + private final Recording.Source source; + + @Getter + private final ZonedDateTime startTime; + + @Getter + private final Recording.Status status; + + @Getter + private final String uri; + + @JsonCreator + private Recording( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("channels") final Integer channels, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("duration") final String duration, + @JsonProperty("encryption_details") final Object encryptionDetails, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("price") final String price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("sid") final String sid, + @JsonProperty("source") final Recording.Source source, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime startTime, + @JsonProperty("status") final Recording.Status status, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.apiVersion = apiVersion; + this.callSid = callSid; + this.channels = channels; + this.conferenceSid = conferenceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.duration = duration; + this.encryptionDetails = encryptionDetails; + this.errorCode = errorCode; + this.price = price; + this.priceUnit = priceUnit; + this.sid = sid; + this.source = source; + this.startTime = startTime; + this.status = status; + this.uri = uri; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Recording other = (Recording) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callSid, other.callSid) && + Objects.equals(channels, other.channels) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals(encryptionDetails, other.encryptionDetails) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(sid, other.sid) && + Objects.equals(source, other.source) && + Objects.equals(startTime, other.startTime) && + Objects.equals(status, other.status) && + Objects.equals(uri, other.uri) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + apiVersion, + callSid, + channels, + conferenceSid, + dateCreated, + dateUpdated, + duration, + encryptionDetails, + errorCode, + price, + priceUnit, + sid, + source, + startTime, + status, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingDeleter.java new file mode 100644 index 0000000000..cf20e69370 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingDeleter.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.conference; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class RecordingDeleter extends Deleter { + + private String pathAccountSid; + private String pathConferenceSid; + private String pathSid; + + public RecordingDeleter( + final String pathConferenceSid, + final String pathSid + ) { + this.pathConferenceSid = pathConferenceSid; + this.pathSid = pathSid; + } + + public RecordingDeleter( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathConferenceSid = pathConferenceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Recording delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingFetcher.java new file mode 100644 index 0000000000..23cdf81c77 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingFetcher.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.conference; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RecordingFetcher extends Fetcher { + + private String pathAccountSid; + private String pathConferenceSid; + private String pathSid; + + public RecordingFetcher( + final String pathConferenceSid, + final String pathSid + ) { + this.pathConferenceSid = pathConferenceSid; + this.pathSid = pathSid; + } + + public RecordingFetcher( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathConferenceSid = pathConferenceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Recording fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Recording fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recording content = Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingReader.java new file mode 100644 index 0000000000..afd3c850c5 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingReader.java @@ -0,0 +1,261 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.conference; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; + +public class RecordingReader extends Reader { + + private String pathAccountSid; + private String pathConferenceSid; + private LocalDate dateCreated; + private LocalDate dateCreatedBefore; + private LocalDate dateCreatedAfter; + private Long pageSize; + + public RecordingReader(final String pathConferenceSid) { + this.pathConferenceSid = pathConferenceSid; + } + + public RecordingReader( + final String pathAccountSid, + final String pathConferenceSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathConferenceSid = pathConferenceSid; + } + + public RecordingReader setDateCreated(final LocalDate dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public RecordingReader setDateCreatedBefore( + final LocalDate dateCreatedBefore + ) { + this.dateCreatedBefore = dateCreatedBefore; + return this; + } + + public RecordingReader setDateCreatedAfter( + final LocalDate dateCreatedAfter + ) { + this.dateCreatedAfter = dateCreatedAfter; + return this; + } + + public RecordingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Recording read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "recordings", + response.getContent(), + Recording.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + dateCreatedBefore, + dateCreatedAfter + ); + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingUpdater.java new file mode 100644 index 0000000000..82808daa3b --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/conference/RecordingUpdater.java @@ -0,0 +1,168 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.conference; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RecordingUpdater extends Updater { + + private String pathAccountSid; + private String pathConferenceSid; + private String pathSid; + private Recording.Status status; + private String pauseBehavior; + + public RecordingUpdater( + final String pathConferenceSid, + final String pathSid, + final Recording.Status status + ) { + this.pathConferenceSid = pathConferenceSid; + this.pathSid = pathSid; + this.status = status; + } + + public RecordingUpdater( + final String pathAccountSid, + final String pathConferenceSid, + final String pathSid, + final Recording.Status status + ) { + this.pathAccountSid = pathAccountSid; + this.pathConferenceSid = pathConferenceSid; + this.pathSid = pathSid; + this.status = status; + } + + public RecordingUpdater setStatus(final Recording.Status status) { + this.status = status; + return this; + } + + public RecordingUpdater setPauseBehavior(final String pauseBehavior) { + this.pauseBehavior = pauseBehavior; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Conferences/{ConferenceSid}/Recordings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Recording update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Recording update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recording content = Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (pauseBehavior != null) { + Serializer.toString( + request, + "PauseBehavior", + pauseBehavior, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOn.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOn.java index a40e69d9a5..f1120337c4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOn.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOn.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; @@ -11,146 +18,108 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AssignedAddOn extends Resource { - private static final long serialVersionUID = 62322787699673L; - /** - * Create a AssignedAddOnFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param pathSid The unique Installed Add-on Sid - * @return AssignedAddOnFetcher capable of executing the fetch - */ - public static AssignedAddOnFetcher fetcher(final String pathAccountSid, - final String pathResourceSid, - final String pathSid) { - return new AssignedAddOnFetcher(pathAccountSid, pathResourceSid, pathSid); + public static AssignedAddOnCreator creator( + final String pathResourceSid, + final String installedAddOnSid + ) { + return new AssignedAddOnCreator(pathResourceSid, installedAddOnSid); } - /** - * Create a AssignedAddOnFetcher to execute fetch. - * - * @param pathResourceSid The resource_sid - * @param pathSid The unique Installed Add-on Sid - * @return AssignedAddOnFetcher capable of executing the fetch - */ - public static AssignedAddOnFetcher fetcher(final String pathResourceSid, - final String pathSid) { - return new AssignedAddOnFetcher(pathResourceSid, pathSid); + public static AssignedAddOnCreator creator( + final String pathAccountSid, + final String pathResourceSid, + final String installedAddOnSid + ) { + return new AssignedAddOnCreator( + pathAccountSid, + pathResourceSid, + installedAddOnSid + ); } - /** - * Create a AssignedAddOnReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @return AssignedAddOnReader capable of executing the read - */ - public static AssignedAddOnReader reader(final String pathAccountSid, - final String pathResourceSid) { - return new AssignedAddOnReader(pathAccountSid, pathResourceSid); + public static AssignedAddOnDeleter deleter( + final String pathResourceSid, + final String pathSid + ) { + return new AssignedAddOnDeleter(pathResourceSid, pathSid); } - /** - * Create a AssignedAddOnReader to execute read. - * - * @param pathResourceSid The resource_sid - * @return AssignedAddOnReader capable of executing the read - */ - public static AssignedAddOnReader reader(final String pathResourceSid) { - return new AssignedAddOnReader(pathResourceSid); + public static AssignedAddOnDeleter deleter( + final String pathAccountSid, + final String pathResourceSid, + final String pathSid + ) { + return new AssignedAddOnDeleter( + pathAccountSid, + pathResourceSid, + pathSid + ); } - /** - * Create a AssignedAddOnCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param installedAddOnSid A string that uniquely identifies the Add-on - * installation - * @return AssignedAddOnCreator capable of executing the create - */ - public static AssignedAddOnCreator creator(final String pathAccountSid, - final String pathResourceSid, - final String installedAddOnSid) { - return new AssignedAddOnCreator(pathAccountSid, pathResourceSid, installedAddOnSid); + public static AssignedAddOnFetcher fetcher( + final String pathResourceSid, + final String pathSid + ) { + return new AssignedAddOnFetcher(pathResourceSid, pathSid); } - /** - * Create a AssignedAddOnCreator to execute create. - * - * @param pathResourceSid The resource_sid - * @param installedAddOnSid A string that uniquely identifies the Add-on - * installation - * @return AssignedAddOnCreator capable of executing the create - */ - public static AssignedAddOnCreator creator(final String pathResourceSid, - final String installedAddOnSid) { - return new AssignedAddOnCreator(pathResourceSid, installedAddOnSid); + public static AssignedAddOnFetcher fetcher( + final String pathAccountSid, + final String pathResourceSid, + final String pathSid + ) { + return new AssignedAddOnFetcher( + pathAccountSid, + pathResourceSid, + pathSid + ); } - /** - * Create a AssignedAddOnDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param pathSid The Installed Add-on Sid to remove - * @return AssignedAddOnDeleter capable of executing the delete - */ - public static AssignedAddOnDeleter deleter(final String pathAccountSid, - final String pathResourceSid, - final String pathSid) { - return new AssignedAddOnDeleter(pathAccountSid, pathResourceSid, pathSid); + public static AssignedAddOnReader reader(final String pathResourceSid) { + return new AssignedAddOnReader(pathResourceSid); } - /** - * Create a AssignedAddOnDeleter to execute delete. - * - * @param pathResourceSid The resource_sid - * @param pathSid The Installed Add-on Sid to remove - * @return AssignedAddOnDeleter capable of executing the delete - */ - public static AssignedAddOnDeleter deleter(final String pathResourceSid, - final String pathSid) { - return new AssignedAddOnDeleter(pathResourceSid, pathSid); + public static AssignedAddOnReader reader( + final String pathAccountSid, + final String pathResourceSid + ) { + return new AssignedAddOnReader(pathAccountSid, pathResourceSid); } /** - * Converts a JSON String into a AssignedAddOn object using the provided - * ObjectMapper. - * + * Converts a JSON String into a AssignedAddOn object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AssignedAddOn object represented by the provided JSON */ - public static AssignedAddOn fromJson(final String json, final ObjectMapper objectMapper) { + public static AssignedAddOn fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssignedAddOn.class); @@ -164,12 +133,15 @@ public static AssignedAddOn fromJson(final String json, final ObjectMapper objec /** * Converts a JSON InputStream into a AssignedAddOn object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AssignedAddOn object represented by the provided JSON */ - public static AssignedAddOn fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AssignedAddOn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssignedAddOn.class); @@ -180,152 +152,83 @@ public static AssignedAddOn fromJson(final InputStream json, final ObjectMapper } } - private final String sid; - private final String accountSid; - private final String resourceSid; - private final String friendlyName; - private final String description; - private final Map configuration; - private final String uniqueName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String uri; - private final Map subresourceUris; - - @JsonCreator - private AssignedAddOn(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("resource_sid") - final String resourceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("description") - final String description, - @JsonProperty("configuration") - final Map configuration, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("uri") - final String uri, - @JsonProperty("subresource_uris") - final Map subresourceUris) { - this.sid = sid; - this.accountSid = accountSid; - this.resourceSid = resourceSid; - this.friendlyName = friendlyName; - this.description = description; - this.configuration = configuration; - this.uniqueName = uniqueName; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.uri = uri; - this.subresourceUris = subresourceUris; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A string that uniquely identifies this assigned Add-on - * installation. - * - * @return A string that uniquely identifies this assigned Add-on installation - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The Account id that has installed this Add-on. - * - * @return The Account id that has installed this Add-on - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Object configuration; - /** - * Returns The The Phone Number id that has installed this Add-on. - * - * @return The Phone Number id that has installed this Add-on - */ - public final String getResourceSid() { - return this.resourceSid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The A description of this Add-on installation. - * - * @return A description of this Add-on installation - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A short description of the Add-on functionality. - * - * @return A short description of the Add-on functionality - */ - public final String getDescription() { - return this.description; - } + @Getter + private final String description; - /** - * Returns The The JSON object representing the current configuration. - * - * @return The JSON object representing the current configuration - */ - public final Map getConfiguration() { - return this.configuration; - } + @Getter + private final String friendlyName; - /** - * Returns The The string that uniquely identifies this Add-on installation. - * - * @return The string that uniquely identifies this Add-on installation - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String resourceSid; - /** - * Returns The The date this Add-on was installed. - * - * @return The date this Add-on was installed - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date this Add-on installation was last updated. - * - * @return The date this Add-on installation was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Map subresourceUris; - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; - } + @Getter + private final String uniqueName; - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; + @Getter + private final String uri; + + @JsonCreator + private AssignedAddOn( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("configuration") final Object configuration, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.configuration = configuration; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.friendlyName = friendlyName; + this.resourceSid = resourceSid; + this.sid = sid; + this.subresourceUris = subresourceUris; + this.uniqueName = uniqueName; + this.uri = uri; } @Override @@ -339,49 +242,35 @@ public boolean equals(final Object o) { } AssignedAddOn other = (AssignedAddOn) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(resourceSid, other.resourceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(description, other.description) && - Objects.equals(configuration, other.configuration) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(uri, other.uri) && - Objects.equals(subresourceUris, other.subresourceUris); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - resourceSid, - friendlyName, - description, - configuration, - uniqueName, - dateCreated, - dateUpdated, - uri, - subresourceUris); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("resourceSid", resourceSid) - .add("friendlyName", friendlyName) - .add("description", description) - .add("configuration", configuration) - .add("uniqueName", uniqueName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("uri", uri) - .add("subresourceUris", subresourceUris) - .toString(); + return Objects.hash( + accountSid, + configuration, + dateCreated, + dateUpdated, + description, + friendlyName, + resourceSid, + sid, + subresourceUris, + uniqueName, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnCreator.java index 217b7f39fe..67f856b3b4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,93 +27,123 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class AssignedAddOnCreator extends Creator { + private String pathAccountSid; - private final String pathResourceSid; - private final String installedAddOnSid; + private String pathResourceSid; + private String installedAddOnSid; - /** - * Construct a new AssignedAddOnCreator. - * - * @param pathResourceSid The resource_sid - * @param installedAddOnSid A string that uniquely identifies the Add-on - * installation - */ - public AssignedAddOnCreator(final String pathResourceSid, - final String installedAddOnSid) { + public AssignedAddOnCreator( + final String pathResourceSid, + final String installedAddOnSid + ) { this.pathResourceSid = pathResourceSid; this.installedAddOnSid = installedAddOnSid; } - /** - * Construct a new AssignedAddOnCreator. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param installedAddOnSid A string that uniquely identifies the Add-on - * installation - */ - public AssignedAddOnCreator(final String pathAccountSid, - final String pathResourceSid, - final String installedAddOnSid) { + public AssignedAddOnCreator( + final String pathAccountSid, + final String pathResourceSid, + final String installedAddOnSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.installedAddOnSid = installedAddOnSid; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created AssignedAddOn - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AssignedAddOn create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public AssignedAddOnCreator setInstalledAddOnSid( + final String installedAddOnSid + ) { + this.installedAddOnSid = installedAddOnSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathResourceSid + "/AssignedAddOns.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOn creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AssignedAddOn creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return AssignedAddOn.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public AssignedAddOn create(final TwilioRestClient client) { + Response response = makeRequest(client); + return AssignedAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AssignedAddOn content = AssignedAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (installedAddOnSid != null) { - request.addPostParam("InstalledAddOnSid", installedAddOnSid); + Serializer.toString( + request, + "InstalledAddOnSid", + installedAddOnSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnDeleter.java index 75fd2f801e..95f6fb495d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,78 +24,105 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class AssignedAddOnDeleter extends Deleter { + private String pathAccountSid; - private final String pathResourceSid; - private final String pathSid; + private String pathResourceSid; + private String pathSid; - /** - * Construct a new AssignedAddOnDeleter. - * - * @param pathResourceSid The resource_sid - * @param pathSid The Installed Add-on Sid to remove - */ - public AssignedAddOnDeleter(final String pathResourceSid, - final String pathSid) { + public AssignedAddOnDeleter( + final String pathResourceSid, + final String pathSid + ) { this.pathResourceSid = pathResourceSid; this.pathSid = pathSid; } - /** - * Construct a new AssignedAddOnDeleter. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param pathSid The Installed Add-on Sid to remove - */ - public AssignedAddOnDeleter(final String pathAccountSid, - final String pathResourceSid, - final String pathSid) { + public AssignedAddOnDeleter( + final String pathAccountSid, + final String pathResourceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathResourceSid + "/AssignedAddOns/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOn delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AssignedAddOn delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnFetcher.java index 6452a7b6a1..f50e2229f1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,79 +24,104 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class AssignedAddOnFetcher extends Fetcher { + private String pathAccountSid; - private final String pathResourceSid; - private final String pathSid; + private String pathResourceSid; + private String pathSid; - /** - * Construct a new AssignedAddOnFetcher. - * - * @param pathResourceSid The resource_sid - * @param pathSid The unique Installed Add-on Sid - */ - public AssignedAddOnFetcher(final String pathResourceSid, - final String pathSid) { + public AssignedAddOnFetcher( + final String pathResourceSid, + final String pathSid + ) { this.pathResourceSid = pathResourceSid; this.pathSid = pathSid; } - /** - * Construct a new AssignedAddOnFetcher. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param pathSid The unique Installed Add-on Sid - */ - public AssignedAddOnFetcher(final String pathAccountSid, - final String pathResourceSid, - final String pathSid) { + public AssignedAddOnFetcher( + final String pathAccountSid, + final String pathResourceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AssignedAddOn - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AssignedAddOn fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathResourceSid + "/AssignedAddOns/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOn fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AssignedAddOn fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public AssignedAddOn fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AssignedAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return AssignedAddOn.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AssignedAddOn content = AssignedAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnReader.java index a8ef19f8bf..4c1ecd371c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/AssignedAddOnReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; @@ -10,178 +17,214 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class AssignedAddOnReader extends Reader { + private String pathAccountSid; - private final String pathResourceSid; + private String pathResourceSid; + private Long pageSize; - /** - * Construct a new AssignedAddOnReader. - * - * @param pathResourceSid The resource_sid - */ public AssignedAddOnReader(final String pathResourceSid) { this.pathResourceSid = pathResourceSid; } - /** - * Construct a new AssignedAddOnReader. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - */ - public AssignedAddOnReader(final String pathAccountSid, - final String pathResourceSid) { + public AssignedAddOnReader( + final String pathAccountSid, + final String pathResourceSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AssignedAddOn ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AssignedAddOnReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AssignedAddOn ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "assigned_add_ons", + response.getContent(), + AssignedAddOn.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathResourceSid + "/AssignedAddOns.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AssignedAddOn ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "assigned_add_ons", + response.getContent(), + AssignedAddOn.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AssignedAddOn read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "assigned_add_ons", + response.getContent(), + AssignedAddOn.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AssignedAddOn Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AssignedAddOn read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "assigned_add_ons", - response.getContent(), - AssignedAddOn.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Local.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Local.java index 6fba33327d..e49570a865 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Local.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Local.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; @@ -10,33 +17,124 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Local extends Resource { - private static final long serialVersionUID = 75964804463033L; + + public static LocalCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new LocalCreator(phoneNumber); + } + + public static LocalCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new LocalCreator(pathAccountSid, phoneNumber); + } + + public static LocalReader reader() { + return new LocalReader(); + } + + public static LocalReader reader(final String pathAccountSid) { + return new LocalReader(pathAccountSid); + } + + public enum EmergencyAddressStatus { + REGISTERED("registered"), + UNREGISTERED("unregistered"), + PENDING_REGISTRATION("pending-registration"), + REGISTRATION_FAILURE("registration-failure"), + PENDING_UNREGISTRATION("pending-unregistration"), + UNREGISTRATION_FAILURE("unregistration-failure"); + + private final String value; + + private EmergencyAddressStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EmergencyAddressStatus forValue(final String value) { + return Promoter.enumFromString( + value, + EmergencyAddressStatus.values() + ); + } + } + + public enum VoiceReceiveMode { + VOICE("voice"), + FAX("fax"); + + private final String value; + + private VoiceReceiveMode(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static VoiceReceiveMode forValue(final String value) { + return Promoter.enumFromString(value, VoiceReceiveMode.values()); + } + } + + public enum EmergencyStatus { + ACTIVE("Active"), + INACTIVE("Inactive"); + + private final String value; + + private EmergencyStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EmergencyStatus forValue(final String value) { + return Promoter.enumFromString(value, EmergencyStatus.values()); + } + } public enum AddressRequirement { NONE("none"), @@ -50,70 +148,28 @@ private AddressRequirement(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a AddressRequirement from a string. - * @param value string value - * @return generated AddressRequirement - */ @JsonCreator public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); } } - /** - * Create a LocalReader to execute read. - * - * @param pathAccountSid The account_sid - * @return LocalReader capable of executing the read - */ - public static LocalReader reader(final String pathAccountSid) { - return new LocalReader(pathAccountSid); - } - - /** - * Create a LocalReader to execute read. - * - * @return LocalReader capable of executing the read - */ - public static LocalReader reader() { - return new LocalReader(); - } - - /** - * Create a LocalCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number you want to purchase. - * @return LocalCreator capable of executing the create - */ - public static LocalCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { - return new LocalCreator(pathAccountSid, phoneNumber); - } - - /** - * Create a LocalCreator to execute create. - * - * @param phoneNumber The phone number you want to purchase. - * @return LocalCreator capable of executing the create - */ - public static LocalCreator creator(final com.twilio.type.PhoneNumber phoneNumber) { - return new LocalCreator(phoneNumber); - } - /** * Converts a JSON String into a Local object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Local object represented by the provided JSON */ - public static Local fromJson(final String json, final ObjectMapper objectMapper) { + public static Local fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Local.class); @@ -127,12 +183,15 @@ public static Local fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Local object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Local object represented by the provided JSON */ - public static Local fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Local fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Local.class); @@ -143,110 +202,202 @@ public static Local fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String addressSid; + + @Getter private final Local.AddressRequirement addressRequirements; + + @Getter + private final String addressSid; + + @Getter private final String apiVersion; + + @Getter private final Boolean beta; + + @Getter + private final String bundleSid; + + @Getter private final PhoneNumberCapabilities capabilities; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String emergencyAddressSid; + + @Getter + private final Local.EmergencyAddressStatus emergencyAddressStatus; + + @Getter + private final Local.EmergencyStatus emergencyStatus; + + @Getter private final String friendlyName; + + @Getter private final String identitySid; - private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String origin; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String sid; + + @Getter private final String smsApplicationSid; + + @Getter private final HttpMethod smsFallbackMethod; + + @Getter private final URI smsFallbackUrl; + + @Getter private final HttpMethod smsMethod; + + @Getter private final URI smsUrl; + + @Getter + private final String status; + + @Getter private final URI statusCallback; + + @Getter private final HttpMethod statusCallbackMethod; + + @Getter private final String trunkSid; + + @Getter private final String uri; + + @Getter private final String voiceApplicationSid; + + @Getter private final Boolean voiceCallerIdLookup; + + @Getter private final HttpMethod voiceFallbackMethod; + + @Getter private final URI voiceFallbackUrl; + + @Getter private final HttpMethod voiceMethod; + + @Getter + private final Local.VoiceReceiveMode voiceReceiveMode; + + @Getter private final URI voiceUrl; @JsonCreator - private Local(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("address_sid") - final String addressSid, - @JsonProperty("address_requirements") - final Local.AddressRequirement addressRequirements, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("identity_sid") - final String identitySid, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("origin") - final String origin, - @JsonProperty("sid") - final String sid, - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("status_callback") - final URI statusCallback, - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("uri") - final String uri, - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_url") - final URI voiceUrl) { + private Local( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "address_requirements" + ) final Local.AddressRequirement addressRequirements, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_address_status" + ) final Local.EmergencyAddressStatus emergencyAddressStatus, + @JsonProperty( + "emergency_status" + ) final Local.EmergencyStatus emergencyStatus, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity_sid") final String identitySid, + @JsonProperty("origin") final String origin, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status") final String status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty( + "voice_receive_mode" + ) final Local.VoiceReceiveMode voiceReceiveMode, + @JsonProperty("voice_url") final URI voiceUrl + ) { this.accountSid = accountSid; - this.addressSid = addressSid; this.addressRequirements = addressRequirements; + this.addressSid = addressSid; this.apiVersion = apiVersion; this.beta = beta; + this.bundleSid = bundleSid; this.capabilities = capabilities; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.emergencyAddressSid = emergencyAddressSid; + this.emergencyAddressStatus = emergencyAddressStatus; + this.emergencyStatus = emergencyStatus; this.friendlyName = friendlyName; this.identitySid = identitySid; - this.phoneNumber = phoneNumber; this.origin = origin; + this.phoneNumber = phoneNumber; this.sid = sid; this.smsApplicationSid = smsApplicationSid; this.smsFallbackMethod = smsFallbackMethod; this.smsFallbackUrl = smsFallbackUrl; this.smsMethod = smsMethod; this.smsUrl = smsUrl; + this.status = status; this.statusCallback = statusCallback; this.statusCallbackMethod = statusCallbackMethod; this.trunkSid = trunkSid; @@ -256,294 +407,10 @@ private Local(@JsonProperty("account_sid") this.voiceFallbackMethod = voiceFallbackMethod; this.voiceFallbackUrl = voiceFallbackUrl; this.voiceMethod = voiceMethod; + this.voiceReceiveMode = voiceReceiveMode; this.voiceUrl = voiceUrl; } - /** - * Returns The The unique id of the Account responsible for this phone number.. - * - * @return The unique id of the Account responsible for this phone number. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The 34 character sid of the address associated with this number.. - * - * @return The 34 character sid of the address associated with this number. - */ - public final String getAddressSid() { - return this.addressSid; - } - - /** - * Returns The This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio.. - * - * @return This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio. - */ - public final Local.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - - /** - * Returns The Calls to this phone number will start a new TwiML session with - * this API version.. - * - * @return Calls to this phone number will start a new TwiML session with this - * API version. - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The Phone numbers new to the Twilio platform are marked as beta.. - * - * @return Phone numbers new to the Twilio platform are marked as beta. - */ - public final Boolean getBeta() { - return this.beta; - } - - /** - * Returns The This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages.. - * - * @return This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - - /** - * Returns The The date that this resource was created, given as GMT RFC 2822 - * format.. - * - * @return The date that this resource was created, given as GMT RFC 2822 - * format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated, given as GMT RFC - * 2822 format.. - * - * @return The date that this resource was last updated, given as GMT RFC 2822 - * format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human readable descriptive text for this resource, up to 64 - * characters long.. - * - * @return A human readable descriptive text for this resource, up to 64 - * characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The identity_sid. - * - * @return The identity_sid - */ - public final String getIdentitySid() { - return this.identitySid; - } - - /** - * Returns The The incoming phone number.. - * - * @return The incoming phone number. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - - /** - * Returns The Twilio owned phone numbers are marked as twilio while hosted - * phone numbers are marked as hosted.. - * - * @return Twilio owned phone numbers are marked as twilio while hosted phone - * numbers are marked as hosted. - */ - public final String getOrigin() { - return this.origin; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The 34 character sid of the application Twilio should use to - * handle SMSs sent to this number.. - * - * @return The 34 character sid of the application Twilio should use to handle - * SMSs sent to this number. - */ - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the above URL.. - * - * @return The HTTP method Twilio will use when requesting the above URL. - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - - /** - * Returns The The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML from SmsUrl.. - * - * @return The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML from SmsUrl. - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - - /** - * Returns The The HTTP method Twilio will use when making requests to the - * SmsUrl.. - * - * @return The HTTP method Twilio will use when making requests to the SmsUrl. - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - - /** - * Returns The The URL Twilio will request when receiving an incoming SMS - * message to this number.. - * - * @return The URL Twilio will request when receiving an incoming SMS message - * to this number. - */ - public final URI getSmsUrl() { - return this.smsUrl; - } - - /** - * Returns The The URL that Twilio will request to pass status parameters to - * your application.. - * - * @return The URL that Twilio will request to pass status parameters to your - * application. - */ - public final URI getStatusCallback() { - return this.statusCallback; - } - - /** - * Returns The The HTTP method Twilio will use to make requests to the - * StatusCallback URL.. - * - * @return The HTTP method Twilio will use to make requests to the - * StatusCallback URL. - */ - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - - /** - * Returns The The 34 character sid of the Trunk Twilio should use to handle - * phone calls to this number.. - * - * @return The 34 character sid of the Trunk Twilio should use to handle phone - * calls to this number. - */ - public final String getTrunkSid() { - return this.trunkSid; - } - - /** - * Returns The The URI for this resource, relative to https://api.. - * - * @return The URI for this resource, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The 34 character sid of the application Twilio should use to - * handle phone calls to this number.. - * - * @return The 34 character sid of the application Twilio should use to handle - * phone calls to this number. - */ - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - - /** - * Returns The Look up the caller's caller-ID name from the CNAM database.. - * - * @return Look up the caller's caller-ID name from the CNAM database. - */ - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the - * VoiceFallbackUrl.. - * - * @return The HTTP method Twilio will use when requesting the VoiceFallbackUrl. - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - - /** - * Returns The The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML requested by Url.. - * - * @return The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML requested by Url. - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the above Url.. - * - * @return The HTTP method Twilio will use when requesting the above Url. - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - - /** - * Returns The The URL Twilio will request when this phone number receives a - * call.. - * - * @return The URL Twilio will request when this phone number receives a call. - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -555,100 +422,84 @@ public boolean equals(final Object o) { } Local other = (Local) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(addressSid, other.addressSid) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(identitySid, other.identitySid) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(origin, other.origin) && - Objects.equals(sid, other.sid) && - Objects.equals(smsApplicationSid, other.smsApplicationSid) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(statusCallback, other.statusCallback) && - Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(uri, other.uri) && - Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && - Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceUrl, other.voiceUrl); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals( + emergencyAddressStatus, + other.emergencyAddressStatus + ) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identitySid, other.identitySid) && + Objects.equals(origin, other.origin) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - addressSid, - addressRequirements, - apiVersion, - beta, - capabilities, - dateCreated, - dateUpdated, - friendlyName, - identitySid, - phoneNumber, - origin, - sid, - smsApplicationSid, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsUrl, - statusCallback, - statusCallbackMethod, - trunkSid, - uri, - voiceApplicationSid, - voiceCallerIdLookup, - voiceFallbackMethod, - voiceFallbackUrl, - voiceMethod, - voiceUrl); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("addressSid", addressSid) - .add("addressRequirements", addressRequirements) - .add("apiVersion", apiVersion) - .add("beta", beta) - .add("capabilities", capabilities) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("identitySid", identitySid) - .add("phoneNumber", phoneNumber) - .add("origin", origin) - .add("sid", sid) - .add("smsApplicationSid", smsApplicationSid) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsUrl", smsUrl) - .add("statusCallback", statusCallback) - .add("statusCallbackMethod", statusCallbackMethod) - .add("trunkSid", trunkSid) - .add("uri", uri) - .add("voiceApplicationSid", voiceApplicationSid) - .add("voiceCallerIdLookup", voiceCallerIdLookup) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceMethod", voiceMethod) - .add("voiceUrl", voiceUrl) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + addressRequirements, + addressSid, + apiVersion, + beta, + bundleSid, + capabilities, + dateCreated, + dateUpdated, + emergencyAddressSid, + emergencyAddressStatus, + emergencyStatus, + friendlyName, + identitySid, + origin, + phoneNumber, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + status, + statusCallback, + statusCallbackMethod, + trunkSid, + uri, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceReceiveMode, + voiceUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalCreator.java index 02992377fd..50e459ed51 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class LocalCreator extends Creator { + private String pathAccountSid; - private final com.twilio.type.PhoneNumber phoneNumber; + private com.twilio.type.PhoneNumber phoneNumber; private String apiVersion; private String friendlyName; private String smsApplicationSid; @@ -40,428 +53,454 @@ public class LocalCreator extends Creator { private URI voiceUrl; private String identitySid; private String addressSid; + private Local.EmergencyStatus emergencyStatus; + private String emergencyAddressSid; + private String trunkSid; + private Local.VoiceReceiveMode voiceReceiveMode; + private String bundleSid; - /** - * Construct a new LocalCreator. - * - * @param phoneNumber The phone number you want to purchase. - */ public LocalCreator(final com.twilio.type.PhoneNumber phoneNumber) { this.phoneNumber = phoneNumber; } - /** - * Construct a new LocalCreator. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number you want to purchase. - */ - public LocalCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { + public LocalCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - /** - * The Twilio REST API version to use for incoming calls made to this number. If - * omitted, uses `2010-04-01`.. - * - * @param apiVersion The Twilio REST API version to use for incoming calls made - * to this number. - * @return this - */ + public LocalCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { + this.phoneNumber = phoneNumber; + return this; + } + + public LocalCreator setPhoneNumber(final String phoneNumber) { + return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); + } + public LocalCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - /** - * A human readable description of the new incoming phone number. Maximum 64 - * characters. Defaults to a formatted version of the number.. - * - * @param friendlyName A human readable description of the new incoming phone - * number. - * @return this - */ public LocalCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The 34 character sid of the application Twilio should use to handle SMSs sent - * to the new number. If a `SmsApplicationSid` is present, Twilio will ignore - * all of the SMS urls above and use those set on the application.. - * - * @param smsApplicationSid The 34 character sid of the application Twilio - * should use to handle SMSs sent to the new number. - * @return this - */ public LocalCreator setSmsApplicationSid(final String smsApplicationSid) { this.smsApplicationSid = smsApplicationSid; return this; } - /** - * The HTTP method that should be used to request the `SmsFallbackUrl`. Must be - * either `GET` or `POST`. Defaults to `POST`.. - * - * @param smsFallbackMethod The HTTP method that should be used to request the - * SmsFallbackUrl. - * @return this - */ - public LocalCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public LocalCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML defined by SmsUrl. - * @return this - */ public LocalCreator setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML defined by SmsUrl. - * @return this - */ public LocalCreator setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method that should be used to request the `SmsUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param smsMethod The HTTP method that should be used to request the SmsUrl. - * @return this - */ public LocalCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the phone - * number.. - * - * @param smsUrl The URL that Twilio should request when somebody sends an SMS - * to the phone number. - * @return this - */ public LocalCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the phone - * number.. - * - * @param smsUrl The URL that Twilio should request when somebody sends an SMS - * to the phone number. - * @return this - */ public LocalCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback The URL that Twilio will request to pass status - * parameters to your application. - * @return this - */ public LocalCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback The URL that Twilio will request to pass status - * parameters to your application. - * @return this - */ public LocalCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio will use to make requests to the `StatusCallback` URL. - * Either `GET` or `POST`. Defaults to `POST`.. - * - * @param statusCallbackMethod The HTTP method Twilio will use to make requests - * to the StatusCallback URL. - * @return this - */ - public LocalCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public LocalCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * The 34 character sid of the application Twilio should use to handle phone - * calls to the new number. If a `VoiceApplicationSid` is present, Twilio will - * ignore all of the voice urls above and use those set on the application. - * Setting a `VoiceApplicationSid` will automatically delete your `TrunkSid` and - * vice versa.. - * - * @param voiceApplicationSid The 34 character sid of the application Twilio - * should use to handle phone calls to the new - * number. - * @return this - */ - public LocalCreator setVoiceApplicationSid(final String voiceApplicationSid) { + public LocalCreator setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - /** - * Do a lookup of a caller's name from the CNAM database and post it to your - * app. Either `true` or `false`. Defaults to `false`.. - * - * @param voiceCallerIdLookup Do a lookup of a caller's name from the CNAM - * database and post it to your app. - * @return this - */ - public LocalCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup) { + public LocalCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - /** - * The HTTP method that should be used to request the `VoiceFallbackUrl`. Either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceFallbackMethod The HTTP method that should be used to request - * the VoiceFallbackUrl. - * @return this - */ - public LocalCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public LocalCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML at `Url`.. - * - * @param voiceFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML at Url. - * @return this - */ public LocalCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML at `Url`.. - * - * @param voiceFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML at Url. - * @return this - */ public LocalCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method that should be used to request the `VoiceUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceMethod The HTTP method that should be used to request the - * VoiceUrl. - * @return this - */ public LocalCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - /** - * The URL that Twilio should request when somebody dials the new phone number. - * The VoiceURL will no longer be used if a `VoiceApplicationSid` or a - * `TrunkSid` is set.. - * - * @param voiceUrl The URL that Twilio should request when somebody dials the - * new phone number. - * @return this - */ public LocalCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The URL that Twilio should request when somebody dials the new phone number. - * The VoiceURL will no longer be used if a `VoiceApplicationSid` or a - * `TrunkSid` is set.. - * - * @param voiceUrl The URL that Twilio should request when somebody dials the - * new phone number. - * @return this - */ public LocalCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The identity_sid. - * - * @param identitySid The identity_sid - * @return this - */ public LocalCreator setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - /** - * The 34 character sid of the address Twilio should associate with the number.. - * - * @param addressSid The 34 character sid of the address Twilio should - * associate with the number. - * @return this - */ public LocalCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Local - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Local create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public LocalCreator setEmergencyStatus( + final Local.EmergencyStatus emergencyStatus + ) { + this.emergencyStatus = emergencyStatus; + return this; + } + + public LocalCreator setEmergencyAddressSid( + final String emergencyAddressSid + ) { + this.emergencyAddressSid = emergencyAddressSid; + return this; + } + + public LocalCreator setTrunkSid(final String trunkSid) { + this.trunkSid = trunkSid; + return this; + } + + public LocalCreator setVoiceReceiveMode( + final Local.VoiceReceiveMode voiceReceiveMode + ) { + this.voiceReceiveMode = voiceReceiveMode; + return this; + } + + public LocalCreator setBundleSid(final String bundleSid) { + this.bundleSid = bundleSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/Local.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Local creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Local creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Local create(final TwilioRestClient client) { + Response response = makeRequest(client); return Local.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Local content = Local.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (phoneNumber != null) { - request.addPostParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); } if (apiVersion != null) { - request.addPostParam("ApiVersion", apiVersion); + Serializer.toString( + request, + "ApiVersion", + apiVersion, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (smsApplicationSid != null) { - request.addPostParam("SmsApplicationSid", smsApplicationSid); + Serializer.toString( + request, + "SmsApplicationSid", + smsApplicationSid, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (voiceApplicationSid != null) { - request.addPostParam("VoiceApplicationSid", voiceApplicationSid); + Serializer.toString( + request, + "VoiceApplicationSid", + voiceApplicationSid, + ParameterType.URLENCODED + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); + Serializer.toString( + request, + "VoiceCallerIdLookup", + voiceCallerIdLookup, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (identitySid != null) { - request.addPostParam("IdentitySid", identitySid); + Serializer.toString( + request, + "IdentitySid", + identitySid, + ParameterType.URLENCODED + ); } if (addressSid != null) { - request.addPostParam("AddressSid", addressSid); + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); + } + + if (emergencyStatus != null) { + Serializer.toString( + request, + "EmergencyStatus", + emergencyStatus, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressSid != null) { + Serializer.toString( + request, + "EmergencyAddressSid", + emergencyAddressSid, + ParameterType.URLENCODED + ); + } + + if (trunkSid != null) { + Serializer.toString( + request, + "TrunkSid", + trunkSid, + ParameterType.URLENCODED + ); + } + + if (voiceReceiveMode != null) { + Serializer.toString( + request, + "VoiceReceiveMode", + voiceReceiveMode, + ParameterType.URLENCODED + ); + } + + if (bundleSid != null) { + Serializer.toString( + request, + "BundleSid", + bundleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalReader.java index baab223a28..7b902239b1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/LocalReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; @@ -10,251 +17,255 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class LocalReader extends Reader { + private String pathAccountSid; private Boolean beta; private String friendlyName; private com.twilio.type.PhoneNumber phoneNumber; private String origin; + private Long pageSize; - /** - * Construct a new LocalReader. - */ - public LocalReader() { - } + public LocalReader() {} - /** - * Construct a new LocalReader. - * - * @param pathAccountSid The account_sid - */ public LocalReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Include phone numbers new to the Twilio platform. Possible values are either - * `true` or `false`. Default is `true`.. - * - * @param beta Include phone numbers new to the Twilio platform. - * @return this - */ public LocalReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * Only show the incoming phone number resources with friendly names that - * exactly match this name.. - * - * @param friendlyName Only show the incoming phone number resources with - * friendly names that exactly match this name. - * @return this - */ public LocalReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Only show the incoming phone number resources that match this pattern. You - * can specify partial numbers and use '*' as a wildcard for any digit.. - * - * @param phoneNumber Only show the incoming phone number resources that match - * this pattern. - * @return this - */ - public LocalReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public LocalReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * Only show the incoming phone number resources that match this pattern. You - * can specify partial numbers and use '*' as a wildcard for any digit.. - * - * @param phoneNumber Only show the incoming phone number resources that match - * this pattern. - * @return this - */ public LocalReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * Include phone numbers based on the origin, by default, phone numbers of all - * origin are included. Possible values are either `twilio` or `hosted`.. - * - * @param origin Include phone numbers based on the origin, by default, phone - * numbers of all origin are included. - * @return this - */ public LocalReader setOrigin(final String origin) { this.origin = origin; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Local ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public LocalReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Local ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + Local.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/Local.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Local ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + Local.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Local read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + Local.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Local Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Local read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "incoming_phone_numbers", - response.getContent(), - Local.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); } if (origin != null) { - request.addQueryParam("Origin", origin); + Serializer.toString(request, "Origin", origin, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Mobile.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Mobile.java index 581836be94..b7c60b6fe8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Mobile.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/Mobile.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; @@ -10,33 +17,124 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Mobile extends Resource { - private static final long serialVersionUID = 123614477626957L; + + public static MobileCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new MobileCreator(phoneNumber); + } + + public static MobileCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new MobileCreator(pathAccountSid, phoneNumber); + } + + public static MobileReader reader() { + return new MobileReader(); + } + + public static MobileReader reader(final String pathAccountSid) { + return new MobileReader(pathAccountSid); + } + + public enum EmergencyAddressStatus { + REGISTERED("registered"), + UNREGISTERED("unregistered"), + PENDING_REGISTRATION("pending-registration"), + REGISTRATION_FAILURE("registration-failure"), + PENDING_UNREGISTRATION("pending-unregistration"), + UNREGISTRATION_FAILURE("unregistration-failure"); + + private final String value; + + private EmergencyAddressStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EmergencyAddressStatus forValue(final String value) { + return Promoter.enumFromString( + value, + EmergencyAddressStatus.values() + ); + } + } + + public enum VoiceReceiveMode { + VOICE("voice"), + FAX("fax"); + + private final String value; + + private VoiceReceiveMode(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static VoiceReceiveMode forValue(final String value) { + return Promoter.enumFromString(value, VoiceReceiveMode.values()); + } + } + + public enum EmergencyStatus { + ACTIVE("Active"), + INACTIVE("Inactive"); + + private final String value; + + private EmergencyStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EmergencyStatus forValue(final String value) { + return Promoter.enumFromString(value, EmergencyStatus.values()); + } + } public enum AddressRequirement { NONE("none"), @@ -50,70 +148,28 @@ private AddressRequirement(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a AddressRequirement from a string. - * @param value string value - * @return generated AddressRequirement - */ @JsonCreator public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); } } - /** - * Create a MobileReader to execute read. - * - * @param pathAccountSid The account_sid - * @return MobileReader capable of executing the read - */ - public static MobileReader reader(final String pathAccountSid) { - return new MobileReader(pathAccountSid); - } - - /** - * Create a MobileReader to execute read. - * - * @return MobileReader capable of executing the read - */ - public static MobileReader reader() { - return new MobileReader(); - } - - /** - * Create a MobileCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number you want to purchase. - * @return MobileCreator capable of executing the create - */ - public static MobileCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { - return new MobileCreator(pathAccountSid, phoneNumber); - } - - /** - * Create a MobileCreator to execute create. - * - * @param phoneNumber The phone number you want to purchase. - * @return MobileCreator capable of executing the create - */ - public static MobileCreator creator(final com.twilio.type.PhoneNumber phoneNumber) { - return new MobileCreator(phoneNumber); - } - /** * Converts a JSON String into a Mobile object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Mobile object represented by the provided JSON */ - public static Mobile fromJson(final String json, final ObjectMapper objectMapper) { + public static Mobile fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Mobile.class); @@ -127,12 +183,15 @@ public static Mobile fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Mobile object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Mobile object represented by the provided JSON */ - public static Mobile fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Mobile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Mobile.class); @@ -143,110 +202,202 @@ public static Mobile fromJson(final InputStream json, final ObjectMapper objectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String addressSid; + + @Getter private final Mobile.AddressRequirement addressRequirements; + + @Getter + private final String addressSid; + + @Getter private final String apiVersion; + + @Getter private final Boolean beta; + + @Getter + private final String bundleSid; + + @Getter private final PhoneNumberCapabilities capabilities; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String emergencyAddressSid; + + @Getter + private final Mobile.EmergencyAddressStatus emergencyAddressStatus; + + @Getter + private final Mobile.EmergencyStatus emergencyStatus; + + @Getter private final String friendlyName; + + @Getter private final String identitySid; - private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String origin; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String sid; + + @Getter private final String smsApplicationSid; + + @Getter private final HttpMethod smsFallbackMethod; + + @Getter private final URI smsFallbackUrl; + + @Getter private final HttpMethod smsMethod; + + @Getter private final URI smsUrl; + + @Getter + private final String status; + + @Getter private final URI statusCallback; + + @Getter private final HttpMethod statusCallbackMethod; + + @Getter private final String trunkSid; + + @Getter private final String uri; + + @Getter private final String voiceApplicationSid; + + @Getter private final Boolean voiceCallerIdLookup; + + @Getter private final HttpMethod voiceFallbackMethod; + + @Getter private final URI voiceFallbackUrl; + + @Getter private final HttpMethod voiceMethod; + + @Getter + private final Mobile.VoiceReceiveMode voiceReceiveMode; + + @Getter private final URI voiceUrl; @JsonCreator - private Mobile(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("address_sid") - final String addressSid, - @JsonProperty("address_requirements") - final Mobile.AddressRequirement addressRequirements, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("identity_sid") - final String identitySid, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("origin") - final String origin, - @JsonProperty("sid") - final String sid, - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("status_callback") - final URI statusCallback, - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("uri") - final String uri, - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_url") - final URI voiceUrl) { + private Mobile( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "address_requirements" + ) final Mobile.AddressRequirement addressRequirements, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_address_status" + ) final Mobile.EmergencyAddressStatus emergencyAddressStatus, + @JsonProperty( + "emergency_status" + ) final Mobile.EmergencyStatus emergencyStatus, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity_sid") final String identitySid, + @JsonProperty("origin") final String origin, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status") final String status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty( + "voice_receive_mode" + ) final Mobile.VoiceReceiveMode voiceReceiveMode, + @JsonProperty("voice_url") final URI voiceUrl + ) { this.accountSid = accountSid; - this.addressSid = addressSid; this.addressRequirements = addressRequirements; + this.addressSid = addressSid; this.apiVersion = apiVersion; this.beta = beta; + this.bundleSid = bundleSid; this.capabilities = capabilities; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.emergencyAddressSid = emergencyAddressSid; + this.emergencyAddressStatus = emergencyAddressStatus; + this.emergencyStatus = emergencyStatus; this.friendlyName = friendlyName; this.identitySid = identitySid; - this.phoneNumber = phoneNumber; this.origin = origin; + this.phoneNumber = phoneNumber; this.sid = sid; this.smsApplicationSid = smsApplicationSid; this.smsFallbackMethod = smsFallbackMethod; this.smsFallbackUrl = smsFallbackUrl; this.smsMethod = smsMethod; this.smsUrl = smsUrl; + this.status = status; this.statusCallback = statusCallback; this.statusCallbackMethod = statusCallbackMethod; this.trunkSid = trunkSid; @@ -256,294 +407,10 @@ private Mobile(@JsonProperty("account_sid") this.voiceFallbackMethod = voiceFallbackMethod; this.voiceFallbackUrl = voiceFallbackUrl; this.voiceMethod = voiceMethod; + this.voiceReceiveMode = voiceReceiveMode; this.voiceUrl = voiceUrl; } - /** - * Returns The The unique id of the Account responsible for this phone number.. - * - * @return The unique id of the Account responsible for this phone number. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The 34 character sid of the address associated with this number.. - * - * @return The 34 character sid of the address associated with this number. - */ - public final String getAddressSid() { - return this.addressSid; - } - - /** - * Returns The This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio.. - * - * @return This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio. - */ - public final Mobile.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - - /** - * Returns The Calls to this phone number will start a new TwiML session with - * this API version.. - * - * @return Calls to this phone number will start a new TwiML session with this - * API version. - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The Phone numbers new to the Twilio platform are marked as beta.. - * - * @return Phone numbers new to the Twilio platform are marked as beta. - */ - public final Boolean getBeta() { - return this.beta; - } - - /** - * Returns The This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages.. - * - * @return This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - - /** - * Returns The The date that this resource was created, given as GMT RFC 2822 - * format.. - * - * @return The date that this resource was created, given as GMT RFC 2822 - * format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated, given as GMT RFC - * 2822 format.. - * - * @return The date that this resource was last updated, given as GMT RFC 2822 - * format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human readable descriptive text for this resource, up to 64 - * characters long.. - * - * @return A human readable descriptive text for this resource, up to 64 - * characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The identity_sid. - * - * @return The identity_sid - */ - public final String getIdentitySid() { - return this.identitySid; - } - - /** - * Returns The The incoming phone number.. - * - * @return The incoming phone number. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - - /** - * Returns The Twilio owned phone numbers are marked as twilio while hosted - * phone numbers are marked as hosted.. - * - * @return Twilio owned phone numbers are marked as twilio while hosted phone - * numbers are marked as hosted. - */ - public final String getOrigin() { - return this.origin; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The 34 character sid of the application Twilio should use to - * handle SMSs sent to this number.. - * - * @return The 34 character sid of the application Twilio should use to handle - * SMSs sent to this number. - */ - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the above URL.. - * - * @return The HTTP method Twilio will use when requesting the above URL. - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - - /** - * Returns The The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML from SmsUrl.. - * - * @return The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML from SmsUrl. - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - - /** - * Returns The The HTTP method Twilio will use when making requests to the - * SmsUrl.. - * - * @return The HTTP method Twilio will use when making requests to the SmsUrl. - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - - /** - * Returns The The URL Twilio will request when receiving an incoming SMS - * message to this number.. - * - * @return The URL Twilio will request when receiving an incoming SMS message - * to this number. - */ - public final URI getSmsUrl() { - return this.smsUrl; - } - - /** - * Returns The The URL that Twilio will request to pass status parameters to - * your application.. - * - * @return The URL that Twilio will request to pass status parameters to your - * application. - */ - public final URI getStatusCallback() { - return this.statusCallback; - } - - /** - * Returns The The HTTP method Twilio will use to make requests to the - * StatusCallback URL.. - * - * @return The HTTP method Twilio will use to make requests to the - * StatusCallback URL. - */ - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - - /** - * Returns The The 34 character sid of the Trunk Twilio should use to handle - * phone calls to this number.. - * - * @return The 34 character sid of the Trunk Twilio should use to handle phone - * calls to this number. - */ - public final String getTrunkSid() { - return this.trunkSid; - } - - /** - * Returns The The URI for this resource, relative to https://api.. - * - * @return The URI for this resource, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The 34 character sid of the application Twilio should use to - * handle phone calls to this number.. - * - * @return The 34 character sid of the application Twilio should use to handle - * phone calls to this number. - */ - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - - /** - * Returns The Look up the caller's caller-ID name from the CNAM database.. - * - * @return Look up the caller's caller-ID name from the CNAM database. - */ - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the - * VoiceFallbackUrl.. - * - * @return The HTTP method Twilio will use when requesting the VoiceFallbackUrl. - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - - /** - * Returns The The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML requested by Url.. - * - * @return The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML requested by Url. - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the above Url.. - * - * @return The HTTP method Twilio will use when requesting the above Url. - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - - /** - * Returns The The URL Twilio will request when this phone number receives a - * call.. - * - * @return The URL Twilio will request when this phone number receives a call. - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -555,100 +422,84 @@ public boolean equals(final Object o) { } Mobile other = (Mobile) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(addressSid, other.addressSid) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(identitySid, other.identitySid) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(origin, other.origin) && - Objects.equals(sid, other.sid) && - Objects.equals(smsApplicationSid, other.smsApplicationSid) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(statusCallback, other.statusCallback) && - Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(uri, other.uri) && - Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && - Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceUrl, other.voiceUrl); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals( + emergencyAddressStatus, + other.emergencyAddressStatus + ) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identitySid, other.identitySid) && + Objects.equals(origin, other.origin) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - addressSid, - addressRequirements, - apiVersion, - beta, - capabilities, - dateCreated, - dateUpdated, - friendlyName, - identitySid, - phoneNumber, - origin, - sid, - smsApplicationSid, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsUrl, - statusCallback, - statusCallbackMethod, - trunkSid, - uri, - voiceApplicationSid, - voiceCallerIdLookup, - voiceFallbackMethod, - voiceFallbackUrl, - voiceMethod, - voiceUrl); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("addressSid", addressSid) - .add("addressRequirements", addressRequirements) - .add("apiVersion", apiVersion) - .add("beta", beta) - .add("capabilities", capabilities) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("identitySid", identitySid) - .add("phoneNumber", phoneNumber) - .add("origin", origin) - .add("sid", sid) - .add("smsApplicationSid", smsApplicationSid) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsUrl", smsUrl) - .add("statusCallback", statusCallback) - .add("statusCallbackMethod", statusCallbackMethod) - .add("trunkSid", trunkSid) - .add("uri", uri) - .add("voiceApplicationSid", voiceApplicationSid) - .add("voiceCallerIdLookup", voiceCallerIdLookup) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceMethod", voiceMethod) - .add("voiceUrl", voiceUrl) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + addressRequirements, + addressSid, + apiVersion, + beta, + bundleSid, + capabilities, + dateCreated, + dateUpdated, + emergencyAddressSid, + emergencyAddressStatus, + emergencyStatus, + friendlyName, + identitySid, + origin, + phoneNumber, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + status, + statusCallback, + statusCallbackMethod, + trunkSid, + uri, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceReceiveMode, + voiceUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileCreator.java index 2bebe69816..c23e0bb2e1 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class MobileCreator extends Creator { + private String pathAccountSid; - private final com.twilio.type.PhoneNumber phoneNumber; + private com.twilio.type.PhoneNumber phoneNumber; private String apiVersion; private String friendlyName; private String smsApplicationSid; @@ -40,428 +53,454 @@ public class MobileCreator extends Creator { private URI voiceUrl; private String identitySid; private String addressSid; + private Mobile.EmergencyStatus emergencyStatus; + private String emergencyAddressSid; + private String trunkSid; + private Mobile.VoiceReceiveMode voiceReceiveMode; + private String bundleSid; - /** - * Construct a new MobileCreator. - * - * @param phoneNumber The phone number you want to purchase. - */ public MobileCreator(final com.twilio.type.PhoneNumber phoneNumber) { this.phoneNumber = phoneNumber; } - /** - * Construct a new MobileCreator. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number you want to purchase. - */ - public MobileCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { + public MobileCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - /** - * The Twilio REST API version to use for incoming calls made to this number. If - * omitted, uses `2010-04-01`.. - * - * @param apiVersion The Twilio REST API version to use for incoming calls made - * to this number. - * @return this - */ + public MobileCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { + this.phoneNumber = phoneNumber; + return this; + } + + public MobileCreator setPhoneNumber(final String phoneNumber) { + return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); + } + public MobileCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - /** - * A human readable description of the new incoming phone number. Maximum 64 - * characters. Defaults to a formatted version of the number.. - * - * @param friendlyName A human readable description of the new incoming phone - * number. - * @return this - */ public MobileCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The 34 character sid of the application Twilio should use to handle SMSs sent - * to the new number. If a `SmsApplicationSid` is present, Twilio will ignore - * all of the SMS urls above and use those set on the application.. - * - * @param smsApplicationSid The 34 character sid of the application Twilio - * should use to handle SMSs sent to the new number. - * @return this - */ public MobileCreator setSmsApplicationSid(final String smsApplicationSid) { this.smsApplicationSid = smsApplicationSid; return this; } - /** - * The HTTP method that should be used to request the `SmsFallbackUrl`. Must be - * either `GET` or `POST`. Defaults to `POST`.. - * - * @param smsFallbackMethod The HTTP method that should be used to request the - * SmsFallbackUrl. - * @return this - */ - public MobileCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public MobileCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML defined by SmsUrl. - * @return this - */ public MobileCreator setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML defined by SmsUrl. - * @return this - */ public MobileCreator setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method that should be used to request the `SmsUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param smsMethod The HTTP method that should be used to request the SmsUrl. - * @return this - */ public MobileCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the phone - * number.. - * - * @param smsUrl The URL that Twilio should request when somebody sends an SMS - * to the phone number. - * @return this - */ public MobileCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the phone - * number.. - * - * @param smsUrl The URL that Twilio should request when somebody sends an SMS - * to the phone number. - * @return this - */ public MobileCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback The URL that Twilio will request to pass status - * parameters to your application. - * @return this - */ public MobileCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback The URL that Twilio will request to pass status - * parameters to your application. - * @return this - */ public MobileCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio will use to make requests to the `StatusCallback` URL. - * Either `GET` or `POST`. Defaults to `POST`.. - * - * @param statusCallbackMethod The HTTP method Twilio will use to make requests - * to the StatusCallback URL. - * @return this - */ - public MobileCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public MobileCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * The 34 character sid of the application Twilio should use to handle phone - * calls to the new number. If a `VoiceApplicationSid` is present, Twilio will - * ignore all of the voice urls above and use those set on the application. - * Setting a `VoiceApplicationSid` will automatically delete your `TrunkSid` and - * vice versa.. - * - * @param voiceApplicationSid The 34 character sid of the application Twilio - * should use to handle phone calls to the new - * number. - * @return this - */ - public MobileCreator setVoiceApplicationSid(final String voiceApplicationSid) { + public MobileCreator setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - /** - * Do a lookup of a caller's name from the CNAM database and post it to your - * app. Either `true` or `false`. Defaults to `false`.. - * - * @param voiceCallerIdLookup Do a lookup of a caller's name from the CNAM - * database and post it to your app. - * @return this - */ - public MobileCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup) { + public MobileCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - /** - * The HTTP method that should be used to request the `VoiceFallbackUrl`. Either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceFallbackMethod The HTTP method that should be used to request - * the VoiceFallbackUrl. - * @return this - */ - public MobileCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public MobileCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML at `Url`.. - * - * @param voiceFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML at Url. - * @return this - */ public MobileCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML at `Url`.. - * - * @param voiceFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML at Url. - * @return this - */ public MobileCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method that should be used to request the `VoiceUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceMethod The HTTP method that should be used to request the - * VoiceUrl. - * @return this - */ public MobileCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - /** - * The URL that Twilio should request when somebody dials the new phone number. - * The VoiceURL will no longer be used if a `VoiceApplicationSid` or a - * `TrunkSid` is set.. - * - * @param voiceUrl The URL that Twilio should request when somebody dials the - * new phone number. - * @return this - */ public MobileCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The URL that Twilio should request when somebody dials the new phone number. - * The VoiceURL will no longer be used if a `VoiceApplicationSid` or a - * `TrunkSid` is set.. - * - * @param voiceUrl The URL that Twilio should request when somebody dials the - * new phone number. - * @return this - */ public MobileCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The identity_sid. - * - * @param identitySid The identity_sid - * @return this - */ public MobileCreator setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - /** - * The 34 character sid of the address Twilio should associate with the number.. - * - * @param addressSid The 34 character sid of the address Twilio should - * associate with the number. - * @return this - */ public MobileCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Mobile - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Mobile create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public MobileCreator setEmergencyStatus( + final Mobile.EmergencyStatus emergencyStatus + ) { + this.emergencyStatus = emergencyStatus; + return this; + } + + public MobileCreator setEmergencyAddressSid( + final String emergencyAddressSid + ) { + this.emergencyAddressSid = emergencyAddressSid; + return this; + } + + public MobileCreator setTrunkSid(final String trunkSid) { + this.trunkSid = trunkSid; + return this; + } + + public MobileCreator setVoiceReceiveMode( + final Mobile.VoiceReceiveMode voiceReceiveMode + ) { + this.voiceReceiveMode = voiceReceiveMode; + return this; + } + + public MobileCreator setBundleSid(final String bundleSid) { + this.bundleSid = bundleSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/Mobile.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Mobile creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Mobile creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Mobile create(final TwilioRestClient client) { + Response response = makeRequest(client); return Mobile.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Mobile content = Mobile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (phoneNumber != null) { - request.addPostParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); } if (apiVersion != null) { - request.addPostParam("ApiVersion", apiVersion); + Serializer.toString( + request, + "ApiVersion", + apiVersion, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (smsApplicationSid != null) { - request.addPostParam("SmsApplicationSid", smsApplicationSid); + Serializer.toString( + request, + "SmsApplicationSid", + smsApplicationSid, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (voiceApplicationSid != null) { - request.addPostParam("VoiceApplicationSid", voiceApplicationSid); + Serializer.toString( + request, + "VoiceApplicationSid", + voiceApplicationSid, + ParameterType.URLENCODED + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); + Serializer.toString( + request, + "VoiceCallerIdLookup", + voiceCallerIdLookup, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (identitySid != null) { - request.addPostParam("IdentitySid", identitySid); + Serializer.toString( + request, + "IdentitySid", + identitySid, + ParameterType.URLENCODED + ); } if (addressSid != null) { - request.addPostParam("AddressSid", addressSid); + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); + } + + if (emergencyStatus != null) { + Serializer.toString( + request, + "EmergencyStatus", + emergencyStatus, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressSid != null) { + Serializer.toString( + request, + "EmergencyAddressSid", + emergencyAddressSid, + ParameterType.URLENCODED + ); + } + + if (trunkSid != null) { + Serializer.toString( + request, + "TrunkSid", + trunkSid, + ParameterType.URLENCODED + ); + } + + if (voiceReceiveMode != null) { + Serializer.toString( + request, + "VoiceReceiveMode", + voiceReceiveMode, + ParameterType.URLENCODED + ); + } + + if (bundleSid != null) { + Serializer.toString( + request, + "BundleSid", + bundleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileReader.java index 2cbb861c68..cb01b44d16 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/MobileReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; @@ -10,251 +17,255 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MobileReader extends Reader { + private String pathAccountSid; private Boolean beta; private String friendlyName; private com.twilio.type.PhoneNumber phoneNumber; private String origin; + private Long pageSize; - /** - * Construct a new MobileReader. - */ - public MobileReader() { - } + public MobileReader() {} - /** - * Construct a new MobileReader. - * - * @param pathAccountSid The account_sid - */ public MobileReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Include phone numbers new to the Twilio platform. Possible values are either - * `true` or `false`. Default is `true`.. - * - * @param beta Include phone numbers new to the Twilio platform. - * @return this - */ public MobileReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * Only show the incoming phone number resources with friendly names that - * exactly match this name.. - * - * @param friendlyName Only show the incoming phone number resources with - * friendly names that exactly match this name. - * @return this - */ public MobileReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Only show the incoming phone number resources that match this pattern. You - * can specify partial numbers and use '*' as a wildcard for any digit.. - * - * @param phoneNumber Only show the incoming phone number resources that match - * this pattern. - * @return this - */ - public MobileReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public MobileReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * Only show the incoming phone number resources that match this pattern. You - * can specify partial numbers and use '*' as a wildcard for any digit.. - * - * @param phoneNumber Only show the incoming phone number resources that match - * this pattern. - * @return this - */ public MobileReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * Include phone numbers based on the origin, by default, phone numbers of all - * origin are included. Possible values are either `twilio` or `hosted`.. - * - * @param origin Include phone numbers based on the origin, by default, phone - * numbers of all origin are included. - * @return this - */ public MobileReader setOrigin(final String origin) { this.origin = origin; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Mobile ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MobileReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Mobile ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + Mobile.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/Mobile.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Mobile ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + Mobile.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Mobile read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + Mobile.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Mobile Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Mobile read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "incoming_phone_numbers", - response.getContent(), - Mobile.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); } if (origin != null) { - request.addQueryParam("Origin", origin); + Serializer.toString(request, "Origin", origin, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFree.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFree.java index 68de4591db..74ad7862f2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFree.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFree.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; @@ -10,33 +17,124 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class TollFree extends Resource { - private static final long serialVersionUID = 181300083665916L; + + public static TollFreeCreator creator( + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new TollFreeCreator(phoneNumber); + } + + public static TollFreeCreator creator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { + return new TollFreeCreator(pathAccountSid, phoneNumber); + } + + public static TollFreeReader reader() { + return new TollFreeReader(); + } + + public static TollFreeReader reader(final String pathAccountSid) { + return new TollFreeReader(pathAccountSid); + } + + public enum EmergencyAddressStatus { + REGISTERED("registered"), + UNREGISTERED("unregistered"), + PENDING_REGISTRATION("pending-registration"), + REGISTRATION_FAILURE("registration-failure"), + PENDING_UNREGISTRATION("pending-unregistration"), + UNREGISTRATION_FAILURE("unregistration-failure"); + + private final String value; + + private EmergencyAddressStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EmergencyAddressStatus forValue(final String value) { + return Promoter.enumFromString( + value, + EmergencyAddressStatus.values() + ); + } + } + + public enum VoiceReceiveMode { + VOICE("voice"), + FAX("fax"); + + private final String value; + + private VoiceReceiveMode(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static VoiceReceiveMode forValue(final String value) { + return Promoter.enumFromString(value, VoiceReceiveMode.values()); + } + } + + public enum EmergencyStatus { + ACTIVE("Active"), + INACTIVE("Inactive"); + + private final String value; + + private EmergencyStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EmergencyStatus forValue(final String value) { + return Promoter.enumFromString(value, EmergencyStatus.values()); + } + } public enum AddressRequirement { NONE("none"), @@ -50,15 +148,11 @@ private AddressRequirement(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a AddressRequirement from a string. - * @param value string value - * @return generated AddressRequirement - */ @JsonCreator public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); @@ -66,55 +160,16 @@ public static AddressRequirement forValue(final String value) { } /** - * Create a TollFreeReader to execute read. - * - * @param pathAccountSid The account_sid - * @return TollFreeReader capable of executing the read - */ - public static TollFreeReader reader(final String pathAccountSid) { - return new TollFreeReader(pathAccountSid); - } - - /** - * Create a TollFreeReader to execute read. - * - * @return TollFreeReader capable of executing the read - */ - public static TollFreeReader reader() { - return new TollFreeReader(); - } - - /** - * Create a TollFreeCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number you want to purchase. - * @return TollFreeCreator capable of executing the create - */ - public static TollFreeCreator creator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { - return new TollFreeCreator(pathAccountSid, phoneNumber); - } - - /** - * Create a TollFreeCreator to execute create. - * - * @param phoneNumber The phone number you want to purchase. - * @return TollFreeCreator capable of executing the create - */ - public static TollFreeCreator creator(final com.twilio.type.PhoneNumber phoneNumber) { - return new TollFreeCreator(phoneNumber); - } - - /** - * Converts a JSON String into a TollFree object using the provided - * ObjectMapper. - * + * Converts a JSON String into a TollFree object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return TollFree object represented by the provided JSON */ - public static TollFree fromJson(final String json, final ObjectMapper objectMapper) { + public static TollFree fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TollFree.class); @@ -128,12 +183,15 @@ public static TollFree fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a TollFree object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return TollFree object represented by the provided JSON */ - public static TollFree fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static TollFree fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TollFree.class); @@ -144,110 +202,202 @@ public static TollFree fromJson(final InputStream json, final ObjectMapper objec } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String addressSid; + + @Getter private final TollFree.AddressRequirement addressRequirements; + + @Getter + private final String addressSid; + + @Getter private final String apiVersion; + + @Getter private final Boolean beta; + + @Getter + private final String bundleSid; + + @Getter private final PhoneNumberCapabilities capabilities; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String emergencyAddressSid; + + @Getter + private final TollFree.EmergencyAddressStatus emergencyAddressStatus; + + @Getter + private final TollFree.EmergencyStatus emergencyStatus; + + @Getter private final String friendlyName; + + @Getter private final String identitySid; - private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String origin; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String sid; + + @Getter private final String smsApplicationSid; + + @Getter private final HttpMethod smsFallbackMethod; + + @Getter private final URI smsFallbackUrl; + + @Getter private final HttpMethod smsMethod; + + @Getter private final URI smsUrl; + + @Getter + private final String status; + + @Getter private final URI statusCallback; + + @Getter private final HttpMethod statusCallbackMethod; + + @Getter private final String trunkSid; + + @Getter private final String uri; + + @Getter private final String voiceApplicationSid; + + @Getter private final Boolean voiceCallerIdLookup; + + @Getter private final HttpMethod voiceFallbackMethod; + + @Getter private final URI voiceFallbackUrl; + + @Getter private final HttpMethod voiceMethod; + + @Getter + private final TollFree.VoiceReceiveMode voiceReceiveMode; + + @Getter private final URI voiceUrl; @JsonCreator - private TollFree(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("address_sid") - final String addressSid, - @JsonProperty("address_requirements") - final TollFree.AddressRequirement addressRequirements, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("identity_sid") - final String identitySid, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("origin") - final String origin, - @JsonProperty("sid") - final String sid, - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("status_callback") - final URI statusCallback, - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("uri") - final String uri, - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_url") - final URI voiceUrl) { + private TollFree( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "address_requirements" + ) final TollFree.AddressRequirement addressRequirements, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("emergency_address_sid") final String emergencyAddressSid, + @JsonProperty( + "emergency_address_status" + ) final TollFree.EmergencyAddressStatus emergencyAddressStatus, + @JsonProperty( + "emergency_status" + ) final TollFree.EmergencyStatus emergencyStatus, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity_sid") final String identitySid, + @JsonProperty("origin") final String origin, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status") final String status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("uri") final String uri, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty( + "voice_receive_mode" + ) final TollFree.VoiceReceiveMode voiceReceiveMode, + @JsonProperty("voice_url") final URI voiceUrl + ) { this.accountSid = accountSid; - this.addressSid = addressSid; this.addressRequirements = addressRequirements; + this.addressSid = addressSid; this.apiVersion = apiVersion; this.beta = beta; + this.bundleSid = bundleSid; this.capabilities = capabilities; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.emergencyAddressSid = emergencyAddressSid; + this.emergencyAddressStatus = emergencyAddressStatus; + this.emergencyStatus = emergencyStatus; this.friendlyName = friendlyName; this.identitySid = identitySid; - this.phoneNumber = phoneNumber; this.origin = origin; + this.phoneNumber = phoneNumber; this.sid = sid; this.smsApplicationSid = smsApplicationSid; this.smsFallbackMethod = smsFallbackMethod; this.smsFallbackUrl = smsFallbackUrl; this.smsMethod = smsMethod; this.smsUrl = smsUrl; + this.status = status; this.statusCallback = statusCallback; this.statusCallbackMethod = statusCallbackMethod; this.trunkSid = trunkSid; @@ -257,294 +407,10 @@ private TollFree(@JsonProperty("account_sid") this.voiceFallbackMethod = voiceFallbackMethod; this.voiceFallbackUrl = voiceFallbackUrl; this.voiceMethod = voiceMethod; + this.voiceReceiveMode = voiceReceiveMode; this.voiceUrl = voiceUrl; } - /** - * Returns The The unique id of the Account responsible for this phone number.. - * - * @return The unique id of the Account responsible for this phone number. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The 34 character sid of the address associated with this number.. - * - * @return The 34 character sid of the address associated with this number. - */ - public final String getAddressSid() { - return this.addressSid; - } - - /** - * Returns The This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio.. - * - * @return This indicates whether the phone number requires you or your - * customer to have an Address registered with Twilio. - */ - public final TollFree.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - - /** - * Returns The Calls to this phone number will start a new TwiML session with - * this API version.. - * - * @return Calls to this phone number will start a new TwiML session with this - * API version. - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The Phone numbers new to the Twilio platform are marked as beta.. - * - * @return Phone numbers new to the Twilio platform are marked as beta. - */ - public final Boolean getBeta() { - return this.beta; - } - - /** - * Returns The This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages.. - * - * @return This is a set of boolean properties that indicate whether a phone - * number can receive calls or messages. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - - /** - * Returns The The date that this resource was created, given as GMT RFC 2822 - * format.. - * - * @return The date that this resource was created, given as GMT RFC 2822 - * format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated, given as GMT RFC - * 2822 format.. - * - * @return The date that this resource was last updated, given as GMT RFC 2822 - * format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human readable descriptive text for this resource, up to 64 - * characters long.. - * - * @return A human readable descriptive text for this resource, up to 64 - * characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The identity_sid. - * - * @return The identity_sid - */ - public final String getIdentitySid() { - return this.identitySid; - } - - /** - * Returns The The incoming phone number.. - * - * @return The incoming phone number. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - - /** - * Returns The Twilio owned phone numbers are marked as twilio while hosted - * phone numbers are marked as hosted.. - * - * @return Twilio owned phone numbers are marked as twilio while hosted phone - * numbers are marked as hosted. - */ - public final String getOrigin() { - return this.origin; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The 34 character sid of the application Twilio should use to - * handle SMSs sent to this number.. - * - * @return The 34 character sid of the application Twilio should use to handle - * SMSs sent to this number. - */ - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the above URL.. - * - * @return The HTTP method Twilio will use when requesting the above URL. - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - - /** - * Returns The The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML from SmsUrl.. - * - * @return The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML from SmsUrl. - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - - /** - * Returns The The HTTP method Twilio will use when making requests to the - * SmsUrl.. - * - * @return The HTTP method Twilio will use when making requests to the SmsUrl. - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - - /** - * Returns The The URL Twilio will request when receiving an incoming SMS - * message to this number.. - * - * @return The URL Twilio will request when receiving an incoming SMS message - * to this number. - */ - public final URI getSmsUrl() { - return this.smsUrl; - } - - /** - * Returns The The URL that Twilio will request to pass status parameters to - * your application.. - * - * @return The URL that Twilio will request to pass status parameters to your - * application. - */ - public final URI getStatusCallback() { - return this.statusCallback; - } - - /** - * Returns The The HTTP method Twilio will use to make requests to the - * StatusCallback URL.. - * - * @return The HTTP method Twilio will use to make requests to the - * StatusCallback URL. - */ - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - - /** - * Returns The The 34 character sid of the Trunk Twilio should use to handle - * phone calls to this number.. - * - * @return The 34 character sid of the Trunk Twilio should use to handle phone - * calls to this number. - */ - public final String getTrunkSid() { - return this.trunkSid; - } - - /** - * Returns The The URI for this resource, relative to https://api.. - * - * @return The URI for this resource, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The 34 character sid of the application Twilio should use to - * handle phone calls to this number.. - * - * @return The 34 character sid of the application Twilio should use to handle - * phone calls to this number. - */ - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - - /** - * Returns The Look up the caller's caller-ID name from the CNAM database.. - * - * @return Look up the caller's caller-ID name from the CNAM database. - */ - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the - * VoiceFallbackUrl.. - * - * @return The HTTP method Twilio will use when requesting the VoiceFallbackUrl. - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - - /** - * Returns The The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML requested by Url.. - * - * @return The URL that Twilio will request if an error occurs retrieving or - * executing the TwiML requested by Url. - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - - /** - * Returns The The HTTP method Twilio will use when requesting the above Url.. - * - * @return The HTTP method Twilio will use when requesting the above Url. - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - - /** - * Returns The The URL Twilio will request when this phone number receives a - * call.. - * - * @return The URL Twilio will request when this phone number receives a call. - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -556,100 +422,84 @@ public boolean equals(final Object o) { } TollFree other = (TollFree) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(addressSid, other.addressSid) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(identitySid, other.identitySid) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(origin, other.origin) && - Objects.equals(sid, other.sid) && - Objects.equals(smsApplicationSid, other.smsApplicationSid) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(statusCallback, other.statusCallback) && - Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(uri, other.uri) && - Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && - Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceUrl, other.voiceUrl); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(emergencyAddressSid, other.emergencyAddressSid) && + Objects.equals( + emergencyAddressStatus, + other.emergencyAddressStatus + ) && + Objects.equals(emergencyStatus, other.emergencyStatus) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identitySid, other.identitySid) && + Objects.equals(origin, other.origin) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceReceiveMode, other.voiceReceiveMode) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - addressSid, - addressRequirements, - apiVersion, - beta, - capabilities, - dateCreated, - dateUpdated, - friendlyName, - identitySid, - phoneNumber, - origin, - sid, - smsApplicationSid, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsUrl, - statusCallback, - statusCallbackMethod, - trunkSid, - uri, - voiceApplicationSid, - voiceCallerIdLookup, - voiceFallbackMethod, - voiceFallbackUrl, - voiceMethod, - voiceUrl); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("addressSid", addressSid) - .add("addressRequirements", addressRequirements) - .add("apiVersion", apiVersion) - .add("beta", beta) - .add("capabilities", capabilities) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("identitySid", identitySid) - .add("phoneNumber", phoneNumber) - .add("origin", origin) - .add("sid", sid) - .add("smsApplicationSid", smsApplicationSid) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsUrl", smsUrl) - .add("statusCallback", statusCallback) - .add("statusCallbackMethod", statusCallbackMethod) - .add("trunkSid", trunkSid) - .add("uri", uri) - .add("voiceApplicationSid", voiceApplicationSid) - .add("voiceCallerIdLookup", voiceCallerIdLookup) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceMethod", voiceMethod) - .add("voiceUrl", voiceUrl) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + addressRequirements, + addressSid, + apiVersion, + beta, + bundleSid, + capabilities, + dateCreated, + dateUpdated, + emergencyAddressSid, + emergencyAddressStatus, + emergencyStatus, + friendlyName, + identitySid, + origin, + phoneNumber, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + status, + statusCallback, + statusCallbackMethod, + trunkSid, + uri, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceReceiveMode, + voiceUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeCreator.java index b739462044..b5424c6b78 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class TollFreeCreator extends Creator { + private String pathAccountSid; - private final com.twilio.type.PhoneNumber phoneNumber; + private com.twilio.type.PhoneNumber phoneNumber; private String apiVersion; private String friendlyName; private String smsApplicationSid; @@ -40,428 +53,459 @@ public class TollFreeCreator extends Creator { private URI voiceUrl; private String identitySid; private String addressSid; + private TollFree.EmergencyStatus emergencyStatus; + private String emergencyAddressSid; + private String trunkSid; + private TollFree.VoiceReceiveMode voiceReceiveMode; + private String bundleSid; - /** - * Construct a new TollFreeCreator. - * - * @param phoneNumber The phone number you want to purchase. - */ public TollFreeCreator(final com.twilio.type.PhoneNumber phoneNumber) { this.phoneNumber = phoneNumber; } - /** - * Construct a new TollFreeCreator. - * - * @param pathAccountSid The account_sid - * @param phoneNumber The phone number you want to purchase. - */ - public TollFreeCreator(final String pathAccountSid, - final com.twilio.type.PhoneNumber phoneNumber) { + public TollFreeCreator( + final String pathAccountSid, + final com.twilio.type.PhoneNumber phoneNumber + ) { this.pathAccountSid = pathAccountSid; this.phoneNumber = phoneNumber; } - /** - * The Twilio REST API version to use for incoming calls made to this number. If - * omitted, uses `2010-04-01`.. - * - * @param apiVersion The Twilio REST API version to use for incoming calls made - * to this number. - * @return this - */ + public TollFreeCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { + this.phoneNumber = phoneNumber; + return this; + } + + public TollFreeCreator setPhoneNumber(final String phoneNumber) { + return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); + } + public TollFreeCreator setApiVersion(final String apiVersion) { this.apiVersion = apiVersion; return this; } - /** - * A human readable description of the new incoming phone number. Maximum 64 - * characters. Defaults to a formatted version of the number.. - * - * @param friendlyName A human readable description of the new incoming phone - * number. - * @return this - */ public TollFreeCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The 34 character sid of the application Twilio should use to handle SMSs sent - * to the new number. If a `SmsApplicationSid` is present, Twilio will ignore - * all of the SMS urls above and use those set on the application.. - * - * @param smsApplicationSid The 34 character sid of the application Twilio - * should use to handle SMSs sent to the new number. - * @return this - */ - public TollFreeCreator setSmsApplicationSid(final String smsApplicationSid) { + public TollFreeCreator setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - /** - * The HTTP method that should be used to request the `SmsFallbackUrl`. Must be - * either `GET` or `POST`. Defaults to `POST`.. - * - * @param smsFallbackMethod The HTTP method that should be used to request the - * SmsFallbackUrl. - * @return this - */ - public TollFreeCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public TollFreeCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML defined by SmsUrl. - * @return this - */ public TollFreeCreator setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by `SmsUrl`.. - * - * @param smsFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML defined by SmsUrl. - * @return this - */ public TollFreeCreator setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method that should be used to request the `SmsUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param smsMethod The HTTP method that should be used to request the SmsUrl. - * @return this - */ public TollFreeCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the phone - * number.. - * - * @param smsUrl The URL that Twilio should request when somebody sends an SMS - * to the phone number. - * @return this - */ public TollFreeCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the phone - * number.. - * - * @param smsUrl The URL that Twilio should request when somebody sends an SMS - * to the phone number. - * @return this - */ public TollFreeCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback The URL that Twilio will request to pass status - * parameters to your application. - * @return this - */ public TollFreeCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param statusCallback The URL that Twilio will request to pass status - * parameters to your application. - * @return this - */ public TollFreeCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The HTTP method Twilio will use to make requests to the `StatusCallback` URL. - * Either `GET` or `POST`. Defaults to `POST`.. - * - * @param statusCallbackMethod The HTTP method Twilio will use to make requests - * to the StatusCallback URL. - * @return this - */ - public TollFreeCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public TollFreeCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * The 34 character sid of the application Twilio should use to handle phone - * calls to the new number. If a `VoiceApplicationSid` is present, Twilio will - * ignore all of the voice urls above and use those set on the application. - * Setting a `VoiceApplicationSid` will automatically delete your `TrunkSid` and - * vice versa.. - * - * @param voiceApplicationSid The 34 character sid of the application Twilio - * should use to handle phone calls to the new - * number. - * @return this - */ - public TollFreeCreator setVoiceApplicationSid(final String voiceApplicationSid) { + public TollFreeCreator setVoiceApplicationSid( + final String voiceApplicationSid + ) { this.voiceApplicationSid = voiceApplicationSid; return this; } - /** - * Do a lookup of a caller's name from the CNAM database and post it to your - * app. Either `true` or `false`. Defaults to `false`.. - * - * @param voiceCallerIdLookup Do a lookup of a caller's name from the CNAM - * database and post it to your app. - * @return this - */ - public TollFreeCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup) { + public TollFreeCreator setVoiceCallerIdLookup( + final Boolean voiceCallerIdLookup + ) { this.voiceCallerIdLookup = voiceCallerIdLookup; return this; } - /** - * The HTTP method that should be used to request the `VoiceFallbackUrl`. Either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceFallbackMethod The HTTP method that should be used to request - * the VoiceFallbackUrl. - * @return this - */ - public TollFreeCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public TollFreeCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML at `Url`.. - * - * @param voiceFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML at Url. - * @return this - */ public TollFreeCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML at `Url`.. - * - * @param voiceFallbackUrl A URL that Twilio will request if an error occurs - * requesting or executing the TwiML at Url. - * @return this - */ public TollFreeCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method that should be used to request the `VoiceUrl`. Must be either - * `GET` or `POST`. Defaults to `POST`.. - * - * @param voiceMethod The HTTP method that should be used to request the - * VoiceUrl. - * @return this - */ public TollFreeCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - /** - * The URL that Twilio should request when somebody dials the new phone number. - * The VoiceURL will no longer be used if a `VoiceApplicationSid` or a - * `TrunkSid` is set.. - * - * @param voiceUrl The URL that Twilio should request when somebody dials the - * new phone number. - * @return this - */ public TollFreeCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The URL that Twilio should request when somebody dials the new phone number. - * The VoiceURL will no longer be used if a `VoiceApplicationSid` or a - * `TrunkSid` is set.. - * - * @param voiceUrl The URL that Twilio should request when somebody dials the - * new phone number. - * @return this - */ public TollFreeCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The identity_sid. - * - * @param identitySid The identity_sid - * @return this - */ public TollFreeCreator setIdentitySid(final String identitySid) { this.identitySid = identitySid; return this; } - /** - * The 34 character sid of the address Twilio should associate with the number.. - * - * @param addressSid The 34 character sid of the address Twilio should - * associate with the number. - * @return this - */ public TollFreeCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created TollFree - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public TollFree create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public TollFreeCreator setEmergencyStatus( + final TollFree.EmergencyStatus emergencyStatus + ) { + this.emergencyStatus = emergencyStatus; + return this; + } + + public TollFreeCreator setEmergencyAddressSid( + final String emergencyAddressSid + ) { + this.emergencyAddressSid = emergencyAddressSid; + return this; + } + + public TollFreeCreator setTrunkSid(final String trunkSid) { + this.trunkSid = trunkSid; + return this; + } + + public TollFreeCreator setVoiceReceiveMode( + final TollFree.VoiceReceiveMode voiceReceiveMode + ) { + this.voiceReceiveMode = voiceReceiveMode; + return this; + } + + public TollFreeCreator setBundleSid(final String bundleSid) { + this.bundleSid = bundleSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/TollFree.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TollFree creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TollFree creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return TollFree.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TollFree create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TollFree.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TollFree content = TollFree.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (phoneNumber != null) { - request.addPostParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); } if (apiVersion != null) { - request.addPostParam("ApiVersion", apiVersion); + Serializer.toString( + request, + "ApiVersion", + apiVersion, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (smsApplicationSid != null) { - request.addPostParam("SmsApplicationSid", smsApplicationSid); + Serializer.toString( + request, + "SmsApplicationSid", + smsApplicationSid, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (voiceApplicationSid != null) { - request.addPostParam("VoiceApplicationSid", voiceApplicationSid); + Serializer.toString( + request, + "VoiceApplicationSid", + voiceApplicationSid, + ParameterType.URLENCODED + ); } if (voiceCallerIdLookup != null) { - request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString()); + Serializer.toString( + request, + "VoiceCallerIdLookup", + voiceCallerIdLookup, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (identitySid != null) { - request.addPostParam("IdentitySid", identitySid); + Serializer.toString( + request, + "IdentitySid", + identitySid, + ParameterType.URLENCODED + ); } if (addressSid != null) { - request.addPostParam("AddressSid", addressSid); + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); + } + + if (emergencyStatus != null) { + Serializer.toString( + request, + "EmergencyStatus", + emergencyStatus, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressSid != null) { + Serializer.toString( + request, + "EmergencyAddressSid", + emergencyAddressSid, + ParameterType.URLENCODED + ); + } + + if (trunkSid != null) { + Serializer.toString( + request, + "TrunkSid", + trunkSid, + ParameterType.URLENCODED + ); + } + + if (voiceReceiveMode != null) { + Serializer.toString( + request, + "VoiceReceiveMode", + voiceReceiveMode, + ParameterType.URLENCODED + ); + } + + if (bundleSid != null) { + Serializer.toString( + request, + "BundleSid", + bundleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeReader.java index 1f1b651879..df67b31c6f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/TollFreeReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber; @@ -10,251 +17,259 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TollFreeReader extends Reader { + private String pathAccountSid; private Boolean beta; private String friendlyName; private com.twilio.type.PhoneNumber phoneNumber; private String origin; + private Long pageSize; - /** - * Construct a new TollFreeReader. - */ - public TollFreeReader() { - } + public TollFreeReader() {} - /** - * Construct a new TollFreeReader. - * - * @param pathAccountSid The account_sid - */ public TollFreeReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Include phone numbers new to the Twilio platform. Possible values are either - * `true` or `false`. Default is `true`.. - * - * @param beta Include phone numbers new to the Twilio platform. - * @return this - */ public TollFreeReader setBeta(final Boolean beta) { this.beta = beta; return this; } - /** - * Only show the incoming phone number resources with friendly names that - * exactly match this name.. - * - * @param friendlyName Only show the incoming phone number resources with - * friendly names that exactly match this name. - * @return this - */ public TollFreeReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Only show the incoming phone number resources that match this pattern. You - * can specify partial numbers and use '*' as a wildcard for any digit.. - * - * @param phoneNumber Only show the incoming phone number resources that match - * this pattern. - * @return this - */ - public TollFreeReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public TollFreeReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * Only show the incoming phone number resources that match this pattern. You - * can specify partial numbers and use '*' as a wildcard for any digit.. - * - * @param phoneNumber Only show the incoming phone number resources that match - * this pattern. - * @return this - */ public TollFreeReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * Include phone numbers based on the origin, by default, phone numbers of all - * origin are included. Possible values are either `twilio` or `hosted`.. - * - * @param origin Include phone numbers based on the origin, by default, phone - * numbers of all origin are included. - * @return this - */ public TollFreeReader setOrigin(final String origin) { this.origin = origin; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TollFree ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TollFreeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TollFree ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + TollFree.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/TollFree.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/TollFree.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return TollFree ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + TollFree.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TollFree read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "incoming_phone_numbers", + response.getContent(), + TollFree.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of TollFree Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("TollFree read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "incoming_phone_numbers", - response.getContent(), - TollFree.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (beta != null) { - request.addQueryParam("Beta", beta.toString()); + Serializer.toString(request, "Beta", beta, ParameterType.QUERY); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); } if (origin != null) { - request.addQueryParam("Origin", origin); + Serializer.toString(request, "Origin", origin, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtension.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtension.java index 5048271421..26108d43c6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtension.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtension.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber.assignedaddon; @@ -11,97 +18,85 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AssignedAddOnExtension extends Resource { - private static final long serialVersionUID = 254756104668429L; - - /** - * Create a AssignedAddOnExtensionFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param pathAssignedAddOnSid The assigned_add_on_sid - * @param pathSid The unique Extension Sid - * @return AssignedAddOnExtensionFetcher capable of executing the fetch - */ - public static AssignedAddOnExtensionFetcher fetcher(final String pathAccountSid, - final String pathResourceSid, - final String pathAssignedAddOnSid, - final String pathSid) { - return new AssignedAddOnExtensionFetcher(pathAccountSid, pathResourceSid, pathAssignedAddOnSid, pathSid); - } - - /** - * Create a AssignedAddOnExtensionFetcher to execute fetch. - * - * @param pathResourceSid The resource_sid - * @param pathAssignedAddOnSid The assigned_add_on_sid - * @param pathSid The unique Extension Sid - * @return AssignedAddOnExtensionFetcher capable of executing the fetch - */ - public static AssignedAddOnExtensionFetcher fetcher(final String pathResourceSid, - final String pathAssignedAddOnSid, - final String pathSid) { - return new AssignedAddOnExtensionFetcher(pathResourceSid, pathAssignedAddOnSid, pathSid); - } - /** - * Create a AssignedAddOnExtensionReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param pathAssignedAddOnSid The assigned_add_on_sid - * @return AssignedAddOnExtensionReader capable of executing the read - */ - public static AssignedAddOnExtensionReader reader(final String pathAccountSid, - final String pathResourceSid, - final String pathAssignedAddOnSid) { - return new AssignedAddOnExtensionReader(pathAccountSid, pathResourceSid, pathAssignedAddOnSid); + public static AssignedAddOnExtensionFetcher fetcher( + final String pathResourceSid, + final String pathAssignedAddOnSid, + final String pathSid + ) { + return new AssignedAddOnExtensionFetcher( + pathResourceSid, + pathAssignedAddOnSid, + pathSid + ); + } + + public static AssignedAddOnExtensionFetcher fetcher( + final String pathAccountSid, + final String pathResourceSid, + final String pathAssignedAddOnSid, + final String pathSid + ) { + return new AssignedAddOnExtensionFetcher( + pathAccountSid, + pathResourceSid, + pathAssignedAddOnSid, + pathSid + ); + } + + public static AssignedAddOnExtensionReader reader( + final String pathResourceSid, + final String pathAssignedAddOnSid + ) { + return new AssignedAddOnExtensionReader( + pathResourceSid, + pathAssignedAddOnSid + ); + } + + public static AssignedAddOnExtensionReader reader( + final String pathAccountSid, + final String pathResourceSid, + final String pathAssignedAddOnSid + ) { + return new AssignedAddOnExtensionReader( + pathAccountSid, + pathResourceSid, + pathAssignedAddOnSid + ); } /** - * Create a AssignedAddOnExtensionReader to execute read. - * - * @param pathResourceSid The resource_sid - * @param pathAssignedAddOnSid The assigned_add_on_sid - * @return AssignedAddOnExtensionReader capable of executing the read - */ - public static AssignedAddOnExtensionReader reader(final String pathResourceSid, - final String pathAssignedAddOnSid) { - return new AssignedAddOnExtensionReader(pathResourceSid, pathAssignedAddOnSid); - } - - /** - * Converts a JSON String into a AssignedAddOnExtension object using the - * provided ObjectMapper. - * + * Converts a JSON String into a AssignedAddOnExtension object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AssignedAddOnExtension object represented by the provided JSON */ - public static AssignedAddOnExtension fromJson(final String json, final ObjectMapper objectMapper) { + public static AssignedAddOnExtension fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssignedAddOnExtension.class); @@ -113,14 +108,17 @@ public static AssignedAddOnExtension fromJson(final String json, final ObjectMap } /** - * Converts a JSON InputStream into a AssignedAddOnExtension object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a AssignedAddOnExtension object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AssignedAddOnExtension object represented by the provided JSON */ - public static AssignedAddOnExtension fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AssignedAddOnExtension fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AssignedAddOnExtension.class); @@ -131,126 +129,66 @@ public static AssignedAddOnExtension fromJson(final InputStream json, final Obje } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String resourceSid; + + @Getter private final String assignedAddOnSid; + + @Getter + private final Boolean enabled; + + @Getter private final String friendlyName; + + @Getter private final String productName; + + @Getter + private final String resourceSid; + + @Getter + private final String sid; + + @Getter private final String uniqueName; + + @Getter private final String uri; - private final Boolean enabled; @JsonCreator - private AssignedAddOnExtension(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("resource_sid") - final String resourceSid, - @JsonProperty("assigned_add_on_sid") - final String assignedAddOnSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("product_name") - final String productName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("uri") - final String uri, - @JsonProperty("enabled") - final Boolean enabled) { - this.sid = sid; + private AssignedAddOnExtension( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assigned_add_on_sid") final String assignedAddOnSid, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("product_name") final String productName, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; - this.resourceSid = resourceSid; this.assignedAddOnSid = assignedAddOnSid; + this.enabled = enabled; this.friendlyName = friendlyName; this.productName = productName; + this.resourceSid = resourceSid; + this.sid = sid; this.uniqueName = uniqueName; this.uri = uri; - this.enabled = enabled; - } - - /** - * Returns The A string that uniquely identifies this Extension. - * - * @return A string that uniquely identifies this Extension - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The Account id that has installed this Add-on. - * - * @return The Account id that has installed this Add-on - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The Phone Number id that has installed this Add-on. - * - * @return The Phone Number id that has installed this Add-on - */ - public final String getResourceSid() { - return this.resourceSid; - } - - /** - * Returns The A string that uniquely identifies the assigned Add-on - * installation. - * - * @return A string that uniquely identifies the assigned Add-on installation - */ - public final String getAssignedAddOnSid() { - return this.assignedAddOnSid; - } - - /** - * Returns The A human-readable description of this Extension. - * - * @return A human-readable description of this Extension - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The A human-readable description of the Extension's Product. - * - * @return A human-readable description of the Extension's Product - */ - public final String getProductName() { - return this.productName; - } - - /** - * Returns The The string that uniquely identifies this Extension. - * - * @return The string that uniquely identifies this Extension - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The A Boolean indicating if the Extension will be invoked. - * - * @return A Boolean indicating if the Extension will be invoked - */ - public final Boolean getEnabled() { - return this.enabled; } @Override @@ -264,43 +202,31 @@ public boolean equals(final Object o) { } AssignedAddOnExtension other = (AssignedAddOnExtension) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(resourceSid, other.resourceSid) && - Objects.equals(assignedAddOnSid, other.assignedAddOnSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(productName, other.productName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(uri, other.uri) && - Objects.equals(enabled, other.enabled); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assignedAddOnSid, other.assignedAddOnSid) && + Objects.equals(enabled, other.enabled) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(productName, other.productName) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - resourceSid, - assignedAddOnSid, - friendlyName, - productName, - uniqueName, - uri, - enabled); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("resourceSid", resourceSid) - .add("assignedAddOnSid", assignedAddOnSid) - .add("friendlyName", friendlyName) - .add("productName", productName) - .add("uniqueName", uniqueName) - .add("uri", uri) - .add("enabled", enabled) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + assignedAddOnSid, + enabled, + friendlyName, + productName, + resourceSid, + sid, + uniqueName, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionFetcher.java index 574f2c20cd..fb618999fc 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber.assignedaddon; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,86 +24,115 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssignedAddOnExtensionFetcher + extends Fetcher { -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class AssignedAddOnExtensionFetcher extends Fetcher { private String pathAccountSid; - private final String pathResourceSid; - private final String pathAssignedAddOnSid; - private final String pathSid; + private String pathResourceSid; + private String pathAssignedAddOnSid; + private String pathSid; - /** - * Construct a new AssignedAddOnExtensionFetcher. - * - * @param pathResourceSid The resource_sid - * @param pathAssignedAddOnSid The assigned_add_on_sid - * @param pathSid The unique Extension Sid - */ - public AssignedAddOnExtensionFetcher(final String pathResourceSid, - final String pathAssignedAddOnSid, - final String pathSid) { + public AssignedAddOnExtensionFetcher( + final String pathResourceSid, + final String pathAssignedAddOnSid, + final String pathSid + ) { this.pathResourceSid = pathResourceSid; this.pathAssignedAddOnSid = pathAssignedAddOnSid; this.pathSid = pathSid; } - /** - * Construct a new AssignedAddOnExtensionFetcher. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param pathAssignedAddOnSid The assigned_add_on_sid - * @param pathSid The unique Extension Sid - */ - public AssignedAddOnExtensionFetcher(final String pathAccountSid, - final String pathResourceSid, - final String pathAssignedAddOnSid, - final String pathSid) { + public AssignedAddOnExtensionFetcher( + final String pathAccountSid, + final String pathResourceSid, + final String pathAssignedAddOnSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.pathAssignedAddOnSid = pathAssignedAddOnSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AssignedAddOnExtension - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AssignedAddOnExtension fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = + path.replace( + "{" + "AssignedAddOnSid" + "}", + this.pathAssignedAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathResourceSid + "/AssignedAddOns/" + this.pathAssignedAddOnSid + "/Extensions/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AssignedAddOnExtension fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AssignedAddOnExtension fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return AssignedAddOnExtension.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public AssignedAddOnExtension fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AssignedAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AssignedAddOnExtension content = AssignedAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionReader.java b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionReader.java index e8ea07d4ab..4213d8daaa 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/incomingphonenumber/assignedaddon/AssignedAddOnExtensionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.incomingphonenumber.assignedaddon; @@ -10,185 +17,231 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssignedAddOnExtensionReader + extends Reader { -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class AssignedAddOnExtensionReader extends Reader { private String pathAccountSid; - private final String pathResourceSid; - private final String pathAssignedAddOnSid; - - /** - * Construct a new AssignedAddOnExtensionReader. - * - * @param pathResourceSid The resource_sid - * @param pathAssignedAddOnSid The assigned_add_on_sid - */ - public AssignedAddOnExtensionReader(final String pathResourceSid, - final String pathAssignedAddOnSid) { + private String pathResourceSid; + private String pathAssignedAddOnSid; + private Long pageSize; + + public AssignedAddOnExtensionReader( + final String pathResourceSid, + final String pathAssignedAddOnSid + ) { this.pathResourceSid = pathResourceSid; this.pathAssignedAddOnSid = pathAssignedAddOnSid; } - /** - * Construct a new AssignedAddOnExtensionReader. - * - * @param pathAccountSid The account_sid - * @param pathResourceSid The resource_sid - * @param pathAssignedAddOnSid The assigned_add_on_sid - */ - public AssignedAddOnExtensionReader(final String pathAccountSid, - final String pathResourceSid, - final String pathAssignedAddOnSid) { + public AssignedAddOnExtensionReader( + final String pathAccountSid, + final String pathResourceSid, + final String pathAssignedAddOnSid + ) { this.pathAccountSid = pathAccountSid; this.pathResourceSid = pathResourceSid; this.pathAssignedAddOnSid = pathAssignedAddOnSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AssignedAddOnExtension ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AssignedAddOnExtensionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AssignedAddOnExtension ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + AssignedAddOnExtension.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{ResourceSid}/AssignedAddOns/{AssignedAddOnSid}/Extensions.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ResourceSid" + "}", + this.pathResourceSid.toString() + ); + path = + path.replace( + "{" + "AssignedAddOnSid" + "}", + this.pathAssignedAddOnSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/" + this.pathResourceSid + "/AssignedAddOns/" + this.pathAssignedAddOnSid + "/Extensions.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AssignedAddOnExtension ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + AssignedAddOnExtension.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AssignedAddOnExtension read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "extensions", + response.getContent(), + AssignedAddOnExtension.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AssignedAddOnExtension Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AssignedAddOnExtension read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "extensions", - response.getContent(), - AssignedAddOnExtension.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/Feedback.java b/src/main/java/com/twilio/rest/api/v2010/account/message/Feedback.java index ae4eeef9df..9786f3fe32 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/Feedback.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/Feedback.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.message; @@ -10,35 +17,45 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Feedback extends Resource { - private static final long serialVersionUID = 93685573726475L; + + public static FeedbackCreator creator(final String pathMessageSid) { + return new FeedbackCreator(pathMessageSid); + } + + public static FeedbackCreator creator( + final String pathAccountSid, + final String pathMessageSid + ) { + return new FeedbackCreator(pathAccountSid, pathMessageSid); + } public enum Outcome { CONFIRMED("confirmed"), - UMCONFIRMED("umconfirmed"); + UNCONFIRMED("unconfirmed"); private final String value; @@ -46,15 +63,11 @@ private Outcome(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Outcome from a string. - * @param value string value - * @return generated Outcome - */ @JsonCreator public static Outcome forValue(final String value) { return Promoter.enumFromString(value, Outcome.values()); @@ -62,36 +75,16 @@ public static Outcome forValue(final String value) { } /** - * Create a FeedbackCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param pathMessageSid The message_sid - * @return FeedbackCreator capable of executing the create - */ - public static FeedbackCreator creator(final String pathAccountSid, - final String pathMessageSid) { - return new FeedbackCreator(pathAccountSid, pathMessageSid); - } - - /** - * Create a FeedbackCreator to execute create. - * - * @param pathMessageSid The message_sid - * @return FeedbackCreator capable of executing the create - */ - public static FeedbackCreator creator(final String pathMessageSid) { - return new FeedbackCreator(pathMessageSid); - } - - /** - * Converts a JSON String into a Feedback object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Feedback object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Feedback object represented by the provided JSON */ - public static Feedback fromJson(final String json, final ObjectMapper objectMapper) { + public static Feedback fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Feedback.class); @@ -105,12 +98,15 @@ public static Feedback fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a Feedback object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Feedback object represented by the provided JSON */ - public static Feedback fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Feedback fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Feedback.class); @@ -121,92 +117,57 @@ public static Feedback fromJson(final InputStream json, final ObjectMapper objec } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String messageSid; + + @Getter private final Feedback.Outcome outcome; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final String uri; @JsonCreator - private Feedback(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("message_sid") - final String messageSid, - @JsonProperty("outcome") - final Feedback.Outcome outcome, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("uri") - final String uri) { + private Feedback( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("message_sid") final String messageSid, + @JsonProperty("outcome") final Feedback.Outcome outcome, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.messageSid = messageSid; this.outcome = outcome; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); this.uri = uri; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The message_sid. - * - * @return The message_sid - */ - public final String getMessageSid() { - return this.messageSid; - } - - /** - * Returns The unconfirmed or confirmed. If ProvideFeedback=true in the initial - * HTTP POST, this value will default to unconfirmed. Make an HTTP POST to - * update this value to confirmed after the message arrives.. - * - * @return unconfirmed or confirmed. If ProvideFeedback=true in the initial - * HTTP POST, this value will default to unconfirmed. Make an HTTP POST - * to update this value to confirmed after the message arrives. - */ - public final Feedback.Outcome getOutcome() { - return this.outcome; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -218,34 +179,25 @@ public boolean equals(final Object o) { } Feedback other = (Feedback) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(messageSid, other.messageSid) && - Objects.equals(outcome, other.outcome) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(messageSid, other.messageSid) && + Objects.equals(outcome, other.outcome) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - messageSid, - outcome, - dateCreated, - dateUpdated, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("messageSid", messageSid) - .add("outcome", outcome) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + messageSid, + outcome, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/FeedbackCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/message/FeedbackCreator.java index 03b45f8663..7fa80b534b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/FeedbackCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/FeedbackCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.message; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,92 +27,115 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class FeedbackCreator extends Creator { + private String pathAccountSid; - private final String pathMessageSid; + private String pathMessageSid; private Feedback.Outcome outcome; - /** - * Construct a new FeedbackCreator. - * - * @param pathMessageSid The message_sid - */ public FeedbackCreator(final String pathMessageSid) { this.pathMessageSid = pathMessageSid; } - /** - * Construct a new FeedbackCreator. - * - * @param pathAccountSid The account_sid - * @param pathMessageSid The message_sid - */ - public FeedbackCreator(final String pathAccountSid, - final String pathMessageSid) { + public FeedbackCreator( + final String pathAccountSid, + final String pathMessageSid + ) { this.pathAccountSid = pathAccountSid; this.pathMessageSid = pathMessageSid; } - /** - * The outcome. - * - * @param outcome The outcome - * @return this - */ public FeedbackCreator setOutcome(final Feedback.Outcome outcome) { this.outcome = outcome; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Feedback - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Feedback create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Feedback.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages/" + this.pathMessageSid + "/Feedback.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Feedback creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Feedback creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Feedback.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Feedback create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Feedback.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Feedback content = Feedback.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (outcome != null) { - request.addPostParam("Outcome", outcome.toString()); + Serializer.toString( + request, + "Outcome", + outcome, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/Media.java b/src/main/java/com/twilio/rest/api/v2010/account/message/Media.java index f05b95e32a..01fd8e8011 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/Media.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/Media.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.message; @@ -11,112 +18,80 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Media extends Resource { - private static final long serialVersionUID = 138990472819672L; - - /** - * Create a MediaDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathMessageSid The message_sid - * @param pathSid Delete by unique media Sid - * @return MediaDeleter capable of executing the delete - */ - public static MediaDeleter deleter(final String pathAccountSid, - final String pathMessageSid, - final String pathSid) { - return new MediaDeleter(pathAccountSid, pathMessageSid, pathSid); - } - /** - * Create a MediaDeleter to execute delete. - * - * @param pathMessageSid The message_sid - * @param pathSid Delete by unique media Sid - * @return MediaDeleter capable of executing the delete - */ - public static MediaDeleter deleter(final String pathMessageSid, - final String pathSid) { + public static MediaDeleter deleter( + final String pathMessageSid, + final String pathSid + ) { return new MediaDeleter(pathMessageSid, pathSid); } - /** - * Create a MediaFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathMessageSid The message_sid - * @param pathSid Fetch by unique media Sid - * @return MediaFetcher capable of executing the fetch - */ - public static MediaFetcher fetcher(final String pathAccountSid, - final String pathMessageSid, - final String pathSid) { - return new MediaFetcher(pathAccountSid, pathMessageSid, pathSid); + public static MediaDeleter deleter( + final String pathAccountSid, + final String pathMessageSid, + final String pathSid + ) { + return new MediaDeleter(pathAccountSid, pathMessageSid, pathSid); } - /** - * Create a MediaFetcher to execute fetch. - * - * @param pathMessageSid The message_sid - * @param pathSid Fetch by unique media Sid - * @return MediaFetcher capable of executing the fetch - */ - public static MediaFetcher fetcher(final String pathMessageSid, - final String pathSid) { + public static MediaFetcher fetcher( + final String pathMessageSid, + final String pathSid + ) { return new MediaFetcher(pathMessageSid, pathSid); } - /** - * Create a MediaReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathMessageSid The message_sid - * @return MediaReader capable of executing the read - */ - public static MediaReader reader(final String pathAccountSid, - final String pathMessageSid) { - return new MediaReader(pathAccountSid, pathMessageSid); + public static MediaFetcher fetcher( + final String pathAccountSid, + final String pathMessageSid, + final String pathSid + ) { + return new MediaFetcher(pathAccountSid, pathMessageSid, pathSid); } - /** - * Create a MediaReader to execute read. - * - * @param pathMessageSid The message_sid - * @return MediaReader capable of executing the read - */ public static MediaReader reader(final String pathMessageSid) { return new MediaReader(pathMessageSid); } + public static MediaReader reader( + final String pathAccountSid, + final String pathMessageSid + ) { + return new MediaReader(pathAccountSid, pathMessageSid); + } + /** * Converts a JSON String into a Media object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Media object represented by the provided JSON */ - public static Media fromJson(final String json, final ObjectMapper objectMapper) { + public static Media fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Media.class); @@ -130,12 +105,15 @@ public static Media fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Media object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Media object represented by the provided JSON */ - public static Media fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Media fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Media.class); @@ -146,101 +124,62 @@ public static Media fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String contentType; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String parentSid; + + @Getter private final String sid; + + @Getter private final String uri; @JsonCreator - private Media(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("content_type") - final String contentType, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("parent_sid") - final String parentSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("uri") - final String uri) { + private Media( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("content_type") final String contentType, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("parent_sid") final String parentSid, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.contentType = contentType; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.parentSid = parentSid; this.sid = sid; this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The default mime-type of the media. - * - * @return The default mime-type of the media - */ - public final String getContentType() { - return this.contentType; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The unique id of the resource that created the media.. - * - * @return The unique id of the resource that created the media. - */ - public final String getParentSid() { - return this.parentSid; - } - - /** - * Returns The A string that uniquely identifies this media. - * - * @return A string that uniquely identifies this media - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -252,37 +191,27 @@ public boolean equals(final Object o) { } Media other = (Media) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(contentType, other.contentType) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(parentSid, other.parentSid) && - Objects.equals(sid, other.sid) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(contentType, other.contentType) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(parentSid, other.parentSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - contentType, - dateCreated, - dateUpdated, - parentSid, - sid, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("contentType", contentType) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("parentSid", parentSid) - .add("sid", sid) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + contentType, + dateCreated, + dateUpdated, + parentSid, + sid, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaDeleter.java index 2214f0c2df..b22199dccd 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.message; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,102 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MediaDeleter extends Deleter { + private String pathAccountSid; - private final String pathMessageSid; - private final String pathSid; + private String pathMessageSid; + private String pathSid; - /** - * Construct a new MediaDeleter. - * - * @param pathMessageSid The message_sid - * @param pathSid Delete by unique media Sid - */ - public MediaDeleter(final String pathMessageSid, - final String pathSid) { + public MediaDeleter(final String pathMessageSid, final String pathSid) { this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - /** - * Construct a new MediaDeleter. - * - * @param pathAccountSid The account_sid - * @param pathMessageSid The message_sid - * @param pathSid Delete by unique media Sid - */ - public MediaDeleter(final String pathAccountSid, - final String pathMessageSid, - final String pathSid) { + public MediaDeleter( + final String pathAccountSid, + final String pathMessageSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages/" + this.pathMessageSid + "/Media/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Media delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Media delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaFetcher.java index 58feece738..00d9678307 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.message; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,98 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MediaFetcher extends Fetcher { + private String pathAccountSid; - private final String pathMessageSid; - private final String pathSid; + private String pathMessageSid; + private String pathSid; - /** - * Construct a new MediaFetcher. - * - * @param pathMessageSid The message_sid - * @param pathSid Fetch by unique media Sid - */ - public MediaFetcher(final String pathMessageSid, - final String pathSid) { + public MediaFetcher(final String pathMessageSid, final String pathSid) { this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - /** - * Construct a new MediaFetcher. - * - * @param pathAccountSid The account_sid - * @param pathMessageSid The message_sid - * @param pathSid Fetch by unique media Sid - */ - public MediaFetcher(final String pathAccountSid, - final String pathMessageSid, - final String pathSid) { + public MediaFetcher( + final String pathAccountSid, + final String pathMessageSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathMessageSid = pathMessageSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Media - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Media fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages/" + this.pathMessageSid + "/Media/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Media fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Media fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Media fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Media.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Media content = Media.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaReader.java b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaReader.java index 9a24266b0e..9190b69d36 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/message/MediaReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/message/MediaReader.java @@ -1,226 +1,257 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.message; -import com.google.common.collect.Range; import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MediaReader extends Reader { + private String pathAccountSid; - private final String pathMessageSid; - private DateTime absoluteDateCreated; - private Range rangeDateCreated; - - /** - * Construct a new MediaReader. - * - * @param pathMessageSid The message_sid - */ + private String pathMessageSid; + private ZonedDateTime dateCreated; + private ZonedDateTime dateCreatedBefore; + private ZonedDateTime dateCreatedAfter; + private Long pageSize; + public MediaReader(final String pathMessageSid) { this.pathMessageSid = pathMessageSid; } - /** - * Construct a new MediaReader. - * - * @param pathAccountSid The account_sid - * @param pathMessageSid The message_sid - */ - public MediaReader(final String pathAccountSid, - final String pathMessageSid) { + public MediaReader( + final String pathAccountSid, + final String pathMessageSid + ) { this.pathAccountSid = pathAccountSid; this.pathMessageSid = pathMessageSid; } - /** - * Only show media created on the given date. Should be formatted as - * `YYYY-MM-DD`. You can also specify inequality, such as - * `DateCreated<=YYYY-MM-DD` for media generated at or before midnight on a - * date, and `DateCreated>=YYYY-MM-DD` for media generated at or after - * midnight on a date.. - * - * @param absoluteDateCreated Filter by date created - * @return this - */ - public MediaReader setDateCreated(final DateTime absoluteDateCreated) { - this.rangeDateCreated = null; - this.absoluteDateCreated = absoluteDateCreated; + public MediaReader setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; return this; } - /** - * Only show media created on the given date. Should be formatted as - * `YYYY-MM-DD`. You can also specify inequality, such as - * `DateCreated<=YYYY-MM-DD` for media generated at or before midnight on a - * date, and `DateCreated>=YYYY-MM-DD` for media generated at or after - * midnight on a date.. - * - * @param rangeDateCreated Filter by date created - * @return this - */ - public MediaReader setDateCreated(final Range rangeDateCreated) { - this.absoluteDateCreated = null; - this.rangeDateCreated = rangeDateCreated; + public MediaReader setDateCreatedBefore( + final ZonedDateTime dateCreatedBefore + ) { + this.dateCreatedBefore = dateCreatedBefore; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Media ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MediaReader setDateCreatedAfter( + final ZonedDateTime dateCreatedAfter + ) { + this.dateCreatedAfter = dateCreatedAfter; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Media ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public MediaReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "media_list", + response.getContent(), + Media.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}/Media.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Messages/" + this.pathMessageSid + "/Media.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Media ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "media_list", + response.getContent(), + Media.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Media read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "media_list", + response.getContent(), + Media.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Media Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Media read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "media_list", - response.getContent(), - Media.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { - if (absoluteDateCreated != null) { - request.addQueryParam("DateCreated", absoluteDateCreated.toString(Request.QUERY_STRING_DATE_TIME_FORMAT)); - } else if (rangeDateCreated != null) { - request.addQueryDateTimeRange("DateCreated", rangeDateCreated); + Serializer.toString( + request, + "DateCreated", + dateCreated, + dateCreatedBefore, + dateCreatedAfter + ); + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/queue/Member.java b/src/main/java/com/twilio/rest/api/v2010/account/queue/Member.java index f220a111ef..79ddcdf9a3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/queue/Member.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/queue/Member.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.queue; @@ -11,121 +18,88 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Member extends Resource { - private static final long serialVersionUID = 27782479642114L; - - /** - * Create a MemberFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathQueueSid The Queue in which to find the members - * @param pathCallSid The call_sid - * @return MemberFetcher capable of executing the fetch - */ - public static MemberFetcher fetcher(final String pathAccountSid, - final String pathQueueSid, - final String pathCallSid) { - return new MemberFetcher(pathAccountSid, pathQueueSid, pathCallSid); - } - /** - * Create a MemberFetcher to execute fetch. - * - * @param pathQueueSid The Queue in which to find the members - * @param pathCallSid The call_sid - * @return MemberFetcher capable of executing the fetch - */ - public static MemberFetcher fetcher(final String pathQueueSid, - final String pathCallSid) { + public static MemberFetcher fetcher( + final String pathQueueSid, + final String pathCallSid + ) { return new MemberFetcher(pathQueueSid, pathCallSid); } - /** - * Create a MemberUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathQueueSid The Queue in which to find the members - * @param pathCallSid The call_sid - * @param url The url - * @param method The method - * @return MemberUpdater capable of executing the update - */ - public static MemberUpdater updater(final String pathAccountSid, - final String pathQueueSid, - final String pathCallSid, - final URI url, - final HttpMethod method) { - return new MemberUpdater(pathAccountSid, pathQueueSid, pathCallSid, url, method); + public static MemberFetcher fetcher( + final String pathAccountSid, + final String pathQueueSid, + final String pathCallSid + ) { + return new MemberFetcher(pathAccountSid, pathQueueSid, pathCallSid); } - /** - * Create a MemberUpdater to execute update. - * - * @param pathQueueSid The Queue in which to find the members - * @param pathCallSid The call_sid - * @param url The url - * @param method The method - * @return MemberUpdater capable of executing the update - */ - public static MemberUpdater updater(final String pathQueueSid, - final String pathCallSid, - final URI url, - final HttpMethod method) { - return new MemberUpdater(pathQueueSid, pathCallSid, url, method); + public static MemberReader reader(final String pathQueueSid) { + return new MemberReader(pathQueueSid); } - /** - * Create a MemberReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathQueueSid The Queue in which to find members - * @return MemberReader capable of executing the read - */ - public static MemberReader reader(final String pathAccountSid, - final String pathQueueSid) { + public static MemberReader reader( + final String pathAccountSid, + final String pathQueueSid + ) { return new MemberReader(pathAccountSid, pathQueueSid); } - /** - * Create a MemberReader to execute read. - * - * @param pathQueueSid The Queue in which to find members - * @return MemberReader capable of executing the read - */ - public static MemberReader reader(final String pathQueueSid) { - return new MemberReader(pathQueueSid); + public static MemberUpdater updater( + final String pathQueueSid, + final String pathCallSid, + final URI url + ) { + return new MemberUpdater(pathQueueSid, pathCallSid, url); + } + + public static MemberUpdater updater( + final String pathAccountSid, + final String pathQueueSid, + final String pathCallSid, + final URI url + ) { + return new MemberUpdater( + pathAccountSid, + pathQueueSid, + pathCallSid, + url + ); } /** * Converts a JSON String into a Member object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -139,12 +113,15 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Member object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -155,75 +132,55 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String callSid; - private final DateTime dateEnqueued; + + @Getter + private final ZonedDateTime dateEnqueued; + + @Getter private final Integer position; + + @Getter + private final String queueSid; + + @Getter private final String uri; + + @Getter private final Integer waitTime; @JsonCreator - private Member(@JsonProperty("call_sid") - final String callSid, - @JsonProperty("date_enqueued") - final String dateEnqueued, - @JsonProperty("position") - final Integer position, - @JsonProperty("uri") - final String uri, - @JsonProperty("wait_time") - final Integer waitTime) { + private Member( + @JsonProperty("call_sid") final String callSid, + @JsonProperty("date_enqueued") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateEnqueued, + @JsonProperty("position") final Integer position, + @JsonProperty("queue_sid") final String queueSid, + @JsonProperty("uri") final String uri, + @JsonProperty("wait_time") final Integer waitTime + ) { this.callSid = callSid; - this.dateEnqueued = DateConverter.rfc2822DateTimeFromString(dateEnqueued); + this.dateEnqueued = dateEnqueued; this.position = position; + this.queueSid = queueSid; this.uri = uri; this.waitTime = waitTime; } - /** - * Returns The Unique string that identifies this resource. - * - * @return Unique string that identifies this resource - */ - public final String getCallSid() { - return this.callSid; - } - - /** - * Returns The The date the member was enqueued. - * - * @return The date the member was enqueued - */ - public final DateTime getDateEnqueued() { - return this.dateEnqueued; - } - - /** - * Returns The This member's current position in the queue.. - * - * @return This member's current position in the queue. - */ - public final Integer getPosition() { - return this.position; - } - - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The number of seconds the member has been in the queue.. - * - * @return The number of seconds the member has been in the queue. - */ - public final Integer getWaitTime() { - return this.waitTime; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -235,31 +192,25 @@ public boolean equals(final Object o) { } Member other = (Member) o; - - return Objects.equals(callSid, other.callSid) && - Objects.equals(dateEnqueued, other.dateEnqueued) && - Objects.equals(position, other.position) && - Objects.equals(uri, other.uri) && - Objects.equals(waitTime, other.waitTime); + return ( + Objects.equals(callSid, other.callSid) && + Objects.equals(dateEnqueued, other.dateEnqueued) && + Objects.equals(position, other.position) && + Objects.equals(queueSid, other.queueSid) && + Objects.equals(uri, other.uri) && + Objects.equals(waitTime, other.waitTime) + ); } @Override public int hashCode() { - return Objects.hash(callSid, - dateEnqueued, - position, - uri, - waitTime); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("callSid", callSid) - .add("dateEnqueued", dateEnqueued) - .add("position", position) - .add("uri", uri) - .add("waitTime", waitTime) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + callSid, + dateEnqueued, + position, + queueSid, + uri, + waitTime + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberFetcher.java index f57084e4a2..6f778029a4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.queue; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,95 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberFetcher extends Fetcher { + private String pathAccountSid; - private final String pathQueueSid; - private final String pathCallSid; + private String pathQueueSid; + private String pathCallSid; - /** - * Construct a new MemberFetcher. - * - * @param pathQueueSid The Queue in which to find the members - * @param pathCallSid The call_sid - */ - public MemberFetcher(final String pathQueueSid, - final String pathCallSid) { + public MemberFetcher(final String pathQueueSid, final String pathCallSid) { this.pathQueueSid = pathQueueSid; this.pathCallSid = pathCallSid; } - /** - * Construct a new MemberFetcher. - * - * @param pathAccountSid The account_sid - * @param pathQueueSid The Queue in which to find the members - * @param pathCallSid The call_sid - */ - public MemberFetcher(final String pathAccountSid, - final String pathQueueSid, - final String pathCallSid) { + public MemberFetcher( + final String pathAccountSid, + final String pathQueueSid, + final String pathCallSid + ) { this.pathAccountSid = pathAccountSid; this.pathQueueSid = pathQueueSid; this.pathCallSid = pathCallSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace("{" + "QueueSid" + "}", this.pathQueueSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Queues/" + this.pathQueueSid + "/Members/" + this.pathCallSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberReader.java b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberReader.java index c70725c9cb..9336ddf59c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.queue; @@ -10,174 +17,207 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberReader extends Reader { + private String pathAccountSid; - private final String pathQueueSid; + private String pathQueueSid; + private Long pageSize; - /** - * Construct a new MemberReader. - * - * @param pathQueueSid The Queue in which to find members - */ public MemberReader(final String pathQueueSid) { this.pathQueueSid = pathQueueSid; } - /** - * Construct a new MemberReader. - * - * @param pathAccountSid The account_sid - * @param pathQueueSid The Queue in which to find members - */ - public MemberReader(final String pathAccountSid, - final String pathQueueSid) { + public MemberReader( + final String pathAccountSid, + final String pathQueueSid + ) { this.pathAccountSid = pathAccountSid; this.pathQueueSid = pathQueueSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MemberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "queue_members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace("{" + "QueueSid" + "}", this.pathQueueSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Queues/" + this.pathQueueSid + "/Members.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "queue_members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "queue_members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Member Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "queue_members", - response.getContent(), - Member.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberUpdater.java index 7f6bdea323..6acab6489f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/queue/MemberUpdater.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.queue; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,107 +28,136 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class MemberUpdater extends Updater { + private String pathAccountSid; - private final String pathQueueSid; - private final String pathCallSid; - private final URI url; - private final HttpMethod method; - - /** - * Construct a new MemberUpdater. - * - * @param pathQueueSid The Queue in which to find the members - * @param pathCallSid The call_sid - * @param url The url - * @param method The method - */ - public MemberUpdater(final String pathQueueSid, - final String pathCallSid, - final URI url, - final HttpMethod method) { + private String pathQueueSid; + private String pathCallSid; + private URI url; + private HttpMethod method; + + public MemberUpdater( + final String pathQueueSid, + final String pathCallSid, + final URI url + ) { this.pathQueueSid = pathQueueSid; this.pathCallSid = pathCallSid; this.url = url; - this.method = method; } - /** - * Construct a new MemberUpdater. - * - * @param pathAccountSid The account_sid - * @param pathQueueSid The Queue in which to find the members - * @param pathCallSid The call_sid - * @param url The url - * @param method The method - */ - public MemberUpdater(final String pathAccountSid, - final String pathQueueSid, - final String pathCallSid, - final URI url, - final HttpMethod method) { + public MemberUpdater( + final String pathAccountSid, + final String pathQueueSid, + final String pathCallSid, + final URI url + ) { this.pathAccountSid = pathAccountSid; this.pathQueueSid = pathQueueSid; this.pathCallSid = pathCallSid; this.url = url; + } + + public MemberUpdater setUrl(final URI url) { + this.url = url; + return this; + } + + public MemberUpdater setUrl(final String url) { + return setUrl(Promoter.uriFromString(url)); + } + + public MemberUpdater setMethod(final HttpMethod method) { this.method = method; + return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Queues/{QueueSid}/Members/{CallSid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace("{" + "QueueSid" + "}", this.pathQueueSid.toString()); + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Queues/" + this.pathQueueSid + "/Members/" + this.pathCallSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member update(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (url != null) { - request.addPostParam("Url", url.toString()); + Serializer.toString(request, "Url", url, ParameterType.URLENCODED); } if (method != null) { - request.addPostParam("Method", method.toString()); + Serializer.toString( + request, + "Method", + method, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResult.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResult.java index 119f9af2a9..43a6cda56c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResult.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResult.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording; @@ -10,31 +17,80 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AddOnResult extends Resource { - private static final long serialVersionUID = 195304696893034L; + + public static AddOnResultDeleter deleter( + final String pathReferenceSid, + final String pathSid + ) { + return new AddOnResultDeleter(pathReferenceSid, pathSid); + } + + public static AddOnResultDeleter deleter( + final String pathAccountSid, + final String pathReferenceSid, + final String pathSid + ) { + return new AddOnResultDeleter( + pathAccountSid, + pathReferenceSid, + pathSid + ); + } + + public static AddOnResultFetcher fetcher( + final String pathReferenceSid, + final String pathSid + ) { + return new AddOnResultFetcher(pathReferenceSid, pathSid); + } + + public static AddOnResultFetcher fetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathSid + ) { + return new AddOnResultFetcher( + pathAccountSid, + pathReferenceSid, + pathSid + ); + } + + public static AddOnResultReader reader(final String pathReferenceSid) { + return new AddOnResultReader(pathReferenceSid); + } + + public static AddOnResultReader reader( + final String pathAccountSid, + final String pathReferenceSid + ) { + return new AddOnResultReader(pathAccountSid, pathReferenceSid); + } public enum Status { CANCELED("canceled"), @@ -52,15 +108,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -68,88 +120,16 @@ public static Status forValue(final String value) { } /** - * Create a AddOnResultFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathSid Fetch by unique result Sid - * @return AddOnResultFetcher capable of executing the fetch - */ - public static AddOnResultFetcher fetcher(final String pathAccountSid, - final String pathReferenceSid, - final String pathSid) { - return new AddOnResultFetcher(pathAccountSid, pathReferenceSid, pathSid); - } - - /** - * Create a AddOnResultFetcher to execute fetch. - * - * @param pathReferenceSid The reference_sid - * @param pathSid Fetch by unique result Sid - * @return AddOnResultFetcher capable of executing the fetch - */ - public static AddOnResultFetcher fetcher(final String pathReferenceSid, - final String pathSid) { - return new AddOnResultFetcher(pathReferenceSid, pathSid); - } - - /** - * Create a AddOnResultReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @return AddOnResultReader capable of executing the read - */ - public static AddOnResultReader reader(final String pathAccountSid, - final String pathReferenceSid) { - return new AddOnResultReader(pathAccountSid, pathReferenceSid); - } - - /** - * Create a AddOnResultReader to execute read. - * - * @param pathReferenceSid The reference_sid - * @return AddOnResultReader capable of executing the read - */ - public static AddOnResultReader reader(final String pathReferenceSid) { - return new AddOnResultReader(pathReferenceSid); - } - - /** - * Create a AddOnResultDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathSid Delete by unique result Sid - * @return AddOnResultDeleter capable of executing the delete - */ - public static AddOnResultDeleter deleter(final String pathAccountSid, - final String pathReferenceSid, - final String pathSid) { - return new AddOnResultDeleter(pathAccountSid, pathReferenceSid, pathSid); - } - - /** - * Create a AddOnResultDeleter to execute delete. - * - * @param pathReferenceSid The reference_sid - * @param pathSid Delete by unique result Sid - * @return AddOnResultDeleter capable of executing the delete - */ - public static AddOnResultDeleter deleter(final String pathReferenceSid, - final String pathSid) { - return new AddOnResultDeleter(pathReferenceSid, pathSid); - } - - /** - * Converts a JSON String into a AddOnResult object using the provided - * ObjectMapper. - * + * Converts a JSON String into a AddOnResult object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AddOnResult object represented by the provided JSON */ - public static AddOnResult fromJson(final String json, final ObjectMapper objectMapper) { + public static AddOnResult fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AddOnResult.class); @@ -163,12 +143,15 @@ public static AddOnResult fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a AddOnResult object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AddOnResult object represented by the provided JSON */ - public static AddOnResult fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AddOnResult fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AddOnResult.class); @@ -179,138 +162,82 @@ public static AddOnResult fromJson(final InputStream json, final ObjectMapper ob } } - private final String sid; - private final String accountSid; - private final AddOnResult.Status status; - private final String addOnSid; - private final String addOnConfigurationSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final DateTime dateCompleted; - private final String referenceSid; - private final Map subresourceUris; - - @JsonCreator - private AddOnResult(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("status") - final AddOnResult.Status status, - @JsonProperty("add_on_sid") - final String addOnSid, - @JsonProperty("add_on_configuration_sid") - final String addOnConfigurationSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("date_completed") - final String dateCompleted, - @JsonProperty("reference_sid") - final String referenceSid, - @JsonProperty("subresource_uris") - final Map subresourceUris) { - this.sid = sid; - this.accountSid = accountSid; - this.status = status; - this.addOnSid = addOnSid; - this.addOnConfigurationSid = addOnConfigurationSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.dateCompleted = DateConverter.rfc2822DateTimeFromString(dateCompleted); - this.referenceSid = referenceSid; - this.subresourceUris = subresourceUris; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A string that uniquely identifies this result. - * - * @return A string that uniquely identifies this result - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String addOnConfigurationSid; - /** - * Returns The The status of this result.. - * - * @return The status of this result. - */ - public final AddOnResult.Status getStatus() { - return this.status; - } + @Getter + private final String addOnSid; - /** - * Returns The A string that uniquely identifies the Add-on.. - * - * @return A string that uniquely identifies the Add-on. - */ - public final String getAddOnSid() { - return this.addOnSid; - } + @Getter + private final ZonedDateTime dateCompleted; - /** - * Returns The A string that uniquely identifies the Add-on configuration.. - * - * @return A string that uniquely identifies the Add-on configuration. - */ - public final String getAddOnConfigurationSid() { - return this.addOnConfigurationSid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String referenceSid; - /** - * Returns The The date this result was completed.. - * - * @return The date this result was completed. - */ - public final DateTime getDateCompleted() { - return this.dateCompleted; - } + @Getter + private final String sid; - /** - * Returns The A string that uniquely identifies the recording.. - * - * @return A string that uniquely identifies the recording. - */ - public final String getReferenceSid() { - return this.referenceSid; - } + @Getter + private final AddOnResult.Status status; - /** - * Returns The A dictionary of URIs for related resources. - * - * @return A dictionary of URIs for related resources - */ - public final Map getSubresourceUris() { - return this.subresourceUris; + @Getter + private final Map subresourceUris; + + @JsonCreator + private AddOnResult( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "add_on_configuration_sid" + ) final String addOnConfigurationSid, + @JsonProperty("add_on_sid") final String addOnSid, + @JsonProperty("date_completed") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCompleted, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("reference_sid") final String referenceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final AddOnResult.Status status, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris + ) { + this.accountSid = accountSid; + this.addOnConfigurationSid = addOnConfigurationSid; + this.addOnSid = addOnSid; + this.dateCompleted = dateCompleted; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.referenceSid = referenceSid; + this.sid = sid; + this.status = status; + this.subresourceUris = subresourceUris; } @Override @@ -324,46 +251,36 @@ public boolean equals(final Object o) { } AddOnResult other = (AddOnResult) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(status, other.status) && - Objects.equals(addOnSid, other.addOnSid) && - Objects.equals(addOnConfigurationSid, other.addOnConfigurationSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(dateCompleted, other.dateCompleted) && - Objects.equals(referenceSid, other.referenceSid) && - Objects.equals(subresourceUris, other.subresourceUris); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + addOnConfigurationSid, + other.addOnConfigurationSid + ) && + Objects.equals(addOnSid, other.addOnSid) && + Objects.equals(dateCompleted, other.dateCompleted) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(referenceSid, other.referenceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(subresourceUris, other.subresourceUris) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - status, - addOnSid, - addOnConfigurationSid, - dateCreated, - dateUpdated, - dateCompleted, - referenceSid, - subresourceUris); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("status", status) - .add("addOnSid", addOnSid) - .add("addOnConfigurationSid", addOnConfigurationSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("dateCompleted", dateCompleted) - .add("referenceSid", referenceSid) - .add("subresourceUris", subresourceUris) - .toString(); + return Objects.hash( + accountSid, + addOnConfigurationSid, + addOnSid, + dateCompleted, + dateCreated, + dateUpdated, + referenceSid, + sid, + status, + subresourceUris + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultDeleter.java index 51f0670278..876097b3b6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,105 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class AddOnResultDeleter extends Deleter { + private String pathAccountSid; - private final String pathReferenceSid; - private final String pathSid; + private String pathReferenceSid; + private String pathSid; - /** - * Construct a new AddOnResultDeleter. - * - * @param pathReferenceSid The reference_sid - * @param pathSid Delete by unique result Sid - */ - public AddOnResultDeleter(final String pathReferenceSid, - final String pathSid) { + public AddOnResultDeleter( + final String pathReferenceSid, + final String pathSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathSid = pathSid; } - /** - * Construct a new AddOnResultDeleter. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathSid Delete by unique result Sid - */ - public AddOnResultDeleter(final String pathAccountSid, - final String pathReferenceSid, - final String pathSid) { + public AddOnResultDeleter( + final String pathAccountSid, + final String pathReferenceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathReferenceSid + "/AddOnResults/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddOnResult delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AddOnResult delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultFetcher.java index 929edae604..48db653710 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,104 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AddOnResultFetcher extends Fetcher { + private String pathAccountSid; - private final String pathReferenceSid; - private final String pathSid; + private String pathReferenceSid; + private String pathSid; - /** - * Construct a new AddOnResultFetcher. - * - * @param pathReferenceSid The reference_sid - * @param pathSid Fetch by unique result Sid - */ - public AddOnResultFetcher(final String pathReferenceSid, - final String pathSid) { + public AddOnResultFetcher( + final String pathReferenceSid, + final String pathSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathSid = pathSid; } - /** - * Construct a new AddOnResultFetcher. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathSid Fetch by unique result Sid - */ - public AddOnResultFetcher(final String pathAccountSid, - final String pathReferenceSid, - final String pathSid) { + public AddOnResultFetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AddOnResult - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AddOnResult fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathReferenceSid + "/AddOnResults/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AddOnResult fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AddOnResult fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public AddOnResult fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AddOnResult.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return AddOnResult.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AddOnResult content = AddOnResult.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultReader.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultReader.java index 6c0ab19b5e..42af5c0b77 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/AddOnResultReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording; @@ -10,174 +17,214 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AddOnResultReader extends Reader { + private String pathAccountSid; - private final String pathReferenceSid; + private String pathReferenceSid; + private Long pageSize; - /** - * Construct a new AddOnResultReader. - * - * @param pathReferenceSid The reference_sid - */ public AddOnResultReader(final String pathReferenceSid) { this.pathReferenceSid = pathReferenceSid; } - /** - * Construct a new AddOnResultReader. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - */ - public AddOnResultReader(final String pathAccountSid, - final String pathReferenceSid) { + public AddOnResultReader( + final String pathAccountSid, + final String pathReferenceSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AddOnResult ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AddOnResultReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AddOnResult ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "add_on_results", + response.getContent(), + AddOnResult.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathReferenceSid + "/AddOnResults.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AddOnResult ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "add_on_results", + response.getContent(), + AddOnResult.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AddOnResult read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "add_on_results", + response.getContent(), + AddOnResult.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AddOnResult Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AddOnResult read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "add_on_results", - response.getContent(), - AddOnResult.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/Transcription.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/Transcription.java index 95bb719bee..20bcae2f90 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/Transcription.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/Transcription.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording; @@ -10,34 +17,81 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.ZonedDateTime; import java.util.Currency; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Transcription extends Resource { - private static final long serialVersionUID = 3308072321352L; + + public static TranscriptionDeleter deleter( + final String pathRecordingSid, + final String pathSid + ) { + return new TranscriptionDeleter(pathRecordingSid, pathSid); + } + + public static TranscriptionDeleter deleter( + final String pathAccountSid, + final String pathRecordingSid, + final String pathSid + ) { + return new TranscriptionDeleter( + pathAccountSid, + pathRecordingSid, + pathSid + ); + } + + public static TranscriptionFetcher fetcher( + final String pathRecordingSid, + final String pathSid + ) { + return new TranscriptionFetcher(pathRecordingSid, pathSid); + } + + public static TranscriptionFetcher fetcher( + final String pathAccountSid, + final String pathRecordingSid, + final String pathSid + ) { + return new TranscriptionFetcher( + pathAccountSid, + pathRecordingSid, + pathSid + ); + } + + public static TranscriptionReader reader(final String pathRecordingSid) { + return new TranscriptionReader(pathRecordingSid); + } + + public static TranscriptionReader reader( + final String pathAccountSid, + final String pathRecordingSid + ) { + return new TranscriptionReader(pathAccountSid, pathRecordingSid); + } public enum Status { IN_PROGRESS("in-progress"), @@ -50,15 +104,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -66,88 +116,16 @@ public static Status forValue(final String value) { } /** - * Create a TranscriptionFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathRecordingSid The recording_sid - * @param pathSid The sid - * @return TranscriptionFetcher capable of executing the fetch - */ - public static TranscriptionFetcher fetcher(final String pathAccountSid, - final String pathRecordingSid, - final String pathSid) { - return new TranscriptionFetcher(pathAccountSid, pathRecordingSid, pathSid); - } - - /** - * Create a TranscriptionFetcher to execute fetch. - * - * @param pathRecordingSid The recording_sid - * @param pathSid The sid - * @return TranscriptionFetcher capable of executing the fetch - */ - public static TranscriptionFetcher fetcher(final String pathRecordingSid, - final String pathSid) { - return new TranscriptionFetcher(pathRecordingSid, pathSid); - } - - /** - * Create a TranscriptionDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathRecordingSid The recording_sid - * @param pathSid The sid - * @return TranscriptionDeleter capable of executing the delete - */ - public static TranscriptionDeleter deleter(final String pathAccountSid, - final String pathRecordingSid, - final String pathSid) { - return new TranscriptionDeleter(pathAccountSid, pathRecordingSid, pathSid); - } - - /** - * Create a TranscriptionDeleter to execute delete. - * - * @param pathRecordingSid The recording_sid - * @param pathSid The sid - * @return TranscriptionDeleter capable of executing the delete - */ - public static TranscriptionDeleter deleter(final String pathRecordingSid, - final String pathSid) { - return new TranscriptionDeleter(pathRecordingSid, pathSid); - } - - /** - * Create a TranscriptionReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathRecordingSid The recording_sid - * @return TranscriptionReader capable of executing the read - */ - public static TranscriptionReader reader(final String pathAccountSid, - final String pathRecordingSid) { - return new TranscriptionReader(pathAccountSid, pathRecordingSid); - } - - /** - * Create a TranscriptionReader to execute read. - * - * @param pathRecordingSid The recording_sid - * @return TranscriptionReader capable of executing the read - */ - public static TranscriptionReader reader(final String pathRecordingSid) { - return new TranscriptionReader(pathRecordingSid); - } - - /** - * Converts a JSON String into a Transcription object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Transcription object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Transcription object represented by the provided JSON */ - public static Transcription fromJson(final String json, final ObjectMapper objectMapper) { + public static Transcription fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcription.class); @@ -161,12 +139,15 @@ public static Transcription fromJson(final String json, final ObjectMapper objec /** * Converts a JSON InputStream into a Transcription object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Transcription object represented by the provided JSON */ - public static Transcription fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Transcription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Transcription.class); @@ -177,52 +158,83 @@ public static Transcription fromJson(final InputStream json, final ObjectMapper } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String duration; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final String recordingSid; + + @Getter private final String sid; + + @Getter private final Transcription.Status status; + + @Getter private final String transcriptionText; + + @Getter private final String type; + + @Getter private final String uri; @JsonCreator - private Transcription(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("duration") - final String duration, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("recording_sid") - final String recordingSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("status") - final Transcription.Status status, - @JsonProperty("transcription_text") - final String transcriptionText, - @JsonProperty("type") - final String type, - @JsonProperty("uri") - final String uri) { + private Transcription( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("duration") final String duration, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("recording_sid") final String recordingSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Transcription.Status status, + @JsonProperty("transcription_text") final String transcriptionText, + @JsonProperty("type") final String type, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.duration = duration; this.price = price; this.priceUnit = priceUnit; @@ -234,123 +246,6 @@ private Transcription(@JsonProperty("account_sid") this.uri = uri; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The duration. - * - * @return The duration - */ - public final String getDuration() { - return this.duration; - } - - /** - * Returns The The price. - * - * @return The price - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The price_unit. - * - * @return The price_unit - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The recording_sid. - * - * @return The recording_sid - */ - public final String getRecordingSid() { - return this.recordingSid; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The status. - * - * @return The status - */ - public final Transcription.Status getStatus() { - return this.status; - } - - /** - * Returns The The transcription_text. - * - * @return The transcription_text - */ - public final String getTranscriptionText() { - return this.transcriptionText; - } - - /** - * Returns The The type. - * - * @return The type - */ - public final String getType() { - return this.type; - } - - /** - * Returns The The uri. - * - * @return The uri - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -362,55 +257,39 @@ public boolean equals(final Object o) { } Transcription other = (Transcription) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(duration, other.duration) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(recordingSid, other.recordingSid) && - Objects.equals(sid, other.sid) && - Objects.equals(status, other.status) && - Objects.equals(transcriptionText, other.transcriptionText) && - Objects.equals(type, other.type) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(recordingSid, other.recordingSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(transcriptionText, other.transcriptionText) && + Objects.equals(type, other.type) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - dateCreated, - dateUpdated, - duration, - price, - priceUnit, - recordingSid, - sid, - status, - transcriptionText, - type, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("duration", duration) - .add("price", price) - .add("priceUnit", priceUnit) - .add("recordingSid", recordingSid) - .add("sid", sid) - .add("status", status) - .add("transcriptionText", transcriptionText) - .add("type", type) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + apiVersion, + dateCreated, + dateUpdated, + duration, + price, + priceUnit, + recordingSid, + sid, + status, + transcriptionText, + type, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionDeleter.java index e90faee614..42a91aee3a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,105 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class TranscriptionDeleter extends Deleter { + private String pathAccountSid; - private final String pathRecordingSid; - private final String pathSid; + private String pathRecordingSid; + private String pathSid; - /** - * Construct a new TranscriptionDeleter. - * - * @param pathRecordingSid The recording_sid - * @param pathSid The sid - */ - public TranscriptionDeleter(final String pathRecordingSid, - final String pathSid) { + public TranscriptionDeleter( + final String pathRecordingSid, + final String pathSid + ) { this.pathRecordingSid = pathRecordingSid; this.pathSid = pathSid; } - /** - * Construct a new TranscriptionDeleter. - * - * @param pathAccountSid The account_sid - * @param pathRecordingSid The recording_sid - * @param pathSid The sid - */ - public TranscriptionDeleter(final String pathAccountSid, - final String pathRecordingSid, - final String pathSid) { + public TranscriptionDeleter( + final String pathAccountSid, + final String pathRecordingSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathRecordingSid = pathRecordingSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "RecordingSid" + "}", + this.pathRecordingSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathRecordingSid + "/Transcriptions/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Transcription delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionFetcher.java index 874b4e022f..9c14c300d7 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,104 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TranscriptionFetcher extends Fetcher { + private String pathAccountSid; - private final String pathRecordingSid; - private final String pathSid; + private String pathRecordingSid; + private String pathSid; - /** - * Construct a new TranscriptionFetcher. - * - * @param pathRecordingSid The recording_sid - * @param pathSid The sid - */ - public TranscriptionFetcher(final String pathRecordingSid, - final String pathSid) { + public TranscriptionFetcher( + final String pathRecordingSid, + final String pathSid + ) { this.pathRecordingSid = pathRecordingSid; this.pathSid = pathSid; } - /** - * Construct a new TranscriptionFetcher. - * - * @param pathAccountSid The account_sid - * @param pathRecordingSid The recording_sid - * @param pathSid The sid - */ - public TranscriptionFetcher(final String pathAccountSid, - final String pathRecordingSid, - final String pathSid) { + public TranscriptionFetcher( + final String pathAccountSid, + final String pathRecordingSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathRecordingSid = pathRecordingSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Transcription - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Transcription fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "RecordingSid" + "}", + this.pathRecordingSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathRecordingSid + "/Transcriptions/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Transcription fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Transcription fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Transcription fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Transcription.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Transcription content = Transcription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionReader.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionReader.java index df8bf610b6..99917650a4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/TranscriptionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording; @@ -10,174 +17,214 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TranscriptionReader extends Reader { + private String pathAccountSid; - private final String pathRecordingSid; + private String pathRecordingSid; + private Long pageSize; - /** - * Construct a new TranscriptionReader. - * - * @param pathRecordingSid The recording_sid - */ public TranscriptionReader(final String pathRecordingSid) { this.pathRecordingSid = pathRecordingSid; } - /** - * Construct a new TranscriptionReader. - * - * @param pathAccountSid The account_sid - * @param pathRecordingSid The recording_sid - */ - public TranscriptionReader(final String pathAccountSid, - final String pathRecordingSid) { + public TranscriptionReader( + final String pathAccountSid, + final String pathRecordingSid + ) { this.pathAccountSid = pathAccountSid; this.pathRecordingSid = pathRecordingSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Transcription ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TranscriptionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Transcription ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "transcriptions", + response.getContent(), + Transcription.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{RecordingSid}/Transcriptions.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "RecordingSid" + "}", + this.pathRecordingSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathRecordingSid + "/Transcriptions.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Transcription ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "transcriptions", + response.getContent(), + Transcription.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Transcription read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "transcriptions", + response.getContent(), + Transcription.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Transcription Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Transcription read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "transcriptions", - response.getContent(), - Transcription.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/Payload.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/Payload.java index 070e2c58d3..866ab1a894 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/Payload.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/Payload.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording.addonresult; @@ -11,124 +18,111 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Payload extends Resource { - private static final long serialVersionUID = 217671696000636L; - /** - * Create a PayloadFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @param pathSid Fetch by unique payload Sid - * @return PayloadFetcher capable of executing the fetch - */ - public static PayloadFetcher fetcher(final String pathAccountSid, - final String pathReferenceSid, - final String pathAddOnResultSid, - final String pathSid) { - return new PayloadFetcher(pathAccountSid, pathReferenceSid, pathAddOnResultSid, pathSid); + public static PayloadDeleter deleter( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { + return new PayloadDeleter( + pathReferenceSid, + pathAddOnResultSid, + pathSid + ); } - /** - * Create a PayloadFetcher to execute fetch. - * - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @param pathSid Fetch by unique payload Sid - * @return PayloadFetcher capable of executing the fetch - */ - public static PayloadFetcher fetcher(final String pathReferenceSid, - final String pathAddOnResultSid, - final String pathSid) { - return new PayloadFetcher(pathReferenceSid, pathAddOnResultSid, pathSid); + public static PayloadDeleter deleter( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { + return new PayloadDeleter( + pathAccountSid, + pathReferenceSid, + pathAddOnResultSid, + pathSid + ); } - /** - * Create a PayloadReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @return PayloadReader capable of executing the read - */ - public static PayloadReader reader(final String pathAccountSid, - final String pathReferenceSid, - final String pathAddOnResultSid) { - return new PayloadReader(pathAccountSid, pathReferenceSid, pathAddOnResultSid); + public static PayloadFetcher fetcher( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { + return new PayloadFetcher( + pathReferenceSid, + pathAddOnResultSid, + pathSid + ); } - /** - * Create a PayloadReader to execute read. - * - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @return PayloadReader capable of executing the read - */ - public static PayloadReader reader(final String pathReferenceSid, - final String pathAddOnResultSid) { - return new PayloadReader(pathReferenceSid, pathAddOnResultSid); + public static PayloadFetcher fetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { + return new PayloadFetcher( + pathAccountSid, + pathReferenceSid, + pathAddOnResultSid, + pathSid + ); } - /** - * Create a PayloadDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @param pathSid Delete by unique payload Sid - * @return PayloadDeleter capable of executing the delete - */ - public static PayloadDeleter deleter(final String pathAccountSid, - final String pathReferenceSid, - final String pathAddOnResultSid, - final String pathSid) { - return new PayloadDeleter(pathAccountSid, pathReferenceSid, pathAddOnResultSid, pathSid); + public static PayloadReader reader( + final String pathReferenceSid, + final String pathAddOnResultSid + ) { + return new PayloadReader(pathReferenceSid, pathAddOnResultSid); } - /** - * Create a PayloadDeleter to execute delete. - * - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @param pathSid Delete by unique payload Sid - * @return PayloadDeleter capable of executing the delete - */ - public static PayloadDeleter deleter(final String pathReferenceSid, - final String pathAddOnResultSid, - final String pathSid) { - return new PayloadDeleter(pathReferenceSid, pathAddOnResultSid, pathSid); + public static PayloadReader reader( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid + ) { + return new PayloadReader( + pathAccountSid, + pathReferenceSid, + pathAddOnResultSid + ); } /** * Converts a JSON String into a Payload object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Payload object represented by the provided JSON */ - public static Payload fromJson(final String json, final ObjectMapper objectMapper) { + public static Payload fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Payload.class); @@ -142,12 +136,15 @@ public static Payload fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Payload object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Payload object represented by the provided JSON */ - public static Payload fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Payload fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Payload.class); @@ -158,151 +155,85 @@ public static Payload fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String addOnResultSid; - private final String accountSid; - private final String label; - private final String addOnSid; - private final String addOnConfigurationSid; - private final String contentType; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String referenceSid; - private final Map subresourceUris; - - @JsonCreator - private Payload(@JsonProperty("sid") - final String sid, - @JsonProperty("add_on_result_sid") - final String addOnResultSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("label") - final String label, - @JsonProperty("add_on_sid") - final String addOnSid, - @JsonProperty("add_on_configuration_sid") - final String addOnConfigurationSid, - @JsonProperty("content_type") - final String contentType, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("reference_sid") - final String referenceSid, - @JsonProperty("subresource_uris") - final Map subresourceUris) { - this.sid = sid; - this.addOnResultSid = addOnResultSid; - this.accountSid = accountSid; - this.label = label; - this.addOnSid = addOnSid; - this.addOnConfigurationSid = addOnConfigurationSid; - this.contentType = contentType; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.referenceSid = referenceSid; - this.subresourceUris = subresourceUris; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A string that uniquely identifies this payload. - * - * @return A string that uniquely identifies this payload - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The A string that uniquely identifies the result. - * - * @return A string that uniquely identifies the result - */ - public final String getAddOnResultSid() { - return this.addOnResultSid; - } + @Getter + private final String addOnConfigurationSid; - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String addOnResultSid; - /** - * Returns The A string that describes the payload.. - * - * @return A string that describes the payload. - */ - public final String getLabel() { - return this.label; - } + @Getter + private final String addOnSid; - /** - * Returns The A string that uniquely identifies the Add-on.. - * - * @return A string that uniquely identifies the Add-on. - */ - public final String getAddOnSid() { - return this.addOnSid; - } + @Getter + private final String contentType; - /** - * Returns The A string that uniquely identifies the Add-on configuration.. - * - * @return A string that uniquely identifies the Add-on configuration. - */ - public final String getAddOnConfigurationSid() { - return this.addOnConfigurationSid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The MIME type of the payload.. - * - * @return The MIME type of the payload. - */ - public final String getContentType() { - return this.contentType; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String label; - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String referenceSid; - /** - * Returns The A string that uniquely identifies the recording.. - * - * @return A string that uniquely identifies the recording. - */ - public final String getReferenceSid() { - return this.referenceSid; - } + @Getter + private final String sid; - /** - * Returns The A dictionary of URIs for related resources. - * - * @return A dictionary of URIs for related resources - */ - public final Map getSubresourceUris() { - return this.subresourceUris; + @Getter + private final Map subresourceUris; + + @JsonCreator + private Payload( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "add_on_configuration_sid" + ) final String addOnConfigurationSid, + @JsonProperty("add_on_result_sid") final String addOnResultSid, + @JsonProperty("add_on_sid") final String addOnSid, + @JsonProperty("content_type") final String contentType, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("label") final String label, + @JsonProperty("reference_sid") final String referenceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris + ) { + this.accountSid = accountSid; + this.addOnConfigurationSid = addOnConfigurationSid; + this.addOnResultSid = addOnResultSid; + this.addOnSid = addOnSid; + this.contentType = contentType; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.label = label; + this.referenceSid = referenceSid; + this.sid = sid; + this.subresourceUris = subresourceUris; } @Override @@ -316,49 +247,38 @@ public boolean equals(final Object o) { } Payload other = (Payload) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(addOnResultSid, other.addOnResultSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(label, other.label) && - Objects.equals(addOnSid, other.addOnSid) && - Objects.equals(addOnConfigurationSid, other.addOnConfigurationSid) && - Objects.equals(contentType, other.contentType) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(referenceSid, other.referenceSid) && - Objects.equals(subresourceUris, other.subresourceUris); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + addOnConfigurationSid, + other.addOnConfigurationSid + ) && + Objects.equals(addOnResultSid, other.addOnResultSid) && + Objects.equals(addOnSid, other.addOnSid) && + Objects.equals(contentType, other.contentType) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(label, other.label) && + Objects.equals(referenceSid, other.referenceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(subresourceUris, other.subresourceUris) + ); } @Override public int hashCode() { - return Objects.hash(sid, - addOnResultSid, - accountSid, - label, - addOnSid, - addOnConfigurationSid, - contentType, - dateCreated, - dateUpdated, - referenceSid, - subresourceUris); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("addOnResultSid", addOnResultSid) - .add("accountSid", accountSid) - .add("label", label) - .add("addOnSid", addOnSid) - .add("addOnConfigurationSid", addOnConfigurationSid) - .add("contentType", contentType) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("referenceSid", referenceSid) - .add("subresourceUris", subresourceUris) - .toString(); + return Objects.hash( + accountSid, + addOnConfigurationSid, + addOnResultSid, + addOnSid, + contentType, + dateCreated, + dateUpdated, + label, + referenceSid, + sid, + subresourceUris + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadDeleter.java index a70df37d7f..d017658783 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording.addonresult; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,81 +24,115 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class PayloadDeleter extends Deleter { + private String pathAccountSid; - private final String pathReferenceSid; - private final String pathAddOnResultSid; - private final String pathSid; + private String pathReferenceSid; + private String pathAddOnResultSid; + private String pathSid; - /** - * Construct a new PayloadDeleter. - * - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @param pathSid Delete by unique payload Sid - */ - public PayloadDeleter(final String pathReferenceSid, - final String pathAddOnResultSid, - final String pathSid) { + public PayloadDeleter( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; this.pathSid = pathSid; } - /** - * Construct a new PayloadDeleter. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @param pathSid Delete by unique payload Sid - */ - public PayloadDeleter(final String pathAccountSid, - final String pathReferenceSid, - final String pathAddOnResultSid, - final String pathSid) { + public PayloadDeleter( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = + path.replace( + "{" + "AddOnResultSid" + "}", + this.pathAddOnResultSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathReferenceSid + "/AddOnResults/" + this.pathAddOnResultSid + "/Payloads/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Payload delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Payload delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadFetcher.java index 737da79eef..1bf86c78b4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording.addonresult; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,82 +24,111 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PayloadFetcher extends Fetcher { + private String pathAccountSid; - private final String pathReferenceSid; - private final String pathAddOnResultSid; - private final String pathSid; + private String pathReferenceSid; + private String pathAddOnResultSid; + private String pathSid; - /** - * Construct a new PayloadFetcher. - * - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @param pathSid Fetch by unique payload Sid - */ - public PayloadFetcher(final String pathReferenceSid, - final String pathAddOnResultSid, - final String pathSid) { + public PayloadFetcher( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; this.pathSid = pathSid; } - /** - * Construct a new PayloadFetcher. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - * @param pathSid Fetch by unique payload Sid - */ - public PayloadFetcher(final String pathAccountSid, - final String pathReferenceSid, - final String pathAddOnResultSid, - final String pathSid) { + public PayloadFetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Payload - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Payload fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = + path.replace( + "{" + "AddOnResultSid" + "}", + this.pathAddOnResultSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathReferenceSid + "/AddOnResults/" + this.pathAddOnResultSid + "/Payloads/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Payload fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Payload fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Payload fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Payload.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Payload content = Payload.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadReader.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadReader.java index c0cff7b2be..102d40b713 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/PayloadReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.recording.addonresult; @@ -10,181 +17,226 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PayloadReader extends Reader { + private String pathAccountSid; - private final String pathReferenceSid; - private final String pathAddOnResultSid; - - /** - * Construct a new PayloadReader. - * - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - */ - public PayloadReader(final String pathReferenceSid, - final String pathAddOnResultSid) { + private String pathReferenceSid; + private String pathAddOnResultSid; + private Long pageSize; + + public PayloadReader( + final String pathReferenceSid, + final String pathAddOnResultSid + ) { this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; } - /** - * Construct a new PayloadReader. - * - * @param pathAccountSid The account_sid - * @param pathReferenceSid The reference_sid - * @param pathAddOnResultSid The add_on_result_sid - */ - public PayloadReader(final String pathAccountSid, - final String pathReferenceSid, - final String pathAddOnResultSid) { + public PayloadReader( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid + ) { this.pathAccountSid = pathAccountSid; this.pathReferenceSid = pathReferenceSid; this.pathAddOnResultSid = pathAddOnResultSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Payload ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public PayloadReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Payload ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "payloads", + response.getContent(), + Payload.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = + path.replace( + "{" + "AddOnResultSid" + "}", + this.pathAddOnResultSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Recordings/" + this.pathReferenceSid + "/AddOnResults/" + this.pathAddOnResultSid + "/Payloads.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Payload ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "payloads", + response.getContent(), + Payload.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Payload read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "payloads", + response.getContent(), + Payload.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Payload Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Payload read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "payloads", - response.getContent(), - Payload.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/payload/Data.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/payload/Data.java new file mode 100644 index 0000000000..cad4b322ba --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/payload/Data.java @@ -0,0 +1,149 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.recording.addonresult.payload; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Data extends Resource { + + public static DataFetcher fetcher( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathPayloadSid + ) { + return new DataFetcher( + pathReferenceSid, + pathAddOnResultSid, + pathPayloadSid + ); + } + + public static DataFetcher fetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathPayloadSid + ) { + return new DataFetcher( + pathAccountSid, + pathReferenceSid, + pathAddOnResultSid, + pathPayloadSid + ); + } + + /** + * Converts a JSON String into a Data object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Data object represented by the provided JSON + */ + public static Data fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Data.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Data object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Data object represented by the provided JSON + */ + public static Data fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Data.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final URI redirectTo; + + @JsonCreator + private Data(@JsonProperty("redirect_to") final URI redirectTo) { + this.redirectTo = redirectTo; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Data other = (Data) o; + return (Objects.equals(redirectTo, other.redirectTo)); + } + + @Override + public int hashCode() { + return Objects.hash(redirectTo); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/payload/DataFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/payload/DataFetcher.java new file mode 100644 index 0000000000..e5853e53c6 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/recording/addonresult/payload/DataFetcher.java @@ -0,0 +1,138 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.recording.addonresult.payload; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DataFetcher extends Fetcher { + + private String pathAccountSid; + private String pathReferenceSid; + private String pathAddOnResultSid; + private String pathPayloadSid; + + public DataFetcher( + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathPayloadSid + ) { + this.pathReferenceSid = pathReferenceSid; + this.pathAddOnResultSid = pathAddOnResultSid; + this.pathPayloadSid = pathPayloadSid; + } + + public DataFetcher( + final String pathAccountSid, + final String pathReferenceSid, + final String pathAddOnResultSid, + final String pathPayloadSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathReferenceSid = pathReferenceSid; + this.pathAddOnResultSid = pathAddOnResultSid; + this.pathPayloadSid = pathPayloadSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Recordings/{ReferenceSid}/AddOnResults/{AddOnResultSid}/Payloads/{PayloadSid}/Data.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "ReferenceSid" + "}", + this.pathReferenceSid.toString() + ); + path = + path.replace( + "{" + "AddOnResultSid" + "}", + this.pathAddOnResultSid.toString() + ); + path = + path.replace( + "{" + "PayloadSid" + "}", + this.pathPayloadSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Data fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Data fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Data.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Data content = Data.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialList.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialList.java index 39046eb8ec..c8c7f2b556 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialList.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialList.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; @@ -11,150 +18,96 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class CredentialList extends Resource { - private static final long serialVersionUID = 214188792953524L; - /** - * Create a CredentialListReader to execute read. - * - * @param pathAccountSid The account_sid - * @return CredentialListReader capable of executing the read - */ - public static CredentialListReader reader(final String pathAccountSid) { - return new CredentialListReader(pathAccountSid); - } - - /** - * Create a CredentialListReader to execute read. - * - * @return CredentialListReader capable of executing the read - */ - public static CredentialListReader reader() { - return new CredentialListReader(); + public static CredentialListCreator creator(final String friendlyName) { + return new CredentialListCreator(friendlyName); } - /** - * Create a CredentialListCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param friendlyName Human readable descriptive text - * @return CredentialListCreator capable of executing the create - */ - public static CredentialListCreator creator(final String pathAccountSid, - final String friendlyName) { + public static CredentialListCreator creator( + final String pathAccountSid, + final String friendlyName + ) { return new CredentialListCreator(pathAccountSid, friendlyName); } - /** - * Create a CredentialListCreator to execute create. - * - * @param friendlyName Human readable descriptive text - * @return CredentialListCreator capable of executing the create - */ - public static CredentialListCreator creator(final String friendlyName) { - return new CredentialListCreator(friendlyName); + public static CredentialListDeleter deleter(final String pathSid) { + return new CredentialListDeleter(pathSid); } - /** - * Create a CredentialListFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique credential list Sid - * @return CredentialListFetcher capable of executing the fetch - */ - public static CredentialListFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new CredentialListFetcher(pathAccountSid, pathSid); + public static CredentialListDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new CredentialListDeleter(pathAccountSid, pathSid); } - /** - * Create a CredentialListFetcher to execute fetch. - * - * @param pathSid Fetch by unique credential list Sid - * @return CredentialListFetcher capable of executing the fetch - */ public static CredentialListFetcher fetcher(final String pathSid) { return new CredentialListFetcher(pathSid); } - /** - * Create a CredentialListUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @param friendlyName Human readable descriptive text - * @return CredentialListUpdater capable of executing the update - */ - public static CredentialListUpdater updater(final String pathAccountSid, - final String pathSid, - final String friendlyName) { - return new CredentialListUpdater(pathAccountSid, pathSid, friendlyName); + public static CredentialListFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new CredentialListFetcher(pathAccountSid, pathSid); } - /** - * Create a CredentialListUpdater to execute update. - * - * @param pathSid The sid - * @param friendlyName Human readable descriptive text - * @return CredentialListUpdater capable of executing the update - */ - public static CredentialListUpdater updater(final String pathSid, - final String friendlyName) { - return new CredentialListUpdater(pathSid, friendlyName); + public static CredentialListReader reader() { + return new CredentialListReader(); } - /** - * Create a CredentialListDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique credential list Sid - * @return CredentialListDeleter capable of executing the delete - */ - public static CredentialListDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new CredentialListDeleter(pathAccountSid, pathSid); + public static CredentialListReader reader(final String pathAccountSid) { + return new CredentialListReader(pathAccountSid); } - /** - * Create a CredentialListDeleter to execute delete. - * - * @param pathSid Delete by unique credential list Sid - * @return CredentialListDeleter capable of executing the delete - */ - public static CredentialListDeleter deleter(final String pathSid) { - return new CredentialListDeleter(pathSid); + public static CredentialListUpdater updater( + final String pathSid, + final String friendlyName + ) { + return new CredentialListUpdater(pathSid, friendlyName); + } + + public static CredentialListUpdater updater( + final String pathAccountSid, + final String pathSid, + final String friendlyName + ) { + return new CredentialListUpdater(pathAccountSid, pathSid, friendlyName); } /** - * Converts a JSON String into a CredentialList object using the provided - * ObjectMapper. - * + * Converts a JSON String into a CredentialList object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return CredentialList object represented by the provided JSON */ - public static CredentialList fromJson(final String json, final ObjectMapper objectMapper) { + public static CredentialList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialList.class); @@ -168,12 +121,15 @@ public static CredentialList fromJson(final String json, final ObjectMapper obje /** * Converts a JSON InputStream into a CredentialList object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return CredentialList object represented by the provided JSON */ - public static CredentialList fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static CredentialList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialList.class); @@ -184,101 +140,65 @@ public static CredentialList fromJson(final InputStream json, final ObjectMapper } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter private final String sid; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; @JsonCreator - private CredentialList(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("sid") - final String sid, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri) { + private CredentialList( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; this.sid = sid; this.subresourceUris = subresourceUris; this.uri = uri; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Human readable descriptive text. - * - * @return Human readable descriptive text - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The A string that uniquely identifies this credential. - * - * @return A string that uniquely identifies this credential - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -290,37 +210,27 @@ public boolean equals(final Object o) { } CredentialList other = (CredentialList) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(sid, other.sid) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - friendlyName, - sid, - subresourceUris, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("sid", sid) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + subresourceUris, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListCreator.java index 7b8e884e58..5f94be375e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,80 +27,109 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialListCreator extends Creator { + private String pathAccountSid; - private final String friendlyName; + private String friendlyName; - /** - * Construct a new CredentialListCreator. - * - * @param friendlyName Human readable descriptive text - */ public CredentialListCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * Construct a new CredentialListCreator. - * - * @param pathAccountSid The account_sid - * @param friendlyName Human readable descriptive text - */ - public CredentialListCreator(final String pathAccountSid, - final String friendlyName) { + public CredentialListCreator( + final String pathAccountSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.friendlyName = friendlyName; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created CredentialList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public CredentialList create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public CredentialListCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialList creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public CredentialList create(final TwilioRestClient client) { + Response response = makeRequest(client); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CredentialList content = CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListDeleter.java index a58bbd7142..6e5577ad44 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class CredentialListDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new CredentialListDeleter. - * - * @param pathSid Delete by unique credential list Sid - */ public CredentialListDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new CredentialListDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique credential list Sid - */ - public CredentialListDeleter(final String pathAccountSid, - final String pathSid) { + public CredentialListDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialList delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListFetcher.java index 05429f08c2..1ac8a2cdb6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialListFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new CredentialListFetcher. - * - * @param pathSid Fetch by unique credential list Sid - */ public CredentialListFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new CredentialListFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique credential list Sid - */ - public CredentialListFetcher(final String pathAccountSid, - final String pathSid) { + public CredentialListFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched CredentialList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public CredentialList fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialList fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public CredentialList fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CredentialList content = CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListReader.java index 4d615a4861..192702d22d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; @@ -10,167 +17,202 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialListReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new CredentialListReader. - */ - public CredentialListReader() { - } + public CredentialListReader() {} - /** - * Construct a new CredentialListReader. - * - * @param pathAccountSid The account_sid - */ public CredentialListReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return CredentialList ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public CredentialListReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return CredentialList ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credential_lists", + response.getContent(), + CredentialList.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return CredentialList ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credential_lists", + response.getContent(), + CredentialList.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CredentialList read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credential_lists", + response.getContent(), + CredentialList.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of CredentialList Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("CredentialList read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credential_lists", - response.getContent(), - CredentialList.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListUpdater.java index 489d33c46e..03268a3064 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/CredentialListUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,87 +27,117 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialListUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; - private final String friendlyName; + private String pathSid; + private String friendlyName; - /** - * Construct a new CredentialListUpdater. - * - * @param pathSid The sid - * @param friendlyName Human readable descriptive text - */ - public CredentialListUpdater(final String pathSid, - final String friendlyName) { + public CredentialListUpdater( + final String pathSid, + final String friendlyName + ) { this.pathSid = pathSid; this.friendlyName = friendlyName; } - /** - * Construct a new CredentialListUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @param friendlyName Human readable descriptive text - */ - public CredentialListUpdater(final String pathAccountSid, - final String pathSid, - final String friendlyName) { + public CredentialListUpdater( + final String pathAccountSid, + final String pathSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; this.friendlyName = friendlyName; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated CredentialList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public CredentialList update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public CredentialListUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialList update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public CredentialList update(final TwilioRestClient client) { + Response response = makeRequest(client); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CredentialList content = CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/Domain.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/Domain.java index 48949e7a95..53e66d6c20 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/Domain.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/Domain.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; @@ -11,146 +18,94 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Domain extends Resource { - private static final long serialVersionUID = 8739716800197L; - /** - * Create a DomainReader to execute read. - * - * @param pathAccountSid The account_sid - * @return DomainReader capable of executing the read - */ - public static DomainReader reader(final String pathAccountSid) { - return new DomainReader(pathAccountSid); - } - - /** - * Create a DomainReader to execute read. - * - * @return DomainReader capable of executing the read - */ - public static DomainReader reader() { - return new DomainReader(); + public static DomainCreator creator(final String domainName) { + return new DomainCreator(domainName); } - /** - * Create a DomainCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param domainName The unique address on Twilio to route SIP traffic - * @return DomainCreator capable of executing the create - */ - public static DomainCreator creator(final String pathAccountSid, - final String domainName) { + public static DomainCreator creator( + final String pathAccountSid, + final String domainName + ) { return new DomainCreator(pathAccountSid, domainName); } - /** - * Create a DomainCreator to execute create. - * - * @param domainName The unique address on Twilio to route SIP traffic - * @return DomainCreator capable of executing the create - */ - public static DomainCreator creator(final String domainName) { - return new DomainCreator(domainName); + public static DomainDeleter deleter(final String pathSid) { + return new DomainDeleter(pathSid); } - /** - * Create a DomainFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique Domain Sid - * @return DomainFetcher capable of executing the fetch - */ - public static DomainFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new DomainFetcher(pathAccountSid, pathSid); + public static DomainDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new DomainDeleter(pathAccountSid, pathSid); } - /** - * Create a DomainFetcher to execute fetch. - * - * @param pathSid Fetch by unique Domain Sid - * @return DomainFetcher capable of executing the fetch - */ public static DomainFetcher fetcher(final String pathSid) { return new DomainFetcher(pathSid); } - /** - * Create a DomainUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return DomainUpdater capable of executing the update - */ - public static DomainUpdater updater(final String pathAccountSid, - final String pathSid) { - return new DomainUpdater(pathAccountSid, pathSid); + public static DomainFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new DomainFetcher(pathAccountSid, pathSid); } - /** - * Create a DomainUpdater to execute update. - * - * @param pathSid The sid - * @return DomainUpdater capable of executing the update - */ - public static DomainUpdater updater(final String pathSid) { - return new DomainUpdater(pathSid); + public static DomainReader reader() { + return new DomainReader(); } - /** - * Create a DomainDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return DomainDeleter capable of executing the delete - */ - public static DomainDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new DomainDeleter(pathAccountSid, pathSid); + public static DomainReader reader(final String pathAccountSid) { + return new DomainReader(pathAccountSid); } - /** - * Create a DomainDeleter to execute delete. - * - * @param pathSid The sid - * @return DomainDeleter capable of executing the delete - */ - public static DomainDeleter deleter(final String pathSid) { - return new DomainDeleter(pathSid); + public static DomainUpdater updater(final String pathSid) { + return new DomainUpdater(pathSid); + } + + public static DomainUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new DomainUpdater(pathAccountSid, pathSid); } /** * Converts a JSON String into a Domain object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Domain object represented by the provided JSON */ - public static Domain fromJson(final String json, final ObjectMapper objectMapper) { + public static Domain fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Domain.class); @@ -164,12 +119,15 @@ public static Domain fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Domain object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Domain object represented by the provided JSON */ - public static Domain fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Domain fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Domain.class); @@ -180,67 +138,134 @@ public static Domain fromJson(final InputStream json, final ObjectMapper objectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; + + @Getter private final String authType; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String byocTrunkSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String domainName; + + @Getter + private final String emergencyCallerSid; + + @Getter + private final Boolean emergencyCallingEnabled; + + @Getter private final String friendlyName; + + @Getter + private final Boolean secure; + + @Getter private final String sid; + + @Getter + private final Boolean sipRegistration; + + @Getter + private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final HttpMethod voiceFallbackMethod; + + @Getter private final URI voiceFallbackUrl; + + @Getter private final HttpMethod voiceMethod; + + @Getter private final HttpMethod voiceStatusCallbackMethod; + + @Getter private final URI voiceStatusCallbackUrl; + + @Getter private final URI voiceUrl; - private final Map subresourceUris; - private final Boolean sipRegistration; @JsonCreator - private Domain(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("auth_type") - final String authType, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("domain_name") - final String domainName, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("sid") - final String sid, - @JsonProperty("uri") - final String uri, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_status_callback_method") - final HttpMethod voiceStatusCallbackMethod, - @JsonProperty("voice_status_callback_url") - final URI voiceStatusCallbackUrl, - @JsonProperty("voice_url") - final URI voiceUrl, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("sip_registration") - final Boolean sipRegistration) { + private Domain( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("auth_type") final String authType, + @JsonProperty("byoc_trunk_sid") final String byocTrunkSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_name") final String domainName, + @JsonProperty("emergency_caller_sid") final String emergencyCallerSid, + @JsonProperty( + "emergency_calling_enabled" + ) final Boolean emergencyCallingEnabled, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("secure") final Boolean secure, + @JsonProperty("sid") final String sid, + @JsonProperty("sip_registration") final Boolean sipRegistration, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty( + "voice_status_callback_method" + ) final HttpMethod voiceStatusCallbackMethod, + @JsonProperty( + "voice_status_callback_url" + ) final URI voiceStatusCallbackUrl, + @JsonProperty("voice_url") final URI voiceUrl + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; this.authType = authType; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.byocTrunkSid = byocTrunkSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.domainName = domainName; + this.emergencyCallerSid = emergencyCallerSid; + this.emergencyCallingEnabled = emergencyCallingEnabled; this.friendlyName = friendlyName; + this.secure = secure; this.sid = sid; + this.sipRegistration = sipRegistration; + this.subresourceUris = subresourceUris; this.uri = uri; this.voiceFallbackMethod = voiceFallbackMethod; this.voiceFallbackUrl = voiceFallbackUrl; @@ -248,163 +273,6 @@ private Domain(@JsonProperty("account_sid") this.voiceStatusCallbackMethod = voiceStatusCallbackMethod; this.voiceStatusCallbackUrl = voiceStatusCallbackUrl; this.voiceUrl = voiceUrl; - this.subresourceUris = subresourceUris; - this.sipRegistration = sipRegistration; - } - - /** - * Returns The The unique id of the account that sent the message. - * - * @return The unique id of the account that sent the message - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The Twilio API version used to process the message. - * - * @return The Twilio API version used to process the message - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The types of authentication mapped to the domain. - * - * @return The types of authentication mapped to the domain - */ - public final String getAuthType() { - return this.authType; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The unique address on Twilio to route SIP traffic. - * - * @return The unique address on Twilio to route SIP traffic - */ - public final String getDomainName() { - return this.domainName; - } - - /** - * Returns The A user-specified, human-readable name for the trigger.. - * - * @return A user-specified, human-readable name for the trigger. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The A string that uniquely identifies the SIP Domain. - * - * @return A string that uniquely identifies the SIP Domain - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The HTTP method used with voice_fallback_url. - * - * @return HTTP method used with voice_fallback_url - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - - /** - * Returns The URL Twilio will request if an error occurs in executing TwiML. - * - * @return URL Twilio will request if an error occurs in executing TwiML - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - - /** - * Returns The HTTP method to use with voice_url. - * - * @return HTTP method to use with voice_url - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - - /** - * Returns The The HTTP method Twilio will use to make requests to the - * StatusCallback URL.. - * - * @return The HTTP method Twilio will use to make requests to the - * StatusCallback URL. - */ - public final HttpMethod getVoiceStatusCallbackMethod() { - return this.voiceStatusCallbackMethod; - } - - /** - * Returns The URL that Twilio will request with status updates. - * - * @return URL that Twilio will request with status updates - */ - public final URI getVoiceStatusCallbackUrl() { - return this.voiceStatusCallbackUrl; - } - - /** - * Returns The URL Twilio will request when receiving a call. - * - * @return URL Twilio will request when receiving a call - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } - - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The If SIP registration is allowed. - * - * @return If SIP registration is allowed - */ - public final Boolean getSipRegistration() { - return this.sipRegistration; } @Override @@ -418,67 +286,64 @@ public boolean equals(final Object o) { } Domain other = (Domain) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(authType, other.authType) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(domainName, other.domainName) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(sid, other.sid) && - Objects.equals(uri, other.uri) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceStatusCallbackMethod, other.voiceStatusCallbackMethod) && - Objects.equals(voiceStatusCallbackUrl, other.voiceStatusCallbackUrl) && - Objects.equals(voiceUrl, other.voiceUrl) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(sipRegistration, other.sipRegistration); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(authType, other.authType) && + Objects.equals(byocTrunkSid, other.byocTrunkSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainName, other.domainName) && + Objects.equals(emergencyCallerSid, other.emergencyCallerSid) && + Objects.equals( + emergencyCallingEnabled, + other.emergencyCallingEnabled + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(secure, other.secure) && + Objects.equals(sid, other.sid) && + Objects.equals(sipRegistration, other.sipRegistration) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals( + voiceStatusCallbackMethod, + other.voiceStatusCallbackMethod + ) && + Objects.equals( + voiceStatusCallbackUrl, + other.voiceStatusCallbackUrl + ) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - authType, - dateCreated, - dateUpdated, - domainName, - friendlyName, - sid, - uri, - voiceFallbackMethod, - voiceFallbackUrl, - voiceMethod, - voiceStatusCallbackMethod, - voiceStatusCallbackUrl, - voiceUrl, - subresourceUris, - sipRegistration); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("authType", authType) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("domainName", domainName) - .add("friendlyName", friendlyName) - .add("sid", sid) - .add("uri", uri) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceMethod", voiceMethod) - .add("voiceStatusCallbackMethod", voiceStatusCallbackMethod) - .add("voiceStatusCallbackUrl", voiceStatusCallbackUrl) - .add("voiceUrl", voiceUrl) - .add("subresourceUris", subresourceUris) - .add("sipRegistration", sipRegistration) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + authType, + byocTrunkSid, + dateCreated, + dateUpdated, + domainName, + emergencyCallerSid, + emergencyCallingEnabled, + friendlyName, + secure, + sid, + sipRegistration, + subresourceUris, + uri, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceStatusCallbackMethod, + voiceStatusCallbackUrl, + voiceUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainCreator.java index 99a0aaf52e..3218774507 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,14 +28,15 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class DomainCreator extends Creator { + private String pathAccountSid; - private final String domainName; + private String domainName; private String friendlyName; - private String authType; private URI voiceUrl; private HttpMethod voiceMethod; private URI voiceFallbackUrl; @@ -32,253 +44,293 @@ public class DomainCreator extends Creator { private URI voiceStatusCallbackUrl; private HttpMethod voiceStatusCallbackMethod; private Boolean sipRegistration; + private Boolean emergencyCallingEnabled; + private Boolean secure; + private String byocTrunkSid; + private String emergencyCallerSid; - /** - * Construct a new DomainCreator. - * - * @param domainName The unique address on Twilio to route SIP traffic - */ public DomainCreator(final String domainName) { this.domainName = domainName; } - /** - * Construct a new DomainCreator. - * - * @param pathAccountSid The account_sid - * @param domainName The unique address on Twilio to route SIP traffic - */ - public DomainCreator(final String pathAccountSid, - final String domainName) { + public DomainCreator(final String pathAccountSid, final String domainName) { this.pathAccountSid = pathAccountSid; this.domainName = domainName; } - /** - * A human readable descriptive text, up to 64 characters long.. - * - * @param friendlyName A user-specified, human-readable name for the trigger. - * @return this - */ - public DomainCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; + public DomainCreator setDomainName(final String domainName) { + this.domainName = domainName; return this; } - /** - * The types of authentication you have mapped to your domain. - * - * @param authType The types of authentication mapped to the domain - * @return this - */ - public DomainCreator setAuthType(final String authType) { - this.authType = authType; + public DomainCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; return this; } - /** - * The URL Twilio will request when this domain receives a call.. - * - * @param voiceUrl URL Twilio will request when receiving a call - * @return this - */ public DomainCreator setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The URL Twilio will request when this domain receives a call.. - * - * @param voiceUrl URL Twilio will request when receiving a call - * @return this - */ public DomainCreator setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The HTTP method Twilio will use when requesting the above Url. Either `GET` - * or `POST`.. - * - * @param voiceMethod HTTP method to use with voice_url - * @return this - */ public DomainCreator setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - /** - * The URL that Twilio will request if an error occurs retrieving or executing - * the TwiML requested by VoiceUrl.. - * - * @param voiceFallbackUrl URL Twilio will request if an error occurs in - * executing TwiML - * @return this - */ public DomainCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * The URL that Twilio will request if an error occurs retrieving or executing - * the TwiML requested by VoiceUrl.. - * - * @param voiceFallbackUrl URL Twilio will request if an error occurs in - * executing TwiML - * @return this - */ public DomainCreator setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method Twilio will use when requesting the VoiceFallbackUrl. Either - * `GET` or `POST`.. - * - * @param voiceFallbackMethod HTTP method used with voice_fallback_url - * @return this - */ - public DomainCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public DomainCreator setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param voiceStatusCallbackUrl URL that Twilio will request with status - * updates - * @return this - */ - public DomainCreator setVoiceStatusCallbackUrl(final URI voiceStatusCallbackUrl) { + public DomainCreator setVoiceStatusCallbackUrl( + final URI voiceStatusCallbackUrl + ) { this.voiceStatusCallbackUrl = voiceStatusCallbackUrl; return this; } - /** - * The URL that Twilio will request to pass status parameters (such as call - * ended) to your application.. - * - * @param voiceStatusCallbackUrl URL that Twilio will request with status - * updates - * @return this - */ - public DomainCreator setVoiceStatusCallbackUrl(final String voiceStatusCallbackUrl) { - return setVoiceStatusCallbackUrl(Promoter.uriFromString(voiceStatusCallbackUrl)); + public DomainCreator setVoiceStatusCallbackUrl( + final String voiceStatusCallbackUrl + ) { + return setVoiceStatusCallbackUrl( + Promoter.uriFromString(voiceStatusCallbackUrl) + ); } - /** - * The HTTP method Twilio will use to make requests to the StatusCallback URL. - * Either `GET` or `POST`.. - * - * @param voiceStatusCallbackMethod The HTTP method Twilio will use to make - * requests to the StatusCallback URL. - * @return this - */ - public DomainCreator setVoiceStatusCallbackMethod(final HttpMethod voiceStatusCallbackMethod) { + public DomainCreator setVoiceStatusCallbackMethod( + final HttpMethod voiceStatusCallbackMethod + ) { this.voiceStatusCallbackMethod = voiceStatusCallbackMethod; return this; } - /** - * The sip_registration. - * - * @param sipRegistration The sip_registration - * @return this - */ public DomainCreator setSipRegistration(final Boolean sipRegistration) { this.sipRegistration = sipRegistration; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Domain - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Domain create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public DomainCreator setEmergencyCallingEnabled( + final Boolean emergencyCallingEnabled + ) { + this.emergencyCallingEnabled = emergencyCallingEnabled; + return this; + } + + public DomainCreator setSecure(final Boolean secure) { + this.secure = secure; + return this; + } + + public DomainCreator setByocTrunkSid(final String byocTrunkSid) { + this.byocTrunkSid = byocTrunkSid; + return this; + } + + public DomainCreator setEmergencyCallerSid( + final String emergencyCallerSid + ) { + this.emergencyCallerSid = emergencyCallerSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Domain creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Domain create(final TwilioRestClient client) { + Response response = makeRequest(client); return Domain.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Domain content = Domain.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (domainName != null) { - request.addPostParam("DomainName", domainName); + Serializer.toString( + request, + "DomainName", + domainName, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (authType != null) { - request.addPostParam("AuthType", authType); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (voiceStatusCallbackUrl != null) { - request.addPostParam("VoiceStatusCallbackUrl", voiceStatusCallbackUrl.toString()); + Serializer.toString( + request, + "VoiceStatusCallbackUrl", + voiceStatusCallbackUrl, + ParameterType.URLENCODED + ); } if (voiceStatusCallbackMethod != null) { - request.addPostParam("VoiceStatusCallbackMethod", voiceStatusCallbackMethod.toString()); + Serializer.toString( + request, + "VoiceStatusCallbackMethod", + voiceStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (sipRegistration != null) { - request.addPostParam("SipRegistration", sipRegistration.toString()); + Serializer.toString( + request, + "SipRegistration", + sipRegistration, + ParameterType.URLENCODED + ); + } + + if (emergencyCallingEnabled != null) { + Serializer.toString( + request, + "EmergencyCallingEnabled", + emergencyCallingEnabled, + ParameterType.URLENCODED + ); + } + + if (secure != null) { + Serializer.toString( + request, + "Secure", + secure, + ParameterType.URLENCODED + ); + } + + if (byocTrunkSid != null) { + Serializer.toString( + request, + "ByocTrunkSid", + byocTrunkSid, + ParameterType.URLENCODED + ); + } + + if (emergencyCallerSid != null) { + Serializer.toString( + request, + "EmergencyCallerSid", + emergencyCallerSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainDeleter.java index 85bdaae4aa..4d4d608c49 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,90 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class DomainDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new DomainDeleter. - * - * @param pathSid The sid - */ public DomainDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new DomainDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public DomainDeleter(final String pathAccountSid, - final String pathSid) { + public DomainDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Domain delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainFetcher.java index a791a9e4b0..ee1e80ba36 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,86 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class DomainFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new DomainFetcher. - * - * @param pathSid Fetch by unique Domain Sid - */ public DomainFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new DomainFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique Domain Sid - */ - public DomainFetcher(final String pathAccountSid, - final String pathSid) { + public DomainFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Domain - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Domain fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Domain fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Domain fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Domain.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Domain content = Domain.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainReader.java index e281449c56..b6c3a49e8b 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; @@ -10,167 +17,197 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class DomainReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new DomainReader. - */ - public DomainReader() { - } + public DomainReader() {} - /** - * Construct a new DomainReader. - * - * @param pathAccountSid The account_sid - */ public DomainReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Domain ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public DomainReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Domain ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "domains", + response.getContent(), + Domain.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/SIP/Domains.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Domain ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "domains", + response.getContent(), + Domain.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Domain read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "domains", + response.getContent(), + Domain.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Domain Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Domain read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "domains", - response.getContent(), - Domain.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainUpdater.java index b9fa02104e..4da73479f9 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/DomainUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,13 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class DomainUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; - private String authType; + private String pathSid; private String friendlyName; private HttpMethod voiceFallbackMethod; private URI voiceFallbackUrl; @@ -32,237 +44,296 @@ public class DomainUpdater extends Updater { private URI voiceStatusCallbackUrl; private URI voiceUrl; private Boolean sipRegistration; + private String domainName; + private Boolean emergencyCallingEnabled; + private Boolean secure; + private String byocTrunkSid; + private String emergencyCallerSid; - /** - * Construct a new DomainUpdater. - * - * @param pathSid The sid - */ public DomainUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new DomainUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public DomainUpdater(final String pathAccountSid, - final String pathSid) { + public DomainUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * The auth_type. - * - * @param authType The auth_type - * @return this - */ - public DomainUpdater setAuthType(final String authType) { - this.authType = authType; - return this; - } - - /** - * A user-specified, human-readable name for the trigger.. - * - * @param friendlyName A user-specified, human-readable name for the trigger. - * @return this - */ public DomainUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The voice_fallback_method. - * - * @param voiceFallbackMethod The voice_fallback_method - * @return this - */ - public DomainUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public DomainUpdater setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * The voice_fallback_url. - * - * @param voiceFallbackUrl The voice_fallback_url - * @return this - */ public DomainUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * The voice_fallback_url. - * - * @param voiceFallbackUrl The voice_fallback_url - * @return this - */ public DomainUpdater setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The HTTP method to use with the voice_url. - * - * @param voiceMethod HTTP method to use with voice_url - * @return this - */ public DomainUpdater setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - /** - * The voice_status_callback_method. - * - * @param voiceStatusCallbackMethod The voice_status_callback_method - * @return this - */ - public DomainUpdater setVoiceStatusCallbackMethod(final HttpMethod voiceStatusCallbackMethod) { + public DomainUpdater setVoiceStatusCallbackMethod( + final HttpMethod voiceStatusCallbackMethod + ) { this.voiceStatusCallbackMethod = voiceStatusCallbackMethod; return this; } - /** - * The voice_status_callback_url. - * - * @param voiceStatusCallbackUrl The voice_status_callback_url - * @return this - */ - public DomainUpdater setVoiceStatusCallbackUrl(final URI voiceStatusCallbackUrl) { + public DomainUpdater setVoiceStatusCallbackUrl( + final URI voiceStatusCallbackUrl + ) { this.voiceStatusCallbackUrl = voiceStatusCallbackUrl; return this; } - /** - * The voice_status_callback_url. - * - * @param voiceStatusCallbackUrl The voice_status_callback_url - * @return this - */ - public DomainUpdater setVoiceStatusCallbackUrl(final String voiceStatusCallbackUrl) { - return setVoiceStatusCallbackUrl(Promoter.uriFromString(voiceStatusCallbackUrl)); + public DomainUpdater setVoiceStatusCallbackUrl( + final String voiceStatusCallbackUrl + ) { + return setVoiceStatusCallbackUrl( + Promoter.uriFromString(voiceStatusCallbackUrl) + ); } - /** - * The voice_url. - * - * @param voiceUrl The voice_url - * @return this - */ public DomainUpdater setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The voice_url. - * - * @param voiceUrl The voice_url - * @return this - */ public DomainUpdater setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * The sip_registration. - * - * @param sipRegistration The sip_registration - * @return this - */ public DomainUpdater setSipRegistration(final Boolean sipRegistration) { this.sipRegistration = sipRegistration; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Domain - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Domain update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public DomainUpdater setDomainName(final String domainName) { + this.domainName = domainName; + return this; + } + + public DomainUpdater setEmergencyCallingEnabled( + final Boolean emergencyCallingEnabled + ) { + this.emergencyCallingEnabled = emergencyCallingEnabled; + return this; + } + + public DomainUpdater setSecure(final Boolean secure) { + this.secure = secure; + return this; + } + + public DomainUpdater setByocTrunkSid(final String byocTrunkSid) { + this.byocTrunkSid = byocTrunkSid; + return this; + } + + public DomainUpdater setEmergencyCallerSid( + final String emergencyCallerSid + ) { + this.emergencyCallerSid = emergencyCallerSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Domain update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Domain update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Domain update(final TwilioRestClient client) { + Response response = makeRequest(client); return Domain.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (authType != null) { - request.addPostParam("AuthType", authType); - } + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Domain content = Domain.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceStatusCallbackMethod != null) { - request.addPostParam("VoiceStatusCallbackMethod", voiceStatusCallbackMethod.toString()); + Serializer.toString( + request, + "VoiceStatusCallbackMethod", + voiceStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (voiceStatusCallbackUrl != null) { - request.addPostParam("VoiceStatusCallbackUrl", voiceStatusCallbackUrl.toString()); + Serializer.toString( + request, + "VoiceStatusCallbackUrl", + voiceStatusCallbackUrl, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } if (sipRegistration != null) { - request.addPostParam("SipRegistration", sipRegistration.toString()); + Serializer.toString( + request, + "SipRegistration", + sipRegistration, + ParameterType.URLENCODED + ); + } + + if (domainName != null) { + Serializer.toString( + request, + "DomainName", + domainName, + ParameterType.URLENCODED + ); + } + + if (emergencyCallingEnabled != null) { + Serializer.toString( + request, + "EmergencyCallingEnabled", + emergencyCallingEnabled, + ParameterType.URLENCODED + ); + } + + if (secure != null) { + Serializer.toString( + request, + "Secure", + secure, + ParameterType.URLENCODED + ); + } + + if (byocTrunkSid != null) { + Serializer.toString( + request, + "ByocTrunkSid", + byocTrunkSid, + ParameterType.URLENCODED + ); + } + + if (emergencyCallerSid != null) { + Serializer.toString( + request, + "EmergencyCallerSid", + emergencyCallerSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlList.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlList.java index 0ad001f225..44c3b285b4 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlList.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlList.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; @@ -11,150 +18,104 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class IpAccessControlList extends Resource { - private static final long serialVersionUID = 214188792953524L; - /** - * Create a IpAccessControlListReader to execute read. - * - * @param pathAccountSid The account_sid - * @return IpAccessControlListReader capable of executing the read - */ - public static IpAccessControlListReader reader(final String pathAccountSid) { - return new IpAccessControlListReader(pathAccountSid); - } - - /** - * Create a IpAccessControlListReader to execute read. - * - * @return IpAccessControlListReader capable of executing the read - */ - public static IpAccessControlListReader reader() { - return new IpAccessControlListReader(); + public static IpAccessControlListCreator creator( + final String friendlyName + ) { + return new IpAccessControlListCreator(friendlyName); } - /** - * Create a IpAccessControlListCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param friendlyName A human readable description of this resource - * @return IpAccessControlListCreator capable of executing the create - */ - public static IpAccessControlListCreator creator(final String pathAccountSid, - final String friendlyName) { + public static IpAccessControlListCreator creator( + final String pathAccountSid, + final String friendlyName + ) { return new IpAccessControlListCreator(pathAccountSid, friendlyName); } - /** - * Create a IpAccessControlListCreator to execute create. - * - * @param friendlyName A human readable description of this resource - * @return IpAccessControlListCreator capable of executing the create - */ - public static IpAccessControlListCreator creator(final String friendlyName) { - return new IpAccessControlListCreator(friendlyName); + public static IpAccessControlListDeleter deleter(final String pathSid) { + return new IpAccessControlListDeleter(pathSid); } - /** - * Create a IpAccessControlListFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique ip-access-control-list Sid - * @return IpAccessControlListFetcher capable of executing the fetch - */ - public static IpAccessControlListFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new IpAccessControlListFetcher(pathAccountSid, pathSid); + public static IpAccessControlListDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new IpAccessControlListDeleter(pathAccountSid, pathSid); } - /** - * Create a IpAccessControlListFetcher to execute fetch. - * - * @param pathSid Fetch by unique ip-access-control-list Sid - * @return IpAccessControlListFetcher capable of executing the fetch - */ public static IpAccessControlListFetcher fetcher(final String pathSid) { return new IpAccessControlListFetcher(pathSid); } - /** - * Create a IpAccessControlListUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @param friendlyName A human readable description of this resource - * @return IpAccessControlListUpdater capable of executing the update - */ - public static IpAccessControlListUpdater updater(final String pathAccountSid, - final String pathSid, - final String friendlyName) { - return new IpAccessControlListUpdater(pathAccountSid, pathSid, friendlyName); + public static IpAccessControlListFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new IpAccessControlListFetcher(pathAccountSid, pathSid); } - /** - * Create a IpAccessControlListUpdater to execute update. - * - * @param pathSid The sid - * @param friendlyName A human readable description of this resource - * @return IpAccessControlListUpdater capable of executing the update - */ - public static IpAccessControlListUpdater updater(final String pathSid, - final String friendlyName) { - return new IpAccessControlListUpdater(pathSid, friendlyName); + public static IpAccessControlListReader reader() { + return new IpAccessControlListReader(); } - /** - * Create a IpAccessControlListDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique ip-access-control-list Sid - * @return IpAccessControlListDeleter capable of executing the delete - */ - public static IpAccessControlListDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new IpAccessControlListDeleter(pathAccountSid, pathSid); + public static IpAccessControlListReader reader( + final String pathAccountSid + ) { + return new IpAccessControlListReader(pathAccountSid); } - /** - * Create a IpAccessControlListDeleter to execute delete. - * - * @param pathSid Delete by unique ip-access-control-list Sid - * @return IpAccessControlListDeleter capable of executing the delete - */ - public static IpAccessControlListDeleter deleter(final String pathSid) { - return new IpAccessControlListDeleter(pathSid); + public static IpAccessControlListUpdater updater( + final String pathSid, + final String friendlyName + ) { + return new IpAccessControlListUpdater(pathSid, friendlyName); + } + + public static IpAccessControlListUpdater updater( + final String pathAccountSid, + final String pathSid, + final String friendlyName + ) { + return new IpAccessControlListUpdater( + pathAccountSid, + pathSid, + friendlyName + ); } /** - * Converts a JSON String into a IpAccessControlList object using the provided - * ObjectMapper. - * + * Converts a JSON String into a IpAccessControlList object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return IpAccessControlList object represented by the provided JSON */ - public static IpAccessControlList fromJson(final String json, final ObjectMapper objectMapper) { + public static IpAccessControlList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAccessControlList.class); @@ -166,14 +127,17 @@ public static IpAccessControlList fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a IpAccessControlList object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a IpAccessControlList object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return IpAccessControlList object represented by the provided JSON */ - public static IpAccessControlList fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static IpAccessControlList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAccessControlList.class); @@ -184,101 +148,65 @@ public static IpAccessControlList fromJson(final InputStream json, final ObjectM } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; @JsonCreator - private IpAccessControlList(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri) { - this.sid = sid; + private IpAccessControlList( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.sid = sid; this.subresourceUris = subresourceUris; this.uri = uri; } - /** - * Returns The A string that uniquely identifies this resource. - * - * @return A string that uniquely identifies this resource - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The A human readable description of this resource. - * - * @return A human readable description of this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -290,37 +218,27 @@ public boolean equals(final Object o) { } IpAccessControlList other = (IpAccessControlList) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - subresourceUris, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + subresourceUris, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListCreator.java index 303e4ad368..0d9204d5e0 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,80 +27,111 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAccessControlListCreator extends Creator { + private String pathAccountSid; - private final String friendlyName; + private String friendlyName; - /** - * Construct a new IpAccessControlListCreator. - * - * @param friendlyName A human readable description of this resource - */ public IpAccessControlListCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * Construct a new IpAccessControlListCreator. - * - * @param pathAccountSid The account_sid - * @param friendlyName A human readable description of this resource - */ - public IpAccessControlListCreator(final String pathAccountSid, - final String friendlyName) { + public IpAccessControlListCreator( + final String pathAccountSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.friendlyName = friendlyName; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created IpAccessControlList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAccessControlList create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public IpAccessControlListCreator setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlList creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public IpAccessControlList create(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAccessControlList content = IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListDeleter.java index 2d6965939e..23159d2bdc 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class IpAccessControlListDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new IpAccessControlListDeleter. - * - * @param pathSid Delete by unique ip-access-control-list Sid - */ public IpAccessControlListDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new IpAccessControlListDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid Delete by unique ip-access-control-list Sid - */ - public IpAccessControlListDeleter(final String pathAccountSid, - final String pathSid) { + public IpAccessControlListDeleter( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlList delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListFetcher.java index 674825cb2c..ce5032301c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAccessControlListFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new IpAccessControlListFetcher. - * - * @param pathSid Fetch by unique ip-access-control-list Sid - */ public IpAccessControlListFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new IpAccessControlListFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique ip-access-control-list Sid - */ - public IpAccessControlListFetcher(final String pathAccountSid, - final String pathSid) { + public IpAccessControlListFetcher( + final String pathAccountSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched IpAccessControlList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAccessControlList fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlList fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public IpAccessControlList fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAccessControlList content = IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListReader.java index 92e95d994f..3d99a5aabe 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; @@ -10,167 +17,204 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAccessControlListReader extends Reader { + private String pathAccountSid; + private Long pageSize; - /** - * Construct a new IpAccessControlListReader. - */ - public IpAccessControlListReader() { - } + public IpAccessControlListReader() {} - /** - * Construct a new IpAccessControlListReader. - * - * @param pathAccountSid The account_sid - */ public IpAccessControlListReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlList ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public IpAccessControlListReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlList ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_access_control_lists", + response.getContent(), + IpAccessControlList.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlList ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_access_control_lists", + response.getContent(), + IpAccessControlList.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "IpAccessControlList read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "ip_access_control_lists", + response.getContent(), + IpAccessControlList.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of IpAccessControlList Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("IpAccessControlList read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "ip_access_control_lists", - response.getContent(), - IpAccessControlList.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListUpdater.java index b39fad00c5..df83fde45a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/IpAccessControlListUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,87 +27,119 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAccessControlListUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; - private final String friendlyName; + private String pathSid; + private String friendlyName; - /** - * Construct a new IpAccessControlListUpdater. - * - * @param pathSid The sid - * @param friendlyName A human readable description of this resource - */ - public IpAccessControlListUpdater(final String pathSid, - final String friendlyName) { + public IpAccessControlListUpdater( + final String pathSid, + final String friendlyName + ) { this.pathSid = pathSid; this.friendlyName = friendlyName; } - /** - * Construct a new IpAccessControlListUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @param friendlyName A human readable description of this resource - */ - public IpAccessControlListUpdater(final String pathAccountSid, - final String pathSid, - final String friendlyName) { + public IpAccessControlListUpdater( + final String pathAccountSid, + final String pathSid, + final String friendlyName + ) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; this.friendlyName = friendlyName; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated IpAccessControlList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAccessControlList update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public IpAccessControlListUpdater setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlList update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public IpAccessControlList update(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAccessControlList content = IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/Credential.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/Credential.java index b4af73d58f..324f55c018 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/Credential.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/Credential.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.credentiallist; @@ -11,169 +18,129 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Credential extends Resource { - private static final long serialVersionUID = 207131851434233L; - /** - * Create a CredentialReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @return CredentialReader capable of executing the read - */ - public static CredentialReader reader(final String pathAccountSid, - final String pathCredentialListSid) { - return new CredentialReader(pathAccountSid, pathCredentialListSid); + public static CredentialCreator creator( + final String pathCredentialListSid, + final String username, + final String password + ) { + return new CredentialCreator(pathCredentialListSid, username, password); } - /** - * Create a CredentialReader to execute read. - * - * @param pathCredentialListSid The credential_list_sid - * @return CredentialReader capable of executing the read - */ - public static CredentialReader reader(final String pathCredentialListSid) { - return new CredentialReader(pathCredentialListSid); + public static CredentialCreator creator( + final String pathAccountSid, + final String pathCredentialListSid, + final String username, + final String password + ) { + return new CredentialCreator( + pathAccountSid, + pathCredentialListSid, + username, + password + ); } - /** - * Create a CredentialCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @param username The username for this credential. - * @param password The password will not be returned in the response. - * @return CredentialCreator capable of executing the create - */ - public static CredentialCreator creator(final String pathAccountSid, - final String pathCredentialListSid, - final String username, - final String password) { - return new CredentialCreator(pathAccountSid, pathCredentialListSid, username, password); + public static CredentialDeleter deleter( + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialDeleter(pathCredentialListSid, pathSid); } - /** - * Create a CredentialCreator to execute create. - * - * @param pathCredentialListSid The credential_list_sid - * @param username The username for this credential. - * @param password The password will not be returned in the response. - * @return CredentialCreator capable of executing the create - */ - public static CredentialCreator creator(final String pathCredentialListSid, - final String username, - final String password) { - return new CredentialCreator(pathCredentialListSid, username, password); + public static CredentialDeleter deleter( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialDeleter( + pathAccountSid, + pathCredentialListSid, + pathSid + ); } - /** - * Create a CredentialFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - * @return CredentialFetcher capable of executing the fetch - */ - public static CredentialFetcher fetcher(final String pathAccountSid, - final String pathCredentialListSid, - final String pathSid) { - return new CredentialFetcher(pathAccountSid, pathCredentialListSid, pathSid); + public static CredentialFetcher fetcher( + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialFetcher(pathCredentialListSid, pathSid); } - /** - * Create a CredentialFetcher to execute fetch. - * - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - * @return CredentialFetcher capable of executing the fetch - */ - public static CredentialFetcher fetcher(final String pathCredentialListSid, - final String pathSid) { - return new CredentialFetcher(pathCredentialListSid, pathSid); + public static CredentialFetcher fetcher( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialFetcher( + pathAccountSid, + pathCredentialListSid, + pathSid + ); } - /** - * Create a CredentialUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - * @return CredentialUpdater capable of executing the update - */ - public static CredentialUpdater updater(final String pathAccountSid, - final String pathCredentialListSid, - final String pathSid) { - return new CredentialUpdater(pathAccountSid, pathCredentialListSid, pathSid); + public static CredentialReader reader(final String pathCredentialListSid) { + return new CredentialReader(pathCredentialListSid); } - /** - * Create a CredentialUpdater to execute update. - * - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - * @return CredentialUpdater capable of executing the update - */ - public static CredentialUpdater updater(final String pathCredentialListSid, - final String pathSid) { - return new CredentialUpdater(pathCredentialListSid, pathSid); + public static CredentialReader reader( + final String pathAccountSid, + final String pathCredentialListSid + ) { + return new CredentialReader(pathAccountSid, pathCredentialListSid); } - /** - * Create a CredentialDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - * @return CredentialDeleter capable of executing the delete - */ - public static CredentialDeleter deleter(final String pathAccountSid, - final String pathCredentialListSid, - final String pathSid) { - return new CredentialDeleter(pathAccountSid, pathCredentialListSid, pathSid); + public static CredentialUpdater updater( + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialUpdater(pathCredentialListSid, pathSid); } - /** - * Create a CredentialDeleter to execute delete. - * - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - * @return CredentialDeleter capable of executing the delete - */ - public static CredentialDeleter deleter(final String pathCredentialListSid, - final String pathSid) { - return new CredentialDeleter(pathCredentialListSid, pathSid); + public static CredentialUpdater updater( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { + return new CredentialUpdater( + pathAccountSid, + pathCredentialListSid, + pathSid + ); } /** - * Converts a JSON String into a Credential object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -187,12 +154,15 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a Credential object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -203,103 +173,60 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; - private final String accountSid; - private final String credentialListSid; - private final String username; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String uri; - - @JsonCreator - private Credential(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("credential_list_sid") - final String credentialListSid, - @JsonProperty("username") - final String username, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("uri") - final String uri) { - this.sid = sid; - this.accountSid = accountSid; - this.credentialListSid = credentialListSid; - this.username = username; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.uri = uri; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account that responsible for this resource.. - * - * @return The unique id of the Account that responsible for this resource. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String credentialListSid; - /** - * Returns The The credential_list_sid. - * - * @return The credential_list_sid - */ - public final String getCredentialListSid() { - return this.credentialListSid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The username for this credential.. - * - * @return The username for this credential. - */ - public final String getUsername() { - return this.username; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was created, given as GMT in RFC 2822 - * format.. - * - * @return The date that this resource was created, given as GMT in RFC 2822 - * format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date that this resource was last updated, given as GMT in RFC - * 2822 format.. - * - * @return The date that this resource was last updated, given as GMT in RFC - * 2822 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String uri; - /** - * Returns The The URI for this resource, relative to https://api.. - * - * @return The URI for this resource, relative to https://api. - */ - public final String getUri() { - return this.uri; + @Getter + private final String username; + + @JsonCreator + private Credential( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("credential_list_sid") final String credentialListSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri, + @JsonProperty("username") final String username + ) { + this.accountSid = accountSid; + this.credentialListSid = credentialListSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.sid = sid; + this.uri = uri; + this.username = username; } @Override @@ -313,37 +240,27 @@ public boolean equals(final Object o) { } Credential other = (Credential) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(credentialListSid, other.credentialListSid) && - Objects.equals(username, other.username) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(credentialListSid, other.credentialListSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) && + Objects.equals(username, other.username) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - credentialListSid, - username, - dateCreated, - dateUpdated, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("credentialListSid", credentialListSid) - .add("username", username) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + credentialListSid, + dateCreated, + dateUpdated, + sid, + uri, + username + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialCreator.java index a98b0203a2..8655b46e82 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.credentiallist; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,98 +27,140 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialCreator extends Creator { + private String pathAccountSid; - private final String pathCredentialListSid; - private final String username; - private final String password; - - /** - * Construct a new CredentialCreator. - * - * @param pathCredentialListSid The credential_list_sid - * @param username The username for this credential. - * @param password The password will not be returned in the response. - */ - public CredentialCreator(final String pathCredentialListSid, - final String username, - final String password) { + private String pathCredentialListSid; + private String username; + private String password; + + public CredentialCreator( + final String pathCredentialListSid, + final String username, + final String password + ) { this.pathCredentialListSid = pathCredentialListSid; this.username = username; this.password = password; } - /** - * Construct a new CredentialCreator. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @param username The username for this credential. - * @param password The password will not be returned in the response. - */ - public CredentialCreator(final String pathAccountSid, - final String pathCredentialListSid, - final String username, - final String password) { + public CredentialCreator( + final String pathAccountSid, + final String pathCredentialListSid, + final String username, + final String password + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; this.username = username; this.password = password; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public CredentialCreator setUsername(final String username) { + this.username = username; + return this; + } + + public CredentialCreator setPassword(final String password) { + this.password = password; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists/" + this.pathCredentialListSid + "/Credentials.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (username != null) { - request.addPostParam("Username", username); + Serializer.toString( + request, + "Username", + username, + ParameterType.URLENCODED + ); } if (password != null) { - request.addPostParam("Password", password); + Serializer.toString( + request, + "Password", + password, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialDeleter.java index e0f46cd9e6..fbc64314ff 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.credentiallist; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,105 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class CredentialDeleter extends Deleter { + private String pathAccountSid; - private final String pathCredentialListSid; - private final String pathSid; + private String pathCredentialListSid; + private String pathSid; - /** - * Construct a new CredentialDeleter. - * - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - */ - public CredentialDeleter(final String pathCredentialListSid, - final String pathSid) { + public CredentialDeleter( + final String pathCredentialListSid, + final String pathSid + ) { this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - /** - * Construct a new CredentialDeleter. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - */ - public CredentialDeleter(final String pathAccountSid, - final String pathCredentialListSid, - final String pathSid) { + public CredentialDeleter( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists/" + this.pathCredentialListSid + "/Credentials/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialFetcher.java index 4396882c8d..5abe154985 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.credentiallist; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,104 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialFetcher extends Fetcher { + private String pathAccountSid; - private final String pathCredentialListSid; - private final String pathSid; + private String pathCredentialListSid; + private String pathSid; - /** - * Construct a new CredentialFetcher. - * - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - */ - public CredentialFetcher(final String pathCredentialListSid, - final String pathSid) { + public CredentialFetcher( + final String pathCredentialListSid, + final String pathSid + ) { this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - /** - * Construct a new CredentialFetcher. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - */ - public CredentialFetcher(final String pathAccountSid, - final String pathCredentialListSid, - final String pathSid) { + public CredentialFetcher( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists/" + this.pathCredentialListSid + "/Credentials/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Credential fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialReader.java index 184e7108cd..ecc99405d6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.credentiallist; @@ -10,174 +17,214 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialReader extends Reader { + private String pathAccountSid; - private final String pathCredentialListSid; + private String pathCredentialListSid; + private Long pageSize; - /** - * Construct a new CredentialReader. - * - * @param pathCredentialListSid The credential_list_sid - */ public CredentialReader(final String pathCredentialListSid) { this.pathCredentialListSid = pathCredentialListSid; } - /** - * Construct a new CredentialReader. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - */ - public CredentialReader(final String pathAccountSid, - final String pathCredentialListSid) { + public CredentialReader( + final String pathAccountSid, + final String pathCredentialListSid + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public CredentialReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists/" + this.pathCredentialListSid + "/Credentials.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Credential Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credentials", - response.getContent(), - Credential.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialUpdater.java index 9a99688609..033c94ccd2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/credentiallist/CredentialUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.credentiallist; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,101 +27,123 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialUpdater extends Updater { + private String pathAccountSid; - private final String pathCredentialListSid; - private final String pathSid; + private String pathCredentialListSid; + private String pathSid; private String password; - /** - * Construct a new CredentialUpdater. - * - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - */ - public CredentialUpdater(final String pathCredentialListSid, - final String pathSid) { + public CredentialUpdater( + final String pathCredentialListSid, + final String pathSid + ) { this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - /** - * Construct a new CredentialUpdater. - * - * @param pathAccountSid The account_sid - * @param pathCredentialListSid The credential_list_sid - * @param pathSid The sid - */ - public CredentialUpdater(final String pathAccountSid, - final String pathCredentialListSid, - final String pathSid) { + public CredentialUpdater( + final String pathAccountSid, + final String pathCredentialListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathCredentialListSid = pathCredentialListSid; this.pathSid = pathSid; } - /** - * The password that the username will use when when authenticating SIP - * requests. The password must be a minimum of 12 characters, contain at least 1 - * digit, and have mixed case. (eg “IWasAtSignal2018”). - * - * @param password The password will not be returned in the response. - * @return this - */ public CredentialUpdater setPassword(final String password) { this.password = password; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/CredentialLists/{CredentialListSid}/Credentials/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "CredentialListSid" + "}", + this.pathCredentialListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/CredentialLists/" + this.pathCredentialListSid + "/Credentials/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (password != null) { - request.addPostParam("Password", password); + Serializer.toString( + request, + "Password", + password, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMapping.java index 1e1d3e9fde..6549ee5ce5 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMapping.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMapping.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; @@ -11,139 +18,112 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class CredentialListMapping extends Resource { - private static final long serialVersionUID = 214188792953524L; - /** - * Create a CredentialListMappingCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param credentialListSid The credential_list_sid - * @return CredentialListMappingCreator capable of executing the create - */ - public static CredentialListMappingCreator creator(final String pathAccountSid, - final String pathDomainSid, - final String credentialListSid) { - return new CredentialListMappingCreator(pathAccountSid, pathDomainSid, credentialListSid); - } - - /** - * Create a CredentialListMappingCreator to execute create. - * - * @param pathDomainSid The domain_sid - * @param credentialListSid The credential_list_sid - * @return CredentialListMappingCreator capable of executing the create - */ - public static CredentialListMappingCreator creator(final String pathDomainSid, - final String credentialListSid) { - return new CredentialListMappingCreator(pathDomainSid, credentialListSid); - } - - /** - * Create a CredentialListMappingReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @return CredentialListMappingReader capable of executing the read - */ - public static CredentialListMappingReader reader(final String pathAccountSid, - final String pathDomainSid) { - return new CredentialListMappingReader(pathAccountSid, pathDomainSid); + public static CredentialListMappingCreator creator( + final String pathDomainSid, + final String credentialListSid + ) { + return new CredentialListMappingCreator( + pathDomainSid, + credentialListSid + ); + } + + public static CredentialListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { + return new CredentialListMappingCreator( + pathAccountSid, + pathDomainSid, + credentialListSid + ); + } + + public static CredentialListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { + return new CredentialListMappingDeleter(pathDomainSid, pathSid); } - /** - * Create a CredentialListMappingReader to execute read. - * - * @param pathDomainSid The domain_sid - * @return CredentialListMappingReader capable of executing the read - */ - public static CredentialListMappingReader reader(final String pathDomainSid) { - return new CredentialListMappingReader(pathDomainSid); + public static CredentialListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new CredentialListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); } - /** - * Create a CredentialListMappingFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param pathSid The sid - * @return CredentialListMappingFetcher capable of executing the fetch - */ - public static CredentialListMappingFetcher fetcher(final String pathAccountSid, - final String pathDomainSid, - final String pathSid) { - return new CredentialListMappingFetcher(pathAccountSid, pathDomainSid, pathSid); + public static CredentialListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { + return new CredentialListMappingFetcher(pathDomainSid, pathSid); } - /** - * Create a CredentialListMappingFetcher to execute fetch. - * - * @param pathDomainSid The domain_sid - * @param pathSid The sid - * @return CredentialListMappingFetcher capable of executing the fetch - */ - public static CredentialListMappingFetcher fetcher(final String pathDomainSid, - final String pathSid) { - return new CredentialListMappingFetcher(pathDomainSid, pathSid); + public static CredentialListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new CredentialListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); } - /** - * Create a CredentialListMappingDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param pathSid The sid - * @return CredentialListMappingDeleter capable of executing the delete - */ - public static CredentialListMappingDeleter deleter(final String pathAccountSid, - final String pathDomainSid, - final String pathSid) { - return new CredentialListMappingDeleter(pathAccountSid, pathDomainSid, pathSid); + public static CredentialListMappingReader reader( + final String pathDomainSid + ) { + return new CredentialListMappingReader(pathDomainSid); } - /** - * Create a CredentialListMappingDeleter to execute delete. - * - * @param pathDomainSid The domain_sid - * @param pathSid The sid - * @return CredentialListMappingDeleter capable of executing the delete - */ - public static CredentialListMappingDeleter deleter(final String pathDomainSid, - final String pathSid) { - return new CredentialListMappingDeleter(pathDomainSid, pathSid); + public static CredentialListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new CredentialListMappingReader(pathAccountSid, pathDomainSid); } /** - * Converts a JSON String into a CredentialListMapping object using the provided - * ObjectMapper. - * + * Converts a JSON String into a CredentialListMapping object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return CredentialListMapping object represented by the provided JSON */ - public static CredentialListMapping fromJson(final String json, final ObjectMapper objectMapper) { + public static CredentialListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialListMapping.class); @@ -155,14 +135,17 @@ public static CredentialListMapping fromJson(final String json, final ObjectMapp } /** - * Converts a JSON InputStream into a CredentialListMapping object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a CredentialListMapping object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return CredentialListMapping object represented by the provided JSON */ - public static CredentialListMapping fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static CredentialListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialListMapping.class); @@ -173,105 +156,60 @@ public static CredentialListMapping fromJson(final InputStream json, final Objec } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String domainSid; + + @Getter private final String friendlyName; + + @Getter private final String sid; + + @Getter private final String uri; - private final Map subresourceUris; @JsonCreator - private CredentialListMapping(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("sid") - final String sid, - @JsonProperty("uri") - final String uri, - @JsonProperty("subresource_uris") - final Map subresourceUris) { + private CredentialListMapping( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.domainSid = domainSid; this.friendlyName = friendlyName; this.sid = sid; this.uri = uri; - this.subresourceUris = subresourceUris; - } - - /** - * Returns The The unique id of the Account that responsible for this resource.. - * - * @return The unique id of the Account that responsible for this resource. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created, given as GMT in RFC 2822 - * format.. - * - * @return The date that this resource was created, given as GMT in RFC 2822 - * format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated, given as GMT in RFC - * 2822 format.. - * - * @return The date that this resource was last updated, given as GMT in RFC - * 2822 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human readable descriptive text for this resource, up to 64 - * characters long.. - * - * @return A human readable descriptive text for this resource, up to 64 - * characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The URI for this resource, relative to https://api.twilio.com. - * - * @return The URI for this resource, relative to https://api.twilio.com - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; } @Override @@ -285,37 +223,27 @@ public boolean equals(final Object o) { } CredentialListMapping other = (CredentialListMapping) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(sid, other.sid) && - Objects.equals(uri, other.uri) && - Objects.equals(subresourceUris, other.subresourceUris); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - friendlyName, - sid, - uri, - subresourceUris); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("sid", sid) - .add("uri", uri) - .add("subresourceUris", subresourceUris) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + domainSid, + friendlyName, + sid, + uri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingCreator.java index 1c9346f59e..0ee052db83 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,87 +27,124 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CredentialListMappingCreator + extends Creator { -public class CredentialListMappingCreator extends Creator { private String pathAccountSid; - private final String pathDomainSid; - private final String credentialListSid; + private String pathDomainSid; + private String credentialListSid; - /** - * Construct a new CredentialListMappingCreator. - * - * @param pathDomainSid The domain_sid - * @param credentialListSid The credential_list_sid - */ - public CredentialListMappingCreator(final String pathDomainSid, - final String credentialListSid) { + public CredentialListMappingCreator( + final String pathDomainSid, + final String credentialListSid + ) { this.pathDomainSid = pathDomainSid; this.credentialListSid = credentialListSid; } - /** - * Construct a new CredentialListMappingCreator. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param credentialListSid The credential_list_sid - */ - public CredentialListMappingCreator(final String pathAccountSid, - final String pathDomainSid, - final String credentialListSid) { + public CredentialListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.credentialListSid = credentialListSid; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created CredentialListMapping - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public CredentialListMapping create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public CredentialListMappingCreator setCredentialListSid( + final String credentialListSid + ) { + this.credentialListSid = credentialListSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathDomainSid + "/CredentialListMappings.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialListMapping creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialListMapping creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return CredentialListMapping.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public CredentialListMapping create(final TwilioRestClient client) { + Response response = makeRequest(client); + return CredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CredentialListMapping content = CredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (credentialListSid != null) { - request.addPostParam("CredentialListSid", credentialListSid); + Serializer.toString( + request, + "CredentialListSid", + credentialListSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingDeleter.java index 9378a1ea1a..b790909a80 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,106 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class CredentialListMappingDeleter + extends Deleter { -public class CredentialListMappingDeleter extends Deleter { private String pathAccountSid; - private final String pathDomainSid; - private final String pathSid; + private String pathDomainSid; + private String pathSid; - /** - * Construct a new CredentialListMappingDeleter. - * - * @param pathDomainSid The domain_sid - * @param pathSid The sid - */ - public CredentialListMappingDeleter(final String pathDomainSid, - final String pathSid) { + public CredentialListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - /** - * Construct a new CredentialListMappingDeleter. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param pathSid The sid - */ - public CredentialListMappingDeleter(final String pathAccountSid, - final String pathDomainSid, - final String pathSid) { + public CredentialListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathDomainSid + "/CredentialListMappings/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialListMapping delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialListMapping delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingFetcher.java index 9648e5fb27..dbaaf82b6a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,105 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CredentialListMappingFetcher + extends Fetcher { -public class CredentialListMappingFetcher extends Fetcher { private String pathAccountSid; - private final String pathDomainSid; - private final String pathSid; + private String pathDomainSid; + private String pathSid; - /** - * Construct a new CredentialListMappingFetcher. - * - * @param pathDomainSid The domain_sid - * @param pathSid The sid - */ - public CredentialListMappingFetcher(final String pathDomainSid, - final String pathSid) { + public CredentialListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - /** - * Construct a new CredentialListMappingFetcher. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param pathSid The sid - */ - public CredentialListMappingFetcher(final String pathAccountSid, - final String pathDomainSid, - final String pathSid) { + public CredentialListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched CredentialListMapping - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public CredentialListMapping fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathDomainSid + "/CredentialListMappings/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialListMapping fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialListMapping fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public CredentialListMapping fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return CredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return CredentialListMapping.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CredentialListMapping content = CredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingReader.java index 83122caaf0..82f52e0a04 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/CredentialListMappingReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; @@ -10,174 +17,218 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialListMappingReader extends Reader { + private String pathAccountSid; - private final String pathDomainSid; + private String pathDomainSid; + private Long pageSize; - /** - * Construct a new CredentialListMappingReader. - * - * @param pathDomainSid The domain_sid - */ public CredentialListMappingReader(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - /** - * Construct a new CredentialListMappingReader. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - */ - public CredentialListMappingReader(final String pathAccountSid, - final String pathDomainSid) { + public CredentialListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return CredentialListMapping ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public CredentialListMappingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return CredentialListMapping ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credential_list_mappings", + response.getContent(), + CredentialListMapping.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/CredentialListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathDomainSid + "/CredentialListMappings.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return CredentialListMapping ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credential_list_mappings", + response.getContent(), + CredentialListMapping.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CredentialListMapping read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credential_list_mappings", + response.getContent(), + CredentialListMapping.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of CredentialListMapping Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("CredentialListMapping read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credential_list_mappings", - response.getContent(), - CredentialListMapping.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMapping.java index 11038efe5c..72c6fe4287 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMapping.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMapping.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; @@ -11,142 +18,121 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class IpAccessControlListMapping extends Resource { - private static final long serialVersionUID = 214188792953524L; - /** - * Create a IpAccessControlListMappingFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param pathSid The sid - * @return IpAccessControlListMappingFetcher capable of executing the fetch - */ - public static IpAccessControlListMappingFetcher fetcher(final String pathAccountSid, - final String pathDomainSid, - final String pathSid) { - return new IpAccessControlListMappingFetcher(pathAccountSid, pathDomainSid, pathSid); + public static IpAccessControlListMappingCreator creator( + final String pathDomainSid, + final String ipAccessControlListSid + ) { + return new IpAccessControlListMappingCreator( + pathDomainSid, + ipAccessControlListSid + ); } - /** - * Create a IpAccessControlListMappingFetcher to execute fetch. - * - * @param pathDomainSid The domain_sid - * @param pathSid The sid - * @return IpAccessControlListMappingFetcher capable of executing the fetch - */ - public static IpAccessControlListMappingFetcher fetcher(final String pathDomainSid, - final String pathSid) { - return new IpAccessControlListMappingFetcher(pathDomainSid, pathSid); + public static IpAccessControlListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String ipAccessControlListSid + ) { + return new IpAccessControlListMappingCreator( + pathAccountSid, + pathDomainSid, + ipAccessControlListSid + ); } - /** - * Create a IpAccessControlListMappingCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param ipAccessControlListSid The ip_access_control_list_sid - * @return IpAccessControlListMappingCreator capable of executing the create - */ - public static IpAccessControlListMappingCreator creator(final String pathAccountSid, - final String pathDomainSid, - final String ipAccessControlListSid) { - return new IpAccessControlListMappingCreator(pathAccountSid, pathDomainSid, ipAccessControlListSid); + public static IpAccessControlListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { + return new IpAccessControlListMappingDeleter(pathDomainSid, pathSid); } - /** - * Create a IpAccessControlListMappingCreator to execute create. - * - * @param pathDomainSid The domain_sid - * @param ipAccessControlListSid The ip_access_control_list_sid - * @return IpAccessControlListMappingCreator capable of executing the create - */ - public static IpAccessControlListMappingCreator creator(final String pathDomainSid, - final String ipAccessControlListSid) { - return new IpAccessControlListMappingCreator(pathDomainSid, ipAccessControlListSid); + public static IpAccessControlListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new IpAccessControlListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); } - /** - * Create a IpAccessControlListMappingReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @return IpAccessControlListMappingReader capable of executing the read - */ - public static IpAccessControlListMappingReader reader(final String pathAccountSid, - final String pathDomainSid) { - return new IpAccessControlListMappingReader(pathAccountSid, pathDomainSid); + public static IpAccessControlListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { + return new IpAccessControlListMappingFetcher(pathDomainSid, pathSid); } - /** - * Create a IpAccessControlListMappingReader to execute read. - * - * @param pathDomainSid The domain_sid - * @return IpAccessControlListMappingReader capable of executing the read - */ - public static IpAccessControlListMappingReader reader(final String pathDomainSid) { - return new IpAccessControlListMappingReader(pathDomainSid); + public static IpAccessControlListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new IpAccessControlListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); } - /** - * Create a IpAccessControlListMappingDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param pathSid The sid - * @return IpAccessControlListMappingDeleter capable of executing the delete - */ - public static IpAccessControlListMappingDeleter deleter(final String pathAccountSid, - final String pathDomainSid, - final String pathSid) { - return new IpAccessControlListMappingDeleter(pathAccountSid, pathDomainSid, pathSid); + public static IpAccessControlListMappingReader reader( + final String pathDomainSid + ) { + return new IpAccessControlListMappingReader(pathDomainSid); } - /** - * Create a IpAccessControlListMappingDeleter to execute delete. - * - * @param pathDomainSid The domain_sid - * @param pathSid The sid - * @return IpAccessControlListMappingDeleter capable of executing the delete - */ - public static IpAccessControlListMappingDeleter deleter(final String pathDomainSid, - final String pathSid) { - return new IpAccessControlListMappingDeleter(pathDomainSid, pathSid); + public static IpAccessControlListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new IpAccessControlListMappingReader( + pathAccountSid, + pathDomainSid + ); } /** - * Converts a JSON String into a IpAccessControlListMapping object using the - * provided ObjectMapper. - * + * Converts a JSON String into a IpAccessControlListMapping object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return IpAccessControlListMapping object represented by the provided JSON */ - public static IpAccessControlListMapping fromJson(final String json, final ObjectMapper objectMapper) { + public static IpAccessControlListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, IpAccessControlListMapping.class); + return objectMapper.readValue( + json, + IpAccessControlListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -155,17 +141,23 @@ public static IpAccessControlListMapping fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a IpAccessControlListMapping object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a IpAccessControlListMapping object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return IpAccessControlListMapping object represented by the provided JSON */ - public static IpAccessControlListMapping fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static IpAccessControlListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, IpAccessControlListMapping.class); + return objectMapper.readValue( + json, + IpAccessControlListMapping.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -173,105 +165,60 @@ public static IpAccessControlListMapping fromJson(final InputStream json, final } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String domainSid; + + @Getter private final String friendlyName; + + @Getter private final String sid; + + @Getter private final String uri; - private final Map subresourceUris; @JsonCreator - private IpAccessControlListMapping(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("sid") - final String sid, - @JsonProperty("uri") - final String uri, - @JsonProperty("subresource_uris") - final Map subresourceUris) { + private IpAccessControlListMapping( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.domainSid = domainSid; this.friendlyName = friendlyName; this.sid = sid; this.uri = uri; - this.subresourceUris = subresourceUris; - } - - /** - * Returns The The unique id of the Account that responsible for this resource.. - * - * @return The unique id of the Account that responsible for this resource. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created, given as GMT in RFC 2822 - * format.. - * - * @return The date that this resource was created, given as GMT in RFC 2822 - * format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated, given as GMT in RFC - * 2822 format.. - * - * @return The date that this resource was last updated, given as GMT in RFC - * 2822 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A human readable descriptive text for this resource, up to 64 - * characters long.. - * - * @return A human readable descriptive text for this resource, up to 64 - * characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The URI for this resource, relative to https://api.twilio.com. - * - * @return The URI for this resource, relative to https://api.twilio.com - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The subresource_uris. - * - * @return The subresource_uris - */ - public final Map getSubresourceUris() { - return this.subresourceUris; } @Override @@ -285,37 +232,27 @@ public boolean equals(final Object o) { } IpAccessControlListMapping other = (IpAccessControlListMapping) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(sid, other.sid) && - Objects.equals(uri, other.uri) && - Objects.equals(subresourceUris, other.subresourceUris); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - friendlyName, - sid, - uri, - subresourceUris); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("sid", sid) - .add("uri", uri) - .add("subresourceUris", subresourceUris) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + domainSid, + friendlyName, + sid, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingCreator.java index 0ab2c5d7f6..0c4b52bf24 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,87 +27,125 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IpAccessControlListMappingCreator + extends Creator { -public class IpAccessControlListMappingCreator extends Creator { private String pathAccountSid; - private final String pathDomainSid; - private final String ipAccessControlListSid; + private String pathDomainSid; + private String ipAccessControlListSid; - /** - * Construct a new IpAccessControlListMappingCreator. - * - * @param pathDomainSid The domain_sid - * @param ipAccessControlListSid The ip_access_control_list_sid - */ - public IpAccessControlListMappingCreator(final String pathDomainSid, - final String ipAccessControlListSid) { + public IpAccessControlListMappingCreator( + final String pathDomainSid, + final String ipAccessControlListSid + ) { this.pathDomainSid = pathDomainSid; this.ipAccessControlListSid = ipAccessControlListSid; } - /** - * Construct a new IpAccessControlListMappingCreator. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param ipAccessControlListSid The ip_access_control_list_sid - */ - public IpAccessControlListMappingCreator(final String pathAccountSid, - final String pathDomainSid, - final String ipAccessControlListSid) { + public IpAccessControlListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String ipAccessControlListSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.ipAccessControlListSid = ipAccessControlListSid; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created IpAccessControlListMapping - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAccessControlListMapping create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public IpAccessControlListMappingCreator setIpAccessControlListSid( + final String ipAccessControlListSid + ) { + this.ipAccessControlListSid = ipAccessControlListSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathDomainSid + "/IpAccessControlListMappings.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlListMapping creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlListMapping creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return IpAccessControlListMapping.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public IpAccessControlListMapping create(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAccessControlListMapping content = + IpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (ipAccessControlListSid != null) { - request.addPostParam("IpAccessControlListSid", ipAccessControlListSid); + Serializer.toString( + request, + "IpAccessControlListSid", + ipAccessControlListSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingDeleter.java index 7a2b90a8a3..e241fd6630 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,106 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class IpAccessControlListMappingDeleter + extends Deleter { -public class IpAccessControlListMappingDeleter extends Deleter { private String pathAccountSid; - private final String pathDomainSid; - private final String pathSid; + private String pathDomainSid; + private String pathSid; - /** - * Construct a new IpAccessControlListMappingDeleter. - * - * @param pathDomainSid The domain_sid - * @param pathSid The sid - */ - public IpAccessControlListMappingDeleter(final String pathDomainSid, - final String pathSid) { + public IpAccessControlListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - /** - * Construct a new IpAccessControlListMappingDeleter. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param pathSid The sid - */ - public IpAccessControlListMappingDeleter(final String pathAccountSid, - final String pathDomainSid, - final String pathSid) { + public IpAccessControlListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathDomainSid + "/IpAccessControlListMappings/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlListMapping delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlListMapping delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingFetcher.java index 648321f314..7dd683392a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,106 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IpAccessControlListMappingFetcher + extends Fetcher { -public class IpAccessControlListMappingFetcher extends Fetcher { private String pathAccountSid; - private final String pathDomainSid; - private final String pathSid; + private String pathDomainSid; + private String pathSid; - /** - * Construct a new IpAccessControlListMappingFetcher. - * - * @param pathDomainSid The domain_sid - * @param pathSid The sid - */ - public IpAccessControlListMappingFetcher(final String pathDomainSid, - final String pathSid) { + public IpAccessControlListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - /** - * Construct a new IpAccessControlListMappingFetcher. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - * @param pathSid The sid - */ - public IpAccessControlListMappingFetcher(final String pathAccountSid, - final String pathDomainSid, - final String pathSid) { + public IpAccessControlListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched IpAccessControlListMapping - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAccessControlListMapping fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathDomainSid + "/IpAccessControlListMappings/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlListMapping fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlListMapping fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public IpAccessControlListMapping fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return IpAccessControlListMapping.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAccessControlListMapping content = + IpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingReader.java index c6220df2a6..101a11cdf3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/IpAccessControlListMappingReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.domain; @@ -10,174 +17,219 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IpAccessControlListMappingReader + extends Reader { -public class IpAccessControlListMappingReader extends Reader { private String pathAccountSid; - private final String pathDomainSid; + private String pathDomainSid; + private Long pageSize; - /** - * Construct a new IpAccessControlListMappingReader. - * - * @param pathDomainSid The domain_sid - */ public IpAccessControlListMappingReader(final String pathDomainSid) { this.pathDomainSid = pathDomainSid; } - /** - * Construct a new IpAccessControlListMappingReader. - * - * @param pathAccountSid The account_sid - * @param pathDomainSid The domain_sid - */ - public IpAccessControlListMappingReader(final String pathAccountSid, - final String pathDomainSid) { + public IpAccessControlListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { this.pathAccountSid = pathAccountSid; this.pathDomainSid = pathDomainSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlListMapping ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public IpAccessControlListMappingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlListMapping ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_access_control_list_mappings", + response.getContent(), + IpAccessControlListMapping.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/IpAccessControlListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/Domains/" + this.pathDomainSid + "/IpAccessControlListMappings.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlListMapping ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_access_control_list_mappings", + response.getContent(), + IpAccessControlListMapping.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "IpAccessControlListMapping read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "ip_access_control_list_mappings", + response.getContent(), + IpAccessControlListMapping.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of IpAccessControlListMapping Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("IpAccessControlListMapping read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "ip_access_control_list_mappings", - response.getContent(), - IpAccessControlListMapping.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMapping.java new file mode 100644 index 0000000000..8856bf346d --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMapping.java @@ -0,0 +1,251 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AuthCallsCredentialListMapping extends Resource { + + public static AuthCallsCredentialListMappingCreator creator( + final String pathDomainSid, + final String credentialListSid + ) { + return new AuthCallsCredentialListMappingCreator( + pathDomainSid, + credentialListSid + ); + } + + public static AuthCallsCredentialListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { + return new AuthCallsCredentialListMappingCreator( + pathAccountSid, + pathDomainSid, + credentialListSid + ); + } + + public static AuthCallsCredentialListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsCredentialListMappingDeleter( + pathDomainSid, + pathSid + ); + } + + public static AuthCallsCredentialListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsCredentialListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); + } + + public static AuthCallsCredentialListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsCredentialListMappingFetcher( + pathDomainSid, + pathSid + ); + } + + public static AuthCallsCredentialListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsCredentialListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); + } + + public static AuthCallsCredentialListMappingReader reader( + final String pathDomainSid + ) { + return new AuthCallsCredentialListMappingReader(pathDomainSid); + } + + public static AuthCallsCredentialListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new AuthCallsCredentialListMappingReader( + pathAccountSid, + pathDomainSid + ); + } + + /** + * Converts a JSON String into a AuthCallsCredentialListMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthCallsCredentialListMapping object represented by the provided JSON + */ + public static AuthCallsCredentialListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + AuthCallsCredentialListMapping.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AuthCallsCredentialListMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthCallsCredentialListMapping object represented by the provided JSON + */ + public static AuthCallsCredentialListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + AuthCallsCredentialListMapping.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @JsonCreator + private AuthCallsCredentialListMapping( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AuthCallsCredentialListMapping other = + (AuthCallsCredentialListMapping) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingCreator.java new file mode 100644 index 0000000000..a822617595 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingCreator.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthCallsCredentialListMappingCreator + extends Creator { + + private String pathAccountSid; + private String pathDomainSid; + private String credentialListSid; + + public AuthCallsCredentialListMappingCreator( + final String pathDomainSid, + final String credentialListSid + ) { + this.pathDomainSid = pathDomainSid; + this.credentialListSid = credentialListSid; + } + + public AuthCallsCredentialListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.credentialListSid = credentialListSid; + } + + public AuthCallsCredentialListMappingCreator setCredentialListSid( + final String credentialListSid + ) { + this.credentialListSid = credentialListSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthCallsCredentialListMapping creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthCallsCredentialListMapping create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return AuthCallsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthCallsCredentialListMapping content = + AuthCallsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (credentialListSid != null) { + Serializer.toString( + request, + "CredentialListSid", + credentialListSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingDeleter.java new file mode 100644 index 0000000000..863aeb0152 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingDeleter.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class AuthCallsCredentialListMappingDeleter + extends Deleter { + + private String pathAccountSid; + private String pathDomainSid; + private String pathSid; + + public AuthCallsCredentialListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + public AuthCallsCredentialListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthCallsCredentialListMapping delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingFetcher.java new file mode 100644 index 0000000000..9708045173 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingFetcher.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthCallsCredentialListMappingFetcher + extends Fetcher { + + private String pathAccountSid; + private String pathDomainSid; + private String pathSid; + + public AuthCallsCredentialListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + public AuthCallsCredentialListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthCallsCredentialListMapping fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthCallsCredentialListMapping fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AuthCallsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthCallsCredentialListMapping content = + AuthCallsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingReader.java new file mode 100644 index 0000000000..1a0cdeb623 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsCredentialListMappingReader.java @@ -0,0 +1,234 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthCallsCredentialListMappingReader + extends Reader { + + private String pathAccountSid; + private String pathDomainSid; + private Long pageSize; + + public AuthCallsCredentialListMappingReader(final String pathDomainSid) { + this.pathDomainSid = pathDomainSid; + } + + public AuthCallsCredentialListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + } + + public AuthCallsCredentialListMappingReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + AuthCallsCredentialListMapping.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/CredentialListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + AuthCallsCredentialListMapping.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AuthCallsCredentialListMapping read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "contents", + response.getContent(), + AuthCallsCredentialListMapping.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMapping.java new file mode 100644 index 0000000000..ce11b42b98 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMapping.java @@ -0,0 +1,251 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AuthCallsIpAccessControlListMapping extends Resource { + + public static AuthCallsIpAccessControlListMappingCreator creator( + final String pathDomainSid, + final String ipAccessControlListSid + ) { + return new AuthCallsIpAccessControlListMappingCreator( + pathDomainSid, + ipAccessControlListSid + ); + } + + public static AuthCallsIpAccessControlListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String ipAccessControlListSid + ) { + return new AuthCallsIpAccessControlListMappingCreator( + pathAccountSid, + pathDomainSid, + ipAccessControlListSid + ); + } + + public static AuthCallsIpAccessControlListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsIpAccessControlListMappingDeleter( + pathDomainSid, + pathSid + ); + } + + public static AuthCallsIpAccessControlListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsIpAccessControlListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); + } + + public static AuthCallsIpAccessControlListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsIpAccessControlListMappingFetcher( + pathDomainSid, + pathSid + ); + } + + public static AuthCallsIpAccessControlListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthCallsIpAccessControlListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); + } + + public static AuthCallsIpAccessControlListMappingReader reader( + final String pathDomainSid + ) { + return new AuthCallsIpAccessControlListMappingReader(pathDomainSid); + } + + public static AuthCallsIpAccessControlListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new AuthCallsIpAccessControlListMappingReader( + pathAccountSid, + pathDomainSid + ); + } + + /** + * Converts a JSON String into a AuthCallsIpAccessControlListMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthCallsIpAccessControlListMapping object represented by the provided JSON + */ + public static AuthCallsIpAccessControlListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + AuthCallsIpAccessControlListMapping.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AuthCallsIpAccessControlListMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthCallsIpAccessControlListMapping object represented by the provided JSON + */ + public static AuthCallsIpAccessControlListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + AuthCallsIpAccessControlListMapping.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @JsonCreator + private AuthCallsIpAccessControlListMapping( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AuthCallsIpAccessControlListMapping other = + (AuthCallsIpAccessControlListMapping) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingCreator.java new file mode 100644 index 0000000000..e1f4905400 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingCreator.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthCallsIpAccessControlListMappingCreator + extends Creator { + + private String pathAccountSid; + private String pathDomainSid; + private String ipAccessControlListSid; + + public AuthCallsIpAccessControlListMappingCreator( + final String pathDomainSid, + final String ipAccessControlListSid + ) { + this.pathDomainSid = pathDomainSid; + this.ipAccessControlListSid = ipAccessControlListSid; + } + + public AuthCallsIpAccessControlListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String ipAccessControlListSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.ipAccessControlListSid = ipAccessControlListSid; + } + + public AuthCallsIpAccessControlListMappingCreator setIpAccessControlListSid( + final String ipAccessControlListSid + ) { + this.ipAccessControlListSid = ipAccessControlListSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthCallsIpAccessControlListMapping creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthCallsIpAccessControlListMapping create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return AuthCallsIpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + AuthCallsIpAccessControlListMapping + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + AuthCallsIpAccessControlListMapping content = + AuthCallsIpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (ipAccessControlListSid != null) { + Serializer.toString( + request, + "IpAccessControlListSid", + ipAccessControlListSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingDeleter.java new file mode 100644 index 0000000000..6a6faff18f --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingDeleter.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class AuthCallsIpAccessControlListMappingDeleter + extends Deleter { + + private String pathAccountSid; + private String pathDomainSid; + private String pathSid; + + public AuthCallsIpAccessControlListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + public AuthCallsIpAccessControlListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthCallsIpAccessControlListMapping delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingFetcher.java new file mode 100644 index 0000000000..0668fa7f26 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingFetcher.java @@ -0,0 +1,131 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthCallsIpAccessControlListMappingFetcher + extends Fetcher { + + private String pathAccountSid; + private String pathDomainSid; + private String pathSid; + + public AuthCallsIpAccessControlListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + public AuthCallsIpAccessControlListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthCallsIpAccessControlListMapping fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthCallsIpAccessControlListMapping fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return AuthCallsIpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + AuthCallsIpAccessControlListMapping + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + AuthCallsIpAccessControlListMapping content = + AuthCallsIpAccessControlListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingReader.java new file mode 100644 index 0000000000..bf459c2839 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtypecalls/AuthCallsIpAccessControlListMappingReader.java @@ -0,0 +1,236 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtypecalls; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthCallsIpAccessControlListMappingReader + extends Reader { + + private String pathAccountSid; + private String pathDomainSid; + private Long pageSize; + + public AuthCallsIpAccessControlListMappingReader( + final String pathDomainSid + ) { + this.pathDomainSid = pathDomainSid; + } + + public AuthCallsIpAccessControlListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + } + + public AuthCallsIpAccessControlListMappingReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse< + AuthCallsIpAccessControlListMapping + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + AuthCallsIpAccessControlListMapping.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Calls/IpAccessControlListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + AuthCallsIpAccessControlListMapping.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AuthCallsIpAccessControlListMapping read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "contents", + response.getContent(), + AuthCallsIpAccessControlListMapping.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMapping.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMapping.java new file mode 100644 index 0000000000..c07fd6ce7a --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMapping.java @@ -0,0 +1,251 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtyperegistrations; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AuthRegistrationsCredentialListMapping extends Resource { + + public static AuthRegistrationsCredentialListMappingCreator creator( + final String pathDomainSid, + final String credentialListSid + ) { + return new AuthRegistrationsCredentialListMappingCreator( + pathDomainSid, + credentialListSid + ); + } + + public static AuthRegistrationsCredentialListMappingCreator creator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { + return new AuthRegistrationsCredentialListMappingCreator( + pathAccountSid, + pathDomainSid, + credentialListSid + ); + } + + public static AuthRegistrationsCredentialListMappingDeleter deleter( + final String pathDomainSid, + final String pathSid + ) { + return new AuthRegistrationsCredentialListMappingDeleter( + pathDomainSid, + pathSid + ); + } + + public static AuthRegistrationsCredentialListMappingDeleter deleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthRegistrationsCredentialListMappingDeleter( + pathAccountSid, + pathDomainSid, + pathSid + ); + } + + public static AuthRegistrationsCredentialListMappingFetcher fetcher( + final String pathDomainSid, + final String pathSid + ) { + return new AuthRegistrationsCredentialListMappingFetcher( + pathDomainSid, + pathSid + ); + } + + public static AuthRegistrationsCredentialListMappingFetcher fetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + return new AuthRegistrationsCredentialListMappingFetcher( + pathAccountSid, + pathDomainSid, + pathSid + ); + } + + public static AuthRegistrationsCredentialListMappingReader reader( + final String pathDomainSid + ) { + return new AuthRegistrationsCredentialListMappingReader(pathDomainSid); + } + + public static AuthRegistrationsCredentialListMappingReader reader( + final String pathAccountSid, + final String pathDomainSid + ) { + return new AuthRegistrationsCredentialListMappingReader( + pathAccountSid, + pathDomainSid + ); + } + + /** + * Converts a JSON String into a AuthRegistrationsCredentialListMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthRegistrationsCredentialListMapping object represented by the provided JSON + */ + public static AuthRegistrationsCredentialListMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + AuthRegistrationsCredentialListMapping.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AuthRegistrationsCredentialListMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthRegistrationsCredentialListMapping object represented by the provided JSON + */ + public static AuthRegistrationsCredentialListMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + AuthRegistrationsCredentialListMapping.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @JsonCreator + private AuthRegistrationsCredentialListMapping( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AuthRegistrationsCredentialListMapping other = + (AuthRegistrationsCredentialListMapping) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingCreator.java new file mode 100644 index 0000000000..223ff1001f --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingCreator.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtyperegistrations; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthRegistrationsCredentialListMappingCreator + extends Creator { + + private String pathAccountSid; + private String pathDomainSid; + private String credentialListSid; + + public AuthRegistrationsCredentialListMappingCreator( + final String pathDomainSid, + final String credentialListSid + ) { + this.pathDomainSid = pathDomainSid; + this.credentialListSid = credentialListSid; + } + + public AuthRegistrationsCredentialListMappingCreator( + final String pathAccountSid, + final String pathDomainSid, + final String credentialListSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.credentialListSid = credentialListSid; + } + + public AuthRegistrationsCredentialListMappingCreator setCredentialListSid( + final String credentialListSid + ) { + this.credentialListSid = credentialListSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.API.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthRegistrationsCredentialListMapping creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthRegistrationsCredentialListMapping create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return AuthRegistrationsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + AuthRegistrationsCredentialListMapping + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + AuthRegistrationsCredentialListMapping content = + AuthRegistrationsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (credentialListSid != null) { + Serializer.toString( + request, + "CredentialListSid", + credentialListSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingDeleter.java new file mode 100644 index 0000000000..14aa5fa85d --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingDeleter.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtyperegistrations; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class AuthRegistrationsCredentialListMappingDeleter + extends Deleter { + + private String pathAccountSid; + private String pathDomainSid; + private String pathSid; + + public AuthRegistrationsCredentialListMappingDeleter( + final String pathDomainSid, + final String pathSid + ) { + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + public AuthRegistrationsCredentialListMappingDeleter( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthRegistrationsCredentialListMapping delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingFetcher.java new file mode 100644 index 0000000000..4332736d89 --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingFetcher.java @@ -0,0 +1,131 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtyperegistrations; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthRegistrationsCredentialListMappingFetcher + extends Fetcher { + + private String pathAccountSid; + private String pathDomainSid; + private String pathSid; + + public AuthRegistrationsCredentialListMappingFetcher( + final String pathDomainSid, + final String pathSid + ) { + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + public AuthRegistrationsCredentialListMappingFetcher( + final String pathAccountSid, + final String pathDomainSid, + final String pathSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthRegistrationsCredentialListMapping fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthRegistrationsCredentialListMapping fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return AuthRegistrationsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + AuthRegistrationsCredentialListMapping + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + AuthRegistrationsCredentialListMapping content = + AuthRegistrationsCredentialListMapping.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingReader.java new file mode 100644 index 0000000000..56acf4243a --- /dev/null +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/domain/authtypes/authtyperegistrations/AuthRegistrationsCredentialListMappingReader.java @@ -0,0 +1,236 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.api.v2010.account.sip.domain.authtypes.authtyperegistrations; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthRegistrationsCredentialListMappingReader + extends Reader { + + private String pathAccountSid; + private String pathDomainSid; + private Long pageSize; + + public AuthRegistrationsCredentialListMappingReader( + final String pathDomainSid + ) { + this.pathDomainSid = pathDomainSid; + } + + public AuthRegistrationsCredentialListMappingReader( + final String pathAccountSid, + final String pathDomainSid + ) { + this.pathAccountSid = pathAccountSid; + this.pathDomainSid = pathDomainSid; + } + + public AuthRegistrationsCredentialListMappingReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse< + AuthRegistrationsCredentialListMapping + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + AuthRegistrationsCredentialListMapping.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/Domains/{DomainSid}/Auth/Registrations/CredentialListMappings.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.API.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + AuthRegistrationsCredentialListMapping.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AuthRegistrationsCredentialListMapping read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "contents", + response.getContent(), + AuthRegistrationsCredentialListMapping.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddress.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddress.java index c94c5d7fdc..158c3e3ae2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddress.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddress.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; @@ -11,169 +18,135 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class IpAddress extends Resource { - private static final long serialVersionUID = 118701358673463L; - /** - * Create a IpAddressReader to execute read. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @return IpAddressReader capable of executing the read - */ - public static IpAddressReader reader(final String pathAccountSid, - final String pathIpAccessControlListSid) { - return new IpAddressReader(pathAccountSid, pathIpAccessControlListSid); + public static IpAddressCreator creator( + final String pathIpAccessControlListSid, + final String friendlyName, + final String ipAddress + ) { + return new IpAddressCreator( + pathIpAccessControlListSid, + friendlyName, + ipAddress + ); } - /** - * Create a IpAddressReader to execute read. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @return IpAddressReader capable of executing the read - */ - public static IpAddressReader reader(final String pathIpAccessControlListSid) { - return new IpAddressReader(pathIpAccessControlListSid); + public static IpAddressCreator creator( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String friendlyName, + final String ipAddress + ) { + return new IpAddressCreator( + pathAccountSid, + pathIpAccessControlListSid, + friendlyName, + ipAddress + ); } - /** - * Create a IpAddressCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param friendlyName The friendly_name - * @param ipAddress The ip_address - * @return IpAddressCreator capable of executing the create - */ - public static IpAddressCreator creator(final String pathAccountSid, - final String pathIpAccessControlListSid, - final String friendlyName, - final String ipAddress) { - return new IpAddressCreator(pathAccountSid, pathIpAccessControlListSid, friendlyName, ipAddress); + public static IpAddressDeleter deleter( + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressDeleter(pathIpAccessControlListSid, pathSid); } - /** - * Create a IpAddressCreator to execute create. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param friendlyName The friendly_name - * @param ipAddress The ip_address - * @return IpAddressCreator capable of executing the create - */ - public static IpAddressCreator creator(final String pathIpAccessControlListSid, - final String friendlyName, - final String ipAddress) { - return new IpAddressCreator(pathIpAccessControlListSid, friendlyName, ipAddress); + public static IpAddressDeleter deleter( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressDeleter( + pathAccountSid, + pathIpAccessControlListSid, + pathSid + ); } - /** - * Create a IpAddressFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - * @return IpAddressFetcher capable of executing the fetch - */ - public static IpAddressFetcher fetcher(final String pathAccountSid, - final String pathIpAccessControlListSid, - final String pathSid) { - return new IpAddressFetcher(pathAccountSid, pathIpAccessControlListSid, pathSid); + public static IpAddressFetcher fetcher( + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressFetcher(pathIpAccessControlListSid, pathSid); } - /** - * Create a IpAddressFetcher to execute fetch. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - * @return IpAddressFetcher capable of executing the fetch - */ - public static IpAddressFetcher fetcher(final String pathIpAccessControlListSid, - final String pathSid) { - return new IpAddressFetcher(pathIpAccessControlListSid, pathSid); + public static IpAddressFetcher fetcher( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressFetcher( + pathAccountSid, + pathIpAccessControlListSid, + pathSid + ); } - /** - * Create a IpAddressUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - * @return IpAddressUpdater capable of executing the update - */ - public static IpAddressUpdater updater(final String pathAccountSid, - final String pathIpAccessControlListSid, - final String pathSid) { - return new IpAddressUpdater(pathAccountSid, pathIpAccessControlListSid, pathSid); + public static IpAddressReader reader( + final String pathIpAccessControlListSid + ) { + return new IpAddressReader(pathIpAccessControlListSid); } - /** - * Create a IpAddressUpdater to execute update. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - * @return IpAddressUpdater capable of executing the update - */ - public static IpAddressUpdater updater(final String pathIpAccessControlListSid, - final String pathSid) { - return new IpAddressUpdater(pathIpAccessControlListSid, pathSid); + public static IpAddressReader reader( + final String pathAccountSid, + final String pathIpAccessControlListSid + ) { + return new IpAddressReader(pathAccountSid, pathIpAccessControlListSid); } - /** - * Create a IpAddressDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - * @return IpAddressDeleter capable of executing the delete - */ - public static IpAddressDeleter deleter(final String pathAccountSid, - final String pathIpAccessControlListSid, - final String pathSid) { - return new IpAddressDeleter(pathAccountSid, pathIpAccessControlListSid, pathSid); + public static IpAddressUpdater updater( + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressUpdater(pathIpAccessControlListSid, pathSid); } - /** - * Create a IpAddressDeleter to execute delete. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - * @return IpAddressDeleter capable of executing the delete - */ - public static IpAddressDeleter deleter(final String pathIpAccessControlListSid, - final String pathSid) { - return new IpAddressDeleter(pathIpAccessControlListSid, pathSid); + public static IpAddressUpdater updater( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { + return new IpAddressUpdater( + pathAccountSid, + pathIpAccessControlListSid, + pathSid + ); } /** - * Converts a JSON String into a IpAddress object using the provided - * ObjectMapper. - * + * Converts a JSON String into a IpAddress object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return IpAddress object represented by the provided JSON */ - public static IpAddress fromJson(final String json, final ObjectMapper objectMapper) { + public static IpAddress fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAddress.class); @@ -187,12 +160,15 @@ public static IpAddress fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a IpAddress object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return IpAddress object represented by the provided JSON */ - public static IpAddress fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static IpAddress fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAddress.class); @@ -203,122 +179,72 @@ public static IpAddress fromJson(final InputStream json, final ObjectMapper obje } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String friendlyName; - private final String ipAddress; - private final String ipAccessControlListSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String uri; - @JsonCreator - private IpAddress(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("ip_address") - final String ipAddress, - @JsonProperty("ip_access_control_list_sid") - final String ipAccessControlListSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("uri") - final String uri) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.ipAddress = ipAddress; - this.ipAccessControlListSid = ipAccessControlListSid; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); - this.uri = uri; - } + @Getter + private final Integer cidrPrefixLength; - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Account that responsible for this resource.. - * - * @return The unique id of the Account that responsible for this resource. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A human readable descriptive text for this resource, up to 64 - * characters long.. - * - * @return A human readable descriptive text for this resource, up to 64 - * characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String friendlyName; - /** - * Returns The An IP address in dotted decimal notation from which you want to - * accept traffic. Any SIP requests from this IP address will be allowed by - * Twilio. IPv4 only supported today.. - * - * @return An IP address in dotted decimal notation from which you want to - * accept traffic. Any SIP requests from this IP address will be allowed - * by Twilio. IPv4 only supported today. - */ - public final String getIpAddress() { - return this.ipAddress; - } + @Getter + private final String ipAccessControlListSid; - /** - * Returns The The ip_access_control_list_sid. - * - * @return The ip_access_control_list_sid - */ - public final String getIpAccessControlListSid() { - return this.ipAccessControlListSid; - } + @Getter + private final String ipAddress; - /** - * Returns The The date that this resource was created, given as GMT in RFC 2822 - * format.. - * - * @return The date that this resource was created, given as GMT in RFC 2822 - * format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date that this resource was last updated, given as GMT in RFC - * 2822 format.. - * - * @return The date that this resource was last updated, given as GMT in RFC - * 2822 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String uri; - /** - * Returns The The URI for this resource, relative to https://api.twilio.com. - * - * @return The URI for this resource, relative to https://api.twilio.com - */ - public final String getUri() { - return this.uri; + @JsonCreator + private IpAddress( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cidr_prefix_length") final Integer cidrPrefixLength, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "ip_access_control_list_sid" + ) final String ipAccessControlListSid, + @JsonProperty("ip_address") final String ipAddress, + @JsonProperty("sid") final String sid, + @JsonProperty("uri") final String uri + ) { + this.accountSid = accountSid; + this.cidrPrefixLength = cidrPrefixLength; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.ipAccessControlListSid = ipAccessControlListSid; + this.ipAddress = ipAddress; + this.sid = sid; + this.uri = uri; } @Override @@ -332,40 +258,34 @@ public boolean equals(final Object o) { } IpAddress other = (IpAddress) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(ipAddress, other.ipAddress) && - Objects.equals(ipAccessControlListSid, other.ipAccessControlListSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(uri, other.uri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cidrPrefixLength, other.cidrPrefixLength) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + ipAccessControlListSid, + other.ipAccessControlListSid + ) && + Objects.equals(ipAddress, other.ipAddress) && + Objects.equals(sid, other.sid) && + Objects.equals(uri, other.uri) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - ipAddress, - ipAccessControlListSid, - dateCreated, - dateUpdated, - uri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("ipAddress", ipAddress) - .add("ipAccessControlListSid", ipAccessControlListSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("uri", uri) - .toString(); + return Objects.hash( + accountSid, + cidrPrefixLength, + dateCreated, + dateUpdated, + friendlyName, + ipAccessControlListSid, + ipAddress, + sid, + uri + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressCreator.java index e4c28188a1..7371c88ccd 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,98 +27,157 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAddressCreator extends Creator { + private String pathAccountSid; - private final String pathIpAccessControlListSid; - private final String friendlyName; - private final String ipAddress; - - /** - * Construct a new IpAddressCreator. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param friendlyName The friendly_name - * @param ipAddress The ip_address - */ - public IpAddressCreator(final String pathIpAccessControlListSid, - final String friendlyName, - final String ipAddress) { + private String pathIpAccessControlListSid; + private String friendlyName; + private String ipAddress; + private Integer cidrPrefixLength; + + public IpAddressCreator( + final String pathIpAccessControlListSid, + final String friendlyName, + final String ipAddress + ) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.friendlyName = friendlyName; this.ipAddress = ipAddress; } - /** - * Construct a new IpAddressCreator. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param friendlyName The friendly_name - * @param ipAddress The ip_address - */ - public IpAddressCreator(final String pathAccountSid, - final String pathIpAccessControlListSid, - final String friendlyName, - final String ipAddress) { + public IpAddressCreator( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String friendlyName, + final String ipAddress + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.friendlyName = friendlyName; this.ipAddress = ipAddress; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created IpAddress - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAddress create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public IpAddressCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public IpAddressCreator setIpAddress(final String ipAddress) { + this.ipAddress = ipAddress; + return this; + } + + public IpAddressCreator setCidrPrefixLength( + final Integer cidrPrefixLength + ) { + this.cidrPrefixLength = cidrPrefixLength; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists/" + this.pathIpAccessControlListSid + "/IpAddresses.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAddress creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public IpAddress create(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return IpAddress.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAddress content = IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (ipAddress != null) { - request.addPostParam("IpAddress", ipAddress); + Serializer.toString( + request, + "IpAddress", + ipAddress, + ParameterType.URLENCODED + ); + } + + if (cidrPrefixLength != null) { + Serializer.toString( + request, + "CidrPrefixLength", + cidrPrefixLength, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressDeleter.java index 45d471b480..9fe6df1ca2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +24,105 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class IpAddressDeleter extends Deleter { + private String pathAccountSid; - private final String pathIpAccessControlListSid; - private final String pathSid; + private String pathIpAccessControlListSid; + private String pathSid; - /** - * Construct a new IpAddressDeleter. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - */ - public IpAddressDeleter(final String pathIpAccessControlListSid, - final String pathSid) { + public IpAddressDeleter( + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - /** - * Construct a new IpAddressDeleter. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - */ - public IpAddressDeleter(final String pathAccountSid, - final String pathIpAccessControlListSid, - final String pathSid) { + public IpAddressDeleter( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists/" + this.pathIpAccessControlListSid + "/IpAddresses/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAddress delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressFetcher.java index dcb7c062ce..f3e60fa164 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +24,104 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAddressFetcher extends Fetcher { + private String pathAccountSid; - private final String pathIpAccessControlListSid; - private final String pathSid; + private String pathIpAccessControlListSid; + private String pathSid; - /** - * Construct a new IpAddressFetcher. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - */ - public IpAddressFetcher(final String pathIpAccessControlListSid, - final String pathSid) { + public IpAddressFetcher( + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - /** - * Construct a new IpAddressFetcher. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - */ - public IpAddressFetcher(final String pathAccountSid, - final String pathIpAccessControlListSid, - final String pathSid) { + public IpAddressFetcher( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched IpAddress - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAddress fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists/" + this.pathIpAccessControlListSid + "/IpAddresses/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAddress fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public IpAddress fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return IpAddress.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAddress content = IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressReader.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressReader.java index b863f68987..eada202e2c 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; @@ -10,174 +17,214 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAddressReader extends Reader { + private String pathAccountSid; - private final String pathIpAccessControlListSid; + private String pathIpAccessControlListSid; + private Long pageSize; - /** - * Construct a new IpAddressReader. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - */ public IpAddressReader(final String pathIpAccessControlListSid) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; } - /** - * Construct a new IpAddressReader. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - */ - public IpAddressReader(final String pathAccountSid, - final String pathIpAccessControlListSid) { + public IpAddressReader( + final String pathAccountSid, + final String pathIpAccessControlListSid + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IpAddress ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public IpAddressReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IpAddress ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_addresses", + response.getContent(), + IpAddress.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists/" + this.pathIpAccessControlListSid + "/IpAddresses.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return IpAddress ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_addresses", + response.getContent(), + IpAddress.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "IpAddress read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "ip_addresses", + response.getContent(), + IpAddress.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of IpAddress Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("IpAddress read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "ip_addresses", - response.getContent(), - IpAddress.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressUpdater.java index 8a7bdadc8c..31f521537e 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/sip/ipaccesscontrollist/IpAddressUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.sip.ipaccesscontrollist; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,115 +27,155 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAddressUpdater extends Updater { + private String pathAccountSid; - private final String pathIpAccessControlListSid; - private final String pathSid; + private String pathIpAccessControlListSid; + private String pathSid; private String ipAddress; private String friendlyName; + private Integer cidrPrefixLength; - /** - * Construct a new IpAddressUpdater. - * - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - */ - public IpAddressUpdater(final String pathIpAccessControlListSid, - final String pathSid) { + public IpAddressUpdater( + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - /** - * Construct a new IpAddressUpdater. - * - * @param pathAccountSid The account_sid - * @param pathIpAccessControlListSid The ip_access_control_list_sid - * @param pathSid The sid - */ - public IpAddressUpdater(final String pathAccountSid, - final String pathIpAccessControlListSid, - final String pathSid) { + public IpAddressUpdater( + final String pathAccountSid, + final String pathIpAccessControlListSid, + final String pathSid + ) { this.pathAccountSid = pathAccountSid; this.pathIpAccessControlListSid = pathIpAccessControlListSid; this.pathSid = pathSid; } - /** - * The ip_address. - * - * @param ipAddress The ip_address - * @return this - */ public IpAddressUpdater setIpAddress(final String ipAddress) { this.ipAddress = ipAddress; return this; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public IpAddressUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated IpAddress - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAddress update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public IpAddressUpdater setCidrPrefixLength( + final Integer cidrPrefixLength + ) { + this.cidrPrefixLength = cidrPrefixLength; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/SIP/IpAccessControlLists/{IpAccessControlListSid}/IpAddresses/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = + path.replace( + "{" + "IpAccessControlListSid" + "}", + this.pathIpAccessControlListSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/SIP/IpAccessControlLists/" + this.pathIpAccessControlListSid + "/IpAddresses/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAddress update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAddress update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return IpAddress.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public IpAddress update(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAddress content = IpAddress.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (ipAddress != null) { - request.addPostParam("IpAddress", ipAddress); + Serializer.toString( + request, + "IpAddress", + ipAddress, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (cidrPrefixLength != null) { + Serializer.toString( + request, + "CidrPrefixLength", + cidrPrefixLength, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/Record.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/Record.java index 04b3eeb3fb..47322a2b73 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/Record.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/Record.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage; @@ -11,317 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Record extends Resource { - private static final long serialVersionUID = 71406401031495L; - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static RecordReader reader() { + return new RecordReader(); } - /** - * Create a RecordReader to execute read. - * - * @param pathAccountSid The account_sid - * @return RecordReader capable of executing the read - */ public static RecordReader reader(final String pathAccountSid) { return new RecordReader(pathAccountSid); } - /** - * Create a RecordReader to execute read. - * - * @return RecordReader capable of executing the read - */ - public static RecordReader reader() { - return new RecordReader(); - } - /** * Converts a JSON String into a Record object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Record object represented by the provided JSON */ - public static Record fromJson(final String json, final ObjectMapper objectMapper) { + public static Record fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Record.class); @@ -335,12 +75,15 @@ public static Record fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Record object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Record object represented by the provided JSON */ - public static Record fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Record fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Record.class); @@ -351,193 +94,107 @@ public static Record fromJson(final InputStream json, final ObjectMapper objectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final Record.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private Record(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final Record.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private Record( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage. - * - * @return The Account that accrued the usage - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage. - * - * @return The category of usage - */ - public final Record.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events (e.g. the number of calls).. - * - * @return The number of usage events (e.g. the number of calls). - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The unit in which `Count` is measured. - * - * @return The unit in which `Count` is measured - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date usage is included in this record. - * - * @return The last date usage is included in this record - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage. - * - * @return The total price of the usage - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which `Price` is measured. - * - * @return The currency in which `Price` is measured - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date usage is included in this record. - * - * @return The first date usage is included in this record - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresources Uris for this UsageRecord. - * - * @return Subresources Uris for this UsageRecord - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of usage. - * - * @return The amount of usage - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which `Usage` is measured. - * - * @return The units in which `Usage` is measured - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -549,58 +206,43 @@ public boolean equals(final Object o) { } Record other = (Record) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/RecordReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/RecordReader.java index 45ad653bc8..5cfcb3d921 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/RecordReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/RecordReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage; @@ -10,240 +17,260 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class RecordReader extends Reader { + private String pathAccountSid; - private Record.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new RecordReader. - */ - public RecordReader() { - } + public RecordReader() {} - /** - * Construct a new RecordReader. - * - * @param pathAccountSid The account_sid - */ public RecordReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only include usage of this [usage - * category](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param category Only include usage of a given category - * @return this - */ - public RecordReader setCategory(final Record.Category category) { + public RecordReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Filter by start date - * @return this - */ public RecordReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Filter by end date - * @return this - */ public RecordReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ - public RecordReader setIncludeSubaccounts(final Boolean includeSubaccounts) { + public RecordReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Record ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public RecordReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Record ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Record.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Records.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Record ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Record.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Record read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + Record.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Record Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Record read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - Record.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/Trigger.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/Trigger.java index c3df01e7d2..7cefbabd3a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/Trigger.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/Trigger.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage; @@ -10,287 +17,94 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Trigger extends Resource { - private static final long serialVersionUID = 174561249107274L; - - public enum UsageCategory { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - private final String value; + public static TriggerCreator creator( + final URI callbackUrl, + final String triggerValue, + final String usageCategory + ) { + return new TriggerCreator(callbackUrl, triggerValue, usageCategory); + } - private UsageCategory(final String value) { - this.value = value; - } + public static TriggerCreator creator( + final String pathAccountSid, + final URI callbackUrl, + final String triggerValue, + final String usageCategory + ) { + return new TriggerCreator( + pathAccountSid, + callbackUrl, + triggerValue, + usageCategory + ); + } - public String toString() { - return value; - } + public static TriggerDeleter deleter(final String pathSid) { + return new TriggerDeleter(pathSid); + } - /** - * Generate a UsageCategory from a string. - * @param value string value - * @return generated UsageCategory - */ - @JsonCreator - public static UsageCategory forValue(final String value) { - return Promoter.enumFromString(value, UsageCategory.values()); - } + public static TriggerDeleter deleter( + final String pathAccountSid, + final String pathSid + ) { + return new TriggerDeleter(pathAccountSid, pathSid); + } + + public static TriggerFetcher fetcher(final String pathSid) { + return new TriggerFetcher(pathSid); + } + + public static TriggerFetcher fetcher( + final String pathAccountSid, + final String pathSid + ) { + return new TriggerFetcher(pathAccountSid, pathSid); + } + + public static TriggerReader reader() { + return new TriggerReader(); + } + + public static TriggerReader reader(final String pathAccountSid) { + return new TriggerReader(pathAccountSid); + } + + public static TriggerUpdater updater(final String pathSid) { + return new TriggerUpdater(pathSid); + } + + public static TriggerUpdater updater( + final String pathAccountSid, + final String pathSid + ) { + return new TriggerUpdater(pathAccountSid, pathSid); } public enum Recurring { @@ -305,15 +119,11 @@ private Recurring(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Recurring from a string. - * @param value string value - * @return generated Recurring - */ @JsonCreator public static Recurring forValue(final String value) { return Promoter.enumFromString(value, Recurring.values()); @@ -331,144 +141,28 @@ private TriggerField(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a TriggerField from a string. - * @param value string value - * @return generated TriggerField - */ @JsonCreator public static TriggerField forValue(final String value) { return Promoter.enumFromString(value, TriggerField.values()); } } - /** - * Create a TriggerFetcher to execute fetch. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique usage-trigger Sid - * @return TriggerFetcher capable of executing the fetch - */ - public static TriggerFetcher fetcher(final String pathAccountSid, - final String pathSid) { - return new TriggerFetcher(pathAccountSid, pathSid); - } - - /** - * Create a TriggerFetcher to execute fetch. - * - * @param pathSid Fetch by unique usage-trigger Sid - * @return TriggerFetcher capable of executing the fetch - */ - public static TriggerFetcher fetcher(final String pathSid) { - return new TriggerFetcher(pathSid); - } - - /** - * Create a TriggerUpdater to execute update. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return TriggerUpdater capable of executing the update - */ - public static TriggerUpdater updater(final String pathAccountSid, - final String pathSid) { - return new TriggerUpdater(pathAccountSid, pathSid); - } - - /** - * Create a TriggerUpdater to execute update. - * - * @param pathSid The sid - * @return TriggerUpdater capable of executing the update - */ - public static TriggerUpdater updater(final String pathSid) { - return new TriggerUpdater(pathSid); - } - - /** - * Create a TriggerDeleter to execute delete. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - * @return TriggerDeleter capable of executing the delete - */ - public static TriggerDeleter deleter(final String pathAccountSid, - final String pathSid) { - return new TriggerDeleter(pathAccountSid, pathSid); - } - - /** - * Create a TriggerDeleter to execute delete. - * - * @param pathSid The sid - * @return TriggerDeleter capable of executing the delete - */ - public static TriggerDeleter deleter(final String pathSid) { - return new TriggerDeleter(pathSid); - } - - /** - * Create a TriggerCreator to execute create. - * - * @param pathAccountSid The account_sid - * @param callbackUrl URL Twilio will request when the trigger fires - * @param triggerValue the value at which the trigger will fire - * @param usageCategory The usage category the trigger watches - * @return TriggerCreator capable of executing the create - */ - public static TriggerCreator creator(final String pathAccountSid, - final URI callbackUrl, - final String triggerValue, - final Trigger.UsageCategory usageCategory) { - return new TriggerCreator(pathAccountSid, callbackUrl, triggerValue, usageCategory); - } - - /** - * Create a TriggerCreator to execute create. - * - * @param callbackUrl URL Twilio will request when the trigger fires - * @param triggerValue the value at which the trigger will fire - * @param usageCategory The usage category the trigger watches - * @return TriggerCreator capable of executing the create - */ - public static TriggerCreator creator(final URI callbackUrl, - final String triggerValue, - final Trigger.UsageCategory usageCategory) { - return new TriggerCreator(callbackUrl, triggerValue, usageCategory); - } - - /** - * Create a TriggerReader to execute read. - * - * @param pathAccountSid The account_sid - * @return TriggerReader capable of executing the read - */ - public static TriggerReader reader(final String pathAccountSid) { - return new TriggerReader(pathAccountSid); - } - - /** - * Create a TriggerReader to execute read. - * - * @return TriggerReader capable of executing the read - */ - public static TriggerReader reader() { - return new TriggerReader(); - } - /** * Converts a JSON String into a Trigger object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Trigger object represented by the provided JSON */ - public static Trigger fromJson(final String json, final ObjectMapper objectMapper) { + public static Trigger fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trigger.class); @@ -482,12 +176,15 @@ public static Trigger fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Trigger object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Trigger object represented by the provided JSON */ - public static Trigger fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Trigger fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trigger.class); @@ -498,64 +195,99 @@ public static Trigger fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; + + @Getter private final HttpMethod callbackMethod; + + @Getter private final URI callbackUrl; + + @Getter private final String currentValue; - private final DateTime dateCreated; - private final DateTime dateFired; - private final DateTime dateUpdated; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateFired; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter private final Trigger.Recurring recurring; + + @Getter private final String sid; + + @Getter private final Trigger.TriggerField triggerBy; + + @Getter private final String triggerValue; + + @Getter private final String uri; - private final Trigger.UsageCategory usageCategory; + + @Getter + private final String usageCategory; + + @Getter private final String usageRecordUri; @JsonCreator - private Trigger(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("callback_method") - final HttpMethod callbackMethod, - @JsonProperty("callback_url") - final URI callbackUrl, - @JsonProperty("current_value") - final String currentValue, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_fired") - final String dateFired, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("recurring") - final Trigger.Recurring recurring, - @JsonProperty("sid") - final String sid, - @JsonProperty("trigger_by") - final Trigger.TriggerField triggerBy, - @JsonProperty("trigger_value") - final String triggerValue, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage_category") - final Trigger.UsageCategory usageCategory, - @JsonProperty("usage_record_uri") - final String usageRecordUri) { + private Trigger( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("callback_method") final HttpMethod callbackMethod, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("current_value") final String currentValue, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_fired") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateFired, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("recurring") final Trigger.Recurring recurring, + @JsonProperty("sid") final String sid, + @JsonProperty("trigger_by") final Trigger.TriggerField triggerBy, + @JsonProperty("trigger_value") final String triggerValue, + @JsonProperty("uri") final String uri, + @JsonProperty("usage_category") final String usageCategory, + @JsonProperty("usage_record_uri") final String usageRecordUri + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; this.callbackMethod = callbackMethod; this.callbackUrl = callbackUrl; this.currentValue = currentValue; - this.dateCreated = DateConverter.rfc2822DateTimeFromString(dateCreated); - this.dateFired = DateConverter.rfc2822DateTimeFromString(dateFired); - this.dateUpdated = DateConverter.rfc2822DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateFired = dateFired; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; this.recurring = recurring; this.sid = sid; @@ -566,150 +298,6 @@ private Trigger(@JsonProperty("account_sid") this.usageRecordUri = usageRecordUri; } - /** - * Returns The The account this trigger monitors.. - * - * @return The account this trigger monitors. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The HTTP method to use with callback_url. - * - * @return HTTP method to use with callback_url - */ - public final HttpMethod getCallbackMethod() { - return this.callbackMethod; - } - - /** - * Returns The URL Twilio will request when the trigger fires. - * - * @return URL Twilio will request when the trigger fires - */ - public final URI getCallbackUrl() { - return this.callbackUrl; - } - - /** - * Returns The The current value of the field the trigger is watching.. - * - * @return The current value of the field the trigger is watching. - */ - public final String getCurrentValue() { - return this.currentValue; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date the trigger was last fired. - * - * @return The date the trigger was last fired - */ - public final DateTime getDateFired() { - return this.dateFired; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A user-specified, human-readable name for the trigger.. - * - * @return A user-specified, human-readable name for the trigger. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The How this trigger recurs. - * - * @return How this trigger recurs - */ - public final Trigger.Recurring getRecurring() { - return this.recurring; - } - - /** - * Returns The The trigger's unique Sid. - * - * @return The trigger's unique Sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The field in the UsageRecord that fires the trigger. - * - * @return The field in the UsageRecord that fires the trigger - */ - public final Trigger.TriggerField getTriggerBy() { - return this.triggerBy; - } - - /** - * Returns The the value at which the trigger will fire. - * - * @return the value at which the trigger will fire - */ - public final String getTriggerValue() { - return this.triggerValue; - } - - /** - * Returns The The URI for this resource. - * - * @return The URI for this resource - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The usage category the trigger watches. - * - * @return The usage category the trigger watches - */ - public final Trigger.UsageCategory getUsageCategory() { - return this.usageCategory; - } - - /** - * Returns The The URI of the UsageRecord this trigger is watching. - * - * @return The URI of the UsageRecord this trigger is watching - */ - public final String getUsageRecordUri() { - return this.usageRecordUri; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -721,64 +309,45 @@ public boolean equals(final Object o) { } Trigger other = (Trigger) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(callbackMethod, other.callbackMethod) && - Objects.equals(callbackUrl, other.callbackUrl) && - Objects.equals(currentValue, other.currentValue) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateFired, other.dateFired) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(recurring, other.recurring) && - Objects.equals(sid, other.sid) && - Objects.equals(triggerBy, other.triggerBy) && - Objects.equals(triggerValue, other.triggerValue) && - Objects.equals(uri, other.uri) && - Objects.equals(usageCategory, other.usageCategory) && - Objects.equals(usageRecordUri, other.usageRecordUri); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(callbackMethod, other.callbackMethod) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(currentValue, other.currentValue) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateFired, other.dateFired) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(recurring, other.recurring) && + Objects.equals(sid, other.sid) && + Objects.equals(triggerBy, other.triggerBy) && + Objects.equals(triggerValue, other.triggerValue) && + Objects.equals(uri, other.uri) && + Objects.equals(usageCategory, other.usageCategory) && + Objects.equals(usageRecordUri, other.usageRecordUri) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - callbackMethod, - callbackUrl, - currentValue, - dateCreated, - dateFired, - dateUpdated, - friendlyName, - recurring, - sid, - triggerBy, - triggerValue, - uri, - usageCategory, - usageRecordUri); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("callbackMethod", callbackMethod) - .add("callbackUrl", callbackUrl) - .add("currentValue", currentValue) - .add("dateCreated", dateCreated) - .add("dateFired", dateFired) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("recurring", recurring) - .add("sid", sid) - .add("triggerBy", triggerBy) - .add("triggerValue", triggerValue) - .add("uri", uri) - .add("usageCategory", usageCategory) - .add("usageRecordUri", usageRecordUri) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + callbackMethod, + callbackUrl, + currentValue, + dateCreated, + dateFired, + dateUpdated, + friendlyName, + recurring, + sid, + triggerBy, + triggerValue, + uri, + usageCategory, + usageRecordUri + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerCreator.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerCreator.java index 9a034d4425..e38ba5f842 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerCreator.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerCreator.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,175 +28,210 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class TriggerCreator extends Creator { + private String pathAccountSid; - private final URI callbackUrl; - private final String triggerValue; - private final Trigger.UsageCategory usageCategory; + private URI callbackUrl; + private String triggerValue; + private String usageCategory; private HttpMethod callbackMethod; private String friendlyName; private Trigger.Recurring recurring; private Trigger.TriggerField triggerBy; - /** - * Construct a new TriggerCreator. - * - * @param callbackUrl URL Twilio will request when the trigger fires - * @param triggerValue the value at which the trigger will fire - * @param usageCategory The usage category the trigger watches - */ - public TriggerCreator(final URI callbackUrl, - final String triggerValue, - final Trigger.UsageCategory usageCategory) { + public TriggerCreator( + final URI callbackUrl, + final String triggerValue, + final String usageCategory + ) { this.callbackUrl = callbackUrl; this.triggerValue = triggerValue; this.usageCategory = usageCategory; } - /** - * Construct a new TriggerCreator. - * - * @param pathAccountSid The account_sid - * @param callbackUrl URL Twilio will request when the trigger fires - * @param triggerValue the value at which the trigger will fire - * @param usageCategory The usage category the trigger watches - */ - public TriggerCreator(final String pathAccountSid, - final URI callbackUrl, - final String triggerValue, - final Trigger.UsageCategory usageCategory) { + public TriggerCreator( + final String pathAccountSid, + final URI callbackUrl, + final String triggerValue, + final String usageCategory + ) { this.pathAccountSid = pathAccountSid; this.callbackUrl = callbackUrl; this.triggerValue = triggerValue; this.usageCategory = usageCategory; } - /** - * Twilio will use this HTTP method when making a request to the CallbackUrl. - * `GET` or `POST`. The default is `POST`.. - * - * @param callbackMethod HTTP method to use with callback_url - * @return this - */ + public TriggerCreator setCallbackUrl(final URI callbackUrl) { + this.callbackUrl = callbackUrl; + return this; + } + + public TriggerCreator setCallbackUrl(final String callbackUrl) { + return setCallbackUrl(Promoter.uriFromString(callbackUrl)); + } + + public TriggerCreator setTriggerValue(final String triggerValue) { + this.triggerValue = triggerValue; + return this; + } + + public TriggerCreator setUsageCategory(final String usageCategory) { + this.usageCategory = usageCategory; + return this; + } + public TriggerCreator setCallbackMethod(final HttpMethod callbackMethod) { this.callbackMethod = callbackMethod; return this; } - /** - * A human readable description of the new trigger. Maximum 64 characters.. - * - * @param friendlyName A user-specified, human-readable name for the trigger. - * @return this - */ public TriggerCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * How this trigger recurs. Empty for non-recurring triggers. One of `daily`, - * `monthly`, or `yearly` for recurring triggers. A trigger will only fire once - * during each recurring period. Recurring periods are in GMT.. - * - * @param recurring How this trigger recurs - * @return this - */ public TriggerCreator setRecurring(final Trigger.Recurring recurring) { this.recurring = recurring; return this; } - /** - * The field in the - * [UsageRecord](https://www.twilio.com/docs/api/rest/usage-records) that will - * fire the trigger. One of `count`, `usage`, or `price` as described in the - * [UsageRecords - * documentation](https://www.twilio.com/docs/api/rest/usage-records#usage-count-price). The default is `usage`.. - * - * @param triggerBy The field in the UsageRecord that fires the trigger - * @return this - */ public TriggerCreator setTriggerBy(final Trigger.TriggerField triggerBy) { this.triggerBy = triggerBy; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Trigger - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Trigger create(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Triggers.json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Trigger creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Trigger create(final TwilioRestClient client) { + Response response = makeRequest(client); return Trigger.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Trigger content = Trigger.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); } if (triggerValue != null) { - request.addPostParam("TriggerValue", triggerValue); + Serializer.toString( + request, + "TriggerValue", + triggerValue, + ParameterType.URLENCODED + ); } if (usageCategory != null) { - request.addPostParam("UsageCategory", usageCategory.toString()); + Serializer.toString( + request, + "UsageCategory", + usageCategory, + ParameterType.URLENCODED + ); } if (callbackMethod != null) { - request.addPostParam("CallbackMethod", callbackMethod.toString()); + Serializer.toString( + request, + "CallbackMethod", + callbackMethod, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (recurring != null) { - request.addPostParam("Recurring", recurring.toString()); + Serializer.toString( + request, + "Recurring", + recurring, + ParameterType.URLENCODED + ); } if (triggerBy != null) { - request.addPostParam("TriggerBy", triggerBy.toString()); + Serializer.toString( + request, + "TriggerBy", + triggerBy, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerDeleter.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerDeleter.java index 85e8c63435..24bfff0b14 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerDeleter.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,90 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class TriggerDeleter extends Deleter { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new TriggerDeleter. - * - * @param pathSid The sid - */ public TriggerDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new TriggerDeleter. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public TriggerDeleter(final String pathAccountSid, - final String pathSid) { + public TriggerDeleter(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Triggers/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Trigger delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerFetcher.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerFetcher.java index 1ddc4e6ad9..10ff8003ac 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerFetcher.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,68 +24,86 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TriggerFetcher extends Fetcher { + private String pathAccountSid; - private final String pathSid; + private String pathSid; - /** - * Construct a new TriggerFetcher. - * - * @param pathSid Fetch by unique usage-trigger Sid - */ public TriggerFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new TriggerFetcher. - * - * @param pathAccountSid The account_sid - * @param pathSid Fetch by unique usage-trigger Sid - */ - public TriggerFetcher(final String pathAccountSid, - final String pathSid) { + public TriggerFetcher(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Trigger - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Trigger fetch(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Triggers/" + this.pathSid + ".json", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Trigger fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Trigger fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Trigger.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Trigger content = Trigger.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerReader.java index ce7220d2d5..dbde230bc2 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage; @@ -10,221 +17,246 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TriggerReader extends Reader { + private String pathAccountSid; private Trigger.Recurring recurring; private Trigger.TriggerField triggerBy; - private Trigger.UsageCategory usageCategory; + private String usageCategory; + private Long pageSize; - /** - * Construct a new TriggerReader. - */ - public TriggerReader() { - } + public TriggerReader() {} - /** - * Construct a new TriggerReader. - * - * @param pathAccountSid The account_sid - */ public TriggerReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only show UsageTriggers that count over this interval. One of `daily`, - * `monthly`, or `yearly`. To retrieve non-recurring triggers, leave this empty - * or use `alltime`.. - * - * @param recurring Filter by recurring - * @return this - */ public TriggerReader setRecurring(final Trigger.Recurring recurring) { this.recurring = recurring; return this; } - /** - * Only show UsageTriggers that trigger by this field in the UsageRecord. Must - * be one of: `count`, `usage`, or `price` as described in the [UsageRecords - * documentation](https://www.twilio.com/docs/api/rest/usage-records#usage-count-price).. - * - * @param triggerBy Filter by trigger by - * @return this - */ public TriggerReader setTriggerBy(final Trigger.TriggerField triggerBy) { this.triggerBy = triggerBy; return this; } - /** - * Only show UsageTriggers that watch this usage category. Must be one of the - * supported [usage - * categories](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param usageCategory Filter by Usage Category - * @return this - */ - public TriggerReader setUsageCategory(final Trigger.UsageCategory usageCategory) { + public TriggerReader setUsageCategory(final String usageCategory) { this.usageCategory = usageCategory; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Trigger ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TriggerReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Trigger ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_triggers", + response.getContent(), + Trigger.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Triggers.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Trigger ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_triggers", + response.getContent(), + Trigger.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Trigger read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_triggers", + response.getContent(), + Trigger.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Trigger Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Trigger read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_triggers", - response.getContent(), - Trigger.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (recurring != null) { - request.addQueryParam("Recurring", recurring.toString()); + Serializer.toString( + request, + "Recurring", + recurring, + ParameterType.QUERY + ); } if (triggerBy != null) { - request.addQueryParam("TriggerBy", triggerBy.toString()); + Serializer.toString( + request, + "TriggerBy", + triggerBy, + ParameterType.QUERY + ); } if (usageCategory != null) { - request.addQueryParam("UsageCategory", usageCategory.toString()); + Serializer.toString( + request, + "UsageCategory", + usageCategory, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerUpdater.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerUpdater.java index 8bbf55d263..bced031d86 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerUpdater.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/TriggerUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,137 +28,140 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class TriggerUpdater extends Updater { + private String pathAccountSid; - private final String pathSid; + private String pathSid; private HttpMethod callbackMethod; private URI callbackUrl; private String friendlyName; - /** - * Construct a new TriggerUpdater. - * - * @param pathSid The sid - */ public TriggerUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Construct a new TriggerUpdater. - * - * @param pathAccountSid The account_sid - * @param pathSid The sid - */ - public TriggerUpdater(final String pathAccountSid, - final String pathSid) { + public TriggerUpdater(final String pathAccountSid, final String pathSid) { this.pathAccountSid = pathAccountSid; this.pathSid = pathSid; } - /** - * The HTTP method Twilio will use when making a request to the CallbackUrl. - * `GET` or `POST`.. - * - * @param callbackMethod HTTP method to use with callback_url - * @return this - */ public TriggerUpdater setCallbackMethod(final HttpMethod callbackMethod) { this.callbackMethod = callbackMethod; return this; } - /** - * Twilio will make a request to this url when the trigger fires.. - * - * @param callbackUrl URL Twilio will request when the trigger fires - * @return this - */ public TriggerUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - /** - * Twilio will make a request to this url when the trigger fires.. - * - * @param callbackUrl URL Twilio will request when the trigger fires - * @return this - */ public TriggerUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - /** - * A user-specified, human-readable name for the trigger.. - * - * @param friendlyName A user-specified, human-readable name for the trigger. - * @return this - */ public TriggerUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Trigger - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Trigger update(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + private Response makeRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Triggers/{Sid}.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Triggers/" + this.pathSid + ".json", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trigger update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Trigger update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Trigger update(final TwilioRestClient client) { + Response response = makeRequest(client); return Trigger.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Trigger content = Trigger.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (callbackMethod != null) { - request.addPostParam("CallbackMethod", callbackMethod.toString()); + Serializer.toString( + request, + "CallbackMethod", + callbackMethod, + ParameterType.URLENCODED + ); } if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTime.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTime.java index 476c32de08..6e99f3084f 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTime.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTime.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -11,317 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AllTime extends Resource { - private static final long serialVersionUID = 88063671827161L; - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static AllTimeReader reader() { + return new AllTimeReader(); } - /** - * Create a AllTimeReader to execute read. - * - * @param pathAccountSid The account_sid - * @return AllTimeReader capable of executing the read - */ public static AllTimeReader reader(final String pathAccountSid) { return new AllTimeReader(pathAccountSid); } - /** - * Create a AllTimeReader to execute read. - * - * @return AllTimeReader capable of executing the read - */ - public static AllTimeReader reader() { - return new AllTimeReader(); - } - /** * Converts a JSON String into a AllTime object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AllTime object represented by the provided JSON */ - public static AllTime fromJson(final String json, final ObjectMapper objectMapper) { + public static AllTime fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AllTime.class); @@ -335,12 +75,15 @@ public static AllTime fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a AllTime object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AllTime object represented by the provided JSON */ - public static AllTime fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AllTime fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AllTime.class); @@ -351,200 +94,107 @@ public static AllTime fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final AllTime.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private AllTime(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final AllTime.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private AllTime( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage.. - * - * @return The Account that accrued the usage. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage.. - * - * @return The category of usage. - */ - public final AllTime.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events.. - * - * @return The number of usage events. - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The units in which Count is measured.. - * - * @return The units in which Count is measured. - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage, in the currency associated with the - * account.. - * - * @return The total price of the usage, in the currency associated with the - * account. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured, in ISO 4127 format.. - * - * @return The currency in which Price is measured, in ISO 4127 format. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresource Uris for this UsageRecord.. - * - * @return Subresource Uris for this UsageRecord. - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI that returns only this UsageRecord, relative to - * https://api.. - * - * @return The URI that returns only this UsageRecord, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of billed usage.. - * - * @return The amount of billed usage. - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which Usage is measured.. - * - * @return The units in which Usage is measured. - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -556,58 +206,43 @@ public boolean equals(final Object o) { } AllTime other = (AllTime) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTimeReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTimeReader.java index 16e8bee9cc..adcb385a22 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTimeReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/AllTimeReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -10,240 +17,265 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class AllTimeReader extends Reader { + private String pathAccountSid; - private AllTime.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new AllTimeReader. - */ - public AllTimeReader() { - } + public AllTimeReader() {} - /** - * Construct a new AllTimeReader. - * - * @param pathAccountSid The account_sid - */ public AllTimeReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only include usage of this [usage - * category](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param category Only include usage of this usage category. - * @return this - */ - public AllTimeReader setCategory(final AllTime.Category category) { + public AllTimeReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Only include usage that has occurred on or after this date. - * @return this - */ public AllTimeReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Only include usage that has occurred on or before this date. - * @return this - */ public AllTimeReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ - public AllTimeReader setIncludeSubaccounts(final Boolean includeSubaccounts) { + public AllTimeReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AllTime ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AllTimeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AllTime ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + AllTime.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/AllTime.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records/AllTime.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AllTime ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + AllTime.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AllTime read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + AllTime.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AllTime Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AllTime read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - AllTime.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Daily.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Daily.java index bd84ea8ba6..d14ddeaec8 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Daily.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Daily.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -11,317 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Daily extends Resource { - private static final long serialVersionUID = 169621990406311L; - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static DailyReader reader() { + return new DailyReader(); } - /** - * Create a DailyReader to execute read. - * - * @param pathAccountSid The account_sid - * @return DailyReader capable of executing the read - */ public static DailyReader reader(final String pathAccountSid) { return new DailyReader(pathAccountSid); } - /** - * Create a DailyReader to execute read. - * - * @return DailyReader capable of executing the read - */ - public static DailyReader reader() { - return new DailyReader(); - } - /** * Converts a JSON String into a Daily object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Daily object represented by the provided JSON */ - public static Daily fromJson(final String json, final ObjectMapper objectMapper) { + public static Daily fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Daily.class); @@ -335,12 +75,15 @@ public static Daily fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Daily object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Daily object represented by the provided JSON */ - public static Daily fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Daily fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Daily.class); @@ -351,200 +94,107 @@ public static Daily fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final Daily.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private Daily(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final Daily.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private Daily( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage.. - * - * @return The Account that accrued the usage. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage.. - * - * @return The category of usage. - */ - public final Daily.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events.. - * - * @return The number of usage events. - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The units in which Count is measured.. - * - * @return The units in which Count is measured. - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage, in the currency associated with the - * account.. - * - * @return The total price of the usage, in the currency associated with the - * account. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured, in ISO 4127 format.. - * - * @return The currency in which Price is measured, in ISO 4127 format. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresource Uris for this UsageRecord.. - * - * @return Subresource Uris for this UsageRecord. - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI that returns only this UsageRecord, relative to - * https://api.. - * - * @return The URI that returns only this UsageRecord, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of billed usage.. - * - * @return The amount of billed usage. - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which Usage is measured.. - * - * @return The units in which Usage is measured. - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -556,58 +206,43 @@ public boolean equals(final Object o) { } Daily other = (Daily) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/DailyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/DailyReader.java index eda2d891d4..0cc040ba46 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/DailyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/DailyReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -10,240 +17,259 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class DailyReader extends Reader { + private String pathAccountSid; - private Daily.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new DailyReader. - */ - public DailyReader() { - } + public DailyReader() {} - /** - * Construct a new DailyReader. - * - * @param pathAccountSid The account_sid - */ public DailyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only include usage of this [usage - * category](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param category Only include usage of this usage category. - * @return this - */ - public DailyReader setCategory(final Daily.Category category) { + public DailyReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Only include usage that has occurred on or after this date. - * @return this - */ public DailyReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Only include usage that has occurred on or before this date. - * @return this - */ public DailyReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ public DailyReader setIncludeSubaccounts(final Boolean includeSubaccounts) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Daily ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public DailyReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Daily ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Daily.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Daily.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records/Daily.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Daily ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Daily.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Daily read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + Daily.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Daily Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Daily read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - Daily.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonth.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonth.java index 1bd1eba7b0..a3a2de2bf3 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonth.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonth.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -11,318 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class LastMonth extends Resource { - private static final long serialVersionUID = 64962400986061L; - - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static LastMonthReader reader() { + return new LastMonthReader(); } - /** - * Create a LastMonthReader to execute read. - * - * @param pathAccountSid The account_sid - * @return LastMonthReader capable of executing the read - */ public static LastMonthReader reader(final String pathAccountSid) { return new LastMonthReader(pathAccountSid); } /** - * Create a LastMonthReader to execute read. - * - * @return LastMonthReader capable of executing the read - */ - public static LastMonthReader reader() { - return new LastMonthReader(); - } - - /** - * Converts a JSON String into a LastMonth object using the provided - * ObjectMapper. - * + * Converts a JSON String into a LastMonth object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return LastMonth object represented by the provided JSON */ - public static LastMonth fromJson(final String json, final ObjectMapper objectMapper) { + public static LastMonth fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, LastMonth.class); @@ -336,12 +75,15 @@ public static LastMonth fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a LastMonth object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return LastMonth object represented by the provided JSON */ - public static LastMonth fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static LastMonth fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, LastMonth.class); @@ -352,200 +94,107 @@ public static LastMonth fromJson(final InputStream json, final ObjectMapper obje } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final LastMonth.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private LastMonth(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final LastMonth.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private LastMonth( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage.. - * - * @return The Account that accrued the usage. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage.. - * - * @return The category of usage. - */ - public final LastMonth.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events.. - * - * @return The number of usage events. - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The units in which Count is measured.. - * - * @return The units in which Count is measured. - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage, in the currency associated with the - * account.. - * - * @return The total price of the usage, in the currency associated with the - * account. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured, in ISO 4127 format.. - * - * @return The currency in which Price is measured, in ISO 4127 format. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresource Uris for this UsageRecord.. - * - * @return Subresource Uris for this UsageRecord. - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI that returns only this UsageRecord, relative to - * https://api.. - * - * @return The URI that returns only this UsageRecord, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of billed usage.. - * - * @return The amount of billed usage. - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which Usage is measured.. - * - * @return The units in which Usage is measured. - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -557,58 +206,43 @@ public boolean equals(final Object o) { } LastMonth other = (LastMonth) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonthReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonthReader.java index b0c012e1bd..7918f0918d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonthReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/LastMonthReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -10,240 +17,265 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class LastMonthReader extends Reader { + private String pathAccountSid; - private LastMonth.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new LastMonthReader. - */ - public LastMonthReader() { - } + public LastMonthReader() {} - /** - * Construct a new LastMonthReader. - * - * @param pathAccountSid The account_sid - */ public LastMonthReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * The category of usage. See [Usage - * Categories](https://www.twilio.com/docs/api/rest/usage-records#usage-categories) below.. - * - * @param category Only include usage of this usage category. - * @return this - */ - public LastMonthReader setCategory(final LastMonth.Category category) { + public LastMonthReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Only include usage that has occurred on or after this date. - * @return this - */ public LastMonthReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Only include usage that has occurred on or before this date. - * @return this - */ public LastMonthReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ - public LastMonthReader setIncludeSubaccounts(final Boolean includeSubaccounts) { + public LastMonthReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return LastMonth ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public LastMonthReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return LastMonth ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + LastMonth.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/LastMonth.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records/LastMonth.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return LastMonth ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + LastMonth.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "LastMonth read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + LastMonth.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of LastMonth Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("LastMonth read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - LastMonth.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Monthly.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Monthly.java index 203eb5457d..7544657776 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Monthly.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Monthly.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -11,317 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Monthly extends Resource { - private static final long serialVersionUID = 31795430446175L; - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static MonthlyReader reader() { + return new MonthlyReader(); } - /** - * Create a MonthlyReader to execute read. - * - * @param pathAccountSid The account_sid - * @return MonthlyReader capable of executing the read - */ public static MonthlyReader reader(final String pathAccountSid) { return new MonthlyReader(pathAccountSid); } - /** - * Create a MonthlyReader to execute read. - * - * @return MonthlyReader capable of executing the read - */ - public static MonthlyReader reader() { - return new MonthlyReader(); - } - /** * Converts a JSON String into a Monthly object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Monthly object represented by the provided JSON */ - public static Monthly fromJson(final String json, final ObjectMapper objectMapper) { + public static Monthly fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Monthly.class); @@ -335,12 +75,15 @@ public static Monthly fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Monthly object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Monthly object represented by the provided JSON */ - public static Monthly fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Monthly fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Monthly.class); @@ -351,200 +94,107 @@ public static Monthly fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final Monthly.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private Monthly(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final Monthly.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private Monthly( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage.. - * - * @return The Account that accrued the usage. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage.. - * - * @return The category of usage. - */ - public final Monthly.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events.. - * - * @return The number of usage events. - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The units in which Count is measured.. - * - * @return The units in which Count is measured. - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage, in the currency associated with the - * account.. - * - * @return The total price of the usage, in the currency associated with the - * account. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured, in ISO 4127 format.. - * - * @return The currency in which Price is measured, in ISO 4127 format. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresource Uris for this UsageRecord.. - * - * @return Subresource Uris for this UsageRecord. - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI that returns only this UsageRecord, relative to - * https://api.. - * - * @return The URI that returns only this UsageRecord, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of billed usage.. - * - * @return The amount of billed usage. - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which Usage is measured.. - * - * @return The units in which Usage is measured. - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -556,58 +206,43 @@ public boolean equals(final Object o) { } Monthly other = (Monthly) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/MonthlyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/MonthlyReader.java index c276994e1f..91f84a7b56 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/MonthlyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/MonthlyReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -10,240 +17,265 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class MonthlyReader extends Reader { + private String pathAccountSid; - private Monthly.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new MonthlyReader. - */ - public MonthlyReader() { - } + public MonthlyReader() {} - /** - * Construct a new MonthlyReader. - * - * @param pathAccountSid The account_sid - */ public MonthlyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only include usage of this [usage - * category](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param category Only include usage of this usage category. - * @return this - */ - public MonthlyReader setCategory(final Monthly.Category category) { + public MonthlyReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Only include usage that has occurred on or after this date. - * @return this - */ public MonthlyReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Only include usage that has occurred on or before this date. - * @return this - */ public MonthlyReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ - public MonthlyReader setIncludeSubaccounts(final Boolean includeSubaccounts) { + public MonthlyReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Monthly ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MonthlyReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Monthly ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Monthly.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Monthly.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records/Monthly.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Monthly ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Monthly.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Monthly read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + Monthly.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Monthly Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Monthly read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - Monthly.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonth.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonth.java index e42db9cb16..e2c5102e94 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonth.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonth.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -11,318 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class ThisMonth extends Resource { - private static final long serialVersionUID = 39146072030212L; - - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static ThisMonthReader reader() { + return new ThisMonthReader(); } - /** - * Create a ThisMonthReader to execute read. - * - * @param pathAccountSid The account_sid - * @return ThisMonthReader capable of executing the read - */ public static ThisMonthReader reader(final String pathAccountSid) { return new ThisMonthReader(pathAccountSid); } /** - * Create a ThisMonthReader to execute read. - * - * @return ThisMonthReader capable of executing the read - */ - public static ThisMonthReader reader() { - return new ThisMonthReader(); - } - - /** - * Converts a JSON String into a ThisMonth object using the provided - * ObjectMapper. - * + * Converts a JSON String into a ThisMonth object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return ThisMonth object represented by the provided JSON */ - public static ThisMonth fromJson(final String json, final ObjectMapper objectMapper) { + public static ThisMonth fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ThisMonth.class); @@ -336,12 +75,15 @@ public static ThisMonth fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a ThisMonth object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return ThisMonth object represented by the provided JSON */ - public static ThisMonth fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static ThisMonth fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ThisMonth.class); @@ -352,200 +94,107 @@ public static ThisMonth fromJson(final InputStream json, final ObjectMapper obje } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final ThisMonth.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private ThisMonth(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final ThisMonth.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private ThisMonth( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage.. - * - * @return The Account that accrued the usage. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage.. - * - * @return The category of usage. - */ - public final ThisMonth.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events.. - * - * @return The number of usage events. - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The units in which Count is measured.. - * - * @return The units in which Count is measured. - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage, in the currency associated with the - * account.. - * - * @return The total price of the usage, in the currency associated with the - * account. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured, in ISO 4127 format.. - * - * @return The currency in which Price is measured, in ISO 4127 format. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresource Uris for this UsageRecord.. - * - * @return Subresource Uris for this UsageRecord. - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI that returns only this UsageRecord, relative to - * https://api.. - * - * @return The URI that returns only this UsageRecord, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of billed usage.. - * - * @return The amount of billed usage. - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which Usage is measured.. - * - * @return The units in which Usage is measured. - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -557,58 +206,43 @@ public boolean equals(final Object o) { } ThisMonth other = (ThisMonth) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonthReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonthReader.java index addf2de4e7..c0da63798d 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonthReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/ThisMonthReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -10,240 +17,265 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class ThisMonthReader extends Reader { + private String pathAccountSid; - private ThisMonth.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new ThisMonthReader. - */ - public ThisMonthReader() { - } + public ThisMonthReader() {} - /** - * Construct a new ThisMonthReader. - * - * @param pathAccountSid The account_sid - */ public ThisMonthReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only include usage of this [usage - * category](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param category Only include usage of this usage category. - * @return this - */ - public ThisMonthReader setCategory(final ThisMonth.Category category) { + public ThisMonthReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Only include usage that has occurred on or after this date. - * @return this - */ public ThisMonthReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Only include usage that has occurred on or before this date. - * @return this - */ public ThisMonthReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ - public ThisMonthReader setIncludeSubaccounts(final Boolean includeSubaccounts) { + public ThisMonthReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ThisMonth ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ThisMonthReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ThisMonth ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + ThisMonth.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/ThisMonth.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records/ThisMonth.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return ThisMonth ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + ThisMonth.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ThisMonth read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + ThisMonth.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of ThisMonth Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ThisMonth read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - ThisMonth.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Today.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Today.java index 671641436f..f2220a1c22 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Today.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Today.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -11,317 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Today extends Resource { - private static final long serialVersionUID = 96248709903219L; - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static TodayReader reader() { + return new TodayReader(); } - /** - * Create a TodayReader to execute read. - * - * @param pathAccountSid The account_sid - * @return TodayReader capable of executing the read - */ public static TodayReader reader(final String pathAccountSid) { return new TodayReader(pathAccountSid); } - /** - * Create a TodayReader to execute read. - * - * @return TodayReader capable of executing the read - */ - public static TodayReader reader() { - return new TodayReader(); - } - /** * Converts a JSON String into a Today object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Today object represented by the provided JSON */ - public static Today fromJson(final String json, final ObjectMapper objectMapper) { + public static Today fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Today.class); @@ -335,12 +75,15 @@ public static Today fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Today object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Today object represented by the provided JSON */ - public static Today fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Today fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Today.class); @@ -351,200 +94,107 @@ public static Today fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final Today.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private Today(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final Today.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private Today( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage.. - * - * @return The Account that accrued the usage. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage.. - * - * @return The category of usage. - */ - public final Today.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events.. - * - * @return The number of usage events. - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The units in which Count is measured.. - * - * @return The units in which Count is measured. - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage, in the currency associated with the - * account.. - * - * @return The total price of the usage, in the currency associated with the - * account. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured, in ISO 4127 format.. - * - * @return The currency in which Price is measured, in ISO 4127 format. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresource Uris for this UsageRecord.. - * - * @return Subresource Uris for this UsageRecord. - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI that returns only this UsageRecord, relative to - * https://api.. - * - * @return The URI that returns only this UsageRecord, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of billed usage.. - * - * @return The amount of billed usage. - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which Usage is measured.. - * - * @return The units in which Usage is measured. - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -556,58 +206,43 @@ public boolean equals(final Object o) { } Today other = (Today) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/TodayReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/TodayReader.java index 1cca49c0cd..1e3a243006 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/TodayReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/TodayReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -10,240 +17,259 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class TodayReader extends Reader { + private String pathAccountSid; - private Today.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new TodayReader. - */ - public TodayReader() { - } + public TodayReader() {} - /** - * Construct a new TodayReader. - * - * @param pathAccountSid The account_sid - */ public TodayReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only include usage of this [usage - * category](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param category Only include usage of this usage category. - * @return this - */ - public TodayReader setCategory(final Today.Category category) { + public TodayReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Only include usage that has occurred on or after this date. - * @return this - */ public TodayReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Only include usage that has occurred on or before this date. - * @return this - */ public TodayReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ public TodayReader setIncludeSubaccounts(final Boolean includeSubaccounts) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Today ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TodayReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Today ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Today.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Today.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records/Today.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Today ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Today.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Today read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + Today.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Today Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Today read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - Today.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yearly.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yearly.java index 32113a54f7..28c3741417 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yearly.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yearly.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -11,317 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Yearly extends Resource { - private static final long serialVersionUID = 169821913142495L; - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static YearlyReader reader() { + return new YearlyReader(); } - /** - * Create a YearlyReader to execute read. - * - * @param pathAccountSid The account_sid - * @return YearlyReader capable of executing the read - */ public static YearlyReader reader(final String pathAccountSid) { return new YearlyReader(pathAccountSid); } - /** - * Create a YearlyReader to execute read. - * - * @return YearlyReader capable of executing the read - */ - public static YearlyReader reader() { - return new YearlyReader(); - } - /** * Converts a JSON String into a Yearly object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Yearly object represented by the provided JSON */ - public static Yearly fromJson(final String json, final ObjectMapper objectMapper) { + public static Yearly fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Yearly.class); @@ -335,12 +75,15 @@ public static Yearly fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Yearly object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Yearly object represented by the provided JSON */ - public static Yearly fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Yearly fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Yearly.class); @@ -351,200 +94,107 @@ public static Yearly fromJson(final InputStream json, final ObjectMapper objectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final Yearly.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private Yearly(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final Yearly.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private Yearly( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage.. - * - * @return The Account that accrued the usage. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage.. - * - * @return The category of usage. - */ - public final Yearly.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events.. - * - * @return The number of usage events. - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The units in which Count is measured.. - * - * @return The units in which Count is measured. - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage, in the currency associated with the - * account.. - * - * @return The total price of the usage, in the currency associated with the - * account. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured, in ISO 4127 format.. - * - * @return The currency in which Price is measured, in ISO 4127 format. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresource Uris for this UsageRecord.. - * - * @return Subresource Uris for this UsageRecord. - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI that returns only this UsageRecord, relative to - * https://api.. - * - * @return The URI that returns only this UsageRecord, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of billed usage.. - * - * @return The amount of billed usage. - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which Usage is measured.. - * - * @return The units in which Usage is measured. - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -556,58 +206,43 @@ public boolean equals(final Object o) { } Yearly other = (Yearly) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YearlyReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YearlyReader.java index 13ebfb3219..a5a64630d6 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YearlyReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YearlyReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -10,240 +17,261 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class YearlyReader extends Reader { + private String pathAccountSid; - private Yearly.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new YearlyReader. - */ - public YearlyReader() { - } + public YearlyReader() {} - /** - * Construct a new YearlyReader. - * - * @param pathAccountSid The account_sid - */ public YearlyReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only include usage of this [usage - * category](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param category Only include usage of this usage category. - * @return this - */ - public YearlyReader setCategory(final Yearly.Category category) { + public YearlyReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Only include usage that has occurred on or after this date. - * @return this - */ public YearlyReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Only include usage that has occurred on or before this date. - * @return this - */ public YearlyReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ - public YearlyReader setIncludeSubaccounts(final Boolean includeSubaccounts) { + public YearlyReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Yearly ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public YearlyReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Yearly ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Yearly.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yearly.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records/Yearly.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Yearly ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Yearly.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Yearly read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + Yearly.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Yearly Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Yearly read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - Yearly.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yesterday.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yesterday.java index 94a2e53df3..412f3d8501 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yesterday.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/Yesterday.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -11,318 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.time.LocalDate; import java.util.Currency; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Yesterday extends Resource { - private static final long serialVersionUID = 238965611069323L; - - public enum Category { - ANSWERING_MACHINE_DETECTION("answering-machine-detection"), - AUTHY_AUTHENTICATIONS("authy-authentications"), - AUTHY_CALLS_OUTBOUND("authy-calls-outbound"), - AUTHY_MONTHLY_FEES("authy-monthly-fees"), - AUTHY_PHONE_INTELLIGENCE("authy-phone-intelligence"), - AUTHY_PHONE_VERIFICATIONS("authy-phone-verifications"), - AUTHY_SMS_OUTBOUND("authy-sms-outbound"), - CALL_PROGESS_EVENTS("call-progess-events"), - CALLERIDLOOKUPS("calleridlookups"), - CALLS("calls"), - CALLS_CLIENT("calls-client"), - CALLS_GLOBALCONFERENCE("calls-globalconference"), - CALLS_INBOUND("calls-inbound"), - CALLS_INBOUND_LOCAL("calls-inbound-local"), - CALLS_INBOUND_MOBILE("calls-inbound-mobile"), - CALLS_INBOUND_TOLLFREE("calls-inbound-tollfree"), - CALLS_OUTBOUND("calls-outbound"), - CALLS_RECORDINGS("calls-recordings"), - CALLS_SIP("calls-sip"), - CALLS_SIP_INBOUND("calls-sip-inbound"), - CALLS_SIP_OUTBOUND("calls-sip-outbound"), - CARRIER_LOOKUPS("carrier-lookups"), - CONVERSATIONS("conversations"), - CONVERSATIONS_API_REQUESTS("conversations-api-requests"), - CONVERSATIONS_CONVERSATION_EVENTS("conversations-conversation-events"), - CONVERSATIONS_ENDPOINT_CONNECTIVITY("conversations-endpoint-connectivity"), - CONVERSATIONS_EVENTS("conversations-events"), - CONVERSATIONS_PARTICIPANT_EVENTS("conversations-participant-events"), - CONVERSATIONS_PARTICIPANTS("conversations-participants"), - CPS("cps"), - GROUP_ROOMS("group-rooms"), - GROUP_ROOMS_DATA_TRACK("group-rooms-data-track"), - GROUP_ROOMS_ENCRYPTED_MEDIA_RECORDED("group-rooms-encrypted-media-recorded"), - GROUP_ROOMS_MEDIA_DOWNLOADED("group-rooms-media-downloaded"), - GROUP_ROOMS_MEDIA_RECORDED("group-rooms-media-recorded"), - GROUP_ROOMS_MEDIA_ROUTED("group-rooms-media-routed"), - GROUP_ROOMS_MEDIA_STORED("group-rooms-media-stored"), - GROUP_ROOMS_PARTICIPANT_MINUTES("group-rooms-participant-minutes"), - GROUP_ROOMS_RECORDED_MINUTES("group-rooms-recorded-minutes"), - IP_MESSAGING("ip-messaging"), - IP_MESSAGING_COMMANDS("ip-messaging-commands"), - IP_MESSAGING_DATA_STORAGE("ip-messaging-data-storage"), - IP_MESSAGING_DATA_TRANSFER("ip-messaging-data-transfer"), - IP_MESSAGING_ENDPOINT_CONNECTIVITY("ip-messaging-endpoint-connectivity"), - LOOKUPS("lookups"), - MARKETPLACE("marketplace"), - MARKETPLACE_ALGORITHMIA_NAMED_ENTITY_RECOGNITION("marketplace-algorithmia-named-entity-recognition"), - MARKETPLACE_DIGITAL_SEGMENT_BUSINESS_INFO("marketplace-digital-segment-business-info"), - MARKETPLACE_GOOGLE_SPEECH_TO_TEXT("marketplace-google-speech-to-text"), - MARKETPLACE_IBM_WATSON_MESSAGE_INSIGHTS("marketplace-ibm-watson-message-insights"), - MARKETPLACE_IBM_WATSON_MESSAGE_SENTIMENT("marketplace-ibm-watson-message-sentiment"), - MARKETPLACE_IBM_WATSON_RECORDING_ANALYSIS("marketplace-ibm-watson-recording-analysis"), - MARKETPLACE_ICEHOOK_SYSTEMS_SCOUT("marketplace-icehook-systems-scout"), - MARKETPLACE_INFOGROUP_DATAAXLE_BIZINFO("marketplace-infogroup-dataaxle-bizinfo"), - MARKETPLACE_CADENCE_TRANSCRIPTION("marketplace-cadence-transcription"), - MARKETPLACE_CADENCE_TRANSLATION("marketplace-cadence-translation"), - MARKETPLACE_CAPIO_SPEECH_TO_TEXT("marketplace-capio-speech-to-text"), - MARKETPLACE_FACEBOOK_OFFLINE_CONVERSIONS("marketplace-facebook-offline-conversions"), - MARKETPLACE_KEEN_IO_CONTACT_CENTER_ANALYTICS("marketplace-keen-io-contact-center-analytics"), - MARKETPLACE_MARCHEX_CLEANCALL("marketplace-marchex-cleancall"), - MARKETPLACE_MARCHEX_SENTIMENT_ANALYSIS_FOR_SMS("marketplace-marchex-sentiment-analysis-for-sms"), - MARKETPLACE_MARKETPLACE_NEXTCALLER_SOCIAL_ID("marketplace-marketplace-nextcaller-social-id"), - MARKETPLACE_MOBILE_COMMONS_OPT_OUT_CLASSIFIER("marketplace-mobile-commons-opt-out-classifier"), - MARKETPLACE_NEXIWAVE_VOICEMAIL_TO_TEXT("marketplace-nexiwave-voicemail-to-text"), - MARKETPLACE_NEXTCALLER_ADVANCED_CALLER_IDENTIFICATION("marketplace-nextcaller-advanced-caller-identification"), - MARKETPLACE_NOMOROBO_SPAM_SCORE("marketplace-nomorobo-spam-score"), - MARKETPLACE_PAYFONE_TCPA_COMPLIANCE("marketplace-payfone-tcpa-compliance"), - MARKETPLACE_TELO_OPENCNAM("marketplace-telo-opencnam"), - MARKETPLACE_TRUECNAM_TRUE_SPAM("marketplace-truecnam-true-spam"), - MARKETPLACE_TWILIO_CALLER_NAME_LOOKUP_US("marketplace-twilio-caller-name-lookup-us"), - MARKETPLACE_TWILIO_CARRIER_INFORMATION_LOOKUP("marketplace-twilio-carrier-information-lookup"), - MARKETPLACE_VOICEBASE_PCI("marketplace-voicebase-pci"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION("marketplace-voicebase-transcription"), - MARKETPLACE_WHITEPAGES_PRO_CALLER_IDENTIFICATION("marketplace-whitepages-pro-caller-identification"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_INTELLIGENCE("marketplace-whitepages-pro-phone-intelligence"), - MARKETPLACE_WHITEPAGES_PRO_PHONE_REPUTATION("marketplace-whitepages-pro-phone-reputation"), - MARKETPLACE_WOLFRAM_SHORT_ANSWER("marketplace-wolfram-short-answer"), - MARKETPLACE_WOLFARM_SPOKEN_RESULTS("marketplace-wolfarm-spoken-results"), - MARKETPLACE_DEEPGRAM_PHRASE_DETECTOR("marketplace-deepgram-phrase-detector"), - MARKETPLACE_CONVRIZA_ABABA("marketplace-convriza-ababa"), - MARKETPLACE_IBM_WATSON_TONE_ANALYZER("marketplace-ibm-watson-tone-analyzer"), - MARKETPLACE_REMEETING_AUTOMATIC_SPEECH_RECOGNITION("marketplace-remeeting-automatic-speech-recognition"), - MARKETPLACE_TCPA_DEFENSE_SOLUTIONS_BLACKLIST_FEED("marketplace-tcpa-defense-solutions-blacklist-feed"), - MARKETPLACE_VOICEBASE_TRANSCRIPTION_CUSTOM_VOCABULARY("marketplace-voicebase-transcription-custom-vocabulary"), - MARKETPLACE_YTICA_CONTACT_CENTER_REPORTING_ANALYTICS("marketplace-ytica-contact-center-reporting-analytics"), - MEDIASTORAGE("mediastorage"), - MMS("mms"), - MMS_INBOUND("mms-inbound"), - MMS_INBOUND_LONGCODE("mms-inbound-longcode"), - MMS_INBOUND_SHORTCODE("mms-inbound-shortcode"), - MMS_OUTBOUND("mms-outbound"), - MMS_OUTBOUND_LONGCODE("mms-outbound-longcode"), - MMS_OUTBOUND_SHORTCODE("mms-outbound-shortcode"), - MONITOR_READS("monitor-reads"), - MONITOR_STORAGE("monitor-storage"), - MONITOR_WRITES("monitor-writes"), - NOTIFY("notify"), - NOTIFY_ACTIONS_ATTEMPTS("notify-actions-attempts"), - NOTIFY_CHANNELS("notify-channels"), - NUMBER_FORMAT_LOOKUPS("number-format-lookups"), - PCHAT("pchat"), - PCHAT_ACTIONS("pchat-actions"), - PCHAT_APS("pchat-aps"), - PCHAT_NOTIFICATIONS("pchat-notifications"), - PCHAT_READS("pchat-reads"), - PCHAT_USERS("pchat-users"), - PCHAT_MESSAGES("pchat-messages"), - PEER_TO_PEER_ROOMS_PARTICIPANT_MINUTES("peer-to-peer-rooms-participant-minutes"), - PFAX("pfax"), - PFAX_MINUTES("pfax-minutes"), - PFAX_MINUTES_INBOUND("pfax-minutes-inbound"), - PFAX_MINUTES_OUTBOUND("pfax-minutes-outbound"), - PFAX_PAGES("pfax-pages"), - PHONENUMBERS("phonenumbers"), - PHONENUMBERS_CPS("phonenumbers-cps"), - PHONENUMBERS_EMERGENCY("phonenumbers-emergency"), - PHONENUMBERS_LOCAL("phonenumbers-local"), - PHONENUMBERS_MOBILE("phonenumbers-mobile"), - PHONENUMBERS_SETUPS("phonenumbers-setups"), - PHONENUMBERS_TOLLFREE("phonenumbers-tollfree"), - PREMIUMSUPPORT("premiumsupport"), - PROXY("proxy"), - PV("pv"), - PV_COMPOSITION_MEDIA_DOWNLOADED("pv-composition-media-downloaded"), - PV_COMPOSITION_MEDIA_ENCRYPTED("pv-composition-media-encrypted"), - PV_COMPOSITION_MEDIA_STORED("pv-composition-media-stored"), - PV_COMPOSITION_MINUTES("pv-composition-minutes"), - PV_RECORDING_COMPOSITIONS("pv-recording-compositions"), - PV_ROOM_PARTICIPANTS("pv-room-participants"), - PV_ROOM_PARTICIPANTS_AU1("pv-room-participants-au1"), - PV_ROOM_PARTICIPANTS_BR1("pv-room-participants-br1"), - PV_ROOM_PARTICIPANTS_IE1("pv-room-participants-ie1"), - PV_ROOM_PARTICIPANTS_JP1("pv-room-participants-jp1"), - PV_ROOM_PARTICIPANTS_SG1("pv-room-participants-sg1"), - PV_ROOM_PARTICIPANTS_US1("pv-room-participants-us1"), - PV_ROOM_PARTICIPANTS_US2("pv-room-participants-us2"), - PV_ROOMS("pv-rooms"), - PV_SIP_ENDPOINT_REGISTRATIONS("pv-sip-endpoint-registrations"), - RECORDINGS("recordings"), - RECORDINGSTORAGE("recordingstorage"), - ROOMS_GROUP_MINUTES("rooms-group-minutes"), - ROOMS_GROUP_BANDWIDTH("rooms-group-bandwidth"), - ROOMS_PEER_TO_PEER_MINUTES("rooms-peer-to-peer-minutes"), - SHORTCODES("shortcodes"), - SHORTCODES_CUSTOMEROWNED("shortcodes-customerowned"), - SHORTCODES_MMS_ENABLEMENT("shortcodes-mms-enablement"), - SHORTCODES_MPS("shortcodes-mps"), - SHORTCODES_RANDOM("shortcodes-random"), - SHORTCODES_UK("shortcodes-uk"), - SHORTCODES_VANITY("shortcodes-vanity"), - SMS("sms"), - SMS_INBOUND("sms-inbound"), - SMS_INBOUND_LONGCODE("sms-inbound-longcode"), - SMS_INBOUND_SHORTCODE("sms-inbound-shortcode"), - SMS_OUTBOUND("sms-outbound"), - SMS_OUTBOUND_CONTENT_INSPECTION("sms-outbound-content-inspection"), - SMS_OUTBOUND_LONGCODE("sms-outbound-longcode"), - SMS_OUTBOUND_SHORTCODE("sms-outbound-shortcode"), - SMS_MESSAGES_FEATURES("sms-messages-features"), - SMS_MESSAGES_FEATURES_SENDERID("sms-messages-features-senderid"), - SPEECH_RECOGNITION("speech-recognition"), - STUDIO_ENGAGEMENTS("studio-engagements"), - SYNC("sync"), - SYNC_ACTIONS("sync-actions"), - SYNC_ENDPOINT_HOURS("sync-endpoint-hours"), - SYNC_ENDPOINT_HOURS_ABOVE_DAILY_CAP("sync-endpoint-hours-above-daily-cap"), - TASKROUTER_TASKS("taskrouter-tasks"), - TOTALPRICE("totalprice"), - TRANSCRIPTIONS("transcriptions"), - TRUNKING_CPS("trunking-cps"), - TRUNKING_EMERGENCY_CALLS("trunking-emergency-calls"), - TRUNKING_ORIGINATION("trunking-origination"), - TRUNKING_ORIGINATION_LOCAL("trunking-origination-local"), - TRUNKING_ORIGINATION_MOBILE("trunking-origination-mobile"), - TRUNKING_ORIGINATION_TOLLFREE("trunking-origination-tollfree"), - TRUNKING_RECORDINGS("trunking-recordings"), - TRUNKING_SECURE("trunking-secure"), - TRUNKING_TERMINATION("trunking-termination"), - TURNMEGABYTES("turnmegabytes"), - TURNMEGABYTES_AUSTRALIA("turnmegabytes-australia"), - TURNMEGABYTES_BRASIL("turnmegabytes-brasil"), - TURNMEGABYTES_INDIA("turnmegabytes-india"), - TURNMEGABYTES_IRELAND("turnmegabytes-ireland"), - TURNMEGABYTES_JAPAN("turnmegabytes-japan"), - TURNMEGABYTES_SINGAPORE("turnmegabytes-singapore"), - TURNMEGABYTES_USEAST("turnmegabytes-useast"), - TURNMEGABYTES_USWEST("turnmegabytes-uswest"), - TWILIO_INTERCONNECT("twilio-interconnect"), - VIDEO_RECORDINGS("video-recordings"), - VOICE_INSIGHTS("voice-insights"), - VOICE_INSIGHTS_AUDIO_TRACE("voice-insights-audio-trace"), - VOICE_INSIGHTS_CARRIER_CALLS("voice-insights-carrier-calls"), - WIRELESS("wireless"), - WIRELESS_ORDERS("wireless-orders"), - WIRELESS_ORDERS_ARTWORK("wireless-orders-artwork"), - WIRELESS_ORDERS_BULK("wireless-orders-bulk"), - WIRELESS_ORDERS_ESIM("wireless-orders-esim"), - WIRELESS_ORDERS_STARTER("wireless-orders-starter"), - WIRELESS_USAGE("wireless-usage"), - WIRELESS_USAGE_COMMANDS("wireless-usage-commands"), - WIRELESS_USAGE_COMMANDS_AFRICA("wireless-usage-commands-africa"), - WIRELESS_USAGE_COMMANDS_ASIA("wireless-usage-commands-asia"), - WIRELESS_USAGE_COMMANDS_CENTRALANDSOUTHAMERICA("wireless-usage-commands-centralandsouthamerica"), - WIRELESS_USAGE_COMMANDS_EUROPE("wireless-usage-commands-europe"), - WIRELESS_USAGE_COMMANDS_HOME("wireless-usage-commands-home"), - WIRELESS_USAGE_COMMANDS_NORTHAMERICA("wireless-usage-commands-northamerica"), - WIRELESS_USAGE_COMMANDS_OCEANIA("wireless-usage-commands-oceania"), - WIRELESS_USAGE_COMMANDS_ROAMING("wireless-usage-commands-roaming"), - WIRELESS_USAGE_DATA("wireless-usage-data"), - WIRELESS_USAGE_DATA_AFRICA("wireless-usage-data-africa"), - WIRELESS_USAGE_DATA_ASIA("wireless-usage-data-asia"), - WIRELESS_USAGE_DATA_CENTRALANDSOUTHAMERICA("wireless-usage-data-centralandsouthamerica"), - WIRELESS_USAGE_DATA_CUSTOM_ADDITIONALMB("wireless-usage-data-custom-additionalmb"), - WIRELESS_USAGE_DATA_CUSTOM_FIRST5MB("wireless-usage-data-custom-first5mb"), - WIRELESS_USAGE_DATA_DOMESTIC_ROAMING("wireless-usage-data-domestic-roaming"), - WIRELESS_USAGE_DATA_EUROPE("wireless-usage-data-europe"), - WIRELESS_USAGE_DATA_INDIVIDUAL_ADDITIONALGB("wireless-usage-data-individual-additionalgb"), - WIRELESS_USAGE_DATA_INDIVIDUAL_FIRSTGB("wireless-usage-data-individual-firstgb"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_CANADA("wireless-usage-data-international-roaming-canada"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_INDIA("wireless-usage-data-international-roaming-india"), - WIRELESS_USAGE_DATA_INTERNATIONAL_ROAMING_MEXICO("wireless-usage-data-international-roaming-mexico"), - WIRELESS_USAGE_DATA_NORTHAMERICA("wireless-usage-data-northamerica"), - WIRELESS_USAGE_DATA_OCEANIA("wireless-usage-data-oceania"), - WIRELESS_USAGE_DATA_POOLED("wireless-usage-data-pooled"), - WIRELESS_USAGE_DATA_POOLED_DOWNLINK("wireless-usage-data-pooled-downlink"), - WIRELESS_USAGE_DATA_POOLED_UPLINK("wireless-usage-data-pooled-uplink"), - WIRELESS_USAGE_MRC("wireless-usage-mrc"), - WIRELESS_USAGE_MRC_CUSTOM("wireless-usage-mrc-custom"), - WIRELESS_USAGE_MRC_INDIVIDUAL("wireless-usage-mrc-individual"), - WIRELESS_USAGE_MRC_POOLED("wireless-usage-mrc-pooled"), - WIRELESS_USAGE_MRC_SUSPENDED("wireless-usage-mrc-suspended"), - WIRELESS_USAGE_VOICE("wireless-usage-voice"), - WIRELESS_USAGE_SMS("wireless-usage-sms"); - - private final String value; - - private Category(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - /** - * Generate a Category from a string. - * @param value string value - * @return generated Category - */ - @JsonCreator - public static Category forValue(final String value) { - return Promoter.enumFromString(value, Category.values()); - } + public static YesterdayReader reader() { + return new YesterdayReader(); } - /** - * Create a YesterdayReader to execute read. - * - * @param pathAccountSid The account_sid - * @return YesterdayReader capable of executing the read - */ public static YesterdayReader reader(final String pathAccountSid) { return new YesterdayReader(pathAccountSid); } /** - * Create a YesterdayReader to execute read. - * - * @return YesterdayReader capable of executing the read - */ - public static YesterdayReader reader() { - return new YesterdayReader(); - } - - /** - * Converts a JSON String into a Yesterday object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Yesterday object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Yesterday object represented by the provided JSON */ - public static Yesterday fromJson(final String json, final ObjectMapper objectMapper) { + public static Yesterday fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Yesterday.class); @@ -336,12 +75,15 @@ public static Yesterday fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a Yesterday object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Yesterday object represented by the provided JSON */ - public static Yesterday fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Yesterday fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Yesterday.class); @@ -352,200 +94,107 @@ public static Yesterday fromJson(final InputStream json, final ObjectMapper obje } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String apiVersion; - private final Yesterday.Category category; + + @Getter + private final String asOf; + + @Getter + private final String category; + + @Getter private final String count; + + @Getter private final String countUnit; + + @Getter private final String description; + + @Getter private final LocalDate endDate; + + @Getter private final BigDecimal price; + + @Getter private final Currency priceUnit; + + @Getter private final LocalDate startDate; + + @Getter private final Map subresourceUris; + + @Getter private final String uri; + + @Getter private final String usage; + + @Getter private final String usageUnit; @JsonCreator - private Yesterday(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("category") - final Yesterday.Category category, - @JsonProperty("count") - final String count, - @JsonProperty("count_unit") - final String countUnit, - @JsonProperty("description") - final String description, - @JsonProperty("end_date") - final String endDate, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("start_date") - final String startDate, - @JsonProperty("subresource_uris") - final Map subresourceUris, - @JsonProperty("uri") - final String uri, - @JsonProperty("usage") - final String usage, - @JsonProperty("usage_unit") - final String usageUnit) { + private Yesterday( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("as_of") final String asOf, + @JsonProperty("category") final String category, + @JsonProperty("count") final String count, + @JsonProperty("count_unit") final String countUnit, + @JsonProperty("description") final String description, + @JsonProperty("end_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate endDate, + @JsonProperty("price") final BigDecimal price, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("start_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate startDate, + @JsonProperty("subresource_uris") final Map< + String, + String + > subresourceUris, + @JsonProperty("uri") final String uri, + @JsonProperty("usage") final String usage, + @JsonProperty("usage_unit") final String usageUnit + ) { this.accountSid = accountSid; this.apiVersion = apiVersion; + this.asOf = asOf; this.category = category; this.count = count; this.countUnit = countUnit; this.description = description; - this.endDate = DateConverter.localDateFromString(endDate); + this.endDate = endDate; this.price = price; this.priceUnit = priceUnit; - this.startDate = DateConverter.localDateFromString(startDate); + this.startDate = startDate; this.subresourceUris = subresourceUris; this.uri = uri; this.usage = usage; this.usageUnit = usageUnit; } - /** - * Returns The The Account that accrued the usage.. - * - * @return The Account that accrued the usage. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The category of usage.. - * - * @return The category of usage. - */ - public final Yesterday.Category getCategory() { - return this.category; - } - - /** - * Returns The The number of usage events.. - * - * @return The number of usage events. - */ - public final String getCount() { - return this.count; - } - - /** - * Returns The The units in which Count is measured.. - * - * @return The units in which Count is measured. - */ - public final String getCountUnit() { - return this.countUnit; - } - - /** - * Returns The A human-readable description of the usage category.. - * - * @return A human-readable description of the usage category. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The last date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getEndDate() { - return this.endDate; - } - - /** - * Returns The The total price of the usage, in the currency associated with the - * account.. - * - * @return The total price of the usage, in the currency associated with the - * account. - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The The currency in which Price is measured, in ISO 4127 format.. - * - * @return The currency in which Price is measured, in ISO 4127 format. - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD.. - * - * @return The first date for which usage is included in this UsageRecord, - * formatted as YYYY-MM-DD. - */ - public final LocalDate getStartDate() { - return this.startDate; - } - - /** - * Returns The Subresource Uris for this UsageRecord.. - * - * @return Subresource Uris for this UsageRecord. - */ - public final Map getSubresourceUris() { - return this.subresourceUris; - } - - /** - * Returns The The URI that returns only this UsageRecord, relative to - * https://api.. - * - * @return The URI that returns only this UsageRecord, relative to https://api. - */ - public final String getUri() { - return this.uri; - } - - /** - * Returns The The amount of billed usage.. - * - * @return The amount of billed usage. - */ - public final String getUsage() { - return this.usage; - } - - /** - * Returns The The units in which Usage is measured.. - * - * @return The units in which Usage is measured. - */ - public final String getUsageUnit() { - return this.usageUnit; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -557,58 +206,43 @@ public boolean equals(final Object o) { } Yesterday other = (Yesterday) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(category, other.category) && - Objects.equals(count, other.count) && - Objects.equals(countUnit, other.countUnit) && - Objects.equals(description, other.description) && - Objects.equals(endDate, other.endDate) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(startDate, other.startDate) && - Objects.equals(subresourceUris, other.subresourceUris) && - Objects.equals(uri, other.uri) && - Objects.equals(usage, other.usage) && - Objects.equals(usageUnit, other.usageUnit); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(asOf, other.asOf) && + Objects.equals(category, other.category) && + Objects.equals(count, other.count) && + Objects.equals(countUnit, other.countUnit) && + Objects.equals(description, other.description) && + Objects.equals(endDate, other.endDate) && + Objects.equals(price, other.price) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(startDate, other.startDate) && + Objects.equals(subresourceUris, other.subresourceUris) && + Objects.equals(uri, other.uri) && + Objects.equals(usage, other.usage) && + Objects.equals(usageUnit, other.usageUnit) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - apiVersion, - category, - count, - countUnit, - description, - endDate, - price, - priceUnit, - startDate, - subresourceUris, - uri, - usage, - usageUnit); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("apiVersion", apiVersion) - .add("category", category) - .add("count", count) - .add("countUnit", countUnit) - .add("description", description) - .add("endDate", endDate) - .add("price", price) - .add("priceUnit", priceUnit) - .add("startDate", startDate) - .add("subresourceUris", subresourceUris) - .add("uri", uri) - .add("usage", usage) - .add("usageUnit", usageUnit) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + apiVersion, + asOf, + category, + count, + countUnit, + description, + endDate, + price, + priceUnit, + startDate, + subresourceUris, + uri, + usage, + usageUnit + ); + } +} diff --git a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YesterdayReader.java b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YesterdayReader.java index 6489c55678..2c81b5888a 100644 --- a/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YesterdayReader.java +++ b/src/main/java/com/twilio/rest/api/v2010/account/usage/record/YesterdayReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Api + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.api.v2010.account.usage.record; @@ -10,240 +17,265 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; public class YesterdayReader extends Reader { + private String pathAccountSid; - private Yesterday.Category category; + private String category; private LocalDate startDate; private LocalDate endDate; private Boolean includeSubaccounts; + private Long pageSize; - /** - * Construct a new YesterdayReader. - */ - public YesterdayReader() { - } + public YesterdayReader() {} - /** - * Construct a new YesterdayReader. - * - * @param pathAccountSid The account_sid - */ public YesterdayReader(final String pathAccountSid) { this.pathAccountSid = pathAccountSid; } - /** - * Only include usage of this [usage - * category](https://www.twilio.com/docs/api/rest/usage-records#usage-categories).. - * - * @param category Only include usage of this usage category. - * @return this - */ - public YesterdayReader setCategory(final Yesterday.Category category) { + public YesterdayReader setCategory(final String category) { this.category = category; return this; } - /** - * Only include usage that has occurred on or after this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `StartDate=-30days` will make `StartDate` be - * 30 days before today.. - * - * @param startDate Only include usage that has occurred on or after this date. - * @return this - */ public YesterdayReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only include usage that has occurred on or before this date. Format is - * YYYY-MM-DD. All dates are in GMT. As a convenience, you can also specify - * offsets to today. For example, `EndDate=+30days` will make `EndDate` be 30 - * days from today.. - * - * @param endDate Only include usage that has occurred on or before this date. - * @return this - */ public YesterdayReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * The include_subaccounts. - * - * @param includeSubaccounts The include_subaccounts - * @return this - */ - public YesterdayReader setIncludeSubaccounts(final Boolean includeSubaccounts) { + public YesterdayReader setIncludeSubaccounts( + final Boolean includeSubaccounts + ) { this.includeSubaccounts = includeSubaccounts; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Yesterday ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public YesterdayReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Yesterday ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Yesterday.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/2010-04-01/Accounts/{AccountSid}/Usage/Records/Yesterday.json"; + + this.pathAccountSid = + this.pathAccountSid == null + ? client.getAccountSid() + : this.pathAccountSid; + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.API.toString(), - "/2010-04-01/Accounts/" + this.pathAccountSid + "/Usage/Records/Yesterday.json", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Yesterday ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid; - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + Yesterday.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Yesterday read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + Yesterday.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.API.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Yesterday Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Yesterday read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "usage_records", - response.getContent(), - Yesterday.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (category != null) { - request.addQueryParam("Category", category.toString()); + Serializer.toString( + request, + "Category", + category, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (includeSubaccounts != null) { - request.addQueryParam("IncludeSubaccounts", includeSubaccounts.toString()); + Serializer.toString( + request, + "IncludeSubaccounts", + includeSubaccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/Export.java b/src/main/java/com/twilio/rest/bulkexports/v1/Export.java new file mode 100644 index 0000000000..ab171ca5bc --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/Export.java @@ -0,0 +1,144 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Export extends Resource { + + public static ExportFetcher fetcher(final String pathResourceType) { + return new ExportFetcher(pathResourceType); + } + + /** + * Converts a JSON String into a Export object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Export object represented by the provided JSON + */ + public static Export fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Export.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Export object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Export object represented by the provided JSON + */ + public static Export fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Export.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Map links; + + @Getter + private final String resourceType; + + @Getter + private final URI url; + + @JsonCreator + private Export( + @JsonProperty("links") final Map links, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("url") final URI url + ) { + this.links = links; + this.resourceType = resourceType; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Export other = (Export) o; + return ( + Objects.equals(links, other.links) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(links, resourceType, url); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfiguration.java b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfiguration.java new file mode 100644 index 0000000000..c519cb6a83 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfiguration.java @@ -0,0 +1,169 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExportConfiguration extends Resource { + + public static ExportConfigurationFetcher fetcher( + final String pathResourceType + ) { + return new ExportConfigurationFetcher(pathResourceType); + } + + public static ExportConfigurationUpdater updater( + final String pathResourceType + ) { + return new ExportConfigurationUpdater(pathResourceType); + } + + /** + * Converts a JSON String into a ExportConfiguration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExportConfiguration object represented by the provided JSON + */ + public static ExportConfiguration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExportConfiguration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExportConfiguration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExportConfiguration object represented by the provided JSON + */ + public static ExportConfiguration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExportConfiguration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean enabled; + + @Getter + private final String resourceType; + + @Getter + private final URI url; + + @Getter + private final String webhookMethod; + + @Getter + private final URI webhookUrl; + + @JsonCreator + private ExportConfiguration( + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhook_url") final URI webhookUrl + ) { + this.enabled = enabled; + this.resourceType = resourceType; + this.url = url; + this.webhookMethod = webhookMethod; + this.webhookUrl = webhookUrl; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExportConfiguration other = (ExportConfiguration) o; + return ( + Objects.equals(enabled, other.enabled) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(url, other.url) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhookUrl, other.webhookUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + enabled, + resourceType, + url, + webhookMethod, + webhookUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationFetcher.java b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationFetcher.java new file mode 100644 index 0000000000..fd0c722eff --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExportConfigurationFetcher extends Fetcher { + + private String pathResourceType; + + public ExportConfigurationFetcher(final String pathResourceType) { + this.pathResourceType = pathResourceType; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Exports/{ResourceType}/Configuration"; + + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.BULKEXPORTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExportConfiguration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExportConfiguration fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExportConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExportConfiguration content = ExportConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationUpdater.java b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationUpdater.java new file mode 100644 index 0000000000..cee82b6c9d --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/ExportConfigurationUpdater.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class ExportConfigurationUpdater extends Updater { + + private String pathResourceType; + private Boolean enabled; + private URI webhookUrl; + private String webhookMethod; + + public ExportConfigurationUpdater(final String pathResourceType) { + this.pathResourceType = pathResourceType; + } + + public ExportConfigurationUpdater setEnabled(final Boolean enabled) { + this.enabled = enabled; + return this; + } + + public ExportConfigurationUpdater setWebhookUrl(final URI webhookUrl) { + this.webhookUrl = webhookUrl; + return this; + } + + public ExportConfigurationUpdater setWebhookUrl(final String webhookUrl) { + return setWebhookUrl(Promoter.uriFromString(webhookUrl)); + } + + public ExportConfigurationUpdater setWebhookMethod( + final String webhookMethod + ) { + this.webhookMethod = webhookMethod; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Exports/{ResourceType}/Configuration"; + + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.BULKEXPORTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExportConfiguration update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExportConfiguration update(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExportConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExportConfiguration content = ExportConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (enabled != null) { + Serializer.toString( + request, + "Enabled", + enabled, + ParameterType.URLENCODED + ); + } + + if (webhookUrl != null) { + Serializer.toString( + request, + "WebhookUrl", + webhookUrl, + ParameterType.URLENCODED + ); + } + + if (webhookMethod != null) { + Serializer.toString( + request, + "WebhookMethod", + webhookMethod, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/ExportFetcher.java b/src/main/java/com/twilio/rest/bulkexports/v1/ExportFetcher.java new file mode 100644 index 0000000000..a766c9d1c8 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/ExportFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExportFetcher extends Fetcher { + + private String pathResourceType; + + public ExportFetcher(final String pathResourceType) { + this.pathResourceType = pathResourceType; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Exports/{ResourceType}"; + + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.BULKEXPORTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Export fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Export fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Export.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Export content = Export.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/Day.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/Day.java new file mode 100644 index 0000000000..642616aa70 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/Day.java @@ -0,0 +1,175 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Day extends Resource { + + public static DayFetcher fetcher( + final String pathResourceType, + final String pathDay + ) { + return new DayFetcher(pathResourceType, pathDay); + } + + public static DayReader reader(final String pathResourceType) { + return new DayReader(pathResourceType); + } + + /** + * Converts a JSON String into a Day object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Day object represented by the provided JSON + */ + public static Day fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Day.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Day object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Day object represented by the provided JSON + */ + public static Day fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Day.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String createDate; + + @Getter + private final String day; + + @Getter + private final String friendlyName; + + @Getter + private final URI redirectTo; + + @Getter + private final String resourceType; + + @Getter + private final Integer size; + + @JsonCreator + private Day( + @JsonProperty("create_date") final String createDate, + @JsonProperty("day") final String day, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("redirect_to") final URI redirectTo, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("size") final Integer size + ) { + this.createDate = createDate; + this.day = day; + this.friendlyName = friendlyName; + this.redirectTo = redirectTo; + this.resourceType = resourceType; + this.size = size; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Day other = (Day) o; + return ( + Objects.equals(createDate, other.createDate) && + Objects.equals(day, other.day) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(redirectTo, other.redirectTo) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(size, other.size) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createDate, + day, + friendlyName, + redirectTo, + resourceType, + size + ); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/DayFetcher.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/DayFetcher.java new file mode 100644 index 0000000000..e6c86c9819 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/DayFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DayFetcher extends Fetcher { + + private String pathResourceType; + private String pathDay; + + public DayFetcher(final String pathResourceType, final String pathDay) { + this.pathResourceType = pathResourceType; + this.pathDay = pathDay; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Exports/{ResourceType}/Days/{Day}"; + + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + path = path.replace("{" + "Day" + "}", this.pathDay.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.BULKEXPORTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Day fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Day fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Day.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Day content = Day.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/DayReader.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/DayReader.java new file mode 100644 index 0000000000..8c164604a9 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/DayReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DayReader extends Reader { + + private String pathResourceType; + private Long pageSize; + + public DayReader(final String pathResourceType) { + this.pathResourceType = pathResourceType; + } + + public DayReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "days", + response.getContent(), + Day.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Exports/{ResourceType}/Days"; + + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.BULKEXPORTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "days", + response.getContent(), + Day.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Day read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "days", + response.getContent(), + Day.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJob.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJob.java new file mode 100644 index 0000000000..83e9ae5e90 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJob.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExportCustomJob extends Resource { + + public static ExportCustomJobCreator creator( + final String pathResourceType, + final String startDay, + final String endDay, + final String friendlyName + ) { + return new ExportCustomJobCreator( + pathResourceType, + startDay, + endDay, + friendlyName + ); + } + + public static ExportCustomJobReader reader(final String pathResourceType) { + return new ExportCustomJobReader(pathResourceType); + } + + /** + * Converts a JSON String into a ExportCustomJob object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExportCustomJob object represented by the provided JSON + */ + public static ExportCustomJob fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExportCustomJob.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExportCustomJob object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExportCustomJob object represented by the provided JSON + */ + public static ExportCustomJob fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExportCustomJob.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List details; + + @Getter + private final String email; + + @Getter + private final String endDay; + + @Getter + private final String estimatedCompletionTime; + + @Getter + private final String friendlyName; + + @Getter + private final String jobQueuePosition; + + @Getter + private final String jobSid; + + @Getter + private final String resourceType; + + @Getter + private final String startDay; + + @Getter + private final String webhookMethod; + + @Getter + private final String webhookUrl; + + @JsonCreator + private ExportCustomJob( + @JsonProperty("details") final List details, + @JsonProperty("email") final String email, + @JsonProperty("end_day") final String endDay, + @JsonProperty( + "estimated_completion_time" + ) final String estimatedCompletionTime, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("job_queue_position") final String jobQueuePosition, + @JsonProperty("job_sid") final String jobSid, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("start_day") final String startDay, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhook_url") final String webhookUrl + ) { + this.details = details; + this.email = email; + this.endDay = endDay; + this.estimatedCompletionTime = estimatedCompletionTime; + this.friendlyName = friendlyName; + this.jobQueuePosition = jobQueuePosition; + this.jobSid = jobSid; + this.resourceType = resourceType; + this.startDay = startDay; + this.webhookMethod = webhookMethod; + this.webhookUrl = webhookUrl; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExportCustomJob other = (ExportCustomJob) o; + return ( + Objects.equals(details, other.details) && + Objects.equals(email, other.email) && + Objects.equals(endDay, other.endDay) && + Objects.equals( + estimatedCompletionTime, + other.estimatedCompletionTime + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(jobQueuePosition, other.jobQueuePosition) && + Objects.equals(jobSid, other.jobSid) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(startDay, other.startDay) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhookUrl, other.webhookUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + details, + email, + endDay, + estimatedCompletionTime, + friendlyName, + jobQueuePosition, + jobSid, + resourceType, + startDay, + webhookMethod, + webhookUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobCreator.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobCreator.java new file mode 100644 index 0000000000..b5778f4188 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobCreator.java @@ -0,0 +1,205 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExportCustomJobCreator extends Creator { + + private String pathResourceType; + private String startDay; + private String endDay; + private String friendlyName; + private String webhookUrl; + private String webhookMethod; + private String email; + + public ExportCustomJobCreator( + final String pathResourceType, + final String startDay, + final String endDay, + final String friendlyName + ) { + this.pathResourceType = pathResourceType; + this.startDay = startDay; + this.endDay = endDay; + this.friendlyName = friendlyName; + } + + public ExportCustomJobCreator setStartDay(final String startDay) { + this.startDay = startDay; + return this; + } + + public ExportCustomJobCreator setEndDay(final String endDay) { + this.endDay = endDay; + return this; + } + + public ExportCustomJobCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ExportCustomJobCreator setWebhookUrl(final String webhookUrl) { + this.webhookUrl = webhookUrl; + return this; + } + + public ExportCustomJobCreator setWebhookMethod(final String webhookMethod) { + this.webhookMethod = webhookMethod; + return this; + } + + public ExportCustomJobCreator setEmail(final String email) { + this.email = email; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Exports/{ResourceType}/Jobs"; + + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.BULKEXPORTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExportCustomJob creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExportCustomJob create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExportCustomJob.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExportCustomJob content = ExportCustomJob.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (startDay != null) { + Serializer.toString( + request, + "StartDay", + startDay, + ParameterType.URLENCODED + ); + } + + if (endDay != null) { + Serializer.toString( + request, + "EndDay", + endDay, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (webhookUrl != null) { + Serializer.toString( + request, + "WebhookUrl", + webhookUrl, + ParameterType.URLENCODED + ); + } + + if (webhookMethod != null) { + Serializer.toString( + request, + "WebhookMethod", + webhookMethod, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobReader.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobReader.java new file mode 100644 index 0000000000..42d4d16f2c --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/ExportCustomJobReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExportCustomJobReader extends Reader { + + private String pathResourceType; + private Long pageSize; + + public ExportCustomJobReader(final String pathResourceType) { + this.pathResourceType = pathResourceType; + } + + public ExportCustomJobReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "jobs", + response.getContent(), + ExportCustomJob.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Exports/{ResourceType}/Jobs"; + + path = + path.replace( + "{" + "ResourceType" + "}", + this.pathResourceType.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.BULKEXPORTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "jobs", + response.getContent(), + ExportCustomJob.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ExportCustomJob read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "jobs", + response.getContent(), + ExportCustomJob.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/Job.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/Job.java new file mode 100644 index 0000000000..c350129ec9 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/Job.java @@ -0,0 +1,220 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Job extends Resource { + + public static JobDeleter deleter(final String pathJobSid) { + return new JobDeleter(pathJobSid); + } + + public static JobFetcher fetcher(final String pathJobSid) { + return new JobFetcher(pathJobSid); + } + + /** + * Converts a JSON String into a Job object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Job object represented by the provided JSON + */ + public static Job fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Job.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Job object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Job object represented by the provided JSON + */ + public static Job fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Job.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List details; + + @Getter + private final String email; + + @Getter + private final String endDay; + + @Getter + private final String estimatedCompletionTime; + + @Getter + private final String friendlyName; + + @Getter + private final String jobQueuePosition; + + @Getter + private final String jobSid; + + @Getter + private final String resourceType; + + @Getter + private final String startDay; + + @Getter + private final URI url; + + @Getter + private final String webhookMethod; + + @Getter + private final String webhookUrl; + + @JsonCreator + private Job( + @JsonProperty("details") final List details, + @JsonProperty("email") final String email, + @JsonProperty("end_day") final String endDay, + @JsonProperty( + "estimated_completion_time" + ) final String estimatedCompletionTime, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("job_queue_position") final String jobQueuePosition, + @JsonProperty("job_sid") final String jobSid, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("start_day") final String startDay, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhook_url") final String webhookUrl + ) { + this.details = details; + this.email = email; + this.endDay = endDay; + this.estimatedCompletionTime = estimatedCompletionTime; + this.friendlyName = friendlyName; + this.jobQueuePosition = jobQueuePosition; + this.jobSid = jobSid; + this.resourceType = resourceType; + this.startDay = startDay; + this.url = url; + this.webhookMethod = webhookMethod; + this.webhookUrl = webhookUrl; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Job other = (Job) o; + return ( + Objects.equals(details, other.details) && + Objects.equals(email, other.email) && + Objects.equals(endDay, other.endDay) && + Objects.equals( + estimatedCompletionTime, + other.estimatedCompletionTime + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(jobQueuePosition, other.jobQueuePosition) && + Objects.equals(jobSid, other.jobSid) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(startDay, other.startDay) && + Objects.equals(url, other.url) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhookUrl, other.webhookUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + details, + email, + endDay, + estimatedCompletionTime, + friendlyName, + jobQueuePosition, + jobSid, + resourceType, + startDay, + url, + webhookMethod, + webhookUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/JobDeleter.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/JobDeleter.java new file mode 100644 index 0000000000..baa9afb160 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/JobDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class JobDeleter extends Deleter { + + private String pathJobSid; + + public JobDeleter(final String pathJobSid) { + this.pathJobSid = pathJobSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Exports/Jobs/{JobSid}"; + + path = path.replace("{" + "JobSid" + "}", this.pathJobSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.BULKEXPORTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Job delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/bulkexports/v1/export/JobFetcher.java b/src/main/java/com/twilio/rest/bulkexports/v1/export/JobFetcher.java new file mode 100644 index 0000000000..44ca8b7739 --- /dev/null +++ b/src/main/java/com/twilio/rest/bulkexports/v1/export/JobFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Bulkexports + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.bulkexports.v1.export; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class JobFetcher extends Fetcher { + + private String pathJobSid; + + public JobFetcher(final String pathJobSid) { + this.pathJobSid = pathJobSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Exports/Jobs/{JobSid}"; + + path = path.replace("{" + "JobSid" + "}", this.pathJobSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.BULKEXPORTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Job fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Job fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Job.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Job content = Job.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/Credential.java b/src/main/java/com/twilio/rest/chat/v1/Credential.java index e635a6cc01..c23565a123 100644 --- a/src/main/java/com/twilio/rest/chat/v1/Credential.java +++ b/src/main/java/com/twilio/rest/chat/v1/Credential.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; @@ -10,32 +17,52 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Credential extends Resource { - private static final long serialVersionUID = 133884911230690L; + + public static CredentialCreator creator(final Credential.PushService type) { + return new CredentialCreator(type); + } + + public static CredentialDeleter deleter(final String pathSid) { + return new CredentialDeleter(pathSid); + } + + public static CredentialFetcher fetcher(final String pathSid) { + return new CredentialFetcher(pathSid); + } + + public static CredentialReader reader() { + return new CredentialReader(); + } + + public static CredentialUpdater updater(final String pathSid) { + return new CredentialUpdater(pathSid); + } public enum PushService { GCM("gcm"), @@ -48,15 +75,11 @@ private PushService(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a PushService from a string. - * @param value string value - * @return generated PushService - */ @JsonCreator public static PushService forValue(final String value) { return Promoter.enumFromString(value, PushService.values()); @@ -64,63 +87,16 @@ public static PushService forValue(final String value) { } /** - * Create a CredentialReader to execute read. - * - * @return CredentialReader capable of executing the read - */ - public static CredentialReader reader() { - return new CredentialReader(); - } - - /** - * Create a CredentialCreator to execute create. - * - * @param type Credential type, one of "gcm" or "apn" - * @return CredentialCreator capable of executing the create - */ - public static CredentialCreator creator(final Credential.PushService type) { - return new CredentialCreator(type); - } - - /** - * Create a CredentialFetcher to execute fetch. - * - * @param pathSid The sid - * @return CredentialFetcher capable of executing the fetch - */ - public static CredentialFetcher fetcher(final String pathSid) { - return new CredentialFetcher(pathSid); - } - - /** - * Create a CredentialUpdater to execute update. - * - * @param pathSid The sid - * @return CredentialUpdater capable of executing the update - */ - public static CredentialUpdater updater(final String pathSid) { - return new CredentialUpdater(pathSid); - } - - /** - * Create a CredentialDeleter to execute delete. - * - * @param pathSid The sid - * @return CredentialDeleter capable of executing the delete - */ - public static CredentialDeleter deleter(final String pathSid) { - return new CredentialDeleter(pathSid); - } - - /** - * Converts a JSON String into a Credential object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -134,12 +110,15 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a Credential object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -150,119 +129,73 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final Credential.PushService type; + + @Getter private final String sandbox; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final Credential.PushService type; + + @Getter private final URI url; @JsonCreator - private Credential(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Credential.PushService type, - @JsonProperty("sandbox") - final String sandbox, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Credential( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.type = type; this.sandbox = sandbox; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.sid = sid; + this.type = type; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account[/console] responsible for this - * resource.. - * - * @return The unique id of the Account[/console] responsible for this resource. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The human-readable name of this resource.. - * - * @return The human-readable name of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The Indicates which push notifications service this credential is for - * - either gcm or apn. - * - * @return Indicates which push notifications service this credential is for - - * either gcm or apn - */ - public final Credential.PushService getType() { - return this.type; - } - - /** - * Returns The [APN only] true when this resource should use the sandbox APN - * service.. - * - * @return [APN only] true when this resource should use the sandbox APN - * service. - */ - public final String getSandbox() { - return this.sandbox; - } - - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The An absolute URL for this credential resource.. - * - * @return An absolute URL for this credential resource. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -274,40 +207,29 @@ public boolean equals(final Object o) { } Credential other = (Credential) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(sandbox, other.sandbox) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - type, - sandbox, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("sandbox", sandbox) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sandbox, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialCreator.java b/src/main/java/com/twilio/rest/chat/v1/CredentialCreator.java index d1d553c271..40e8d7e146 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,9 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialCreator extends Creator { - private final Credential.PushService type; + + private Credential.PushService type; private String friendlyName; private String certificate; private String privateKey; @@ -26,161 +40,166 @@ public class CredentialCreator extends Creator { private String apiKey; private String secret; - /** - * Construct a new CredentialCreator. - * - * @param type Credential type, one of "gcm" or "apn" - */ public CredentialCreator(final Credential.PushService type) { this.type = type; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ + public CredentialCreator setType(final Credential.PushService type) { + this.type = type; + return this; + } + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate, e.g. `-----BEGIN - * CERTIFICATE-----MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A==-----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate, - * e. - * @return this - */ public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key, e.g. `-----BEGIN - * RSA PRIVATE - * KEY-----MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR\n.-----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key, - * e. - * @return this - */ public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "API key" for project from Google Developer console - * for your GCM Service application credential. - * - * @param apiKey [GCM only] This is the "API key" for project from Google - * Developer console for your GCM Service application credential - * @return this - */ public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * The secret. - * - * @param secret The secret - * @return this - */ public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials"; + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Credentials", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialDeleter.java b/src/main/java/com/twilio/rest/chat/v1/CredentialDeleter.java index b28f159370..6489fe72c9 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class CredentialDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new CredentialDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialFetcher.java b/src/main/java/com/twilio/rest/chat/v1/CredentialFetcher.java index 7213107ed5..ecc7555193 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new CredentialFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialReader.java b/src/main/java/com/twilio/rest/chat/v1/CredentialReader.java index 9b2c884a84..6cac6be33b 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public CredentialReader() {} + + public CredentialReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Credentials"; + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Credentials", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Credential Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credentials", - response.getContent(), - Credential.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/CredentialUpdater.java b/src/main/java/com/twilio/rest/chat/v1/CredentialUpdater.java index 4bcccb3ee6..2afd60a870 100644 --- a/src/main/java/com/twilio/rest/chat/v1/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/CredentialUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,9 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String certificate; private String privateKey; @@ -26,157 +40,154 @@ public class CredentialUpdater extends Updater { private String apiKey; private String secret; - /** - * Construct a new CredentialUpdater. - * - * @param pathSid The sid - */ public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate, e.g. `-----BEGIN - * CERTIFICATE-----MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A==-----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate, - * e. - * @return this - */ public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key, e.g. `-----BEGIN - * RSA PRIVATE - * KEY-----MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR\n.-----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key, - * e. - * @return this - */ public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "API key" for project from Google Developer console - * for your GCM Service application credential. - * - * @param apiKey [GCM only] This is the "API key" for project from Google - * Developer console for your GCM Service application credential - * @return this - */ public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * The secret. - * - * @param secret The secret - * @return this - */ public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Credential update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/Service.java b/src/main/java/com/twilio/rest/chat/v1/Service.java index 6baf46b383..178993a414 100644 --- a/src/main/java/com/twilio/rest/chat/v1/Service.java +++ b/src/main/java/com/twilio/rest/chat/v1/Service.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; @@ -11,90 +18,63 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Service extends Resource { - private static final long serialVersionUID = 209287578457944L; - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid The sid - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); + public static ServiceCreator creator(final String friendlyName) { + return new ServiceCreator(friendlyName); } - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid The sid - * @return ServiceDeleter capable of executing the delete - */ public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - /** - * Create a ServiceCreator to execute create. - * - * @param friendlyName Human-readable name for this service instance - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator(final String friendlyName) { - return new ServiceCreator(friendlyName); + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); } - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ public static ServiceReader reader() { return new ServiceReader(); } - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid The sid - * @return ServiceUpdater capable of executing the update - */ public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** * Converts a JSON String into a Service object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -108,12 +88,15 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Service object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -124,296 +107,146 @@ public static Service fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String defaultServiceRoleSid; - private final String defaultChannelRoleSid; - private final String defaultChannelCreatorRoleSid; - private final Boolean readStatusEnabled; - private final Boolean reachabilityEnabled; - private final Integer typingIndicatorTimeout; - private final Integer consumptionReportInterval; - private final Map limits; - private final Map webhooks; - private final String preWebhookUrl; - private final String postWebhookUrl; - private final String webhookMethod; - private final List webhookFilters; - private final Map notifications; - private final URI url; - private final Map links; - - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("default_service_role_sid") - final String defaultServiceRoleSid, - @JsonProperty("default_channel_role_sid") - final String defaultChannelRoleSid, - @JsonProperty("default_channel_creator_role_sid") - final String defaultChannelCreatorRoleSid, - @JsonProperty("read_status_enabled") - final Boolean readStatusEnabled, - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled, - @JsonProperty("typing_indicator_timeout") - final Integer typingIndicatorTimeout, - @JsonProperty("consumption_report_interval") - final Integer consumptionReportInterval, - @JsonProperty("limits") - final Map limits, - @JsonProperty("webhooks") - final Map webhooks, - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - @JsonProperty("webhook_method") - final String webhookMethod, - @JsonProperty("webhook_filters") - final List webhookFilters, - @JsonProperty("notifications") - final Map notifications, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.defaultServiceRoleSid = defaultServiceRoleSid; - this.defaultChannelRoleSid = defaultChannelRoleSid; - this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; - this.readStatusEnabled = readStatusEnabled; - this.reachabilityEnabled = reachabilityEnabled; - this.typingIndicatorTimeout = typingIndicatorTimeout; - this.consumptionReportInterval = consumptionReportInterval; - this.limits = limits; - this.webhooks = webhooks; - this.preWebhookUrl = preWebhookUrl; - this.postWebhookUrl = postWebhookUrl; - this.webhookMethod = webhookMethod; - this.webhookFilters = webhookFilters; - this.notifications = notifications; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this service.. - * - * @return The unique id of the Account responsible for this service. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Integer consumptionReportInterval; - /** - * Returns The The human-readable name of this service.. - * - * @return The human-readable name of this service. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String defaultChannelCreatorRoleSid; - /** - * Returns The The service role assigned to users when they are added to the - * service.. - * - * @return The service role assigned to users when they are added to the - * service. - */ - public final String getDefaultServiceRoleSid() { - return this.defaultServiceRoleSid; - } + @Getter + private final String defaultChannelRoleSid; - /** - * Returns The The channel role assigned to users when they are added to a - * channel.. - * - * @return The channel role assigned to users when they are added to a channel. - */ - public final String getDefaultChannelRoleSid() { - return this.defaultChannelRoleSid; - } + @Getter + private final String defaultServiceRoleSid; - /** - * Returns The The channel role assigned to a channel creator when joining a new - * channel.. - * - * @return The channel role assigned to a channel creator when joining a new - * channel. - */ - public final String getDefaultChannelCreatorRoleSid() { - return this.defaultChannelCreatorRoleSid; - } + @Getter + private final String friendlyName; - /** - * Returns The Enable the Message Constumption Horizon feature.. - * - * @return Enable the Message Constumption Horizon feature. - */ - public final Boolean getReadStatusEnabled() { - return this.readStatusEnabled; - } + @Getter + private final Object limits; - /** - * Returns The Indicates whether the the Reachability feature is enabled for - * this Service instance.. - * - * @return Indicates whether the the Reachability feature is enabled for this - * Service instance. - */ - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } + @Getter + private final Map links; - /** - * Returns The The amount of time after a "started typing" event when clients - * should assume that user is no longer typing, even if no "ended typing" - * message was received.. - * - * @return The amount of time after a "started typing" event when clients - * should assume that user is no longer typing, even if no "ended - * typing" message was received. - */ - public final Integer getTypingIndicatorTimeout() { - return this.typingIndicatorTimeout; - } + @Getter + private final Object notifications; - /** - * Returns The The interval between consumption reports submission batches from - * client endpoints.. - * - * @return The interval between consumption reports submission batches from - * client endpoints. - */ - public final Integer getConsumptionReportInterval() { - return this.consumptionReportInterval; - } + @Getter + private final String postWebhookUrl; - /** - * Returns The The limits. - * - * @return The limits - */ - public final Map getLimits() { - return this.limits; - } + @Getter + private final String preWebhookUrl; - /** - * Returns The The webhooks. - * - * @return The webhooks - */ - public final Map getWebhooks() { - return this.webhooks; - } + @Getter + private final Boolean reachabilityEnabled; - /** - * Returns The The webhook URL for PRE-Event webhooks.. - * - * @return The webhook URL for PRE-Event webhooks. - */ - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } + @Getter + private final Boolean readStatusEnabled; - /** - * Returns The The webhook URL for POST-Event webhooks.. - * - * @return The webhook URL for POST-Event webhooks. - */ - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } + @Getter + private final String sid; - /** - * Returns The The webhook request format to use.. - * - * @return The webhook request format to use. - */ - public final String getWebhookMethod() { - return this.webhookMethod; - } + @Getter + private final Integer typingIndicatorTimeout; - /** - * Returns The The list of WebHook events that are enabled for this Service - * instance.. - * - * @return The list of WebHook events that are enabled for this Service - * instance. - */ - public final List getWebhookFilters() { - return this.webhookFilters; - } + @Getter + private final URI url; - /** - * Returns The Notification configuration for the Service instance.. - * - * @return Notification configuration for the Service instance. - */ - public final Map getNotifications() { - return this.notifications; - } + @Getter + private final List webhookFilters; - /** - * Returns The An absolute URL for this service.. - * - * @return An absolute URL for this service. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String webhookMethod; - /** - * Returns The URLs to access the Channels, Roles, and Users for this service.. - * - * @return URLs to access the Channels, Roles, and Users for this service. - */ - public final Map getLinks() { - return this.links; + @Getter + private final Object webhooks; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "consumption_report_interval" + ) final Integer consumptionReportInterval, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "default_channel_creator_role_sid" + ) final String defaultChannelCreatorRoleSid, + @JsonProperty( + "default_channel_role_sid" + ) final String defaultChannelRoleSid, + @JsonProperty( + "default_service_role_sid" + ) final String defaultServiceRoleSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("limits") final Object limits, + @JsonProperty("links") final Map links, + @JsonProperty("notifications") final Object notifications, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty("read_status_enabled") final Boolean readStatusEnabled, + @JsonProperty("sid") final String sid, + @JsonProperty( + "typing_indicator_timeout" + ) final Integer typingIndicatorTimeout, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_filters") final List webhookFilters, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhooks") final Object webhooks + ) { + this.accountSid = accountSid; + this.consumptionReportInterval = consumptionReportInterval; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; + this.defaultChannelRoleSid = defaultChannelRoleSid; + this.defaultServiceRoleSid = defaultServiceRoleSid; + this.friendlyName = friendlyName; + this.limits = limits; + this.links = links; + this.notifications = notifications; + this.postWebhookUrl = postWebhookUrl; + this.preWebhookUrl = preWebhookUrl; + this.reachabilityEnabled = reachabilityEnabled; + this.readStatusEnabled = readStatusEnabled; + this.sid = sid; + this.typingIndicatorTimeout = typingIndicatorTimeout; + this.url = url; + this.webhookFilters = webhookFilters; + this.webhookMethod = webhookMethod; + this.webhooks = webhooks; } @Override @@ -427,79 +260,70 @@ public boolean equals(final Object o) { } Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(defaultServiceRoleSid, other.defaultServiceRoleSid) && - Objects.equals(defaultChannelRoleSid, other.defaultChannelRoleSid) && - Objects.equals(defaultChannelCreatorRoleSid, other.defaultChannelCreatorRoleSid) && - Objects.equals(readStatusEnabled, other.readStatusEnabled) && - Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && - Objects.equals(typingIndicatorTimeout, other.typingIndicatorTimeout) && - Objects.equals(consumptionReportInterval, other.consumptionReportInterval) && - Objects.equals(limits, other.limits) && - Objects.equals(webhooks, other.webhooks) && - Objects.equals(preWebhookUrl, other.preWebhookUrl) && - Objects.equals(postWebhookUrl, other.postWebhookUrl) && - Objects.equals(webhookMethod, other.webhookMethod) && - Objects.equals(webhookFilters, other.webhookFilters) && - Objects.equals(notifications, other.notifications) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + consumptionReportInterval, + other.consumptionReportInterval + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultChannelCreatorRoleSid, + other.defaultChannelCreatorRoleSid + ) && + Objects.equals( + defaultChannelRoleSid, + other.defaultChannelRoleSid + ) && + Objects.equals( + defaultServiceRoleSid, + other.defaultServiceRoleSid + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(limits, other.limits) && + Objects.equals(links, other.links) && + Objects.equals(notifications, other.notifications) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals(readStatusEnabled, other.readStatusEnabled) && + Objects.equals(sid, other.sid) && + Objects.equals( + typingIndicatorTimeout, + other.typingIndicatorTimeout + ) && + Objects.equals(url, other.url) && + Objects.equals(webhookFilters, other.webhookFilters) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhooks, other.webhooks) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - defaultServiceRoleSid, - defaultChannelRoleSid, - defaultChannelCreatorRoleSid, - readStatusEnabled, - reachabilityEnabled, - typingIndicatorTimeout, - consumptionReportInterval, - limits, - webhooks, - preWebhookUrl, - postWebhookUrl, - webhookMethod, - webhookFilters, - notifications, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("defaultServiceRoleSid", defaultServiceRoleSid) - .add("defaultChannelRoleSid", defaultChannelRoleSid) - .add("defaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid) - .add("readStatusEnabled", readStatusEnabled) - .add("reachabilityEnabled", reachabilityEnabled) - .add("typingIndicatorTimeout", typingIndicatorTimeout) - .add("consumptionReportInterval", consumptionReportInterval) - .add("limits", limits) - .add("webhooks", webhooks) - .add("preWebhookUrl", preWebhookUrl) - .add("postWebhookUrl", postWebhookUrl) - .add("webhookMethod", webhookMethod) - .add("webhookFilters", webhookFilters) - .add("notifications", notifications) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + consumptionReportInterval, + dateCreated, + dateUpdated, + defaultChannelCreatorRoleSid, + defaultChannelRoleSid, + defaultServiceRoleSid, + friendlyName, + limits, + links, + notifications, + postWebhookUrl, + preWebhookUrl, + reachabilityEnabled, + readStatusEnabled, + sid, + typingIndicatorTimeout, + url, + webhookFilters, + webhookMethod, + webhooks + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/chat/v1/ServiceCreator.java index 49c0fd09d5..1d016bce2c 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +27,86 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceCreator extends Creator { - private final String friendlyName; - /** - * Construct a new ServiceCreator. - * - * @param friendlyName Human-readable name for this service instance - */ + private String friendlyName; + public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/chat/v1/ServiceDeleter.java index 4e9bd0c7cf..3c5d654b5f 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ServiceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new ServiceDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/chat/v1/ServiceFetcher.java index ada00727b7..04628b70ee 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new ServiceFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceReader.java b/src/main/java/com/twilio/rest/chat/v1/ServiceReader.java index d0a0b07683..77fe9fb387 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/chat/v1/ServiceUpdater.java index 2a23e108ba..8a4ca8a11f 100644 --- a/src/main/java/com/twilio/rest/chat/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/ServiceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class ServiceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String defaultServiceRoleSid; private String defaultChannelRoleSid; @@ -45,1382 +58,1103 @@ public class ServiceUpdater extends Updater { private List webhookFilters; private URI webhooksOnMessageSendUrl; private HttpMethod webhooksOnMessageSendMethod; - private String webhooksOnMessageSendFormat; private URI webhooksOnMessageUpdateUrl; private HttpMethod webhooksOnMessageUpdateMethod; - private String webhooksOnMessageUpdateFormat; private URI webhooksOnMessageRemoveUrl; private HttpMethod webhooksOnMessageRemoveMethod; - private String webhooksOnMessageRemoveFormat; private URI webhooksOnChannelAddUrl; private HttpMethod webhooksOnChannelAddMethod; - private String webhooksOnChannelAddFormat; private URI webhooksOnChannelDestroyUrl; private HttpMethod webhooksOnChannelDestroyMethod; - private String webhooksOnChannelDestroyFormat; private URI webhooksOnChannelUpdateUrl; private HttpMethod webhooksOnChannelUpdateMethod; - private String webhooksOnChannelUpdateFormat; private URI webhooksOnMemberAddUrl; private HttpMethod webhooksOnMemberAddMethod; - private String webhooksOnMemberAddFormat; private URI webhooksOnMemberRemoveUrl; private HttpMethod webhooksOnMemberRemoveMethod; - private String webhooksOnMemberRemoveFormat; private URI webhooksOnMessageSentUrl; private HttpMethod webhooksOnMessageSentMethod; - private String webhooksOnMessageSentFormat; private URI webhooksOnMessageUpdatedUrl; private HttpMethod webhooksOnMessageUpdatedMethod; - private String webhooksOnMessageUpdatedFormat; private URI webhooksOnMessageRemovedUrl; private HttpMethod webhooksOnMessageRemovedMethod; - private String webhooksOnMessageRemovedFormat; private URI webhooksOnChannelAddedUrl; private HttpMethod webhooksOnChannelAddedMethod; - private String webhooksOnChannelAddedFormat; private URI webhooksOnChannelDestroyedUrl; private HttpMethod webhooksOnChannelDestroyedMethod; - private String webhooksOnChannelDestroyedFormat; private URI webhooksOnChannelUpdatedUrl; private HttpMethod webhooksOnChannelUpdatedMethod; - private String webhooksOnChannelUpdatedFormat; private URI webhooksOnMemberAddedUrl; private HttpMethod webhooksOnMemberAddedMethod; - private String webhooksOnMemberAddedFormat; private URI webhooksOnMemberRemovedUrl; private HttpMethod webhooksOnMemberRemovedMethod; - private String webhooksOnMemberRemovedFormat; private Integer limitsChannelMembers; private Integer limitsUserChannels; - /** - * Construct a new ServiceUpdater. - * - * @param pathSid The sid - */ public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Human-readable name for this service instance. - * - * @param friendlyName Human-readable name for this service instance - * @return this - */ public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The default_service_role_sid. - * - * @param defaultServiceRoleSid The default_service_role_sid - * @return this - */ - public ServiceUpdater setDefaultServiceRoleSid(final String defaultServiceRoleSid) { + public ServiceUpdater setDefaultServiceRoleSid( + final String defaultServiceRoleSid + ) { this.defaultServiceRoleSid = defaultServiceRoleSid; return this; } - /** - * Channel role assigned on channel join (see - * [Roles](https://www.twilio.com/docs/api/chat/rest/v1/roles) data model for - * the details). - * - * @param defaultChannelRoleSid Channel role assigned on channel join - * @return this - */ - public ServiceUpdater setDefaultChannelRoleSid(final String defaultChannelRoleSid) { + public ServiceUpdater setDefaultChannelRoleSid( + final String defaultChannelRoleSid + ) { this.defaultChannelRoleSid = defaultChannelRoleSid; return this; } - /** - * Channel role assigned to creator of channel when joining for first time. - * - * @param defaultChannelCreatorRoleSid Channel role assigned to creator of - * channel when joining for first time - * @return this - */ - public ServiceUpdater setDefaultChannelCreatorRoleSid(final String defaultChannelCreatorRoleSid) { + public ServiceUpdater setDefaultChannelCreatorRoleSid( + final String defaultChannelCreatorRoleSid + ) { this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; return this; } - /** - * `true` if the member read status feature is enabled, `false` if not. - * Defaults to `true`.. - * - * @param readStatusEnabled true if the member read status feature is enabled, - * false if not. - * @return this - */ - public ServiceUpdater setReadStatusEnabled(final Boolean readStatusEnabled) { + public ServiceUpdater setReadStatusEnabled( + final Boolean readStatusEnabled + ) { this.readStatusEnabled = readStatusEnabled; return this; } - /** - * `true` if the reachability feature should be enabled. Defaults to `false`. - * - * @param reachabilityEnabled true if the reachability feature should be - * enabled. - * @return this - */ - public ServiceUpdater setReachabilityEnabled(final Boolean reachabilityEnabled) { + public ServiceUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } - /** - * ISO 8601 duration indicating the timeout after "started typing" event when - * client should assume that user is not typing anymore even if no "ended - * typing" message received. - * - * @param typingIndicatorTimeout ISO 8601 duration indicating the timeout after - * "started typing" event when client should - * assume that user is not typing anymore even if - * no "ended typing" message received - * @return this - */ - public ServiceUpdater setTypingIndicatorTimeout(final Integer typingIndicatorTimeout) { + public ServiceUpdater setTypingIndicatorTimeout( + final Integer typingIndicatorTimeout + ) { this.typingIndicatorTimeout = typingIndicatorTimeout; return this; } - /** - * ISO 8601 duration indicating the interval between consumption reports sent - * from client endpoints.. - * - * @param consumptionReportInterval ISO 8601 duration indicating the interval - * between consumption reports sent from client - * endpoints. - * @return this - */ - public ServiceUpdater setConsumptionReportInterval(final Integer consumptionReportInterval) { + public ServiceUpdater setConsumptionReportInterval( + final Integer consumptionReportInterval + ) { this.consumptionReportInterval = consumptionReportInterval; return this; } - /** - * The notifications.new_message.enabled. - * - * @param notificationsNewMessageEnabled The notifications.new_message.enabled - * @return this - */ - public ServiceUpdater setNotificationsNewMessageEnabled(final Boolean notificationsNewMessageEnabled) { + public ServiceUpdater setNotificationsNewMessageEnabled( + final Boolean notificationsNewMessageEnabled + ) { this.notificationsNewMessageEnabled = notificationsNewMessageEnabled; return this; } - /** - * The notifications.new_message.template. - * - * @param notificationsNewMessageTemplate The notifications.new_message.template - * @return this - */ - public ServiceUpdater setNotificationsNewMessageTemplate(final String notificationsNewMessageTemplate) { + public ServiceUpdater setNotificationsNewMessageTemplate( + final String notificationsNewMessageTemplate + ) { this.notificationsNewMessageTemplate = notificationsNewMessageTemplate; return this; } - /** - * The notifications.added_to_channel.enabled. - * - * @param notificationsAddedToChannelEnabled The - * notifications.added_to_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelEnabled(final Boolean notificationsAddedToChannelEnabled) { - this.notificationsAddedToChannelEnabled = notificationsAddedToChannelEnabled; + public ServiceUpdater setNotificationsAddedToChannelEnabled( + final Boolean notificationsAddedToChannelEnabled + ) { + this.notificationsAddedToChannelEnabled = + notificationsAddedToChannelEnabled; return this; } - /** - * The notifications.added_to_channel.template. - * - * @param notificationsAddedToChannelTemplate The - * notifications.added_to_channel.template - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelTemplate(final String notificationsAddedToChannelTemplate) { - this.notificationsAddedToChannelTemplate = notificationsAddedToChannelTemplate; + public ServiceUpdater setNotificationsAddedToChannelTemplate( + final String notificationsAddedToChannelTemplate + ) { + this.notificationsAddedToChannelTemplate = + notificationsAddedToChannelTemplate; return this; } - /** - * The notifications.removed_from_channel.enabled. - * - * @param notificationsRemovedFromChannelEnabled The - * notifications.removed_from_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelEnabled(final Boolean notificationsRemovedFromChannelEnabled) { - this.notificationsRemovedFromChannelEnabled = notificationsRemovedFromChannelEnabled; + public ServiceUpdater setNotificationsRemovedFromChannelEnabled( + final Boolean notificationsRemovedFromChannelEnabled + ) { + this.notificationsRemovedFromChannelEnabled = + notificationsRemovedFromChannelEnabled; return this; } - /** - * The notifications.removed_from_channel.template. - * - * @param notificationsRemovedFromChannelTemplate The - * notifications.removed_from_channel.template - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelTemplate(final String notificationsRemovedFromChannelTemplate) { - this.notificationsRemovedFromChannelTemplate = notificationsRemovedFromChannelTemplate; + public ServiceUpdater setNotificationsRemovedFromChannelTemplate( + final String notificationsRemovedFromChannelTemplate + ) { + this.notificationsRemovedFromChannelTemplate = + notificationsRemovedFromChannelTemplate; return this; } - /** - * The notifications.invited_to_channel.enabled. - * - * @param notificationsInvitedToChannelEnabled The - * notifications.invited_to_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelEnabled(final Boolean notificationsInvitedToChannelEnabled) { - this.notificationsInvitedToChannelEnabled = notificationsInvitedToChannelEnabled; + public ServiceUpdater setNotificationsInvitedToChannelEnabled( + final Boolean notificationsInvitedToChannelEnabled + ) { + this.notificationsInvitedToChannelEnabled = + notificationsInvitedToChannelEnabled; return this; } - /** - * The notifications.invited_to_channel.template. - * - * @param notificationsInvitedToChannelTemplate The - * notifications.invited_to_channel.template - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelTemplate(final String notificationsInvitedToChannelTemplate) { - this.notificationsInvitedToChannelTemplate = notificationsInvitedToChannelTemplate; + public ServiceUpdater setNotificationsInvitedToChannelTemplate( + final String notificationsInvitedToChannelTemplate + ) { + this.notificationsInvitedToChannelTemplate = + notificationsInvitedToChannelTemplate; return this; } - /** - * The webhook URL for PRE-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param preWebhookUrl The webhook URL for PRE-Event webhooks. - * @return this - */ public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - /** - * The webhook URL for PRE-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param preWebhookUrl The webhook URL for PRE-Event webhooks. - * @return this - */ public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - /** - * The webhook URL for POST-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param postWebhookUrl The webhook URL for POST-Event webhooks. - * @return this - */ public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - /** - * The webhook URL for POST-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param postWebhookUrl The webhook URL for POST-Event webhooks. - * @return this - */ public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - /** - * The webhook request format to use. Must be POST or GET. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param webhookMethod The webhook request format to use. - * @return this - */ public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod) { this.webhookMethod = webhookMethod; return this; } - /** - * The list of WebHook events that are enabled for this Service instance. See - * [Webhook Events](https://www.twilio.com/docs/api/chat/webhooks) for more - * details.. - * - * @param webhookFilters The list of WebHook events that are enabled for this - * Service instance. - * @return this - */ public ServiceUpdater setWebhookFilters(final List webhookFilters) { this.webhookFilters = webhookFilters; return this; } - /** - * The list of WebHook events that are enabled for this Service instance. See - * [Webhook Events](https://www.twilio.com/docs/api/chat/webhooks) for more - * details.. - * - * @param webhookFilters The list of WebHook events that are enabled for this - * Service instance. - * @return this - */ public ServiceUpdater setWebhookFilters(final String webhookFilters) { return setWebhookFilters(Promoter.listOfOne(webhookFilters)); } - /** - * The webhooks.on_message_send.url. - * - * @param webhooksOnMessageSendUrl The webhooks.on_message_send.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSendUrl(final URI webhooksOnMessageSendUrl) { + public ServiceUpdater setWebhooksOnMessageSendUrl( + final URI webhooksOnMessageSendUrl + ) { this.webhooksOnMessageSendUrl = webhooksOnMessageSendUrl; return this; } - /** - * The webhooks.on_message_send.url. - * - * @param webhooksOnMessageSendUrl The webhooks.on_message_send.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSendUrl(final String webhooksOnMessageSendUrl) { - return setWebhooksOnMessageSendUrl(Promoter.uriFromString(webhooksOnMessageSendUrl)); + public ServiceUpdater setWebhooksOnMessageSendUrl( + final String webhooksOnMessageSendUrl + ) { + return setWebhooksOnMessageSendUrl( + Promoter.uriFromString(webhooksOnMessageSendUrl) + ); } - /** - * The webhooks.on_message_send.method. - * - * @param webhooksOnMessageSendMethod The webhooks.on_message_send.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSendMethod(final HttpMethod webhooksOnMessageSendMethod) { + public ServiceUpdater setWebhooksOnMessageSendMethod( + final HttpMethod webhooksOnMessageSendMethod + ) { this.webhooksOnMessageSendMethod = webhooksOnMessageSendMethod; return this; } - /** - * The webhooks.on_message_send.format. - * - * @param webhooksOnMessageSendFormat The webhooks.on_message_send.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSendFormat(final String webhooksOnMessageSendFormat) { - this.webhooksOnMessageSendFormat = webhooksOnMessageSendFormat; - return this; - } - - /** - * The webhooks.on_message_update.url. - * - * @param webhooksOnMessageUpdateUrl The webhooks.on_message_update.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdateUrl(final URI webhooksOnMessageUpdateUrl) { + public ServiceUpdater setWebhooksOnMessageUpdateUrl( + final URI webhooksOnMessageUpdateUrl + ) { this.webhooksOnMessageUpdateUrl = webhooksOnMessageUpdateUrl; return this; } - /** - * The webhooks.on_message_update.url. - * - * @param webhooksOnMessageUpdateUrl The webhooks.on_message_update.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdateUrl(final String webhooksOnMessageUpdateUrl) { - return setWebhooksOnMessageUpdateUrl(Promoter.uriFromString(webhooksOnMessageUpdateUrl)); + public ServiceUpdater setWebhooksOnMessageUpdateUrl( + final String webhooksOnMessageUpdateUrl + ) { + return setWebhooksOnMessageUpdateUrl( + Promoter.uriFromString(webhooksOnMessageUpdateUrl) + ); } - /** - * The webhooks.on_message_update.method. - * - * @param webhooksOnMessageUpdateMethod The webhooks.on_message_update.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdateMethod(final HttpMethod webhooksOnMessageUpdateMethod) { + public ServiceUpdater setWebhooksOnMessageUpdateMethod( + final HttpMethod webhooksOnMessageUpdateMethod + ) { this.webhooksOnMessageUpdateMethod = webhooksOnMessageUpdateMethod; return this; } - /** - * The webhooks.on_message_update.format. - * - * @param webhooksOnMessageUpdateFormat The webhooks.on_message_update.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdateFormat(final String webhooksOnMessageUpdateFormat) { - this.webhooksOnMessageUpdateFormat = webhooksOnMessageUpdateFormat; - return this; - } - - /** - * The webhooks.on_message_remove.url. - * - * @param webhooksOnMessageRemoveUrl The webhooks.on_message_remove.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemoveUrl(final URI webhooksOnMessageRemoveUrl) { + public ServiceUpdater setWebhooksOnMessageRemoveUrl( + final URI webhooksOnMessageRemoveUrl + ) { this.webhooksOnMessageRemoveUrl = webhooksOnMessageRemoveUrl; return this; } - /** - * The webhooks.on_message_remove.url. - * - * @param webhooksOnMessageRemoveUrl The webhooks.on_message_remove.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemoveUrl(final String webhooksOnMessageRemoveUrl) { - return setWebhooksOnMessageRemoveUrl(Promoter.uriFromString(webhooksOnMessageRemoveUrl)); + public ServiceUpdater setWebhooksOnMessageRemoveUrl( + final String webhooksOnMessageRemoveUrl + ) { + return setWebhooksOnMessageRemoveUrl( + Promoter.uriFromString(webhooksOnMessageRemoveUrl) + ); } - /** - * The webhooks.on_message_remove.method. - * - * @param webhooksOnMessageRemoveMethod The webhooks.on_message_remove.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemoveMethod(final HttpMethod webhooksOnMessageRemoveMethod) { + public ServiceUpdater setWebhooksOnMessageRemoveMethod( + final HttpMethod webhooksOnMessageRemoveMethod + ) { this.webhooksOnMessageRemoveMethod = webhooksOnMessageRemoveMethod; return this; } - /** - * The webhooks.on_message_remove.format. - * - * @param webhooksOnMessageRemoveFormat The webhooks.on_message_remove.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemoveFormat(final String webhooksOnMessageRemoveFormat) { - this.webhooksOnMessageRemoveFormat = webhooksOnMessageRemoveFormat; - return this; - } - - /** - * The webhooks.on_channel_add.url. - * - * @param webhooksOnChannelAddUrl The webhooks.on_channel_add.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddUrl(final URI webhooksOnChannelAddUrl) { + public ServiceUpdater setWebhooksOnChannelAddUrl( + final URI webhooksOnChannelAddUrl + ) { this.webhooksOnChannelAddUrl = webhooksOnChannelAddUrl; return this; } - /** - * The webhooks.on_channel_add.url. - * - * @param webhooksOnChannelAddUrl The webhooks.on_channel_add.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddUrl(final String webhooksOnChannelAddUrl) { - return setWebhooksOnChannelAddUrl(Promoter.uriFromString(webhooksOnChannelAddUrl)); + public ServiceUpdater setWebhooksOnChannelAddUrl( + final String webhooksOnChannelAddUrl + ) { + return setWebhooksOnChannelAddUrl( + Promoter.uriFromString(webhooksOnChannelAddUrl) + ); } - /** - * The webhooks.on_channel_add.method. - * - * @param webhooksOnChannelAddMethod The webhooks.on_channel_add.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddMethod(final HttpMethod webhooksOnChannelAddMethod) { + public ServiceUpdater setWebhooksOnChannelAddMethod( + final HttpMethod webhooksOnChannelAddMethod + ) { this.webhooksOnChannelAddMethod = webhooksOnChannelAddMethod; return this; } - /** - * The webhooks.on_channel_add.format. - * - * @param webhooksOnChannelAddFormat The webhooks.on_channel_add.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddFormat(final String webhooksOnChannelAddFormat) { - this.webhooksOnChannelAddFormat = webhooksOnChannelAddFormat; - return this; - } - - /** - * The webhooks.on_channel_destroy.url. - * - * @param webhooksOnChannelDestroyUrl The webhooks.on_channel_destroy.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyUrl(final URI webhooksOnChannelDestroyUrl) { + public ServiceUpdater setWebhooksOnChannelDestroyUrl( + final URI webhooksOnChannelDestroyUrl + ) { this.webhooksOnChannelDestroyUrl = webhooksOnChannelDestroyUrl; return this; } - /** - * The webhooks.on_channel_destroy.url. - * - * @param webhooksOnChannelDestroyUrl The webhooks.on_channel_destroy.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyUrl(final String webhooksOnChannelDestroyUrl) { - return setWebhooksOnChannelDestroyUrl(Promoter.uriFromString(webhooksOnChannelDestroyUrl)); + public ServiceUpdater setWebhooksOnChannelDestroyUrl( + final String webhooksOnChannelDestroyUrl + ) { + return setWebhooksOnChannelDestroyUrl( + Promoter.uriFromString(webhooksOnChannelDestroyUrl) + ); } - /** - * The webhooks.on_channel_destroy.method. - * - * @param webhooksOnChannelDestroyMethod The webhooks.on_channel_destroy.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyMethod(final HttpMethod webhooksOnChannelDestroyMethod) { + public ServiceUpdater setWebhooksOnChannelDestroyMethod( + final HttpMethod webhooksOnChannelDestroyMethod + ) { this.webhooksOnChannelDestroyMethod = webhooksOnChannelDestroyMethod; return this; } - /** - * The webhooks.on_channel_destroy.format. - * - * @param webhooksOnChannelDestroyFormat The webhooks.on_channel_destroy.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyFormat(final String webhooksOnChannelDestroyFormat) { - this.webhooksOnChannelDestroyFormat = webhooksOnChannelDestroyFormat; - return this; - } - - /** - * The webhooks.on_channel_update.url. - * - * @param webhooksOnChannelUpdateUrl The webhooks.on_channel_update.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdateUrl(final URI webhooksOnChannelUpdateUrl) { + public ServiceUpdater setWebhooksOnChannelUpdateUrl( + final URI webhooksOnChannelUpdateUrl + ) { this.webhooksOnChannelUpdateUrl = webhooksOnChannelUpdateUrl; return this; } - /** - * The webhooks.on_channel_update.url. - * - * @param webhooksOnChannelUpdateUrl The webhooks.on_channel_update.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdateUrl(final String webhooksOnChannelUpdateUrl) { - return setWebhooksOnChannelUpdateUrl(Promoter.uriFromString(webhooksOnChannelUpdateUrl)); + public ServiceUpdater setWebhooksOnChannelUpdateUrl( + final String webhooksOnChannelUpdateUrl + ) { + return setWebhooksOnChannelUpdateUrl( + Promoter.uriFromString(webhooksOnChannelUpdateUrl) + ); } - /** - * The webhooks.on_channel_update.method. - * - * @param webhooksOnChannelUpdateMethod The webhooks.on_channel_update.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdateMethod(final HttpMethod webhooksOnChannelUpdateMethod) { + public ServiceUpdater setWebhooksOnChannelUpdateMethod( + final HttpMethod webhooksOnChannelUpdateMethod + ) { this.webhooksOnChannelUpdateMethod = webhooksOnChannelUpdateMethod; return this; } - /** - * The webhooks.on_channel_update.format. - * - * @param webhooksOnChannelUpdateFormat The webhooks.on_channel_update.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdateFormat(final String webhooksOnChannelUpdateFormat) { - this.webhooksOnChannelUpdateFormat = webhooksOnChannelUpdateFormat; - return this; - } - - /** - * The webhooks.on_member_add.url. - * - * @param webhooksOnMemberAddUrl The webhooks.on_member_add.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddUrl(final URI webhooksOnMemberAddUrl) { + public ServiceUpdater setWebhooksOnMemberAddUrl( + final URI webhooksOnMemberAddUrl + ) { this.webhooksOnMemberAddUrl = webhooksOnMemberAddUrl; return this; } - /** - * The webhooks.on_member_add.url. - * - * @param webhooksOnMemberAddUrl The webhooks.on_member_add.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddUrl(final String webhooksOnMemberAddUrl) { - return setWebhooksOnMemberAddUrl(Promoter.uriFromString(webhooksOnMemberAddUrl)); + public ServiceUpdater setWebhooksOnMemberAddUrl( + final String webhooksOnMemberAddUrl + ) { + return setWebhooksOnMemberAddUrl( + Promoter.uriFromString(webhooksOnMemberAddUrl) + ); } - /** - * The webhooks.on_member_add.method. - * - * @param webhooksOnMemberAddMethod The webhooks.on_member_add.method - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddMethod(final HttpMethod webhooksOnMemberAddMethod) { + public ServiceUpdater setWebhooksOnMemberAddMethod( + final HttpMethod webhooksOnMemberAddMethod + ) { this.webhooksOnMemberAddMethod = webhooksOnMemberAddMethod; return this; } - /** - * The webhooks.on_member_add.format. - * - * @param webhooksOnMemberAddFormat The webhooks.on_member_add.format - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddFormat(final String webhooksOnMemberAddFormat) { - this.webhooksOnMemberAddFormat = webhooksOnMemberAddFormat; - return this; - } - - /** - * The webhooks.on_member_remove.url. - * - * @param webhooksOnMemberRemoveUrl The webhooks.on_member_remove.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemoveUrl(final URI webhooksOnMemberRemoveUrl) { + public ServiceUpdater setWebhooksOnMemberRemoveUrl( + final URI webhooksOnMemberRemoveUrl + ) { this.webhooksOnMemberRemoveUrl = webhooksOnMemberRemoveUrl; return this; } - /** - * The webhooks.on_member_remove.url. - * - * @param webhooksOnMemberRemoveUrl The webhooks.on_member_remove.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemoveUrl(final String webhooksOnMemberRemoveUrl) { - return setWebhooksOnMemberRemoveUrl(Promoter.uriFromString(webhooksOnMemberRemoveUrl)); + public ServiceUpdater setWebhooksOnMemberRemoveUrl( + final String webhooksOnMemberRemoveUrl + ) { + return setWebhooksOnMemberRemoveUrl( + Promoter.uriFromString(webhooksOnMemberRemoveUrl) + ); } - /** - * The webhooks.on_member_remove.method. - * - * @param webhooksOnMemberRemoveMethod The webhooks.on_member_remove.method - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemoveMethod(final HttpMethod webhooksOnMemberRemoveMethod) { + public ServiceUpdater setWebhooksOnMemberRemoveMethod( + final HttpMethod webhooksOnMemberRemoveMethod + ) { this.webhooksOnMemberRemoveMethod = webhooksOnMemberRemoveMethod; return this; } - /** - * The webhooks.on_member_remove.format. - * - * @param webhooksOnMemberRemoveFormat The webhooks.on_member_remove.format - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemoveFormat(final String webhooksOnMemberRemoveFormat) { - this.webhooksOnMemberRemoveFormat = webhooksOnMemberRemoveFormat; - return this; - } - - /** - * The webhooks.on_message_sent.url. - * - * @param webhooksOnMessageSentUrl The webhooks.on_message_sent.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSentUrl(final URI webhooksOnMessageSentUrl) { + public ServiceUpdater setWebhooksOnMessageSentUrl( + final URI webhooksOnMessageSentUrl + ) { this.webhooksOnMessageSentUrl = webhooksOnMessageSentUrl; return this; } - /** - * The webhooks.on_message_sent.url. - * - * @param webhooksOnMessageSentUrl The webhooks.on_message_sent.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSentUrl(final String webhooksOnMessageSentUrl) { - return setWebhooksOnMessageSentUrl(Promoter.uriFromString(webhooksOnMessageSentUrl)); + public ServiceUpdater setWebhooksOnMessageSentUrl( + final String webhooksOnMessageSentUrl + ) { + return setWebhooksOnMessageSentUrl( + Promoter.uriFromString(webhooksOnMessageSentUrl) + ); } - /** - * The webhooks.on_message_sent.method. - * - * @param webhooksOnMessageSentMethod The webhooks.on_message_sent.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSentMethod(final HttpMethod webhooksOnMessageSentMethod) { + public ServiceUpdater setWebhooksOnMessageSentMethod( + final HttpMethod webhooksOnMessageSentMethod + ) { this.webhooksOnMessageSentMethod = webhooksOnMessageSentMethod; return this; } - /** - * The webhooks.on_message_sent.format. - * - * @param webhooksOnMessageSentFormat The webhooks.on_message_sent.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSentFormat(final String webhooksOnMessageSentFormat) { - this.webhooksOnMessageSentFormat = webhooksOnMessageSentFormat; - return this; - } - - /** - * The webhooks.on_message_updated.url. - * - * @param webhooksOnMessageUpdatedUrl The webhooks.on_message_updated.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdatedUrl(final URI webhooksOnMessageUpdatedUrl) { + public ServiceUpdater setWebhooksOnMessageUpdatedUrl( + final URI webhooksOnMessageUpdatedUrl + ) { this.webhooksOnMessageUpdatedUrl = webhooksOnMessageUpdatedUrl; return this; } - /** - * The webhooks.on_message_updated.url. - * - * @param webhooksOnMessageUpdatedUrl The webhooks.on_message_updated.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdatedUrl(final String webhooksOnMessageUpdatedUrl) { - return setWebhooksOnMessageUpdatedUrl(Promoter.uriFromString(webhooksOnMessageUpdatedUrl)); + public ServiceUpdater setWebhooksOnMessageUpdatedUrl( + final String webhooksOnMessageUpdatedUrl + ) { + return setWebhooksOnMessageUpdatedUrl( + Promoter.uriFromString(webhooksOnMessageUpdatedUrl) + ); } - /** - * The webhooks.on_message_updated.method. - * - * @param webhooksOnMessageUpdatedMethod The webhooks.on_message_updated.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdatedMethod(final HttpMethod webhooksOnMessageUpdatedMethod) { + public ServiceUpdater setWebhooksOnMessageUpdatedMethod( + final HttpMethod webhooksOnMessageUpdatedMethod + ) { this.webhooksOnMessageUpdatedMethod = webhooksOnMessageUpdatedMethod; return this; } - /** - * The webhooks.on_message_updated.format. - * - * @param webhooksOnMessageUpdatedFormat The webhooks.on_message_updated.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdatedFormat(final String webhooksOnMessageUpdatedFormat) { - this.webhooksOnMessageUpdatedFormat = webhooksOnMessageUpdatedFormat; - return this; - } - - /** - * The webhooks.on_message_removed.url. - * - * @param webhooksOnMessageRemovedUrl The webhooks.on_message_removed.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemovedUrl(final URI webhooksOnMessageRemovedUrl) { + public ServiceUpdater setWebhooksOnMessageRemovedUrl( + final URI webhooksOnMessageRemovedUrl + ) { this.webhooksOnMessageRemovedUrl = webhooksOnMessageRemovedUrl; return this; } - /** - * The webhooks.on_message_removed.url. - * - * @param webhooksOnMessageRemovedUrl The webhooks.on_message_removed.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemovedUrl(final String webhooksOnMessageRemovedUrl) { - return setWebhooksOnMessageRemovedUrl(Promoter.uriFromString(webhooksOnMessageRemovedUrl)); + public ServiceUpdater setWebhooksOnMessageRemovedUrl( + final String webhooksOnMessageRemovedUrl + ) { + return setWebhooksOnMessageRemovedUrl( + Promoter.uriFromString(webhooksOnMessageRemovedUrl) + ); } - /** - * The webhooks.on_message_removed.method. - * - * @param webhooksOnMessageRemovedMethod The webhooks.on_message_removed.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemovedMethod(final HttpMethod webhooksOnMessageRemovedMethod) { + public ServiceUpdater setWebhooksOnMessageRemovedMethod( + final HttpMethod webhooksOnMessageRemovedMethod + ) { this.webhooksOnMessageRemovedMethod = webhooksOnMessageRemovedMethod; return this; } - /** - * The webhooks.on_message_removed.format. - * - * @param webhooksOnMessageRemovedFormat The webhooks.on_message_removed.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemovedFormat(final String webhooksOnMessageRemovedFormat) { - this.webhooksOnMessageRemovedFormat = webhooksOnMessageRemovedFormat; - return this; - } - - /** - * The webhooks.on_channel_added.url. - * - * @param webhooksOnChannelAddedUrl The webhooks.on_channel_added.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddedUrl(final URI webhooksOnChannelAddedUrl) { + public ServiceUpdater setWebhooksOnChannelAddedUrl( + final URI webhooksOnChannelAddedUrl + ) { this.webhooksOnChannelAddedUrl = webhooksOnChannelAddedUrl; return this; } - /** - * The webhooks.on_channel_added.url. - * - * @param webhooksOnChannelAddedUrl The webhooks.on_channel_added.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddedUrl(final String webhooksOnChannelAddedUrl) { - return setWebhooksOnChannelAddedUrl(Promoter.uriFromString(webhooksOnChannelAddedUrl)); + public ServiceUpdater setWebhooksOnChannelAddedUrl( + final String webhooksOnChannelAddedUrl + ) { + return setWebhooksOnChannelAddedUrl( + Promoter.uriFromString(webhooksOnChannelAddedUrl) + ); } - /** - * The webhooks.on_channel_added.method. - * - * @param webhooksOnChannelAddedMethod The webhooks.on_channel_added.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddedMethod(final HttpMethod webhooksOnChannelAddedMethod) { + public ServiceUpdater setWebhooksOnChannelAddedMethod( + final HttpMethod webhooksOnChannelAddedMethod + ) { this.webhooksOnChannelAddedMethod = webhooksOnChannelAddedMethod; return this; } - /** - * The webhooks.on_channel_added.format. - * - * @param webhooksOnChannelAddedFormat The webhooks.on_channel_added.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddedFormat(final String webhooksOnChannelAddedFormat) { - this.webhooksOnChannelAddedFormat = webhooksOnChannelAddedFormat; - return this; - } - - /** - * The webhooks.on_channel_destroyed.url. - * - * @param webhooksOnChannelDestroyedUrl The webhooks.on_channel_destroyed.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyedUrl(final URI webhooksOnChannelDestroyedUrl) { + public ServiceUpdater setWebhooksOnChannelDestroyedUrl( + final URI webhooksOnChannelDestroyedUrl + ) { this.webhooksOnChannelDestroyedUrl = webhooksOnChannelDestroyedUrl; return this; } - /** - * The webhooks.on_channel_destroyed.url. - * - * @param webhooksOnChannelDestroyedUrl The webhooks.on_channel_destroyed.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyedUrl(final String webhooksOnChannelDestroyedUrl) { - return setWebhooksOnChannelDestroyedUrl(Promoter.uriFromString(webhooksOnChannelDestroyedUrl)); - } - - /** - * The webhooks.on_channel_destroyed.method. - * - * @param webhooksOnChannelDestroyedMethod The - * webhooks.on_channel_destroyed.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyedMethod(final HttpMethod webhooksOnChannelDestroyedMethod) { - this.webhooksOnChannelDestroyedMethod = webhooksOnChannelDestroyedMethod; - return this; + public ServiceUpdater setWebhooksOnChannelDestroyedUrl( + final String webhooksOnChannelDestroyedUrl + ) { + return setWebhooksOnChannelDestroyedUrl( + Promoter.uriFromString(webhooksOnChannelDestroyedUrl) + ); } - /** - * The webhooks.on_channel_destroyed.format. - * - * @param webhooksOnChannelDestroyedFormat The - * webhooks.on_channel_destroyed.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyedFormat(final String webhooksOnChannelDestroyedFormat) { - this.webhooksOnChannelDestroyedFormat = webhooksOnChannelDestroyedFormat; + public ServiceUpdater setWebhooksOnChannelDestroyedMethod( + final HttpMethod webhooksOnChannelDestroyedMethod + ) { + this.webhooksOnChannelDestroyedMethod = + webhooksOnChannelDestroyedMethod; return this; } - /** - * The webhooks.on_channel_updated.url. - * - * @param webhooksOnChannelUpdatedUrl The webhooks.on_channel_updated.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdatedUrl(final URI webhooksOnChannelUpdatedUrl) { + public ServiceUpdater setWebhooksOnChannelUpdatedUrl( + final URI webhooksOnChannelUpdatedUrl + ) { this.webhooksOnChannelUpdatedUrl = webhooksOnChannelUpdatedUrl; return this; } - /** - * The webhooks.on_channel_updated.url. - * - * @param webhooksOnChannelUpdatedUrl The webhooks.on_channel_updated.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdatedUrl(final String webhooksOnChannelUpdatedUrl) { - return setWebhooksOnChannelUpdatedUrl(Promoter.uriFromString(webhooksOnChannelUpdatedUrl)); + public ServiceUpdater setWebhooksOnChannelUpdatedUrl( + final String webhooksOnChannelUpdatedUrl + ) { + return setWebhooksOnChannelUpdatedUrl( + Promoter.uriFromString(webhooksOnChannelUpdatedUrl) + ); } - /** - * The webhooks.on_channel_updated.method. - * - * @param webhooksOnChannelUpdatedMethod The webhooks.on_channel_updated.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdatedMethod(final HttpMethod webhooksOnChannelUpdatedMethod) { + public ServiceUpdater setWebhooksOnChannelUpdatedMethod( + final HttpMethod webhooksOnChannelUpdatedMethod + ) { this.webhooksOnChannelUpdatedMethod = webhooksOnChannelUpdatedMethod; return this; } - /** - * The webhooks.on_channel_updated.format. - * - * @param webhooksOnChannelUpdatedFormat The webhooks.on_channel_updated.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdatedFormat(final String webhooksOnChannelUpdatedFormat) { - this.webhooksOnChannelUpdatedFormat = webhooksOnChannelUpdatedFormat; - return this; - } - - /** - * The webhooks.on_member_added.url. - * - * @param webhooksOnMemberAddedUrl The webhooks.on_member_added.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddedUrl(final URI webhooksOnMemberAddedUrl) { + public ServiceUpdater setWebhooksOnMemberAddedUrl( + final URI webhooksOnMemberAddedUrl + ) { this.webhooksOnMemberAddedUrl = webhooksOnMemberAddedUrl; return this; } - /** - * The webhooks.on_member_added.url. - * - * @param webhooksOnMemberAddedUrl The webhooks.on_member_added.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddedUrl(final String webhooksOnMemberAddedUrl) { - return setWebhooksOnMemberAddedUrl(Promoter.uriFromString(webhooksOnMemberAddedUrl)); + public ServiceUpdater setWebhooksOnMemberAddedUrl( + final String webhooksOnMemberAddedUrl + ) { + return setWebhooksOnMemberAddedUrl( + Promoter.uriFromString(webhooksOnMemberAddedUrl) + ); } - /** - * The webhooks.on_member_added.method. - * - * @param webhooksOnMemberAddedMethod The webhooks.on_member_added.method - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddedMethod(final HttpMethod webhooksOnMemberAddedMethod) { + public ServiceUpdater setWebhooksOnMemberAddedMethod( + final HttpMethod webhooksOnMemberAddedMethod + ) { this.webhooksOnMemberAddedMethod = webhooksOnMemberAddedMethod; return this; } - /** - * The webhooks.on_member_added.format. - * - * @param webhooksOnMemberAddedFormat The webhooks.on_member_added.format - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddedFormat(final String webhooksOnMemberAddedFormat) { - this.webhooksOnMemberAddedFormat = webhooksOnMemberAddedFormat; - return this; - } - - /** - * The webhooks.on_member_removed.url. - * - * @param webhooksOnMemberRemovedUrl The webhooks.on_member_removed.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemovedUrl(final URI webhooksOnMemberRemovedUrl) { + public ServiceUpdater setWebhooksOnMemberRemovedUrl( + final URI webhooksOnMemberRemovedUrl + ) { this.webhooksOnMemberRemovedUrl = webhooksOnMemberRemovedUrl; return this; } - /** - * The webhooks.on_member_removed.url. - * - * @param webhooksOnMemberRemovedUrl The webhooks.on_member_removed.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemovedUrl(final String webhooksOnMemberRemovedUrl) { - return setWebhooksOnMemberRemovedUrl(Promoter.uriFromString(webhooksOnMemberRemovedUrl)); + public ServiceUpdater setWebhooksOnMemberRemovedUrl( + final String webhooksOnMemberRemovedUrl + ) { + return setWebhooksOnMemberRemovedUrl( + Promoter.uriFromString(webhooksOnMemberRemovedUrl) + ); } - /** - * The webhooks.on_member_removed.method. - * - * @param webhooksOnMemberRemovedMethod The webhooks.on_member_removed.method - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemovedMethod(final HttpMethod webhooksOnMemberRemovedMethod) { + public ServiceUpdater setWebhooksOnMemberRemovedMethod( + final HttpMethod webhooksOnMemberRemovedMethod + ) { this.webhooksOnMemberRemovedMethod = webhooksOnMemberRemovedMethod; return this; } - /** - * The webhooks.on_member_removed.format. - * - * @param webhooksOnMemberRemovedFormat The webhooks.on_member_removed.format - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemovedFormat(final String webhooksOnMemberRemovedFormat) { - this.webhooksOnMemberRemovedFormat = webhooksOnMemberRemovedFormat; - return this; - } - - /** - * The limits.channel_members. - * - * @param limitsChannelMembers The limits.channel_members - * @return this - */ - public ServiceUpdater setLimitsChannelMembers(final Integer limitsChannelMembers) { + public ServiceUpdater setLimitsChannelMembers( + final Integer limitsChannelMembers + ) { this.limitsChannelMembers = limitsChannelMembers; return this; } - /** - * The limits.user_channels. - * - * @param limitsUserChannels The limits.user_channels - * @return this - */ - public ServiceUpdater setLimitsUserChannels(final Integer limitsUserChannels) { + public ServiceUpdater setLimitsUserChannels( + final Integer limitsUserChannels + ) { this.limitsUserChannels = limitsUserChannels; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (defaultServiceRoleSid != null) { - request.addPostParam("DefaultServiceRoleSid", defaultServiceRoleSid); + Serializer.toString( + request, + "DefaultServiceRoleSid", + defaultServiceRoleSid, + ParameterType.URLENCODED + ); } if (defaultChannelRoleSid != null) { - request.addPostParam("DefaultChannelRoleSid", defaultChannelRoleSid); + Serializer.toString( + request, + "DefaultChannelRoleSid", + defaultChannelRoleSid, + ParameterType.URLENCODED + ); } if (defaultChannelCreatorRoleSid != null) { - request.addPostParam("DefaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid); + Serializer.toString( + request, + "DefaultChannelCreatorRoleSid", + defaultChannelCreatorRoleSid, + ParameterType.URLENCODED + ); } if (readStatusEnabled != null) { - request.addPostParam("ReadStatusEnabled", readStatusEnabled.toString()); + Serializer.toString( + request, + "ReadStatusEnabled", + readStatusEnabled, + ParameterType.URLENCODED + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); + Serializer.toString( + request, + "ReachabilityEnabled", + reachabilityEnabled, + ParameterType.URLENCODED + ); } if (typingIndicatorTimeout != null) { - request.addPostParam("TypingIndicatorTimeout", typingIndicatorTimeout.toString()); + Serializer.toString( + request, + "TypingIndicatorTimeout", + typingIndicatorTimeout, + ParameterType.URLENCODED + ); } if (consumptionReportInterval != null) { - request.addPostParam("ConsumptionReportInterval", consumptionReportInterval.toString()); + Serializer.toString( + request, + "ConsumptionReportInterval", + consumptionReportInterval, + ParameterType.URLENCODED + ); } if (notificationsNewMessageEnabled != null) { - request.addPostParam("Notifications.NewMessage.Enabled", notificationsNewMessageEnabled.toString()); + Serializer.toString( + request, + "Notifications.NewMessage.Enabled", + notificationsNewMessageEnabled, + ParameterType.URLENCODED + ); } if (notificationsNewMessageTemplate != null) { - request.addPostParam("Notifications.NewMessage.Template", notificationsNewMessageTemplate); + Serializer.toString( + request, + "Notifications.NewMessage.Template", + notificationsNewMessageTemplate, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelEnabled != null) { - request.addPostParam("Notifications.AddedToChannel.Enabled", notificationsAddedToChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.AddedToChannel.Enabled", + notificationsAddedToChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelTemplate != null) { - request.addPostParam("Notifications.AddedToChannel.Template", notificationsAddedToChannelTemplate); + Serializer.toString( + request, + "Notifications.AddedToChannel.Template", + notificationsAddedToChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelEnabled != null) { - request.addPostParam("Notifications.RemovedFromChannel.Enabled", notificationsRemovedFromChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Enabled", + notificationsRemovedFromChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelTemplate != null) { - request.addPostParam("Notifications.RemovedFromChannel.Template", notificationsRemovedFromChannelTemplate); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Template", + notificationsRemovedFromChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelEnabled != null) { - request.addPostParam("Notifications.InvitedToChannel.Enabled", notificationsInvitedToChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Enabled", + notificationsInvitedToChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelTemplate != null) { - request.addPostParam("Notifications.InvitedToChannel.Template", notificationsInvitedToChannelTemplate); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Template", + notificationsInvitedToChannelTemplate, + ParameterType.URLENCODED + ); } if (preWebhookUrl != null) { - request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); + Serializer.toString( + request, + "PreWebhookUrl", + preWebhookUrl, + ParameterType.URLENCODED + ); } if (postWebhookUrl != null) { - request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); + Serializer.toString( + request, + "PostWebhookUrl", + postWebhookUrl, + ParameterType.URLENCODED + ); } if (webhookMethod != null) { - request.addPostParam("WebhookMethod", webhookMethod.toString()); + Serializer.toString( + request, + "WebhookMethod", + webhookMethod, + ParameterType.URLENCODED + ); } if (webhookFilters != null) { - for (String prop : webhookFilters) { - request.addPostParam("WebhookFilters", prop); + for (String param : webhookFilters) { + Serializer.toString( + request, + "WebhookFilters", + param, + ParameterType.URLENCODED + ); } } if (webhooksOnMessageSendUrl != null) { - request.addPostParam("Webhooks.OnMessageSend.Url", webhooksOnMessageSendUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageSend.Url", + webhooksOnMessageSendUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageSendMethod != null) { - request.addPostParam("Webhooks.OnMessageSend.Method", webhooksOnMessageSendMethod.toString()); - } - - if (webhooksOnMessageSendFormat != null) { - request.addPostParam("Webhooks.OnMessageSend.Format", webhooksOnMessageSendFormat); + Serializer.toString( + request, + "Webhooks.OnMessageSend.Method", + webhooksOnMessageSendMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageUpdateUrl != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Url", webhooksOnMessageUpdateUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageUpdate.Url", + webhooksOnMessageUpdateUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageUpdateMethod != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Method", webhooksOnMessageUpdateMethod.toString()); - } - - if (webhooksOnMessageUpdateFormat != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Format", webhooksOnMessageUpdateFormat); + Serializer.toString( + request, + "Webhooks.OnMessageUpdate.Method", + webhooksOnMessageUpdateMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageRemoveUrl != null) { - request.addPostParam("Webhooks.OnMessageRemove.Url", webhooksOnMessageRemoveUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageRemove.Url", + webhooksOnMessageRemoveUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageRemoveMethod != null) { - request.addPostParam("Webhooks.OnMessageRemove.Method", webhooksOnMessageRemoveMethod.toString()); - } - - if (webhooksOnMessageRemoveFormat != null) { - request.addPostParam("Webhooks.OnMessageRemove.Format", webhooksOnMessageRemoveFormat); + Serializer.toString( + request, + "Webhooks.OnMessageRemove.Method", + webhooksOnMessageRemoveMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelAddUrl != null) { - request.addPostParam("Webhooks.OnChannelAdd.Url", webhooksOnChannelAddUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelAdd.Url", + webhooksOnChannelAddUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelAddMethod != null) { - request.addPostParam("Webhooks.OnChannelAdd.Method", webhooksOnChannelAddMethod.toString()); - } - - if (webhooksOnChannelAddFormat != null) { - request.addPostParam("Webhooks.OnChannelAdd.Format", webhooksOnChannelAddFormat); + Serializer.toString( + request, + "Webhooks.OnChannelAdd.Method", + webhooksOnChannelAddMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelDestroyUrl != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Url", webhooksOnChannelDestroyUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelDestroy.Url", + webhooksOnChannelDestroyUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelDestroyMethod != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Method", webhooksOnChannelDestroyMethod.toString()); - } - - if (webhooksOnChannelDestroyFormat != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Format", webhooksOnChannelDestroyFormat); + Serializer.toString( + request, + "Webhooks.OnChannelDestroy.Method", + webhooksOnChannelDestroyMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelUpdateUrl != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Url", webhooksOnChannelUpdateUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelUpdate.Url", + webhooksOnChannelUpdateUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelUpdateMethod != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Method", webhooksOnChannelUpdateMethod.toString()); - } - - if (webhooksOnChannelUpdateFormat != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Format", webhooksOnChannelUpdateFormat); + Serializer.toString( + request, + "Webhooks.OnChannelUpdate.Method", + webhooksOnChannelUpdateMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMemberAddUrl != null) { - request.addPostParam("Webhooks.OnMemberAdd.Url", webhooksOnMemberAddUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMemberAdd.Url", + webhooksOnMemberAddUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMemberAddMethod != null) { - request.addPostParam("Webhooks.OnMemberAdd.Method", webhooksOnMemberAddMethod.toString()); - } - - if (webhooksOnMemberAddFormat != null) { - request.addPostParam("Webhooks.OnMemberAdd.Format", webhooksOnMemberAddFormat); + Serializer.toString( + request, + "Webhooks.OnMemberAdd.Method", + webhooksOnMemberAddMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMemberRemoveUrl != null) { - request.addPostParam("Webhooks.OnMemberRemove.Url", webhooksOnMemberRemoveUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMemberRemove.Url", + webhooksOnMemberRemoveUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMemberRemoveMethod != null) { - request.addPostParam("Webhooks.OnMemberRemove.Method", webhooksOnMemberRemoveMethod.toString()); - } - - if (webhooksOnMemberRemoveFormat != null) { - request.addPostParam("Webhooks.OnMemberRemove.Format", webhooksOnMemberRemoveFormat); + Serializer.toString( + request, + "Webhooks.OnMemberRemove.Method", + webhooksOnMemberRemoveMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageSentUrl != null) { - request.addPostParam("Webhooks.OnMessageSent.Url", webhooksOnMessageSentUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageSent.Url", + webhooksOnMessageSentUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageSentMethod != null) { - request.addPostParam("Webhooks.OnMessageSent.Method", webhooksOnMessageSentMethod.toString()); - } - - if (webhooksOnMessageSentFormat != null) { - request.addPostParam("Webhooks.OnMessageSent.Format", webhooksOnMessageSentFormat); + Serializer.toString( + request, + "Webhooks.OnMessageSent.Method", + webhooksOnMessageSentMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageUpdatedUrl != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Url", webhooksOnMessageUpdatedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageUpdated.Url", + webhooksOnMessageUpdatedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageUpdatedMethod != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Method", webhooksOnMessageUpdatedMethod.toString()); - } - - if (webhooksOnMessageUpdatedFormat != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Format", webhooksOnMessageUpdatedFormat); + Serializer.toString( + request, + "Webhooks.OnMessageUpdated.Method", + webhooksOnMessageUpdatedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageRemovedUrl != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Url", webhooksOnMessageRemovedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageRemoved.Url", + webhooksOnMessageRemovedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageRemovedMethod != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Method", webhooksOnMessageRemovedMethod.toString()); - } - - if (webhooksOnMessageRemovedFormat != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Format", webhooksOnMessageRemovedFormat); + Serializer.toString( + request, + "Webhooks.OnMessageRemoved.Method", + webhooksOnMessageRemovedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelAddedUrl != null) { - request.addPostParam("Webhooks.OnChannelAdded.Url", webhooksOnChannelAddedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelAdded.Url", + webhooksOnChannelAddedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelAddedMethod != null) { - request.addPostParam("Webhooks.OnChannelAdded.Method", webhooksOnChannelAddedMethod.toString()); - } - - if (webhooksOnChannelAddedFormat != null) { - request.addPostParam("Webhooks.OnChannelAdded.Format", webhooksOnChannelAddedFormat); + Serializer.toString( + request, + "Webhooks.OnChannelAdded.Method", + webhooksOnChannelAddedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelDestroyedUrl != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Url", webhooksOnChannelDestroyedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelDestroyed.Url", + webhooksOnChannelDestroyedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelDestroyedMethod != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Method", webhooksOnChannelDestroyedMethod.toString()); - } - - if (webhooksOnChannelDestroyedFormat != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Format", webhooksOnChannelDestroyedFormat); + Serializer.toString( + request, + "Webhooks.OnChannelDestroyed.Method", + webhooksOnChannelDestroyedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelUpdatedUrl != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Url", webhooksOnChannelUpdatedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelUpdated.Url", + webhooksOnChannelUpdatedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelUpdatedMethod != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Method", webhooksOnChannelUpdatedMethod.toString()); - } - - if (webhooksOnChannelUpdatedFormat != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Format", webhooksOnChannelUpdatedFormat); + Serializer.toString( + request, + "Webhooks.OnChannelUpdated.Method", + webhooksOnChannelUpdatedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMemberAddedUrl != null) { - request.addPostParam("Webhooks.OnMemberAdded.Url", webhooksOnMemberAddedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMemberAdded.Url", + webhooksOnMemberAddedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMemberAddedMethod != null) { - request.addPostParam("Webhooks.OnMemberAdded.Method", webhooksOnMemberAddedMethod.toString()); - } - - if (webhooksOnMemberAddedFormat != null) { - request.addPostParam("Webhooks.OnMemberAdded.Format", webhooksOnMemberAddedFormat); + Serializer.toString( + request, + "Webhooks.OnMemberAdded.Method", + webhooksOnMemberAddedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMemberRemovedUrl != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Url", webhooksOnMemberRemovedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMemberRemoved.Url", + webhooksOnMemberRemovedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMemberRemovedMethod != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Method", webhooksOnMemberRemovedMethod.toString()); - } - - if (webhooksOnMemberRemovedFormat != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Format", webhooksOnMemberRemovedFormat); + Serializer.toString( + request, + "Webhooks.OnMemberRemoved.Method", + webhooksOnMemberRemovedMethod, + ParameterType.URLENCODED + ); } if (limitsChannelMembers != null) { - request.addPostParam("Limits.ChannelMembers", limitsChannelMembers.toString()); + Serializer.toString( + request, + "Limits.ChannelMembers", + limitsChannelMembers, + ParameterType.URLENCODED + ); } if (limitsUserChannels != null) { - request.addPostParam("Limits.UserChannels", limitsUserChannels.toString()); + Serializer.toString( + request, + "Limits.UserChannels", + limitsUserChannels, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/Channel.java b/src/main/java/com/twilio/rest/chat/v1/service/Channel.java index 76246ed215..ef8aae82ec 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/Channel.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/Channel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; @@ -10,32 +17,62 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Channel extends Resource { - private static final long serialVersionUID = 275623534063843L; + + public static ChannelCreator creator(final String pathServiceSid) { + return new ChannelCreator(pathServiceSid); + } + + public static ChannelDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelDeleter(pathServiceSid, pathSid); + } + + public static ChannelFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelFetcher(pathServiceSid, pathSid); + } + + public static ChannelReader reader(final String pathServiceSid) { + return new ChannelReader(pathServiceSid); + } + + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelUpdater(pathServiceSid, pathSid); + } public enum ChannelType { PUBLIC("public"), @@ -47,85 +84,28 @@ private ChannelType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ChannelType from a string. - * @param value string value - * @return generated ChannelType - */ @JsonCreator public static ChannelType forValue(final String value) { return Promoter.enumFromString(value, ChannelType.values()); } } - /** - * Create a ChannelFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelFetcher capable of executing the fetch - */ - public static ChannelFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new ChannelFetcher(pathServiceSid, pathSid); - } - - /** - * Create a ChannelDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelDeleter capable of executing the delete - */ - public static ChannelDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new ChannelDeleter(pathServiceSid, pathSid); - } - - /** - * Create a ChannelCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return ChannelCreator capable of executing the create - */ - public static ChannelCreator creator(final String pathServiceSid) { - return new ChannelCreator(pathServiceSid); - } - - /** - * Create a ChannelReader to execute read. - * - * @param pathServiceSid The service_sid - * @return ChannelReader capable of executing the read - */ - public static ChannelReader reader(final String pathServiceSid) { - return new ChannelReader(pathServiceSid); - } - - /** - * Create a ChannelUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelUpdater capable of executing the update - */ - public static ChannelUpdater updater(final String pathServiceSid, - final String pathSid) { - return new ChannelUpdater(pathServiceSid, pathSid); - } - /** * Converts a JSON String into a Channel object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Channel object represented by the provided JSON */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -139,12 +119,15 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Channel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Channel object represented by the provided JSON */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -155,196 +138,101 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String friendlyName; - private final String uniqueName; - private final String attributes; - private final Channel.ChannelType type; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - private final Integer membersCount; - private final Integer messagesCount; - private final URI url; - private final Map links; - - @JsonCreator - private Channel(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("type") - final Channel.ChannelType type, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy, - @JsonProperty("members_count") - final Integer membersCount, - @JsonProperty("messages_count") - final Integer messagesCount, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.friendlyName = friendlyName; - this.uniqueName = uniqueName; - this.attributes = attributes; - this.type = type; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - this.membersCount = membersCount; - this.messagesCount = messagesCount; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the [Account][/console] responsible for this - * channel.. - * - * @return The unique id of the [Account][/console] responsible for this - * channel. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String attributes; - /** - * Returns The The unique id of the [Service][service] this channel belongs to.. - * - * @return The unique id of the [Service][service] this channel belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String createdBy; - /** - * Returns The The human-readable name of this channel.. - * - * @return The human-readable name of this channel. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique, addressable name of this channel.. - * - * @return The unique, addressable name of this channel. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } + @Getter + private final String friendlyName; - /** - * Returns The The visibility of this channel - either public or private. - * - * @return The visibility of this channel - either public or private - */ - public final Channel.ChannelType getType() { - return this.type; - } + @Getter + private final Map links; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Integer membersCount; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer messagesCount; - /** - * Returns The Identity of the channel's creator.. - * - * @return Identity of the channel's creator. - */ - public final String getCreatedBy() { - return this.createdBy; - } + @Getter + private final String serviceSid; - /** - * Returns The The members_count. - * - * @return The members_count - */ - public final Integer getMembersCount() { - return this.membersCount; - } + @Getter + private final String sid; - /** - * Returns The The messages_count. - * - * @return The messages_count - */ - public final Integer getMessagesCount() { - return this.messagesCount; - } + @Getter + private final Channel.ChannelType type; - /** - * Returns The An absolute URL for this channel.. - * - * @return An absolute URL for this channel. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String uniqueName; - /** - * Returns The Absolute URLs to access the [Members][members] and - * [Messages][messages] for this channel.. - * - * @return Absolute URLs to access the [Members][members] and - * [Messages][messages] for this channel. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Channel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.membersCount = membersCount; + this.messagesCount = messagesCount; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -358,58 +246,41 @@ public boolean equals(final Object o) { } Channel other = (Channel) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(attributes, other.attributes) && - Objects.equals(type, other.type) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy) && - Objects.equals(membersCount, other.membersCount) && - Objects.equals(messagesCount, other.messagesCount) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - friendlyName, - uniqueName, - attributes, - type, - dateCreated, - dateUpdated, - createdBy, - membersCount, - messagesCount, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("friendlyName", friendlyName) - .add("uniqueName", uniqueName) - .add("attributes", attributes) - .add("type", type) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .add("membersCount", membersCount) - .add("messagesCount", messagesCount) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + attributes, + createdBy, + dateCreated, + dateUpdated, + friendlyName, + links, + membersCount, + messagesCount, + serviceSid, + sid, + type, + uniqueName, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelCreator.java index 88b7b06409..52ece86916 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,128 +27,138 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ChannelCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; private String friendlyName; private String uniqueName; private String attributes; private Channel.ChannelType type; - /** - * Construct a new ChannelCreator. - * - * @param pathServiceSid The service_sid - */ public ChannelCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * A human-readable name for the Channel. Optional.. - * - * @param friendlyName A human-readable name for the Channel. - * @return this - */ public ChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A unique, addressable name for the Channel. Optional.. - * - * @param uniqueName A unique, addressable name for the Channel. - * @return this - */ public ChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An optional metadata field you can use to store any data you wish. No - * processing or validation is done on this field.. - * - * @param attributes An optional metadata field you can use to store any data - * you wish. - * @return this - */ public ChannelCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The visibility of the channel - `public` or `private`. Defaults to `public`.. - * - * @param type The visibility of the channel - public or private. - * @return this - */ public ChannelCreator setType(final Channel.ChannelType type) { this.type = type; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel create(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelDeleter.java index 203862e115..2e76c8f054 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ChannelDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ChannelDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public ChannelDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelFetcher.java index 10b4a083fe..9cb1c03b8f 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ChannelFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ChannelFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public ChannelFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelReader.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelReader.java index 55212c225d..94d289a48f 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; @@ -10,190 +17,218 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class ChannelReader extends Reader { - private final String pathServiceSid; + + private String pathServiceSid; private List type; + private Long pageSize; - /** - * Construct a new ChannelReader. - * - * @param pathServiceSid The service_sid - */ public ChannelReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * The type. - * - * @param type The type - * @return this - */ public ChannelReader setType(final List type) { this.type = type; return this; } - /** - * The type. - * - * @param type The type - * @return this - */ public ChannelReader setType(final Channel.ChannelType type) { return setType(Promoter.listOfOne(type)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Channel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - Channel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (type != null) { - for (Channel.ChannelType prop : type) { - request.addQueryParam("Type", prop.toString()); + for (Channel.ChannelType param : type) { + Serializer.toString( + request, + "Type", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/ChannelUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/ChannelUpdater.java index 2df90c0371..f8fa464bd4 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/ChannelUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,116 +27,126 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ChannelUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; private String friendlyName; private String uniqueName; private String attributes; - /** - * Construct a new ChannelUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelUpdater(final String pathServiceSid, - final String pathSid) { + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * A human-readable name for the Channel. Optional.. - * - * @param friendlyName A human-readable name for the Channel. - * @return this - */ public ChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A unique, addressable name for the Channel. Optional.. - * - * @param uniqueName A unique, addressable name for the Channel. - * @return this - */ public ChannelUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An optional metadata field you can use to store any data you wish. No - * processing or validation is done on this field.. - * - * @param attributes An optional metadata field you can use to store any data - * you wish. - * @return this - */ public ChannelUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel update(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/Role.java b/src/main/java/com/twilio/rest/chat/v1/service/Role.java index 2d924b3796..cecf9c68e5 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/Role.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/Role.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; @@ -10,33 +17,68 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Role extends Resource { - private static final long serialVersionUID = 78785177979928L; + + public static RoleCreator creator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + return new RoleCreator(pathServiceSid, friendlyName, type, permission); + } + + public static RoleDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new RoleDeleter(pathServiceSid, pathSid); + } + + public static RoleFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new RoleFetcher(pathServiceSid, pathSid); + } + + public static RoleReader reader(final String pathServiceSid) { + return new RoleReader(pathServiceSid); + } + + public static RoleUpdater updater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { + return new RoleUpdater(pathServiceSid, pathSid, permission); + } public enum RoleType { CHANNEL("channel"), @@ -48,93 +90,28 @@ private RoleType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a RoleType from a string. - * @param value string value - * @return generated RoleType - */ @JsonCreator public static RoleType forValue(final String value) { return Promoter.enumFromString(value, RoleType.values()); } } - /** - * Create a RoleFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return RoleFetcher capable of executing the fetch - */ - public static RoleFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new RoleFetcher(pathServiceSid, pathSid); - } - - /** - * Create a RoleDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return RoleDeleter capable of executing the delete - */ - public static RoleDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new RoleDeleter(pathServiceSid, pathSid); - } - - /** - * Create a RoleCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param friendlyName The human-readable name of this role. - * @param type What kind of role this is. - * @param permission A permission this role should have. - * @return RoleCreator capable of executing the create - */ - public static RoleCreator creator(final String pathServiceSid, - final String friendlyName, - final Role.RoleType type, - final List permission) { - return new RoleCreator(pathServiceSid, friendlyName, type, permission); - } - - /** - * Create a RoleReader to execute read. - * - * @param pathServiceSid The service_sid - * @return RoleReader capable of executing the read - */ - public static RoleReader reader(final String pathServiceSid) { - return new RoleReader(pathServiceSid); - } - - /** - * Create a RoleUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param permission A permission this role should have. - * @return RoleUpdater capable of executing the update - */ - public static RoleUpdater updater(final String pathServiceSid, - final String pathSid, - final List permission) { - return new RoleUpdater(pathServiceSid, pathSid, permission); - } - /** * Converts a JSON String into a Role object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Role object represented by the provided JSON */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -148,12 +125,15 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Role object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Role object represented by the provided JSON */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -164,125 +144,76 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String friendlyName; - private final Role.RoleType type; - private final List permissions; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private Role(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Role.RoleType type, - @JsonProperty("permissions") - final List permissions, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.friendlyName = friendlyName; - this.type = type; - this.permissions = permissions; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this role.. - * - * @return The unique id of the Account responsible for this role. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Service this role belongs to.. - * - * @return The unique id of the Service this role belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The human-readable name of this role.. - * - * @return The human-readable name of this role. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String friendlyName; - /** - * Returns The What kind of role this is.. - * - * @return What kind of role this is. - */ - public final Role.RoleType getType() { - return this.type; - } + @Getter + private final List permissions; - /** - * Returns The A JSON array of the permissions this role has.. - * - * @return A JSON array of the permissions this role has. - */ - public final List getPermissions() { - return this.permissions; - } + @Getter + private final String serviceSid; - /** - * Returns The The date that this resource was created in ISO 8601 format.. - * - * @return The date that this resource was created in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date that this resource was last updated in ISO 8601 format.. - * - * @return The date that this resource was last updated in ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Role.RoleType type; - /** - * Returns The An absolute URL for this role.. - * - * @return An absolute URL for this role. - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private Role( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("permissions") final List permissions, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.permissions = permissions; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.url = url; } @Override @@ -296,43 +227,31 @@ public boolean equals(final Object o) { } Role other = (Role) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(permissions, other.permissions) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(permissions, other.permissions) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - friendlyName, - type, - permissions, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("permissions", permissions) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + permissions, + serviceSid, + sid, + type, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleCreator.java index cc12b7379d..51b5f30e34 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleCreator.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,90 +28,138 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class RoleCreator extends Creator { - private final String pathServiceSid; - private final String friendlyName; - private final Role.RoleType type; - private final List permission; - - /** - * Construct a new RoleCreator. - * - * @param pathServiceSid The service_sid - * @param friendlyName The human-readable name of this role. - * @param type What kind of role this is. - * @param permission A permission this role should have. - */ - public RoleCreator(final String pathServiceSid, - final String friendlyName, - final Role.RoleType type, - final List permission) { + + private String pathServiceSid; + private String friendlyName; + private Role.RoleType type; + private List permission; + + public RoleCreator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role create(final TwilioRestClient client) { + public RoleCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public RoleCreator setType(final Role.RoleType type) { + this.type = type; + return this; + } + + public RoleCreator setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleCreator setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role create(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (permission != null) { - for (String prop : permission) { - request.addPostParam("Permission", prop); + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleDeleter.java index d49188f870..159729d2b8 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class RoleDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new RoleDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public RoleDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public RoleDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleFetcher.java index 9ef5e71199..848a23aa91 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RoleFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new RoleFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public RoleFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public RoleFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleReader.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleReader.java index 9fdf3e4494..9e6b0eb8d6 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; @@ -10,159 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RoleReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new RoleReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public RoleReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public RoleReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Role Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "roles", - response.getContent(), - Role.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/RoleUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/RoleUpdater.java index 15283a1eae..7e2b9ddcfd 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/RoleUpdater.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,78 +28,108 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class RoleUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; - private final List permission; - /** - * Construct a new RoleUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param permission A permission this role should have. - */ - public RoleUpdater(final String pathServiceSid, - final String pathSid, - final List permission) { + private String pathServiceSid; + private String pathSid; + private List permission; + + public RoleUpdater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.permission = permission; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role update(final TwilioRestClient client) { + public RoleUpdater setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleUpdater setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role update(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (permission != null) { - for (String prop : permission) { - request.addPostParam("Permission", prop); + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/User.java b/src/main/java/com/twilio/rest/chat/v1/service/User.java index c5957fb055..6e7ab47529 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/User.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/User.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; @@ -11,98 +18,74 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class User extends Resource { - private static final long serialVersionUID = 15176818292650L; - /** - * Create a UserFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserFetcher capable of executing the fetch - */ - public static UserFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new UserFetcher(pathServiceSid, pathSid); + public static UserCreator creator( + final String pathServiceSid, + final String identity + ) { + return new UserCreator(pathServiceSid, identity); } - /** - * Create a UserDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserDeleter capable of executing the delete - */ - public static UserDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static UserDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new UserDeleter(pathServiceSid, pathSid); } - /** - * Create a UserCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param identity A unique string that identifies the user within this service - * - often a username or email address. - * @return UserCreator capable of executing the create - */ - public static UserCreator creator(final String pathServiceSid, - final String identity) { - return new UserCreator(pathServiceSid, identity); + public static UserFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new UserFetcher(pathServiceSid, pathSid); } - /** - * Create a UserReader to execute read. - * - * @param pathServiceSid The service_sid - * @return UserReader capable of executing the read - */ public static UserReader reader(final String pathServiceSid) { return new UserReader(pathServiceSid); } - /** - * Create a UserUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserUpdater capable of executing the update - */ - public static UserUpdater updater(final String pathServiceSid, - final String pathSid) { + public static UserUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new UserUpdater(pathServiceSid, pathSid); } /** * Converts a JSON String into a User object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return User object represented by the provided JSON */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -116,12 +99,15 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a User object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return User object represented by the provided JSON */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -132,200 +118,105 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String attributes; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final String roleSid; + + @Getter private final String identity; - private final Boolean isOnline; + + @Getter private final Boolean isNotifiable; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final Boolean isOnline; + + @Getter private final Integer joinedChannelsCount; + + @Getter private final Map links; + + @Getter + private final String roleSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private User(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("is_online") - final Boolean isOnline, - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("joined_channels_count") - final Integer joinedChannelsCount, - @JsonProperty("links") - final Map links, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private User( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity") final String identity, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty( + "joined_channels_count" + ) final Integer joinedChannelsCount, + @JsonProperty("links") final Map links, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; this.attributes = attributes; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.roleSid = roleSid; this.identity = identity; - this.isOnline = isOnline; this.isNotifiable = isNotifiable; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.isOnline = isOnline; this.joinedChannelsCount = joinedChannelsCount; this.links = links; + this.roleSid = roleSid; + this.serviceSid = serviceSid; + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account responsible for this user.. - * - * @return The unique id of the Account responsible for this user. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique id of the Service this user belongs to.. - * - * @return The unique id of the Service this user belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } - - /** - * Returns The The human-readable name of this user.. - * - * @return The human-readable name of this user. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique id of the [Role][role] assigned to this user.. - * - * @return The unique id of the [Role][role] assigned to this user. - */ - public final String getRoleSid() { - return this.roleSid; - } - - /** - * Returns The A unique string that identifies the user within this service - - * often a username or email address.. - * - * @return A unique string that identifies the user within this service - often - * a username or email address. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Indicates whether the User is actively connected to the Service - * instance and online.. - * - * @return Indicates whether the User is actively connected to the Service - * instance and online. - */ - public final Boolean getIsOnline() { - return this.isOnline; - } - - /** - * Returns The Indicates whether the User has a potentially valid Push - * Notification registration for the Service instance.. - * - * @return Indicates whether the User has a potentially valid Push Notification - * registration for the Service instance. - */ - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - - /** - * Returns The The date that this resource was created in ISO 8601 format.. - * - * @return The date that this resource was created in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated in ISO 8601 format.. - * - * @return The date that this resource was last updated in ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The joined_channels_count. - * - * @return The joined_channels_count - */ - public final Integer getJoinedChannelsCount() { - return this.joinedChannelsCount; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The An absolute URL for this user.. - * - * @return An absolute URL for this user. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -337,58 +228,41 @@ public boolean equals(final Object o) { } User other = (User) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(identity, other.identity) && - Objects.equals(isOnline, other.isOnline) && - Objects.equals(isNotifiable, other.isNotifiable) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && - Objects.equals(links, other.links) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identity, other.identity) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && + Objects.equals(links, other.links) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - attributes, - friendlyName, - roleSid, - identity, - isOnline, - isNotifiable, - dateCreated, - dateUpdated, - joinedChannelsCount, - links, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("attributes", attributes) - .add("friendlyName", friendlyName) - .add("roleSid", roleSid) - .add("identity", identity) - .add("isOnline", isOnline) - .add("isNotifiable", isNotifiable) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("joinedChannelsCount", joinedChannelsCount) - .add("links", links) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + dateCreated, + dateUpdated, + friendlyName, + identity, + isNotifiable, + isOnline, + joinedChannelsCount, + links, + roleSid, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/UserCreator.java index 546fde9d34..0b5b311d74 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,124 +27,139 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserCreator extends Creator { - private final String pathServiceSid; - private final String identity; + + private String pathServiceSid; + private String identity; private String roleSid; private String attributes; private String friendlyName; - /** - * Construct a new UserCreator. - * - * @param pathServiceSid The service_sid - * @param identity A unique string that identifies the user within this service - * - often a username or email address. - */ - public UserCreator(final String pathServiceSid, - final String identity) { + public UserCreator(final String pathServiceSid, final String identity) { this.pathServiceSid = pathServiceSid; this.identity = identity; } - /** - * The unique id of the - * [Role](https://www.twilio.com/docs/api/chat/rest/v1/roles) assigned to this - * user.. - * - * @param roleSid The unique id of the Role assigned to this user. - * @return this - */ + public UserCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An optional string used to contain any metadata or other information for the - * User. The string must contain structurally valid JSON if specified.. - * - * @param attributes An optional string used to contain any metadata or other - * information for the User. - * @return this - */ public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * An optional human readable string representing the user. Often used for - * display purposes.. - * - * @param friendlyName An optional human readable string representing the user. - * @return this - */ public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User create(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/UserDeleter.java index a691095bf4..6d0fb2a629 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class UserDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new UserDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public UserDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/UserFetcher.java index 8c3cc27a37..2cdfdb3bfd 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new UserFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public UserFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserReader.java b/src/main/java/com/twilio/rest/chat/v1/service/UserReader.java index 4537c2388b..ae5e95f5e9 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; @@ -10,159 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new UserReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public UserReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of User Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "users", - response.getContent(), - User.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/UserUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/UserUpdater.java index 53ed3adea8..21e3567f77 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/UserUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,117 +27,126 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; private String roleSid; private String attributes; private String friendlyName; - /** - * Construct a new UserUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserUpdater(final String pathServiceSid, - final String pathSid) { + public UserUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * The unique id of the [Role][role] assigned to this user.. - * - * @param roleSid The unique id of the [Role][role] assigned to this user. - * @return this - */ public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An optional string used to contain any metadata or other information for the - * User. The string must contain structurally valid JSON if specified.. - * - * @param attributes An optional string used to contain any metadata or other - * information for the User. - * @return this - */ public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * An optional human readable string representing the user. Often used for - * display purposes.. - * - * @param friendlyName An optional human readable string representing the user. - * @return this - */ public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User update(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/Invite.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/Invite.java index a9cc058151..6084a6be77 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/Invite.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/Invite.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; @@ -11,93 +18,72 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Invite extends Resource { - private static final long serialVersionUID = 189960368613614L; - /** - * Create a InviteFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return InviteFetcher capable of executing the fetch - */ - public static InviteFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); + public static InviteCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { + return new InviteCreator(pathServiceSid, pathChannelSid, identity); } - /** - * Create a InviteCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * @return InviteCreator capable of executing the create - */ - public static InviteCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { - return new InviteCreator(pathServiceSid, pathChannelSid, identity); + public static InviteDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a InviteReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return InviteReader capable of executing the read - */ - public static InviteReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new InviteReader(pathServiceSid, pathChannelSid); + public static InviteFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a InviteDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return InviteDeleter capable of executing the delete - */ - public static InviteDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); + public static InviteReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new InviteReader(pathServiceSid, pathChannelSid); } /** * Converts a JSON String into a Invite object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Invite object represented by the provided JSON */ - public static Invite fromJson(final String json, final ObjectMapper objectMapper) { + public static Invite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -111,12 +97,15 @@ public static Invite fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Invite object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Invite object represented by the provided JSON */ - public static Invite fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Invite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -127,141 +116,83 @@ public static Invite fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String channelSid; - private final String serviceSid; + + @Getter + private final String createdBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final String roleSid; - private final String createdBy; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private Invite(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("created_by") - final String createdBy, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Invite( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.channelSid = channelSid; - this.serviceSid = serviceSid; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.roleSid = roleSid; - this.createdBy = createdBy; + this.serviceSid = serviceSid; + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account[/console] responsible for this - * member.. - * - * @return The unique id of the Account[/console] responsible for this member. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique id of the Channel for this member.. - * - * @return The unique id of the Channel for this member. - */ - public final String getChannelSid() { - return this.channelSid; - } - - /** - * Returns The The unique id of the Service this member belongs to.. - * - * @return The unique id of the Service this member belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The A unique string identifier for this User in this Service.. - * - * @return A unique string identifier for this User in this Service. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The Role assigned to this member.. - * - * @return The Role assigned to this member. - */ - public final String getRoleSid() { - return this.roleSid; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - /** - * Returns The An absolute URL for this member.. - * - * @return An absolute URL for this member. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -273,46 +204,33 @@ public boolean equals(final Object o) { } Invite other = (Invite) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(createdBy, other.createdBy) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - channelSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - roleSid, - createdBy, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("channelSid", channelSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("roleSid", roleSid) - .add("createdBy", createdBy) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + channelSid, + createdBy, + dateCreated, + dateUpdated, + identity, + roleSid, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteCreator.java index 21cf2599d1..d377f3e509 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,91 +27,120 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class InviteCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String identity; + + private String pathServiceSid; + private String pathChannelSid; + private String identity; private String roleSid; - /** - * Construct a new InviteCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - */ - public InviteCreator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { + public InviteCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - /** - * The [Role](https://www.twilio.com/docs/api/chat/rest/v1/role) assigned to - * this member.. - * - * @param roleSid The Role assigned to this member. - * @return this - */ + public InviteCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public InviteCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Invite - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Invite create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Invite create(final TwilioRestClient client) { + Response response = makeRequest(client); return Invite.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Invite content = Invite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteDeleter.java index 59cb985d95..0461a32ccf 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class InviteDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new InviteDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public InviteDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public InviteDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteFetcher.java index 1d560b9a7b..5f71bdf903 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class InviteFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new InviteFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public InviteFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public InviteFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Invite - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Invite fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Invite fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Invite.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Invite content = Invite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteReader.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteReader.java index 234dffbc8d..beace15874 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/InviteReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; @@ -10,202 +17,224 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class InviteReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private List identity; + private Long pageSize; - /** - * Construct a new InviteReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public InviteReader(final String pathServiceSid, - final String pathChannelSid) { + public InviteReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/v1/user) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). See the - * [access - * tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public InviteReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/v1/user) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). See the - * [access - * tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public InviteReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public InviteReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Invite read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Invite Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Invite read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "invites", - response.getContent(), - Invite.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/Member.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/Member.java index b61642770c..737d55d70e 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/Member.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/Member.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; @@ -11,107 +18,80 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Member extends Resource { - private static final long serialVersionUID = 102574959310114L; - /** - * Create a MemberFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberFetcher capable of executing the fetch - */ - public static MemberFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); + public static MemberCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { + return new MemberCreator(pathServiceSid, pathChannelSid, identity); } - /** - * Create a MemberCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * @return MemberCreator capable of executing the create - */ - public static MemberCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { - return new MemberCreator(pathServiceSid, pathChannelSid, identity); + public static MemberDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a MemberReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MemberReader capable of executing the read - */ - public static MemberReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new MemberReader(pathServiceSid, pathChannelSid); + public static MemberFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a MemberDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberDeleter capable of executing the delete - */ - public static MemberDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); + public static MemberReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MemberReader(pathServiceSid, pathChannelSid); } - /** - * Create a MemberUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberUpdater capable of executing the update - */ - public static MemberUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public static MemberUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberUpdater(pathServiceSid, pathChannelSid, pathSid); } /** * Converts a JSON String into a Member object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -125,12 +105,15 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Member object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -141,155 +124,93 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; - private final String accountSid; - private final String channelSid; - private final String serviceSid; - private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String roleSid; - private final Integer lastConsumedMessageIndex; - private final DateTime lastConsumptionTimestamp; - private final URI url; - - @JsonCreator - private Member(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - @JsonProperty("last_consumption_timestamp") - final String lastConsumptionTimestamp, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.channelSid = channelSid; - this.serviceSid = serviceSid; - this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.roleSid = roleSid; - this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.lastConsumptionTimestamp = DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this member.. - * - * @return The unique id of the Account responsible for this member. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String channelSid; - /** - * Returns The The unique id of the Channel for this member.. - * - * @return The unique id of the Channel for this member. - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Service this member belongs to.. - * - * @return The unique id of the Service this member belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A unique string identifier for this User in this Service.. - * - * @return A unique string identifier for this User in this Service. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final String identity; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Integer lastConsumedMessageIndex; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime lastConsumptionTimestamp; - /** - * Returns The The Role assigned to this member.. - * - * @return The Role assigned to this member. - */ - public final String getRoleSid() { - return this.roleSid; - } + @Getter + private final String roleSid; - /** - * Returns The An Integer representing index of the last Message this Member has - * read within this Channel. - * - * @return An Integer representing index of the last Message this Member has - * read within this Channel - */ - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } + @Getter + private final String serviceSid; - /** - * Returns The An ISO8601 based timestamp string representing the datetime of - * the last Message read event for this Member within this Channel. - * - * @return An ISO8601 based timestamp string representing the datetime of the - * last Message read event for this Member within this Channel - */ - public final DateTime getLastConsumptionTimestamp() { - return this.lastConsumptionTimestamp; - } + @Getter + private final String sid; - /** - * Returns The An absolute URL for this member.. - * - * @return An absolute URL for this member. - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private Member( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty("last_consumption_timestamp") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime lastConsumptionTimestamp, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.identity = identity; + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + this.lastConsumptionTimestamp = lastConsumptionTimestamp; + this.roleSid = roleSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -303,49 +224,41 @@ public boolean equals(final Object o) { } Member other = (Member) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && - Objects.equals(lastConsumptionTimestamp, other.lastConsumptionTimestamp) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals( + lastConsumptionTimestamp, + other.lastConsumptionTimestamp + ) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - channelSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - roleSid, - lastConsumedMessageIndex, - lastConsumptionTimestamp, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("channelSid", channelSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("roleSid", roleSid) - .add("lastConsumedMessageIndex", lastConsumedMessageIndex) - .add("lastConsumptionTimestamp", lastConsumptionTimestamp) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + channelSid, + dateCreated, + dateUpdated, + identity, + lastConsumedMessageIndex, + lastConsumptionTimestamp, + roleSid, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberCreator.java index c0bbe515cc..e146df5a49 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,91 +27,120 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String identity; + + private String pathServiceSid; + private String pathChannelSid; + private String identity; private String roleSid; - /** - * Construct a new MemberCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - */ - public MemberCreator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { + public MemberCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - /** - * The [Role](https://www.twilio.com/docs/api/chat/rest/v1/roles) assigned to - * this member.. - * - * @param roleSid The Role assigned to this member. - * @return this - */ + public MemberCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public MemberCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member create(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberDeleter.java index 8935b09df5..8cfa35cce3 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MemberDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MemberDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MemberDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberFetcher.java index 580cfc5126..b74f8905a9 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MemberFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MemberFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberReader.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberReader.java index 1e3d0accb1..16dbd471ac 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; @@ -10,202 +17,224 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class MemberReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private List identity; + private Long pageSize; - /** - * Construct a new MemberReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MemberReader(final String pathServiceSid, - final String pathChannelSid) { + public MemberReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/v1/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/v1/services). See the - * [access - * tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public MemberReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/v1/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/v1/services). See the - * [access - * tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public MemberReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MemberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Member Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "members", - response.getContent(), - Member.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberUpdater.java index 3115ec5a28..6e5e55d6b6 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MemberUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,108 +27,125 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; private String roleSid; private Integer lastConsumedMessageIndex; - /** - * Construct a new MemberUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public MemberUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The [Role](https://www.twilio.com/docs/api/chat/rest/v1/roles) assigned to - * this member.. - * - * @param roleSid The Role assigned to this member. - * @return this - */ public MemberUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An Integer representing index of the last - * [Message](https://www.twilio.com/docs/api/chat/rest/v1/messages) this Member - * has read within this - * [Channel](https://www.twilio.com/docs/api/chat/rest/v1/channels). - * - * @param lastConsumedMessageIndex An Integer representing index of the last - * Message this Member has read within this - * Channel - * @return this - */ - public MemberUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex) { + public MemberUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member update(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); + Serializer.toString( + request, + "LastConsumedMessageIndex", + lastConsumedMessageIndex, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/Message.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/Message.java index 1315ba9cd7..20bc60b5ad 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/Message.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/Message.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; @@ -10,32 +17,71 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Message extends Resource { - private static final long serialVersionUID = 68490171213295L; + + public static MessageCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String body + ) { + return new MessageCreator(pathServiceSid, pathChannelSid, body); + } + + public static MessageDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); + } + + public static MessageFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); + } + + public static MessageReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MessageReader(pathServiceSid, pathChannelSid); + } + + public static MessageUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); + } public enum OrderType { ASC("asc"), @@ -47,97 +93,28 @@ private OrderType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a OrderType from a string. - * @param value string value - * @return generated OrderType - */ @JsonCreator public static OrderType forValue(final String value) { return Promoter.enumFromString(value, OrderType.values()); } } - /** - * Create a MessageFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageFetcher capable of executing the fetch - */ - public static MessageFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); - } - - /** - * Create a MessageCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param body The body - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String body) { - return new MessageCreator(pathServiceSid, pathChannelSid, body); - } - - /** - * Create a MessageReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MessageReader capable of executing the read - */ - public static MessageReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new MessageReader(pathServiceSid, pathChannelSid); - } - - /** - * Create a MessageDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageDeleter capable of executing the delete - */ - public static MessageDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); - } - - /** - * Create a MessageUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageUpdater capable of executing the update - */ - public static MessageUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); - } - /** * Converts a JSON String into a Message object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -151,12 +128,15 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Message object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -167,179 +147,96 @@ public static Message fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String attributes; - private final String serviceSid; - private final String to; - private final String channelSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final Boolean wasEdited; - private final String from; - private final String body; - private final Integer index; - private final URI url; - - @JsonCreator - private Message(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("to") - final String to, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("was_edited") - final Boolean wasEdited, - @JsonProperty("from") - final String from, - @JsonProperty("body") - final String body, - @JsonProperty("index") - final Integer index, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.attributes = attributes; - this.serviceSid = serviceSid; - this.to = to; - this.channelSid = channelSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.wasEdited = wasEdited; - this.from = from; - this.body = body; - this.index = index; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this message.. - * - * @return The unique id of the Account responsible for this message. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String attributes; - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } + @Getter + private final String body; - /** - * Returns The The unique id of the Service this message belongs to.. - * - * @return The unique id of the Service this message belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String channelSid; - /** - * Returns The The unique id of the Channel this message was sent to.. - * - * @return The unique id of the Channel this message was sent to. - */ - public final String getTo() { - return this.to; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The channel_sid. - * - * @return The channel_sid - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String from; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer index; - /** - * Returns The true if the message has been updated since it was created.. - * - * @return true if the message has been updated since it was created. - */ - public final Boolean getWasEdited() { - return this.wasEdited; - } + @Getter + private final String serviceSid; - /** - * Returns The The identity of the message's author.. - * - * @return The identity of the message's author. - */ - public final String getFrom() { - return this.from; - } + @Getter + private final String sid; - /** - * Returns The The contents of the message.. - * - * @return The contents of the message. - */ - public final String getBody() { - return this.body; - } + @Getter + private final String to; - /** - * Returns The The index of the message within the Channel. - * - * @return The index of the message within the Channel - */ - public final Integer getIndex() { - return this.index; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this message.. - * - * @return An absolute URL for this message. - */ - public final URI getUrl() { - return this.url; + @Getter + private final Boolean wasEdited; + + @JsonCreator + private Message( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("body") final String body, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("from") final String from, + @JsonProperty("index") final Integer index, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("to") final String to, + @JsonProperty("url") final URI url, + @JsonProperty("was_edited") final Boolean wasEdited + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.body = body; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.from = from; + this.index = index; + this.serviceSid = serviceSid; + this.sid = sid; + this.to = to; + this.url = url; + this.wasEdited = wasEdited; } @Override @@ -353,55 +250,39 @@ public boolean equals(final Object o) { } Message other = (Message) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(to, other.to) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(wasEdited, other.wasEdited) && - Objects.equals(from, other.from) && - Objects.equals(body, other.body) && - Objects.equals(index, other.index) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(body, other.body) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(from, other.from) && + Objects.equals(index, other.index) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(to, other.to) && + Objects.equals(url, other.url) && + Objects.equals(wasEdited, other.wasEdited) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - attributes, - serviceSid, - to, - channelSid, - dateCreated, - dateUpdated, - wasEdited, - from, - body, - index, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("attributes", attributes) - .add("serviceSid", serviceSid) - .add("to", to) - .add("channelSid", channelSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("wasEdited", wasEdited) - .add("from", from) - .add("body", body) - .add("index", index) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + body, + channelSid, + dateCreated, + dateUpdated, + from, + index, + serviceSid, + sid, + to, + url, + wasEdited + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageCreator.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageCreator.java index 0753b774a9..c5ca653376 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageCreator.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,106 +27,136 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String body; + + private String pathServiceSid; + private String pathChannelSid; + private String body; private String from; private String attributes; - /** - * Construct a new MessageCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param body The body - */ - public MessageCreator(final String pathServiceSid, - final String pathChannelSid, - final String body) { + public MessageCreator( + final String pathServiceSid, + final String pathChannelSid, + final String body + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.body = body; } - /** - * The from. - * - * @param from The from - * @return this - */ + public MessageCreator setBody(final String body) { + this.body = body; + return this; + } + public MessageCreator setFrom(final String from) { this.from = from; return this; } - /** - * The attributes. - * - * @param attributes The attributes - * @return this - */ public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message create(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (from != null) { - request.addPostParam("From", from); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageDeleter.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageDeleter.java index 60823e9bbf..319305e932 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MessageDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MessageDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MessageDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageFetcher.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageFetcher.java index 3726a63285..882e9c471a 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MessageFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MessageFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageReader.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageReader.java index 0dfa6516a5..8df50cd132 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; @@ -10,179 +17,216 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private Message.OrderType order; + private Long pageSize; - /** - * Construct a new MessageReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MessageReader(final String pathServiceSid, - final String pathChannelSid) { + public MessageReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * The order. - * - * @param order The order - * @return this - */ public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MessageReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Message Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "messages", - response.getContent(), - Message.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); + Serializer.toString(request, "Order", order, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageUpdater.java b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageUpdater.java index 64ed4521dd..3ed97f9467 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/channel/MessageUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,105 +27,123 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; private String body; private String attributes; - /** - * Construct a new MessageUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public MessageUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The new message body string. You can also send structured data by serializing - * it into a string.. - * - * @param body The new message body string. - * @return this - */ public MessageUpdater setBody(final String body) { this.body = body; return this; } - /** - * The new attributes metadata field you can use to store any data you wish. - * The string value must contain structurally valid JSON if specified.. - * - * @param attributes The new attributes metadata field you can use to store any - * data you wish. - * @return this - */ public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message update(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannel.java b/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannel.java index 2ef6e882dd..dd4c0cf073 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannel.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.user; @@ -10,29 +17,36 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class UserChannel extends Resource { - private static final long serialVersionUID = 254880238496884L; + + public static UserChannelReader reader( + final String pathServiceSid, + final String pathUserSid + ) { + return new UserChannelReader(pathServiceSid, pathUserSid); + } public enum ChannelStatus { JOINED("joined"), @@ -45,15 +59,11 @@ private ChannelStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ChannelStatus from a string. - * @param value string value - * @return generated ChannelStatus - */ @JsonCreator public static ChannelStatus forValue(final String value) { return Promoter.enumFromString(value, ChannelStatus.values()); @@ -61,26 +71,16 @@ public static ChannelStatus forValue(final String value) { } /** - * Create a UserChannelReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @return UserChannelReader capable of executing the read - */ - public static UserChannelReader reader(final String pathServiceSid, - final String pathUserSid) { - return new UserChannelReader(pathServiceSid, pathUserSid); - } - - /** - * Converts a JSON String into a UserChannel object using the provided - * ObjectMapper. - * + * Converts a JSON String into a UserChannel object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return UserChannel object represented by the provided JSON */ - public static UserChannel fromJson(final String json, final ObjectMapper objectMapper) { + public static UserChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -94,12 +94,15 @@ public static UserChannel fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a UserChannel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return UserChannel object represented by the provided JSON */ - public static UserChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static UserChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -110,112 +113,63 @@ public static UserChannel fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String channelSid; + + @Getter + private final Integer lastConsumedMessageIndex; + + @Getter + private final Map links; + + @Getter private final String memberSid; + + @Getter + private final String serviceSid; + + @Getter private final UserChannel.ChannelStatus status; - private final Integer lastConsumedMessageIndex; + + @Getter private final Integer unreadMessagesCount; - private final Map links; @JsonCreator - private UserChannel(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("member_sid") - final String memberSid, - @JsonProperty("status") - final UserChannel.ChannelStatus status, - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - @JsonProperty("links") - final Map links) { + private UserChannel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty("links") final Map links, + @JsonProperty("member_sid") final String memberSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("status") final UserChannel.ChannelStatus status, + @JsonProperty("unread_messages_count") final Integer unreadMessagesCount + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; this.channelSid = channelSid; + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + this.links = links; this.memberSid = memberSid; + this.serviceSid = serviceSid; this.status = status; - this.lastConsumedMessageIndex = lastConsumedMessageIndex; this.unreadMessagesCount = unreadMessagesCount; - this.links = links; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The channel_sid. - * - * @return The channel_sid - */ - public final String getChannelSid() { - return this.channelSid; - } - - /** - * Returns The The member_sid. - * - * @return The member_sid - */ - public final String getMemberSid() { - return this.memberSid; - } - - /** - * Returns The The status. - * - * @return The status - */ - public final UserChannel.ChannelStatus getStatus() { - return this.status; - } - - /** - * Returns The The last_consumed_message_index. - * - * @return The last_consumed_message_index - */ - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - - /** - * Returns The The unread_messages_count. - * - * @return The unread_messages_count - */ - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -229,40 +183,32 @@ public boolean equals(final Object o) { } UserChannel other = (UserChannel) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(memberSid, other.memberSid) && - Objects.equals(status, other.status) && - Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && - Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals(links, other.links) && + Objects.equals(memberSid, other.memberSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(status, other.status) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - channelSid, - memberSid, - status, - lastConsumedMessageIndex, - unreadMessagesCount, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("channelSid", channelSid) - .add("memberSid", memberSid) - .add("status", status) - .add("lastConsumedMessageIndex", lastConsumedMessageIndex) - .add("unreadMessagesCount", unreadMessagesCount) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + channelSid, + lastConsumedMessageIndex, + links, + memberSid, + serviceSid, + status, + unreadMessagesCount + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannelReader.java b/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannelReader.java index 79745b62d4..fcac5d247a 100644 --- a/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannelReader.java +++ b/src/main/java/com/twilio/rest/chat/v1/service/user/UserChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v1.service.user; @@ -10,163 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserChannelReader extends Reader { - private final String pathServiceSid; - private final String pathUserSid; - - /** - * Construct a new UserChannelReader. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - */ - public UserChannelReader(final String pathServiceSid, - final String pathUserSid) { + + private String pathServiceSid; + private String pathUserSid; + private Long pageSize; + + public UserChannelReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users/{UserSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UserChannel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of UserChannel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserChannel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - UserChannel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/Credential.java b/src/main/java/com/twilio/rest/chat/v2/Credential.java index c253160bfa..b0c9648d0a 100644 --- a/src/main/java/com/twilio/rest/chat/v2/Credential.java +++ b/src/main/java/com/twilio/rest/chat/v2/Credential.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; @@ -10,32 +17,52 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Credential extends Resource { - private static final long serialVersionUID = 133884911230690L; + + public static CredentialCreator creator(final Credential.PushService type) { + return new CredentialCreator(type); + } + + public static CredentialDeleter deleter(final String pathSid) { + return new CredentialDeleter(pathSid); + } + + public static CredentialFetcher fetcher(final String pathSid) { + return new CredentialFetcher(pathSid); + } + + public static CredentialReader reader() { + return new CredentialReader(); + } + + public static CredentialUpdater updater(final String pathSid) { + return new CredentialUpdater(pathSid); + } public enum PushService { GCM("gcm"), @@ -48,15 +75,11 @@ private PushService(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a PushService from a string. - * @param value string value - * @return generated PushService - */ @JsonCreator public static PushService forValue(final String value) { return Promoter.enumFromString(value, PushService.values()); @@ -64,63 +87,16 @@ public static PushService forValue(final String value) { } /** - * Create a CredentialReader to execute read. - * - * @return CredentialReader capable of executing the read - */ - public static CredentialReader reader() { - return new CredentialReader(); - } - - /** - * Create a CredentialCreator to execute create. - * - * @param type Credential type, one of "gcm", "fcm", or "apn" - * @return CredentialCreator capable of executing the create - */ - public static CredentialCreator creator(final Credential.PushService type) { - return new CredentialCreator(type); - } - - /** - * Create a CredentialFetcher to execute fetch. - * - * @param pathSid The sid - * @return CredentialFetcher capable of executing the fetch - */ - public static CredentialFetcher fetcher(final String pathSid) { - return new CredentialFetcher(pathSid); - } - - /** - * Create a CredentialUpdater to execute update. - * - * @param pathSid The sid - * @return CredentialUpdater capable of executing the update - */ - public static CredentialUpdater updater(final String pathSid) { - return new CredentialUpdater(pathSid); - } - - /** - * Create a CredentialDeleter to execute delete. - * - * @param pathSid The sid - * @return CredentialDeleter capable of executing the delete - */ - public static CredentialDeleter deleter(final String pathSid) { - return new CredentialDeleter(pathSid); - } - - /** - * Converts a JSON String into a Credential object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -134,12 +110,15 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a Credential object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -150,118 +129,73 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final Credential.PushService type; + + @Getter private final String sandbox; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final Credential.PushService type; + + @Getter private final URI url; @JsonCreator - private Credential(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Credential.PushService type, - @JsonProperty("sandbox") - final String sandbox, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Credential( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.type = type; this.sandbox = sandbox; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.sid = sid; + this.type = type; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account responsible for this resource.. - * - * @return The unique id of the Account responsible for this resource. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The human-readable name of this resource.. - * - * @return The human-readable name of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The Indicates which push notifications service this credential is for - * - either gcm, fcm, or apn. - * - * @return Indicates which push notifications service this credential is for - - * either gcm, fcm, or apn - */ - public final Credential.PushService getType() { - return this.type; - } - - /** - * Returns The [APN only] true when this resource should use the sandbox APN - * service.. - * - * @return [APN only] true when this resource should use the sandbox APN - * service. - */ - public final String getSandbox() { - return this.sandbox; - } - - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The An absolute URL for this credential resource.. - * - * @return An absolute URL for this credential resource. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -273,40 +207,29 @@ public boolean equals(final Object o) { } Credential other = (Credential) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(sandbox, other.sandbox) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - type, - sandbox, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("sandbox", sandbox) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sandbox, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialCreator.java b/src/main/java/com/twilio/rest/chat/v2/CredentialCreator.java index 1e2a6ec3a3..c4e5aeeb9d 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,9 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialCreator extends Creator { - private final Credential.PushService type; + + private Credential.PushService type; private String friendlyName; private String certificate; private String privateKey; @@ -26,166 +40,166 @@ public class CredentialCreator extends Creator { private String apiKey; private String secret; - /** - * Construct a new CredentialCreator. - * - * @param type Credential type, one of "gcm", "fcm", or "apn" - */ public CredentialCreator(final Credential.PushService type) { this.type = type; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ + public CredentialCreator setType(final Credential.PushService type) { + this.type = type; + return this; + } + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate, e.g. - * `-----BEGIN CERTIFICATE----- - * MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== - * -----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate, - * e. - * @return this - */ public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key, e.g. - * `-----BEGIN RSA PRIVATE KEY----- - * MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. - * -----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key, - * e. - * @return this - */ public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "API key" for project from Google Developer console - * for your GCM Service application credential. - * - * @param apiKey [GCM only] This is the "API key" for project from Google - * Developer console for your GCM Service application credential - * @return this - */ public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * [FCM only] This is the "Server key" of your project from Firebase console - * under Settings / Cloud messaging.. - * - * @param secret [FCM only] This is the "Server key" of your project from - * Firebase console under Settings / Cloud messaging. - * @return this - */ public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Credentials"; + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Credentials", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialDeleter.java b/src/main/java/com/twilio/rest/chat/v2/CredentialDeleter.java index cb3f302106..e2fa8c6876 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class CredentialDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new CredentialDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialFetcher.java b/src/main/java/com/twilio/rest/chat/v2/CredentialFetcher.java index 2ed907f3d6..9cde5df42a 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new CredentialFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialReader.java b/src/main/java/com/twilio/rest/chat/v2/CredentialReader.java index 17d6264a3a..a099d3b735 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public CredentialReader() {} + + public CredentialReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Credentials"; + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Credentials", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Credential Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credentials", - response.getContent(), - Credential.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/CredentialUpdater.java b/src/main/java/com/twilio/rest/chat/v2/CredentialUpdater.java index 0ab6a2a745..76fade8955 100644 --- a/src/main/java/com/twilio/rest/chat/v2/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/CredentialUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,9 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String certificate; private String privateKey; @@ -26,162 +40,154 @@ public class CredentialUpdater extends Updater { private String apiKey; private String secret; - /** - * Construct a new CredentialUpdater. - * - * @param pathSid The sid - */ public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate, e.g. - * `-----BEGIN CERTIFICATE----- - * MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== - * -----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate, - * e. - * @return this - */ public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key, e.g. - * `-----BEGIN RSA PRIVATE KEY----- - * MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. - * -----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key, - * e. - * @return this - */ public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "API key" for project from Google Developer console - * for your GCM Service application credential. - * - * @param apiKey [GCM only] This is the "API key" for project from Google - * Developer console for your GCM Service application credential - * @return this - */ public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * [FCM only] This is the "Server key" of your project from Firebase console - * under Settings / Cloud messaging.. - * - * @param secret [FCM only] This is the "Server key" of your project from - * Firebase console under Settings / Cloud messaging. - * @return this - */ public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Credentials/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Credential update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/Service.java b/src/main/java/com/twilio/rest/chat/v2/Service.java index 5500502198..799ea206db 100644 --- a/src/main/java/com/twilio/rest/chat/v2/Service.java +++ b/src/main/java/com/twilio/rest/chat/v2/Service.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; @@ -11,90 +18,63 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Service extends Resource { - private static final long serialVersionUID = 81815704097903L; - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid The sid - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); + public static ServiceCreator creator(final String friendlyName) { + return new ServiceCreator(friendlyName); } - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid The sid - * @return ServiceDeleter capable of executing the delete - */ public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - /** - * Create a ServiceCreator to execute create. - * - * @param friendlyName Human-readable name for this service instance - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator(final String friendlyName) { - return new ServiceCreator(friendlyName); + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); } - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ public static ServiceReader reader() { return new ServiceReader(); } - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid The sid - * @return ServiceUpdater capable of executing the update - */ public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** * Converts a JSON String into a Service object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -108,12 +88,15 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Service object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -124,325 +107,160 @@ public static Service fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String defaultServiceRoleSid; - private final String defaultChannelRoleSid; - private final String defaultChannelCreatorRoleSid; - private final Boolean readStatusEnabled; - private final Boolean reachabilityEnabled; - private final Integer typingIndicatorTimeout; - private final Integer consumptionReportInterval; - private final Map limits; - private final String preWebhookUrl; - private final String postWebhookUrl; - private final String webhookMethod; - private final List webhookFilters; - private final Integer preWebhookRetryCount; - private final Integer postWebhookRetryCount; - private final Map notifications; - private final Map media; - private final URI url; - private final Map links; - - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("default_service_role_sid") - final String defaultServiceRoleSid, - @JsonProperty("default_channel_role_sid") - final String defaultChannelRoleSid, - @JsonProperty("default_channel_creator_role_sid") - final String defaultChannelCreatorRoleSid, - @JsonProperty("read_status_enabled") - final Boolean readStatusEnabled, - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled, - @JsonProperty("typing_indicator_timeout") - final Integer typingIndicatorTimeout, - @JsonProperty("consumption_report_interval") - final Integer consumptionReportInterval, - @JsonProperty("limits") - final Map limits, - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - @JsonProperty("webhook_method") - final String webhookMethod, - @JsonProperty("webhook_filters") - final List webhookFilters, - @JsonProperty("pre_webhook_retry_count") - final Integer preWebhookRetryCount, - @JsonProperty("post_webhook_retry_count") - final Integer postWebhookRetryCount, - @JsonProperty("notifications") - final Map notifications, - @JsonProperty("media") - final Map media, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.defaultServiceRoleSid = defaultServiceRoleSid; - this.defaultChannelRoleSid = defaultChannelRoleSid; - this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; - this.readStatusEnabled = readStatusEnabled; - this.reachabilityEnabled = reachabilityEnabled; - this.typingIndicatorTimeout = typingIndicatorTimeout; - this.consumptionReportInterval = consumptionReportInterval; - this.limits = limits; - this.preWebhookUrl = preWebhookUrl; - this.postWebhookUrl = postWebhookUrl; - this.webhookMethod = webhookMethod; - this.webhookFilters = webhookFilters; - this.preWebhookRetryCount = preWebhookRetryCount; - this.postWebhookRetryCount = postWebhookRetryCount; - this.notifications = notifications; - this.media = media; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this service.. - * - * @return The unique id of the Account responsible for this service. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Integer consumptionReportInterval; - /** - * Returns The The human-readable name of this service.. - * - * @return The human-readable name of this service. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String defaultChannelCreatorRoleSid; - /** - * Returns The The service role assigned to users when they are added to the - * service.. - * - * @return The service role assigned to users when they are added to the - * service. - */ - public final String getDefaultServiceRoleSid() { - return this.defaultServiceRoleSid; - } + @Getter + private final String defaultChannelRoleSid; - /** - * Returns The The channel role assigned to users when they are added to a - * channel.. - * - * @return The channel role assigned to users when they are added to a channel. - */ - public final String getDefaultChannelRoleSid() { - return this.defaultChannelRoleSid; - } + @Getter + private final String defaultServiceRoleSid; - /** - * Returns The The channel role assigned to a channel creator when joining a new - * channel.. - * - * @return The channel role assigned to a channel creator when joining a new - * channel. - */ - public final String getDefaultChannelCreatorRoleSid() { - return this.defaultChannelCreatorRoleSid; - } + @Getter + private final String friendlyName; - /** - * Returns The Enable the Message Constumption Horizon feature.. - * - * @return Enable the Message Constumption Horizon feature. - */ - public final Boolean getReadStatusEnabled() { - return this.readStatusEnabled; - } + @Getter + private final Object limits; - /** - * Returns The Indicates whether the the Reachability feature is enabled for - * this Service instance.. - * - * @return Indicates whether the the Reachability feature is enabled for this - * Service instance. - */ - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } + @Getter + private final Map links; - /** - * Returns The The amount of time in seconds after a "started typing" event when - * clients should assume that user is no longer typing, even if no "ended - * typing" message was received.. - * - * @return The amount of time in seconds after a "started typing" event when - * clients should assume that user is no longer typing, even if no - * "ended typing" message was received. - */ - public final Integer getTypingIndicatorTimeout() { - return this.typingIndicatorTimeout; - } + @Getter + private final Object media; - /** - * Returns The DEPRECATED.. - * - * @return DEPRECATED. - */ - public final Integer getConsumptionReportInterval() { - return this.consumptionReportInterval; - } + @Getter + private final Object notifications; - /** - * Returns The Configuration for service instance level limits.. - * - * @return Configuration for service instance level limits. - */ - public final Map getLimits() { - return this.limits; - } + @Getter + private final Integer postWebhookRetryCount; - /** - * Returns The The webhook URL for PRE-Event webhooks.. - * - * @return The webhook URL for PRE-Event webhooks. - */ - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } + @Getter + private final String postWebhookUrl; - /** - * Returns The The webhook URL for POST-Event webhooks.. - * - * @return The webhook URL for POST-Event webhooks. - */ - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } + @Getter + private final Integer preWebhookRetryCount; - /** - * Returns The The webhook request format to use for both PRE and POST - * webhooks.. - * - * @return The webhook request format to use for both PRE and POST webhooks. - */ - public final String getWebhookMethod() { - return this.webhookMethod; - } + @Getter + private final String preWebhookUrl; - /** - * Returns The The list of WebHook events that are enabled for this Service - * instance.. - * - * @return The list of WebHook events that are enabled for this Service - * instance. - */ - public final List getWebhookFilters() { - return this.webhookFilters; - } + @Getter + private final Boolean reachabilityEnabled; - /** - * Returns The Count of times webhook will be retried in case of timeout or - * 429/503/504 HTTP responses.. - * - * @return Count of times webhook will be retried in case of timeout or - * 429/503/504 HTTP responses. - */ - public final Integer getPreWebhookRetryCount() { - return this.preWebhookRetryCount; - } + @Getter + private final Boolean readStatusEnabled; - /** - * Returns The Count of times webhook will be retried in case of timeout or - * 429/503/504 HTTP responses.. - * - * @return Count of times webhook will be retried in case of timeout or - * 429/503/504 HTTP responses. - */ - public final Integer getPostWebhookRetryCount() { - return this.postWebhookRetryCount; - } + @Getter + private final String sid; - /** - * Returns The Notification configuration for the Service instance.. - * - * @return Notification configuration for the Service instance. - */ - public final Map getNotifications() { - return this.notifications; - } + @Getter + private final Integer typingIndicatorTimeout; - /** - * Returns The The media. - * - * @return The media - */ - public final Map getMedia() { - return this.media; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this service.. - * - * @return An absolute URL for this service. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final List webhookFilters; - /** - * Returns The URLs to access the Channels, Roles, and Users for this service.. - * - * @return URLs to access the Channels, Roles, and Users for this service. - */ - public final Map getLinks() { - return this.links; + @Getter + private final String webhookMethod; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "consumption_report_interval" + ) final Integer consumptionReportInterval, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "default_channel_creator_role_sid" + ) final String defaultChannelCreatorRoleSid, + @JsonProperty( + "default_channel_role_sid" + ) final String defaultChannelRoleSid, + @JsonProperty( + "default_service_role_sid" + ) final String defaultServiceRoleSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("limits") final Object limits, + @JsonProperty("links") final Map links, + @JsonProperty("media") final Object media, + @JsonProperty("notifications") final Object notifications, + @JsonProperty( + "post_webhook_retry_count" + ) final Integer postWebhookRetryCount, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty( + "pre_webhook_retry_count" + ) final Integer preWebhookRetryCount, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty("read_status_enabled") final Boolean readStatusEnabled, + @JsonProperty("sid") final String sid, + @JsonProperty( + "typing_indicator_timeout" + ) final Integer typingIndicatorTimeout, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_filters") final List webhookFilters, + @JsonProperty("webhook_method") final String webhookMethod + ) { + this.accountSid = accountSid; + this.consumptionReportInterval = consumptionReportInterval; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; + this.defaultChannelRoleSid = defaultChannelRoleSid; + this.defaultServiceRoleSid = defaultServiceRoleSid; + this.friendlyName = friendlyName; + this.limits = limits; + this.links = links; + this.media = media; + this.notifications = notifications; + this.postWebhookRetryCount = postWebhookRetryCount; + this.postWebhookUrl = postWebhookUrl; + this.preWebhookRetryCount = preWebhookRetryCount; + this.preWebhookUrl = preWebhookUrl; + this.reachabilityEnabled = reachabilityEnabled; + this.readStatusEnabled = readStatusEnabled; + this.sid = sid; + this.typingIndicatorTimeout = typingIndicatorTimeout; + this.url = url; + this.webhookFilters = webhookFilters; + this.webhookMethod = webhookMethod; } @Override @@ -456,85 +274,77 @@ public boolean equals(final Object o) { } Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(defaultServiceRoleSid, other.defaultServiceRoleSid) && - Objects.equals(defaultChannelRoleSid, other.defaultChannelRoleSid) && - Objects.equals(defaultChannelCreatorRoleSid, other.defaultChannelCreatorRoleSid) && - Objects.equals(readStatusEnabled, other.readStatusEnabled) && - Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && - Objects.equals(typingIndicatorTimeout, other.typingIndicatorTimeout) && - Objects.equals(consumptionReportInterval, other.consumptionReportInterval) && - Objects.equals(limits, other.limits) && - Objects.equals(preWebhookUrl, other.preWebhookUrl) && - Objects.equals(postWebhookUrl, other.postWebhookUrl) && - Objects.equals(webhookMethod, other.webhookMethod) && - Objects.equals(webhookFilters, other.webhookFilters) && - Objects.equals(preWebhookRetryCount, other.preWebhookRetryCount) && - Objects.equals(postWebhookRetryCount, other.postWebhookRetryCount) && - Objects.equals(notifications, other.notifications) && - Objects.equals(media, other.media) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + consumptionReportInterval, + other.consumptionReportInterval + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultChannelCreatorRoleSid, + other.defaultChannelCreatorRoleSid + ) && + Objects.equals( + defaultChannelRoleSid, + other.defaultChannelRoleSid + ) && + Objects.equals( + defaultServiceRoleSid, + other.defaultServiceRoleSid + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(limits, other.limits) && + Objects.equals(links, other.links) && + Objects.equals(media, other.media) && + Objects.equals(notifications, other.notifications) && + Objects.equals( + postWebhookRetryCount, + other.postWebhookRetryCount + ) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(preWebhookRetryCount, other.preWebhookRetryCount) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals(readStatusEnabled, other.readStatusEnabled) && + Objects.equals(sid, other.sid) && + Objects.equals( + typingIndicatorTimeout, + other.typingIndicatorTimeout + ) && + Objects.equals(url, other.url) && + Objects.equals(webhookFilters, other.webhookFilters) && + Objects.equals(webhookMethod, other.webhookMethod) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - defaultServiceRoleSid, - defaultChannelRoleSid, - defaultChannelCreatorRoleSid, - readStatusEnabled, - reachabilityEnabled, - typingIndicatorTimeout, - consumptionReportInterval, - limits, - preWebhookUrl, - postWebhookUrl, - webhookMethod, - webhookFilters, - preWebhookRetryCount, - postWebhookRetryCount, - notifications, - media, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("defaultServiceRoleSid", defaultServiceRoleSid) - .add("defaultChannelRoleSid", defaultChannelRoleSid) - .add("defaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid) - .add("readStatusEnabled", readStatusEnabled) - .add("reachabilityEnabled", reachabilityEnabled) - .add("typingIndicatorTimeout", typingIndicatorTimeout) - .add("consumptionReportInterval", consumptionReportInterval) - .add("limits", limits) - .add("preWebhookUrl", preWebhookUrl) - .add("postWebhookUrl", postWebhookUrl) - .add("webhookMethod", webhookMethod) - .add("webhookFilters", webhookFilters) - .add("preWebhookRetryCount", preWebhookRetryCount) - .add("postWebhookRetryCount", postWebhookRetryCount) - .add("notifications", notifications) - .add("media", media) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + consumptionReportInterval, + dateCreated, + dateUpdated, + defaultChannelCreatorRoleSid, + defaultChannelRoleSid, + defaultServiceRoleSid, + friendlyName, + limits, + links, + media, + notifications, + postWebhookRetryCount, + postWebhookUrl, + preWebhookRetryCount, + preWebhookUrl, + reachabilityEnabled, + readStatusEnabled, + sid, + typingIndicatorTimeout, + url, + webhookFilters, + webhookMethod + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceCreator.java b/src/main/java/com/twilio/rest/chat/v2/ServiceCreator.java index 742960e984..8da6faabb5 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +27,86 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceCreator extends Creator { - private final String friendlyName; - /** - * Construct a new ServiceCreator. - * - * @param friendlyName Human-readable name for this service instance - */ + private String friendlyName; + public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services"; + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceDeleter.java b/src/main/java/com/twilio/rest/chat/v2/ServiceDeleter.java index 054043503d..b0b673b62d 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ServiceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new ServiceDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceFetcher.java b/src/main/java/com/twilio/rest/chat/v2/ServiceFetcher.java index 78b0d9d76f..f3c73851c0 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new ServiceFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceReader.java b/src/main/java/com/twilio/rest/chat/v2/ServiceReader.java index dfbbc24c04..58a5d3d73b 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services"; + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/ServiceUpdater.java b/src/main/java/com/twilio/rest/chat/v2/ServiceUpdater.java index 3653fdfc25..a69bb81d81 100644 --- a/src/main/java/com/twilio/rest/chat/v2/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/ServiceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class ServiceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String defaultServiceRoleSid; private String defaultChannelRoleSid; @@ -55,595 +68,577 @@ public class ServiceUpdater extends Updater { private Integer postWebhookRetryCount; private Boolean notificationsLogEnabled; - /** - * Construct a new ServiceUpdater. - * - * @param pathSid The sid - */ public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Human-readable name for this service instance. - * - * @param friendlyName Human-readable name for this service instance - * @return this - */ public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The default_service_role_sid. - * - * @param defaultServiceRoleSid The default_service_role_sid - * @return this - */ - public ServiceUpdater setDefaultServiceRoleSid(final String defaultServiceRoleSid) { + public ServiceUpdater setDefaultServiceRoleSid( + final String defaultServiceRoleSid + ) { this.defaultServiceRoleSid = defaultServiceRoleSid; return this; } - /** - * Channel role assigned on channel join (see - * [Roles](https://www.twilio.com/docs/chat/api/roles) data model for the - * details). - * - * @param defaultChannelRoleSid Channel role assigned on channel join - * @return this - */ - public ServiceUpdater setDefaultChannelRoleSid(final String defaultChannelRoleSid) { + public ServiceUpdater setDefaultChannelRoleSid( + final String defaultChannelRoleSid + ) { this.defaultChannelRoleSid = defaultChannelRoleSid; return this; } - /** - * Channel role assigned to creator of channel when joining for first time. - * - * @param defaultChannelCreatorRoleSid Channel role assigned to creator of - * channel when joining for first time - * @return this - */ - public ServiceUpdater setDefaultChannelCreatorRoleSid(final String defaultChannelCreatorRoleSid) { + public ServiceUpdater setDefaultChannelCreatorRoleSid( + final String defaultChannelCreatorRoleSid + ) { this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; return this; } - /** - * `true` if the member read status feature is enabled, `false` if not. - * Defaults to `true`.. - * - * @param readStatusEnabled true if the member read status feature is enabled, - * false if not. - * @return this - */ - public ServiceUpdater setReadStatusEnabled(final Boolean readStatusEnabled) { + public ServiceUpdater setReadStatusEnabled( + final Boolean readStatusEnabled + ) { this.readStatusEnabled = readStatusEnabled; return this; } - /** - * `true` if the reachability feature should be enabled. Defaults to `false`. - * - * @param reachabilityEnabled true if the reachability feature should be - * enabled. - * @return this - */ - public ServiceUpdater setReachabilityEnabled(final Boolean reachabilityEnabled) { + public ServiceUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } - /** - * The duration in seconds indicating the timeout after "started typing" event - * when client should assume that user is not typing anymore even if no "ended - * typing" message received. - * - * @param typingIndicatorTimeout The duration in seconds indicating the timeout - * after "started typing" event when client should - * assume that user is not typing anymore even if - * no "ended typing" message received - * @return this - */ - public ServiceUpdater setTypingIndicatorTimeout(final Integer typingIndicatorTimeout) { + public ServiceUpdater setTypingIndicatorTimeout( + final Integer typingIndicatorTimeout + ) { this.typingIndicatorTimeout = typingIndicatorTimeout; return this; } - /** - * The consumption_report_interval. - * - * @param consumptionReportInterval The consumption_report_interval - * @return this - */ - public ServiceUpdater setConsumptionReportInterval(final Integer consumptionReportInterval) { + public ServiceUpdater setConsumptionReportInterval( + final Integer consumptionReportInterval + ) { this.consumptionReportInterval = consumptionReportInterval; return this; } - /** - * The notifications.new_message.enabled. - * - * @param notificationsNewMessageEnabled The notifications.new_message.enabled - * @return this - */ - public ServiceUpdater setNotificationsNewMessageEnabled(final Boolean notificationsNewMessageEnabled) { + public ServiceUpdater setNotificationsNewMessageEnabled( + final Boolean notificationsNewMessageEnabled + ) { this.notificationsNewMessageEnabled = notificationsNewMessageEnabled; return this; } - /** - * The notifications.new_message.template. - * - * @param notificationsNewMessageTemplate The notifications.new_message.template - * @return this - */ - public ServiceUpdater setNotificationsNewMessageTemplate(final String notificationsNewMessageTemplate) { + public ServiceUpdater setNotificationsNewMessageTemplate( + final String notificationsNewMessageTemplate + ) { this.notificationsNewMessageTemplate = notificationsNewMessageTemplate; return this; } - /** - * The notifications.new_message.sound. - * - * @param notificationsNewMessageSound The notifications.new_message.sound - * @return this - */ - public ServiceUpdater setNotificationsNewMessageSound(final String notificationsNewMessageSound) { + public ServiceUpdater setNotificationsNewMessageSound( + final String notificationsNewMessageSound + ) { this.notificationsNewMessageSound = notificationsNewMessageSound; return this; } - /** - * The notifications.new_message.badge_count_enabled. - * - * @param notificationsNewMessageBadgeCountEnabled The - * notifications.new_message.badge_count_enabled - * @return this - */ - public ServiceUpdater setNotificationsNewMessageBadgeCountEnabled(final Boolean notificationsNewMessageBadgeCountEnabled) { - this.notificationsNewMessageBadgeCountEnabled = notificationsNewMessageBadgeCountEnabled; + public ServiceUpdater setNotificationsNewMessageBadgeCountEnabled( + final Boolean notificationsNewMessageBadgeCountEnabled + ) { + this.notificationsNewMessageBadgeCountEnabled = + notificationsNewMessageBadgeCountEnabled; return this; } - /** - * The notifications.added_to_channel.enabled. - * - * @param notificationsAddedToChannelEnabled The - * notifications.added_to_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelEnabled(final Boolean notificationsAddedToChannelEnabled) { - this.notificationsAddedToChannelEnabled = notificationsAddedToChannelEnabled; + public ServiceUpdater setNotificationsAddedToChannelEnabled( + final Boolean notificationsAddedToChannelEnabled + ) { + this.notificationsAddedToChannelEnabled = + notificationsAddedToChannelEnabled; return this; } - /** - * The notifications.added_to_channel.template. - * - * @param notificationsAddedToChannelTemplate The - * notifications.added_to_channel.template - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelTemplate(final String notificationsAddedToChannelTemplate) { - this.notificationsAddedToChannelTemplate = notificationsAddedToChannelTemplate; + public ServiceUpdater setNotificationsAddedToChannelTemplate( + final String notificationsAddedToChannelTemplate + ) { + this.notificationsAddedToChannelTemplate = + notificationsAddedToChannelTemplate; return this; } - /** - * The notifications.added_to_channel.sound. - * - * @param notificationsAddedToChannelSound The - * notifications.added_to_channel.sound - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelSound(final String notificationsAddedToChannelSound) { - this.notificationsAddedToChannelSound = notificationsAddedToChannelSound; + public ServiceUpdater setNotificationsAddedToChannelSound( + final String notificationsAddedToChannelSound + ) { + this.notificationsAddedToChannelSound = + notificationsAddedToChannelSound; return this; } - /** - * The notifications.removed_from_channel.enabled. - * - * @param notificationsRemovedFromChannelEnabled The - * notifications.removed_from_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelEnabled(final Boolean notificationsRemovedFromChannelEnabled) { - this.notificationsRemovedFromChannelEnabled = notificationsRemovedFromChannelEnabled; + public ServiceUpdater setNotificationsRemovedFromChannelEnabled( + final Boolean notificationsRemovedFromChannelEnabled + ) { + this.notificationsRemovedFromChannelEnabled = + notificationsRemovedFromChannelEnabled; return this; } - /** - * The notifications.removed_from_channel.template. - * - * @param notificationsRemovedFromChannelTemplate The - * notifications.removed_from_channel.template - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelTemplate(final String notificationsRemovedFromChannelTemplate) { - this.notificationsRemovedFromChannelTemplate = notificationsRemovedFromChannelTemplate; + public ServiceUpdater setNotificationsRemovedFromChannelTemplate( + final String notificationsRemovedFromChannelTemplate + ) { + this.notificationsRemovedFromChannelTemplate = + notificationsRemovedFromChannelTemplate; return this; } - /** - * The notifications.removed_from_channel.sound. - * - * @param notificationsRemovedFromChannelSound The - * notifications.removed_from_channel.sound - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelSound(final String notificationsRemovedFromChannelSound) { - this.notificationsRemovedFromChannelSound = notificationsRemovedFromChannelSound; + public ServiceUpdater setNotificationsRemovedFromChannelSound( + final String notificationsRemovedFromChannelSound + ) { + this.notificationsRemovedFromChannelSound = + notificationsRemovedFromChannelSound; return this; } - /** - * The notifications.invited_to_channel.enabled. - * - * @param notificationsInvitedToChannelEnabled The - * notifications.invited_to_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelEnabled(final Boolean notificationsInvitedToChannelEnabled) { - this.notificationsInvitedToChannelEnabled = notificationsInvitedToChannelEnabled; + public ServiceUpdater setNotificationsInvitedToChannelEnabled( + final Boolean notificationsInvitedToChannelEnabled + ) { + this.notificationsInvitedToChannelEnabled = + notificationsInvitedToChannelEnabled; return this; } - /** - * The notifications.invited_to_channel.template. - * - * @param notificationsInvitedToChannelTemplate The - * notifications.invited_to_channel.template - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelTemplate(final String notificationsInvitedToChannelTemplate) { - this.notificationsInvitedToChannelTemplate = notificationsInvitedToChannelTemplate; + public ServiceUpdater setNotificationsInvitedToChannelTemplate( + final String notificationsInvitedToChannelTemplate + ) { + this.notificationsInvitedToChannelTemplate = + notificationsInvitedToChannelTemplate; return this; } - /** - * The notifications.invited_to_channel.sound. - * - * @param notificationsInvitedToChannelSound The - * notifications.invited_to_channel.sound - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelSound(final String notificationsInvitedToChannelSound) { - this.notificationsInvitedToChannelSound = notificationsInvitedToChannelSound; + public ServiceUpdater setNotificationsInvitedToChannelSound( + final String notificationsInvitedToChannelSound + ) { + this.notificationsInvitedToChannelSound = + notificationsInvitedToChannelSound; return this; } - /** - * The webhook URL for PRE-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param preWebhookUrl The webhook URL for PRE-Event webhooks. - * @return this - */ public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - /** - * The webhook URL for PRE-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param preWebhookUrl The webhook URL for PRE-Event webhooks. - * @return this - */ public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - /** - * The webhook URL for POST-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param postWebhookUrl The webhook URL for POST-Event webhooks. - * @return this - */ public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - /** - * The webhook URL for POST-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param postWebhookUrl The webhook URL for POST-Event webhooks. - * @return this - */ public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - /** - * The webhook request format to use. Must be POST or GET. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param webhookMethod The webhook request format to use. - * @return this - */ public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod) { this.webhookMethod = webhookMethod; return this; } - /** - * The list of WebHook events that are enabled for this Service instance. See - * [Webhook Events](https://www.twilio.com/docs/chat/webhook-events) for more - * details.. - * - * @param webhookFilters The list of WebHook events that are enabled for this - * Service instance. - * @return this - */ public ServiceUpdater setWebhookFilters(final List webhookFilters) { this.webhookFilters = webhookFilters; return this; } - /** - * The list of WebHook events that are enabled for this Service instance. See - * [Webhook Events](https://www.twilio.com/docs/chat/webhook-events) for more - * details.. - * - * @param webhookFilters The list of WebHook events that are enabled for this - * Service instance. - * @return this - */ public ServiceUpdater setWebhookFilters(final String webhookFilters) { return setWebhookFilters(Promoter.listOfOne(webhookFilters)); } - /** - * The maximum number of Members that can be added to Channels within this - * Service. The maximum allowed value is 1,000. - * - * @param limitsChannelMembers The maximum number of Members that can be added - * to Channels within this Service. - * @return this - */ - public ServiceUpdater setLimitsChannelMembers(final Integer limitsChannelMembers) { + public ServiceUpdater setLimitsChannelMembers( + final Integer limitsChannelMembers + ) { this.limitsChannelMembers = limitsChannelMembers; return this; } - /** - * The maximum number of Channels Users can be a Member of within this Service. - * The maximum value allowed is 1,000. - * - * @param limitsUserChannels The maximum number of Channels Users can be a - * Member of within this Service. - * @return this - */ - public ServiceUpdater setLimitsUserChannels(final Integer limitsUserChannels) { + public ServiceUpdater setLimitsUserChannels( + final Integer limitsUserChannels + ) { this.limitsUserChannels = limitsUserChannels; return this; } - /** - * The media.compatibility_message. - * - * @param mediaCompatibilityMessage The media.compatibility_message - * @return this - */ - public ServiceUpdater setMediaCompatibilityMessage(final String mediaCompatibilityMessage) { + public ServiceUpdater setMediaCompatibilityMessage( + final String mediaCompatibilityMessage + ) { this.mediaCompatibilityMessage = mediaCompatibilityMessage; return this; } - /** - * Count of times webhook will be retried in case of timeout (5 seconds) or - * 429/503/504 HTTP responses. Default retry count is 0 times.. - * - * @param preWebhookRetryCount Count of times webhook will be retried in case - * of timeout or 429/503/504 HTTP responses. - * @return this - */ - public ServiceUpdater setPreWebhookRetryCount(final Integer preWebhookRetryCount) { + public ServiceUpdater setPreWebhookRetryCount( + final Integer preWebhookRetryCount + ) { this.preWebhookRetryCount = preWebhookRetryCount; return this; } - /** - * Count of times webhook will be retried in case of timeout (5 seconds) or - * 429/503/504 HTTP responses. Default retry count is 0 times.. - * - * @param postWebhookRetryCount Count of times webhook will be retried in case - * of timeout or 429/503/504 HTTP responses. - * @return this - */ - public ServiceUpdater setPostWebhookRetryCount(final Integer postWebhookRetryCount) { + public ServiceUpdater setPostWebhookRetryCount( + final Integer postWebhookRetryCount + ) { this.postWebhookRetryCount = postWebhookRetryCount; return this; } - /** - * The notifications.log_enabled. - * - * @param notificationsLogEnabled The notifications.log_enabled - * @return this - */ - public ServiceUpdater setNotificationsLogEnabled(final Boolean notificationsLogEnabled) { + public ServiceUpdater setNotificationsLogEnabled( + final Boolean notificationsLogEnabled + ) { this.notificationsLogEnabled = notificationsLogEnabled; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (defaultServiceRoleSid != null) { - request.addPostParam("DefaultServiceRoleSid", defaultServiceRoleSid); + Serializer.toString( + request, + "DefaultServiceRoleSid", + defaultServiceRoleSid, + ParameterType.URLENCODED + ); } if (defaultChannelRoleSid != null) { - request.addPostParam("DefaultChannelRoleSid", defaultChannelRoleSid); + Serializer.toString( + request, + "DefaultChannelRoleSid", + defaultChannelRoleSid, + ParameterType.URLENCODED + ); } if (defaultChannelCreatorRoleSid != null) { - request.addPostParam("DefaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid); + Serializer.toString( + request, + "DefaultChannelCreatorRoleSid", + defaultChannelCreatorRoleSid, + ParameterType.URLENCODED + ); } if (readStatusEnabled != null) { - request.addPostParam("ReadStatusEnabled", readStatusEnabled.toString()); + Serializer.toString( + request, + "ReadStatusEnabled", + readStatusEnabled, + ParameterType.URLENCODED + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); + Serializer.toString( + request, + "ReachabilityEnabled", + reachabilityEnabled, + ParameterType.URLENCODED + ); } if (typingIndicatorTimeout != null) { - request.addPostParam("TypingIndicatorTimeout", typingIndicatorTimeout.toString()); + Serializer.toString( + request, + "TypingIndicatorTimeout", + typingIndicatorTimeout, + ParameterType.URLENCODED + ); } if (consumptionReportInterval != null) { - request.addPostParam("ConsumptionReportInterval", consumptionReportInterval.toString()); + Serializer.toString( + request, + "ConsumptionReportInterval", + consumptionReportInterval, + ParameterType.URLENCODED + ); } if (notificationsNewMessageEnabled != null) { - request.addPostParam("Notifications.NewMessage.Enabled", notificationsNewMessageEnabled.toString()); + Serializer.toString( + request, + "Notifications.NewMessage.Enabled", + notificationsNewMessageEnabled, + ParameterType.URLENCODED + ); } if (notificationsNewMessageTemplate != null) { - request.addPostParam("Notifications.NewMessage.Template", notificationsNewMessageTemplate); + Serializer.toString( + request, + "Notifications.NewMessage.Template", + notificationsNewMessageTemplate, + ParameterType.URLENCODED + ); } if (notificationsNewMessageSound != null) { - request.addPostParam("Notifications.NewMessage.Sound", notificationsNewMessageSound); + Serializer.toString( + request, + "Notifications.NewMessage.Sound", + notificationsNewMessageSound, + ParameterType.URLENCODED + ); } if (notificationsNewMessageBadgeCountEnabled != null) { - request.addPostParam("Notifications.NewMessage.BadgeCountEnabled", notificationsNewMessageBadgeCountEnabled.toString()); + Serializer.toString( + request, + "Notifications.NewMessage.BadgeCountEnabled", + notificationsNewMessageBadgeCountEnabled, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelEnabled != null) { - request.addPostParam("Notifications.AddedToChannel.Enabled", notificationsAddedToChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.AddedToChannel.Enabled", + notificationsAddedToChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelTemplate != null) { - request.addPostParam("Notifications.AddedToChannel.Template", notificationsAddedToChannelTemplate); + Serializer.toString( + request, + "Notifications.AddedToChannel.Template", + notificationsAddedToChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelSound != null) { - request.addPostParam("Notifications.AddedToChannel.Sound", notificationsAddedToChannelSound); + Serializer.toString( + request, + "Notifications.AddedToChannel.Sound", + notificationsAddedToChannelSound, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelEnabled != null) { - request.addPostParam("Notifications.RemovedFromChannel.Enabled", notificationsRemovedFromChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Enabled", + notificationsRemovedFromChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelTemplate != null) { - request.addPostParam("Notifications.RemovedFromChannel.Template", notificationsRemovedFromChannelTemplate); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Template", + notificationsRemovedFromChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelSound != null) { - request.addPostParam("Notifications.RemovedFromChannel.Sound", notificationsRemovedFromChannelSound); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Sound", + notificationsRemovedFromChannelSound, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelEnabled != null) { - request.addPostParam("Notifications.InvitedToChannel.Enabled", notificationsInvitedToChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Enabled", + notificationsInvitedToChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelTemplate != null) { - request.addPostParam("Notifications.InvitedToChannel.Template", notificationsInvitedToChannelTemplate); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Template", + notificationsInvitedToChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelSound != null) { - request.addPostParam("Notifications.InvitedToChannel.Sound", notificationsInvitedToChannelSound); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Sound", + notificationsInvitedToChannelSound, + ParameterType.URLENCODED + ); } if (preWebhookUrl != null) { - request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); + Serializer.toString( + request, + "PreWebhookUrl", + preWebhookUrl, + ParameterType.URLENCODED + ); } if (postWebhookUrl != null) { - request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); + Serializer.toString( + request, + "PostWebhookUrl", + postWebhookUrl, + ParameterType.URLENCODED + ); } if (webhookMethod != null) { - request.addPostParam("WebhookMethod", webhookMethod.toString()); + Serializer.toString( + request, + "WebhookMethod", + webhookMethod, + ParameterType.URLENCODED + ); } if (webhookFilters != null) { - for (String prop : webhookFilters) { - request.addPostParam("WebhookFilters", prop); + for (String param : webhookFilters) { + Serializer.toString( + request, + "WebhookFilters", + param, + ParameterType.URLENCODED + ); } } if (limitsChannelMembers != null) { - request.addPostParam("Limits.ChannelMembers", limitsChannelMembers.toString()); + Serializer.toString( + request, + "Limits.ChannelMembers", + limitsChannelMembers, + ParameterType.URLENCODED + ); } if (limitsUserChannels != null) { - request.addPostParam("Limits.UserChannels", limitsUserChannels.toString()); + Serializer.toString( + request, + "Limits.UserChannels", + limitsUserChannels, + ParameterType.URLENCODED + ); } if (mediaCompatibilityMessage != null) { - request.addPostParam("Media.CompatibilityMessage", mediaCompatibilityMessage); + Serializer.toString( + request, + "Media.CompatibilityMessage", + mediaCompatibilityMessage, + ParameterType.URLENCODED + ); } if (preWebhookRetryCount != null) { - request.addPostParam("PreWebhookRetryCount", preWebhookRetryCount.toString()); + Serializer.toString( + request, + "PreWebhookRetryCount", + preWebhookRetryCount, + ParameterType.URLENCODED + ); } if (postWebhookRetryCount != null) { - request.addPostParam("PostWebhookRetryCount", postWebhookRetryCount.toString()); + Serializer.toString( + request, + "PostWebhookRetryCount", + postWebhookRetryCount, + ParameterType.URLENCODED + ); } if (notificationsLogEnabled != null) { - request.addPostParam("Notifications.LogEnabled", notificationsLogEnabled.toString()); + Serializer.toString( + request, + "Notifications.LogEnabled", + notificationsLogEnabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/Binding.java b/src/main/java/com/twilio/rest/chat/v2/service/Binding.java index c5fe4de393..27c835d262 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/Binding.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/Binding.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; @@ -10,33 +17,52 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Binding extends Resource { - private static final long serialVersionUID = 102481637129176L; + + public static BindingDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new BindingDeleter(pathServiceSid, pathSid); + } + + public static BindingFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new BindingFetcher(pathServiceSid, pathSid); + } + + public static BindingReader reader(final String pathServiceSid) { + return new BindingReader(pathServiceSid); + } public enum BindingType { GCM("gcm"), @@ -49,63 +75,28 @@ private BindingType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a BindingType from a string. - * @param value string value - * @return generated BindingType - */ @JsonCreator public static BindingType forValue(final String value) { return Promoter.enumFromString(value, BindingType.values()); } } - /** - * Create a BindingReader to execute read. - * - * @param pathServiceSid The service_sid - * @return BindingReader capable of executing the read - */ - public static BindingReader reader(final String pathServiceSid) { - return new BindingReader(pathServiceSid); - } - - /** - * Create a BindingFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return BindingFetcher capable of executing the fetch - */ - public static BindingFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new BindingFetcher(pathServiceSid, pathSid); - } - - /** - * Create a BindingDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return BindingDeleter capable of executing the delete - */ - public static BindingDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new BindingDeleter(pathServiceSid, pathSid); - } - /** * Converts a JSON String into a Binding object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Binding object represented by the provided JSON */ - public static Binding fromJson(final String json, final ObjectMapper objectMapper) { + public static Binding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -119,12 +110,15 @@ public static Binding fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Binding object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Binding object represented by the provided JSON */ - public static Binding fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Binding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -135,166 +129,91 @@ public static Binding fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String endpoint; - private final String identity; - private final String credentialSid; - private final Binding.BindingType bindingType; - private final List messageTypes; - private final URI url; - private final Map links; - - @JsonCreator - private Binding(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("endpoint") - final String endpoint, - @JsonProperty("identity") - final String identity, - @JsonProperty("credential_sid") - final String credentialSid, - @JsonProperty("binding_type") - final Binding.BindingType bindingType, - @JsonProperty("message_types") - final List messageTypes, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.endpoint = endpoint; - this.identity = identity; - this.credentialSid = credentialSid; - this.bindingType = bindingType; - this.messageTypes = messageTypes; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this binding.. - * - * @return The unique id of the Account responsible for this binding. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Binding.BindingType bindingType; - /** - * Returns The The unique id of the Service this binding belongs to.. - * - * @return The unique id of the Service this binding belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String credentialSid; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The unique endpoint identifier for this Binding.. - * - * @return The unique endpoint identifier for this Binding. - */ - public final String getEndpoint() { - return this.endpoint; - } + @Getter + private final String endpoint; - /** - * Returns The A unique string identifier for the Binding for this User in this - * Service.. - * - * @return A unique string identifier for the Binding for this User in this - * Service. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final String identity; - /** - * Returns The The unique id of the Credential for this binding.. - * - * @return The unique id of the Credential for this binding. - */ - public final String getCredentialSid() { - return this.credentialSid; - } + @Getter + private final Map links; - /** - * Returns The The push technology to use for this binding.. - * - * @return The push technology to use for this binding. - */ - public final Binding.BindingType getBindingType() { - return this.bindingType; - } + @Getter + private final List messageTypes; - /** - * Returns The List of message types for this binding.. - * - * @return List of message types for this binding. - */ - public final List getMessageTypes() { - return this.messageTypes; - } + @Getter + private final String serviceSid; - /** - * Returns The An absolute URL for this binding.. - * - * @return An absolute URL for this binding. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String sid; - /** - * Returns The Absolute URLs to access the Users for this Binding.. - * - * @return Absolute URLs to access the Users for this Binding. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Binding( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("binding_type") final Binding.BindingType bindingType, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("links") final Map links, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.bindingType = bindingType; + this.credentialSid = credentialSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.endpoint = endpoint; + this.identity = identity; + this.links = links; + this.messageTypes = messageTypes; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -308,52 +227,37 @@ public boolean equals(final Object o) { } Binding other = (Binding) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(endpoint, other.endpoint) && - Objects.equals(identity, other.identity) && - Objects.equals(credentialSid, other.credentialSid) && - Objects.equals(bindingType, other.bindingType) && - Objects.equals(messageTypes, other.messageTypes) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(links, other.links) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - endpoint, - identity, - credentialSid, - bindingType, - messageTypes, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("endpoint", endpoint) - .add("identity", identity) - .add("credentialSid", credentialSid) - .add("bindingType", bindingType) - .add("messageTypes", messageTypes) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + bindingType, + credentialSid, + dateCreated, + dateUpdated, + endpoint, + identity, + links, + messageTypes, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/BindingDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/BindingDeleter.java index 571ce321c8..72d24b293e 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/BindingDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/BindingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class BindingDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new BindingDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public BindingDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public BindingDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Binding delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/BindingFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/BindingFetcher.java index 64b615bc4d..0db7414289 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/BindingFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/BindingFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class BindingFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new BindingFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public BindingFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public BindingFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Binding - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Binding fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Binding fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Binding fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Binding.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Binding content = Binding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/BindingReader.java b/src/main/java/com/twilio/rest/chat/v2/service/BindingReader.java index ec17565fe2..9a0a74ad5d 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/BindingReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/BindingReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; @@ -10,222 +17,241 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class BindingReader extends Reader { - private final String pathServiceSid; + + private String pathServiceSid; private List bindingType; private List identity; + private Long pageSize; - /** - * Construct a new BindingReader. - * - * @param pathServiceSid The service_sid - */ public BindingReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * The push technology used for the returned Bindings. Supported values are - * apn, gcm and fcm. See [push notification - * configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more information.. - * - * @param bindingType The push technology used for the bindings returned. - * @return this - */ - public BindingReader setBindingType(final List bindingType) { + public BindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - /** - * The push technology used for the returned Bindings. Supported values are - * apn, gcm and fcm. See [push notification - * configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more information.. - * - * @param bindingType The push technology used for the bindings returned. - * @return this - */ public BindingReader setBindingType(final Binding.BindingType bindingType) { return setBindingType(Promoter.listOfOne(bindingType)); } - /** - * The identity. - * - * @param identity The identity - * @return this - */ public BindingReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * The identity. - * - * @param identity The identity - * @return this - */ public BindingReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public BindingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Bindings"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Bindings", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Binding read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Binding Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Binding read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "bindings", - response.getContent(), - Binding.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (bindingType != null) { - for (Binding.BindingType prop : bindingType) { - request.addQueryParam("BindingType", prop.toString()); + for (Binding.BindingType param : bindingType) { + Serializer.toString( + request, + "BindingType", + param, + ParameterType.QUERY + ); } } if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/Channel.java b/src/main/java/com/twilio/rest/chat/v2/service/Channel.java index cf7ae6880d..72ff3b0f57 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/Channel.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/Channel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; @@ -10,122 +17,116 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Channel extends Resource { - private static final long serialVersionUID = 275623534063843L; - public enum ChannelType { - PUBLIC("public"), - PRIVATE("private"); + public static ChannelCreator creator(final String pathServiceSid) { + return new ChannelCreator(pathServiceSid); + } + + public static ChannelDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelDeleter(pathServiceSid, pathSid); + } + + public static ChannelFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelFetcher(pathServiceSid, pathSid); + } + + public static ChannelReader reader(final String pathServiceSid) { + return new ChannelReader(pathServiceSid); + } + + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelUpdater(pathServiceSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); private final String value; - private ChannelType(final String value) { + private WebhookEnabledType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ChannelType from a string. - * @param value string value - * @return generated ChannelType - */ @JsonCreator - public static ChannelType forValue(final String value) { - return Promoter.enumFromString(value, ChannelType.values()); + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); } } - /** - * Create a ChannelFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelFetcher capable of executing the fetch - */ - public static ChannelFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new ChannelFetcher(pathServiceSid, pathSid); - } + public enum ChannelType { + PUBLIC("public"), + PRIVATE("private"); - /** - * Create a ChannelDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelDeleter capable of executing the delete - */ - public static ChannelDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new ChannelDeleter(pathServiceSid, pathSid); - } + private final String value; - /** - * Create a ChannelCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return ChannelCreator capable of executing the create - */ - public static ChannelCreator creator(final String pathServiceSid) { - return new ChannelCreator(pathServiceSid); - } + private ChannelType(final String value) { + this.value = value; + } - /** - * Create a ChannelReader to execute read. - * - * @param pathServiceSid The service_sid - * @return ChannelReader capable of executing the read - */ - public static ChannelReader reader(final String pathServiceSid) { - return new ChannelReader(pathServiceSid); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a ChannelUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelUpdater capable of executing the update - */ - public static ChannelUpdater updater(final String pathServiceSid, - final String pathSid) { - return new ChannelUpdater(pathServiceSid, pathSid); + @JsonCreator + public static ChannelType forValue(final String value) { + return Promoter.enumFromString(value, ChannelType.values()); + } } /** * Converts a JSON String into a Channel object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Channel object represented by the provided JSON */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -139,12 +140,15 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Channel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Channel object represented by the provided JSON */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -155,194 +159,101 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String friendlyName; - private final String uniqueName; - private final String attributes; - private final Channel.ChannelType type; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - private final Integer membersCount; - private final Integer messagesCount; - private final URI url; - private final Map links; - - @JsonCreator - private Channel(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("type") - final Channel.ChannelType type, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy, - @JsonProperty("members_count") - final Integer membersCount, - @JsonProperty("messages_count") - final Integer messagesCount, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.friendlyName = friendlyName; - this.uniqueName = uniqueName; - this.attributes = attributes; - this.type = type; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - this.membersCount = membersCount; - this.messagesCount = messagesCount; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this channel.. - * - * @return The unique id of the Account responsible for this channel. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String attributes; - /** - * Returns The The unique id of the Service this channel belongs to.. - * - * @return The unique id of the Service this channel belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String createdBy; - /** - * Returns The The human-readable name of this channel.. - * - * @return The human-readable name of this channel. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique, addressable name of this channel.. - * - * @return The unique, addressable name of this channel. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } + @Getter + private final String friendlyName; - /** - * Returns The The visibility of this channel - either public or private. - * - * @return The visibility of this channel - either public or private - */ - public final Channel.ChannelType getType() { - return this.type; - } + @Getter + private final Map links; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Integer membersCount; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer messagesCount; - /** - * Returns The Identity of the channel's creator.. - * - * @return Identity of the channel's creator. - */ - public final String getCreatedBy() { - return this.createdBy; - } + @Getter + private final String serviceSid; - /** - * Returns The The number of Members in the Channel. - * - * @return The number of Members in the Channel - */ - public final Integer getMembersCount() { - return this.membersCount; - } + @Getter + private final String sid; - /** - * Returns The The number of Messages in the Channel. - * - * @return The number of Messages in the Channel - */ - public final Integer getMessagesCount() { - return this.messagesCount; - } + @Getter + private final Channel.ChannelType type; - /** - * Returns The An absolute URL for this channel.. - * - * @return An absolute URL for this channel. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String uniqueName; - /** - * Returns The Absolute URLs to access the Members, Messages , Invites and, if - * it exists the last Message for this Channel.. - * - * @return Absolute URLs to access the Members, Messages , Invites and, if it - * exists the last Message for this Channel. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Channel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.membersCount = membersCount; + this.messagesCount = messagesCount; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -356,58 +267,41 @@ public boolean equals(final Object o) { } Channel other = (Channel) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(attributes, other.attributes) && - Objects.equals(type, other.type) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy) && - Objects.equals(membersCount, other.membersCount) && - Objects.equals(messagesCount, other.messagesCount) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - friendlyName, - uniqueName, - attributes, - type, - dateCreated, - dateUpdated, - createdBy, - membersCount, - messagesCount, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("friendlyName", friendlyName) - .add("uniqueName", uniqueName) - .add("attributes", attributes) - .add("type", type) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .add("membersCount", membersCount) - .add("messagesCount", messagesCount) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + attributes, + createdBy, + dateCreated, + dateUpdated, + friendlyName, + links, + membersCount, + messagesCount, + serviceSid, + sid, + type, + uniqueName, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelCreator.java index 0316104908..5ae297ed03 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Creator; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,188 +27,204 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class ChannelCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; + private Channel.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; private String uniqueName; private String attributes; private Channel.ChannelType type; - private DateTime dateCreated; - private DateTime dateUpdated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; private String createdBy; - /** - * Construct a new ChannelCreator. - * - * @param pathServiceSid The service_sid - */ public ChannelCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * A human-readable name for the Channel. Optional.. - * - * @param friendlyName A human-readable name for the Channel. - * @return this - */ public ChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A unique, addressable name for the Channel. Optional.. - * - * @param uniqueName A unique, addressable name for the Channel. - * @return this - */ public ChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An optional metadata field you can use to store any data you wish. No - * processing or validation is done on this field.. - * - * @param attributes An optional metadata field you can use to store any data - * you wish. - * @return this - */ public ChannelCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The visibility of the channel - `public` or `private`. Defaults to `public`.. - * - * @param type The visibility of the channel - public or private. - * @return this - */ public ChannelCreator setType(final Channel.ChannelType type) { this.type = type; return this; } - /** - * The optional ISO8601 time specifying the datetime the Channel should be set - * as being created. Will be set to the current time by the Chat service if not - * specified. Note that this should only be used in cases where a a Channel is - * being recreated from a backup/separate source. - * - * @param dateCreated The optional ISO8601 time specifying the datetime the - * Channel should be set as being created. - * @return this - */ - public ChannelCreator setDateCreated(final DateTime dateCreated) { + public ChannelCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The optional ISO8601 time specifying the datetime the Channel should be set - * as having been last updated. Will be set to the `null` by the Chat service - * if not specified. Note that this should only be used in cases where a - * Channel is being recreated from a backup/separate source and where a Message - * was previously updated.. - * - * @param dateUpdated The optional ISO8601 time specifying the datetime the - * Channel should be set as having been last updated. - * @return this - */ - public ChannelCreator setDateUpdated(final DateTime dateUpdated) { + public ChannelCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Optional field to specify the Identity of the User that created the Channel. - * Will be set to "system" if not specified.. - * - * @param createdBy Optional field to specify the Identity of the User that - * created the Channel. - * @return this - */ public ChannelCreator setCreatedBy(final String createdBy) { this.createdBy = createdBy; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel create(final TwilioRestClient client) { + public ChannelCreator setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel create(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); } if (createdBy != null) { - request.addPostParam("CreatedBy", createdBy); + Serializer.toString( + request, + "CreatedBy", + createdBy, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelDeleter.java index 68fd06ee02..ecf0437df6 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +26,101 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ChannelDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ChannelDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + private Channel.WebhookEnabledType xTwilioWebhookEnabled; + + public ChannelDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public ChannelDeleter setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelFetcher.java index cc43823bd2..b2dde850df 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ChannelFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ChannelFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public ChannelFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelReader.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelReader.java index 04503b44a6..46c91ef81e 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; @@ -10,190 +17,218 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class ChannelReader extends Reader { - private final String pathServiceSid; + + private String pathServiceSid; private List type; + private Long pageSize; - /** - * Construct a new ChannelReader. - * - * @param pathServiceSid The service_sid - */ public ChannelReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * The type. - * - * @param type The type - * @return this - */ public ChannelReader setType(final List type) { this.type = type; return this; } - /** - * The type. - * - * @param type The type - * @return this - */ public ChannelReader setType(final Channel.ChannelType type) { return setType(Promoter.listOfOne(type)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Channel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - Channel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (type != null) { - for (Channel.ChannelType prop : type) { - request.addQueryParam("Type", prop.toString()); + for (Channel.ChannelType param : type) { + Serializer.toString( + request, + "Type", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/ChannelUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/ChannelUpdater.java index b236c9003f..1166ac938c 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/ChannelUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.DateConverter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,170 +27,192 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class ChannelUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; + private Channel.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; private String uniqueName; private String attributes; - private DateTime dateCreated; - private DateTime dateUpdated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; private String createdBy; - /** - * Construct a new ChannelUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelUpdater(final String pathServiceSid, - final String pathSid) { + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * A human-readable name for the Channel. Optional.. - * - * @param friendlyName A human-readable name for the Channel. - * @return this - */ public ChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A unique, addressable name for the Channel. Optional.. - * - * @param uniqueName A unique, addressable name for the Channel. - * @return this - */ public ChannelUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An optional metadata field you can use to store any data you wish. No - * processing or validation is done on this field.. - * - * @param attributes An optional metadata field you can use to store any data - * you wish. - * @return this - */ public ChannelUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The optional ISO8601 time specifying the datetime the Channel should be set - * as being created.. - * - * @param dateCreated The optional ISO8601 time specifying the datetime the - * Channel should be set as being created. - * @return this - */ - public ChannelUpdater setDateCreated(final DateTime dateCreated) { + public ChannelUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The optional ISO8601 time specifying the datetime the Channel should be set - * as having been last updated.. - * - * @param dateUpdated The optional ISO8601 time specifying the datetime the - * Channel should be set as having been last updated. - * @return this - */ - public ChannelUpdater setDateUpdated(final DateTime dateUpdated) { + public ChannelUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Optional field to specify the Identity of the User that created the Channel.. - * - * @param createdBy Optional field to specify the Identity of the User that - * created the Channel. - * @return this - */ public ChannelUpdater setCreatedBy(final String createdBy) { this.createdBy = createdBy; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel update(final TwilioRestClient client) { + public ChannelUpdater setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel update(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); } if (createdBy != null) { - request.addPostParam("CreatedBy", createdBy); + Serializer.toString( + request, + "CreatedBy", + createdBy, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/Role.java b/src/main/java/com/twilio/rest/chat/v2/service/Role.java index 0a83655190..f7774bd228 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/Role.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/Role.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; @@ -10,33 +17,68 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Role extends Resource { - private static final long serialVersionUID = 78785177979928L; + + public static RoleCreator creator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + return new RoleCreator(pathServiceSid, friendlyName, type, permission); + } + + public static RoleDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new RoleDeleter(pathServiceSid, pathSid); + } + + public static RoleFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new RoleFetcher(pathServiceSid, pathSid); + } + + public static RoleReader reader(final String pathServiceSid) { + return new RoleReader(pathServiceSid); + } + + public static RoleUpdater updater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { + return new RoleUpdater(pathServiceSid, pathSid, permission); + } public enum RoleType { CHANNEL("channel"), @@ -48,93 +90,28 @@ private RoleType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a RoleType from a string. - * @param value string value - * @return generated RoleType - */ @JsonCreator public static RoleType forValue(final String value) { return Promoter.enumFromString(value, RoleType.values()); } } - /** - * Create a RoleFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return RoleFetcher capable of executing the fetch - */ - public static RoleFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new RoleFetcher(pathServiceSid, pathSid); - } - - /** - * Create a RoleDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return RoleDeleter capable of executing the delete - */ - public static RoleDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new RoleDeleter(pathServiceSid, pathSid); - } - - /** - * Create a RoleCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param friendlyName The human-readable name of this role. - * @param type What kind of role this is. - * @param permission A permission this role should have. - * @return RoleCreator capable of executing the create - */ - public static RoleCreator creator(final String pathServiceSid, - final String friendlyName, - final Role.RoleType type, - final List permission) { - return new RoleCreator(pathServiceSid, friendlyName, type, permission); - } - - /** - * Create a RoleReader to execute read. - * - * @param pathServiceSid The service_sid - * @return RoleReader capable of executing the read - */ - public static RoleReader reader(final String pathServiceSid) { - return new RoleReader(pathServiceSid); - } - - /** - * Create a RoleUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param permission A permission this role should have. - * @return RoleUpdater capable of executing the update - */ - public static RoleUpdater updater(final String pathServiceSid, - final String pathSid, - final List permission) { - return new RoleUpdater(pathServiceSid, pathSid, permission); - } - /** * Converts a JSON String into a Role object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Role object represented by the provided JSON */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -148,12 +125,15 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Role object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Role object represented by the provided JSON */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -164,125 +144,76 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String friendlyName; - private final Role.RoleType type; - private final List permissions; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private Role(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Role.RoleType type, - @JsonProperty("permissions") - final List permissions, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.friendlyName = friendlyName; - this.type = type; - this.permissions = permissions; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this role.. - * - * @return The unique id of the Account responsible for this role. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Service this role belongs to.. - * - * @return The unique id of the Service this role belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The human-readable name of this role.. - * - * @return The human-readable name of this role. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String friendlyName; - /** - * Returns The What kind of role this is.. - * - * @return What kind of role this is. - */ - public final Role.RoleType getType() { - return this.type; - } + @Getter + private final List permissions; - /** - * Returns The A JSON array of the permissions this role has.. - * - * @return A JSON array of the permissions this role has. - */ - public final List getPermissions() { - return this.permissions; - } + @Getter + private final String serviceSid; - /** - * Returns The The date that this resource was created in ISO 8601 format.. - * - * @return The date that this resource was created in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date that this resource was last updated in ISO 8601 format.. - * - * @return The date that this resource was last updated in ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Role.RoleType type; - /** - * Returns The An absolute URL for this role.. - * - * @return An absolute URL for this role. - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private Role( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("permissions") final List permissions, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.permissions = permissions; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.url = url; } @Override @@ -296,43 +227,31 @@ public boolean equals(final Object o) { } Role other = (Role) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(permissions, other.permissions) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(permissions, other.permissions) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - friendlyName, - type, - permissions, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("permissions", permissions) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + permissions, + serviceSid, + sid, + type, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleCreator.java index 5bca2e6305..d9721ebdf0 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleCreator.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,90 +28,138 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class RoleCreator extends Creator { - private final String pathServiceSid; - private final String friendlyName; - private final Role.RoleType type; - private final List permission; - - /** - * Construct a new RoleCreator. - * - * @param pathServiceSid The service_sid - * @param friendlyName The human-readable name of this role. - * @param type What kind of role this is. - * @param permission A permission this role should have. - */ - public RoleCreator(final String pathServiceSid, - final String friendlyName, - final Role.RoleType type, - final List permission) { + + private String pathServiceSid; + private String friendlyName; + private Role.RoleType type; + private List permission; + + public RoleCreator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role create(final TwilioRestClient client) { + public RoleCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public RoleCreator setType(final Role.RoleType type) { + this.type = type; + return this; + } + + public RoleCreator setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleCreator setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role create(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (permission != null) { - for (String prop : permission) { - request.addPostParam("Permission", prop); + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleDeleter.java index 35affe5e93..02b655c40f 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class RoleDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new RoleDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public RoleDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public RoleDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleFetcher.java index ab41e9bbd2..36f13e4945 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RoleFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new RoleFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public RoleFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public RoleFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleReader.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleReader.java index 2ed88793a7..60b6795f52 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; @@ -10,159 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RoleReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new RoleReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public RoleReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public RoleReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Role Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "roles", - response.getContent(), - Role.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/RoleUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/RoleUpdater.java index 3c64aa7dc3..290399e73a 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/RoleUpdater.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,78 +28,108 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class RoleUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; - private final List permission; - /** - * Construct a new RoleUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param permission A permission this role should have. - */ - public RoleUpdater(final String pathServiceSid, - final String pathSid, - final List permission) { + private String pathServiceSid; + private String pathSid; + private List permission; + + public RoleUpdater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.permission = permission; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role update(final TwilioRestClient client) { + public RoleUpdater setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleUpdater setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role update(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (permission != null) { - for (String prop : permission) { - request.addPostParam("Permission", prop); + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/User.java b/src/main/java/com/twilio/rest/chat/v2/service/User.java index 5bbf6588ef..66bc5abaa8 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/User.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/User.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; @@ -10,99 +17,98 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class User extends Resource { - private static final long serialVersionUID = 15176818292650L; - /** - * Create a UserFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserFetcher capable of executing the fetch - */ - public static UserFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new UserFetcher(pathServiceSid, pathSid); + public static UserCreator creator( + final String pathServiceSid, + final String identity + ) { + return new UserCreator(pathServiceSid, identity); } - /** - * Create a UserDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserDeleter capable of executing the delete - */ - public static UserDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static UserDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new UserDeleter(pathServiceSid, pathSid); } - /** - * Create a UserCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param identity A unique string that identifies the user within this service - * - often a username or email address. - * @return UserCreator capable of executing the create - */ - public static UserCreator creator(final String pathServiceSid, - final String identity) { - return new UserCreator(pathServiceSid, identity); + public static UserFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new UserFetcher(pathServiceSid, pathSid); } - /** - * Create a UserReader to execute read. - * - * @param pathServiceSid The service_sid - * @return UserReader capable of executing the read - */ public static UserReader reader(final String pathServiceSid) { return new UserReader(pathServiceSid); } - /** - * Create a UserUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserUpdater capable of executing the update - */ - public static UserUpdater updater(final String pathServiceSid, - final String pathSid) { + public static UserUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new UserUpdater(pathServiceSid, pathSid); } + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + /** * Converts a JSON String into a User object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return User object represented by the provided JSON */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -116,12 +122,15 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a User object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return User object represented by the provided JSON */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -132,200 +141,105 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String attributes; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final String roleSid; + + @Getter private final String identity; - private final Boolean isOnline; + + @Getter private final Boolean isNotifiable; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final Boolean isOnline; + + @Getter private final Integer joinedChannelsCount; + + @Getter private final Map links; + + @Getter + private final String roleSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private User(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("is_online") - final Boolean isOnline, - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("joined_channels_count") - final Integer joinedChannelsCount, - @JsonProperty("links") - final Map links, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private User( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity") final String identity, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty( + "joined_channels_count" + ) final Integer joinedChannelsCount, + @JsonProperty("links") final Map links, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; this.attributes = attributes; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.roleSid = roleSid; this.identity = identity; - this.isOnline = isOnline; this.isNotifiable = isNotifiable; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.isOnline = isOnline; this.joinedChannelsCount = joinedChannelsCount; this.links = links; + this.roleSid = roleSid; + this.serviceSid = serviceSid; + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account responsible for this user.. - * - * @return The unique id of the Account responsible for this user. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique id of the Service this user belongs to.. - * - * @return The unique id of the Service this user belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } - - /** - * Returns The The human-readable name of this user.. - * - * @return The human-readable name of this user. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique id of the [Role][role] assigned to this user.. - * - * @return The unique id of the [Role][role] assigned to this user. - */ - public final String getRoleSid() { - return this.roleSid; - } - - /** - * Returns The A unique string that identifies the user within this service - - * often a username or email address.. - * - * @return A unique string that identifies the user within this service - often - * a username or email address. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Indicates whether the User is actively connected to the Service - * instance and online.. - * - * @return Indicates whether the User is actively connected to the Service - * instance and online. - */ - public final Boolean getIsOnline() { - return this.isOnline; - } - - /** - * Returns The Indicates whether the User has a potentially valid Push - * Notification registration for the Service instance.. - * - * @return Indicates whether the User has a potentially valid Push Notification - * registration for the Service instance. - */ - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - - /** - * Returns The The date that this resource was created in ISO 8601 format.. - * - * @return The date that this resource was created in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated in ISO 8601 format.. - * - * @return The date that this resource was last updated in ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The number of Channels this User is a Member of.. - * - * @return The number of Channels this User is a Member of. - */ - public final Integer getJoinedChannelsCount() { - return this.joinedChannelsCount; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The An absolute URL for this user.. - * - * @return An absolute URL for this user. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -337,58 +251,41 @@ public boolean equals(final Object o) { } User other = (User) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(identity, other.identity) && - Objects.equals(isOnline, other.isOnline) && - Objects.equals(isNotifiable, other.isNotifiable) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && - Objects.equals(links, other.links) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identity, other.identity) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && + Objects.equals(links, other.links) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - attributes, - friendlyName, - roleSid, - identity, - isOnline, - isNotifiable, - dateCreated, - dateUpdated, - joinedChannelsCount, - links, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("attributes", attributes) - .add("friendlyName", friendlyName) - .add("roleSid", roleSid) - .add("identity", identity) - .add("isOnline", isOnline) - .add("isNotifiable", isNotifiable) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("joinedChannelsCount", joinedChannelsCount) - .add("links", links) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + dateCreated, + dateUpdated, + friendlyName, + identity, + isNotifiable, + isOnline, + joinedChannelsCount, + links, + roleSid, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/UserCreator.java index b571d5c0a1..ad9d6be427 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,123 +27,159 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserCreator extends Creator { - private final String pathServiceSid; - private final String identity; + + private String pathServiceSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; + private String identity; private String roleSid; private String attributes; private String friendlyName; - /** - * Construct a new UserCreator. - * - * @param pathServiceSid The service_sid - * @param identity A unique string that identifies the user within this service - * - often a username or email address. - */ - public UserCreator(final String pathServiceSid, - final String identity) { + public UserCreator(final String pathServiceSid, final String identity) { this.pathServiceSid = pathServiceSid; this.identity = identity; } - /** - * The unique id of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) - * assigned to this user.. - * - * @param roleSid The unique id of the Role assigned to this user. - * @return this - */ + public UserCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An optional string used to contain any metadata or other information for the - * User. The string must contain structurally valid JSON if specified.. - * - * @param attributes An optional string used to contain any metadata or other - * information for the User. - * @return this - */ public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * An optional human readable string representing the user. Often used for - * display purposes.. - * - * @param friendlyName An optional human readable string representing the user. - * @return this - */ public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User create(final TwilioRestClient client) { + public UserCreator setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User create(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/UserDeleter.java index b6f00a9e24..7bcfa98514 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class UserDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new UserDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public UserDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/UserFetcher.java index 6039942abe..4c1f513883 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new UserFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public UserFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserReader.java b/src/main/java/com/twilio/rest/chat/v2/service/UserReader.java index 51ffa484ec..5ab7249203 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; @@ -10,159 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new UserReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public UserReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of User Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "users", - response.getContent(), - User.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/UserUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/UserUpdater.java index 2faff02582..60cc7ef560 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/UserUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,117 +27,146 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; private String roleSid; private String attributes; private String friendlyName; - /** - * Construct a new UserUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserUpdater(final String pathServiceSid, - final String pathSid) { + public UserUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * The unique id of the [Role][role] assigned to this user.. - * - * @param roleSid The unique id of the [Role][role] assigned to this user. - * @return this - */ public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An optional string used to contain any metadata or other information for the - * User. The string must contain structurally valid JSON if specified.. - * - * @param attributes An optional string used to contain any metadata or other - * information for the User. - * @return this - */ public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * An optional human readable string representing the user. Often used for - * display purposes.. - * - * @param friendlyName An optional human readable string representing the user. - * @return this - */ public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User update(final TwilioRestClient client) { + public UserUpdater setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User update(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/Invite.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/Invite.java index 41a628c5e6..44c4f234b5 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/Invite.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/Invite.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; @@ -11,93 +18,72 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Invite extends Resource { - private static final long serialVersionUID = 189960368613614L; - /** - * Create a InviteFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return InviteFetcher capable of executing the fetch - */ - public static InviteFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); + public static InviteCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { + return new InviteCreator(pathServiceSid, pathChannelSid, identity); } - /** - * Create a InviteCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * @return InviteCreator capable of executing the create - */ - public static InviteCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { - return new InviteCreator(pathServiceSid, pathChannelSid, identity); + public static InviteDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a InviteReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return InviteReader capable of executing the read - */ - public static InviteReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new InviteReader(pathServiceSid, pathChannelSid); + public static InviteFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a InviteDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return InviteDeleter capable of executing the delete - */ - public static InviteDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); + public static InviteReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new InviteReader(pathServiceSid, pathChannelSid); } /** * Converts a JSON String into a Invite object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Invite object represented by the provided JSON */ - public static Invite fromJson(final String json, final ObjectMapper objectMapper) { + public static Invite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -111,12 +97,15 @@ public static Invite fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Invite object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Invite object represented by the provided JSON */ - public static Invite fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Invite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -127,140 +116,83 @@ public static Invite fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String channelSid; - private final String serviceSid; + + @Getter + private final String createdBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final String roleSid; - private final String createdBy; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private Invite(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("created_by") - final String createdBy, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Invite( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.channelSid = channelSid; - this.serviceSid = serviceSid; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.roleSid = roleSid; - this.createdBy = createdBy; + this.serviceSid = serviceSid; + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account responsible for this member.. - * - * @return The unique id of the Account responsible for this member. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique id of the Channel for this member.. - * - * @return The unique id of the Channel for this member. - */ - public final String getChannelSid() { - return this.channelSid; - } - - /** - * Returns The The unique id of the Service this member belongs to.. - * - * @return The unique id of the Service this member belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The A unique string identifier for this User in this Service.. - * - * @return A unique string identifier for this User in this Service. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The Role assigned to this member.. - * - * @return The Role assigned to this member. - */ - public final String getRoleSid() { - return this.roleSid; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - /** - * Returns The An absolute URL for this member.. - * - * @return An absolute URL for this member. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -272,46 +204,33 @@ public boolean equals(final Object o) { } Invite other = (Invite) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(createdBy, other.createdBy) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - channelSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - roleSid, - createdBy, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("channelSid", channelSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("roleSid", roleSid) - .add("createdBy", createdBy) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + channelSid, + createdBy, + dateCreated, + dateUpdated, + identity, + roleSid, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteCreator.java index bdd7b769af..e6a091b852 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,91 +27,120 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class InviteCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String identity; + + private String pathServiceSid; + private String pathChannelSid; + private String identity; private String roleSid; - /** - * Construct a new InviteCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - */ - public InviteCreator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { + public InviteCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - /** - * The [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned to this - * member.. - * - * @param roleSid The Role assigned to this member. - * @return this - */ + public InviteCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public InviteCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Invite - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Invite create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Invite create(final TwilioRestClient client) { + Response response = makeRequest(client); return Invite.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Invite content = Invite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteDeleter.java index 78c60e1b09..1ed5792825 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class InviteDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new InviteDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public InviteDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public InviteDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteFetcher.java index a99494de0d..4036045e43 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class InviteFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new InviteFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public InviteFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public InviteFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Invite - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Invite fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Invite fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Invite.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Invite content = Invite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteReader.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteReader.java index d0afeb8c0d..08bf091d9e 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/InviteReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; @@ -10,202 +17,224 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class InviteReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private List identity; + private Long pageSize; - /** - * Construct a new InviteReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public InviteReader(final String pathServiceSid, - final String pathChannelSid) { + public InviteReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/services). See the - * [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) - * docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public InviteReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/services). See the - * [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) - * docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public InviteReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public InviteReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Invite read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Invite Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Invite read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "invites", - response.getContent(), - Invite.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/Member.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/Member.java index 462d360661..27f9a29d3b 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/Member.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/Member.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; @@ -10,110 +17,104 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Member extends Resource { - private static final long serialVersionUID = 102574959310114L; - /** - * Create a MemberFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberFetcher capable of executing the fetch - */ - public static MemberFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); + public static MemberCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { + return new MemberCreator(pathServiceSid, pathChannelSid, identity); } - /** - * Create a MemberCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * See the access tokens docs for more details. (📇 PII MTL: 120 - * days) - * @return MemberCreator capable of executing the create - */ - public static MemberCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { - return new MemberCreator(pathServiceSid, pathChannelSid, identity); + public static MemberDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a MemberReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MemberReader capable of executing the read - */ - public static MemberReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new MemberReader(pathServiceSid, pathChannelSid); + public static MemberFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a MemberDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberDeleter capable of executing the delete - */ - public static MemberDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); + public static MemberReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MemberReader(pathServiceSid, pathChannelSid); } - /** - * Create a MemberUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberUpdater capable of executing the update - */ - public static MemberUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public static MemberUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberUpdater(pathServiceSid, pathChannelSid, pathSid); } + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + /** * Converts a JSON String into a Member object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -127,12 +128,15 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Member object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -143,155 +147,98 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String channelSid; - private final String serviceSid; - private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String roleSid; - private final Integer lastConsumedMessageIndex; - private final DateTime lastConsumptionTimestamp; - private final URI url; - @JsonCreator - private Member(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - @JsonProperty("last_consumption_timestamp") - final String lastConsumptionTimestamp, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.channelSid = channelSid; - this.serviceSid = serviceSid; - this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.roleSid = roleSid; - this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.lastConsumptionTimestamp = DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); - this.url = url; - } + @Getter + private final String attributes; - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String channelSid; - /** - * Returns The The unique id of the Account responsible for this member.. - * - * @return The unique id of the Account responsible for this member. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Channel for this member.. - * - * @return The unique id of the Channel for this member. - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The unique id of the Service this member belongs to.. - * - * @return The unique id of the Service this member belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String identity; - /** - * Returns The A unique string identifier for this User in this Service.. - * - * @return A unique string identifier for this User in this Service. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final Integer lastConsumedMessageIndex; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime lastConsumptionTimestamp; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String roleSid; - /** - * Returns The The Role assigned to this member.. - * - * @return The Role assigned to this member. - */ - public final String getRoleSid() { - return this.roleSid; - } + @Getter + private final String serviceSid; - /** - * Returns The An Integer representing index of the last Message this Member has - * read within this Channel. - * - * @return An Integer representing index of the last Message this Member has - * read within this Channel - */ - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } + @Getter + private final String sid; - /** - * Returns The An ISO8601 based timestamp string representing the datetime of - * the last Message read event for this Member within this Channel. - * - * @return An ISO8601 based timestamp string representing the datetime of the - * last Message read event for this Member within this Channel - */ - public final DateTime getLastConsumptionTimestamp() { - return this.lastConsumptionTimestamp; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this member.. - * - * @return An absolute URL for this member. - */ - public final URI getUrl() { - return this.url; + @JsonCreator + private Member( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty("last_consumption_timestamp") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime lastConsumptionTimestamp, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.identity = identity; + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + this.lastConsumptionTimestamp = lastConsumptionTimestamp; + this.roleSid = roleSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -305,49 +252,43 @@ public boolean equals(final Object o) { } Member other = (Member) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && - Objects.equals(lastConsumptionTimestamp, other.lastConsumptionTimestamp) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals( + lastConsumptionTimestamp, + other.lastConsumptionTimestamp + ) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - channelSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - roleSid, - lastConsumedMessageIndex, - lastConsumptionTimestamp, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("channelSid", channelSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("roleSid", roleSid) - .add("lastConsumedMessageIndex", lastConsumedMessageIndex) - .add("lastConsumptionTimestamp", lastConsumptionTimestamp) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + channelSid, + dateCreated, + dateUpdated, + identity, + lastConsumedMessageIndex, + lastConsumptionTimestamp, + roleSid, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberCreator.java index babe447545..069a19b092 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Creator; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,185 +27,220 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MemberCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String identity; + + private String pathServiceSid; + private String pathChannelSid; + private Member.WebhookEnabledType xTwilioWebhookEnabled; + private String identity; private String roleSid; private Integer lastConsumedMessageIndex; - private DateTime lastConsumptionTimestamp; - private DateTime dateCreated; - private DateTime dateUpdated; - - /** - * Construct a new MemberCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * See the access tokens docs for more details. (📇 PII MTL: 120 - * days) - */ - public MemberCreator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { + private ZonedDateTime lastConsumptionTimestamp; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + + public MemberCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - /** - * The role to be assigned to this member. Defaults to the roles specified on - * the [Service](https://www.twilio.com/docs/chat/api/services).. - * - * @param roleSid The role to be assigned to this member. Defaults to the roles - * specified on the Service. - * @return this - */ + public MemberCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public MemberCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Field used to specify the last consumed Message index for the Channel for - * this Member. Should only be used when recreating a Member from a - * backup/separate source.. - * - * @param lastConsumedMessageIndex Field used to specify the last consumed - * Message index for the Channel for this - * Member. Should only be used when recreating - * a Member from a backup/separate source. - * @return this - */ - public MemberCreator setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex) { + public MemberCreator setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - /** - * ISO8601 time indicating the last datetime the Member consumed a Message in - * the Channel. Should only be used when recreating a Member from a - * backup/separate source. - * - * @param lastConsumptionTimestamp ISO8601 time indicating the last datetime - * the Member consumed a Message in the Channel. - * Should only be used when recreating a Member - * from a backup/separate source - * @return this - */ - public MemberCreator setLastConsumptionTimestamp(final DateTime lastConsumptionTimestamp) { + public MemberCreator setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } - /** - * The ISO8601 time specifying the datetime the Members should be set as being - * created. Will be set to the current time by the Chat service if not - * specified. Note that this should only be used in cases where a Member is - * being recreated from a backup/separate source. - * - * @param dateCreated The ISO8601 time specifying the datetime the Members - * should be set as being created. Will be set to the - * current time by the Chat service if not specified. Note - * that this should only be used in cases where a Member is - * being recreated from a backup/separate source - * @return this - */ - public MemberCreator setDateCreated(final DateTime dateCreated) { + public MemberCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The ISO8601 time specifying the datetime the Member should be set as having - * been last updated. Will be set to the `null` by the Chat service if not - * specified. Note that this should only be used in cases where a Member is - * being recreated from a backup/separate source and where a Member was - * previously updated.. - * - * @param dateUpdated The ISO8601 time specifying the datetime the Member - * should be set as having been last updated. Will be set to - * the null by the Chat service if not specified. Note that - * this should only be used in cases where a Member is being - * recreated from a backup/separate source and where a - * Member was previously updated. - * @return this - */ - public MemberCreator setDateUpdated(final DateTime dateUpdated) { + public MemberCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member create(final TwilioRestClient client) { + public MemberCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public MemberCreator setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member create(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); + Serializer.toString( + request, + "LastConsumedMessageIndex", + lastConsumedMessageIndex, + ParameterType.URLENCODED + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toString()); + Serializer.toString( + request, + "LastConsumptionTimestamp", + lastConsumptionTimestamp, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberDeleter.java index 1efe239dde..1cb5acad06 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +26,113 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MemberDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MemberDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + private Member.WebhookEnabledType xTwilioWebhookEnabled; + + public MemberDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public MemberDeleter setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberFetcher.java index 853fec1090..87ba30037f 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MemberFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MemberFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberReader.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberReader.java index 8593362a55..26e239d82c 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; @@ -10,206 +17,224 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class MemberReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private List identity; + private Long pageSize; - /** - * Construct a new MemberReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MemberReader(final String pathServiceSid, - final String pathChannelSid) { + public MemberReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/services). See the - * [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) - * docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * See the access tokens docs for more details. (📇 PII MTL: 120 - * days) - * @return this - */ public MemberReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/services). See the - * [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) - * docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * See the access tokens docs for more details. (📇 PII MTL: 120 - * days) - * @return this - */ public MemberReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MemberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Member Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "members", - response.getContent(), - Member.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberUpdater.java index dde79b4477..95e74088d5 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MemberUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.DateConverter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,168 +27,208 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MemberUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + private Member.WebhookEnabledType xTwilioWebhookEnabled; private String roleSid; private Integer lastConsumedMessageIndex; - private DateTime lastConsumptionTimestamp; - private DateTime dateCreated; - private DateTime dateUpdated; - - /** - * Construct a new MemberUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private ZonedDateTime lastConsumptionTimestamp; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + + public MemberUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The role to be assigned to this member. Defaults to the roles specified on - * the [Service](https://www.twilio.com/docs/chat/api/services).. - * - * @param roleSid The role to be assigned to this member. - * @return this - */ public MemberUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Field used to specify the last consumed Message index for the Channel for - * this Member. Should only be used when recreating a Member from a - * backup/separate source.. - * - * @param lastConsumedMessageIndex Field used to specify the last consumed - * Message index for the Channel for this - * Member. - * @return this - */ - public MemberUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex) { + public MemberUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - /** - * ISO8601 time indicating the last datetime the Member consumed a Message in - * the Channel. Should only be used when recreating a Member from a - * backup/separate source. - * - * @param lastConsumptionTimestamp ISO8601 time indicating the last datetime - * the Member consumed a Message in the Channel. - * @return this - */ - public MemberUpdater setLastConsumptionTimestamp(final DateTime lastConsumptionTimestamp) { + public MemberUpdater setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } - /** - * The ISO8601 time specifying the datetime the Members should be set as being - * created. Will be set to the current time by the Chat service if not - * specified. Note that this should only be used in cases where a Member is - * being recreated from a backup/separate source. - * - * @param dateCreated The ISO8601 time specifying the datetime the Members - * should be set as being created. - * @return this - */ - public MemberUpdater setDateCreated(final DateTime dateCreated) { + public MemberUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The ISO8601 time specifying the datetime the Member should be set as having - * been last updated. Will be set to the `null` by the Chat service if not - * specified. Note that this should only be used in cases where a Member is - * being recreated from a backup/separate source and where a Member was - * previously updated.. - * - * @param dateUpdated The ISO8601 time specifying the datetime the Member - * should be set as having been last updated. - * @return this - */ - public MemberUpdater setDateUpdated(final DateTime dateUpdated) { + public MemberUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member update(final TwilioRestClient client) { + public MemberUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public MemberUpdater setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member update(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); + Serializer.toString( + request, + "LastConsumedMessageIndex", + lastConsumedMessageIndex, + ParameterType.URLENCODED + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toString()); + Serializer.toString( + request, + "LastConsumptionTimestamp", + lastConsumptionTimestamp, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/Message.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/Message.java index db39adb414..95dc3e0376 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/Message.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/Message.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; @@ -10,133 +17,124 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Message extends Resource { - private static final long serialVersionUID = 240696203452729L; - public enum OrderType { - ASC("asc"), - DESC("desc"); + public static MessageCreator creator( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MessageCreator(pathServiceSid, pathChannelSid); + } + + public static MessageDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); + } + + public static MessageFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); + } + + public static MessageReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MessageReader(pathServiceSid, pathChannelSid); + } + + public static MessageUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); private final String value; - private OrderType(final String value) { + private WebhookEnabledType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a OrderType from a string. - * @param value string value - * @return generated OrderType - */ @JsonCreator - public static OrderType forValue(final String value) { - return Promoter.enumFromString(value, OrderType.values()); + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); } } - /** - * Create a MessageFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageFetcher capable of executing the fetch - */ - public static MessageFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); - } + public enum OrderType { + ASC("asc"), + DESC("desc"); - /** - * Create a MessageCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final String pathServiceSid, - final String pathChannelSid) { - return new MessageCreator(pathServiceSid, pathChannelSid); - } + private final String value; - /** - * Create a MessageReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MessageReader capable of executing the read - */ - public static MessageReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new MessageReader(pathServiceSid, pathChannelSid); - } + private OrderType(final String value) { + this.value = value; + } - /** - * Create a MessageDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageDeleter capable of executing the delete - */ - public static MessageDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a MessageUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageUpdater capable of executing the update - */ - public static MessageUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); + @JsonCreator + public static OrderType forValue(final String value) { + return Promoter.enumFromString(value, OrderType.values()); + } } /** * Converts a JSON String into a Message object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -150,12 +148,15 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Message object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -166,220 +167,111 @@ public static Message fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String attributes; - private final String serviceSid; - private final String to; - private final String channelSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String lastUpdatedBy; - private final Boolean wasEdited; - private final String from; - private final String body; - private final Integer index; - private final String type; - private final Map media; - private final URI url; - - @JsonCreator - private Message(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("to") - final String to, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("last_updated_by") - final String lastUpdatedBy, - @JsonProperty("was_edited") - final Boolean wasEdited, - @JsonProperty("from") - final String from, - @JsonProperty("body") - final String body, - @JsonProperty("index") - final Integer index, - @JsonProperty("type") - final String type, - @JsonProperty("media") - final Map media, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.attributes = attributes; - this.serviceSid = serviceSid; - this.to = to; - this.channelSid = channelSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.lastUpdatedBy = lastUpdatedBy; - this.wasEdited = wasEdited; - this.from = from; - this.body = body; - this.index = index; - this.type = type; - this.media = media; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this message.. - * - * @return The unique id of the Account responsible for this message. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String attributes; - /** - * Returns The A string metadata field you can use to store any data you wish.. - * - * @return A string metadata field you can use to store any data you wish. - */ - public final String getAttributes() { - return this.attributes; - } + @Getter + private final String body; - /** - * Returns The The unique id of the Service this message belongs to.. - * - * @return The unique id of the Service this message belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String channelSid; - /** - * Returns The The unique id of the Channel this message was sent to.. - * - * @return The unique id of the Channel this message was sent to. - */ - public final String getTo() { - return this.to; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The channel_sid. - * - * @return The channel_sid - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String from; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer index; - /** - * Returns The Field to specify the Identity of the User that last updated the - * Message. - * - * @return Field to specify the Identity of the User that last updated the - * Message - */ - public final String getLastUpdatedBy() { - return this.lastUpdatedBy; - } + @Getter + private final String lastUpdatedBy; - /** - * Returns The true if the message has been updated since it was created.. - * - * @return true if the message has been updated since it was created. - */ - public final Boolean getWasEdited() { - return this.wasEdited; - } + @Getter + private final Object media; - /** - * Returns The The identity of the message's author.. - * - * @return The identity of the message's author. - */ - public final String getFrom() { - return this.from; - } + @Getter + private final String serviceSid; - /** - * Returns The The contents of the message.. - * - * @return The contents of the message. - */ - public final String getBody() { - return this.body; - } + @Getter + private final String sid; - /** - * Returns The The index of the message within the Channel. - * - * @return The index of the message within the Channel - */ - public final Integer getIndex() { - return this.index; - } + @Getter + private final String to; - /** - * Returns The Message type.. - * - * @return Message type. - */ - public final String getType() { - return this.type; - } + @Getter + private final String type; - /** - * Returns The If a Media resource instance is attached to the Message, this - * will contain the Media object for the attached Media.. - * - * @return If a Media resource instance is attached to the Message, this will - * contain the Media object for the attached Media. - */ - public final Map getMedia() { - return this.media; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this message.. - * - * @return An absolute URL for this message. - */ - public final URI getUrl() { - return this.url; + @Getter + private final Boolean wasEdited; + + @JsonCreator + private Message( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("body") final String body, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("from") final String from, + @JsonProperty("index") final Integer index, + @JsonProperty("last_updated_by") final String lastUpdatedBy, + @JsonProperty("media") final Object media, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("to") final String to, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url, + @JsonProperty("was_edited") final Boolean wasEdited + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.body = body; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.from = from; + this.index = index; + this.lastUpdatedBy = lastUpdatedBy; + this.media = media; + this.serviceSid = serviceSid; + this.sid = sid; + this.to = to; + this.type = type; + this.url = url; + this.wasEdited = wasEdited; } @Override @@ -393,64 +285,45 @@ public boolean equals(final Object o) { } Message other = (Message) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(to, other.to) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(lastUpdatedBy, other.lastUpdatedBy) && - Objects.equals(wasEdited, other.wasEdited) && - Objects.equals(from, other.from) && - Objects.equals(body, other.body) && - Objects.equals(index, other.index) && - Objects.equals(type, other.type) && - Objects.equals(media, other.media) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(body, other.body) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(from, other.from) && + Objects.equals(index, other.index) && + Objects.equals(lastUpdatedBy, other.lastUpdatedBy) && + Objects.equals(media, other.media) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(to, other.to) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) && + Objects.equals(wasEdited, other.wasEdited) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - attributes, - serviceSid, - to, - channelSid, - dateCreated, - dateUpdated, - lastUpdatedBy, - wasEdited, - from, - body, - index, - type, - media, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("attributes", attributes) - .add("serviceSid", serviceSid) - .add("to", to) - .add("channelSid", channelSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("lastUpdatedBy", lastUpdatedBy) - .add("wasEdited", wasEdited) - .add("from", from) - .add("body", body) - .add("index", index) - .add("type", type) - .add("media", media) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + body, + channelSid, + dateCreated, + dateUpdated, + from, + index, + lastUpdatedBy, + media, + serviceSid, + sid, + to, + type, + url, + wasEdited + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageCreator.java index 52707de6de..3a9476ecfd 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Creator; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,198 +27,215 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MessageCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; private String from; private String attributes; - private DateTime dateCreated; - private DateTime dateUpdated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; private String lastUpdatedBy; private String body; private String mediaSid; - /** - * Construct a new MessageCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MessageCreator(final String pathServiceSid, - final String pathChannelSid) { + public MessageCreator( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * The [identity](https://www.twilio.com/docs/api/chat/guides/identity) of the - * message's author. Defaults to `system`.. - * - * @param from The identity of the message's author. Defaults to system if not - * specified. - * @return this - */ public MessageCreator setFrom(final String from) { this.from = from; return this; } - /** - * An string metadata field you can use to store any data you wish. The string - * value must contain structurally valid JSON if specified. **Note** that this - * will always be null for resources returned via LIST GET operations, but will - * be present for single GET operations.. - * - * @param attributes The attributes metadata field you can use to store any - * data you wish. - * @return this - */ public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The ISO8601 time specifying the datetime the Message should be set as being - * created. Will be set to the current time by the Chat service if not - * specified. Note that this should only be used in cases where a Chat's - * history is being recreated from a backup/separate source.. - * - * @param dateCreated The ISO8601 time specifying the datetime the Message - * should be set as being created. - * @return this - */ - public MessageCreator setDateCreated(final DateTime dateCreated) { + public MessageCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The ISO8601 time specifying the datetime the Message should be set as having - * been last updated. Will be set to the `null` by the Chat service if not - * specified. Note that this should only be used in cases where a Chat's - * history is being recreated from a backup/separate source and where a Message - * was previously updated.. - * - * @param dateUpdated The ISO8601 time specifying the datetime the Message - * should be set as having been last updated. - * @return this - */ - public MessageCreator setDateUpdated(final DateTime dateUpdated) { + public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Specify the Identity of the User that last updated the Message (if relevant). - * - * @param lastUpdatedBy Specify the Identity of the User that last updated the - * Message - * @return this - */ public MessageCreator setLastUpdatedBy(final String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; return this; } - /** - * A string message to send to this channel. You can also send structured data - * by serializing it into a string. May be empty string or `null`, will be set - * as empty string as a result in this cases.. - * - * @param body The message body string. - * @return this - */ public MessageCreator setBody(final String body) { this.body = body; return this; } - /** - * The [Media](https://www.twilio.com/docs/api/chat/rest/media) Sid to be - * attached to this Message.. - * - * @param mediaSid The Media Sid to be attached to this Message. - * @return this - */ public MessageCreator setMediaSid(final String mediaSid) { this.mediaSid = mediaSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message create(final TwilioRestClient client) { + public MessageCreator setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message create(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (from != null) { - request.addPostParam("From", from); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); } if (lastUpdatedBy != null) { - request.addPostParam("LastUpdatedBy", lastUpdatedBy); + Serializer.toString( + request, + "LastUpdatedBy", + lastUpdatedBy, + ParameterType.URLENCODED + ); } if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (mediaSid != null) { - request.addPostParam("MediaSid", mediaSid); + Serializer.toString( + request, + "MediaSid", + mediaSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageDeleter.java index 48fb78f3ba..f307fba68a 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +26,113 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MessageDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MessageDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; + + public MessageDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public MessageDeleter setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageFetcher.java index a13a505fe0..cf4b4a8ac4 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MessageFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MessageFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageReader.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageReader.java index 9b4d3feb55..191a46e7c3 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; @@ -10,181 +17,216 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private Message.OrderType order; + private Long pageSize; - /** - * Construct a new MessageReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MessageReader(final String pathServiceSid, - final String pathChannelSid) { + public MessageReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * Specifies sorting order for messages list, possible values are: `asc` or - * `desc`. If no value is specified, then `asc` is used as the default.. - * - * @param order Specifies sorting order for messages list, possible values are: - * `asc` or `desc`. - * @return this - */ public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MessageReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Message Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "messages", - response.getContent(), - Message.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); + Serializer.toString(request, "Order", order, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageUpdater.java index 4126a25249..ca58a6711f 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/MessageUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.DateConverter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,162 +27,204 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MessageUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; private String body; private String attributes; - private DateTime dateCreated; - private DateTime dateUpdated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; private String lastUpdatedBy; + private String from; - /** - * Construct a new MessageUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public MessageUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The message body string. You can also send structured data by serializing it - * into a string. May be updated to empty string or `null`, will be set as empty - * string as a result in this cases.. - * - * @param body The message body string. - * @return this - */ public MessageUpdater setBody(final String body) { this.body = body; return this; } - /** - * A string metadata field you can use to store any data you wish. The string - * value must contain structurally valid JSON if specified. **Note** that this - * will always be null for resources returned via LIST GET operations, but will - * be present for single GET operations.. - * - * @param attributes The attributes metadata field you can use to store any - * data you wish. - * @return this - */ public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The ISO8601 time specifying the datetime the Message should be set as being - * created.. - * - * @param dateCreated The ISO8601 time specifying the datetime the Message - * should be set as being created. - * @return this - */ - public MessageUpdater setDateCreated(final DateTime dateCreated) { + public MessageUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The ISO8601 time specifying the datetime the Message should be set as having - * been last updated.. - * - * @param dateUpdated The ISO8601 time specifying the datetime the Message - * should be set as having been last updated. - * @return this - */ - public MessageUpdater setDateUpdated(final DateTime dateUpdated) { + public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Specify the Identity of the User that last updated the Message (if relevant). - * - * @param lastUpdatedBy Specify the Identity of the User that last updated the - * Message - * @return this - */ public MessageUpdater setLastUpdatedBy(final String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message update(final TwilioRestClient client) { + public MessageUpdater setFrom(final String from) { + this.from = from; + return this; + } + + public MessageUpdater setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message update(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); } if (lastUpdatedBy != null) { - request.addPostParam("LastUpdatedBy", lastUpdatedBy); + Serializer.toString( + request, + "LastUpdatedBy", + lastUpdatedBy, + ParameterType.URLENCODED + ); + } + + if (from != null) { + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/Webhook.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/Webhook.java index 6071279be9..0d93e286ec 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/Webhook.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/Webhook.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; @@ -10,33 +17,71 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Webhook extends Resource { - private static final long serialVersionUID = 142993163058456L; + + public static WebhookCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final Webhook.Type type + ) { + return new WebhookCreator(pathServiceSid, pathChannelSid, type); + } + + public static WebhookDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new WebhookDeleter(pathServiceSid, pathChannelSid, pathSid); + } + + public static WebhookFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new WebhookFetcher(pathServiceSid, pathChannelSid, pathSid); + } + + public static WebhookReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new WebhookReader(pathServiceSid, pathChannelSid); + } + + public static WebhookUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new WebhookUpdater(pathServiceSid, pathChannelSid, pathSid); + } public enum Type { WEBHOOK("webhook"), @@ -49,15 +94,11 @@ private Type(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Type from a string. - * @param value string value - * @return generated Type - */ @JsonCreator public static Type forValue(final String value) { return Promoter.enumFromString(value, Type.values()); @@ -74,97 +115,28 @@ private Method(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Method from a string. - * @param value string value - * @return generated Method - */ @JsonCreator public static Method forValue(final String value) { return Promoter.enumFromString(value, Method.values()); } } - /** - * Create a WebhookReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return WebhookReader capable of executing the read - */ - public static WebhookReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new WebhookReader(pathServiceSid, pathChannelSid); - } - - /** - * Create a WebhookFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return WebhookFetcher capable of executing the fetch - */ - public static WebhookFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new WebhookFetcher(pathServiceSid, pathChannelSid, pathSid); - } - - /** - * Create a WebhookCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param type The type - * @return WebhookCreator capable of executing the create - */ - public static WebhookCreator creator(final String pathServiceSid, - final String pathChannelSid, - final Webhook.Type type) { - return new WebhookCreator(pathServiceSid, pathChannelSid, type); - } - - /** - * Create a WebhookUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return WebhookUpdater capable of executing the update - */ - public static WebhookUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new WebhookUpdater(pathServiceSid, pathChannelSid, pathSid); - } - - /** - * Create a WebhookDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return WebhookDeleter capable of executing the delete - */ - public static WebhookDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new WebhookDeleter(pathServiceSid, pathChannelSid, pathSid); - } - /** * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Webhook object represented by the provided JSON */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -178,12 +150,15 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Webhook object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Webhook object represented by the provided JSON */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -194,125 +169,76 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String channelSid; - private final String type; - private final URI url; - private final Map configuration; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private Webhook(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("type") - final String type, - @JsonProperty("url") - final URI url, - @JsonProperty("configuration") - final Map configuration, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.channelSid = channelSid; - this.type = type; - this.url = url; - this.configuration = configuration; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String channelSid; - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final Object configuration; - /** - * Returns The The channel_sid. - * - * @return The channel_sid - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The type. - * - * @return The type - */ - public final String getType() { - return this.type; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String serviceSid; - /** - * Returns The The configuration. - * - * @return The configuration - */ - public final Map getConfiguration() { - return this.configuration; - } + @Getter + private final String sid; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String type; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; + @Getter + private final URI url; + + @JsonCreator + private Webhook( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("configuration") final Object configuration, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelSid = channelSid; + this.configuration = configuration; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.url = url; } @Override @@ -326,43 +252,31 @@ public boolean equals(final Object o) { } Webhook other = (Webhook) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(type, other.type) && - Objects.equals(url, other.url) && - Objects.equals(configuration, other.configuration) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - channelSid, - type, - url, - configuration, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("channelSid", channelSid) - .add("type", type) - .add("url", url) - .add("configuration", configuration) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); + return Objects.hash( + accountSid, + channelSid, + configuration, + dateCreated, + dateUpdated, + serviceSid, + sid, + type, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookCreator.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookCreator.java index 72a7748f3d..2a0f8e52d2 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookCreator.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,13 +28,15 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class WebhookCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final Webhook.Type type; + + private String pathServiceSid; + private String pathChannelSid; + private Webhook.Type type; private String configurationUrl; private Webhook.Method configurationMethod; private List configurationFilters; @@ -31,182 +44,211 @@ public class WebhookCreator extends Creator { private String configurationFlowSid; private Integer configurationRetryCount; - /** - * Construct a new WebhookCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param type The type - */ - public WebhookCreator(final String pathServiceSid, - final String pathChannelSid, - final Webhook.Type type) { + public WebhookCreator( + final String pathServiceSid, + final String pathChannelSid, + final Webhook.Type type + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.type = type; } - /** - * The configuration.url. - * - * @param configurationUrl The configuration.url - * @return this - */ + public WebhookCreator setType(final Webhook.Type type) { + this.type = type; + return this; + } + public WebhookCreator setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - /** - * The configuration.method. - * - * @param configurationMethod The configuration.method - * @return this - */ - public WebhookCreator setConfigurationMethod(final Webhook.Method configurationMethod) { + public WebhookCreator setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - /** - * The configuration.filters. - * - * @param configurationFilters The configuration.filters - * @return this - */ - public WebhookCreator setConfigurationFilters(final List configurationFilters) { + public WebhookCreator setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - /** - * The configuration.filters. - * - * @param configurationFilters The configuration.filters - * @return this - */ - public WebhookCreator setConfigurationFilters(final String configurationFilters) { - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + public WebhookCreator setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - /** - * The configuration.triggers. - * - * @param configurationTriggers The configuration.triggers - * @return this - */ - public WebhookCreator setConfigurationTriggers(final List configurationTriggers) { + public WebhookCreator setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - /** - * The configuration.triggers. - * - * @param configurationTriggers The configuration.triggers - * @return this - */ - public WebhookCreator setConfigurationTriggers(final String configurationTriggers) { - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + public WebhookCreator setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - /** - * The configuration.flow_sid. - * - * @param configurationFlowSid The configuration.flow_sid - * @return this - */ - public WebhookCreator setConfigurationFlowSid(final String configurationFlowSid) { + public WebhookCreator setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - /** - * The configuration.retry_count. - * - * @param configurationRetryCount The configuration.retry_count - * @return this - */ - public WebhookCreator setConfigurationRetryCount(final Integer configurationRetryCount) { + public WebhookCreator setConfigurationRetryCount( + final Integer configurationRetryCount + ) { this.configurationRetryCount = configurationRetryCount; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Webhook - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Webhook create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Webhook create(final TwilioRestClient client) { + Response response = makeRequest(client); return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (configurationUrl != null) { - request.addPostParam("Configuration.Url", configurationUrl); + Serializer.toString( + request, + "Configuration.Url", + configurationUrl, + ParameterType.URLENCODED + ); } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); + Serializer.toString( + request, + "Configuration.Method", + configurationMethod, + ParameterType.URLENCODED + ); } if (configurationFilters != null) { - for (String prop : configurationFilters) { - request.addPostParam("Configuration.Filters", prop); + for (String param : configurationFilters) { + Serializer.toString( + request, + "Configuration.Filters", + param, + ParameterType.URLENCODED + ); } } if (configurationTriggers != null) { - for (String prop : configurationTriggers) { - request.addPostParam("Configuration.Triggers", prop); + for (String param : configurationTriggers) { + Serializer.toString( + request, + "Configuration.Triggers", + param, + ParameterType.URLENCODED + ); } } if (configurationFlowSid != null) { - request.addPostParam("Configuration.FlowSid", configurationFlowSid); + Serializer.toString( + request, + "Configuration.FlowSid", + configurationFlowSid, + ParameterType.URLENCODED + ); } if (configurationRetryCount != null) { - request.addPostParam("Configuration.RetryCount", configurationRetryCount.toString()); + Serializer.toString( + request, + "Configuration.RetryCount", + configurationRetryCount, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookDeleter.java index 3acf01b432..f93b2a4f80 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class WebhookDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new WebhookDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public WebhookDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public WebhookDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookFetcher.java index 563a6a4fea..40a1683826 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WebhookFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new WebhookFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public WebhookFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public WebhookFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Webhook - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Webhook fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Webhook fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookReader.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookReader.java index b4ec638c65..8503870297 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; @@ -10,163 +17,206 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WebhookReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; - - /** - * Construct a new WebhookReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public WebhookReader(final String pathServiceSid, - final String pathChannelSid) { + + private String pathServiceSid; + private String pathChannelSid; + private Long pageSize; + + public WebhookReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Webhook ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public WebhookReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Webhook ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Webhook ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Webhook Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Webhook read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "webhooks", - response.getContent(), - Webhook.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookUpdater.java index 8e7875403e..1e67f9d7ea 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/channel/WebhookUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,13 +28,15 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class WebhookUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; private String configurationUrl; private Webhook.Method configurationMethod; private List configurationFilters; @@ -31,178 +44,198 @@ public class WebhookUpdater extends Updater { private String configurationFlowSid; private Integer configurationRetryCount; - /** - * Construct a new WebhookUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public WebhookUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public WebhookUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The configuration.url. - * - * @param configurationUrl The configuration.url - * @return this - */ public WebhookUpdater setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - /** - * The configuration.method. - * - * @param configurationMethod The configuration.method - * @return this - */ - public WebhookUpdater setConfigurationMethod(final Webhook.Method configurationMethod) { + public WebhookUpdater setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - /** - * The configuration.filters. - * - * @param configurationFilters The configuration.filters - * @return this - */ - public WebhookUpdater setConfigurationFilters(final List configurationFilters) { + public WebhookUpdater setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - /** - * The configuration.filters. - * - * @param configurationFilters The configuration.filters - * @return this - */ - public WebhookUpdater setConfigurationFilters(final String configurationFilters) { - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + public WebhookUpdater setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - /** - * The configuration.triggers. - * - * @param configurationTriggers The configuration.triggers - * @return this - */ - public WebhookUpdater setConfigurationTriggers(final List configurationTriggers) { + public WebhookUpdater setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - /** - * The configuration.triggers. - * - * @param configurationTriggers The configuration.triggers - * @return this - */ - public WebhookUpdater setConfigurationTriggers(final String configurationTriggers) { - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + public WebhookUpdater setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - /** - * The configuration.flow_sid. - * - * @param configurationFlowSid The configuration.flow_sid - * @return this - */ - public WebhookUpdater setConfigurationFlowSid(final String configurationFlowSid) { + public WebhookUpdater setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - /** - * The configuration.retry_count. - * - * @param configurationRetryCount The configuration.retry_count - * @return this - */ - public WebhookUpdater setConfigurationRetryCount(final Integer configurationRetryCount) { + public WebhookUpdater setConfigurationRetryCount( + final Integer configurationRetryCount + ) { this.configurationRetryCount = configurationRetryCount; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Webhook - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Webhook update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Webhook update(final TwilioRestClient client) { + Response response = makeRequest(client); return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (configurationUrl != null) { - request.addPostParam("Configuration.Url", configurationUrl); + Serializer.toString( + request, + "Configuration.Url", + configurationUrl, + ParameterType.URLENCODED + ); } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); + Serializer.toString( + request, + "Configuration.Method", + configurationMethod, + ParameterType.URLENCODED + ); } if (configurationFilters != null) { - for (String prop : configurationFilters) { - request.addPostParam("Configuration.Filters", prop); + for (String param : configurationFilters) { + Serializer.toString( + request, + "Configuration.Filters", + param, + ParameterType.URLENCODED + ); } } if (configurationTriggers != null) { - for (String prop : configurationTriggers) { - request.addPostParam("Configuration.Triggers", prop); + for (String param : configurationTriggers) { + Serializer.toString( + request, + "Configuration.Triggers", + param, + ParameterType.URLENCODED + ); } } if (configurationFlowSid != null) { - request.addPostParam("Configuration.FlowSid", configurationFlowSid); + Serializer.toString( + request, + "Configuration.FlowSid", + configurationFlowSid, + ParameterType.URLENCODED + ); } if (configurationRetryCount != null) { - request.addPostParam("Configuration.RetryCount", configurationRetryCount.toString()); + Serializer.toString( + request, + "Configuration.RetryCount", + configurationRetryCount, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBinding.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBinding.java index 2d0ed3d1b6..9e61f157d8 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBinding.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBinding.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.user; @@ -10,33 +17,56 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class UserBinding extends Resource { - private static final long serialVersionUID = 241481961692245L; + + public static UserBindingDeleter deleter( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { + return new UserBindingDeleter(pathServiceSid, pathUserSid, pathSid); + } + + public static UserBindingFetcher fetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { + return new UserBindingFetcher(pathServiceSid, pathUserSid, pathSid); + } + + public static UserBindingReader reader( + final String pathServiceSid, + final String pathUserSid + ) { + return new UserBindingReader(pathServiceSid, pathUserSid); + } public enum BindingType { GCM("gcm"), @@ -49,15 +79,11 @@ private BindingType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a BindingType from a string. - * @param value string value - * @return generated BindingType - */ @JsonCreator public static BindingType forValue(final String value) { return Promoter.enumFromString(value, BindingType.values()); @@ -65,54 +91,16 @@ public static BindingType forValue(final String value) { } /** - * Create a UserBindingReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @return UserBindingReader capable of executing the read - */ - public static UserBindingReader reader(final String pathServiceSid, - final String pathUserSid) { - return new UserBindingReader(pathServiceSid, pathUserSid); - } - - /** - * Create a UserBindingFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @param pathSid The sid - * @return UserBindingFetcher capable of executing the fetch - */ - public static UserBindingFetcher fetcher(final String pathServiceSid, - final String pathUserSid, - final String pathSid) { - return new UserBindingFetcher(pathServiceSid, pathUserSid, pathSid); - } - - /** - * Create a UserBindingDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @param pathSid The sid - * @return UserBindingDeleter capable of executing the delete - */ - public static UserBindingDeleter deleter(final String pathServiceSid, - final String pathUserSid, - final String pathSid) { - return new UserBindingDeleter(pathServiceSid, pathUserSid, pathSid); - } - - /** - * Converts a JSON String into a UserBinding object using the provided - * ObjectMapper. - * + * Converts a JSON String into a UserBinding object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return UserBinding object represented by the provided JSON */ - public static UserBinding fromJson(final String json, final ObjectMapper objectMapper) { + public static UserBinding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserBinding.class); @@ -126,12 +114,15 @@ public static UserBinding fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a UserBinding object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return UserBinding object represented by the provided JSON */ - public static UserBinding fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static UserBinding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserBinding.class); @@ -142,166 +133,91 @@ public static UserBinding fromJson(final InputStream json, final ObjectMapper ob } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String endpoint; - private final String identity; - private final String userSid; - private final String credentialSid; - private final UserBinding.BindingType bindingType; - private final List messageTypes; - private final URI url; - - @JsonCreator - private UserBinding(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("endpoint") - final String endpoint, - @JsonProperty("identity") - final String identity, - @JsonProperty("user_sid") - final String userSid, - @JsonProperty("credential_sid") - final String credentialSid, - @JsonProperty("binding_type") - final UserBinding.BindingType bindingType, - @JsonProperty("message_types") - final List messageTypes, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.endpoint = endpoint; - this.identity = identity; - this.userSid = userSid; - this.credentialSid = credentialSid; - this.bindingType = bindingType; - this.messageTypes = messageTypes; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this binding.. - * - * @return The unique id of the Account responsible for this binding. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final UserBinding.BindingType bindingType; - /** - * Returns The The unique id of the Service this binding belongs to.. - * - * @return The unique id of the Service this binding belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String credentialSid; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The unique endpoint identifier for this Binding.. - * - * @return The unique endpoint identifier for this Binding. - */ - public final String getEndpoint() { - return this.endpoint; - } + @Getter + private final String endpoint; - /** - * Returns The A unique string identifier for the Binding for this User in this - * Service.. - * - * @return A unique string identifier for the Binding for this User in this - * Service. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final String identity; - /** - * Returns The The unique id of the User for this binding.. - * - * @return The unique id of the User for this binding. - */ - public final String getUserSid() { - return this.userSid; - } + @Getter + private final List messageTypes; - /** - * Returns The The unique id of the Credential for this binding.. - * - * @return The unique id of the Credential for this binding. - */ - public final String getCredentialSid() { - return this.credentialSid; - } + @Getter + private final String serviceSid; - /** - * Returns The The push technology to use for this binding.. - * - * @return The push technology to use for this binding. - */ - public final UserBinding.BindingType getBindingType() { - return this.bindingType; - } + @Getter + private final String sid; - /** - * Returns The List of message types for this binding.. - * - * @return List of message types for this binding. - */ - public final List getMessageTypes() { - return this.messageTypes; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this binding.. - * - * @return An absolute URL for this binding. - */ - public final URI getUrl() { - return this.url; + @Getter + private final String userSid; + + @JsonCreator + private UserBinding( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("binding_type") final UserBinding.BindingType bindingType, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("user_sid") final String userSid + ) { + this.accountSid = accountSid; + this.bindingType = bindingType; + this.credentialSid = credentialSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.endpoint = endpoint; + this.identity = identity; + this.messageTypes = messageTypes; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + this.userSid = userSid; } @Override @@ -315,52 +231,37 @@ public boolean equals(final Object o) { } UserBinding other = (UserBinding) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(endpoint, other.endpoint) && - Objects.equals(identity, other.identity) && - Objects.equals(userSid, other.userSid) && - Objects.equals(credentialSid, other.credentialSid) && - Objects.equals(bindingType, other.bindingType) && - Objects.equals(messageTypes, other.messageTypes) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(userSid, other.userSid) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - endpoint, - identity, - userSid, - credentialSid, - bindingType, - messageTypes, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("endpoint", endpoint) - .add("identity", identity) - .add("userSid", userSid) - .add("credentialSid", credentialSid) - .add("bindingType", bindingType) - .add("messageTypes", messageTypes) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + bindingType, + credentialSid, + dateCreated, + dateUpdated, + endpoint, + identity, + messageTypes, + serviceSid, + sid, + url, + userSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingDeleter.java index 0e3c3fa4f2..649d5aacfc 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingDeleter.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.user; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class UserBindingDeleter extends Deleter { - private final String pathServiceSid; - private final String pathUserSid; - private final String pathSid; - /** - * Construct a new UserBindingDeleter. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @param pathSid The sid - */ - public UserBindingDeleter(final String pathServiceSid, - final String pathUserSid, - final String pathSid) { + private String pathServiceSid; + private String pathUserSid; + private String pathSid; + + public UserBindingDeleter( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "UserBinding delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingFetcher.java index b409b52e5b..f4be1e1187 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingFetcher.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.user; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,88 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserBindingFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathUserSid; - private final String pathSid; - /** - * Construct a new UserBindingFetcher. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @param pathSid The sid - */ - public UserBindingFetcher(final String pathServiceSid, - final String pathUserSid, - final String pathSid) { + private String pathServiceSid; + private String pathUserSid; + private String pathSid; + + public UserBindingFetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched UserBinding - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public UserBinding fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "UserBinding fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return UserBinding.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public UserBinding fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserBinding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserBinding content = UserBinding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingReader.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingReader.java index a7f0e7eceb..981efa1d63 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserBindingReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.user; @@ -10,198 +17,228 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class UserBindingReader extends Reader { - private final String pathServiceSid; - private final String pathUserSid; + + private String pathServiceSid; + private String pathUserSid; private List bindingType; + private Long pageSize; - /** - * Construct a new UserBindingReader. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - */ - public UserBindingReader(final String pathServiceSid, - final String pathUserSid) { + public UserBindingReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - /** - * The push technology used for the returned Bindings. Supported values are - * apn, gcm and fcm. See [push notification - * configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more information.. - * - * @param bindingType The push technology used for the bindings returned. - * @return this - */ - public UserBindingReader setBindingType(final List bindingType) { + public UserBindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - /** - * The push technology used for the returned Bindings. Supported values are - * apn, gcm and fcm. See [push notification - * configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more information.. - * - * @param bindingType The push technology used for the bindings returned. - * @return this - */ - public UserBindingReader setBindingType(final UserBinding.BindingType bindingType) { + public UserBindingReader setBindingType( + final UserBinding.BindingType bindingType + ) { return setBindingType(Promoter.listOfOne(bindingType)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserBindingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + UserBinding.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Bindings", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + UserBinding.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UserBinding read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "bindings", + response.getContent(), + UserBinding.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of UserBinding Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserBinding read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "bindings", - response.getContent(), - UserBinding.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (bindingType != null) { - for (UserBinding.BindingType prop : bindingType) { - request.addQueryParam("BindingType", prop.toString()); + for (UserBinding.BindingType param : bindingType) { + Serializer.toString( + request, + "BindingType", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannel.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannel.java index 02843b57c3..6fd7713355 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannel.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.user; @@ -10,34 +17,120 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class UserChannel extends Resource { - private static final long serialVersionUID = 254880238496884L; + + public static UserChannelDeleter deleter( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelDeleter( + pathServiceSid, + pathUserSid, + pathChannelSid + ); + } + + public static UserChannelFetcher fetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelFetcher( + pathServiceSid, + pathUserSid, + pathChannelSid + ); + } + + public static UserChannelReader reader( + final String pathServiceSid, + final String pathUserSid + ) { + return new UserChannelReader(pathServiceSid, pathUserSid); + } + + public static UserChannelUpdater updater( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelUpdater( + pathServiceSid, + pathUserSid, + pathChannelSid + ); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + public enum NotificationLevel { + DEFAULT("default"), + MUTED("muted"); + + private final String value; + + private NotificationLevel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static NotificationLevel forValue(final String value) { + return Promoter.enumFromString(value, NotificationLevel.values()); + } + } public enum ChannelStatus { JOINED("joined"), INVITED("invited"), - NOT_PARTICIPATING("not_participating"); + NOT_PARTICIPATING("notParticipating"); private final String value; @@ -45,15 +138,11 @@ private ChannelStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ChannelStatus from a string. - * @param value string value - * @return generated ChannelStatus - */ @JsonCreator public static ChannelStatus forValue(final String value) { return Promoter.enumFromString(value, ChannelStatus.values()); @@ -61,26 +150,16 @@ public static ChannelStatus forValue(final String value) { } /** - * Create a UserChannelReader to execute read. - * - * @param pathServiceSid The unique id of the Service those channels belong to. - * @param pathUserSid The unique id of a User. - * @return UserChannelReader capable of executing the read - */ - public static UserChannelReader reader(final String pathServiceSid, - final String pathUserSid) { - return new UserChannelReader(pathServiceSid, pathUserSid); - } - - /** - * Converts a JSON String into a UserChannel object using the provided - * ObjectMapper. - * + * Converts a JSON String into a UserChannel object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return UserChannel object represented by the provided JSON */ - public static UserChannel fromJson(final String json, final ObjectMapper objectMapper) { + public static UserChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -94,12 +173,15 @@ public static UserChannel fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a UserChannel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return UserChannel object represented by the provided JSON */ - public static UserChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static UserChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -110,113 +192,82 @@ public static UserChannel fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String channelSid; - private final String memberSid; - private final UserChannel.ChannelStatus status; + + @Getter private final Integer lastConsumedMessageIndex; - private final Integer unreadMessagesCount; - private final Map links; - @JsonCreator - private UserChannel(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("member_sid") - final String memberSid, - @JsonProperty("status") - final UserChannel.ChannelStatus status, - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - @JsonProperty("links") - final Map links) { - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.channelSid = channelSid; - this.memberSid = memberSid; - this.status = status; - this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.unreadMessagesCount = unreadMessagesCount; - this.links = links; - } + @Getter + private final Map links; - /** - * Returns The The unique id of the Account responsible for this channel.. - * - * @return The unique id of the Account responsible for this channel. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String memberSid; - /** - * Returns The The unique id of the Service this channel belongs to.. - * - * @return The unique id of the Service this channel belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final UserChannel.NotificationLevel notificationLevel; - /** - * Returns The The unique id of a Channel.. - * - * @return The unique id of a Channel. - */ - public final String getChannelSid() { - return this.channelSid; - } + @Getter + private final String serviceSid; - /** - * Returns The The unique id of this User as a Member in this Channel.. - * - * @return The unique id of this User as a Member in this Channel. - */ - public final String getMemberSid() { - return this.memberSid; - } + @Getter + private final UserChannel.ChannelStatus status; - /** - * Returns The The status of the User on this Channel.. - * - * @return The status of the User on this Channel. - */ - public final UserChannel.ChannelStatus getStatus() { - return this.status; - } + @Getter + private final Integer unreadMessagesCount; - /** - * Returns The The index of the last read Message in this Channel for this - * User.. - * - * @return The index of the last read Message in this Channel for this User. - */ - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } + @Getter + private final URI url; - /** - * Returns The The count of unread Messages in this Channel for this User.. - * - * @return The count of unread Messages in this Channel for this User. - */ - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } + @Getter + private final String userSid; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @JsonCreator + private UserChannel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty("links") final Map links, + @JsonProperty("member_sid") final String memberSid, + @JsonProperty( + "notification_level" + ) final UserChannel.NotificationLevel notificationLevel, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("status") final UserChannel.ChannelStatus status, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty("url") final URI url, + @JsonProperty("user_sid") final String userSid + ) { + this.accountSid = accountSid; + this.channelSid = channelSid; + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + this.links = links; + this.memberSid = memberSid; + this.notificationLevel = notificationLevel; + this.serviceSid = serviceSid; + this.status = status; + this.unreadMessagesCount = unreadMessagesCount; + this.url = url; + this.userSid = userSid; } @Override @@ -230,40 +281,38 @@ public boolean equals(final Object o) { } UserChannel other = (UserChannel) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(memberSid, other.memberSid) && - Objects.equals(status, other.status) && - Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && - Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals(links, other.links) && + Objects.equals(memberSid, other.memberSid) && + Objects.equals(notificationLevel, other.notificationLevel) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(status, other.status) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(url, other.url) && + Objects.equals(userSid, other.userSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - channelSid, - memberSid, - status, - lastConsumedMessageIndex, - unreadMessagesCount, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("channelSid", channelSid) - .add("memberSid", memberSid) - .add("status", status) - .add("lastConsumedMessageIndex", lastConsumedMessageIndex) - .add("unreadMessagesCount", unreadMessagesCount) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + channelSid, + lastConsumedMessageIndex, + links, + memberSid, + notificationLevel, + serviceSid, + status, + unreadMessagesCount, + url, + userSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelDeleter.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelDeleter.java new file mode 100644 index 0000000000..372e67ace3 --- /dev/null +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelDeleter.java @@ -0,0 +1,138 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.chat.v2.service.user; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UserChannelDeleter extends Deleter { + + private String pathServiceSid; + private String pathUserSid; + private String pathChannelSid; + private UserChannel.WebhookEnabledType xTwilioWebhookEnabled; + + public UserChannelDeleter( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathUserSid = pathUserSid; + this.pathChannelSid = pathChannelSid; + } + + public UserChannelDeleter setXTwilioWebhookEnabled( + final UserChannel.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CHAT.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserChannel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelFetcher.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelFetcher.java new file mode 100644 index 0000000000..0ec33c77be --- /dev/null +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.chat.v2.service.user; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserChannelFetcher extends Fetcher { + + private String pathServiceSid; + private String pathUserSid; + private String pathChannelSid; + + public UserChannelFetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathUserSid = pathUserSid; + this.pathChannelSid = pathChannelSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CHAT.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserChannel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserChannel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserChannel content = UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelReader.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelReader.java index c3ff217eb7..6a8c15ce85 100644 --- a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelReader.java +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.chat.v2.service.user; @@ -10,163 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserChannelReader extends Reader { - private final String pathServiceSid; - private final String pathUserSid; - - /** - * Construct a new UserChannelReader. - * - * @param pathServiceSid The unique id of the Service those channels belong to. - * @param pathUserSid The unique id of a User. - */ - public UserChannelReader(final String pathServiceSid, - final String pathUserSid) { + + private String pathServiceSid; + private String pathUserSid; + private Long pageSize; + + public UserChannelReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.CHAT.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UserChannel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.CHAT.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of UserChannel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserChannel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - UserChannel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelUpdater.java b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelUpdater.java new file mode 100644 index 0000000000..a8c3b9c4dc --- /dev/null +++ b/src/main/java/com/twilio/rest/chat/v2/service/user/UserChannelUpdater.java @@ -0,0 +1,174 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.chat.v2.service.user; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class UserChannelUpdater extends Updater { + + private String pathServiceSid; + private String pathUserSid; + private String pathChannelSid; + private UserChannel.NotificationLevel notificationLevel; + private Integer lastConsumedMessageIndex; + private ZonedDateTime lastConsumptionTimestamp; + + public UserChannelUpdater( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathUserSid = pathUserSid; + this.pathChannelSid = pathChannelSid; + } + + public UserChannelUpdater setNotificationLevel( + final UserChannel.NotificationLevel notificationLevel + ) { + this.notificationLevel = notificationLevel; + return this; + } + + public UserChannelUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + return this; + } + + public UserChannelUpdater setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { + this.lastConsumptionTimestamp = lastConsumptionTimestamp; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CHAT.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserChannel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserChannel update(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserChannel content = UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (notificationLevel != null) { + Serializer.toString( + request, + "NotificationLevel", + notificationLevel, + ParameterType.URLENCODED + ); + } + + if (lastConsumedMessageIndex != null) { + Serializer.toString( + request, + "LastConsumedMessageIndex", + lastConsumedMessageIndex, + ParameterType.URLENCODED + ); + } + + if (lastConsumptionTimestamp != null) { + Serializer.toString( + request, + "LastConsumptionTimestamp", + lastConsumptionTimestamp, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/chat/v3/Channel.java b/src/main/java/com/twilio/rest/chat/v3/Channel.java new file mode 100644 index 0000000000..f44eb1083b --- /dev/null +++ b/src/main/java/com/twilio/rest/chat/v3/Channel.java @@ -0,0 +1,284 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.chat.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Channel extends Resource { + + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelUpdater(pathServiceSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + public enum ChannelType { + PUBLIC("public"), + PRIVATE("private"); + + private final String value; + + private ChannelType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ChannelType forValue(final String value) { + return Promoter.enumFromString(value, ChannelType.values()); + } + } + + /** + * Converts a JSON String into a Channel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Channel.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Channel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Channel.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String createdBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Integer membersCount; + + @Getter + private final Integer messagesCount; + + @Getter + private final String messagingServiceSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final Channel.ChannelType type; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private Channel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.membersCount = membersCount; + this.messagesCount = messagesCount; + this.messagingServiceSid = messagingServiceSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Channel other = (Channel) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + createdBy, + dateCreated, + dateUpdated, + friendlyName, + membersCount, + messagesCount, + messagingServiceSid, + serviceSid, + sid, + type, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/chat/v3/ChannelUpdater.java b/src/main/java/com/twilio/rest/chat/v3/ChannelUpdater.java new file mode 100644 index 0000000000..efd7026526 --- /dev/null +++ b/src/main/java/com/twilio/rest/chat/v3/ChannelUpdater.java @@ -0,0 +1,159 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Chat + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.chat.v3; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelUpdater extends Updater { + + private String pathServiceSid; + private String pathSid; + private Channel.WebhookEnabledType xTwilioWebhookEnabled; + private Channel.ChannelType type; + private String messagingServiceSid; + + public ChannelUpdater(final String pathServiceSid, final String pathSid) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + public ChannelUpdater setType(final Channel.ChannelType type) { + this.type = type; + return this; + } + + public ChannelUpdater setMessagingServiceSid( + final String messagingServiceSid + ) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + public ChannelUpdater setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CHAT.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Channel update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Channel.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/Content.java b/src/main/java/com/twilio/rest/content/v1/Content.java new file mode 100644 index 0000000000..d49fe461d2 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/Content.java @@ -0,0 +1,3742 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Content extends Resource { + + public static ContentCreator creator( + final Content.ContentCreateRequest contentCreateRequest + ) { + return new ContentCreator(contentCreateRequest); + } + + public static ContentDeleter deleter(final String pathSid) { + return new ContentDeleter(pathSid); + } + + public static ContentFetcher fetcher(final String pathSid) { + return new ContentFetcher(pathSid); + } + + public static ContentReader reader() { + return new ContentReader(); + } + + public static ContentUpdater updater( + final String pathSid, + final Content.ContentUpdateRequest contentUpdateRequest + ) { + return new ContentUpdater(pathSid, contentUpdateRequest); + } + + public enum CarouselActionType { + URL("URL"), + PHONE_NUMBER("PHONE_NUMBER"), + QUICK_REPLY("QUICK_REPLY"); + + private final String value; + + private CarouselActionType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CarouselActionType forValue(final String value) { + return Promoter.enumFromString(value, CarouselActionType.values()); + } + } + + public enum AuthenticationActionType { + COPY_CODE("COPY_CODE"); + + private final String value; + + private AuthenticationActionType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static AuthenticationActionType forValue(final String value) { + return Promoter.enumFromString( + value, + AuthenticationActionType.values() + ); + } + } + + public enum CardActionType { + URL("URL"), + PHONE_NUMBER("PHONE_NUMBER"), + QUICK_REPLY("QUICK_REPLY"), + COPY_CODE("COPY_CODE"), + VOICE_CALL("VOICE_CALL"), + PIX("PIX"), + BOLETO("BOLETO"), + PAYMENT_LINK("PAYMENT_LINK"); + + private final String value; + + private CardActionType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CardActionType forValue(final String value) { + return Promoter.enumFromString(value, CardActionType.values()); + } + } + + public enum QuickReplyActionType { + QUICK_REPLY("QUICK_REPLY"); + + private final String value; + + private QuickReplyActionType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static QuickReplyActionType forValue(final String value) { + return Promoter.enumFromString( + value, + QuickReplyActionType.values() + ); + } + } + + public enum WebviewSizeType { + TALL("TALL"), + FULL("FULL"), + HALF("HALF"), + NONE("NONE"); + + private final String value; + + private WebviewSizeType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebviewSizeType forValue(final String value) { + return Promoter.enumFromString(value, WebviewSizeType.values()); + } + } + + public enum CallToActionActionType { + URL("URL"), + PHONE_NUMBER("PHONE_NUMBER"), + COPY_CODE("COPY_CODE"), + VOICE_CALL("VOICE_CALL"), + VOICE_CALL_REQUEST("VOICE_CALL_REQUEST"), + REQUEST_CONTACT_INFO("REQUEST_CONTACT_INFO"); + + private final String value; + + private CallToActionActionType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallToActionActionType forValue(final String value) { + return Promoter.enumFromString( + value, + CallToActionActionType.values() + ); + } + } + + @JsonDeserialize(builder = FlowsPage.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class FlowsPage { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("next_page_id") + @Getter + private final String nextPageId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + @Getter + private final String subtitle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("layout") + @Getter + private final List layout; + + private FlowsPage(Builder builder) { + this.id = builder.id; + this.nextPageId = builder.nextPageId; + this.title = builder.title; + this.subtitle = builder.subtitle; + this.layout = builder.layout; + } + + public static Builder builder( + final String id, + final String title, + final List layout + ) { + return new Builder(id, title, layout); + } + + public static FlowsPage fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, FlowsPage.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("next_page_id") + private String nextPageId; + + @JsonProperty("title") + private String title; + + @JsonProperty("subtitle") + private String subtitle; + + @JsonProperty("layout") + private List layout; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("title") final String title, + @JsonProperty("layout") final List layout + ) { + this.id = id; + this.title = title; + this.layout = layout; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("next_page_id") + public Builder nextPageId(String nextPageId) { + this.nextPageId = nextPageId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + public Builder subtitle(String subtitle) { + this.subtitle = subtitle; + return this; + } + + public FlowsPage build() { + return new FlowsPage(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FlowsPage other = (FlowsPage) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(nextPageId, other.nextPageId) && + Objects.equals(title, other.title) && + Objects.equals(subtitle, other.subtitle) && + Objects.equals(layout, other.layout) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, nextPageId, title, subtitle, layout); + } + } + + @JsonDeserialize(builder = Types.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Types { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/text") + @Getter + private final TwilioText twilioText; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/media") + @Getter + private final TwilioMedia twilioMedia; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/location") + @Getter + private final TwilioLocation twilioLocation; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/list-picker") + @Getter + private final TwilioListPicker twilioListPicker; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/call-to-action") + @Getter + private final TwilioCallToAction twilioCallToAction; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/quick-reply") + @Getter + private final TwilioQuickReply twilioQuickReply; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/card") + @Getter + private final TwilioCard twilioCard; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/catalog") + @Getter + private final TwilioCatalog twilioCatalog; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/carousel") + @Getter + private final TwilioCarousel twilioCarousel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/flows") + @Getter + private final TwilioFlows twilioFlows; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/schedule") + @Getter + private final TwilioSchedule twilioSchedule; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("whatsapp/card") + @Getter + private final WhatsappCard whatsappCard; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("whatsapp/authentication") + @Getter + private final WhatsappAuthentication whatsappAuthentication; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("whatsapp/flows") + @Getter + private final WhatsappFlows whatsappFlows; + + private Types(Builder builder) { + this.twilioText = builder.twilioText; + this.twilioMedia = builder.twilioMedia; + this.twilioLocation = builder.twilioLocation; + this.twilioListPicker = builder.twilioListPicker; + this.twilioCallToAction = builder.twilioCallToAction; + this.twilioQuickReply = builder.twilioQuickReply; + this.twilioCard = builder.twilioCard; + this.twilioCatalog = builder.twilioCatalog; + this.twilioCarousel = builder.twilioCarousel; + this.twilioFlows = builder.twilioFlows; + this.twilioSchedule = builder.twilioSchedule; + this.whatsappCard = builder.whatsappCard; + this.whatsappAuthentication = builder.whatsappAuthentication; + this.whatsappFlows = builder.whatsappFlows; + } + + public static Builder builder() { + return new Builder(); + } + + public static Types fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Types.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("twilio/text") + private TwilioText twilioText; + + @JsonProperty("twilio/media") + private TwilioMedia twilioMedia; + + @JsonProperty("twilio/location") + private TwilioLocation twilioLocation; + + @JsonProperty("twilio/list-picker") + private TwilioListPicker twilioListPicker; + + @JsonProperty("twilio/call-to-action") + private TwilioCallToAction twilioCallToAction; + + @JsonProperty("twilio/quick-reply") + private TwilioQuickReply twilioQuickReply; + + @JsonProperty("twilio/card") + private TwilioCard twilioCard; + + @JsonProperty("twilio/catalog") + private TwilioCatalog twilioCatalog; + + @JsonProperty("twilio/carousel") + private TwilioCarousel twilioCarousel; + + @JsonProperty("twilio/flows") + private TwilioFlows twilioFlows; + + @JsonProperty("twilio/schedule") + private TwilioSchedule twilioSchedule; + + @JsonProperty("whatsapp/card") + private WhatsappCard whatsappCard; + + @JsonProperty("whatsapp/authentication") + private WhatsappAuthentication whatsappAuthentication; + + @JsonProperty("whatsapp/flows") + private WhatsappFlows whatsappFlows; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/text") + public Builder twilioText(TwilioText twilioText) { + this.twilioText = twilioText; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/media") + public Builder twilioMedia(TwilioMedia twilioMedia) { + this.twilioMedia = twilioMedia; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/location") + public Builder twilioLocation(TwilioLocation twilioLocation) { + this.twilioLocation = twilioLocation; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/list-picker") + public Builder twilioListPicker(TwilioListPicker twilioListPicker) { + this.twilioListPicker = twilioListPicker; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/call-to-action") + public Builder twilioCallToAction( + TwilioCallToAction twilioCallToAction + ) { + this.twilioCallToAction = twilioCallToAction; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/quick-reply") + public Builder twilioQuickReply(TwilioQuickReply twilioQuickReply) { + this.twilioQuickReply = twilioQuickReply; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/card") + public Builder twilioCard(TwilioCard twilioCard) { + this.twilioCard = twilioCard; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/catalog") + public Builder twilioCatalog(TwilioCatalog twilioCatalog) { + this.twilioCatalog = twilioCatalog; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/carousel") + public Builder twilioCarousel(TwilioCarousel twilioCarousel) { + this.twilioCarousel = twilioCarousel; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/flows") + public Builder twilioFlows(TwilioFlows twilioFlows) { + this.twilioFlows = twilioFlows; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio/schedule") + public Builder twilioSchedule(TwilioSchedule twilioSchedule) { + this.twilioSchedule = twilioSchedule; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("whatsapp/card") + public Builder whatsappCard(WhatsappCard whatsappCard) { + this.whatsappCard = whatsappCard; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("whatsapp/authentication") + public Builder whatsappAuthentication( + WhatsappAuthentication whatsappAuthentication + ) { + this.whatsappAuthentication = whatsappAuthentication; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("whatsapp/flows") + public Builder whatsappFlows(WhatsappFlows whatsappFlows) { + this.whatsappFlows = whatsappFlows; + return this; + } + + public Types build() { + return new Types(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Types other = (Types) o; + return ( + Objects.equals(twilioText, other.twilioText) && + Objects.equals(twilioMedia, other.twilioMedia) && + Objects.equals(twilioLocation, other.twilioLocation) && + Objects.equals(twilioListPicker, other.twilioListPicker) && + Objects.equals(twilioCallToAction, other.twilioCallToAction) && + Objects.equals(twilioQuickReply, other.twilioQuickReply) && + Objects.equals(twilioCard, other.twilioCard) && + Objects.equals(twilioCatalog, other.twilioCatalog) && + Objects.equals(twilioCarousel, other.twilioCarousel) && + Objects.equals(twilioFlows, other.twilioFlows) && + Objects.equals(twilioSchedule, other.twilioSchedule) && + Objects.equals(whatsappCard, other.whatsappCard) && + Objects.equals( + whatsappAuthentication, + other.whatsappAuthentication + ) && + Objects.equals(whatsappFlows, other.whatsappFlows) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + twilioText, + twilioMedia, + twilioLocation, + twilioListPicker, + twilioCallToAction, + twilioQuickReply, + twilioCard, + twilioCatalog, + twilioCarousel, + twilioFlows, + twilioSchedule, + whatsappCard, + whatsappAuthentication, + whatsappFlows + ); + } + } + + @JsonDeserialize(builder = CallToActionAction.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallToActionAction { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Content.CallToActionActionType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final String url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone") + @Getter + private final String phone; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + @Getter + private final String code; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + private CallToActionAction(Builder builder) { + this.type = builder.type; + this.title = builder.title; + this.url = builder.url; + this.phone = builder.phone; + this.code = builder.code; + this.id = builder.id; + } + + public static Builder builder( + final Content.CallToActionActionType type + ) { + return new Builder(type); + } + + public static CallToActionAction fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CallToActionAction.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Content.CallToActionActionType type; + + @JsonProperty("title") + private String title; + + @JsonProperty("url") + private String url; + + @JsonProperty("phone") + private String phone; + + @JsonProperty("code") + private String code; + + @JsonProperty("id") + private String id; + + @JsonCreator + public Builder( + @JsonProperty("type") final Content.CallToActionActionType type + ) { + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + public Builder title(String title) { + this.title = title; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + public Builder url(String url) { + this.url = url; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone") + public Builder phone(String phone) { + this.phone = phone; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + public Builder code(String code) { + this.code = code; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + public CallToActionAction build() { + return new CallToActionAction(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallToActionAction other = (CallToActionAction) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(title, other.title) && + Objects.equals(url, other.url) && + Objects.equals(phone, other.phone) && + Objects.equals(code, other.code) && + Objects.equals(id, other.id) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, title, url, phone, code, id); + } + } + + @JsonDeserialize(builder = CarouselAction.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CarouselAction { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Content.CarouselActionType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final String url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone") + @Getter + private final String phone; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + private CarouselAction(Builder builder) { + this.type = builder.type; + this.title = builder.title; + this.url = builder.url; + this.phone = builder.phone; + this.id = builder.id; + } + + public static Builder builder( + final Content.CarouselActionType type, + final String title + ) { + return new Builder(type, title); + } + + public static CarouselAction fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CarouselAction.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Content.CarouselActionType type; + + @JsonProperty("title") + private String title; + + @JsonProperty("url") + private String url; + + @JsonProperty("phone") + private String phone; + + @JsonProperty("id") + private String id; + + @JsonCreator + public Builder( + @JsonProperty("type") final Content.CarouselActionType type, + @JsonProperty("title") final String title + ) { + this.type = type; + this.title = title; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + public Builder url(String url) { + this.url = url; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone") + public Builder phone(String phone) { + this.phone = phone; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + public CarouselAction build() { + return new CarouselAction(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CarouselAction other = (CarouselAction) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(title, other.title) && + Objects.equals(url, other.url) && + Objects.equals(phone, other.phone) && + Objects.equals(id, other.id) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, title, url, phone, id); + } + } + + @JsonDeserialize(builder = WhatsappCard.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class WhatsappCard { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("footer") + @Getter + private final String footer; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media") + @Getter + private final List media; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("header_text") + @Getter + private final String headerText; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + private WhatsappCard(Builder builder) { + this.body = builder.body; + this.footer = builder.footer; + this.media = builder.media; + this.headerText = builder.headerText; + this.actions = builder.actions; + } + + public static Builder builder(final String body) { + return new Builder(body); + } + + public static WhatsappCard fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, WhatsappCard.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonProperty("footer") + private String footer; + + @JsonProperty("media") + private List media; + + @JsonProperty("header_text") + private String headerText; + + @JsonProperty("actions") + private List actions; + + @JsonCreator + public Builder(@JsonProperty("body") final String body) { + this.body = body; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("footer") + public Builder footer(String footer) { + this.footer = footer; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media") + public Builder media(List media) { + this.media = media; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("header_text") + public Builder headerText(String headerText) { + this.headerText = headerText; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + public Builder actions(List actions) { + this.actions = actions; + return this; + } + + public WhatsappCard build() { + return new WhatsappCard(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + WhatsappCard other = (WhatsappCard) o; + return ( + Objects.equals(body, other.body) && + Objects.equals(footer, other.footer) && + Objects.equals(media, other.media) && + Objects.equals(headerText, other.headerText) && + Objects.equals(actions, other.actions) + ); + } + + @Override + public int hashCode() { + return Objects.hash(body, footer, media, headerText, actions); + } + } + + @JsonDeserialize(builder = WhatsappAuthentication.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class WhatsappAuthentication { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("add_security_recommendation") + @Getter + private final Boolean addSecurityRecommendation; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code_expiration_minutes") + @Getter + private final BigDecimal codeExpirationMinutes; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + private WhatsappAuthentication(Builder builder) { + this.addSecurityRecommendation = builder.addSecurityRecommendation; + this.codeExpirationMinutes = builder.codeExpirationMinutes; + this.actions = builder.actions; + } + + public static Builder builder( + final List actions + ) { + return new Builder(actions); + } + + public static WhatsappAuthentication fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, WhatsappAuthentication.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("add_security_recommendation") + private Boolean addSecurityRecommendation; + + @JsonProperty("code_expiration_minutes") + private BigDecimal codeExpirationMinutes; + + @JsonProperty("actions") + private List actions; + + @JsonCreator + public Builder( + @JsonProperty("actions") final List< + AuthenticationAction + > actions + ) { + this.actions = actions; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("add_security_recommendation") + public Builder addSecurityRecommendation( + Boolean addSecurityRecommendation + ) { + this.addSecurityRecommendation = addSecurityRecommendation; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code_expiration_minutes") + public Builder codeExpirationMinutes( + BigDecimal codeExpirationMinutes + ) { + this.codeExpirationMinutes = codeExpirationMinutes; + return this; + } + + public WhatsappAuthentication build() { + return new WhatsappAuthentication(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + WhatsappAuthentication other = (WhatsappAuthentication) o; + return ( + Objects.equals( + addSecurityRecommendation, + other.addSecurityRecommendation + ) && + Objects.equals( + codeExpirationMinutes, + other.codeExpirationMinutes + ) && + Objects.equals(actions, other.actions) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + addSecurityRecommendation, + codeExpirationMinutes, + actions + ); + } + } + + @JsonDeserialize(builder = QuickReplyAction.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QuickReplyAction { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Content.QuickReplyActionType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + private QuickReplyAction(Builder builder) { + this.type = builder.type; + this.title = builder.title; + this.id = builder.id; + } + + public static Builder builder(final String title) { + return new Builder(title); + } + + public static QuickReplyAction fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, QuickReplyAction.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Content.QuickReplyActionType type; + + @JsonProperty("title") + private String title; + + @JsonProperty("id") + private String id; + + @JsonCreator + public Builder(@JsonProperty("title") final String title) { + this.title = title; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Content.QuickReplyActionType type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + public QuickReplyAction build() { + return new QuickReplyAction(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QuickReplyAction other = (QuickReplyAction) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(title, other.title) && + Objects.equals(id, other.id) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, title, id); + } + } + + @JsonDeserialize(builder = TwilioCard.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioCard { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + @Getter + private final String subtitle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media") + @Getter + private final List media; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + private TwilioCard(Builder builder) { + this.title = builder.title; + this.subtitle = builder.subtitle; + this.media = builder.media; + this.actions = builder.actions; + } + + public static Builder builder() { + return new Builder(); + } + + public static TwilioCard fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioCard.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("title") + private String title; + + @JsonProperty("subtitle") + private String subtitle; + + @JsonProperty("media") + private List media; + + @JsonProperty("actions") + private List actions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + public Builder title(String title) { + this.title = title; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + public Builder subtitle(String subtitle) { + this.subtitle = subtitle; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media") + public Builder media(List media) { + this.media = media; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + public Builder actions(List actions) { + this.actions = actions; + return this; + } + + public TwilioCard build() { + return new TwilioCard(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioCard other = (TwilioCard) o; + return ( + Objects.equals(title, other.title) && + Objects.equals(subtitle, other.subtitle) && + Objects.equals(media, other.media) && + Objects.equals(actions, other.actions) + ); + } + + @Override + public int hashCode() { + return Objects.hash(title, subtitle, media, actions); + } + } + + @JsonDeserialize(builder = AuthenticationAction.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AuthenticationAction { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Content.AuthenticationActionType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("copy_code_text") + @Getter + private final String copyCodeText; + + private AuthenticationAction(Builder builder) { + this.type = builder.type; + this.copyCodeText = builder.copyCodeText; + } + + public static Builder builder( + final Content.AuthenticationActionType type, + final String copyCodeText + ) { + return new Builder(type, copyCodeText); + } + + public static AuthenticationAction fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, AuthenticationAction.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Content.AuthenticationActionType type; + + @JsonProperty("copy_code_text") + private String copyCodeText; + + @JsonCreator + public Builder( + @JsonProperty( + "type" + ) final Content.AuthenticationActionType type, + @JsonProperty("copy_code_text") final String copyCodeText + ) { + this.type = type; + this.copyCodeText = copyCodeText; + } + + public AuthenticationAction build() { + return new AuthenticationAction(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AuthenticationAction other = (AuthenticationAction) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(copyCodeText, other.copyCodeText) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, copyCodeText); + } + } + + @JsonDeserialize(builder = ContentCreateRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ContentCreateRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("variables") + @Getter + private final Map variables; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("language") + @Getter + private final String language; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("types") + @Getter + private final Types types; + + private ContentCreateRequest(Builder builder) { + this.friendlyName = builder.friendlyName; + this.variables = builder.variables; + this.language = builder.language; + this.types = builder.types; + } + + public static Builder builder( + final String language, + final Types types + ) { + return new Builder(language, types); + } + + public static ContentCreateRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ContentCreateRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonProperty("variables") + private Map variables; + + @JsonProperty("language") + private String language; + + @JsonProperty("types") + private Types types; + + @JsonCreator + public Builder( + @JsonProperty("language") final String language, + @JsonProperty("types") final Types types + ) { + this.language = language; + this.types = types; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("variables") + public Builder variables(Map variables) { + this.variables = variables; + return this; + } + + public ContentCreateRequest build() { + return new ContentCreateRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContentCreateRequest other = (ContentCreateRequest) o; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(variables, other.variables) && + Objects.equals(language, other.language) && + Objects.equals(types, other.types) + ); + } + + @Override + public int hashCode() { + return Objects.hash(friendlyName, variables, language, types); + } + } + + @JsonDeserialize(builder = TwilioCallToAction.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioCallToAction { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + private TwilioCallToAction(Builder builder) { + this.body = builder.body; + this.actions = builder.actions; + } + + public static Builder builder( + final String body, + final List actions + ) { + return new Builder(body, actions); + } + + public static TwilioCallToAction fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioCallToAction.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonProperty("actions") + private List actions; + + @JsonCreator + public Builder( + @JsonProperty("body") final String body, + @JsonProperty("actions") final List actions + ) { + this.body = body; + this.actions = actions; + } + + public TwilioCallToAction build() { + return new TwilioCallToAction(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioCallToAction other = (TwilioCallToAction) o; + return ( + Objects.equals(body, other.body) && + Objects.equals(actions, other.actions) + ); + } + + @Override + public int hashCode() { + return Objects.hash(body, actions); + } + } + + @JsonDeserialize(builder = ContentUpdateRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ContentUpdateRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("variables") + @Getter + private final Map variables; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("language") + @Getter + private final String language; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("types") + @Getter + private final Types types; + + private ContentUpdateRequest(Builder builder) { + this.friendlyName = builder.friendlyName; + this.variables = builder.variables; + this.language = builder.language; + this.types = builder.types; + } + + public static Builder builder(final Types types) { + return new Builder(types); + } + + public static ContentUpdateRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ContentUpdateRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonProperty("variables") + private Map variables; + + @JsonProperty("language") + private String language; + + @JsonProperty("types") + private Types types; + + @JsonCreator + public Builder(@JsonProperty("types") final Types types) { + this.types = types; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("variables") + public Builder variables(Map variables) { + this.variables = variables; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("language") + public Builder language(String language) { + this.language = language; + return this; + } + + public ContentUpdateRequest build() { + return new ContentUpdateRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContentUpdateRequest other = (ContentUpdateRequest) o; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(variables, other.variables) && + Objects.equals(language, other.language) && + Objects.equals(types, other.types) + ); + } + + @Override + public int hashCode() { + return Objects.hash(friendlyName, variables, language, types); + } + } + + @JsonDeserialize(builder = TwilioQuickReply.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioQuickReply { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + private TwilioQuickReply(Builder builder) { + this.body = builder.body; + this.actions = builder.actions; + } + + public static Builder builder( + final String body, + final List actions + ) { + return new Builder(body, actions); + } + + public static TwilioQuickReply fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioQuickReply.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonProperty("actions") + private List actions; + + @JsonCreator + public Builder( + @JsonProperty("body") final String body, + @JsonProperty("actions") final List actions + ) { + this.body = body; + this.actions = actions; + } + + public TwilioQuickReply build() { + return new TwilioQuickReply(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioQuickReply other = (TwilioQuickReply) o; + return ( + Objects.equals(body, other.body) && + Objects.equals(actions, other.actions) + ); + } + + @Override + public int hashCode() { + return Objects.hash(body, actions); + } + } + + @JsonDeserialize(builder = TwilioMedia.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioMedia { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media") + @Getter + private final List media; + + private TwilioMedia(Builder builder) { + this.body = builder.body; + this.media = builder.media; + } + + public static Builder builder(final List media) { + return new Builder(media); + } + + public static TwilioMedia fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioMedia.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonProperty("media") + private List media; + + @JsonCreator + public Builder(@JsonProperty("media") final List media) { + this.media = media; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + public Builder body(String body) { + this.body = body; + return this; + } + + public TwilioMedia build() { + return new TwilioMedia(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioMedia other = (TwilioMedia) o; + return ( + Objects.equals(body, other.body) && + Objects.equals(media, other.media) + ); + } + + @Override + public int hashCode() { + return Objects.hash(body, media); + } + } + + @JsonDeserialize(builder = TwilioFlows.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioFlows { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("button_text") + @Getter + private final String buttonText; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + @Getter + private final String subtitle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media_url") + @Getter + private final String mediaUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pages") + @Getter + private final List pages; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + private TwilioFlows(Builder builder) { + this.body = builder.body; + this.buttonText = builder.buttonText; + this.subtitle = builder.subtitle; + this.mediaUrl = builder.mediaUrl; + this.pages = builder.pages; + this.type = builder.type; + } + + public static Builder builder( + final String body, + final String buttonText, + final List pages, + final String type + ) { + return new Builder(body, buttonText, pages, type); + } + + public static TwilioFlows fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioFlows.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonProperty("button_text") + private String buttonText; + + @JsonProperty("subtitle") + private String subtitle; + + @JsonProperty("media_url") + private String mediaUrl; + + @JsonProperty("pages") + private List pages; + + @JsonProperty("type") + private String type; + + @JsonCreator + public Builder( + @JsonProperty("body") final String body, + @JsonProperty("button_text") final String buttonText, + @JsonProperty("pages") final List pages, + @JsonProperty("type") final String type + ) { + this.body = body; + this.buttonText = buttonText; + this.pages = pages; + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + public Builder subtitle(String subtitle) { + this.subtitle = subtitle; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media_url") + public Builder mediaUrl(String mediaUrl) { + this.mediaUrl = mediaUrl; + return this; + } + + public TwilioFlows build() { + return new TwilioFlows(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioFlows other = (TwilioFlows) o; + return ( + Objects.equals(body, other.body) && + Objects.equals(buttonText, other.buttonText) && + Objects.equals(subtitle, other.subtitle) && + Objects.equals(mediaUrl, other.mediaUrl) && + Objects.equals(pages, other.pages) && + Objects.equals(type, other.type) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + body, + buttonText, + subtitle, + mediaUrl, + pages, + type + ); + } + } + + @JsonDeserialize(builder = FlowsPageComponent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class FlowsPageComponent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + @Getter + private final String label; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + private FlowsPageComponent(Builder builder) { + this.label = builder.label; + this.type = builder.type; + } + + public static Builder builder(final String type) { + return new Builder(type); + } + + public static FlowsPageComponent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, FlowsPageComponent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("label") + private String label; + + @JsonProperty("type") + private String type; + + @JsonCreator + public Builder(@JsonProperty("type") final String type) { + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + public Builder label(String label) { + this.label = label; + return this; + } + + public FlowsPageComponent build() { + return new FlowsPageComponent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FlowsPageComponent other = (FlowsPageComponent) o; + return ( + Objects.equals(label, other.label) && + Objects.equals(type, other.type) + ); + } + + @Override + public int hashCode() { + return Objects.hash(label, type); + } + } + + @JsonDeserialize(builder = WhatsappFlows.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class WhatsappFlows { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("button_text") + @Getter + private final String buttonText; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + @Getter + private final String subtitle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media_url") + @Getter + private final String mediaUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("flow_id") + @Getter + private final String flowId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("flow_token") + @Getter + private final String flowToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("flow_first_page_id") + @Getter + private final String flowFirstPageId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("is_flow_first_page_endpoint") + @Getter + private final Boolean isFlowFirstPageEndpoint; + + private WhatsappFlows(Builder builder) { + this.body = builder.body; + this.buttonText = builder.buttonText; + this.subtitle = builder.subtitle; + this.mediaUrl = builder.mediaUrl; + this.flowId = builder.flowId; + this.flowToken = builder.flowToken; + this.flowFirstPageId = builder.flowFirstPageId; + this.isFlowFirstPageEndpoint = builder.isFlowFirstPageEndpoint; + } + + public static Builder builder( + final String body, + final String buttonText, + final String flowId + ) { + return new Builder(body, buttonText, flowId); + } + + public static WhatsappFlows fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, WhatsappFlows.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonProperty("button_text") + private String buttonText; + + @JsonProperty("subtitle") + private String subtitle; + + @JsonProperty("media_url") + private String mediaUrl; + + @JsonProperty("flow_id") + private String flowId; + + @JsonProperty("flow_token") + private String flowToken; + + @JsonProperty("flow_first_page_id") + private String flowFirstPageId; + + @JsonProperty("is_flow_first_page_endpoint") + private Boolean isFlowFirstPageEndpoint; + + @JsonCreator + public Builder( + @JsonProperty("body") final String body, + @JsonProperty("button_text") final String buttonText, + @JsonProperty("flow_id") final String flowId + ) { + this.body = body; + this.buttonText = buttonText; + this.flowId = flowId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + public Builder subtitle(String subtitle) { + this.subtitle = subtitle; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media_url") + public Builder mediaUrl(String mediaUrl) { + this.mediaUrl = mediaUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("flow_token") + public Builder flowToken(String flowToken) { + this.flowToken = flowToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("flow_first_page_id") + public Builder flowFirstPageId(String flowFirstPageId) { + this.flowFirstPageId = flowFirstPageId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("is_flow_first_page_endpoint") + public Builder isFlowFirstPageEndpoint( + Boolean isFlowFirstPageEndpoint + ) { + this.isFlowFirstPageEndpoint = isFlowFirstPageEndpoint; + return this; + } + + public WhatsappFlows build() { + return new WhatsappFlows(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + WhatsappFlows other = (WhatsappFlows) o; + return ( + Objects.equals(body, other.body) && + Objects.equals(buttonText, other.buttonText) && + Objects.equals(subtitle, other.subtitle) && + Objects.equals(mediaUrl, other.mediaUrl) && + Objects.equals(flowId, other.flowId) && + Objects.equals(flowToken, other.flowToken) && + Objects.equals(flowFirstPageId, other.flowFirstPageId) && + Objects.equals( + isFlowFirstPageEndpoint, + other.isFlowFirstPageEndpoint + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + body, + buttonText, + subtitle, + mediaUrl, + flowId, + flowToken, + flowFirstPageId, + isFlowFirstPageEndpoint + ); + } + } + + @JsonDeserialize(builder = TwilioListPicker.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioListPicker { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("button") + @Getter + private final String button; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("items") + @Getter + private final List items; + + private TwilioListPicker(Builder builder) { + this.body = builder.body; + this.button = builder.button; + this.items = builder.items; + } + + public static Builder builder( + final String body, + final String button, + final List items + ) { + return new Builder(body, button, items); + } + + public static TwilioListPicker fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioListPicker.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonProperty("button") + private String button; + + @JsonProperty("items") + private List items; + + @JsonCreator + public Builder( + @JsonProperty("body") final String body, + @JsonProperty("button") final String button, + @JsonProperty("items") final List items + ) { + this.body = body; + this.button = button; + this.items = items; + } + + public TwilioListPicker build() { + return new TwilioListPicker(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioListPicker other = (TwilioListPicker) o; + return ( + Objects.equals(body, other.body) && + Objects.equals(button, other.button) && + Objects.equals(items, other.items) + ); + } + + @Override + public int hashCode() { + return Objects.hash(body, button, items); + } + } + + @JsonDeserialize(builder = TwilioCatalog.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioCatalog { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + @Getter + private final String subtitle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("items") + @Getter + private final List items; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dynamic_items") + @Getter + private final String dynamicItems; + + private TwilioCatalog(Builder builder) { + this.title = builder.title; + this.body = builder.body; + this.subtitle = builder.subtitle; + this.id = builder.id; + this.items = builder.items; + this.dynamicItems = builder.dynamicItems; + } + + public static Builder builder(final String body) { + return new Builder(body); + } + + public static TwilioCatalog fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioCatalog.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("title") + private String title; + + @JsonProperty("body") + private String body; + + @JsonProperty("subtitle") + private String subtitle; + + @JsonProperty("id") + private String id; + + @JsonProperty("items") + private List items; + + @JsonProperty("dynamic_items") + private String dynamicItems; + + @JsonCreator + public Builder(@JsonProperty("body") final String body) { + this.body = body; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + public Builder title(String title) { + this.title = title; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("subtitle") + public Builder subtitle(String subtitle) { + this.subtitle = subtitle; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("items") + public Builder items(List items) { + this.items = items; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dynamic_items") + public Builder dynamicItems(String dynamicItems) { + this.dynamicItems = dynamicItems; + return this; + } + + public TwilioCatalog build() { + return new TwilioCatalog(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioCatalog other = (TwilioCatalog) o; + return ( + Objects.equals(title, other.title) && + Objects.equals(body, other.body) && + Objects.equals(subtitle, other.subtitle) && + Objects.equals(id, other.id) && + Objects.equals(items, other.items) && + Objects.equals(dynamicItems, other.dynamicItems) + ); + } + + @Override + public int hashCode() { + return Objects.hash(title, body, subtitle, id, items, dynamicItems); + } + } + + @JsonDeserialize(builder = TwilioText.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioText { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + private TwilioText(Builder builder) { + this.body = builder.body; + } + + public static Builder builder(final String body) { + return new Builder(body); + } + + public static TwilioText fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioText.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonCreator + public Builder(@JsonProperty("body") final String body) { + this.body = body; + } + + public TwilioText build() { + return new TwilioText(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioText other = (TwilioText) o; + return (Objects.equals(body, other.body)); + } + + @Override + public int hashCode() { + return Objects.hash(body); + } + } + + @JsonDeserialize(builder = CatalogItem.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CatalogItem { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("section_title") + @Getter + private final String sectionTitle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media_url") + @Getter + private final String mediaUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("price") + @Getter + private final BigDecimal price; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + private CatalogItem(Builder builder) { + this.id = builder.id; + this.sectionTitle = builder.sectionTitle; + this.name = builder.name; + this.mediaUrl = builder.mediaUrl; + this.price = builder.price; + this.description = builder.description; + } + + public static Builder builder() { + return new Builder(); + } + + public static CatalogItem fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CatalogItem.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("section_title") + private String sectionTitle; + + @JsonProperty("name") + private String name; + + @JsonProperty("media_url") + private String mediaUrl; + + @JsonProperty("price") + private BigDecimal price; + + @JsonProperty("description") + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("section_title") + public Builder sectionTitle(String sectionTitle) { + this.sectionTitle = sectionTitle; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media_url") + public Builder mediaUrl(String mediaUrl) { + this.mediaUrl = mediaUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("price") + public Builder price(BigDecimal price) { + this.price = price; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public CatalogItem build() { + return new CatalogItem(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CatalogItem other = (CatalogItem) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(sectionTitle, other.sectionTitle) && + Objects.equals(name, other.name) && + Objects.equals(mediaUrl, other.mediaUrl) && + Objects.equals(price, other.price) && + Objects.equals(description, other.description) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + sectionTitle, + name, + mediaUrl, + price, + description + ); + } + } + + @JsonDeserialize(builder = TwilioSchedule.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioSchedule { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_slots") + @Getter + private final String timeSlots; + + private TwilioSchedule(Builder builder) { + this.id = builder.id; + this.title = builder.title; + this.timeSlots = builder.timeSlots; + } + + public static Builder builder( + final String id, + final String title, + final String timeSlots + ) { + return new Builder(id, title, timeSlots); + } + + public static TwilioSchedule fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioSchedule.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("title") + private String title; + + @JsonProperty("time_slots") + private String timeSlots; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("title") final String title, + @JsonProperty("time_slots") final String timeSlots + ) { + this.id = id; + this.title = title; + this.timeSlots = timeSlots; + } + + public TwilioSchedule build() { + return new TwilioSchedule(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioSchedule other = (TwilioSchedule) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(title, other.title) && + Objects.equals(timeSlots, other.timeSlots) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, title, timeSlots); + } + } + + @JsonDeserialize(builder = TwilioCarousel.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioCarousel { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("cards") + @Getter + private final List cards; + + private TwilioCarousel(Builder builder) { + this.body = builder.body; + this.cards = builder.cards; + } + + public static Builder builder( + final String body, + final List cards + ) { + return new Builder(body, cards); + } + + public static TwilioCarousel fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioCarousel.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("body") + private String body; + + @JsonProperty("cards") + private List cards; + + @JsonCreator + public Builder( + @JsonProperty("body") final String body, + @JsonProperty("cards") final List cards + ) { + this.body = body; + this.cards = cards; + } + + public TwilioCarousel build() { + return new TwilioCarousel(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioCarousel other = (TwilioCarousel) o; + return ( + Objects.equals(body, other.body) && + Objects.equals(cards, other.cards) + ); + } + + @Override + public int hashCode() { + return Objects.hash(body, cards); + } + } + + @JsonDeserialize(builder = CardAction.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CardAction { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Content.CardActionType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final String url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone") + @Getter + private final String phone; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + @Getter + private final String code; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("webview_size") + @Getter + private final Content.WebviewSizeType webviewSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("digitable_line") + @Getter + private final String digitableLine; + + private CardAction(Builder builder) { + this.type = builder.type; + this.title = builder.title; + this.url = builder.url; + this.phone = builder.phone; + this.id = builder.id; + this.code = builder.code; + this.webviewSize = builder.webviewSize; + this.digitableLine = builder.digitableLine; + } + + public static Builder builder(final Content.CardActionType type) { + return new Builder(type); + } + + public static CardAction fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CardAction.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Content.CardActionType type; + + @JsonProperty("title") + private String title; + + @JsonProperty("url") + private String url; + + @JsonProperty("phone") + private String phone; + + @JsonProperty("id") + private String id; + + @JsonProperty("code") + private String code; + + @JsonProperty("webview_size") + private Content.WebviewSizeType webviewSize; + + @JsonProperty("digitable_line") + private String digitableLine; + + @JsonCreator + public Builder( + @JsonProperty("type") final Content.CardActionType type + ) { + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + public Builder title(String title) { + this.title = title; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + public Builder url(String url) { + this.url = url; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone") + public Builder phone(String phone) { + this.phone = phone; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + public Builder code(String code) { + this.code = code; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("webview_size") + public Builder webviewSize(Content.WebviewSizeType webviewSize) { + this.webviewSize = webviewSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("digitable_line") + public Builder digitableLine(String digitableLine) { + this.digitableLine = digitableLine; + return this; + } + + public CardAction build() { + return new CardAction(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CardAction other = (CardAction) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(title, other.title) && + Objects.equals(url, other.url) && + Objects.equals(phone, other.phone) && + Objects.equals(id, other.id) && + Objects.equals(code, other.code) && + Objects.equals(webviewSize, other.webviewSize) && + Objects.equals(digitableLine, other.digitableLine) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + type, + title, + url, + phone, + id, + code, + webviewSize, + digitableLine + ); + } + } + + @JsonDeserialize(builder = CarouselCard.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CarouselCard { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("body") + @Getter + private final String body; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("media") + @Getter + private final String media; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + private CarouselCard(Builder builder) { + this.title = builder.title; + this.body = builder.body; + this.media = builder.media; + this.actions = builder.actions; + } + + public static Builder builder( + final String body, + final String media, + final List actions + ) { + return new Builder(body, media, actions); + } + + public static CarouselCard fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CarouselCard.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("title") + private String title; + + @JsonProperty("body") + private String body; + + @JsonProperty("media") + private String media; + + @JsonProperty("actions") + private List actions; + + @JsonCreator + public Builder( + @JsonProperty("body") final String body, + @JsonProperty("media") final String media, + @JsonProperty("actions") final List actions + ) { + this.body = body; + this.media = media; + this.actions = actions; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + public Builder title(String title) { + this.title = title; + return this; + } + + public CarouselCard build() { + return new CarouselCard(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CarouselCard other = (CarouselCard) o; + return ( + Objects.equals(title, other.title) && + Objects.equals(body, other.body) && + Objects.equals(media, other.media) && + Objects.equals(actions, other.actions) + ); + } + + @Override + public int hashCode() { + return Objects.hash(title, body, media, actions); + } + } + + @JsonDeserialize(builder = TwilioLocation.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TwilioLocation { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("latitude") + @Getter + private final BigDecimal latitude; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("longitude") + @Getter + private final BigDecimal longitude; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + @Getter + private final String label; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + private TwilioLocation(Builder builder) { + this.latitude = builder.latitude; + this.longitude = builder.longitude; + this.label = builder.label; + this.id = builder.id; + this.address = builder.address; + } + + public static Builder builder( + final BigDecimal latitude, + final BigDecimal longitude + ) { + return new Builder(latitude, longitude); + } + + public static TwilioLocation fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TwilioLocation.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("latitude") + private BigDecimal latitude; + + @JsonProperty("longitude") + private BigDecimal longitude; + + @JsonProperty("label") + private String label; + + @JsonProperty("id") + private String id; + + @JsonProperty("address") + private String address; + + @JsonCreator + public Builder( + @JsonProperty("latitude") final BigDecimal latitude, + @JsonProperty("longitude") final BigDecimal longitude + ) { + this.latitude = latitude; + this.longitude = longitude; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + public Builder label(String label) { + this.label = label; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + public Builder address(String address) { + this.address = address; + return this; + } + + public TwilioLocation build() { + return new TwilioLocation(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TwilioLocation other = (TwilioLocation) o; + return ( + Objects.equals(latitude, other.latitude) && + Objects.equals(longitude, other.longitude) && + Objects.equals(label, other.label) && + Objects.equals(id, other.id) && + Objects.equals(address, other.address) + ); + } + + @Override + public int hashCode() { + return Objects.hash(latitude, longitude, label, id, address); + } + } + + @JsonDeserialize(builder = ListItem.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListItem { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("item") + @Getter + private final String item; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + private ListItem(Builder builder) { + this.id = builder.id; + this.item = builder.item; + this.description = builder.description; + } + + public static Builder builder(final String id, final String item) { + return new Builder(id, item); + } + + public static ListItem fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, ListItem.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("item") + private String item; + + @JsonProperty("description") + private String description; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("item") final String item + ) { + this.id = id; + this.item = item; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public ListItem build() { + return new ListItem(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListItem other = (ListItem) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(item, other.item) && + Objects.equals(description, other.description) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, item, description); + } + } + + /** + * Converts a JSON String into a Content object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Content object represented by the provided JSON + */ + public static Content fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Content.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Content object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Content object represented by the provided JSON + */ + public static Content fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Content.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String language; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final Object types; + + @Getter + private final URI url; + + @Getter + private final Object variables; + + @JsonCreator + private Content( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language") final String language, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("types") final Object types, + @JsonProperty("url") final URI url, + @JsonProperty("variables") final Object variables + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.language = language; + this.links = links; + this.sid = sid; + this.types = types; + this.url = url; + this.variables = variables; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Content other = (Content) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(language, other.language) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(types, other.types) && + Objects.equals(url, other.url) && + Objects.equals(variables, other.variables) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + language, + links, + sid, + types, + url, + variables + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/ContentAndApprovals.java b/src/main/java/com/twilio/rest/content/v1/ContentAndApprovals.java new file mode 100644 index 0000000000..038b93cef4 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/ContentAndApprovals.java @@ -0,0 +1,201 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ContentAndApprovals extends Resource { + + public static ContentAndApprovalsReader reader() { + return new ContentAndApprovalsReader(); + } + + /** + * Converts a JSON String into a ContentAndApprovals object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ContentAndApprovals object represented by the provided JSON + */ + public static ContentAndApprovals fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ContentAndApprovals.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ContentAndApprovals object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ContentAndApprovals object represented by the provided JSON + */ + public static ContentAndApprovals fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ContentAndApprovals.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object approvalRequests; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String language; + + @Getter + private final String sid; + + @Getter + private final Object types; + + @Getter + private final Object variables; + + @JsonCreator + private ContentAndApprovals( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("approval_requests") final Object approvalRequests, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language") final String language, + @JsonProperty("sid") final String sid, + @JsonProperty("types") final Object types, + @JsonProperty("variables") final Object variables + ) { + this.accountSid = accountSid; + this.approvalRequests = approvalRequests; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.language = language; + this.sid = sid; + this.types = types; + this.variables = variables; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContentAndApprovals other = (ContentAndApprovals) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(approvalRequests, other.approvalRequests) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(language, other.language) && + Objects.equals(sid, other.sid) && + Objects.equals(types, other.types) && + Objects.equals(variables, other.variables) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + approvalRequests, + dateCreated, + dateUpdated, + friendlyName, + language, + sid, + types, + variables + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/ContentAndApprovalsReader.java b/src/main/java/com/twilio/rest/content/v1/ContentAndApprovalsReader.java new file mode 100644 index 0000000000..af0fb33a14 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/ContentAndApprovalsReader.java @@ -0,0 +1,204 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ContentAndApprovalsReader extends Reader { + + private Integer pageSize; + + public ContentAndApprovalsReader() {} + + public ContentAndApprovalsReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + ContentAndApprovals.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/ContentAndApprovals"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONTENT.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + ContentAndApprovals.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ContentAndApprovals read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "contents", + response.getContent(), + ContentAndApprovals.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/ContentCreator.java b/src/main/java/com/twilio/rest/content/v1/ContentCreator.java new file mode 100644 index 0000000000..3d8412bb1c --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/ContentCreator.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ContentCreator extends Creator { + + private Content.ContentCreateRequest contentCreateRequest; + + public ContentCreator( + final Content.ContentCreateRequest contentCreateRequest + ) { + this.contentCreateRequest = contentCreateRequest; + } + + public ContentCreator setContentCreateRequest( + final Content.ContentCreateRequest contentCreateRequest + ) { + this.contentCreateRequest = contentCreateRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Content"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONTENT.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Content creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Content create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Content.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Content content = Content.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (contentCreateRequest != null) { + request.setBody(Content.toJson(contentCreateRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/ContentDeleter.java b/src/main/java/com/twilio/rest/content/v1/ContentDeleter.java new file mode 100644 index 0000000000..90adf05b8c --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/ContentDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ContentDeleter extends Deleter { + + private String pathSid; + + public ContentDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Content/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONTENT.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Content delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/ContentFetcher.java b/src/main/java/com/twilio/rest/content/v1/ContentFetcher.java new file mode 100644 index 0000000000..d709c8e205 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/ContentFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ContentFetcher extends Fetcher { + + private String pathSid; + + public ContentFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Content/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONTENT.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Content fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Content fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Content.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Content content = Content.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/ContentReader.java b/src/main/java/com/twilio/rest/content/v1/ContentReader.java new file mode 100644 index 0000000000..5b7bbac47b --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/ContentReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ContentReader extends Reader { + + private Integer pageSize; + + public ContentReader() {} + + public ContentReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + Content.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Content"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONTENT.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + Content.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Content read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "contents", + response.getContent(), + Content.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/ContentUpdater.java b/src/main/java/com/twilio/rest/content/v1/ContentUpdater.java new file mode 100644 index 0000000000..9002e84580 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/ContentUpdater.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ContentUpdater extends Updater { + + private String pathSid; + private Content.ContentUpdateRequest contentUpdateRequest; + + public ContentUpdater( + final String pathSid, + final Content.ContentUpdateRequest contentUpdateRequest + ) { + this.pathSid = pathSid; + this.contentUpdateRequest = contentUpdateRequest; + } + + public ContentUpdater setContentUpdateRequest( + final Content.ContentUpdateRequest contentUpdateRequest + ) { + this.contentUpdateRequest = contentUpdateRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Content/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.CONTENT.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Content update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Content update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Content.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Content content = Content.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (contentUpdateRequest != null) { + request.setBody(Content.toJson(contentUpdateRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/LegacyContent.java b/src/main/java/com/twilio/rest/content/v1/LegacyContent.java new file mode 100644 index 0000000000..ff928b004e --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/LegacyContent.java @@ -0,0 +1,216 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class LegacyContent extends Resource { + + public static LegacyContentReader reader() { + return new LegacyContentReader(); + } + + /** + * Converts a JSON String into a LegacyContent object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return LegacyContent object represented by the provided JSON + */ + public static LegacyContent fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, LegacyContent.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a LegacyContent object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return LegacyContent object represented by the provided JSON + */ + public static LegacyContent fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, LegacyContent.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String language; + + @Getter + private final String legacyBody; + + @Getter + private final String legacyTemplateName; + + @Getter + private final String sid; + + @Getter + private final Object types; + + @Getter + private final URI url; + + @Getter + private final Object variables; + + @JsonCreator + private LegacyContent( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language") final String language, + @JsonProperty("legacy_body") final String legacyBody, + @JsonProperty("legacy_template_name") final String legacyTemplateName, + @JsonProperty("sid") final String sid, + @JsonProperty("types") final Object types, + @JsonProperty("url") final URI url, + @JsonProperty("variables") final Object variables + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.language = language; + this.legacyBody = legacyBody; + this.legacyTemplateName = legacyTemplateName; + this.sid = sid; + this.types = types; + this.url = url; + this.variables = variables; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LegacyContent other = (LegacyContent) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(language, other.language) && + Objects.equals(legacyBody, other.legacyBody) && + Objects.equals(legacyTemplateName, other.legacyTemplateName) && + Objects.equals(sid, other.sid) && + Objects.equals(types, other.types) && + Objects.equals(url, other.url) && + Objects.equals(variables, other.variables) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + language, + legacyBody, + legacyTemplateName, + sid, + types, + url, + variables + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/LegacyContentReader.java b/src/main/java/com/twilio/rest/content/v1/LegacyContentReader.java new file mode 100644 index 0000000000..66154ee57a --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/LegacyContentReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class LegacyContentReader extends Reader { + + private Integer pageSize; + + public LegacyContentReader() {} + + public LegacyContentReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + LegacyContent.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/LegacyContent"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONTENT.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + LegacyContent.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "LegacyContent read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "contents", + response.getContent(), + LegacyContent.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreate.java b/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreate.java new file mode 100644 index 0000000000..b218d5cc93 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreate.java @@ -0,0 +1,388 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1.content; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ApprovalCreate extends Resource { + + public static ApprovalCreateCreator creator( + final String pathContentSid, + final ApprovalCreate.ContentApprovalRequest contentApprovalRequest + ) { + return new ApprovalCreateCreator( + pathContentSid, + contentApprovalRequest + ); + } + + public static ApprovalCreateUpdater updater( + final String pathContentSid, + final ApprovalCreate.ContentApprovalUpdateRequest contentApprovalUpdateRequest + ) { + return new ApprovalCreateUpdater( + pathContentSid, + contentApprovalUpdateRequest + ); + } + + @JsonDeserialize(builder = ContentApprovalRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ContentApprovalRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("category") + @Getter + private final String category; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("send_ttl_seconds") + @Getter + private final Integer sendTtlSeconds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bid_amount") + @Getter + private final Integer bidAmount; + + private ContentApprovalRequest(Builder builder) { + this.name = builder.name; + this.category = builder.category; + this.sendTtlSeconds = builder.sendTtlSeconds; + this.bidAmount = builder.bidAmount; + } + + public static Builder builder( + final String name, + final String category + ) { + return new Builder(name, category); + } + + public static ContentApprovalRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ContentApprovalRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("category") + private String category; + + @JsonProperty("send_ttl_seconds") + private Integer sendTtlSeconds; + + @JsonProperty("bid_amount") + private Integer bidAmount; + + @JsonCreator + public Builder( + @JsonProperty("name") final String name, + @JsonProperty("category") final String category + ) { + this.name = name; + this.category = category; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("send_ttl_seconds") + public Builder sendTtlSeconds(Integer sendTtlSeconds) { + this.sendTtlSeconds = sendTtlSeconds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bid_amount") + public Builder bidAmount(Integer bidAmount) { + this.bidAmount = bidAmount; + return this; + } + + public ContentApprovalRequest build() { + return new ContentApprovalRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContentApprovalRequest other = (ContentApprovalRequest) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(category, other.category) && + Objects.equals(sendTtlSeconds, other.sendTtlSeconds) && + Objects.equals(bidAmount, other.bidAmount) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, category, sendTtlSeconds, bidAmount); + } + } + + @JsonDeserialize(builder = ContentApprovalUpdateRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ContentApprovalUpdateRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bid_amount") + @Getter + private final Integer bidAmount; + + private ContentApprovalUpdateRequest(Builder builder) { + this.bidAmount = builder.bidAmount; + } + + public static Builder builder(final Integer bidAmount) { + return new Builder(bidAmount); + } + + public static ContentApprovalUpdateRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ContentApprovalUpdateRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("bid_amount") + private Integer bidAmount; + + @JsonCreator + public Builder( + @JsonProperty("bid_amount") final Integer bidAmount + ) { + this.bidAmount = bidAmount; + } + + public ContentApprovalUpdateRequest build() { + return new ContentApprovalUpdateRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContentApprovalUpdateRequest other = + (ContentApprovalUpdateRequest) o; + return (Objects.equals(bidAmount, other.bidAmount)); + } + + @Override + public int hashCode() { + return Objects.hash(bidAmount); + } + } + + /** + * Converts a JSON String into a ApprovalCreate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ApprovalCreate object represented by the provided JSON + */ + public static ApprovalCreate fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ApprovalCreate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ApprovalCreate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ApprovalCreate object represented by the provided JSON + */ + public static ApprovalCreate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ApprovalCreate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean allowCategoryChange; + + @Getter + private final Integer bidAmount; + + @Getter + private final String category; + + @Getter + private final String contentType; + + @Getter + private final String name; + + @Getter + private final String rejectionReason; + + @Getter + private final Integer sendTtlSeconds; + + @Getter + private final String status; + + @JsonCreator + private ApprovalCreate( + @JsonProperty( + "allow_category_change" + ) final Boolean allowCategoryChange, + @JsonProperty("bid_amount") final Integer bidAmount, + @JsonProperty("category") final String category, + @JsonProperty("content_type") final String contentType, + @JsonProperty("name") final String name, + @JsonProperty("rejection_reason") final String rejectionReason, + @JsonProperty("send_ttl_seconds") final Integer sendTtlSeconds, + @JsonProperty("status") final String status + ) { + this.allowCategoryChange = allowCategoryChange; + this.bidAmount = bidAmount; + this.category = category; + this.contentType = contentType; + this.name = name; + this.rejectionReason = rejectionReason; + this.sendTtlSeconds = sendTtlSeconds; + this.status = status; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ApprovalCreate other = (ApprovalCreate) o; + return ( + Objects.equals(allowCategoryChange, other.allowCategoryChange) && + Objects.equals(bidAmount, other.bidAmount) && + Objects.equals(category, other.category) && + Objects.equals(contentType, other.contentType) && + Objects.equals(name, other.name) && + Objects.equals(rejectionReason, other.rejectionReason) && + Objects.equals(sendTtlSeconds, other.sendTtlSeconds) && + Objects.equals(status, other.status) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + allowCategoryChange, + bidAmount, + category, + contentType, + name, + rejectionReason, + sendTtlSeconds, + status + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreateCreator.java b/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreateCreator.java new file mode 100644 index 0000000000..0b2d23221b --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreateCreator.java @@ -0,0 +1,125 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1.content; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ApprovalCreateCreator extends Creator { + + private String pathContentSid; + private ApprovalCreate.ContentApprovalRequest contentApprovalRequest; + + public ApprovalCreateCreator( + final String pathContentSid, + final ApprovalCreate.ContentApprovalRequest contentApprovalRequest + ) { + this.pathContentSid = pathContentSid; + this.contentApprovalRequest = contentApprovalRequest; + } + + public ApprovalCreateCreator setContentApprovalRequest( + final ApprovalCreate.ContentApprovalRequest contentApprovalRequest + ) { + this.contentApprovalRequest = contentApprovalRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Content/{ContentSid}/ApprovalRequests/whatsapp"; + + path = + path.replace( + "{" + "ContentSid" + "}", + this.pathContentSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONTENT.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ApprovalCreate creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ApprovalCreate create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ApprovalCreate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ApprovalCreate content = ApprovalCreate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (contentApprovalRequest != null) { + request.setBody( + ApprovalCreate.toJson(contentApprovalRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreateUpdater.java b/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreateUpdater.java new file mode 100644 index 0000000000..3299efdad2 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/content/ApprovalCreateUpdater.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1.content; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ApprovalCreateUpdater extends Updater { + + private String pathContentSid; + private ApprovalCreate.ContentApprovalUpdateRequest contentApprovalUpdateRequest; + + public ApprovalCreateUpdater( + final String pathContentSid, + final ApprovalCreate.ContentApprovalUpdateRequest contentApprovalUpdateRequest + ) { + this.pathContentSid = pathContentSid; + this.contentApprovalUpdateRequest = contentApprovalUpdateRequest; + } + + public ApprovalCreateUpdater setContentApprovalUpdateRequest( + final ApprovalCreate.ContentApprovalUpdateRequest contentApprovalUpdateRequest + ) { + this.contentApprovalUpdateRequest = contentApprovalUpdateRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Content/{ContentSid}/ApprovalRequests/whatsapp"; + + path = + path.replace( + "{" + "ContentSid" + "}", + this.pathContentSid.toString() + ); + + Request request = new Request( + HttpMethod.PATCH, + Domains.CONTENT.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ApprovalCreate update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ApprovalCreate update(final TwilioRestClient client) { + Response response = makeRequest(client); + return ApprovalCreate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ApprovalCreate content = ApprovalCreate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (contentApprovalUpdateRequest != null) { + request.setBody( + ApprovalCreate.toJson( + contentApprovalUpdateRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetch.java b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetch.java new file mode 100644 index 0000000000..fba69a7e5d --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetch.java @@ -0,0 +1,149 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1.content; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ApprovalFetch extends Resource { + + public static ApprovalFetchFetcher fetcher(final String pathSid) { + return new ApprovalFetchFetcher(pathSid); + } + + /** + * Converts a JSON String into a ApprovalFetch object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ApprovalFetch object represented by the provided JSON + */ + public static ApprovalFetch fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ApprovalFetch.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ApprovalFetch object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ApprovalFetch object represented by the provided JSON + */ + public static ApprovalFetch fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ApprovalFetch.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final Object whatsapp; + + @JsonCreator + private ApprovalFetch( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("whatsapp") final Object whatsapp + ) { + this.accountSid = accountSid; + this.sid = sid; + this.url = url; + this.whatsapp = whatsapp; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ApprovalFetch other = (ApprovalFetch) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(whatsapp, other.whatsapp) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, sid, url, whatsapp); + } +} diff --git a/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetchFetcher.java b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetchFetcher.java new file mode 100644 index 0000000000..146be94365 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v1/content/ApprovalFetchFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v1.content; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ApprovalFetchFetcher extends Fetcher { + + private String pathSid; + + public ApprovalFetchFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Content/{Sid}/ApprovalRequests"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONTENT.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ApprovalFetch fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ApprovalFetch fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ApprovalFetch.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ApprovalFetch content = ApprovalFetch.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v2/Content.java b/src/main/java/com/twilio/rest/content/v2/Content.java new file mode 100644 index 0000000000..5e184b2649 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v2/Content.java @@ -0,0 +1,210 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Content extends Resource { + + public static ContentReader reader() { + return new ContentReader(); + } + + /** + * Converts a JSON String into a Content object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Content object represented by the provided JSON + */ + public static Content fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Content.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Content object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Content object represented by the provided JSON + */ + public static Content fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Content.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String language; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final Object types; + + @Getter + private final URI url; + + @Getter + private final Object variables; + + @JsonCreator + private Content( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language") final String language, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("types") final Object types, + @JsonProperty("url") final URI url, + @JsonProperty("variables") final Object variables + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.language = language; + this.links = links; + this.sid = sid; + this.types = types; + this.url = url; + this.variables = variables; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Content other = (Content) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(language, other.language) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(types, other.types) && + Objects.equals(url, other.url) && + Objects.equals(variables, other.variables) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + language, + links, + sid, + types, + url, + variables + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v2/ContentAndApprovals.java b/src/main/java/com/twilio/rest/content/v2/ContentAndApprovals.java new file mode 100644 index 0000000000..9398b3b8c1 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v2/ContentAndApprovals.java @@ -0,0 +1,201 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ContentAndApprovals extends Resource { + + public static ContentAndApprovalsReader reader() { + return new ContentAndApprovalsReader(); + } + + /** + * Converts a JSON String into a ContentAndApprovals object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ContentAndApprovals object represented by the provided JSON + */ + public static ContentAndApprovals fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ContentAndApprovals.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ContentAndApprovals object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ContentAndApprovals object represented by the provided JSON + */ + public static ContentAndApprovals fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ContentAndApprovals.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object approvalRequests; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String language; + + @Getter + private final String sid; + + @Getter + private final Object types; + + @Getter + private final Object variables; + + @JsonCreator + private ContentAndApprovals( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("approval_requests") final Object approvalRequests, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language") final String language, + @JsonProperty("sid") final String sid, + @JsonProperty("types") final Object types, + @JsonProperty("variables") final Object variables + ) { + this.accountSid = accountSid; + this.approvalRequests = approvalRequests; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.language = language; + this.sid = sid; + this.types = types; + this.variables = variables; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContentAndApprovals other = (ContentAndApprovals) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(approvalRequests, other.approvalRequests) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(language, other.language) && + Objects.equals(sid, other.sid) && + Objects.equals(types, other.types) && + Objects.equals(variables, other.variables) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + approvalRequests, + dateCreated, + dateUpdated, + friendlyName, + language, + sid, + types, + variables + ); + } +} diff --git a/src/main/java/com/twilio/rest/content/v2/ContentAndApprovalsReader.java b/src/main/java/com/twilio/rest/content/v2/ContentAndApprovalsReader.java new file mode 100644 index 0000000000..0d49a5c09f --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v2/ContentAndApprovalsReader.java @@ -0,0 +1,372 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; + +public class ContentAndApprovalsReader extends Reader { + + private Integer pageSize; + private String sortByDate; + private String sortByContentName; + private ZonedDateTime dateCreatedAfter; + private ZonedDateTime dateCreatedBefore; + private String contentName; + private String content; + private List language; + private List contentType; + private List channelEligibility; + + public ContentAndApprovalsReader() {} + + public ContentAndApprovalsReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ContentAndApprovalsReader setSortByDate(final String sortByDate) { + this.sortByDate = sortByDate; + return this; + } + + public ContentAndApprovalsReader setSortByContentName( + final String sortByContentName + ) { + this.sortByContentName = sortByContentName; + return this; + } + + public ContentAndApprovalsReader setDateCreatedAfter( + final ZonedDateTime dateCreatedAfter + ) { + this.dateCreatedAfter = dateCreatedAfter; + return this; + } + + public ContentAndApprovalsReader setDateCreatedBefore( + final ZonedDateTime dateCreatedBefore + ) { + this.dateCreatedBefore = dateCreatedBefore; + return this; + } + + public ContentAndApprovalsReader setContentName(final String contentName) { + this.contentName = contentName; + return this; + } + + public ContentAndApprovalsReader setContent(final String content) { + this.content = content; + return this; + } + + public ContentAndApprovalsReader setLanguage(final List language) { + this.language = language; + return this; + } + + public ContentAndApprovalsReader setLanguage(final String language) { + return setLanguage(Promoter.listOfOne(language)); + } + + public ContentAndApprovalsReader setContentType( + final List contentType + ) { + this.contentType = contentType; + return this; + } + + public ContentAndApprovalsReader setContentType(final String contentType) { + return setContentType(Promoter.listOfOne(contentType)); + } + + public ContentAndApprovalsReader setChannelEligibility( + final List channelEligibility + ) { + this.channelEligibility = channelEligibility; + return this; + } + + public ContentAndApprovalsReader setChannelEligibility( + final String channelEligibility + ) { + return setChannelEligibility(Promoter.listOfOne(channelEligibility)); + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + ContentAndApprovals.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/ContentAndApprovals"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONTENT.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + ContentAndApprovals.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ContentAndApprovals read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "contents", + response.getContent(), + ContentAndApprovals.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (sortByDate != null) { + Serializer.toString( + request, + "SortByDate", + sortByDate, + ParameterType.QUERY + ); + } + + if (sortByContentName != null) { + Serializer.toString( + request, + "SortByContentName", + sortByContentName, + ParameterType.QUERY + ); + } + + if (dateCreatedAfter != null) { + Serializer.toString( + request, + "DateCreatedAfter", + dateCreatedAfter, + ParameterType.QUERY + ); + } + + if (dateCreatedBefore != null) { + Serializer.toString( + request, + "DateCreatedBefore", + dateCreatedBefore, + ParameterType.QUERY + ); + } + + if (contentName != null) { + Serializer.toString( + request, + "ContentName", + contentName, + ParameterType.QUERY + ); + } + + if (content != null) { + Serializer.toString( + request, + "Content", + content, + ParameterType.QUERY + ); + } + + if (language != null) { + for (String param : language) { + Serializer.toString( + request, + "Language", + param, + ParameterType.QUERY + ); + } + } + + if (contentType != null) { + for (String param : contentType) { + Serializer.toString( + request, + "ContentType", + param, + ParameterType.QUERY + ); + } + } + + if (channelEligibility != null) { + for (String param : channelEligibility) { + Serializer.toString( + request, + "ChannelEligibility", + param, + ParameterType.QUERY + ); + } + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/content/v2/ContentReader.java b/src/main/java/com/twilio/rest/content/v2/ContentReader.java new file mode 100644 index 0000000000..d109fdeb92 --- /dev/null +++ b/src/main/java/com/twilio/rest/content/v2/ContentReader.java @@ -0,0 +1,366 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Content + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.content.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; + +public class ContentReader extends Reader { + + private Integer pageSize; + private String sortByDate; + private String sortByContentName; + private ZonedDateTime dateCreatedAfter; + private ZonedDateTime dateCreatedBefore; + private String contentName; + private String content; + private List language; + private List contentType; + private List channelEligibility; + + public ContentReader() {} + + public ContentReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ContentReader setSortByDate(final String sortByDate) { + this.sortByDate = sortByDate; + return this; + } + + public ContentReader setSortByContentName(final String sortByContentName) { + this.sortByContentName = sortByContentName; + return this; + } + + public ContentReader setDateCreatedAfter( + final ZonedDateTime dateCreatedAfter + ) { + this.dateCreatedAfter = dateCreatedAfter; + return this; + } + + public ContentReader setDateCreatedBefore( + final ZonedDateTime dateCreatedBefore + ) { + this.dateCreatedBefore = dateCreatedBefore; + return this; + } + + public ContentReader setContentName(final String contentName) { + this.contentName = contentName; + return this; + } + + public ContentReader setContent(final String content) { + this.content = content; + return this; + } + + public ContentReader setLanguage(final List language) { + this.language = language; + return this; + } + + public ContentReader setLanguage(final String language) { + return setLanguage(Promoter.listOfOne(language)); + } + + public ContentReader setContentType(final List contentType) { + this.contentType = contentType; + return this; + } + + public ContentReader setContentType(final String contentType) { + return setContentType(Promoter.listOfOne(contentType)); + } + + public ContentReader setChannelEligibility( + final List channelEligibility + ) { + this.channelEligibility = channelEligibility; + return this; + } + + public ContentReader setChannelEligibility( + final String channelEligibility + ) { + return setChannelEligibility(Promoter.listOfOne(channelEligibility)); + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + Content.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Content"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONTENT.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "contents", + response.getContent(), + Content.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Content read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "contents", + response.getContent(), + Content.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (sortByDate != null) { + Serializer.toString( + request, + "SortByDate", + sortByDate, + ParameterType.QUERY + ); + } + + if (sortByContentName != null) { + Serializer.toString( + request, + "SortByContentName", + sortByContentName, + ParameterType.QUERY + ); + } + + if (dateCreatedAfter != null) { + Serializer.toString( + request, + "DateCreatedAfter", + dateCreatedAfter, + ParameterType.QUERY + ); + } + + if (dateCreatedBefore != null) { + Serializer.toString( + request, + "DateCreatedBefore", + dateCreatedBefore, + ParameterType.QUERY + ); + } + + if (contentName != null) { + Serializer.toString( + request, + "ContentName", + contentName, + ParameterType.QUERY + ); + } + + if (content != null) { + Serializer.toString( + request, + "Content", + content, + ParameterType.QUERY + ); + } + + if (language != null) { + for (String param : language) { + Serializer.toString( + request, + "Language", + param, + ParameterType.QUERY + ); + } + } + + if (contentType != null) { + for (String param : contentType) { + Serializer.toString( + request, + "ContentType", + param, + ParameterType.QUERY + ); + } + } + + if (channelEligibility != null) { + for (String param : channelEligibility) { + Serializer.toString( + request, + "ChannelEligibility", + param, + ParameterType.QUERY + ); + } + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfiguration.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfiguration.java new file mode 100644 index 0000000000..e5f1e7027a --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfiguration.java @@ -0,0 +1,300 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AddressConfiguration extends Resource { + + public static AddressConfigurationCreator creator( + final AddressConfiguration.Type type, + final String address + ) { + return new AddressConfigurationCreator(type, address); + } + + public static AddressConfigurationDeleter deleter(final String pathSid) { + return new AddressConfigurationDeleter(pathSid); + } + + public static AddressConfigurationFetcher fetcher(final String pathSid) { + return new AddressConfigurationFetcher(pathSid); + } + + public static AddressConfigurationReader reader() { + return new AddressConfigurationReader(); + } + + public static AddressConfigurationUpdater updater(final String pathSid) { + return new AddressConfigurationUpdater(pathSid); + } + + public enum Type { + SMS("sms"), + WHATSAPP("whatsapp"), + MESSENGER("messenger"), + GBM("gbm"), + EMAIL("email"), + RCS("rcs"), + APPLE("apple"), + CHAT("chat"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum Method { + GET("get"), + POST("post"); + + private final String value; + + private Method(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Method forValue(final String value) { + return Promoter.enumFromString(value, Method.values()); + } + } + + public enum AutoCreationType { + WEBHOOK("webhook"), + STUDIO("studio"), + DEFAULT("default"); + + private final String value; + + private AutoCreationType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static AutoCreationType forValue(final String value) { + return Promoter.enumFromString(value, AutoCreationType.values()); + } + } + + /** + * Converts a JSON String into a AddressConfiguration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AddressConfiguration object represented by the provided JSON + */ + public static AddressConfiguration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AddressConfiguration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AddressConfiguration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AddressConfiguration object represented by the provided JSON + */ + public static AddressConfiguration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AddressConfiguration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String address; + + @Getter + private final String addressCountry; + + @Getter + private final Object autoCreation; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @Getter + private final String type; + + @Getter + private final URI url; + + @JsonCreator + private AddressConfiguration( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address") final String address, + @JsonProperty("address_country") final String addressCountry, + @JsonProperty("auto_creation") final Object autoCreation, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.address = address; + this.addressCountry = addressCountry; + this.autoCreation = autoCreation; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AddressConfiguration other = (AddressConfiguration) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(address, other.address) && + Objects.equals(addressCountry, other.addressCountry) && + Objects.equals(autoCreation, other.autoCreation) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + address, + addressCountry, + autoCreation, + dateCreated, + dateUpdated, + friendlyName, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationCreator.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationCreator.java new file mode 100644 index 0000000000..6054074b39 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationCreator.java @@ -0,0 +1,319 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class AddressConfigurationCreator extends Creator { + + private AddressConfiguration.Type type; + private String address; + private String friendlyName; + private Boolean autoCreationEnabled; + private AddressConfiguration.AutoCreationType autoCreationType; + private String autoCreationConversationServiceSid; + private String autoCreationWebhookUrl; + private AddressConfiguration.Method autoCreationWebhookMethod; + private List autoCreationWebhookFilters; + private String autoCreationStudioFlowSid; + private Integer autoCreationStudioRetryCount; + private String addressCountry; + + public AddressConfigurationCreator( + final AddressConfiguration.Type type, + final String address + ) { + this.type = type; + this.address = address; + } + + public AddressConfigurationCreator setType( + final AddressConfiguration.Type type + ) { + this.type = type; + return this; + } + + public AddressConfigurationCreator setAddress(final String address) { + this.address = address; + return this; + } + + public AddressConfigurationCreator setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public AddressConfigurationCreator setAutoCreationEnabled( + final Boolean autoCreationEnabled + ) { + this.autoCreationEnabled = autoCreationEnabled; + return this; + } + + public AddressConfigurationCreator setAutoCreationType( + final AddressConfiguration.AutoCreationType autoCreationType + ) { + this.autoCreationType = autoCreationType; + return this; + } + + public AddressConfigurationCreator setAutoCreationConversationServiceSid( + final String autoCreationConversationServiceSid + ) { + this.autoCreationConversationServiceSid = + autoCreationConversationServiceSid; + return this; + } + + public AddressConfigurationCreator setAutoCreationWebhookUrl( + final String autoCreationWebhookUrl + ) { + this.autoCreationWebhookUrl = autoCreationWebhookUrl; + return this; + } + + public AddressConfigurationCreator setAutoCreationWebhookMethod( + final AddressConfiguration.Method autoCreationWebhookMethod + ) { + this.autoCreationWebhookMethod = autoCreationWebhookMethod; + return this; + } + + public AddressConfigurationCreator setAutoCreationWebhookFilters( + final List autoCreationWebhookFilters + ) { + this.autoCreationWebhookFilters = autoCreationWebhookFilters; + return this; + } + + public AddressConfigurationCreator setAutoCreationWebhookFilters( + final String autoCreationWebhookFilters + ) { + return setAutoCreationWebhookFilters( + Promoter.listOfOne(autoCreationWebhookFilters) + ); + } + + public AddressConfigurationCreator setAutoCreationStudioFlowSid( + final String autoCreationStudioFlowSid + ) { + this.autoCreationStudioFlowSid = autoCreationStudioFlowSid; + return this; + } + + public AddressConfigurationCreator setAutoCreationStudioRetryCount( + final Integer autoCreationStudioRetryCount + ) { + this.autoCreationStudioRetryCount = autoCreationStudioRetryCount; + return this; + } + + public AddressConfigurationCreator setAddressCountry( + final String addressCountry + ) { + this.addressCountry = addressCountry; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration/Addresses"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AddressConfiguration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AddressConfiguration create(final TwilioRestClient client) { + Response response = makeRequest(client); + return AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AddressConfiguration content = AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (address != null) { + Serializer.toString( + request, + "Address", + address, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (autoCreationEnabled != null) { + Serializer.toString( + request, + "AutoCreation.Enabled", + autoCreationEnabled, + ParameterType.URLENCODED + ); + } + + if (autoCreationType != null) { + Serializer.toString( + request, + "AutoCreation.Type", + autoCreationType, + ParameterType.URLENCODED + ); + } + + if (autoCreationConversationServiceSid != null) { + Serializer.toString( + request, + "AutoCreation.ConversationServiceSid", + autoCreationConversationServiceSid, + ParameterType.URLENCODED + ); + } + + if (autoCreationWebhookUrl != null) { + Serializer.toString( + request, + "AutoCreation.WebhookUrl", + autoCreationWebhookUrl, + ParameterType.URLENCODED + ); + } + + if (autoCreationWebhookMethod != null) { + Serializer.toString( + request, + "AutoCreation.WebhookMethod", + autoCreationWebhookMethod, + ParameterType.URLENCODED + ); + } + + if (autoCreationWebhookFilters != null) { + for (String param : autoCreationWebhookFilters) { + Serializer.toString( + request, + "AutoCreation.WebhookFilters", + param, + ParameterType.URLENCODED + ); + } + } + + if (autoCreationStudioFlowSid != null) { + Serializer.toString( + request, + "AutoCreation.StudioFlowSid", + autoCreationStudioFlowSid, + ParameterType.URLENCODED + ); + } + + if (autoCreationStudioRetryCount != null) { + Serializer.toString( + request, + "AutoCreation.StudioRetryCount", + autoCreationStudioRetryCount, + ParameterType.URLENCODED + ); + } + + if (addressCountry != null) { + Serializer.toString( + request, + "AddressCountry", + addressCountry, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationDeleter.java new file mode 100644 index 0000000000..dd424ecd2f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class AddressConfigurationDeleter extends Deleter { + + private String pathSid; + + public AddressConfigurationDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration/Addresses/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AddressConfiguration delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationFetcher.java new file mode 100644 index 0000000000..1c3661d7da --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AddressConfigurationFetcher extends Fetcher { + + private String pathSid; + + public AddressConfigurationFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration/Addresses/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AddressConfiguration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AddressConfiguration fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AddressConfiguration content = AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationReader.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationReader.java new file mode 100644 index 0000000000..186308a0f7 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationReader.java @@ -0,0 +1,214 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AddressConfigurationReader extends Reader { + + private String type; + private Long pageSize; + + public AddressConfigurationReader() {} + + public AddressConfigurationReader setType(final String type) { + this.type = type; + return this; + } + + public AddressConfigurationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "address_configurations", + response.getContent(), + AddressConfiguration.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Configuration/Addresses"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "address_configurations", + response.getContent(), + AddressConfiguration.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AddressConfiguration read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "address_configurations", + response.getContent(), + AddressConfiguration.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (type != null) { + Serializer.toString(request, "Type", type, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationUpdater.java new file mode 100644 index 0000000000..7920b471f5 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/AddressConfigurationUpdater.java @@ -0,0 +1,269 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class AddressConfigurationUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private Boolean autoCreationEnabled; + private AddressConfiguration.AutoCreationType autoCreationType; + private String autoCreationConversationServiceSid; + private String autoCreationWebhookUrl; + private AddressConfiguration.Method autoCreationWebhookMethod; + private List autoCreationWebhookFilters; + private String autoCreationStudioFlowSid; + private Integer autoCreationStudioRetryCount; + + public AddressConfigurationUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public AddressConfigurationUpdater setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public AddressConfigurationUpdater setAutoCreationEnabled( + final Boolean autoCreationEnabled + ) { + this.autoCreationEnabled = autoCreationEnabled; + return this; + } + + public AddressConfigurationUpdater setAutoCreationType( + final AddressConfiguration.AutoCreationType autoCreationType + ) { + this.autoCreationType = autoCreationType; + return this; + } + + public AddressConfigurationUpdater setAutoCreationConversationServiceSid( + final String autoCreationConversationServiceSid + ) { + this.autoCreationConversationServiceSid = + autoCreationConversationServiceSid; + return this; + } + + public AddressConfigurationUpdater setAutoCreationWebhookUrl( + final String autoCreationWebhookUrl + ) { + this.autoCreationWebhookUrl = autoCreationWebhookUrl; + return this; + } + + public AddressConfigurationUpdater setAutoCreationWebhookMethod( + final AddressConfiguration.Method autoCreationWebhookMethod + ) { + this.autoCreationWebhookMethod = autoCreationWebhookMethod; + return this; + } + + public AddressConfigurationUpdater setAutoCreationWebhookFilters( + final List autoCreationWebhookFilters + ) { + this.autoCreationWebhookFilters = autoCreationWebhookFilters; + return this; + } + + public AddressConfigurationUpdater setAutoCreationWebhookFilters( + final String autoCreationWebhookFilters + ) { + return setAutoCreationWebhookFilters( + Promoter.listOfOne(autoCreationWebhookFilters) + ); + } + + public AddressConfigurationUpdater setAutoCreationStudioFlowSid( + final String autoCreationStudioFlowSid + ) { + this.autoCreationStudioFlowSid = autoCreationStudioFlowSid; + return this; + } + + public AddressConfigurationUpdater setAutoCreationStudioRetryCount( + final Integer autoCreationStudioRetryCount + ) { + this.autoCreationStudioRetryCount = autoCreationStudioRetryCount; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration/Addresses/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AddressConfiguration update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AddressConfiguration update(final TwilioRestClient client) { + Response response = makeRequest(client); + return AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AddressConfiguration content = AddressConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (autoCreationEnabled != null) { + Serializer.toString( + request, + "AutoCreation.Enabled", + autoCreationEnabled, + ParameterType.URLENCODED + ); + } + + if (autoCreationType != null) { + Serializer.toString( + request, + "AutoCreation.Type", + autoCreationType, + ParameterType.URLENCODED + ); + } + + if (autoCreationConversationServiceSid != null) { + Serializer.toString( + request, + "AutoCreation.ConversationServiceSid", + autoCreationConversationServiceSid, + ParameterType.URLENCODED + ); + } + + if (autoCreationWebhookUrl != null) { + Serializer.toString( + request, + "AutoCreation.WebhookUrl", + autoCreationWebhookUrl, + ParameterType.URLENCODED + ); + } + + if (autoCreationWebhookMethod != null) { + Serializer.toString( + request, + "AutoCreation.WebhookMethod", + autoCreationWebhookMethod, + ParameterType.URLENCODED + ); + } + + if (autoCreationWebhookFilters != null) { + for (String param : autoCreationWebhookFilters) { + Serializer.toString( + request, + "AutoCreation.WebhookFilters", + param, + ParameterType.URLENCODED + ); + } + } + + if (autoCreationStudioFlowSid != null) { + Serializer.toString( + request, + "AutoCreation.StudioFlowSid", + autoCreationStudioFlowSid, + ParameterType.URLENCODED + ); + } + + if (autoCreationStudioRetryCount != null) { + Serializer.toString( + request, + "AutoCreation.StudioRetryCount", + autoCreationStudioRetryCount, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/Configuration.java b/src/main/java/com/twilio/rest/conversations/v1/Configuration.java new file mode 100644 index 0000000000..40ae50e372 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/Configuration.java @@ -0,0 +1,192 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Configuration extends Resource { + + public static ConfigurationFetcher fetcher() { + return new ConfigurationFetcher(); + } + + public static ConfigurationUpdater updater() { + return new ConfigurationUpdater(); + } + + /** + * Converts a JSON String into a Configuration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Configuration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String defaultChatServiceSid; + + @Getter + private final String defaultClosedTimer; + + @Getter + private final String defaultInactiveTimer; + + @Getter + private final String defaultMessagingServiceSid; + + @Getter + private final Map links; + + @Getter + private final URI url; + + @JsonCreator + private Configuration( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "default_chat_service_sid" + ) final String defaultChatServiceSid, + @JsonProperty("default_closed_timer") final String defaultClosedTimer, + @JsonProperty( + "default_inactive_timer" + ) final String defaultInactiveTimer, + @JsonProperty( + "default_messaging_service_sid" + ) final String defaultMessagingServiceSid, + @JsonProperty("links") final Map links, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.defaultChatServiceSid = defaultChatServiceSid; + this.defaultClosedTimer = defaultClosedTimer; + this.defaultInactiveTimer = defaultInactiveTimer; + this.defaultMessagingServiceSid = defaultMessagingServiceSid; + this.links = links; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Configuration other = (Configuration) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + defaultChatServiceSid, + other.defaultChatServiceSid + ) && + Objects.equals(defaultClosedTimer, other.defaultClosedTimer) && + Objects.equals(defaultInactiveTimer, other.defaultInactiveTimer) && + Objects.equals( + defaultMessagingServiceSid, + other.defaultMessagingServiceSid + ) && + Objects.equals(links, other.links) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + defaultChatServiceSid, + defaultClosedTimer, + defaultInactiveTimer, + defaultMessagingServiceSid, + links, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConfigurationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/ConfigurationFetcher.java new file mode 100644 index 0000000000..1d1afda592 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConfigurationFetcher.java @@ -0,0 +1,90 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationFetcher extends Fetcher { + + public ConfigurationFetcher() {} + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Configuration content = Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConfigurationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/ConfigurationUpdater.java new file mode 100644 index 0000000000..3283bfb60e --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConfigurationUpdater.java @@ -0,0 +1,166 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationUpdater extends Updater { + + private String defaultChatServiceSid; + private String defaultMessagingServiceSid; + private String defaultInactiveTimer; + private String defaultClosedTimer; + + public ConfigurationUpdater() {} + + public ConfigurationUpdater setDefaultChatServiceSid( + final String defaultChatServiceSid + ) { + this.defaultChatServiceSid = defaultChatServiceSid; + return this; + } + + public ConfigurationUpdater setDefaultMessagingServiceSid( + final String defaultMessagingServiceSid + ) { + this.defaultMessagingServiceSid = defaultMessagingServiceSid; + return this; + } + + public ConfigurationUpdater setDefaultInactiveTimer( + final String defaultInactiveTimer + ) { + this.defaultInactiveTimer = defaultInactiveTimer; + return this; + } + + public ConfigurationUpdater setDefaultClosedTimer( + final String defaultClosedTimer + ) { + this.defaultClosedTimer = defaultClosedTimer; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Configuration content = Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (defaultChatServiceSid != null) { + Serializer.toString( + request, + "DefaultChatServiceSid", + defaultChatServiceSid, + ParameterType.URLENCODED + ); + } + + if (defaultMessagingServiceSid != null) { + Serializer.toString( + request, + "DefaultMessagingServiceSid", + defaultMessagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (defaultInactiveTimer != null) { + Serializer.toString( + request, + "DefaultInactiveTimer", + defaultInactiveTimer, + ParameterType.URLENCODED + ); + } + + if (defaultClosedTimer != null) { + Serializer.toString( + request, + "DefaultClosedTimer", + defaultClosedTimer, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/Conversation.java b/src/main/java/com/twilio/rest/conversations/v1/Conversation.java new file mode 100644 index 0000000000..ae54d30466 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/Conversation.java @@ -0,0 +1,300 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Conversation extends Resource { + + public static ConversationCreator creator() { + return new ConversationCreator(); + } + + public static ConversationDeleter deleter(final String pathSid) { + return new ConversationDeleter(pathSid); + } + + public static ConversationFetcher fetcher(final String pathSid) { + return new ConversationFetcher(pathSid); + } + + public static ConversationReader reader() { + return new ConversationReader(); + } + + public static ConversationUpdater updater(final String pathSid) { + return new ConversationUpdater(pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + public enum State { + INITIALIZING("initializing"), + INACTIVE("inactive"), + ACTIVE("active"), + CLOSED("closed"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + /** + * Converts a JSON String into a Conversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Conversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final Object bindings; + + @Getter + private final String chatServiceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String messagingServiceSid; + + @Getter + private final String sid; + + @Getter + private final Conversation.State state; + + @Getter + private final Object timers; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private Conversation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("bindings") final Object bindings, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("state") final Conversation.State state, + @JsonProperty("timers") final Object timers, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.bindings = bindings; + this.chatServiceSid = chatServiceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.messagingServiceSid = messagingServiceSid; + this.sid = sid; + this.state = state; + this.timers = timers; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Conversation other = (Conversation) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(bindings, other.bindings) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(state, other.state) && + Objects.equals(timers, other.timers) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + bindings, + chatServiceSid, + dateCreated, + dateUpdated, + friendlyName, + links, + messagingServiceSid, + sid, + state, + timers, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationCreator.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationCreator.java new file mode 100644 index 0000000000..1adbfeaf50 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationCreator.java @@ -0,0 +1,290 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ConversationCreator extends Creator { + + private Conversation.WebhookEnabledType xTwilioWebhookEnabled; + private String friendlyName; + private String uniqueName; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String messagingServiceSid; + private String attributes; + private Conversation.State state; + private String timersInactive; + private String timersClosed; + private String bindingsEmailAddress; + private String bindingsEmailName; + + public ConversationCreator() {} + + public ConversationCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ConversationCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public ConversationCreator setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ConversationCreator setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public ConversationCreator setMessagingServiceSid( + final String messagingServiceSid + ) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + public ConversationCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public ConversationCreator setState(final Conversation.State state) { + this.state = state; + return this; + } + + public ConversationCreator setTimersInactive(final String timersInactive) { + this.timersInactive = timersInactive; + return this; + } + + public ConversationCreator setTimersClosed(final String timersClosed) { + this.timersClosed = timersClosed; + return this; + } + + public ConversationCreator setBindingsEmailAddress( + final String bindingsEmailAddress + ) { + this.bindingsEmailAddress = bindingsEmailAddress; + return this; + } + + public ConversationCreator setBindingsEmailName( + final String bindingsEmailName + ) { + this.bindingsEmailName = bindingsEmailName; + return this; + } + + public ConversationCreator setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conversation content = Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (state != null) { + Serializer.toString( + request, + "State", + state, + ParameterType.URLENCODED + ); + } + + if (timersInactive != null) { + Serializer.toString( + request, + "Timers.Inactive", + timersInactive, + ParameterType.URLENCODED + ); + } + + if (timersClosed != null) { + Serializer.toString( + request, + "Timers.Closed", + timersClosed, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailAddress != null) { + Serializer.toString( + request, + "Bindings.Email.Address", + bindingsEmailAddress, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailName != null) { + Serializer.toString( + request, + "Bindings.Email.Name", + bindingsEmailName, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationDeleter.java new file mode 100644 index 0000000000..d7ab52cdee --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationDeleter.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ConversationDeleter extends Deleter { + + private String pathSid; + private Conversation.WebhookEnabledType xTwilioWebhookEnabled; + + public ConversationDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + public ConversationDeleter setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationFetcher.java new file mode 100644 index 0000000000..5d92c4ef76 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationFetcher extends Fetcher { + + private String pathSid; + + public ConversationFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conversation content = Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationReader.java new file mode 100644 index 0000000000..7945beaa3c --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationReader.java @@ -0,0 +1,242 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationReader extends Reader { + + private String startDate; + private String endDate; + private Conversation.State state; + private Long pageSize; + + public ConversationReader() {} + + public ConversationReader setStartDate(final String startDate) { + this.startDate = startDate; + return this; + } + + public ConversationReader setEndDate(final String endDate) { + this.endDate = endDate; + return this; + } + + public ConversationReader setState(final Conversation.State state) { + this.state = state; + return this; + } + + public ConversationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + Conversation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Conversations"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + Conversation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Conversation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conversations", + response.getContent(), + Conversation.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (startDate != null) { + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); + } + + if (endDate != null) { + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); + } + + if (state != null) { + Serializer.toString(request, "State", state, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationUpdater.java new file mode 100644 index 0000000000..a0a8f932e3 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationUpdater.java @@ -0,0 +1,295 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ConversationUpdater extends Updater { + + private String pathSid; + private Conversation.WebhookEnabledType xTwilioWebhookEnabled; + private String friendlyName; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String messagingServiceSid; + private Conversation.State state; + private String timersInactive; + private String timersClosed; + private String uniqueName; + private String bindingsEmailAddress; + private String bindingsEmailName; + + public ConversationUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public ConversationUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ConversationUpdater setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ConversationUpdater setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public ConversationUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public ConversationUpdater setMessagingServiceSid( + final String messagingServiceSid + ) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + public ConversationUpdater setState(final Conversation.State state) { + this.state = state; + return this; + } + + public ConversationUpdater setTimersInactive(final String timersInactive) { + this.timersInactive = timersInactive; + return this; + } + + public ConversationUpdater setTimersClosed(final String timersClosed) { + this.timersClosed = timersClosed; + return this; + } + + public ConversationUpdater setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public ConversationUpdater setBindingsEmailAddress( + final String bindingsEmailAddress + ) { + this.bindingsEmailAddress = bindingsEmailAddress; + return this; + } + + public ConversationUpdater setBindingsEmailName( + final String bindingsEmailName + ) { + this.bindingsEmailName = bindingsEmailName; + return this; + } + + public ConversationUpdater setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conversation content = Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (state != null) { + Serializer.toString( + request, + "State", + state, + ParameterType.URLENCODED + ); + } + + if (timersInactive != null) { + Serializer.toString( + request, + "Timers.Inactive", + timersInactive, + ParameterType.URLENCODED + ); + } + + if (timersClosed != null) { + Serializer.toString( + request, + "Timers.Closed", + timersClosed, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailAddress != null) { + Serializer.toString( + request, + "Bindings.Email.Address", + bindingsEmailAddress, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailName != null) { + Serializer.toString( + request, + "Bindings.Email.Name", + bindingsEmailName, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationWithParticipants.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationWithParticipants.java new file mode 100644 index 0000000000..86bb43b6c8 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationWithParticipants.java @@ -0,0 +1,290 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ConversationWithParticipants extends Resource { + + public static ConversationWithParticipantsCreator creator() { + return new ConversationWithParticipantsCreator(); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + public enum State { + INITIALIZING("initializing"), + INACTIVE("inactive"), + ACTIVE("active"), + CLOSED("closed"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + /** + * Converts a JSON String into a ConversationWithParticipants object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ConversationWithParticipants object represented by the provided JSON + */ + public static ConversationWithParticipants fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ConversationWithParticipants.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ConversationWithParticipants object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ConversationWithParticipants object represented by the provided JSON + */ + public static ConversationWithParticipants fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ConversationWithParticipants.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final Object bindings; + + @Getter + private final String chatServiceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String messagingServiceSid; + + @Getter + private final String sid; + + @Getter + private final ConversationWithParticipants.State state; + + @Getter + private final Object timers; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private ConversationWithParticipants( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("bindings") final Object bindings, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("state") final ConversationWithParticipants.State state, + @JsonProperty("timers") final Object timers, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.bindings = bindings; + this.chatServiceSid = chatServiceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.messagingServiceSid = messagingServiceSid; + this.sid = sid; + this.state = state; + this.timers = timers; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationWithParticipants other = (ConversationWithParticipants) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(bindings, other.bindings) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(state, other.state) && + Objects.equals(timers, other.timers) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + bindings, + chatServiceSid, + dateCreated, + dateUpdated, + friendlyName, + links, + messagingServiceSid, + sid, + state, + timers, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ConversationWithParticipantsCreator.java b/src/main/java/com/twilio/rest/conversations/v1/ConversationWithParticipantsCreator.java new file mode 100644 index 0000000000..f1f672dada --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ConversationWithParticipantsCreator.java @@ -0,0 +1,335 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; + +public class ConversationWithParticipantsCreator + extends Creator { + + private ConversationWithParticipants.WebhookEnabledType xTwilioWebhookEnabled; + private String friendlyName; + private String uniqueName; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String messagingServiceSid; + private String attributes; + private ConversationWithParticipants.State state; + private String timersInactive; + private String timersClosed; + private String bindingsEmailAddress; + private String bindingsEmailName; + private List participant; + + public ConversationWithParticipantsCreator() {} + + public ConversationWithParticipantsCreator setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public ConversationWithParticipantsCreator setUniqueName( + final String uniqueName + ) { + this.uniqueName = uniqueName; + return this; + } + + public ConversationWithParticipantsCreator setDateCreated( + final ZonedDateTime dateCreated + ) { + this.dateCreated = dateCreated; + return this; + } + + public ConversationWithParticipantsCreator setDateUpdated( + final ZonedDateTime dateUpdated + ) { + this.dateUpdated = dateUpdated; + return this; + } + + public ConversationWithParticipantsCreator setMessagingServiceSid( + final String messagingServiceSid + ) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + public ConversationWithParticipantsCreator setAttributes( + final String attributes + ) { + this.attributes = attributes; + return this; + } + + public ConversationWithParticipantsCreator setState( + final ConversationWithParticipants.State state + ) { + this.state = state; + return this; + } + + public ConversationWithParticipantsCreator setTimersInactive( + final String timersInactive + ) { + this.timersInactive = timersInactive; + return this; + } + + public ConversationWithParticipantsCreator setTimersClosed( + final String timersClosed + ) { + this.timersClosed = timersClosed; + return this; + } + + public ConversationWithParticipantsCreator setBindingsEmailAddress( + final String bindingsEmailAddress + ) { + this.bindingsEmailAddress = bindingsEmailAddress; + return this; + } + + public ConversationWithParticipantsCreator setBindingsEmailName( + final String bindingsEmailName + ) { + this.bindingsEmailName = bindingsEmailName; + return this; + } + + public ConversationWithParticipantsCreator setParticipant( + final List participant + ) { + this.participant = participant; + return this; + } + + public ConversationWithParticipantsCreator setParticipant( + final String participant + ) { + return setParticipant(Promoter.listOfOne(participant)); + } + + public ConversationWithParticipantsCreator setXTwilioWebhookEnabled( + final ConversationWithParticipants.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ConversationWithParticipants"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConversationWithParticipants creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ConversationWithParticipants create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ConversationWithParticipants.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ConversationWithParticipants content = + ConversationWithParticipants.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (state != null) { + Serializer.toString( + request, + "State", + state, + ParameterType.URLENCODED + ); + } + + if (timersInactive != null) { + Serializer.toString( + request, + "Timers.Inactive", + timersInactive, + ParameterType.URLENCODED + ); + } + + if (timersClosed != null) { + Serializer.toString( + request, + "Timers.Closed", + timersClosed, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailAddress != null) { + Serializer.toString( + request, + "Bindings.Email.Address", + bindingsEmailAddress, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailName != null) { + Serializer.toString( + request, + "Bindings.Email.Name", + bindingsEmailName, + ParameterType.URLENCODED + ); + } + + if (participant != null) { + for (String param : participant) { + Serializer.toString( + request, + "Participant", + param, + ParameterType.URLENCODED + ); + } + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/Credential.java b/src/main/java/com/twilio/rest/conversations/v1/Credential.java new file mode 100644 index 0000000000..a7466cd76d --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/Credential.java @@ -0,0 +1,235 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Credential extends Resource { + + public static CredentialCreator creator(final Credential.PushType type) { + return new CredentialCreator(type); + } + + public static CredentialDeleter deleter(final String pathSid) { + return new CredentialDeleter(pathSid); + } + + public static CredentialFetcher fetcher(final String pathSid) { + return new CredentialFetcher(pathSid); + } + + public static CredentialReader reader() { + return new CredentialReader(); + } + + public static CredentialUpdater updater(final String pathSid) { + return new CredentialUpdater(pathSid); + } + + public enum PushType { + APN("apn"), + GCM("gcm"), + FCM("fcm"); + + private final String value; + + private PushType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static PushType forValue(final String value) { + return Promoter.enumFromString(value, PushType.values()); + } + } + + /** + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Credential.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Credential object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Credential object represented by the provided JSON + */ + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Credential.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sandbox; + + @Getter + private final String sid; + + @Getter + private final Credential.PushType type; + + @Getter + private final URI url; + + @JsonCreator + private Credential( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Credential.PushType type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sandbox = sandbox; + this.sid = sid; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Credential other = (Credential) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sandbox, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialCreator.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialCreator.java new file mode 100644 index 0000000000..00de6ed55a --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialCreator.java @@ -0,0 +1,205 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CredentialCreator extends Creator { + + private Credential.PushType type; + private String friendlyName; + private String certificate; + private String privateKey; + private Boolean sandbox; + private String apiKey; + private String secret; + + public CredentialCreator(final Credential.PushType type) { + this.type = type; + } + + public CredentialCreator setType(final Credential.PushType type) { + this.type = type; + return this; + } + + public CredentialCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public CredentialCreator setCertificate(final String certificate) { + this.certificate = certificate; + return this; + } + + public CredentialCreator setPrivateKey(final String privateKey) { + this.privateKey = privateKey; + return this; + } + + public CredentialCreator setSandbox(final Boolean sandbox) { + this.sandbox = sandbox; + return this; + } + + public CredentialCreator setApiKey(final String apiKey) { + this.apiKey = apiKey; + return this; + } + + public CredentialCreator setSecret(final String secret) { + this.secret = secret; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Credential create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (certificate != null) { + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); + } + + if (privateKey != null) { + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); + } + + if (sandbox != null) { + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); + } + + if (apiKey != null) { + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); + } + + if (secret != null) { + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialDeleter.java new file mode 100644 index 0000000000..acb5181b57 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class CredentialDeleter extends Deleter { + + private String pathSid; + + public CredentialDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialFetcher.java new file mode 100644 index 0000000000..bee666a59c --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CredentialFetcher extends Fetcher { + + private String pathSid; + + public CredentialFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Credential fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialReader.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialReader.java new file mode 100644 index 0000000000..019d2958ca --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CredentialReader extends Reader { + + private Long pageSize; + + public CredentialReader() {} + + public CredentialReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Credentials"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/CredentialUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/CredentialUpdater.java new file mode 100644 index 0000000000..802b80dc7d --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/CredentialUpdater.java @@ -0,0 +1,208 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CredentialUpdater extends Updater { + + private String pathSid; + private Credential.PushType type; + private String friendlyName; + private String certificate; + private String privateKey; + private Boolean sandbox; + private String apiKey; + private String secret; + + public CredentialUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public CredentialUpdater setType(final Credential.PushType type) { + this.type = type; + return this; + } + + public CredentialUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public CredentialUpdater setCertificate(final String certificate) { + this.certificate = certificate; + return this; + } + + public CredentialUpdater setPrivateKey(final String privateKey) { + this.privateKey = privateKey; + return this; + } + + public CredentialUpdater setSandbox(final Boolean sandbox) { + this.sandbox = sandbox; + return this; + } + + public CredentialUpdater setApiKey(final String apiKey) { + this.apiKey = apiKey; + return this; + } + + public CredentialUpdater setSecret(final String secret) { + this.secret = secret; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Credential update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (certificate != null) { + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); + } + + if (privateKey != null) { + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); + } + + if (sandbox != null) { + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); + } + + if (apiKey != null) { + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); + } + + if (secret != null) { + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversation.java b/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversation.java new file mode 100644 index 0000000000..429710b8bf --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversation.java @@ -0,0 +1,308 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ParticipantConversation extends Resource { + + public static ParticipantConversationReader reader() { + return new ParticipantConversationReader(); + } + + public enum State { + INACTIVE("inactive"), + ACTIVE("active"), + CLOSED("closed"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + /** + * Converts a JSON String into a ParticipantConversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ParticipantConversation object represented by the provided JSON + */ + public static ParticipantConversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ParticipantConversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ParticipantConversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ParticipantConversation object represented by the provided JSON + */ + public static ParticipantConversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ParticipantConversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String chatServiceSid; + + @Getter + private final String conversationAttributes; + + @Getter + private final String conversationCreatedBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime conversationDateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime conversationDateUpdated; + + @Getter + private final String conversationFriendlyName; + + @Getter + private final String conversationSid; + + @Getter + private final ParticipantConversation.State conversationState; + + @Getter + private final Object conversationTimers; + + @Getter + private final String conversationUniqueName; + + @Getter + private final Map links; + + @Getter + private final String participantIdentity; + + @Getter + private final Object participantMessagingBinding; + + @Getter + private final String participantSid; + + @Getter + private final String participantUserSid; + + @JsonCreator + private ParticipantConversation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty( + "conversation_attributes" + ) final String conversationAttributes, + @JsonProperty( + "conversation_created_by" + ) final String conversationCreatedBy, + @JsonProperty("conversation_date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime conversationDateCreated, + @JsonProperty("conversation_date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime conversationDateUpdated, + @JsonProperty( + "conversation_friendly_name" + ) final String conversationFriendlyName, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty( + "conversation_state" + ) final ParticipantConversation.State conversationState, + @JsonProperty("conversation_timers") final Object conversationTimers, + @JsonProperty( + "conversation_unique_name" + ) final String conversationUniqueName, + @JsonProperty("links") final Map links, + @JsonProperty("participant_identity") final String participantIdentity, + @JsonProperty( + "participant_messaging_binding" + ) final Object participantMessagingBinding, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("participant_user_sid") final String participantUserSid + ) { + this.accountSid = accountSid; + this.chatServiceSid = chatServiceSid; + this.conversationAttributes = conversationAttributes; + this.conversationCreatedBy = conversationCreatedBy; + this.conversationDateCreated = conversationDateCreated; + this.conversationDateUpdated = conversationDateUpdated; + this.conversationFriendlyName = conversationFriendlyName; + this.conversationSid = conversationSid; + this.conversationState = conversationState; + this.conversationTimers = conversationTimers; + this.conversationUniqueName = conversationUniqueName; + this.links = links; + this.participantIdentity = participantIdentity; + this.participantMessagingBinding = participantMessagingBinding; + this.participantSid = participantSid; + this.participantUserSid = participantUserSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ParticipantConversation other = (ParticipantConversation) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals( + conversationAttributes, + other.conversationAttributes + ) && + Objects.equals( + conversationCreatedBy, + other.conversationCreatedBy + ) && + Objects.equals( + conversationDateCreated, + other.conversationDateCreated + ) && + Objects.equals( + conversationDateUpdated, + other.conversationDateUpdated + ) && + Objects.equals( + conversationFriendlyName, + other.conversationFriendlyName + ) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(conversationState, other.conversationState) && + Objects.equals(conversationTimers, other.conversationTimers) && + Objects.equals( + conversationUniqueName, + other.conversationUniqueName + ) && + Objects.equals(links, other.links) && + Objects.equals(participantIdentity, other.participantIdentity) && + Objects.equals( + participantMessagingBinding, + other.participantMessagingBinding + ) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(participantUserSid, other.participantUserSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + chatServiceSid, + conversationAttributes, + conversationCreatedBy, + conversationDateCreated, + conversationDateUpdated, + conversationFriendlyName, + conversationSid, + conversationState, + conversationTimers, + conversationUniqueName, + links, + participantIdentity, + participantMessagingBinding, + participantSid, + participantUserSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversationReader.java new file mode 100644 index 0000000000..db9a600cf2 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ParticipantConversationReader.java @@ -0,0 +1,237 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantConversationReader + extends Reader { + + private String identity; + private String address; + private Long pageSize; + + public ParticipantConversationReader() {} + + public ParticipantConversationReader setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public ParticipantConversationReader setAddress(final String address) { + this.address = address; + return this; + } + + public ParticipantConversationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + ParticipantConversation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/ParticipantConversations"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + ParticipantConversation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ParticipantConversation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conversations", + response.getContent(), + ParticipantConversation.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.QUERY + ); + } + + if (address != null) { + Serializer.toString( + request, + "Address", + address, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/Role.java b/src/main/java/com/twilio/rest/conversations/v1/Role.java new file mode 100644 index 0000000000..ecd029304f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/Role.java @@ -0,0 +1,249 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Role extends Resource { + + public static RoleCreator creator( + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + return new RoleCreator(friendlyName, type, permission); + } + + public static RoleDeleter deleter(final String pathSid) { + return new RoleDeleter(pathSid); + } + + public static RoleFetcher fetcher(final String pathSid) { + return new RoleFetcher(pathSid); + } + + public static RoleReader reader() { + return new RoleReader(); + } + + public static RoleUpdater updater( + final String pathSid, + final List permission + ) { + return new RoleUpdater(pathSid, permission); + } + + public enum RoleType { + CONVERSATION("conversation"), + SERVICE("service"); + + private final String value; + + private RoleType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RoleType forValue(final String value) { + return Promoter.enumFromString(value, RoleType.values()); + } + } + + /** + * Converts a JSON String into a Role object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Role.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Role object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Role.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String chatServiceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final List permissions; + + @Getter + private final String sid; + + @Getter + private final Role.RoleType type; + + @Getter + private final URI url; + + @JsonCreator + private Role( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("permissions") final List permissions, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.chatServiceSid = chatServiceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.permissions = permissions; + this.sid = sid; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Role other = (Role) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(permissions, other.permissions) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + chatServiceSid, + dateCreated, + dateUpdated, + friendlyName, + permissions, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleCreator.java b/src/main/java/com/twilio/rest/conversations/v1/RoleCreator.java new file mode 100644 index 0000000000..cdaa705979 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleCreator.java @@ -0,0 +1,156 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class RoleCreator extends Creator { + + private String friendlyName; + private Role.RoleType type; + private List permission; + + public RoleCreator( + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + this.friendlyName = friendlyName; + this.type = type; + this.permission = permission; + } + + public RoleCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public RoleCreator setType(final Role.RoleType type) { + this.type = type; + return this; + } + + public RoleCreator setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleCreator setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Roles"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Role create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Role.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (permission != null) { + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/RoleDeleter.java new file mode 100644 index 0000000000..e8638c2f06 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class RoleDeleter extends Deleter { + + private String pathSid; + + public RoleDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Roles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/RoleFetcher.java new file mode 100644 index 0000000000..f2fe984377 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RoleFetcher extends Fetcher { + + private String pathSid; + + public RoleFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Roles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Role fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Role.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleReader.java b/src/main/java/com/twilio/rest/conversations/v1/RoleReader.java new file mode 100644 index 0000000000..e06aff2729 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleReader.java @@ -0,0 +1,198 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RoleReader extends Reader { + + private Long pageSize; + + public RoleReader() {} + + public RoleReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Roles"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/RoleUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/RoleUpdater.java new file mode 100644 index 0000000000..20f6807d33 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/RoleUpdater.java @@ -0,0 +1,124 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class RoleUpdater extends Updater { + + private String pathSid; + private List permission; + + public RoleUpdater(final String pathSid, final List permission) { + this.pathSid = pathSid; + this.permission = permission; + } + + public RoleUpdater setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleUpdater setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Roles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Role update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Role.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (permission != null) { + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/Service.java b/src/main/java/com/twilio/rest/conversations/v1/Service.java new file mode 100644 index 0000000000..957d8ede0d --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/Service.java @@ -0,0 +1,201 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Service extends Resource { + + public static ServiceCreator creator(final String friendlyName) { + return new ServiceCreator(friendlyName); + } + + public static ServiceDeleter deleter(final String pathSid) { + return new ServiceDeleter(pathSid); + } + + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); + } + + public static ServiceReader reader() { + return new ServiceReader(); + } + + /** + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Service.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Service.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Service other = (Service) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + links, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/conversations/v1/ServiceCreator.java new file mode 100644 index 0000000000..3e3344438b --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ServiceCreator.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceCreator extends Creator { + + private String friendlyName; + + public ServiceCreator(final String friendlyName) { + this.friendlyName = friendlyName; + } + + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/ServiceDeleter.java new file mode 100644 index 0000000000..25f912f9be --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ServiceDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ServiceDeleter extends Deleter { + + private String pathSid; + + public ServiceDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/ServiceFetcher.java new file mode 100644 index 0000000000..190e102a2e --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ServiceFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceFetcher extends Fetcher { + + private String pathSid; + + public ServiceFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/ServiceReader.java b/src/main/java/com/twilio/rest/conversations/v1/ServiceReader.java new file mode 100644 index 0000000000..adeb64339f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/ServiceReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceReader extends Reader { + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/User.java b/src/main/java/com/twilio/rest/conversations/v1/User.java new file mode 100644 index 0000000000..e3be6d44fb --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/User.java @@ -0,0 +1,270 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class User extends Resource { + + public static UserCreator creator(final String identity) { + return new UserCreator(identity); + } + + public static UserDeleter deleter(final String pathSid) { + return new UserDeleter(pathSid); + } + + public static UserFetcher fetcher(final String pathSid) { + return new UserFetcher(pathSid); + } + + public static UserReader reader() { + return new UserReader(); + } + + public static UserUpdater updater(final String pathSid) { + return new UserUpdater(pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + /** + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String chatServiceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String identity; + + @Getter + private final Boolean isNotifiable; + + @Getter + private final Boolean isOnline; + + @Getter + private final Map links; + + @Getter + private final String roleSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private User( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity") final String identity, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty("links") final Map links, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.chatServiceSid = chatServiceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.identity = identity; + this.isNotifiable = isNotifiable; + this.isOnline = isOnline; + this.links = links; + this.roleSid = roleSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + User other = (User) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identity, other.identity) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(links, other.links) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + chatServiceSid, + dateCreated, + dateUpdated, + friendlyName, + identity, + isNotifiable, + isOnline, + links, + roleSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserCreator.java b/src/main/java/com/twilio/rest/conversations/v1/UserCreator.java new file mode 100644 index 0000000000..3f2d6f2815 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/UserCreator.java @@ -0,0 +1,177 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserCreator extends Creator { + + private User.WebhookEnabledType xTwilioWebhookEnabled; + private String identity; + private String friendlyName; + private String attributes; + private String roleSid; + + public UserCreator(final String identity) { + this.identity = identity; + } + + public UserCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public UserCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public UserCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public UserCreator setRoleSid(final String roleSid) { + this.roleSid = roleSid; + return this; + } + + public UserCreator setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User create(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (roleSid != null) { + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/UserDeleter.java new file mode 100644 index 0000000000..7ed7d4266e --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/UserDeleter.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UserDeleter extends Deleter { + + private String pathSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; + + public UserDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + public UserDeleter setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/UserFetcher.java new file mode 100644 index 0000000000..518c533d5b --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/UserFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserFetcher extends Fetcher { + + private String pathSid; + + public UserFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserReader.java b/src/main/java/com/twilio/rest/conversations/v1/UserReader.java new file mode 100644 index 0000000000..3ef84a863e --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/UserReader.java @@ -0,0 +1,198 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserReader extends Reader { + + private Long pageSize; + + public UserReader() {} + + public UserReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Users"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/UserUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/UserUpdater.java new file mode 100644 index 0000000000..eaa3c9d3b3 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/UserUpdater.java @@ -0,0 +1,165 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserUpdater extends Updater { + + private String pathSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; + private String friendlyName; + private String attributes; + private String roleSid; + + public UserUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public UserUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public UserUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public UserUpdater setRoleSid(final String roleSid) { + this.roleSid = roleSid; + return this; + } + + public UserUpdater setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User update(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (roleSid != null) { + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/configuration/Webhook.java b/src/main/java/com/twilio/rest/conversations/v1/configuration/Webhook.java new file mode 100644 index 0000000000..b4458a3008 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/configuration/Webhook.java @@ -0,0 +1,224 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.configuration; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Webhook extends Resource { + + public static WebhookFetcher fetcher() { + return new WebhookFetcher(); + } + + public static WebhookUpdater updater() { + return new WebhookUpdater(); + } + + public enum Target { + WEBHOOK("webhook"), + FLEX("flex"); + + private final String value; + + private Target(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Target forValue(final String value) { + return Promoter.enumFromString(value, Target.values()); + } + } + + public enum Method { + GET("GET"), + POST("POST"); + + private final String value; + + private Method(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Method forValue(final String value) { + return Promoter.enumFromString(value, Method.values()); + } + } + + /** + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final List filters; + + @Getter + private final Webhook.Method method; + + @Getter + private final String postWebhookUrl; + + @Getter + private final String preWebhookUrl; + + @Getter + private final Webhook.Target target; + + @Getter + private final URI url; + + @JsonCreator + private Webhook( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("filters") final List filters, + @JsonProperty("method") final Webhook.Method method, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("target") final Webhook.Target target, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.filters = filters; + this.method = method; + this.postWebhookUrl = postWebhookUrl; + this.preWebhookUrl = preWebhookUrl; + this.target = target; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Webhook other = (Webhook) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(filters, other.filters) && + Objects.equals(method, other.method) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(target, other.target) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + filters, + method, + postWebhookUrl, + preWebhookUrl, + target, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookFetcher.java new file mode 100644 index 0000000000..e06b065c15 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookFetcher.java @@ -0,0 +1,87 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.configuration; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebhookFetcher extends Fetcher { + + public WebhookFetcher() {} + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration/Webhooks"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookUpdater.java new file mode 100644 index 0000000000..a4ccff79a3 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/configuration/WebhookUpdater.java @@ -0,0 +1,178 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.configuration; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class WebhookUpdater extends Updater { + + private String method; + private List filters; + private String preWebhookUrl; + private String postWebhookUrl; + private Webhook.Target target; + + public WebhookUpdater() {} + + public WebhookUpdater setMethod(final String method) { + this.method = method; + return this; + } + + public WebhookUpdater setFilters(final List filters) { + this.filters = filters; + return this; + } + + public WebhookUpdater setFilters(final String filters) { + return setFilters(Promoter.listOfOne(filters)); + } + + public WebhookUpdater setPreWebhookUrl(final String preWebhookUrl) { + this.preWebhookUrl = preWebhookUrl; + return this; + } + + public WebhookUpdater setPostWebhookUrl(final String postWebhookUrl) { + this.postWebhookUrl = postWebhookUrl; + return this; + } + + public WebhookUpdater setTarget(final Webhook.Target target) { + this.target = target; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration/Webhooks"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (method != null) { + Serializer.toString( + request, + "Method", + method, + ParameterType.URLENCODED + ); + } + + if (filters != null) { + for (String param : filters) { + Serializer.toString( + request, + "Filters", + param, + ParameterType.URLENCODED + ); + } + } + + if (preWebhookUrl != null) { + Serializer.toString( + request, + "PreWebhookUrl", + preWebhookUrl, + ParameterType.URLENCODED + ); + } + + if (postWebhookUrl != null) { + Serializer.toString( + request, + "PostWebhookUrl", + postWebhookUrl, + ParameterType.URLENCODED + ); + } + + if (target != null) { + Serializer.toString( + request, + "Target", + target, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/Message.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/Message.java new file mode 100644 index 0000000000..feb6048d77 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/Message.java @@ -0,0 +1,315 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Message extends Resource { + + public static MessageCreator creator(final String pathConversationSid) { + return new MessageCreator(pathConversationSid); + } + + public static MessageDeleter deleter( + final String pathConversationSid, + final String pathSid + ) { + return new MessageDeleter(pathConversationSid, pathSid); + } + + public static MessageFetcher fetcher( + final String pathConversationSid, + final String pathSid + ) { + return new MessageFetcher(pathConversationSid, pathSid); + } + + public static MessageReader reader(final String pathConversationSid) { + return new MessageReader(pathConversationSid); + } + + public static MessageUpdater updater( + final String pathConversationSid, + final String pathSid + ) { + return new MessageUpdater(pathConversationSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + public enum OrderType { + ASC("asc"), + DESC("desc"); + + private final String value; + + private OrderType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderType forValue(final String value) { + return Promoter.enumFromString(value, OrderType.values()); + } + } + + /** + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Message.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Message.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String author; + + @Getter + private final String body; + + @Getter + private final String contentSid; + + @Getter + private final String conversationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Object delivery; + + @Getter + private final Integer index; + + @Getter + private final Map links; + + @Getter + private final List media; + + @Getter + private final String participantSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Message( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("author") final String author, + @JsonProperty("body") final String body, + @JsonProperty("content_sid") final String contentSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("delivery") final Object delivery, + @JsonProperty("index") final Integer index, + @JsonProperty("links") final Map links, + @JsonProperty("media") final List media, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.author = author; + this.body = body; + this.contentSid = contentSid; + this.conversationSid = conversationSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.delivery = delivery; + this.index = index; + this.links = links; + this.media = media; + this.participantSid = participantSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Message other = (Message) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(author, other.author) && + Objects.equals(body, other.body) && + Objects.equals(contentSid, other.contentSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(delivery, other.delivery) && + Objects.equals(index, other.index) && + Objects.equals(links, other.links) && + Objects.equals(media, other.media) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + author, + body, + contentSid, + conversationSid, + dateCreated, + dateUpdated, + delivery, + index, + links, + media, + participantSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageCreator.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageCreator.java new file mode 100644 index 0000000000..3f0934f498 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageCreator.java @@ -0,0 +1,260 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class MessageCreator extends Creator { + + private String pathConversationSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; + private String author; + private String body; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String mediaSid; + private String contentSid; + private String contentVariables; + private String subject; + + public MessageCreator(final String pathConversationSid) { + this.pathConversationSid = pathConversationSid; + } + + public MessageCreator setAuthor(final String author) { + this.author = author; + return this; + } + + public MessageCreator setBody(final String body) { + this.body = body; + return this; + } + + public MessageCreator setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public MessageCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public MessageCreator setMediaSid(final String mediaSid) { + this.mediaSid = mediaSid; + return this; + } + + public MessageCreator setContentSid(final String contentSid) { + this.contentSid = contentSid; + return this; + } + + public MessageCreator setContentVariables(final String contentVariables) { + this.contentVariables = contentVariables; + return this; + } + + public MessageCreator setSubject(final String subject) { + this.subject = subject; + return this; + } + + public MessageCreator setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Messages"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Message create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Message.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (author != null) { + Serializer.toString( + request, + "Author", + author, + ParameterType.URLENCODED + ); + } + + if (body != null) { + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (mediaSid != null) { + Serializer.toString( + request, + "MediaSid", + mediaSid, + ParameterType.URLENCODED + ); + } + + if (contentSid != null) { + Serializer.toString( + request, + "ContentSid", + contentSid, + ParameterType.URLENCODED + ); + } + + if (contentVariables != null) { + Serializer.toString( + request, + "ContentVariables", + contentVariables, + ParameterType.URLENCODED + ); + } + + if (subject != null) { + Serializer.toString( + request, + "Subject", + subject, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageDeleter.java new file mode 100644 index 0000000000..0057a5074c --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageDeleter.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class MessageDeleter extends Deleter { + + private String pathConversationSid; + private String pathSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; + + public MessageDeleter( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public MessageDeleter setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageFetcher.java new file mode 100644 index 0000000000..0c99d64ffb --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageFetcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MessageFetcher extends Fetcher { + + private String pathConversationSid; + private String pathSid; + + public MessageFetcher( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Message fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Message.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageReader.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageReader.java new file mode 100644 index 0000000000..3eb3aef474 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageReader.java @@ -0,0 +1,221 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MessageReader extends Reader { + + private String pathConversationSid; + private Message.OrderType order; + private Long pageSize; + + public MessageReader(final String pathConversationSid) { + this.pathConversationSid = pathConversationSid; + } + + public MessageReader setOrder(final Message.OrderType order) { + this.order = order; + return this; + } + + public MessageReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Messages"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (order != null) { + Serializer.toString(request, "Order", order, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageUpdater.java new file mode 100644 index 0000000000..33cfb8198e --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/MessageUpdater.java @@ -0,0 +1,221 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class MessageUpdater extends Updater { + + private String pathConversationSid; + private String pathSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; + private String author; + private String body; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String subject; + + public MessageUpdater( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public MessageUpdater setAuthor(final String author) { + this.author = author; + return this; + } + + public MessageUpdater setBody(final String body) { + this.body = body; + return this; + } + + public MessageUpdater setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public MessageUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public MessageUpdater setSubject(final String subject) { + this.subject = subject; + return this; + } + + public MessageUpdater setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Message update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Message.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (author != null) { + Serializer.toString( + request, + "Author", + author, + ParameterType.URLENCODED + ); + } + + if (body != null) { + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (subject != null) { + Serializer.toString( + request, + "Subject", + subject, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/Participant.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/Participant.java new file mode 100644 index 0000000000..229060eff3 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/Participant.java @@ -0,0 +1,273 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Participant extends Resource { + + public static ParticipantCreator creator(final String pathConversationSid) { + return new ParticipantCreator(pathConversationSid); + } + + public static ParticipantDeleter deleter( + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantDeleter(pathConversationSid, pathSid); + } + + public static ParticipantFetcher fetcher( + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantFetcher(pathConversationSid, pathSid); + } + + public static ParticipantReader reader(final String pathConversationSid) { + return new ParticipantReader(pathConversationSid); + } + + public static ParticipantUpdater updater( + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantUpdater(pathConversationSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + /** + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Participant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Participant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String conversationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String identity; + + @Getter + private final Integer lastReadMessageIndex; + + @Getter + private final String lastReadTimestamp; + + @Getter + private final Object messagingBinding; + + @Getter + private final String roleSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Participant( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty( + "last_read_message_index" + ) final Integer lastReadMessageIndex, + @JsonProperty("last_read_timestamp") final String lastReadTimestamp, + @JsonProperty("messaging_binding") final Object messagingBinding, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.conversationSid = conversationSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.identity = identity; + this.lastReadMessageIndex = lastReadMessageIndex; + this.lastReadTimestamp = lastReadTimestamp; + this.messagingBinding = messagingBinding; + this.roleSid = roleSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Participant other = (Participant) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && + Objects.equals(lastReadTimestamp, other.lastReadTimestamp) && + Objects.equals(messagingBinding, other.messagingBinding) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + conversationSid, + dateCreated, + dateUpdated, + identity, + lastReadMessageIndex, + lastReadTimestamp, + messagingBinding, + roleSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantCreator.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantCreator.java new file mode 100644 index 0000000000..ee32b65a83 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantCreator.java @@ -0,0 +1,255 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ParticipantCreator extends Creator { + + private String pathConversationSid; + private Participant.WebhookEnabledType xTwilioWebhookEnabled; + private String identity; + private String messagingBindingAddress; + private String messagingBindingProxyAddress; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String messagingBindingProjectedAddress; + private String roleSid; + + public ParticipantCreator(final String pathConversationSid) { + this.pathConversationSid = pathConversationSid; + } + + public ParticipantCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public ParticipantCreator setMessagingBindingAddress( + final String messagingBindingAddress + ) { + this.messagingBindingAddress = messagingBindingAddress; + return this; + } + + public ParticipantCreator setMessagingBindingProxyAddress( + final String messagingBindingProxyAddress + ) { + this.messagingBindingProxyAddress = messagingBindingProxyAddress; + return this; + } + + public ParticipantCreator setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ParticipantCreator setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public ParticipantCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public ParticipantCreator setMessagingBindingProjectedAddress( + final String messagingBindingProjectedAddress + ) { + this.messagingBindingProjectedAddress = + messagingBindingProjectedAddress; + return this; + } + + public ParticipantCreator setRoleSid(final String roleSid) { + this.roleSid = roleSid; + return this; + } + + public ParticipantCreator setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Participants"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + + if (messagingBindingAddress != null) { + Serializer.toString( + request, + "MessagingBinding.Address", + messagingBindingAddress, + ParameterType.URLENCODED + ); + } + + if (messagingBindingProxyAddress != null) { + Serializer.toString( + request, + "MessagingBinding.ProxyAddress", + messagingBindingProxyAddress, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (messagingBindingProjectedAddress != null) { + Serializer.toString( + request, + "MessagingBinding.ProjectedAddress", + messagingBindingProjectedAddress, + ParameterType.URLENCODED + ); + } + + if (roleSid != null) { + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantDeleter.java new file mode 100644 index 0000000000..dd06bc0b94 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantDeleter.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ParticipantDeleter extends Deleter { + + private String pathConversationSid; + private String pathSid; + private Participant.WebhookEnabledType xTwilioWebhookEnabled; + + public ParticipantDeleter( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public ParticipantDeleter setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantFetcher.java new file mode 100644 index 0000000000..ef58598f58 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantFetcher extends Fetcher { + + private String pathConversationSid; + private String pathSid; + + public ParticipantFetcher( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantReader.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantReader.java new file mode 100644 index 0000000000..0de6f0b9c7 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantReader extends Reader { + + private String pathConversationSid; + private Long pageSize; + + public ParticipantReader(final String pathConversationSid) { + this.pathConversationSid = pathConversationSid; + } + + public ParticipantReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Participants"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantUpdater.java new file mode 100644 index 0000000000..cf7d0769b9 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/ParticipantUpdater.java @@ -0,0 +1,278 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ParticipantUpdater extends Updater { + + private String pathConversationSid; + private String pathSid; + private Participant.WebhookEnabledType xTwilioWebhookEnabled; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String roleSid; + private String messagingBindingProxyAddress; + private String messagingBindingProjectedAddress; + private String identity; + private Integer lastReadMessageIndex; + private String lastReadTimestamp; + + public ParticipantUpdater( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public ParticipantUpdater setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ParticipantUpdater setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public ParticipantUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public ParticipantUpdater setRoleSid(final String roleSid) { + this.roleSid = roleSid; + return this; + } + + public ParticipantUpdater setMessagingBindingProxyAddress( + final String messagingBindingProxyAddress + ) { + this.messagingBindingProxyAddress = messagingBindingProxyAddress; + return this; + } + + public ParticipantUpdater setMessagingBindingProjectedAddress( + final String messagingBindingProjectedAddress + ) { + this.messagingBindingProjectedAddress = + messagingBindingProjectedAddress; + return this; + } + + public ParticipantUpdater setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public ParticipantUpdater setLastReadMessageIndex( + final Integer lastReadMessageIndex + ) { + this.lastReadMessageIndex = lastReadMessageIndex; + return this; + } + + public ParticipantUpdater setLastReadTimestamp( + final String lastReadTimestamp + ) { + this.lastReadTimestamp = lastReadTimestamp; + return this; + } + + public ParticipantUpdater setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (roleSid != null) { + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); + } + + if (messagingBindingProxyAddress != null) { + Serializer.toString( + request, + "MessagingBinding.ProxyAddress", + messagingBindingProxyAddress, + ParameterType.URLENCODED + ); + } + + if (messagingBindingProjectedAddress != null) { + Serializer.toString( + request, + "MessagingBinding.ProjectedAddress", + messagingBindingProjectedAddress, + ParameterType.URLENCODED + ); + } + + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + + if (lastReadMessageIndex != null) { + Serializer.toString( + request, + "LastReadMessageIndex", + lastReadMessageIndex, + ParameterType.URLENCODED + ); + } + + if (lastReadTimestamp != null) { + Serializer.toString( + request, + "LastReadTimestamp", + lastReadTimestamp, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/Webhook.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/Webhook.java new file mode 100644 index 0000000000..0e03f7eea1 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/Webhook.java @@ -0,0 +1,268 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Webhook extends Resource { + + public static WebhookCreator creator( + final String pathConversationSid, + final Webhook.Target target + ) { + return new WebhookCreator(pathConversationSid, target); + } + + public static WebhookDeleter deleter( + final String pathConversationSid, + final String pathSid + ) { + return new WebhookDeleter(pathConversationSid, pathSid); + } + + public static WebhookFetcher fetcher( + final String pathConversationSid, + final String pathSid + ) { + return new WebhookFetcher(pathConversationSid, pathSid); + } + + public static WebhookReader reader(final String pathConversationSid) { + return new WebhookReader(pathConversationSid); + } + + public static WebhookUpdater updater( + final String pathConversationSid, + final String pathSid + ) { + return new WebhookUpdater(pathConversationSid, pathSid); + } + + public enum Target { + WEBHOOK("webhook"), + TRIGGER("trigger"), + STUDIO("studio"); + + private final String value; + + private Target(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Target forValue(final String value) { + return Promoter.enumFromString(value, Target.values()); + } + } + + public enum Method { + GET("get"), + POST("post"); + + private final String value; + + private Method(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Method forValue(final String value) { + return Promoter.enumFromString(value, Method.values()); + } + } + + /** + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object configuration; + + @Getter + private final String conversationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final String target; + + @Getter + private final URI url; + + @JsonCreator + private Webhook( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("configuration") final Object configuration, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("target") final String target, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.configuration = configuration; + this.conversationSid = conversationSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.sid = sid; + this.target = target; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Webhook other = (Webhook) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(configuration, other.configuration) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(target, other.target) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + configuration, + conversationSid, + dateCreated, + dateUpdated, + sid, + target, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookCreator.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookCreator.java new file mode 100644 index 0000000000..65d7277b1f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookCreator.java @@ -0,0 +1,245 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class WebhookCreator extends Creator { + + private String pathConversationSid; + private Webhook.Target target; + private String configurationUrl; + private Webhook.Method configurationMethod; + private List configurationFilters; + private List configurationTriggers; + private String configurationFlowSid; + private Integer configurationReplayAfter; + + public WebhookCreator( + final String pathConversationSid, + final Webhook.Target target + ) { + this.pathConversationSid = pathConversationSid; + this.target = target; + } + + public WebhookCreator setTarget(final Webhook.Target target) { + this.target = target; + return this; + } + + public WebhookCreator setConfigurationUrl(final String configurationUrl) { + this.configurationUrl = configurationUrl; + return this; + } + + public WebhookCreator setConfigurationMethod( + final Webhook.Method configurationMethod + ) { + this.configurationMethod = configurationMethod; + return this; + } + + public WebhookCreator setConfigurationFilters( + final List configurationFilters + ) { + this.configurationFilters = configurationFilters; + return this; + } + + public WebhookCreator setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); + } + + public WebhookCreator setConfigurationTriggers( + final List configurationTriggers + ) { + this.configurationTriggers = configurationTriggers; + return this; + } + + public WebhookCreator setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); + } + + public WebhookCreator setConfigurationFlowSid( + final String configurationFlowSid + ) { + this.configurationFlowSid = configurationFlowSid; + return this; + } + + public WebhookCreator setConfigurationReplayAfter( + final Integer configurationReplayAfter + ) { + this.configurationReplayAfter = configurationReplayAfter; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Webhooks"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (target != null) { + Serializer.toString( + request, + "Target", + target, + ParameterType.URLENCODED + ); + } + + if (configurationUrl != null) { + Serializer.toString( + request, + "Configuration.Url", + configurationUrl, + ParameterType.URLENCODED + ); + } + + if (configurationMethod != null) { + Serializer.toString( + request, + "Configuration.Method", + configurationMethod, + ParameterType.URLENCODED + ); + } + + if (configurationFilters != null) { + for (String param : configurationFilters) { + Serializer.toString( + request, + "Configuration.Filters", + param, + ParameterType.URLENCODED + ); + } + } + + if (configurationTriggers != null) { + for (String param : configurationTriggers) { + Serializer.toString( + request, + "Configuration.Triggers", + param, + ParameterType.URLENCODED + ); + } + } + + if (configurationFlowSid != null) { + Serializer.toString( + request, + "Configuration.FlowSid", + configurationFlowSid, + ParameterType.URLENCODED + ); + } + + if (configurationReplayAfter != null) { + Serializer.toString( + request, + "Configuration.ReplayAfter", + configurationReplayAfter, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookDeleter.java new file mode 100644 index 0000000000..203d8ff4e7 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class WebhookDeleter extends Deleter { + + private String pathConversationSid; + private String pathSid; + + public WebhookDeleter( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookFetcher.java new file mode 100644 index 0000000000..ef8db1957b --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookFetcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebhookFetcher extends Fetcher { + + private String pathConversationSid; + private String pathSid; + + public WebhookFetcher( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookReader.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookReader.java new file mode 100644 index 0000000000..92b21a3829 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebhookReader extends Reader { + + private String pathConversationSid; + private Long pageSize; + + public WebhookReader(final String pathConversationSid) { + this.pathConversationSid = pathConversationSid; + } + + public WebhookReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Webhooks"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookUpdater.java new file mode 100644 index 0000000000..125ae42fc7 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/WebhookUpdater.java @@ -0,0 +1,215 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class WebhookUpdater extends Updater { + + private String pathConversationSid; + private String pathSid; + private String configurationUrl; + private Webhook.Method configurationMethod; + private List configurationFilters; + private List configurationTriggers; + private String configurationFlowSid; + + public WebhookUpdater( + final String pathConversationSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public WebhookUpdater setConfigurationUrl(final String configurationUrl) { + this.configurationUrl = configurationUrl; + return this; + } + + public WebhookUpdater setConfigurationMethod( + final Webhook.Method configurationMethod + ) { + this.configurationMethod = configurationMethod; + return this; + } + + public WebhookUpdater setConfigurationFilters( + final List configurationFilters + ) { + this.configurationFilters = configurationFilters; + return this; + } + + public WebhookUpdater setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); + } + + public WebhookUpdater setConfigurationTriggers( + final List configurationTriggers + ) { + this.configurationTriggers = configurationTriggers; + return this; + } + + public WebhookUpdater setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); + } + + public WebhookUpdater setConfigurationFlowSid( + final String configurationFlowSid + ) { + this.configurationFlowSid = configurationFlowSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conversations/{ConversationSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (configurationUrl != null) { + Serializer.toString( + request, + "Configuration.Url", + configurationUrl, + ParameterType.URLENCODED + ); + } + + if (configurationMethod != null) { + Serializer.toString( + request, + "Configuration.Method", + configurationMethod, + ParameterType.URLENCODED + ); + } + + if (configurationFilters != null) { + for (String param : configurationFilters) { + Serializer.toString( + request, + "Configuration.Filters", + param, + ParameterType.URLENCODED + ); + } + } + + if (configurationTriggers != null) { + for (String param : configurationTriggers) { + Serializer.toString( + request, + "Configuration.Triggers", + param, + ParameterType.URLENCODED + ); + } + } + + if (configurationFlowSid != null) { + Serializer.toString( + request, + "Configuration.FlowSid", + configurationFlowSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceipt.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceipt.java new file mode 100644 index 0000000000..e9fb9634fb --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceipt.java @@ -0,0 +1,257 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation.message; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DeliveryReceipt extends Resource { + + public static DeliveryReceiptFetcher fetcher( + final String pathConversationSid, + final String pathMessageSid, + final String pathSid + ) { + return new DeliveryReceiptFetcher( + pathConversationSid, + pathMessageSid, + pathSid + ); + } + + public static DeliveryReceiptReader reader( + final String pathConversationSid, + final String pathMessageSid + ) { + return new DeliveryReceiptReader(pathConversationSid, pathMessageSid); + } + + public enum DeliveryStatus { + READ("read"), + FAILED("failed"), + DELIVERED("delivered"), + UNDELIVERED("undelivered"), + SENT("sent"); + + private final String value; + + private DeliveryStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static DeliveryStatus forValue(final String value) { + return Promoter.enumFromString(value, DeliveryStatus.values()); + } + } + + /** + * Converts a JSON String into a DeliveryReceipt object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DeliveryReceipt object represented by the provided JSON + */ + public static DeliveryReceipt fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeliveryReceipt.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DeliveryReceipt object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DeliveryReceipt object represented by the provided JSON + */ + public static DeliveryReceipt fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeliveryReceipt.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String channelMessageSid; + + @Getter + private final String conversationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Integer errorCode; + + @Getter + private final String messageSid; + + @Getter + private final String participantSid; + + @Getter + private final String sid; + + @Getter + private final DeliveryReceipt.DeliveryStatus status; + + @Getter + private final URI url; + + @JsonCreator + private DeliveryReceipt( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_message_sid") final String channelMessageSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("message_sid") final String messageSid, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final DeliveryReceipt.DeliveryStatus status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelMessageSid = channelMessageSid; + this.conversationSid = conversationSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.errorCode = errorCode; + this.messageSid = messageSid; + this.participantSid = participantSid; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DeliveryReceipt other = (DeliveryReceipt) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelMessageSid, other.channelMessageSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(messageSid, other.messageSid) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + channelMessageSid, + conversationSid, + dateCreated, + dateUpdated, + errorCode, + messageSid, + participantSid, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptFetcher.java new file mode 100644 index 0000000000..817482df36 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation.message; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DeliveryReceiptFetcher extends Fetcher { + + private String pathConversationSid; + private String pathMessageSid; + private String pathSid; + + public DeliveryReceiptFetcher( + final String pathConversationSid, + final String pathMessageSid, + final String pathSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathMessageSid = pathMessageSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts/{Sid}"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DeliveryReceipt fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DeliveryReceipt fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DeliveryReceipt.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DeliveryReceipt content = DeliveryReceipt.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptReader.java b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptReader.java new file mode 100644 index 0000000000..937e681fbf --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/conversation/message/DeliveryReceiptReader.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.conversation.message; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DeliveryReceiptReader extends Reader { + + private String pathConversationSid; + private String pathMessageSid; + private Long pageSize; + + public DeliveryReceiptReader( + final String pathConversationSid, + final String pathMessageSid + ) { + this.pathConversationSid = pathConversationSid; + this.pathMessageSid = pathMessageSid; + } + + public DeliveryReceiptReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "delivery_receipts", + response.getContent(), + DeliveryReceipt.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts"; + + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "delivery_receipts", + response.getContent(), + DeliveryReceipt.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "DeliveryReceipt read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "delivery_receipts", + response.getContent(), + DeliveryReceipt.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/Binding.java b/src/main/java/com/twilio/rest/conversations/v1/service/Binding.java new file mode 100644 index 0000000000..57354d3eb3 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/Binding.java @@ -0,0 +1,256 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Binding extends Resource { + + public static BindingDeleter deleter( + final String pathChatServiceSid, + final String pathSid + ) { + return new BindingDeleter(pathChatServiceSid, pathSid); + } + + public static BindingFetcher fetcher( + final String pathChatServiceSid, + final String pathSid + ) { + return new BindingFetcher(pathChatServiceSid, pathSid); + } + + public static BindingReader reader(final String pathChatServiceSid) { + return new BindingReader(pathChatServiceSid); + } + + public enum BindingType { + APN("apn"), + GCM("gcm"), + FCM("fcm"), + TWILSOCK("twilsock"); + + private final String value; + + private BindingType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BindingType forValue(final String value) { + return Promoter.enumFromString(value, BindingType.values()); + } + } + + /** + * Converts a JSON String into a Binding object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Binding.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Binding object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Binding object represented by the provided JSON + */ + public static Binding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Binding.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Binding.BindingType bindingType; + + @Getter + private final String chatServiceSid; + + @Getter + private final String credentialSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String endpoint; + + @Getter + private final String identity; + + @Getter + private final List messageTypes; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Binding( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("binding_type") final Binding.BindingType bindingType, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.bindingType = bindingType; + this.chatServiceSid = chatServiceSid; + this.credentialSid = credentialSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.endpoint = endpoint; + this.identity = identity; + this.messageTypes = messageTypes; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Binding other = (Binding) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + bindingType, + chatServiceSid, + credentialSid, + dateCreated, + dateUpdated, + endpoint, + identity, + messageTypes, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/BindingDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/BindingDeleter.java new file mode 100644 index 0000000000..b6b0396a0f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/BindingDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class BindingDeleter extends Deleter { + + private String pathChatServiceSid; + private String pathSid; + + public BindingDeleter( + final String pathChatServiceSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Binding delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/BindingFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/BindingFetcher.java new file mode 100644 index 0000000000..56d220c95b --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/BindingFetcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BindingFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathSid; + + public BindingFetcher( + final String pathChatServiceSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Binding fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Binding fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Binding.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Binding content = Binding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/BindingReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/BindingReader.java new file mode 100644 index 0000000000..eed3430617 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/BindingReader.java @@ -0,0 +1,257 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class BindingReader extends Reader { + + private String pathChatServiceSid; + private List bindingType; + private List identity; + private Long pageSize; + + public BindingReader(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public BindingReader setBindingType( + final List bindingType + ) { + this.bindingType = bindingType; + return this; + } + + public BindingReader setBindingType(final Binding.BindingType bindingType) { + return setBindingType(Promoter.listOfOne(bindingType)); + } + + public BindingReader setIdentity(final List identity) { + this.identity = identity; + return this; + } + + public BindingReader setIdentity(final String identity) { + return setIdentity(Promoter.listOfOne(identity)); + } + + public BindingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Bindings"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Binding read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (bindingType != null) { + for (Binding.BindingType param : bindingType) { + Serializer.toString( + request, + "BindingType", + param, + ParameterType.QUERY + ); + } + } + + if (identity != null) { + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); + } + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/Configuration.java b/src/main/java/com/twilio/rest/conversations/v1/service/Configuration.java new file mode 100644 index 0000000000..7cf5caa321 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/Configuration.java @@ -0,0 +1,200 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Configuration extends Resource { + + public static ConfigurationFetcher fetcher( + final String pathChatServiceSid + ) { + return new ConfigurationFetcher(pathChatServiceSid); + } + + public static ConfigurationUpdater updater( + final String pathChatServiceSid + ) { + return new ConfigurationUpdater(pathChatServiceSid); + } + + /** + * Converts a JSON String into a Configuration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Configuration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String chatServiceSid; + + @Getter + private final String defaultChatServiceRoleSid; + + @Getter + private final String defaultConversationCreatorRoleSid; + + @Getter + private final String defaultConversationRoleSid; + + @Getter + private final Map links; + + @Getter + private final Boolean reachabilityEnabled; + + @Getter + private final URI url; + + @JsonCreator + private Configuration( + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty( + "default_chat_service_role_sid" + ) final String defaultChatServiceRoleSid, + @JsonProperty( + "default_conversation_creator_role_sid" + ) final String defaultConversationCreatorRoleSid, + @JsonProperty( + "default_conversation_role_sid" + ) final String defaultConversationRoleSid, + @JsonProperty("links") final Map links, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty("url") final URI url + ) { + this.chatServiceSid = chatServiceSid; + this.defaultChatServiceRoleSid = defaultChatServiceRoleSid; + this.defaultConversationCreatorRoleSid = + defaultConversationCreatorRoleSid; + this.defaultConversationRoleSid = defaultConversationRoleSid; + this.links = links; + this.reachabilityEnabled = reachabilityEnabled; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Configuration other = (Configuration) o; + return ( + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals( + defaultChatServiceRoleSid, + other.defaultChatServiceRoleSid + ) && + Objects.equals( + defaultConversationCreatorRoleSid, + other.defaultConversationCreatorRoleSid + ) && + Objects.equals( + defaultConversationRoleSid, + other.defaultConversationRoleSid + ) && + Objects.equals(links, other.links) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + chatServiceSid, + defaultChatServiceRoleSid, + defaultConversationCreatorRoleSid, + defaultConversationRoleSid, + links, + reachabilityEnabled, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationFetcher.java new file mode 100644 index 0000000000..f7cb969141 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationFetcher extends Fetcher { + + private String pathChatServiceSid; + + public ConfigurationFetcher(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Configuration"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Configuration content = Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationUpdater.java new file mode 100644 index 0000000000..00eb6b4825 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConfigurationUpdater.java @@ -0,0 +1,176 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationUpdater extends Updater { + + private String pathChatServiceSid; + private String defaultConversationCreatorRoleSid; + private String defaultConversationRoleSid; + private String defaultChatServiceRoleSid; + private Boolean reachabilityEnabled; + + public ConfigurationUpdater(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public ConfigurationUpdater setDefaultConversationCreatorRoleSid( + final String defaultConversationCreatorRoleSid + ) { + this.defaultConversationCreatorRoleSid = + defaultConversationCreatorRoleSid; + return this; + } + + public ConfigurationUpdater setDefaultConversationRoleSid( + final String defaultConversationRoleSid + ) { + this.defaultConversationRoleSid = defaultConversationRoleSid; + return this; + } + + public ConfigurationUpdater setDefaultChatServiceRoleSid( + final String defaultChatServiceRoleSid + ) { + this.defaultChatServiceRoleSid = defaultChatServiceRoleSid; + return this; + } + + public ConfigurationUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { + this.reachabilityEnabled = reachabilityEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Configuration"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Configuration content = Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (defaultConversationCreatorRoleSid != null) { + Serializer.toString( + request, + "DefaultConversationCreatorRoleSid", + defaultConversationCreatorRoleSid, + ParameterType.URLENCODED + ); + } + + if (defaultConversationRoleSid != null) { + Serializer.toString( + request, + "DefaultConversationRoleSid", + defaultConversationRoleSid, + ParameterType.URLENCODED + ); + } + + if (defaultChatServiceRoleSid != null) { + Serializer.toString( + request, + "DefaultChatServiceRoleSid", + defaultChatServiceRoleSid, + ParameterType.URLENCODED + ); + } + + if (reachabilityEnabled != null) { + Serializer.toString( + request, + "ReachabilityEnabled", + reachabilityEnabled, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/Conversation.java b/src/main/java/com/twilio/rest/conversations/v1/service/Conversation.java new file mode 100644 index 0000000000..60aee7af49 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/Conversation.java @@ -0,0 +1,309 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Conversation extends Resource { + + public static ConversationCreator creator(final String pathChatServiceSid) { + return new ConversationCreator(pathChatServiceSid); + } + + public static ConversationDeleter deleter( + final String pathChatServiceSid, + final String pathSid + ) { + return new ConversationDeleter(pathChatServiceSid, pathSid); + } + + public static ConversationFetcher fetcher( + final String pathChatServiceSid, + final String pathSid + ) { + return new ConversationFetcher(pathChatServiceSid, pathSid); + } + + public static ConversationReader reader(final String pathChatServiceSid) { + return new ConversationReader(pathChatServiceSid); + } + + public static ConversationUpdater updater( + final String pathChatServiceSid, + final String pathSid + ) { + return new ConversationUpdater(pathChatServiceSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + public enum State { + INACTIVE("inactive"), + ACTIVE("active"), + CLOSED("closed"), + INITIALIZING("initializing"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + /** + * Converts a JSON String into a Conversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Conversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final Object bindings; + + @Getter + private final String chatServiceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String messagingServiceSid; + + @Getter + private final String sid; + + @Getter + private final Conversation.State state; + + @Getter + private final Object timers; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private Conversation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("bindings") final Object bindings, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("state") final Conversation.State state, + @JsonProperty("timers") final Object timers, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.bindings = bindings; + this.chatServiceSid = chatServiceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.messagingServiceSid = messagingServiceSid; + this.sid = sid; + this.state = state; + this.timers = timers; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Conversation other = (Conversation) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(bindings, other.bindings) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(state, other.state) && + Objects.equals(timers, other.timers) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + bindings, + chatServiceSid, + dateCreated, + dateUpdated, + friendlyName, + links, + messagingServiceSid, + sid, + state, + timers, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationCreator.java new file mode 100644 index 0000000000..a900342565 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationCreator.java @@ -0,0 +1,299 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ConversationCreator extends Creator { + + private String pathChatServiceSid; + private Conversation.WebhookEnabledType xTwilioWebhookEnabled; + private String friendlyName; + private String uniqueName; + private String attributes; + private String messagingServiceSid; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private Conversation.State state; + private String timersInactive; + private String timersClosed; + private String bindingsEmailAddress; + private String bindingsEmailName; + + public ConversationCreator(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public ConversationCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ConversationCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public ConversationCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public ConversationCreator setMessagingServiceSid( + final String messagingServiceSid + ) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + public ConversationCreator setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ConversationCreator setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public ConversationCreator setState(final Conversation.State state) { + this.state = state; + return this; + } + + public ConversationCreator setTimersInactive(final String timersInactive) { + this.timersInactive = timersInactive; + return this; + } + + public ConversationCreator setTimersClosed(final String timersClosed) { + this.timersClosed = timersClosed; + return this; + } + + public ConversationCreator setBindingsEmailAddress( + final String bindingsEmailAddress + ) { + this.bindingsEmailAddress = bindingsEmailAddress; + return this; + } + + public ConversationCreator setBindingsEmailName( + final String bindingsEmailName + ) { + this.bindingsEmailName = bindingsEmailName; + return this; + } + + public ConversationCreator setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Conversations"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conversation content = Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (state != null) { + Serializer.toString( + request, + "State", + state, + ParameterType.URLENCODED + ); + } + + if (timersInactive != null) { + Serializer.toString( + request, + "Timers.Inactive", + timersInactive, + ParameterType.URLENCODED + ); + } + + if (timersClosed != null) { + Serializer.toString( + request, + "Timers.Closed", + timersClosed, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailAddress != null) { + Serializer.toString( + request, + "Bindings.Email.Address", + bindingsEmailAddress, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailName != null) { + Serializer.toString( + request, + "Bindings.Email.Name", + bindingsEmailName, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationDeleter.java new file mode 100644 index 0000000000..32735ac862 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationDeleter.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ConversationDeleter extends Deleter { + + private String pathChatServiceSid; + private String pathSid; + private Conversation.WebhookEnabledType xTwilioWebhookEnabled; + + public ConversationDeleter( + final String pathChatServiceSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + public ConversationDeleter setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Conversations/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationFetcher.java new file mode 100644 index 0000000000..9d2f848f48 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathSid; + + public ConversationFetcher( + final String pathChatServiceSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Conversations/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conversation content = Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationReader.java new file mode 100644 index 0000000000..55a5e54323 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationReader.java @@ -0,0 +1,251 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationReader extends Reader { + + private String pathChatServiceSid; + private String startDate; + private String endDate; + private Conversation.State state; + private Long pageSize; + + public ConversationReader(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public ConversationReader setStartDate(final String startDate) { + this.startDate = startDate; + return this; + } + + public ConversationReader setEndDate(final String endDate) { + this.endDate = endDate; + return this; + } + + public ConversationReader setState(final Conversation.State state) { + this.state = state; + return this; + } + + public ConversationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + Conversation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Conversations"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + Conversation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Conversation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conversations", + response.getContent(), + Conversation.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (startDate != null) { + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); + } + + if (endDate != null) { + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); + } + + if (state != null) { + Serializer.toString(request, "State", state, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationUpdater.java new file mode 100644 index 0000000000..baf7c87626 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationUpdater.java @@ -0,0 +1,305 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ConversationUpdater extends Updater { + + private String pathChatServiceSid; + private String pathSid; + private Conversation.WebhookEnabledType xTwilioWebhookEnabled; + private String friendlyName; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String messagingServiceSid; + private Conversation.State state; + private String timersInactive; + private String timersClosed; + private String uniqueName; + private String bindingsEmailAddress; + private String bindingsEmailName; + + public ConversationUpdater( + final String pathChatServiceSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + public ConversationUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ConversationUpdater setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ConversationUpdater setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public ConversationUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public ConversationUpdater setMessagingServiceSid( + final String messagingServiceSid + ) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + public ConversationUpdater setState(final Conversation.State state) { + this.state = state; + return this; + } + + public ConversationUpdater setTimersInactive(final String timersInactive) { + this.timersInactive = timersInactive; + return this; + } + + public ConversationUpdater setTimersClosed(final String timersClosed) { + this.timersClosed = timersClosed; + return this; + } + + public ConversationUpdater setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public ConversationUpdater setBindingsEmailAddress( + final String bindingsEmailAddress + ) { + this.bindingsEmailAddress = bindingsEmailAddress; + return this; + } + + public ConversationUpdater setBindingsEmailName( + final String bindingsEmailName + ) { + this.bindingsEmailName = bindingsEmailName; + return this; + } + + public ConversationUpdater setXTwilioWebhookEnabled( + final Conversation.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Conversations/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conversation content = Conversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (state != null) { + Serializer.toString( + request, + "State", + state, + ParameterType.URLENCODED + ); + } + + if (timersInactive != null) { + Serializer.toString( + request, + "Timers.Inactive", + timersInactive, + ParameterType.URLENCODED + ); + } + + if (timersClosed != null) { + Serializer.toString( + request, + "Timers.Closed", + timersClosed, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailAddress != null) { + Serializer.toString( + request, + "Bindings.Email.Address", + bindingsEmailAddress, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailName != null) { + Serializer.toString( + request, + "Bindings.Email.Name", + bindingsEmailName, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationWithParticipants.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationWithParticipants.java new file mode 100644 index 0000000000..cf4057e279 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationWithParticipants.java @@ -0,0 +1,292 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ConversationWithParticipants extends Resource { + + public static ConversationWithParticipantsCreator creator( + final String pathChatServiceSid + ) { + return new ConversationWithParticipantsCreator(pathChatServiceSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + public enum State { + INITIALIZING("initializing"), + INACTIVE("inactive"), + ACTIVE("active"), + CLOSED("closed"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + /** + * Converts a JSON String into a ConversationWithParticipants object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ConversationWithParticipants object represented by the provided JSON + */ + public static ConversationWithParticipants fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ConversationWithParticipants.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ConversationWithParticipants object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ConversationWithParticipants object represented by the provided JSON + */ + public static ConversationWithParticipants fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ConversationWithParticipants.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final Object bindings; + + @Getter + private final String chatServiceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String messagingServiceSid; + + @Getter + private final String sid; + + @Getter + private final ConversationWithParticipants.State state; + + @Getter + private final Object timers; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private ConversationWithParticipants( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("bindings") final Object bindings, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("state") final ConversationWithParticipants.State state, + @JsonProperty("timers") final Object timers, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.bindings = bindings; + this.chatServiceSid = chatServiceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.messagingServiceSid = messagingServiceSid; + this.sid = sid; + this.state = state; + this.timers = timers; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationWithParticipants other = (ConversationWithParticipants) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(bindings, other.bindings) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(state, other.state) && + Objects.equals(timers, other.timers) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + bindings, + chatServiceSid, + dateCreated, + dateUpdated, + friendlyName, + links, + messagingServiceSid, + sid, + state, + timers, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ConversationWithParticipantsCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationWithParticipantsCreator.java new file mode 100644 index 0000000000..5e2a1d237a --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ConversationWithParticipantsCreator.java @@ -0,0 +1,347 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; + +public class ConversationWithParticipantsCreator + extends Creator { + + private String pathChatServiceSid; + private ConversationWithParticipants.WebhookEnabledType xTwilioWebhookEnabled; + private String friendlyName; + private String uniqueName; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String messagingServiceSid; + private String attributes; + private ConversationWithParticipants.State state; + private String timersInactive; + private String timersClosed; + private String bindingsEmailAddress; + private String bindingsEmailName; + private List participant; + + public ConversationWithParticipantsCreator( + final String pathChatServiceSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public ConversationWithParticipantsCreator setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public ConversationWithParticipantsCreator setUniqueName( + final String uniqueName + ) { + this.uniqueName = uniqueName; + return this; + } + + public ConversationWithParticipantsCreator setDateCreated( + final ZonedDateTime dateCreated + ) { + this.dateCreated = dateCreated; + return this; + } + + public ConversationWithParticipantsCreator setDateUpdated( + final ZonedDateTime dateUpdated + ) { + this.dateUpdated = dateUpdated; + return this; + } + + public ConversationWithParticipantsCreator setMessagingServiceSid( + final String messagingServiceSid + ) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + public ConversationWithParticipantsCreator setAttributes( + final String attributes + ) { + this.attributes = attributes; + return this; + } + + public ConversationWithParticipantsCreator setState( + final ConversationWithParticipants.State state + ) { + this.state = state; + return this; + } + + public ConversationWithParticipantsCreator setTimersInactive( + final String timersInactive + ) { + this.timersInactive = timersInactive; + return this; + } + + public ConversationWithParticipantsCreator setTimersClosed( + final String timersClosed + ) { + this.timersClosed = timersClosed; + return this; + } + + public ConversationWithParticipantsCreator setBindingsEmailAddress( + final String bindingsEmailAddress + ) { + this.bindingsEmailAddress = bindingsEmailAddress; + return this; + } + + public ConversationWithParticipantsCreator setBindingsEmailName( + final String bindingsEmailName + ) { + this.bindingsEmailName = bindingsEmailName; + return this; + } + + public ConversationWithParticipantsCreator setParticipant( + final List participant + ) { + this.participant = participant; + return this; + } + + public ConversationWithParticipantsCreator setParticipant( + final String participant + ) { + return setParticipant(Promoter.listOfOne(participant)); + } + + public ConversationWithParticipantsCreator setXTwilioWebhookEnabled( + final ConversationWithParticipants.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/ConversationWithParticipants"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConversationWithParticipants creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ConversationWithParticipants create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ConversationWithParticipants.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ConversationWithParticipants content = + ConversationWithParticipants.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (state != null) { + Serializer.toString( + request, + "State", + state, + ParameterType.URLENCODED + ); + } + + if (timersInactive != null) { + Serializer.toString( + request, + "Timers.Inactive", + timersInactive, + ParameterType.URLENCODED + ); + } + + if (timersClosed != null) { + Serializer.toString( + request, + "Timers.Closed", + timersClosed, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailAddress != null) { + Serializer.toString( + request, + "Bindings.Email.Address", + bindingsEmailAddress, + ParameterType.URLENCODED + ); + } + + if (bindingsEmailName != null) { + Serializer.toString( + request, + "Bindings.Email.Name", + bindingsEmailName, + ParameterType.URLENCODED + ); + } + + if (participant != null) { + for (String param : participant) { + Serializer.toString( + request, + "Participant", + param, + ParameterType.URLENCODED + ); + } + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversation.java b/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversation.java new file mode 100644 index 0000000000..f7c22a98df --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversation.java @@ -0,0 +1,310 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ParticipantConversation extends Resource { + + public static ParticipantConversationReader reader( + final String pathChatServiceSid + ) { + return new ParticipantConversationReader(pathChatServiceSid); + } + + public enum State { + INACTIVE("inactive"), + ACTIVE("active"), + CLOSED("closed"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + /** + * Converts a JSON String into a ParticipantConversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ParticipantConversation object represented by the provided JSON + */ + public static ParticipantConversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ParticipantConversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ParticipantConversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ParticipantConversation object represented by the provided JSON + */ + public static ParticipantConversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ParticipantConversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String chatServiceSid; + + @Getter + private final String conversationAttributes; + + @Getter + private final String conversationCreatedBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime conversationDateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime conversationDateUpdated; + + @Getter + private final String conversationFriendlyName; + + @Getter + private final String conversationSid; + + @Getter + private final ParticipantConversation.State conversationState; + + @Getter + private final Object conversationTimers; + + @Getter + private final String conversationUniqueName; + + @Getter + private final Map links; + + @Getter + private final String participantIdentity; + + @Getter + private final Object participantMessagingBinding; + + @Getter + private final String participantSid; + + @Getter + private final String participantUserSid; + + @JsonCreator + private ParticipantConversation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty( + "conversation_attributes" + ) final String conversationAttributes, + @JsonProperty( + "conversation_created_by" + ) final String conversationCreatedBy, + @JsonProperty("conversation_date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime conversationDateCreated, + @JsonProperty("conversation_date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime conversationDateUpdated, + @JsonProperty( + "conversation_friendly_name" + ) final String conversationFriendlyName, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty( + "conversation_state" + ) final ParticipantConversation.State conversationState, + @JsonProperty("conversation_timers") final Object conversationTimers, + @JsonProperty( + "conversation_unique_name" + ) final String conversationUniqueName, + @JsonProperty("links") final Map links, + @JsonProperty("participant_identity") final String participantIdentity, + @JsonProperty( + "participant_messaging_binding" + ) final Object participantMessagingBinding, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("participant_user_sid") final String participantUserSid + ) { + this.accountSid = accountSid; + this.chatServiceSid = chatServiceSid; + this.conversationAttributes = conversationAttributes; + this.conversationCreatedBy = conversationCreatedBy; + this.conversationDateCreated = conversationDateCreated; + this.conversationDateUpdated = conversationDateUpdated; + this.conversationFriendlyName = conversationFriendlyName; + this.conversationSid = conversationSid; + this.conversationState = conversationState; + this.conversationTimers = conversationTimers; + this.conversationUniqueName = conversationUniqueName; + this.links = links; + this.participantIdentity = participantIdentity; + this.participantMessagingBinding = participantMessagingBinding; + this.participantSid = participantSid; + this.participantUserSid = participantUserSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ParticipantConversation other = (ParticipantConversation) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals( + conversationAttributes, + other.conversationAttributes + ) && + Objects.equals( + conversationCreatedBy, + other.conversationCreatedBy + ) && + Objects.equals( + conversationDateCreated, + other.conversationDateCreated + ) && + Objects.equals( + conversationDateUpdated, + other.conversationDateUpdated + ) && + Objects.equals( + conversationFriendlyName, + other.conversationFriendlyName + ) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(conversationState, other.conversationState) && + Objects.equals(conversationTimers, other.conversationTimers) && + Objects.equals( + conversationUniqueName, + other.conversationUniqueName + ) && + Objects.equals(links, other.links) && + Objects.equals(participantIdentity, other.participantIdentity) && + Objects.equals( + participantMessagingBinding, + other.participantMessagingBinding + ) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(participantUserSid, other.participantUserSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + chatServiceSid, + conversationAttributes, + conversationCreatedBy, + conversationDateCreated, + conversationDateUpdated, + conversationFriendlyName, + conversationSid, + conversationState, + conversationTimers, + conversationUniqueName, + links, + participantIdentity, + participantMessagingBinding, + participantSid, + participantUserSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversationReader.java new file mode 100644 index 0000000000..c82d702fa0 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/ParticipantConversationReader.java @@ -0,0 +1,246 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantConversationReader + extends Reader { + + private String pathChatServiceSid; + private String identity; + private String address; + private Long pageSize; + + public ParticipantConversationReader(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public ParticipantConversationReader setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public ParticipantConversationReader setAddress(final String address) { + this.address = address; + return this; + } + + public ParticipantConversationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + ParticipantConversation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/ParticipantConversations"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + ParticipantConversation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ParticipantConversation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conversations", + response.getContent(), + ParticipantConversation.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.QUERY + ); + } + + if (address != null) { + Serializer.toString( + request, + "Address", + address, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/Role.java b/src/main/java/com/twilio/rest/conversations/v1/service/Role.java new file mode 100644 index 0000000000..56815d340f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/Role.java @@ -0,0 +1,262 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Role extends Resource { + + public static RoleCreator creator( + final String pathChatServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + return new RoleCreator( + pathChatServiceSid, + friendlyName, + type, + permission + ); + } + + public static RoleDeleter deleter( + final String pathChatServiceSid, + final String pathSid + ) { + return new RoleDeleter(pathChatServiceSid, pathSid); + } + + public static RoleFetcher fetcher( + final String pathChatServiceSid, + final String pathSid + ) { + return new RoleFetcher(pathChatServiceSid, pathSid); + } + + public static RoleReader reader(final String pathChatServiceSid) { + return new RoleReader(pathChatServiceSid); + } + + public static RoleUpdater updater( + final String pathChatServiceSid, + final String pathSid, + final List permission + ) { + return new RoleUpdater(pathChatServiceSid, pathSid, permission); + } + + public enum RoleType { + CONVERSATION("conversation"), + SERVICE("service"); + + private final String value; + + private RoleType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RoleType forValue(final String value) { + return Promoter.enumFromString(value, RoleType.values()); + } + } + + /** + * Converts a JSON String into a Role object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Role.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Role object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Role object represented by the provided JSON + */ + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Role.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String chatServiceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final List permissions; + + @Getter + private final String sid; + + @Getter + private final Role.RoleType type; + + @Getter + private final URI url; + + @JsonCreator + private Role( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("permissions") final List permissions, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.chatServiceSid = chatServiceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.permissions = permissions; + this.sid = sid; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Role other = (Role) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(permissions, other.permissions) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + chatServiceSid, + dateCreated, + dateUpdated, + friendlyName, + permissions, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleCreator.java new file mode 100644 index 0000000000..2941ac5252 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleCreator.java @@ -0,0 +1,165 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class RoleCreator extends Creator { + + private String pathChatServiceSid; + private String friendlyName; + private Role.RoleType type; + private List permission; + + public RoleCreator( + final String pathChatServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.friendlyName = friendlyName; + this.type = type; + this.permission = permission; + } + + public RoleCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public RoleCreator setType(final Role.RoleType type) { + this.type = type; + return this; + } + + public RoleCreator setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleCreator setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Roles"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Role create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Role.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (permission != null) { + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleDeleter.java new file mode 100644 index 0000000000..8c5027f2c3 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleDeleter.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class RoleDeleter extends Deleter { + + private String pathChatServiceSid; + private String pathSid; + + public RoleDeleter(final String pathChatServiceSid, final String pathSid) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleFetcher.java new file mode 100644 index 0000000000..8752ad461b --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RoleFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathSid; + + public RoleFetcher(final String pathChatServiceSid, final String pathSid) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Role fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Role.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleReader.java new file mode 100644 index 0000000000..7d79d0f633 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RoleReader extends Reader { + + private String pathChatServiceSid; + private Long pageSize; + + public RoleReader(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public RoleReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Roles"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/RoleUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/RoleUpdater.java new file mode 100644 index 0000000000..634a91b150 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/RoleUpdater.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class RoleUpdater extends Updater { + + private String pathChatServiceSid; + private String pathSid; + private List permission; + + public RoleUpdater( + final String pathChatServiceSid, + final String pathSid, + final List permission + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + this.permission = permission; + } + + public RoleUpdater setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleUpdater setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Role update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Role.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (permission != null) { + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/User.java b/src/main/java/com/twilio/rest/conversations/v1/service/User.java new file mode 100644 index 0000000000..ede367b732 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/User.java @@ -0,0 +1,282 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class User extends Resource { + + public static UserCreator creator( + final String pathChatServiceSid, + final String identity + ) { + return new UserCreator(pathChatServiceSid, identity); + } + + public static UserDeleter deleter( + final String pathChatServiceSid, + final String pathSid + ) { + return new UserDeleter(pathChatServiceSid, pathSid); + } + + public static UserFetcher fetcher( + final String pathChatServiceSid, + final String pathSid + ) { + return new UserFetcher(pathChatServiceSid, pathSid); + } + + public static UserReader reader(final String pathChatServiceSid) { + return new UserReader(pathChatServiceSid); + } + + public static UserUpdater updater( + final String pathChatServiceSid, + final String pathSid + ) { + return new UserUpdater(pathChatServiceSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + /** + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String chatServiceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String identity; + + @Getter + private final Boolean isNotifiable; + + @Getter + private final Boolean isOnline; + + @Getter + private final Map links; + + @Getter + private final String roleSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private User( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity") final String identity, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty("links") final Map links, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.chatServiceSid = chatServiceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.identity = identity; + this.isNotifiable = isNotifiable; + this.isOnline = isOnline; + this.links = links; + this.roleSid = roleSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + User other = (User) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identity, other.identity) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(links, other.links) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + chatServiceSid, + dateCreated, + dateUpdated, + friendlyName, + identity, + isNotifiable, + isOnline, + links, + roleSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserCreator.java new file mode 100644 index 0000000000..93eaee117e --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserCreator.java @@ -0,0 +1,185 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserCreator extends Creator { + + private String pathChatServiceSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; + private String identity; + private String friendlyName; + private String attributes; + private String roleSid; + + public UserCreator(final String pathChatServiceSid, final String identity) { + this.pathChatServiceSid = pathChatServiceSid; + this.identity = identity; + } + + public UserCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public UserCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public UserCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public UserCreator setRoleSid(final String roleSid) { + this.roleSid = roleSid; + return this; + } + + public UserCreator setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Users"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User create(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (roleSid != null) { + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserDeleter.java new file mode 100644 index 0000000000..e35d277ee3 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserDeleter.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UserDeleter extends Deleter { + + private String pathChatServiceSid; + private String pathSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; + + public UserDeleter(final String pathChatServiceSid, final String pathSid) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + public UserDeleter setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserFetcher.java new file mode 100644 index 0000000000..cc4ec9837d --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathSid; + + public UserFetcher(final String pathChatServiceSid, final String pathSid) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserReader.java new file mode 100644 index 0000000000..f3c8b2a307 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserReader extends Reader { + + private String pathChatServiceSid; + private Long pageSize; + + public UserReader(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public UserReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Users"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/UserUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/UserUpdater.java new file mode 100644 index 0000000000..73784f3024 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/UserUpdater.java @@ -0,0 +1,172 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserUpdater extends Updater { + + private String pathChatServiceSid; + private String pathSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; + private String friendlyName; + private String attributes; + private String roleSid; + + public UserUpdater(final String pathChatServiceSid, final String pathSid) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathSid = pathSid; + } + + public UserUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public UserUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public UserUpdater setRoleSid(final String roleSid) { + this.roleSid = roleSid; + return this; + } + + public UserUpdater setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User update(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (roleSid != null) { + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Notification.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Notification.java new file mode 100644 index 0000000000..70ab79276f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Notification.java @@ -0,0 +1,184 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.configuration; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Notification extends Resource { + + public static NotificationFetcher fetcher(final String pathChatServiceSid) { + return new NotificationFetcher(pathChatServiceSid); + } + + public static NotificationUpdater updater(final String pathChatServiceSid) { + return new NotificationUpdater(pathChatServiceSid); + } + + /** + * Converts a JSON String into a Notification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Notification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Notification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Notification object represented by the provided JSON + */ + public static Notification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Notification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object addedToConversation; + + @Getter + private final String chatServiceSid; + + @Getter + private final Boolean logEnabled; + + @Getter + private final Object newMessage; + + @Getter + private final Object removedFromConversation; + + @Getter + private final URI url; + + @JsonCreator + private Notification( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("added_to_conversation") final Object addedToConversation, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("log_enabled") final Boolean logEnabled, + @JsonProperty("new_message") final Object newMessage, + @JsonProperty( + "removed_from_conversation" + ) final Object removedFromConversation, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.addedToConversation = addedToConversation; + this.chatServiceSid = chatServiceSid; + this.logEnabled = logEnabled; + this.newMessage = newMessage; + this.removedFromConversation = removedFromConversation; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Notification other = (Notification) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addedToConversation, other.addedToConversation) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(logEnabled, other.logEnabled) && + Objects.equals(newMessage, other.newMessage) && + Objects.equals( + removedFromConversation, + other.removedFromConversation + ) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + addedToConversation, + chatServiceSid, + logEnabled, + newMessage, + removedFromConversation, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationFetcher.java new file mode 100644 index 0000000000..843f0cba65 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationFetcher.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.configuration; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NotificationFetcher extends Fetcher { + + private String pathChatServiceSid; + + public NotificationFetcher(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Configuration/Notifications"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Notification fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Notification fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Notification content = Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationUpdater.java new file mode 100644 index 0000000000..57562515cd --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/NotificationUpdater.java @@ -0,0 +1,327 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.configuration; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NotificationUpdater extends Updater { + + private String pathChatServiceSid; + private Boolean logEnabled; + private Boolean newMessageEnabled; + private String newMessageTemplate; + private String newMessageSound; + private Boolean newMessageBadgeCountEnabled; + private Boolean addedToConversationEnabled; + private String addedToConversationTemplate; + private String addedToConversationSound; + private Boolean removedFromConversationEnabled; + private String removedFromConversationTemplate; + private String removedFromConversationSound; + private Boolean newMessageWithMediaEnabled; + private String newMessageWithMediaTemplate; + + public NotificationUpdater(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public NotificationUpdater setLogEnabled(final Boolean logEnabled) { + this.logEnabled = logEnabled; + return this; + } + + public NotificationUpdater setNewMessageEnabled( + final Boolean newMessageEnabled + ) { + this.newMessageEnabled = newMessageEnabled; + return this; + } + + public NotificationUpdater setNewMessageTemplate( + final String newMessageTemplate + ) { + this.newMessageTemplate = newMessageTemplate; + return this; + } + + public NotificationUpdater setNewMessageSound( + final String newMessageSound + ) { + this.newMessageSound = newMessageSound; + return this; + } + + public NotificationUpdater setNewMessageBadgeCountEnabled( + final Boolean newMessageBadgeCountEnabled + ) { + this.newMessageBadgeCountEnabled = newMessageBadgeCountEnabled; + return this; + } + + public NotificationUpdater setAddedToConversationEnabled( + final Boolean addedToConversationEnabled + ) { + this.addedToConversationEnabled = addedToConversationEnabled; + return this; + } + + public NotificationUpdater setAddedToConversationTemplate( + final String addedToConversationTemplate + ) { + this.addedToConversationTemplate = addedToConversationTemplate; + return this; + } + + public NotificationUpdater setAddedToConversationSound( + final String addedToConversationSound + ) { + this.addedToConversationSound = addedToConversationSound; + return this; + } + + public NotificationUpdater setRemovedFromConversationEnabled( + final Boolean removedFromConversationEnabled + ) { + this.removedFromConversationEnabled = removedFromConversationEnabled; + return this; + } + + public NotificationUpdater setRemovedFromConversationTemplate( + final String removedFromConversationTemplate + ) { + this.removedFromConversationTemplate = removedFromConversationTemplate; + return this; + } + + public NotificationUpdater setRemovedFromConversationSound( + final String removedFromConversationSound + ) { + this.removedFromConversationSound = removedFromConversationSound; + return this; + } + + public NotificationUpdater setNewMessageWithMediaEnabled( + final Boolean newMessageWithMediaEnabled + ) { + this.newMessageWithMediaEnabled = newMessageWithMediaEnabled; + return this; + } + + public NotificationUpdater setNewMessageWithMediaTemplate( + final String newMessageWithMediaTemplate + ) { + this.newMessageWithMediaTemplate = newMessageWithMediaTemplate; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Configuration/Notifications"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Notification update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Notification update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Notification content = Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (logEnabled != null) { + Serializer.toString( + request, + "LogEnabled", + logEnabled, + ParameterType.URLENCODED + ); + } + + if (newMessageEnabled != null) { + Serializer.toString( + request, + "NewMessage.Enabled", + newMessageEnabled, + ParameterType.URLENCODED + ); + } + + if (newMessageTemplate != null) { + Serializer.toString( + request, + "NewMessage.Template", + newMessageTemplate, + ParameterType.URLENCODED + ); + } + + if (newMessageSound != null) { + Serializer.toString( + request, + "NewMessage.Sound", + newMessageSound, + ParameterType.URLENCODED + ); + } + + if (newMessageBadgeCountEnabled != null) { + Serializer.toString( + request, + "NewMessage.BadgeCountEnabled", + newMessageBadgeCountEnabled, + ParameterType.URLENCODED + ); + } + + if (addedToConversationEnabled != null) { + Serializer.toString( + request, + "AddedToConversation.Enabled", + addedToConversationEnabled, + ParameterType.URLENCODED + ); + } + + if (addedToConversationTemplate != null) { + Serializer.toString( + request, + "AddedToConversation.Template", + addedToConversationTemplate, + ParameterType.URLENCODED + ); + } + + if (addedToConversationSound != null) { + Serializer.toString( + request, + "AddedToConversation.Sound", + addedToConversationSound, + ParameterType.URLENCODED + ); + } + + if (removedFromConversationEnabled != null) { + Serializer.toString( + request, + "RemovedFromConversation.Enabled", + removedFromConversationEnabled, + ParameterType.URLENCODED + ); + } + + if (removedFromConversationTemplate != null) { + Serializer.toString( + request, + "RemovedFromConversation.Template", + removedFromConversationTemplate, + ParameterType.URLENCODED + ); + } + + if (removedFromConversationSound != null) { + Serializer.toString( + request, + "RemovedFromConversation.Sound", + removedFromConversationSound, + ParameterType.URLENCODED + ); + } + + if (newMessageWithMediaEnabled != null) { + Serializer.toString( + request, + "NewMessage.WithMedia.Enabled", + newMessageWithMediaEnabled, + ParameterType.URLENCODED + ); + } + + if (newMessageWithMediaTemplate != null) { + Serializer.toString( + request, + "NewMessage.WithMedia.Template", + newMessageWithMediaTemplate, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Webhook.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Webhook.java new file mode 100644 index 0000000000..6e4f186524 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/Webhook.java @@ -0,0 +1,203 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.configuration; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Webhook extends Resource { + + public static WebhookFetcher fetcher(final String pathChatServiceSid) { + return new WebhookFetcher(pathChatServiceSid); + } + + public static WebhookUpdater updater(final String pathChatServiceSid) { + return new WebhookUpdater(pathChatServiceSid); + } + + public enum Method { + GET("GET"), + POST("POST"); + + private final String value; + + private Method(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Method forValue(final String value) { + return Promoter.enumFromString(value, Method.values()); + } + } + + /** + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String chatServiceSid; + + @Getter + private final List filters; + + @Getter + private final Webhook.Method method; + + @Getter + private final URI postWebhookUrl; + + @Getter + private final URI preWebhookUrl; + + @Getter + private final URI url; + + @JsonCreator + private Webhook( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("filters") final List filters, + @JsonProperty("method") final Webhook.Method method, + @JsonProperty("post_webhook_url") final URI postWebhookUrl, + @JsonProperty("pre_webhook_url") final URI preWebhookUrl, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.chatServiceSid = chatServiceSid; + this.filters = filters; + this.method = method; + this.postWebhookUrl = postWebhookUrl; + this.preWebhookUrl = preWebhookUrl; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Webhook other = (Webhook) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(filters, other.filters) && + Objects.equals(method, other.method) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + chatServiceSid, + filters, + method, + postWebhookUrl, + preWebhookUrl, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookFetcher.java new file mode 100644 index 0000000000..7d2c58a8e4 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.configuration; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebhookFetcher extends Fetcher { + + private String pathChatServiceSid; + + public WebhookFetcher(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Configuration/Webhooks"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookUpdater.java new file mode 100644 index 0000000000..d4c9f799f8 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/configuration/WebhookUpdater.java @@ -0,0 +1,181 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.configuration; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; +import java.util.List; + +public class WebhookUpdater extends Updater { + + private String pathChatServiceSid; + private URI preWebhookUrl; + private URI postWebhookUrl; + private List filters; + private String method; + + public WebhookUpdater(final String pathChatServiceSid) { + this.pathChatServiceSid = pathChatServiceSid; + } + + public WebhookUpdater setPreWebhookUrl(final URI preWebhookUrl) { + this.preWebhookUrl = preWebhookUrl; + return this; + } + + public WebhookUpdater setPreWebhookUrl(final String preWebhookUrl) { + return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); + } + + public WebhookUpdater setPostWebhookUrl(final URI postWebhookUrl) { + this.postWebhookUrl = postWebhookUrl; + return this; + } + + public WebhookUpdater setPostWebhookUrl(final String postWebhookUrl) { + return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); + } + + public WebhookUpdater setFilters(final List filters) { + this.filters = filters; + return this; + } + + public WebhookUpdater setFilters(final String filters) { + return setFilters(Promoter.listOfOne(filters)); + } + + public WebhookUpdater setMethod(final String method) { + this.method = method; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ChatServiceSid}/Configuration/Webhooks"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (preWebhookUrl != null) { + Serializer.toString( + request, + "PreWebhookUrl", + preWebhookUrl, + ParameterType.URLENCODED + ); + } + + if (postWebhookUrl != null) { + Serializer.toString( + request, + "PostWebhookUrl", + postWebhookUrl, + ParameterType.URLENCODED + ); + } + + if (filters != null) { + for (String param : filters) { + Serializer.toString( + request, + "Filters", + param, + ParameterType.URLENCODED + ); + } + } + + if (method != null) { + Serializer.toString( + request, + "Method", + method, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Message.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Message.java new file mode 100644 index 0000000000..51e68a13ee --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Message.java @@ -0,0 +1,343 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Message extends Resource { + + public static MessageCreator creator( + final String pathChatServiceSid, + final String pathConversationSid + ) { + return new MessageCreator(pathChatServiceSid, pathConversationSid); + } + + public static MessageDeleter deleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new MessageDeleter( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public static MessageFetcher fetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new MessageFetcher( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public static MessageReader reader( + final String pathChatServiceSid, + final String pathConversationSid + ) { + return new MessageReader(pathChatServiceSid, pathConversationSid); + } + + public static MessageUpdater updater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new MessageUpdater( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + public enum OrderType { + ASC("asc"), + DESC("desc"); + + private final String value; + + private OrderType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderType forValue(final String value) { + return Promoter.enumFromString(value, OrderType.values()); + } + } + + /** + * Converts a JSON String into a Message object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Message.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Message object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Message object represented by the provided JSON + */ + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Message.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String author; + + @Getter + private final String body; + + @Getter + private final String chatServiceSid; + + @Getter + private final String contentSid; + + @Getter + private final String conversationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Object delivery; + + @Getter + private final Integer index; + + @Getter + private final Map links; + + @Getter + private final List media; + + @Getter + private final String participantSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Message( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("author") final String author, + @JsonProperty("body") final String body, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("content_sid") final String contentSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("delivery") final Object delivery, + @JsonProperty("index") final Integer index, + @JsonProperty("links") final Map links, + @JsonProperty("media") final List media, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.author = author; + this.body = body; + this.chatServiceSid = chatServiceSid; + this.contentSid = contentSid; + this.conversationSid = conversationSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.delivery = delivery; + this.index = index; + this.links = links; + this.media = media; + this.participantSid = participantSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Message other = (Message) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(author, other.author) && + Objects.equals(body, other.body) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(contentSid, other.contentSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(delivery, other.delivery) && + Objects.equals(index, other.index) && + Objects.equals(links, other.links) && + Objects.equals(media, other.media) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + author, + body, + chatServiceSid, + contentSid, + conversationSid, + dateCreated, + dateUpdated, + delivery, + index, + links, + media, + participantSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageCreator.java new file mode 100644 index 0000000000..1b1bbea79b --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageCreator.java @@ -0,0 +1,271 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class MessageCreator extends Creator { + + private String pathChatServiceSid; + private String pathConversationSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; + private String author; + private String body; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String mediaSid; + private String contentSid; + private String contentVariables; + private String subject; + + public MessageCreator( + final String pathChatServiceSid, + final String pathConversationSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + } + + public MessageCreator setAuthor(final String author) { + this.author = author; + return this; + } + + public MessageCreator setBody(final String body) { + this.body = body; + return this; + } + + public MessageCreator setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public MessageCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public MessageCreator setMediaSid(final String mediaSid) { + this.mediaSid = mediaSid; + return this; + } + + public MessageCreator setContentSid(final String contentSid) { + this.contentSid = contentSid; + return this; + } + + public MessageCreator setContentVariables(final String contentVariables) { + this.contentVariables = contentVariables; + return this; + } + + public MessageCreator setSubject(final String subject) { + this.subject = subject; + return this; + } + + public MessageCreator setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Message create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Message.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (author != null) { + Serializer.toString( + request, + "Author", + author, + ParameterType.URLENCODED + ); + } + + if (body != null) { + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (mediaSid != null) { + Serializer.toString( + request, + "MediaSid", + mediaSid, + ParameterType.URLENCODED + ); + } + + if (contentSid != null) { + Serializer.toString( + request, + "ContentSid", + contentSid, + ParameterType.URLENCODED + ); + } + + if (contentVariables != null) { + Serializer.toString( + request, + "ContentVariables", + contentVariables, + ParameterType.URLENCODED + ); + } + + if (subject != null) { + Serializer.toString( + request, + "Subject", + subject, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageDeleter.java new file mode 100644 index 0000000000..ff0c1fff56 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageDeleter.java @@ -0,0 +1,138 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class MessageDeleter extends Deleter { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; + + public MessageDeleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public MessageDeleter setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageFetcher.java new file mode 100644 index 0000000000..923c8aad55 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageFetcher.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MessageFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + + public MessageFetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Message fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Message.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageReader.java new file mode 100644 index 0000000000..bdc95c084f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageReader.java @@ -0,0 +1,232 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MessageReader extends Reader { + + private String pathChatServiceSid; + private String pathConversationSid; + private Message.OrderType order; + private Long pageSize; + + public MessageReader( + final String pathChatServiceSid, + final String pathConversationSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + } + + public MessageReader setOrder(final Message.OrderType order) { + this.order = order; + return this; + } + + public MessageReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (order != null) { + Serializer.toString(request, "Order", order, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageUpdater.java new file mode 100644 index 0000000000..1ae00c9cf6 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/MessageUpdater.java @@ -0,0 +1,230 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class MessageUpdater extends Updater { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; + private String author; + private String body; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String subject; + + public MessageUpdater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public MessageUpdater setAuthor(final String author) { + this.author = author; + return this; + } + + public MessageUpdater setBody(final String body) { + this.body = body; + return this; + } + + public MessageUpdater setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public MessageUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public MessageUpdater setSubject(final String subject) { + this.subject = subject; + return this; + } + + public MessageUpdater setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Message update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Message.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (author != null) { + Serializer.toString( + request, + "Author", + author, + ParameterType.URLENCODED + ); + } + + if (body != null) { + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (subject != null) { + Serializer.toString( + request, + "Subject", + subject, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Participant.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Participant.java new file mode 100644 index 0000000000..31ba20a7bd --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Participant.java @@ -0,0 +1,301 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Participant extends Resource { + + public static ParticipantCreator creator( + final String pathChatServiceSid, + final String pathConversationSid + ) { + return new ParticipantCreator(pathChatServiceSid, pathConversationSid); + } + + public static ParticipantDeleter deleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantDeleter( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public static ParticipantFetcher fetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantFetcher( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public static ParticipantReader reader( + final String pathChatServiceSid, + final String pathConversationSid + ) { + return new ParticipantReader(pathChatServiceSid, pathConversationSid); + } + + public static ParticipantUpdater updater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new ParticipantUpdater( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + + /** + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Participant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Participant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String chatServiceSid; + + @Getter + private final String conversationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String identity; + + @Getter + private final Integer lastReadMessageIndex; + + @Getter + private final String lastReadTimestamp; + + @Getter + private final Object messagingBinding; + + @Getter + private final String roleSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Participant( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty( + "last_read_message_index" + ) final Integer lastReadMessageIndex, + @JsonProperty("last_read_timestamp") final String lastReadTimestamp, + @JsonProperty("messaging_binding") final Object messagingBinding, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.chatServiceSid = chatServiceSid; + this.conversationSid = conversationSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.identity = identity; + this.lastReadMessageIndex = lastReadMessageIndex; + this.lastReadTimestamp = lastReadTimestamp; + this.messagingBinding = messagingBinding; + this.roleSid = roleSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Participant other = (Participant) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && + Objects.equals(lastReadTimestamp, other.lastReadTimestamp) && + Objects.equals(messagingBinding, other.messagingBinding) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + chatServiceSid, + conversationSid, + dateCreated, + dateUpdated, + identity, + lastReadMessageIndex, + lastReadTimestamp, + messagingBinding, + roleSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantCreator.java new file mode 100644 index 0000000000..00ab9ee072 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantCreator.java @@ -0,0 +1,266 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ParticipantCreator extends Creator { + + private String pathChatServiceSid; + private String pathConversationSid; + private Participant.WebhookEnabledType xTwilioWebhookEnabled; + private String identity; + private String messagingBindingAddress; + private String messagingBindingProxyAddress; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + private String messagingBindingProjectedAddress; + private String roleSid; + + public ParticipantCreator( + final String pathChatServiceSid, + final String pathConversationSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + } + + public ParticipantCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public ParticipantCreator setMessagingBindingAddress( + final String messagingBindingAddress + ) { + this.messagingBindingAddress = messagingBindingAddress; + return this; + } + + public ParticipantCreator setMessagingBindingProxyAddress( + final String messagingBindingProxyAddress + ) { + this.messagingBindingProxyAddress = messagingBindingProxyAddress; + return this; + } + + public ParticipantCreator setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ParticipantCreator setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public ParticipantCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public ParticipantCreator setMessagingBindingProjectedAddress( + final String messagingBindingProjectedAddress + ) { + this.messagingBindingProjectedAddress = + messagingBindingProjectedAddress; + return this; + } + + public ParticipantCreator setRoleSid(final String roleSid) { + this.roleSid = roleSid; + return this; + } + + public ParticipantCreator setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + + if (messagingBindingAddress != null) { + Serializer.toString( + request, + "MessagingBinding.Address", + messagingBindingAddress, + ParameterType.URLENCODED + ); + } + + if (messagingBindingProxyAddress != null) { + Serializer.toString( + request, + "MessagingBinding.ProxyAddress", + messagingBindingProxyAddress, + ParameterType.URLENCODED + ); + } + + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (messagingBindingProjectedAddress != null) { + Serializer.toString( + request, + "MessagingBinding.ProjectedAddress", + messagingBindingProjectedAddress, + ParameterType.URLENCODED + ); + } + + if (roleSid != null) { + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantDeleter.java new file mode 100644 index 0000000000..1706b64eab --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantDeleter.java @@ -0,0 +1,138 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ParticipantDeleter extends Deleter { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + private Participant.WebhookEnabledType xTwilioWebhookEnabled; + + public ParticipantDeleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public ParticipantDeleter setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantFetcher.java new file mode 100644 index 0000000000..c8762dad10 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + + public ParticipantFetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantReader.java new file mode 100644 index 0000000000..2b5a0ab1fe --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantReader.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantReader extends Reader { + + private String pathChatServiceSid; + private String pathConversationSid; + private Long pageSize; + + public ParticipantReader( + final String pathChatServiceSid, + final String pathConversationSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + } + + public ParticipantReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantUpdater.java new file mode 100644 index 0000000000..a0294bb27f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/ParticipantUpdater.java @@ -0,0 +1,287 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ParticipantUpdater extends Updater { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + private Participant.WebhookEnabledType xTwilioWebhookEnabled; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String identity; + private String attributes; + private String roleSid; + private String messagingBindingProxyAddress; + private String messagingBindingProjectedAddress; + private Integer lastReadMessageIndex; + private String lastReadTimestamp; + + public ParticipantUpdater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public ParticipantUpdater setDateCreated(final ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + public ParticipantUpdater setDateUpdated(final ZonedDateTime dateUpdated) { + this.dateUpdated = dateUpdated; + return this; + } + + public ParticipantUpdater setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public ParticipantUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public ParticipantUpdater setRoleSid(final String roleSid) { + this.roleSid = roleSid; + return this; + } + + public ParticipantUpdater setMessagingBindingProxyAddress( + final String messagingBindingProxyAddress + ) { + this.messagingBindingProxyAddress = messagingBindingProxyAddress; + return this; + } + + public ParticipantUpdater setMessagingBindingProjectedAddress( + final String messagingBindingProjectedAddress + ) { + this.messagingBindingProjectedAddress = + messagingBindingProjectedAddress; + return this; + } + + public ParticipantUpdater setLastReadMessageIndex( + final Integer lastReadMessageIndex + ) { + this.lastReadMessageIndex = lastReadMessageIndex; + return this; + } + + public ParticipantUpdater setLastReadTimestamp( + final String lastReadTimestamp + ) { + this.lastReadTimestamp = lastReadTimestamp; + return this; + } + + public ParticipantUpdater setXTwilioWebhookEnabled( + final Participant.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (dateCreated != null) { + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); + } + + if (dateUpdated != null) { + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (roleSid != null) { + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); + } + + if (messagingBindingProxyAddress != null) { + Serializer.toString( + request, + "MessagingBinding.ProxyAddress", + messagingBindingProxyAddress, + ParameterType.URLENCODED + ); + } + + if (messagingBindingProjectedAddress != null) { + Serializer.toString( + request, + "MessagingBinding.ProjectedAddress", + messagingBindingProjectedAddress, + ParameterType.URLENCODED + ); + } + + if (lastReadMessageIndex != null) { + Serializer.toString( + request, + "LastReadMessageIndex", + lastReadMessageIndex, + ParameterType.URLENCODED + ); + } + + if (lastReadTimestamp != null) { + Serializer.toString( + request, + "LastReadTimestamp", + lastReadTimestamp, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Webhook.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Webhook.java new file mode 100644 index 0000000000..e7f8f9a415 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/Webhook.java @@ -0,0 +1,298 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Webhook extends Resource { + + public static WebhookCreator creator( + final String pathChatServiceSid, + final String pathConversationSid, + final Webhook.Target target + ) { + return new WebhookCreator( + pathChatServiceSid, + pathConversationSid, + target + ); + } + + public static WebhookDeleter deleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new WebhookDeleter( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public static WebhookFetcher fetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new WebhookFetcher( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public static WebhookReader reader( + final String pathChatServiceSid, + final String pathConversationSid + ) { + return new WebhookReader(pathChatServiceSid, pathConversationSid); + } + + public static WebhookUpdater updater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + return new WebhookUpdater( + pathChatServiceSid, + pathConversationSid, + pathSid + ); + } + + public enum Target { + WEBHOOK("webhook"), + TRIGGER("trigger"), + STUDIO("studio"); + + private final String value; + + private Target(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Target forValue(final String value) { + return Promoter.enumFromString(value, Target.values()); + } + } + + public enum Method { + GET("get"), + POST("post"); + + private final String value; + + private Method(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Method forValue(final String value) { + return Promoter.enumFromString(value, Method.values()); + } + } + + /** + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String chatServiceSid; + + @Getter + private final Object configuration; + + @Getter + private final String conversationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final String target; + + @Getter + private final URI url; + + @JsonCreator + private Webhook( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("configuration") final Object configuration, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("target") final String target, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.chatServiceSid = chatServiceSid; + this.configuration = configuration; + this.conversationSid = conversationSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.sid = sid; + this.target = target; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Webhook other = (Webhook) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(configuration, other.configuration) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(target, other.target) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + chatServiceSid, + configuration, + conversationSid, + dateCreated, + dateUpdated, + sid, + target, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookCreator.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookCreator.java new file mode 100644 index 0000000000..6ab3803cc9 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookCreator.java @@ -0,0 +1,254 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class WebhookCreator extends Creator { + + private String pathChatServiceSid; + private String pathConversationSid; + private Webhook.Target target; + private String configurationUrl; + private Webhook.Method configurationMethod; + private List configurationFilters; + private List configurationTriggers; + private String configurationFlowSid; + private Integer configurationReplayAfter; + + public WebhookCreator( + final String pathChatServiceSid, + final String pathConversationSid, + final Webhook.Target target + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.target = target; + } + + public WebhookCreator setTarget(final Webhook.Target target) { + this.target = target; + return this; + } + + public WebhookCreator setConfigurationUrl(final String configurationUrl) { + this.configurationUrl = configurationUrl; + return this; + } + + public WebhookCreator setConfigurationMethod( + final Webhook.Method configurationMethod + ) { + this.configurationMethod = configurationMethod; + return this; + } + + public WebhookCreator setConfigurationFilters( + final List configurationFilters + ) { + this.configurationFilters = configurationFilters; + return this; + } + + public WebhookCreator setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); + } + + public WebhookCreator setConfigurationTriggers( + final List configurationTriggers + ) { + this.configurationTriggers = configurationTriggers; + return this; + } + + public WebhookCreator setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); + } + + public WebhookCreator setConfigurationFlowSid( + final String configurationFlowSid + ) { + this.configurationFlowSid = configurationFlowSid; + return this; + } + + public WebhookCreator setConfigurationReplayAfter( + final Integer configurationReplayAfter + ) { + this.configurationReplayAfter = configurationReplayAfter; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (target != null) { + Serializer.toString( + request, + "Target", + target, + ParameterType.URLENCODED + ); + } + + if (configurationUrl != null) { + Serializer.toString( + request, + "Configuration.Url", + configurationUrl, + ParameterType.URLENCODED + ); + } + + if (configurationMethod != null) { + Serializer.toString( + request, + "Configuration.Method", + configurationMethod, + ParameterType.URLENCODED + ); + } + + if (configurationFilters != null) { + for (String param : configurationFilters) { + Serializer.toString( + request, + "Configuration.Filters", + param, + ParameterType.URLENCODED + ); + } + } + + if (configurationTriggers != null) { + for (String param : configurationTriggers) { + Serializer.toString( + request, + "Configuration.Triggers", + param, + ParameterType.URLENCODED + ); + } + } + + if (configurationFlowSid != null) { + Serializer.toString( + request, + "Configuration.FlowSid", + configurationFlowSid, + ParameterType.URLENCODED + ); + } + + if (configurationReplayAfter != null) { + Serializer.toString( + request, + "Configuration.ReplayAfter", + configurationReplayAfter, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookDeleter.java new file mode 100644 index 0000000000..709d249149 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookDeleter.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class WebhookDeleter extends Deleter { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + + public WebhookDeleter( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookFetcher.java new file mode 100644 index 0000000000..5c4debde02 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookFetcher.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebhookFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + + public WebhookFetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookReader.java new file mode 100644 index 0000000000..68b7d4b164 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookReader.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebhookReader extends Reader { + + private String pathChatServiceSid; + private String pathConversationSid; + private Long pageSize; + + public WebhookReader( + final String pathChatServiceSid, + final String pathConversationSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + } + + public WebhookReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookUpdater.java new file mode 100644 index 0000000000..52ce9ac0f1 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/WebhookUpdater.java @@ -0,0 +1,224 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class WebhookUpdater extends Updater { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathSid; + private String configurationUrl; + private Webhook.Method configurationMethod; + private List configurationFilters; + private List configurationTriggers; + private String configurationFlowSid; + + public WebhookUpdater( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathSid = pathSid; + } + + public WebhookUpdater setConfigurationUrl(final String configurationUrl) { + this.configurationUrl = configurationUrl; + return this; + } + + public WebhookUpdater setConfigurationMethod( + final Webhook.Method configurationMethod + ) { + this.configurationMethod = configurationMethod; + return this; + } + + public WebhookUpdater setConfigurationFilters( + final List configurationFilters + ) { + this.configurationFilters = configurationFilters; + return this; + } + + public WebhookUpdater setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); + } + + public WebhookUpdater setConfigurationTriggers( + final List configurationTriggers + ) { + this.configurationTriggers = configurationTriggers; + return this; + } + + public WebhookUpdater setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); + } + + public WebhookUpdater setConfigurationFlowSid( + final String configurationFlowSid + ) { + this.configurationFlowSid = configurationFlowSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (configurationUrl != null) { + Serializer.toString( + request, + "Configuration.Url", + configurationUrl, + ParameterType.URLENCODED + ); + } + + if (configurationMethod != null) { + Serializer.toString( + request, + "Configuration.Method", + configurationMethod, + ParameterType.URLENCODED + ); + } + + if (configurationFilters != null) { + for (String param : configurationFilters) { + Serializer.toString( + request, + "Configuration.Filters", + param, + ParameterType.URLENCODED + ); + } + } + + if (configurationTriggers != null) { + for (String param : configurationTriggers) { + Serializer.toString( + request, + "Configuration.Triggers", + param, + ParameterType.URLENCODED + ); + } + } + + if (configurationFlowSid != null) { + Serializer.toString( + request, + "Configuration.FlowSid", + configurationFlowSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceipt.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceipt.java new file mode 100644 index 0000000000..e886955d5a --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceipt.java @@ -0,0 +1,271 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation.message; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DeliveryReceipt extends Resource { + + public static DeliveryReceiptFetcher fetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathMessageSid, + final String pathSid + ) { + return new DeliveryReceiptFetcher( + pathChatServiceSid, + pathConversationSid, + pathMessageSid, + pathSid + ); + } + + public static DeliveryReceiptReader reader( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathMessageSid + ) { + return new DeliveryReceiptReader( + pathChatServiceSid, + pathConversationSid, + pathMessageSid + ); + } + + public enum DeliveryStatus { + READ("read"), + FAILED("failed"), + DELIVERED("delivered"), + UNDELIVERED("undelivered"), + SENT("sent"); + + private final String value; + + private DeliveryStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static DeliveryStatus forValue(final String value) { + return Promoter.enumFromString(value, DeliveryStatus.values()); + } + } + + /** + * Converts a JSON String into a DeliveryReceipt object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DeliveryReceipt object represented by the provided JSON + */ + public static DeliveryReceipt fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeliveryReceipt.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DeliveryReceipt object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DeliveryReceipt object represented by the provided JSON + */ + public static DeliveryReceipt fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeliveryReceipt.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String channelMessageSid; + + @Getter + private final String chatServiceSid; + + @Getter + private final String conversationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Integer errorCode; + + @Getter + private final String messageSid; + + @Getter + private final String participantSid; + + @Getter + private final String sid; + + @Getter + private final DeliveryReceipt.DeliveryStatus status; + + @Getter + private final URI url; + + @JsonCreator + private DeliveryReceipt( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_message_sid") final String channelMessageSid, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("message_sid") final String messageSid, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final DeliveryReceipt.DeliveryStatus status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelMessageSid = channelMessageSid; + this.chatServiceSid = chatServiceSid; + this.conversationSid = conversationSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.errorCode = errorCode; + this.messageSid = messageSid; + this.participantSid = participantSid; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DeliveryReceipt other = (DeliveryReceipt) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelMessageSid, other.channelMessageSid) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(messageSid, other.messageSid) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + channelMessageSid, + chatServiceSid, + conversationSid, + dateCreated, + dateUpdated, + errorCode, + messageSid, + participantSid, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptFetcher.java new file mode 100644 index 0000000000..c5d8a87676 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptFetcher.java @@ -0,0 +1,123 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation.message; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DeliveryReceiptFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathMessageSid; + private String pathSid; + + public DeliveryReceiptFetcher( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathMessageSid, + final String pathSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathMessageSid = pathMessageSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts/{Sid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DeliveryReceipt fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DeliveryReceipt fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DeliveryReceipt.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DeliveryReceipt content = DeliveryReceipt.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptReader.java new file mode 100644 index 0000000000..0f9d27c9ae --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/conversation/message/DeliveryReceiptReader.java @@ -0,0 +1,230 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.conversation.message; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DeliveryReceiptReader extends Reader { + + private String pathChatServiceSid; + private String pathConversationSid; + private String pathMessageSid; + private Long pageSize; + + public DeliveryReceiptReader( + final String pathChatServiceSid, + final String pathConversationSid, + final String pathMessageSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathConversationSid = pathConversationSid; + this.pathMessageSid = pathMessageSid; + } + + public DeliveryReceiptReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "delivery_receipts", + response.getContent(), + DeliveryReceipt.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Conversations/{ConversationSid}/Messages/{MessageSid}/Receipts"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + path = + path.replace( + "{" + "MessageSid" + "}", + this.pathMessageSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "delivery_receipts", + response.getContent(), + DeliveryReceipt.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "DeliveryReceipt read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "delivery_receipts", + response.getContent(), + DeliveryReceipt.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversation.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversation.java new file mode 100644 index 0000000000..f3e39be099 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversation.java @@ -0,0 +1,358 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.user; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class UserConversation extends Resource { + + public static UserConversationDeleter deleter( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationDeleter( + pathChatServiceSid, + pathUserSid, + pathConversationSid + ); + } + + public static UserConversationFetcher fetcher( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationFetcher( + pathChatServiceSid, + pathUserSid, + pathConversationSid + ); + } + + public static UserConversationReader reader( + final String pathChatServiceSid, + final String pathUserSid + ) { + return new UserConversationReader(pathChatServiceSid, pathUserSid); + } + + public static UserConversationUpdater updater( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationUpdater( + pathChatServiceSid, + pathUserSid, + pathConversationSid + ); + } + + public enum State { + INACTIVE("inactive"), + ACTIVE("active"), + CLOSED("closed"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + public enum NotificationLevel { + DEFAULT("default"), + MUTED("muted"); + + private final String value; + + private NotificationLevel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static NotificationLevel forValue(final String value) { + return Promoter.enumFromString(value, NotificationLevel.values()); + } + } + + /** + * Converts a JSON String into a UserConversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserConversation object represented by the provided JSON + */ + public static UserConversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UserConversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a UserConversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserConversation object represented by the provided JSON + */ + public static UserConversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UserConversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String chatServiceSid; + + @Getter + private final String conversationSid; + + @Getter + private final UserConversation.State conversationState; + + @Getter + private final String createdBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Integer lastReadMessageIndex; + + @Getter + private final Map links; + + @Getter + private final UserConversation.NotificationLevel notificationLevel; + + @Getter + private final String participantSid; + + @Getter + private final Object timers; + + @Getter + private final String uniqueName; + + @Getter + private final Integer unreadMessagesCount; + + @Getter + private final URI url; + + @Getter + private final String userSid; + + @JsonCreator + private UserConversation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty( + "conversation_state" + ) final UserConversation.State conversationState, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "last_read_message_index" + ) final Integer lastReadMessageIndex, + @JsonProperty("links") final Map links, + @JsonProperty( + "notification_level" + ) final UserConversation.NotificationLevel notificationLevel, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("timers") final Object timers, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty("url") final URI url, + @JsonProperty("user_sid") final String userSid + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.chatServiceSid = chatServiceSid; + this.conversationSid = conversationSid; + this.conversationState = conversationState; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.lastReadMessageIndex = lastReadMessageIndex; + this.links = links; + this.notificationLevel = notificationLevel; + this.participantSid = participantSid; + this.timers = timers; + this.uniqueName = uniqueName; + this.unreadMessagesCount = unreadMessagesCount; + this.url = url; + this.userSid = userSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UserConversation other = (UserConversation) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(conversationState, other.conversationState) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && + Objects.equals(links, other.links) && + Objects.equals(notificationLevel, other.notificationLevel) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(timers, other.timers) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(url, other.url) && + Objects.equals(userSid, other.userSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + chatServiceSid, + conversationSid, + conversationState, + createdBy, + dateCreated, + dateUpdated, + friendlyName, + lastReadMessageIndex, + links, + notificationLevel, + participantSid, + timers, + uniqueName, + unreadMessagesCount, + url, + userSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationDeleter.java new file mode 100644 index 0000000000..02d16fec30 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationDeleter.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.user; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UserConversationDeleter extends Deleter { + + private String pathChatServiceSid; + private String pathUserSid; + private String pathConversationSid; + + public UserConversationDeleter( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathUserSid = pathUserSid; + this.pathConversationSid = pathConversationSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserConversation delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationFetcher.java new file mode 100644 index 0000000000..8f57e883ce --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.user; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserConversationFetcher extends Fetcher { + + private String pathChatServiceSid; + private String pathUserSid; + private String pathConversationSid; + + public UserConversationFetcher( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathUserSid = pathUserSid; + this.pathConversationSid = pathConversationSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserConversation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserConversation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserConversation content = UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationReader.java new file mode 100644 index 0000000000..2af8c815a7 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationReader.java @@ -0,0 +1,218 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.user; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserConversationReader extends Reader { + + private String pathChatServiceSid; + private String pathUserSid; + private Long pageSize; + + public UserConversationReader( + final String pathChatServiceSid, + final String pathUserSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathUserSid = pathUserSid; + } + + public UserConversationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + UserConversation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + UserConversation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UserConversation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conversations", + response.getContent(), + UserConversation.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationUpdater.java new file mode 100644 index 0000000000..c79f213409 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/service/user/UserConversationUpdater.java @@ -0,0 +1,174 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.service.user; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class UserConversationUpdater extends Updater { + + private String pathChatServiceSid; + private String pathUserSid; + private String pathConversationSid; + private UserConversation.NotificationLevel notificationLevel; + private ZonedDateTime lastReadTimestamp; + private Integer lastReadMessageIndex; + + public UserConversationUpdater( + final String pathChatServiceSid, + final String pathUserSid, + final String pathConversationSid + ) { + this.pathChatServiceSid = pathChatServiceSid; + this.pathUserSid = pathUserSid; + this.pathConversationSid = pathConversationSid; + } + + public UserConversationUpdater setNotificationLevel( + final UserConversation.NotificationLevel notificationLevel + ) { + this.notificationLevel = notificationLevel; + return this; + } + + public UserConversationUpdater setLastReadTimestamp( + final ZonedDateTime lastReadTimestamp + ) { + this.lastReadTimestamp = lastReadTimestamp; + return this; + } + + public UserConversationUpdater setLastReadMessageIndex( + final Integer lastReadMessageIndex + ) { + this.lastReadMessageIndex = lastReadMessageIndex; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ChatServiceSid}/Users/{UserSid}/Conversations/{ConversationSid}"; + + path = + path.replace( + "{" + "ChatServiceSid" + "}", + this.pathChatServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserConversation update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserConversation update(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserConversation content = UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (notificationLevel != null) { + Serializer.toString( + request, + "NotificationLevel", + notificationLevel, + ParameterType.URLENCODED + ); + } + + if (lastReadTimestamp != null) { + Serializer.toString( + request, + "LastReadTimestamp", + lastReadTimestamp, + ParameterType.URLENCODED + ); + } + + if (lastReadMessageIndex != null) { + Serializer.toString( + request, + "LastReadMessageIndex", + lastReadMessageIndex, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversation.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversation.java new file mode 100644 index 0000000000..882115190d --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversation.java @@ -0,0 +1,340 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.user; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class UserConversation extends Resource { + + public static UserConversationDeleter deleter( + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationDeleter(pathUserSid, pathConversationSid); + } + + public static UserConversationFetcher fetcher( + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationFetcher(pathUserSid, pathConversationSid); + } + + public static UserConversationReader reader(final String pathUserSid) { + return new UserConversationReader(pathUserSid); + } + + public static UserConversationUpdater updater( + final String pathUserSid, + final String pathConversationSid + ) { + return new UserConversationUpdater(pathUserSid, pathConversationSid); + } + + public enum State { + INACTIVE("inactive"), + ACTIVE("active"), + CLOSED("closed"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + public enum NotificationLevel { + DEFAULT("default"), + MUTED("muted"); + + private final String value; + + private NotificationLevel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static NotificationLevel forValue(final String value) { + return Promoter.enumFromString(value, NotificationLevel.values()); + } + } + + /** + * Converts a JSON String into a UserConversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UserConversation object represented by the provided JSON + */ + public static UserConversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UserConversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a UserConversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UserConversation object represented by the provided JSON + */ + public static UserConversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UserConversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String attributes; + + @Getter + private final String chatServiceSid; + + @Getter + private final String conversationSid; + + @Getter + private final UserConversation.State conversationState; + + @Getter + private final String createdBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Integer lastReadMessageIndex; + + @Getter + private final Map links; + + @Getter + private final UserConversation.NotificationLevel notificationLevel; + + @Getter + private final String participantSid; + + @Getter + private final Object timers; + + @Getter + private final String uniqueName; + + @Getter + private final Integer unreadMessagesCount; + + @Getter + private final URI url; + + @Getter + private final String userSid; + + @JsonCreator + private UserConversation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty( + "conversation_state" + ) final UserConversation.State conversationState, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "last_read_message_index" + ) final Integer lastReadMessageIndex, + @JsonProperty("links") final Map links, + @JsonProperty( + "notification_level" + ) final UserConversation.NotificationLevel notificationLevel, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("timers") final Object timers, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty("url") final URI url, + @JsonProperty("user_sid") final String userSid + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.chatServiceSid = chatServiceSid; + this.conversationSid = conversationSid; + this.conversationState = conversationState; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.lastReadMessageIndex = lastReadMessageIndex; + this.links = links; + this.notificationLevel = notificationLevel; + this.participantSid = participantSid; + this.timers = timers; + this.uniqueName = uniqueName; + this.unreadMessagesCount = unreadMessagesCount; + this.url = url; + this.userSid = userSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UserConversation other = (UserConversation) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(conversationState, other.conversationState) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(lastReadMessageIndex, other.lastReadMessageIndex) && + Objects.equals(links, other.links) && + Objects.equals(notificationLevel, other.notificationLevel) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(timers, other.timers) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(url, other.url) && + Objects.equals(userSid, other.userSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + chatServiceSid, + conversationSid, + conversationState, + createdBy, + dateCreated, + dateUpdated, + friendlyName, + lastReadMessageIndex, + links, + notificationLevel, + participantSid, + timers, + uniqueName, + unreadMessagesCount, + url, + userSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationDeleter.java new file mode 100644 index 0000000000..6ffc1ef3e0 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.user; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UserConversationDeleter extends Deleter { + + private String pathUserSid; + private String pathConversationSid; + + public UserConversationDeleter( + final String pathUserSid, + final String pathConversationSid + ) { + this.pathUserSid = pathUserSid; + this.pathConversationSid = pathConversationSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users/{UserSid}/Conversations/{ConversationSid}"; + + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserConversation delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationFetcher.java new file mode 100644 index 0000000000..7fcd62d41d --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.user; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserConversationFetcher extends Fetcher { + + private String pathUserSid; + private String pathConversationSid; + + public UserConversationFetcher( + final String pathUserSid, + final String pathConversationSid + ) { + this.pathUserSid = pathUserSid; + this.pathConversationSid = pathConversationSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users/{UserSid}/Conversations/{ConversationSid}"; + + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserConversation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserConversation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserConversation content = UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationReader.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationReader.java new file mode 100644 index 0000000000..0fdfa91305 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.user; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserConversationReader extends Reader { + + private String pathUserSid; + private Long pageSize; + + public UserConversationReader(final String pathUserSid) { + this.pathUserSid = pathUserSid; + } + + public UserConversationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + UserConversation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Users/{UserSid}/Conversations"; + + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + UserConversation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UserConversation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conversations", + response.getContent(), + UserConversation.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationUpdater.java new file mode 100644 index 0000000000..b9919e305a --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v1/user/UserConversationUpdater.java @@ -0,0 +1,165 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Conversations + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v1.user; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class UserConversationUpdater extends Updater { + + private String pathUserSid; + private String pathConversationSid; + private UserConversation.NotificationLevel notificationLevel; + private ZonedDateTime lastReadTimestamp; + private Integer lastReadMessageIndex; + + public UserConversationUpdater( + final String pathUserSid, + final String pathConversationSid + ) { + this.pathUserSid = pathUserSid; + this.pathConversationSid = pathConversationSid; + } + + public UserConversationUpdater setNotificationLevel( + final UserConversation.NotificationLevel notificationLevel + ) { + this.notificationLevel = notificationLevel; + return this; + } + + public UserConversationUpdater setLastReadTimestamp( + final ZonedDateTime lastReadTimestamp + ) { + this.lastReadTimestamp = lastReadTimestamp; + return this; + } + + public UserConversationUpdater setLastReadMessageIndex( + final Integer lastReadMessageIndex + ) { + this.lastReadMessageIndex = lastReadMessageIndex; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users/{UserSid}/Conversations/{ConversationSid}"; + + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ConversationSid" + "}", + this.pathConversationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserConversation update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserConversation update(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserConversation content = UserConversation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (notificationLevel != null) { + Serializer.toString( + request, + "NotificationLevel", + notificationLevel, + ParameterType.URLENCODED + ); + } + + if (lastReadTimestamp != null) { + Serializer.toString( + request, + "LastReadTimestamp", + lastReadTimestamp, + ParameterType.URLENCODED + ); + } + + if (lastReadMessageIndex != null) { + Serializer.toString( + request, + "LastReadMessageIndex", + lastReadMessageIndex, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/Action.java b/src/main/java/com/twilio/rest/conversations/v2/Action.java new file mode 100644 index 0000000000..f74511e58b --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/Action.java @@ -0,0 +1,1002 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Action extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateActionResponse extends Resource { + + @Getter + private final ZonedDateTime completedAt; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String failureReason; + + @Getter + private final String id; + + @Getter + private final Map related; + + @Getter + private final Action.ConversationsV2ActionStatus status; + + @Getter + private final String type; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private CreateActionResponse( + @JsonProperty("completedAt") final ZonedDateTime completedAt, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("failureReason") final String failureReason, + @JsonProperty("id") final String id, + @JsonProperty("related") final Map related, + @JsonProperty( + "status" + ) final Action.ConversationsV2ActionStatus status, + @JsonProperty("type") final String type, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.completedAt = completedAt; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.failureReason = failureReason; + this.id = id; + this.related = related; + this.status = status; + this.type = type; + this.updatedAt = updatedAt; + } + + public static CreateActionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateActionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateActionResponse other = (CreateActionResponse) o; + return ( + Objects.equals(completedAt, other.completedAt) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(id, other.id) && + Objects.equals(related, other.related) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + completedAt, + conversationId, + createdAt, + failureReason, + id, + related, + status, + type, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateActionResponse extends Resource { + + @JsonCreator + private UpdateActionResponse() {} + + public static UpdateActionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateActionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateActionResponse other = (UpdateActionResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteActionResponse extends Resource { + + @JsonCreator + private DeleteActionResponse() {} + + public static DeleteActionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteActionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteActionResponse other = (DeleteActionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListActionResponse extends Resource { + + @JsonCreator + private ListActionResponse() {} + + public static ListActionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListActionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListActionResponse other = (ListActionResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchActionResponse extends Resource { + + @JsonCreator + private PatchActionResponse() {} + + public static PatchActionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchActionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchActionResponse other = (PatchActionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchActionResponse extends Resource { + + @Getter + private final ZonedDateTime completedAt; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String failureReason; + + @Getter + private final String id; + + @Getter + private final Map related; + + @Getter + private final Action.ConversationsV2ActionStatus status; + + @Getter + private final String type; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchActionResponse( + @JsonProperty("completedAt") final ZonedDateTime completedAt, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("failureReason") final String failureReason, + @JsonProperty("id") final String id, + @JsonProperty("related") final Map related, + @JsonProperty( + "status" + ) final Action.ConversationsV2ActionStatus status, + @JsonProperty("type") final String type, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.completedAt = completedAt; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.failureReason = failureReason; + this.id = id; + this.related = related; + this.status = status; + this.type = type; + this.updatedAt = updatedAt; + } + + public static FetchActionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchActionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchActionResponse other = (FetchActionResponse) o; + return ( + Objects.equals(completedAt, other.completedAt) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(id, other.id) && + Objects.equals(related, other.related) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + completedAt, + conversationId, + createdAt, + failureReason, + id, + related, + status, + type, + updatedAt + ); + } + } + + public static ActionCreator creator( + final String pathConversationId, + final Action.CreateConversationActionRequest createConversationActionRequest + ) { + return new ActionCreator( + pathConversationId, + createConversationActionRequest + ); + } + + public static ActionFetcher fetcher( + final String pathConversationId, + final String pathActionId + ) { + return new ActionFetcher(pathConversationId, pathActionId); + } + + public enum ConversationsV2Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + VIDEO("VIDEO"); + + private final String value; + + private ConversationsV2Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2Channel forValue(final String value) { + return Promoter.enumFromString( + value, + ConversationsV2Channel.values() + ); + } + } + + public enum ConversationsV2ActionStatus { + PENDING("PENDING"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private ConversationsV2ActionStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2ActionStatus forValue(final String value) { + return Promoter.enumFromString( + value, + ConversationsV2ActionStatus.values() + ); + } + } + + @JsonDeserialize(builder = CreateConversationActionRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationActionRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("payload") + @Getter + private final ConversationsV2SendMessagePayload payload; + + private CreateConversationActionRequest(Builder builder) { + this.type = builder.type; + this.payload = builder.payload; + } + + public static Builder builder( + final String type, + final ConversationsV2SendMessagePayload payload + ) { + return new Builder(type, payload); + } + + public static CreateConversationActionRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationActionRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private String type; + + @JsonProperty("payload") + private ConversationsV2SendMessagePayload payload; + + @JsonCreator + public Builder( + @JsonProperty("type") final String type, + @JsonProperty( + "payload" + ) final ConversationsV2SendMessagePayload payload + ) { + this.type = type; + this.payload = payload; + } + + public CreateConversationActionRequest build() { + return new CreateConversationActionRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationActionRequest other = + (CreateConversationActionRequest) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(payload, other.payload) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, payload); + } + } + + @JsonDeserialize(builder = ConversationsV2SendMessagePayload.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2SendMessagePayload { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("from") + @Getter + private final ConversationsV2SendMessageParticipant from; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + @Getter + private final List to; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final ConversationsV2SendMessageContent content; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + @Getter + private final Map channelSettings; + + private ConversationsV2SendMessagePayload(Builder builder) { + this.from = builder.from; + this.to = builder.to; + this.content = builder.content; + this.channelSettings = builder.channelSettings; + } + + public static Builder builder( + final ConversationsV2SendMessageParticipant from, + final List to, + final ConversationsV2SendMessageContent content + ) { + return new Builder(from, to, content); + } + + public static ConversationsV2SendMessagePayload fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2SendMessagePayload.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("from") + private ConversationsV2SendMessageParticipant from; + + @JsonProperty("to") + private List to; + + @JsonProperty("content") + private ConversationsV2SendMessageContent content; + + @JsonProperty("channelSettings") + private Map channelSettings; + + @JsonCreator + public Builder( + @JsonProperty( + "from" + ) final ConversationsV2SendMessageParticipant from, + @JsonProperty("to") final List< + ConversationsV2SendMessageParticipant + > to, + @JsonProperty( + "content" + ) final ConversationsV2SendMessageContent content + ) { + this.from = from; + this.to = to; + this.content = content; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + public Builder channelSettings( + Map channelSettings + ) { + this.channelSettings = channelSettings; + return this; + } + + public ConversationsV2SendMessagePayload build() { + return new ConversationsV2SendMessagePayload(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2SendMessagePayload other = + (ConversationsV2SendMessagePayload) o; + return ( + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(content, other.content) && + Objects.equals(channelSettings, other.channelSettings) + ); + } + + @Override + public int hashCode() { + return Objects.hash(from, to, content, channelSettings); + } + } + + @JsonDeserialize(builder = ConversationsV2SendMessageContent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2SendMessageContent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + @Getter + private final String text; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("contentId") + @Getter + private final String contentId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("variables") + @Getter + private final Map variables; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mediaUrls") + @Getter + private final List mediaUrls; + + private ConversationsV2SendMessageContent(Builder builder) { + this.text = builder.text; + this.contentId = builder.contentId; + this.variables = builder.variables; + this.mediaUrls = builder.mediaUrls; + } + + public static Builder builder() { + return new Builder(); + } + + public static ConversationsV2SendMessageContent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2SendMessageContent.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("text") + private String text; + + @JsonProperty("contentId") + private String contentId; + + @JsonProperty("variables") + private Map variables; + + @JsonProperty("mediaUrls") + private List mediaUrls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + public Builder text(String text) { + this.text = text; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("contentId") + public Builder contentId(String contentId) { + this.contentId = contentId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("variables") + public Builder variables(Map variables) { + this.variables = variables; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mediaUrls") + public Builder mediaUrls(List mediaUrls) { + this.mediaUrls = mediaUrls; + return this; + } + + public ConversationsV2SendMessageContent build() { + return new ConversationsV2SendMessageContent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2SendMessageContent other = + (ConversationsV2SendMessageContent) o; + return ( + Objects.equals(text, other.text) && + Objects.equals(contentId, other.contentId) && + Objects.equals(variables, other.variables) && + Objects.equals(mediaUrls, other.mediaUrls) + ); + } + + @Override + public int hashCode() { + return Objects.hash(text, contentId, variables, mediaUrls); + } + } + + @JsonDeserialize( + builder = ConversationsV2SendMessageParticipant.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2SendMessageParticipant { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + @Getter + private final String participantId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Action.ConversationsV2Channel channel; + + private ConversationsV2SendMessageParticipant(Builder builder) { + this.participantId = builder.participantId; + this.address = builder.address; + this.channel = builder.channel; + } + + public static Builder builder() { + return new Builder(); + } + + public static ConversationsV2SendMessageParticipant fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2SendMessageParticipant.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("participantId") + private String participantId; + + @JsonProperty("address") + private String address; + + @JsonProperty("channel") + private Action.ConversationsV2Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + public Builder participantId(String participantId) { + this.participantId = participantId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + public Builder address(String address) { + this.address = address; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + public Builder channel(Action.ConversationsV2Channel channel) { + this.channel = channel; + return this; + } + + public ConversationsV2SendMessageParticipant build() { + return new ConversationsV2SendMessageParticipant(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2SendMessageParticipant other = + (ConversationsV2SendMessageParticipant) o; + return ( + Objects.equals(participantId, other.participantId) && + Objects.equals(address, other.address) && + Objects.equals(channel, other.channel) + ); + } + + @Override + public int hashCode() { + return Objects.hash(participantId, address, channel); + } + } + + /** + * Converts a JSON String into a Action object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Action object represented by the provided JSON + */ + public static Action fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Action.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Action object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Action object represented by the provided JSON + */ + public static Action fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Action.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Action() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ActionCreator.java b/src/main/java/com/twilio/rest/conversations/v2/ActionCreator.java new file mode 100644 index 0000000000..d2e937ce35 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ActionCreator.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ActionCreator extends Creator { + + private String pathConversationId; + private Action.CreateConversationActionRequest createConversationActionRequest; + + public ActionCreator( + final String pathConversationId, + final Action.CreateConversationActionRequest createConversationActionRequest + ) { + this.pathConversationId = pathConversationId; + this.createConversationActionRequest = createConversationActionRequest; + } + + public ActionCreator setCreateConversationActionRequest( + final Action.CreateConversationActionRequest createConversationActionRequest + ) { + this.createConversationActionRequest = createConversationActionRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Actions"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Action creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Action.CreateActionResponse create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Action.CreateActionResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Action.CreateActionResponse content = + Action.CreateActionResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createConversationActionRequest != null) { + request.setBody( + Action.toJson(createConversationActionRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ActionFetcher.java b/src/main/java/com/twilio/rest/conversations/v2/ActionFetcher.java new file mode 100644 index 0000000000..76f5156e1a --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ActionFetcher.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ActionFetcher extends Fetcher { + + private String pathConversationId; + private String pathActionId; + + public ActionFetcher( + final String pathConversationId, + final String pathActionId + ) { + this.pathConversationId = pathConversationId; + this.pathActionId = pathActionId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Actions/{ActionId}"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + path = + path.replace("{" + "ActionId" + "}", this.pathActionId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Action fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Action.FetchActionResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Action.FetchActionResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Action.FetchActionResponse content = + Action.FetchActionResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/Communication.java b/src/main/java/com/twilio/rest/conversations/v2/Communication.java new file mode 100644 index 0000000000..e87eb1f2ec --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/Communication.java @@ -0,0 +1,2409 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Communication extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateCommunicationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final ConversationsV2ParticipantAddress author; + + @Getter + private final String channelId; + + @Getter + private final ListCommunicationByConversation200ResponseCommunicationsContent content; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final ZonedDateTime occurredAt; + + @Getter + private final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients; + + @Getter + private final String resourceId; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private CreateCommunicationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty( + "author" + ) final ConversationsV2ParticipantAddress author, + @JsonProperty("channelId") final String channelId, + @JsonProperty( + "content" + ) final ListCommunicationByConversation200ResponseCommunicationsContent content, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("recipients") final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients, + @JsonProperty("resourceId") final String resourceId, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.author = author; + this.channelId = channelId; + this.content = content; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.occurredAt = occurredAt; + this.recipients = recipients; + this.resourceId = resourceId; + this.updatedAt = updatedAt; + } + + public static CreateCommunicationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateCommunicationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateCommunicationResponse other = (CreateCommunicationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(author, other.author) && + Objects.equals(channelId, other.channelId) && + Objects.equals(content, other.content) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(recipients, other.recipients) && + Objects.equals(resourceId, other.resourceId) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + author, + channelId, + content, + conversationId, + createdAt, + id, + occurredAt, + recipients, + resourceId, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateCommunicationResponse extends Resource { + + @JsonCreator + private UpdateCommunicationResponse() {} + + public static UpdateCommunicationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateCommunicationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateCommunicationResponse other = (UpdateCommunicationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteCommunicationResponse extends Resource { + + @JsonCreator + private DeleteCommunicationResponse() {} + + public static DeleteCommunicationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteCommunicationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteCommunicationResponse other = (DeleteCommunicationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListCommunicationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final ConversationsV2ParticipantAddress author; + + @Getter + private final String channelId; + + @Getter + private final ListCommunicationByConversation200ResponseCommunicationsContent content; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final ZonedDateTime occurredAt; + + @Getter + private final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients; + + @Getter + private final String resourceId; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListCommunicationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty( + "author" + ) final ConversationsV2ParticipantAddress author, + @JsonProperty("channelId") final String channelId, + @JsonProperty( + "content" + ) final ListCommunicationByConversation200ResponseCommunicationsContent content, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("recipients") final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients, + @JsonProperty("resourceId") final String resourceId, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.author = author; + this.channelId = channelId; + this.content = content; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.occurredAt = occurredAt; + this.recipients = recipients; + this.resourceId = resourceId; + this.updatedAt = updatedAt; + } + + public static ListCommunicationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListCommunicationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListCommunicationResponse other = (ListCommunicationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(author, other.author) && + Objects.equals(channelId, other.channelId) && + Objects.equals(content, other.content) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(recipients, other.recipients) && + Objects.equals(resourceId, other.resourceId) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + author, + channelId, + content, + conversationId, + createdAt, + id, + occurredAt, + recipients, + resourceId, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchCommunicationResponse extends Resource { + + @JsonCreator + private PatchCommunicationResponse() {} + + public static PatchCommunicationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchCommunicationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchCommunicationResponse other = (PatchCommunicationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchCommunicationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final ConversationsV2ParticipantAddress author; + + @Getter + private final String channelId; + + @Getter + private final ListCommunicationByConversation200ResponseCommunicationsContent content; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final ZonedDateTime occurredAt; + + @Getter + private final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients; + + @Getter + private final String resourceId; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchCommunicationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty( + "author" + ) final ConversationsV2ParticipantAddress author, + @JsonProperty("channelId") final String channelId, + @JsonProperty( + "content" + ) final ListCommunicationByConversation200ResponseCommunicationsContent content, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("recipients") final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients, + @JsonProperty("resourceId") final String resourceId, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.author = author; + this.channelId = channelId; + this.content = content; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.occurredAt = occurredAt; + this.recipients = recipients; + this.resourceId = resourceId; + this.updatedAt = updatedAt; + } + + public static FetchCommunicationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchCommunicationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchCommunicationResponse other = (FetchCommunicationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(author, other.author) && + Objects.equals(channelId, other.channelId) && + Objects.equals(content, other.content) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(recipients, other.recipients) && + Objects.equals(resourceId, other.resourceId) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + author, + channelId, + content, + conversationId, + createdAt, + id, + occurredAt, + recipients, + resourceId, + updatedAt + ); + } + } + + public static CommunicationCreator creator( + final String pathConversationId + ) { + return new CommunicationCreator(pathConversationId); + } + + public static CommunicationFetcher fetcher( + final String pathConversationId, + final String pathId + ) { + return new CommunicationFetcher(pathConversationId, pathId); + } + + public static CommunicationReader reader(final String pathConversationId) { + return new CommunicationReader(pathConversationId); + } + + public enum Type { + TEXT("TEXT"), + TRANSCRIPTION("TRANSCRIPTION"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum ConversationsV2Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + VIDEO("VIDEO"); + + private final String value; + + private ConversationsV2Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2Channel forValue(final String value) { + return Promoter.enumFromString( + value, + ConversationsV2Channel.values() + ); + } + } + + public enum Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + VIDEO("VIDEO"); + + private final String value; + + private Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Channel forValue(final String value) { + return Promoter.enumFromString(value, Channel.values()); + } + } + + public enum ConversationsV2RecipientDeliveryStatus { + INITIATED("INITIATED"), + IN_PROGRESS("IN_PROGRESS"), + DELIVERED("DELIVERED"), + READ("READ"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private ConversationsV2RecipientDeliveryStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2RecipientDeliveryStatus forValue( + final String value + ) { + return Promoter.enumFromString( + value, + ConversationsV2RecipientDeliveryStatus.values() + ); + } + } + + @JsonDeserialize(builder = ConversationsV2ParticipantAddress.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2ParticipantAddress { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Communication.ConversationsV2Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + @Getter + private final String participantId; + + private ConversationsV2ParticipantAddress(Builder builder) { + this.address = builder.address; + this.channel = builder.channel; + this.participantId = builder.participantId; + } + + public static Builder builder( + final String address, + final Communication.ConversationsV2Channel channel + ) { + return new Builder(address, channel); + } + + public static ConversationsV2ParticipantAddress fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2ParticipantAddress.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("address") + private String address; + + @JsonProperty("channel") + private Communication.ConversationsV2Channel channel; + + @JsonProperty("participantId") + private String participantId; + + @JsonCreator + public Builder( + @JsonProperty("address") final String address, + @JsonProperty( + "channel" + ) final Communication.ConversationsV2Channel channel + ) { + this.address = address; + this.channel = channel; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + public Builder participantId(String participantId) { + this.participantId = participantId; + return this; + } + + public ConversationsV2ParticipantAddress build() { + return new ConversationsV2ParticipantAddress(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2ParticipantAddress other = + (ConversationsV2ParticipantAddress) o; + return ( + Objects.equals(address, other.address) && + Objects.equals(channel, other.channel) && + Objects.equals(participantId, other.participantId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(address, channel, participantId); + } + } + + @JsonDeserialize( + builder = CreateCommunicationInConversationRequestRecipients.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateCommunicationInConversationRequestRecipients { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Communication.Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + @Getter + private final String participantId; + + private CreateCommunicationInConversationRequestRecipients( + Builder builder + ) { + this.address = builder.address; + this.channel = builder.channel; + this.participantId = builder.participantId; + } + + public static Builder builder( + final String address, + final Communication.Channel channel + ) { + return new Builder(address, channel); + } + + public static CreateCommunicationInConversationRequestRecipients fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateCommunicationInConversationRequestRecipients.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("address") + private String address; + + @JsonProperty("channel") + private Communication.Channel channel; + + @JsonProperty("participantId") + private String participantId; + + @JsonCreator + public Builder( + @JsonProperty("address") final String address, + @JsonProperty("channel") final Communication.Channel channel + ) { + this.address = address; + this.channel = channel; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + public Builder participantId(String participantId) { + this.participantId = participantId; + return this; + } + + public CreateCommunicationInConversationRequestRecipients build() { + return new CreateCommunicationInConversationRequestRecipients( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateCommunicationInConversationRequestRecipients other = + (CreateCommunicationInConversationRequestRecipients) o; + return ( + Objects.equals(address, other.address) && + Objects.equals(channel, other.channel) && + Objects.equals(participantId, other.participantId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(address, channel, participantId); + } + } + + @JsonDeserialize( + builder = ConversationsV2ContentTranscriptionTranscriptionWords.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2ContentTranscriptionTranscriptionWords { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + @Getter + private final String text; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("startTime") + @Getter + private final ZonedDateTime startTime; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("endTime") + @Getter + private final ZonedDateTime endTime; + + private ConversationsV2ContentTranscriptionTranscriptionWords( + Builder builder + ) { + this.text = builder.text; + this.startTime = builder.startTime; + this.endTime = builder.endTime; + } + + public static Builder builder(final String text) { + return new Builder(text); + } + + public static ConversationsV2ContentTranscriptionTranscriptionWords fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2ContentTranscriptionTranscriptionWords.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("text") + private String text; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("startTime") + private ZonedDateTime startTime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("endTime") + private ZonedDateTime endTime; + + @JsonCreator + public Builder(@JsonProperty("text") final String text) { + this.text = text; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("startTime") + public Builder startTime(ZonedDateTime startTime) { + this.startTime = startTime; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("endTime") + public Builder endTime(ZonedDateTime endTime) { + this.endTime = endTime; + return this; + } + + public ConversationsV2ContentTranscriptionTranscriptionWords build() { + return new ConversationsV2ContentTranscriptionTranscriptionWords( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2ContentTranscriptionTranscriptionWords other = + (ConversationsV2ContentTranscriptionTranscriptionWords) o; + return ( + Objects.equals(text, other.text) && + Objects.equals(startTime, other.startTime) && + Objects.equals(endTime, other.endTime) + ); + } + + @Override + public int hashCode() { + return Objects.hash(text, startTime, endTime); + } + } + + @JsonDeserialize( + builder = ListCommunicationByConversation200ResponseCommunicationsContent.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListCommunicationByConversation200ResponseCommunicationsContent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Communication.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + @Getter + private final String text; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("transcription") + @Getter + private final ConversationsV2ContentTranscriptionTranscription transcription; + + private ListCommunicationByConversation200ResponseCommunicationsContent( + Builder builder + ) { + this.type = builder.type; + this.text = builder.text; + this.transcription = builder.transcription; + } + + public static Builder builder() { + return new Builder(); + } + + public static ListCommunicationByConversation200ResponseCommunicationsContent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListCommunicationByConversation200ResponseCommunicationsContent.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Communication.Type type; + + @JsonProperty("text") + private String text; + + @JsonProperty("transcription") + private ConversationsV2ContentTranscriptionTranscription transcription; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Communication.Type type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + public Builder text(String text) { + this.text = text; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("transcription") + public Builder transcription( + ConversationsV2ContentTranscriptionTranscription transcription + ) { + this.transcription = transcription; + return this; + } + + public ListCommunicationByConversation200ResponseCommunicationsContent build() { + return new ListCommunicationByConversation200ResponseCommunicationsContent( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListCommunicationByConversation200ResponseCommunicationsContent other = + (ListCommunicationByConversation200ResponseCommunicationsContent) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(text, other.text) && + Objects.equals(transcription, other.transcription) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, text, transcription); + } + } + + @JsonDeserialize( + builder = ListCommunicationByConversation200ResponseCommunications.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListCommunicationByConversation200ResponseCommunications { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountId") + @Getter + private final String accountId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("author") + @Getter + private final ConversationsV2ParticipantAddress author; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final ListCommunicationByConversation200ResponseCommunicationsContent content; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + @Getter + private final String channelId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resourceId") + @Getter + private final String resourceId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("recipients") + @Getter + private final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + private ListCommunicationByConversation200ResponseCommunications( + Builder builder + ) { + this.id = builder.id; + this.conversationId = builder.conversationId; + this.accountId = builder.accountId; + this.author = builder.author; + this.content = builder.content; + this.channelId = builder.channelId; + this.resourceId = builder.resourceId; + this.recipients = builder.recipients; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.occurredAt = builder.occurredAt; + } + + public static Builder builder( + final String id, + final String conversationId, + final String accountId, + final ConversationsV2ParticipantAddress author, + final ListCommunicationByConversation200ResponseCommunicationsContent content, + final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients + ) { + return new Builder( + id, + conversationId, + accountId, + author, + content, + recipients + ); + } + + public static ListCommunicationByConversation200ResponseCommunications fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListCommunicationByConversation200ResponseCommunications.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonProperty("accountId") + private String accountId; + + @JsonProperty("author") + private ConversationsV2ParticipantAddress author; + + @JsonProperty("content") + private ListCommunicationByConversation200ResponseCommunicationsContent content; + + @JsonProperty("channelId") + private String channelId; + + @JsonProperty("resourceId") + private String resourceId; + + @JsonProperty("recipients") + private List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("accountId") final String accountId, + @JsonProperty( + "author" + ) final ConversationsV2ParticipantAddress author, + @JsonProperty( + "content" + ) final ListCommunicationByConversation200ResponseCommunicationsContent content, + @JsonProperty("recipients") final List< + ListCommunicationByConversation200ResponseCommunicationsRecipients + > recipients + ) { + this.id = id; + this.conversationId = conversationId; + this.accountId = accountId; + this.author = author; + this.content = content; + this.recipients = recipients; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + public Builder channelId(String channelId) { + this.channelId = channelId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resourceId") + public Builder resourceId(String resourceId) { + this.resourceId = resourceId; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + public Builder updatedAt(ZonedDateTime updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + public Builder occurredAt(ZonedDateTime occurredAt) { + this.occurredAt = occurredAt; + return this; + } + + public ListCommunicationByConversation200ResponseCommunications build() { + return new ListCommunicationByConversation200ResponseCommunications( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListCommunicationByConversation200ResponseCommunications other = + (ListCommunicationByConversation200ResponseCommunications) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(accountId, other.accountId) && + Objects.equals(author, other.author) && + Objects.equals(content, other.content) && + Objects.equals(channelId, other.channelId) && + Objects.equals(resourceId, other.resourceId) && + Objects.equals(recipients, other.recipients) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(occurredAt, other.occurredAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + conversationId, + accountId, + author, + content, + channelId, + resourceId, + recipients, + createdAt, + updatedAt, + occurredAt + ); + } + } + + @JsonDeserialize( + builder = CreateCommunicationInConversationRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateCommunicationInConversationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("author") + @Getter + private final CreateCommunicationInConversationRequestAuthor author; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final CreateCommunicationInConversationRequestContent content; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + @Getter + private final String channelId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resourceId") + @Getter + private final String resourceId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("recipients") + @Getter + private final List< + CreateCommunicationInConversationRequestRecipients + > recipients; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + private CreateCommunicationInConversationRequest(Builder builder) { + this.author = builder.author; + this.content = builder.content; + this.channelId = builder.channelId; + this.resourceId = builder.resourceId; + this.recipients = builder.recipients; + this.occurredAt = builder.occurredAt; + } + + public static Builder builder( + final CreateCommunicationInConversationRequestAuthor author, + final CreateCommunicationInConversationRequestContent content, + final List< + CreateCommunicationInConversationRequestRecipients + > recipients + ) { + return new Builder(author, content, recipients); + } + + public static CreateCommunicationInConversationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateCommunicationInConversationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("author") + private CreateCommunicationInConversationRequestAuthor author; + + @JsonProperty("content") + private CreateCommunicationInConversationRequestContent content; + + @JsonProperty("channelId") + private String channelId; + + @JsonProperty("resourceId") + private String resourceId; + + @JsonProperty("recipients") + private List< + CreateCommunicationInConversationRequestRecipients + > recipients; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonCreator + public Builder( + @JsonProperty( + "author" + ) final CreateCommunicationInConversationRequestAuthor author, + @JsonProperty( + "content" + ) final CreateCommunicationInConversationRequestContent content, + @JsonProperty("recipients") final List< + CreateCommunicationInConversationRequestRecipients + > recipients + ) { + this.author = author; + this.content = content; + this.recipients = recipients; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + public Builder channelId(String channelId) { + this.channelId = channelId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resourceId") + public Builder resourceId(String resourceId) { + this.resourceId = resourceId; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + public Builder occurredAt(ZonedDateTime occurredAt) { + this.occurredAt = occurredAt; + return this; + } + + public CreateCommunicationInConversationRequest build() { + return new CreateCommunicationInConversationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateCommunicationInConversationRequest other = + (CreateCommunicationInConversationRequest) o; + return ( + Objects.equals(author, other.author) && + Objects.equals(content, other.content) && + Objects.equals(channelId, other.channelId) && + Objects.equals(resourceId, other.resourceId) && + Objects.equals(recipients, other.recipients) && + Objects.equals(occurredAt, other.occurredAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + author, + content, + channelId, + resourceId, + recipients, + occurredAt + ); + } + } + + @JsonDeserialize( + builder = ConversationsV2ContentTranscriptionTranscription.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2ContentTranscriptionTranscription { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Integer channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("confidence") + @Getter + private final Float confidence; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("engine") + @Getter + private final String engine; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words") + @Getter + private final List< + ConversationsV2ContentTranscriptionTranscriptionWords + > words; + + private ConversationsV2ContentTranscriptionTranscription( + Builder builder + ) { + this.channel = builder.channel; + this.confidence = builder.confidence; + this.engine = builder.engine; + this.words = builder.words; + } + + public static Builder builder() { + return new Builder(); + } + + public static ConversationsV2ContentTranscriptionTranscription fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2ContentTranscriptionTranscription.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("channel") + private Integer channel; + + @JsonProperty("confidence") + private Float confidence; + + @JsonProperty("engine") + private String engine; + + @JsonProperty("words") + private List< + ConversationsV2ContentTranscriptionTranscriptionWords + > words; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + public Builder channel(Integer channel) { + this.channel = channel; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("confidence") + public Builder confidence(Float confidence) { + this.confidence = confidence; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("engine") + public Builder engine(String engine) { + this.engine = engine; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words") + public Builder words( + List< + ConversationsV2ContentTranscriptionTranscriptionWords + > words + ) { + this.words = words; + return this; + } + + public ConversationsV2ContentTranscriptionTranscription build() { + return new ConversationsV2ContentTranscriptionTranscription( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2ContentTranscriptionTranscription other = + (ConversationsV2ContentTranscriptionTranscription) o; + return ( + Objects.equals(channel, other.channel) && + Objects.equals(confidence, other.confidence) && + Objects.equals(engine, other.engine) && + Objects.equals(words, other.words) + ); + } + + @Override + public int hashCode() { + return Objects.hash(channel, confidence, engine, words); + } + } + + @JsonDeserialize( + builder = CreateCommunicationInConversationRequestAuthor.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateCommunicationInConversationRequestAuthor { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Communication.Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + @Getter + private final String participantId; + + private CreateCommunicationInConversationRequestAuthor( + Builder builder + ) { + this.address = builder.address; + this.channel = builder.channel; + this.participantId = builder.participantId; + } + + public static Builder builder( + final String address, + final Communication.Channel channel + ) { + return new Builder(address, channel); + } + + public static CreateCommunicationInConversationRequestAuthor fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateCommunicationInConversationRequestAuthor.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("address") + private String address; + + @JsonProperty("channel") + private Communication.Channel channel; + + @JsonProperty("participantId") + private String participantId; + + @JsonCreator + public Builder( + @JsonProperty("address") final String address, + @JsonProperty("channel") final Communication.Channel channel + ) { + this.address = address; + this.channel = channel; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + public Builder participantId(String participantId) { + this.participantId = participantId; + return this; + } + + public CreateCommunicationInConversationRequestAuthor build() { + return new CreateCommunicationInConversationRequestAuthor(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateCommunicationInConversationRequestAuthor other = + (CreateCommunicationInConversationRequestAuthor) o; + return ( + Objects.equals(address, other.address) && + Objects.equals(channel, other.channel) && + Objects.equals(participantId, other.participantId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(address, channel, participantId); + } + } + + @JsonDeserialize( + builder = ListCommunicationByConversation200ResponseCommunicationsRecipients.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListCommunicationByConversation200ResponseCommunicationsRecipients { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Communication.ConversationsV2Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + @Getter + private final String participantId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("deliveryStatus") + @Getter + private final Communication.ConversationsV2RecipientDeliveryStatus deliveryStatus; + + private ListCommunicationByConversation200ResponseCommunicationsRecipients( + Builder builder + ) { + this.address = builder.address; + this.channel = builder.channel; + this.participantId = builder.participantId; + this.deliveryStatus = builder.deliveryStatus; + } + + public static Builder builder( + final String address, + final Communication.ConversationsV2Channel channel + ) { + return new Builder(address, channel); + } + + public static ListCommunicationByConversation200ResponseCommunicationsRecipients fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListCommunicationByConversation200ResponseCommunicationsRecipients.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("address") + private String address; + + @JsonProperty("channel") + private Communication.ConversationsV2Channel channel; + + @JsonProperty("participantId") + private String participantId; + + @JsonProperty("deliveryStatus") + private Communication.ConversationsV2RecipientDeliveryStatus deliveryStatus; + + @JsonCreator + public Builder( + @JsonProperty("address") final String address, + @JsonProperty( + "channel" + ) final Communication.ConversationsV2Channel channel + ) { + this.address = address; + this.channel = channel; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + public Builder participantId(String participantId) { + this.participantId = participantId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("deliveryStatus") + public Builder deliveryStatus( + Communication.ConversationsV2RecipientDeliveryStatus deliveryStatus + ) { + this.deliveryStatus = deliveryStatus; + return this; + } + + public ListCommunicationByConversation200ResponseCommunicationsRecipients build() { + return new ListCommunicationByConversation200ResponseCommunicationsRecipients( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListCommunicationByConversation200ResponseCommunicationsRecipients other = + (ListCommunicationByConversation200ResponseCommunicationsRecipients) o; + return ( + Objects.equals(address, other.address) && + Objects.equals(channel, other.channel) && + Objects.equals(participantId, other.participantId) && + Objects.equals(deliveryStatus, other.deliveryStatus) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + address, + channel, + participantId, + deliveryStatus + ); + } + } + + @JsonDeserialize( + builder = ListCommunicationByConversation200ResponseMeta.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListCommunicationByConversation200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListCommunicationByConversation200ResponseMeta( + Builder builder + ) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static ListCommunicationByConversation200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListCommunicationByConversation200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListCommunicationByConversation200ResponseMeta build() { + return new ListCommunicationByConversation200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListCommunicationByConversation200ResponseMeta other = + (ListCommunicationByConversation200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize(builder = ContentTranscriptionTranscription.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ContentTranscriptionTranscription { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Integer channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("confidence") + @Getter + private final BigDecimal confidence; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("engine") + @Getter + private final String engine; + + private ContentTranscriptionTranscription(Builder builder) { + this.channel = builder.channel; + this.confidence = builder.confidence; + this.engine = builder.engine; + } + + public static Builder builder() { + return new Builder(); + } + + public static ContentTranscriptionTranscription fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ContentTranscriptionTranscription.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("channel") + private Integer channel; + + @JsonProperty("confidence") + private BigDecimal confidence; + + @JsonProperty("engine") + private String engine; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + public Builder channel(Integer channel) { + this.channel = channel; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("confidence") + public Builder confidence(BigDecimal confidence) { + this.confidence = confidence; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("engine") + public Builder engine(String engine) { + this.engine = engine; + return this; + } + + public ContentTranscriptionTranscription build() { + return new ContentTranscriptionTranscription(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContentTranscriptionTranscription other = + (ContentTranscriptionTranscription) o; + return ( + Objects.equals(channel, other.channel) && + Objects.equals(confidence, other.confidence) && + Objects.equals(engine, other.engine) + ); + } + + @Override + public int hashCode() { + return Objects.hash(channel, confidence, engine); + } + } + + @JsonDeserialize( + builder = CreateCommunicationInConversationRequestContent.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateCommunicationInConversationRequestContent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Communication.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + @Getter + private final String text; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("transcription") + @Getter + private final ContentTranscriptionTranscription transcription; + + private CreateCommunicationInConversationRequestContent( + Builder builder + ) { + this.type = builder.type; + this.text = builder.text; + this.transcription = builder.transcription; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateCommunicationInConversationRequestContent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateCommunicationInConversationRequestContent.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Communication.Type type; + + @JsonProperty("text") + private String text; + + @JsonProperty("transcription") + private ContentTranscriptionTranscription transcription; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Communication.Type type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + public Builder text(String text) { + this.text = text; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("transcription") + public Builder transcription( + ContentTranscriptionTranscription transcription + ) { + this.transcription = transcription; + return this; + } + + public CreateCommunicationInConversationRequestContent build() { + return new CreateCommunicationInConversationRequestContent( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateCommunicationInConversationRequestContent other = + (CreateCommunicationInConversationRequestContent) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(text, other.text) && + Objects.equals(transcription, other.transcription) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, text, transcription); + } + } + + /** + * Converts a JSON String into a Communication object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Communication object represented by the provided JSON + */ + public static Communication fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Communication.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Communication object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Communication object represented by the provided JSON + */ + public static Communication fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Communication.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Communication() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/CommunicationCreator.java b/src/main/java/com/twilio/rest/conversations/v2/CommunicationCreator.java new file mode 100644 index 0000000000..7126efe020 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/CommunicationCreator.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CommunicationCreator + extends Creator { + + private String pathConversationId; + private Communication.CreateCommunicationInConversationRequest createCommunicationInConversationRequest; + + public CommunicationCreator(final String pathConversationId) { + this.pathConversationId = pathConversationId; + } + + public CommunicationCreator setCreateCommunicationInConversationRequest( + final Communication.CreateCommunicationInConversationRequest createCommunicationInConversationRequest + ) { + this.createCommunicationInConversationRequest = + createCommunicationInConversationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Communications"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Communication creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Communication.CreateCommunicationResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Communication.CreateCommunicationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Communication.CreateCommunicationResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Communication.CreateCommunicationResponse content = + Communication.CreateCommunicationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createCommunicationInConversationRequest != null) { + request.setBody( + Communication.toJson( + createCommunicationInConversationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/CommunicationFetcher.java b/src/main/java/com/twilio/rest/conversations/v2/CommunicationFetcher.java new file mode 100644 index 0000000000..07f886152d --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/CommunicationFetcher.java @@ -0,0 +1,110 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CommunicationFetcher + extends Fetcher { + + private String pathConversationId; + private String pathId; + + public CommunicationFetcher( + final String pathConversationId, + final String pathId + ) { + this.pathConversationId = pathConversationId; + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Communications/{id}"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Communication fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Communication.FetchCommunicationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Communication.FetchCommunicationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Communication.FetchCommunicationResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Communication.FetchCommunicationResponse content = + Communication.FetchCommunicationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/CommunicationReader.java b/src/main/java/com/twilio/rest/conversations/v2/CommunicationReader.java new file mode 100644 index 0000000000..c7f1682d0c --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/CommunicationReader.java @@ -0,0 +1,277 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CommunicationReader + extends Reader { + + private String pathConversationId; + private String channelId; + private Integer pageSize; + private String pageToken; + + public CommunicationReader(final String pathConversationId) { + this.pathConversationId = pathConversationId; + } + + public CommunicationReader setChannelId(final String channelId) { + this.channelId = channelId; + return this; + } + + public CommunicationReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public CommunicationReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse< + Communication.ListCommunicationResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "communications", + response.getContent(), + Communication.ListCommunicationResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Communications"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "communications", + response.getContent(), + Communication.ListCommunicationResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Communication read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "communications", + response.getContent(), + Communication.ListCommunicationResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/Conversations/{ConversationId}/Communications"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/Conversations/{ConversationId}/Communications"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (channelId != null) { + Serializer.toString( + request, + "channelId", + channelId, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/Configuration.java b/src/main/java/com/twilio/rest/conversations/v2/Configuration.java new file mode 100644 index 0000000000..63c417c22c --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/Configuration.java @@ -0,0 +1,3592 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Configuration extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateConfigurationResponse extends Resource { + + @Getter + private final Map related; + + @Getter + private final URI statusUrl; + + @JsonCreator + private CreateConfigurationResponse( + @JsonProperty("related") final Map related, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.related = related; + this.statusUrl = statusUrl; + } + + public static CreateConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateConfigurationResponse other = (CreateConfigurationResponse) o; + return ( + Objects.equals(related, other.related) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(related, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateConfigurationResponse extends Resource { + + @Getter + private final Map related; + + @Getter + private final URI statusUrl; + + @JsonCreator + private UpdateConfigurationResponse( + @JsonProperty("related") final Map related, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.related = related; + this.statusUrl = statusUrl; + } + + public static UpdateConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateConfigurationResponse other = (UpdateConfigurationResponse) o; + return ( + Objects.equals(related, other.related) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(related, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteConfigurationResponse extends Resource { + + @Getter + private final Map related; + + @Getter + private final URI statusUrl; + + @JsonCreator + private DeleteConfigurationResponse( + @JsonProperty("related") final Map related, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.related = related; + this.statusUrl = statusUrl; + } + + public static DeleteConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteConfigurationResponse other = (DeleteConfigurationResponse) o; + return ( + Objects.equals(related, other.related) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(related, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListConfigurationResponse extends Resource { + + @Getter + private final Map< + String, + ConversationsV2ChannelSetting + > channelSettings; + + @Getter + private final Configuration.ConversationsV2ConversationGroupingType conversationGroupingType; + + @Getter + private final ConversationsV2ConversationsV1Bridge conversationsV1Bridge; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final List intelligenceConfigurationIds; + + @Getter + private final Boolean memoryExtractionEnabled; + + @Getter + private final String memoryStoreId; + + @Getter + private final List observationExtractionStrategyIds; + + @Getter + private final String redactionConfigurationId; + + @Getter + private final List statusCallbacks; + + @Getter + private final List traitExtractionStrategyIds; + + @Getter + private final ZonedDateTime updatedAt; + + @Getter + private final Long version; + + @JsonCreator + private ListConfigurationResponse( + @JsonProperty("channelSettings") final Map< + String, + ConversationsV2ChannelSetting + > channelSettings, + @JsonProperty( + "conversationGroupingType" + ) final Configuration.ConversationsV2ConversationGroupingType conversationGroupingType, + @JsonProperty( + "conversationsV1Bridge" + ) final ConversationsV2ConversationsV1Bridge conversationsV1Bridge, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("intelligenceConfigurationIds") final List< + String + > intelligenceConfigurationIds, + @JsonProperty( + "memoryExtractionEnabled" + ) final Boolean memoryExtractionEnabled, + @JsonProperty("memoryStoreId") final String memoryStoreId, + @JsonProperty("observationExtractionStrategyIds") final List< + String + > observationExtractionStrategyIds, + @JsonProperty( + "redactionConfigurationId" + ) final String redactionConfigurationId, + @JsonProperty("statusCallbacks") final List< + ConversationsV2StatusCallbackConfig + > statusCallbacks, + @JsonProperty("traitExtractionStrategyIds") final List< + String + > traitExtractionStrategyIds, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("version") final Long version + ) { + this.channelSettings = channelSettings; + this.conversationGroupingType = conversationGroupingType; + this.conversationsV1Bridge = conversationsV1Bridge; + this.createdAt = createdAt; + this.description = description; + this.displayName = displayName; + this.id = id; + this.intelligenceConfigurationIds = intelligenceConfigurationIds; + this.memoryExtractionEnabled = memoryExtractionEnabled; + this.memoryStoreId = memoryStoreId; + this.observationExtractionStrategyIds = + observationExtractionStrategyIds; + this.redactionConfigurationId = redactionConfigurationId; + this.statusCallbacks = statusCallbacks; + this.traitExtractionStrategyIds = traitExtractionStrategyIds; + this.updatedAt = updatedAt; + this.version = version; + } + + public static ListConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListConfigurationResponse other = (ListConfigurationResponse) o; + return ( + Objects.equals(channelSettings, other.channelSettings) && + Objects.equals( + conversationGroupingType, + other.conversationGroupingType + ) && + Objects.equals( + conversationsV1Bridge, + other.conversationsV1Bridge + ) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + memoryExtractionEnabled, + other.memoryExtractionEnabled + ) && + Objects.equals(memoryStoreId, other.memoryStoreId) && + Objects.equals( + observationExtractionStrategyIds, + other.observationExtractionStrategyIds + ) && + Objects.equals( + redactionConfigurationId, + other.redactionConfigurationId + ) && + Objects.equals(statusCallbacks, other.statusCallbacks) && + Objects.equals( + traitExtractionStrategyIds, + other.traitExtractionStrategyIds + ) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + channelSettings, + conversationGroupingType, + conversationsV1Bridge, + createdAt, + description, + displayName, + id, + intelligenceConfigurationIds, + memoryExtractionEnabled, + memoryStoreId, + observationExtractionStrategyIds, + redactionConfigurationId, + statusCallbacks, + traitExtractionStrategyIds, + updatedAt, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchConfigurationResponse extends Resource { + + @Getter + private final Map related; + + @Getter + private final URI statusUrl; + + @JsonCreator + private PatchConfigurationResponse( + @JsonProperty("related") final Map related, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.related = related; + this.statusUrl = statusUrl; + } + + public static PatchConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchConfigurationResponse other = (PatchConfigurationResponse) o; + return ( + Objects.equals(related, other.related) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(related, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchConfigurationResponse extends Resource { + + @Getter + private final Map< + String, + ConversationsV2ChannelSetting + > channelSettings; + + @Getter + private final Configuration.ConversationsV2ConversationGroupingType conversationGroupingType; + + @Getter + private final ConversationsV2ConversationsV1Bridge conversationsV1Bridge; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final List intelligenceConfigurationIds; + + @Getter + private final Boolean memoryExtractionEnabled; + + @Getter + private final String memoryStoreId; + + @Getter + private final List observationExtractionStrategyIds; + + @Getter + private final String redactionConfigurationId; + + @Getter + private final List statusCallbacks; + + @Getter + private final List traitExtractionStrategyIds; + + @Getter + private final ZonedDateTime updatedAt; + + @Getter + private final Long version; + + @JsonCreator + private FetchConfigurationResponse( + @JsonProperty("channelSettings") final Map< + String, + ConversationsV2ChannelSetting + > channelSettings, + @JsonProperty( + "conversationGroupingType" + ) final Configuration.ConversationsV2ConversationGroupingType conversationGroupingType, + @JsonProperty( + "conversationsV1Bridge" + ) final ConversationsV2ConversationsV1Bridge conversationsV1Bridge, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("intelligenceConfigurationIds") final List< + String + > intelligenceConfigurationIds, + @JsonProperty( + "memoryExtractionEnabled" + ) final Boolean memoryExtractionEnabled, + @JsonProperty("memoryStoreId") final String memoryStoreId, + @JsonProperty("observationExtractionStrategyIds") final List< + String + > observationExtractionStrategyIds, + @JsonProperty( + "redactionConfigurationId" + ) final String redactionConfigurationId, + @JsonProperty("statusCallbacks") final List< + ConversationsV2StatusCallbackConfig + > statusCallbacks, + @JsonProperty("traitExtractionStrategyIds") final List< + String + > traitExtractionStrategyIds, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("version") final Long version + ) { + this.channelSettings = channelSettings; + this.conversationGroupingType = conversationGroupingType; + this.conversationsV1Bridge = conversationsV1Bridge; + this.createdAt = createdAt; + this.description = description; + this.displayName = displayName; + this.id = id; + this.intelligenceConfigurationIds = intelligenceConfigurationIds; + this.memoryExtractionEnabled = memoryExtractionEnabled; + this.memoryStoreId = memoryStoreId; + this.observationExtractionStrategyIds = + observationExtractionStrategyIds; + this.redactionConfigurationId = redactionConfigurationId; + this.statusCallbacks = statusCallbacks; + this.traitExtractionStrategyIds = traitExtractionStrategyIds; + this.updatedAt = updatedAt; + this.version = version; + } + + public static FetchConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchConfigurationResponse other = (FetchConfigurationResponse) o; + return ( + Objects.equals(channelSettings, other.channelSettings) && + Objects.equals( + conversationGroupingType, + other.conversationGroupingType + ) && + Objects.equals( + conversationsV1Bridge, + other.conversationsV1Bridge + ) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + memoryExtractionEnabled, + other.memoryExtractionEnabled + ) && + Objects.equals(memoryStoreId, other.memoryStoreId) && + Objects.equals( + observationExtractionStrategyIds, + other.observationExtractionStrategyIds + ) && + Objects.equals( + redactionConfigurationId, + other.redactionConfigurationId + ) && + Objects.equals(statusCallbacks, other.statusCallbacks) && + Objects.equals( + traitExtractionStrategyIds, + other.traitExtractionStrategyIds + ) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + channelSettings, + conversationGroupingType, + conversationsV1Bridge, + createdAt, + description, + displayName, + id, + intelligenceConfigurationIds, + memoryExtractionEnabled, + memoryStoreId, + observationExtractionStrategyIds, + redactionConfigurationId, + statusCallbacks, + traitExtractionStrategyIds, + updatedAt, + version + ); + } + } + + public static ConfigurationCreator creator() { + return new ConfigurationCreator(); + } + + public static ConfigurationDeleter deleter(final String pathId) { + return new ConfigurationDeleter(pathId); + } + + public static ConfigurationFetcher fetcher(final String pathId) { + return new ConfigurationFetcher(pathId); + } + + public static ConfigurationReader reader() { + return new ConfigurationReader(); + } + + public static ConfigurationPatcher patcher(final String pathId) { + return new ConfigurationPatcher(pathId); + } + + public static ConfigurationUpdater updater(final String pathId) { + return new ConfigurationUpdater(pathId); + } + + public enum ConversationGroupingType { + GROUP_BY_PROFILE("GROUP_BY_PROFILE"), + GROUP_BY_PARTICIPANT_ADDRESSES("GROUP_BY_PARTICIPANT_ADDRESSES"), + GROUP_BY_PARTICIPANT_ADDRESSES_AND_CHANNEL_TYPE( + "GROUP_BY_PARTICIPANT_ADDRESSES_AND_CHANNEL_TYPE" + ); + + private final String value; + + private ConversationGroupingType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationGroupingType forValue(final String value) { + return Promoter.enumFromString( + value, + ConversationGroupingType.values() + ); + } + } + + public enum Method { + POST("POST"), + GET("GET"); + + private final String value; + + private Method(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Method forValue(final String value) { + return Promoter.enumFromString(value, Method.values()); + } + } + + public enum ConversationsV2ConversationGroupingType { + GROUP_BY_PROFILE("GROUP_BY_PROFILE"), + GROUP_BY_PARTICIPANT_ADDRESSES("GROUP_BY_PARTICIPANT_ADDRESSES"), + GROUP_BY_PARTICIPANT_ADDRESSES_AND_CHANNEL_TYPE( + "GROUP_BY_PARTICIPANT_ADDRESSES_AND_CHANNEL_TYPE" + ); + + private final String value; + + private ConversationsV2ConversationGroupingType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2ConversationGroupingType forValue( + final String value + ) { + return Promoter.enumFromString( + value, + ConversationsV2ConversationGroupingType.values() + ); + } + } + + @JsonDeserialize(builder = ListConfiguration200ResponseMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListConfiguration200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListConfiguration200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static ListConfiguration200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListConfiguration200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListConfiguration200ResponseMeta build() { + return new ListConfiguration200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListConfiguration200ResponseMeta other = + (ListConfiguration200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize( + builder = UpdateConfigurationRequestChannelSettingsValueCaptureRules.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateConfigurationRequestChannelSettingsValueCaptureRules { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("from") + @Getter + private final String from; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + @Getter + private final String to; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + @Getter + private final Map metadata; + + private UpdateConfigurationRequestChannelSettingsValueCaptureRules( + Builder builder + ) { + this.from = builder.from; + this.to = builder.to; + this.metadata = builder.metadata; + } + + public static Builder builder(final String from, final String to) { + return new Builder(from, to); + } + + public static UpdateConfigurationRequestChannelSettingsValueCaptureRules fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateConfigurationRequestChannelSettingsValueCaptureRules.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("from") + private String from; + + @JsonProperty("to") + private String to; + + @JsonProperty("metadata") + private Map metadata; + + @JsonCreator + public Builder( + @JsonProperty("from") final String from, + @JsonProperty("to") final String to + ) { + this.from = from; + this.to = to; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + public Builder metadata(Map metadata) { + this.metadata = metadata; + return this; + } + + public UpdateConfigurationRequestChannelSettingsValueCaptureRules build() { + return new UpdateConfigurationRequestChannelSettingsValueCaptureRules( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateConfigurationRequestChannelSettingsValueCaptureRules other = + (UpdateConfigurationRequestChannelSettingsValueCaptureRules) o; + return ( + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(metadata, other.metadata) + ); + } + + @Override + public int hashCode() { + return Objects.hash(from, to, metadata); + } + } + + @JsonDeserialize( + builder = UpdateConfigurationRequestStatusCallbacks.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateConfigurationRequestStatusCallbacks { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final URI url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + @Getter + private final Configuration.Method method; + + private UpdateConfigurationRequestStatusCallbacks(Builder builder) { + this.url = builder.url; + this.method = builder.method; + } + + public static Builder builder(final URI url) { + return new Builder(url); + } + + public static UpdateConfigurationRequestStatusCallbacks fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateConfigurationRequestStatusCallbacks.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("url") + private URI url; + + @JsonProperty("method") + private Configuration.Method method; + + @JsonCreator + public Builder(@JsonProperty("url") final URI url) { + this.url = url; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + public Builder method(Configuration.Method method) { + this.method = method; + return this; + } + + public UpdateConfigurationRequestStatusCallbacks build() { + return new UpdateConfigurationRequestStatusCallbacks(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateConfigurationRequestStatusCallbacks other = + (UpdateConfigurationRequestStatusCallbacks) o; + return ( + Objects.equals(url, other.url) && + Objects.equals(method, other.method) + ); + } + + @Override + public int hashCode() { + return Objects.hash(url, method); + } + } + + @JsonDeserialize( + builder = PatchConfigurationRequestConversationsV1Bridge.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PatchConfigurationRequestConversationsV1Bridge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("serviceId") + @Getter + private final String serviceId; + + private PatchConfigurationRequestConversationsV1Bridge( + Builder builder + ) { + this.serviceId = builder.serviceId; + } + + public static Builder builder(final String serviceId) { + return new Builder(serviceId); + } + + public static PatchConfigurationRequestConversationsV1Bridge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + PatchConfigurationRequestConversationsV1Bridge.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("serviceId") + private String serviceId; + + @JsonCreator + public Builder(@JsonProperty("serviceId") final String serviceId) { + this.serviceId = serviceId; + } + + public PatchConfigurationRequestConversationsV1Bridge build() { + return new PatchConfigurationRequestConversationsV1Bridge(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PatchConfigurationRequestConversationsV1Bridge other = + (PatchConfigurationRequestConversationsV1Bridge) o; + return (Objects.equals(serviceId, other.serviceId)); + } + + @Override + public int hashCode() { + return Objects.hash(serviceId); + } + } + + @JsonDeserialize( + builder = UpdateConfigurationRequestChannelSettingsValue.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateConfigurationRequestChannelSettingsValue { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + @Getter + private final UpdateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("captureRules") + @Getter + private final List< + UpdateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules; + + private UpdateConfigurationRequestChannelSettingsValue( + Builder builder + ) { + this.statusTimeouts = builder.statusTimeouts; + this.captureRules = builder.captureRules; + } + + public static Builder builder() { + return new Builder(); + } + + public static UpdateConfigurationRequestChannelSettingsValue fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateConfigurationRequestChannelSettingsValue.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("statusTimeouts") + private UpdateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts; + + @JsonProperty("captureRules") + private List< + UpdateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + public Builder statusTimeouts( + UpdateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts + ) { + this.statusTimeouts = statusTimeouts; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("captureRules") + public Builder captureRules( + List< + UpdateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules + ) { + this.captureRules = captureRules; + return this; + } + + public UpdateConfigurationRequestChannelSettingsValue build() { + return new UpdateConfigurationRequestChannelSettingsValue(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateConfigurationRequestChannelSettingsValue other = + (UpdateConfigurationRequestChannelSettingsValue) o; + return ( + Objects.equals(statusTimeouts, other.statusTimeouts) && + Objects.equals(captureRules, other.captureRules) + ); + } + + @Override + public int hashCode() { + return Objects.hash(statusTimeouts, captureRules); + } + } + + @JsonDeserialize( + builder = CreateConfigurationRequestChannelSettingsValue.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConfigurationRequestChannelSettingsValue { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + @Getter + private final CreateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("captureRules") + @Getter + private final List< + CreateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules; + + private CreateConfigurationRequestChannelSettingsValue( + Builder builder + ) { + this.statusTimeouts = builder.statusTimeouts; + this.captureRules = builder.captureRules; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateConfigurationRequestChannelSettingsValue fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConfigurationRequestChannelSettingsValue.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("statusTimeouts") + private CreateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts; + + @JsonProperty("captureRules") + private List< + CreateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + public Builder statusTimeouts( + CreateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts + ) { + this.statusTimeouts = statusTimeouts; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("captureRules") + public Builder captureRules( + List< + CreateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules + ) { + this.captureRules = captureRules; + return this; + } + + public CreateConfigurationRequestChannelSettingsValue build() { + return new CreateConfigurationRequestChannelSettingsValue(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConfigurationRequestChannelSettingsValue other = + (CreateConfigurationRequestChannelSettingsValue) o; + return ( + Objects.equals(statusTimeouts, other.statusTimeouts) && + Objects.equals(captureRules, other.captureRules) + ); + } + + @Override + public int hashCode() { + return Objects.hash(statusTimeouts, captureRules); + } + } + + @JsonDeserialize( + builder = CreateConfigurationRequestConversationsV1Bridge.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConfigurationRequestConversationsV1Bridge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("serviceId") + @Getter + private final String serviceId; + + private CreateConfigurationRequestConversationsV1Bridge( + Builder builder + ) { + this.serviceId = builder.serviceId; + } + + public static Builder builder(final String serviceId) { + return new Builder(serviceId); + } + + public static CreateConfigurationRequestConversationsV1Bridge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConfigurationRequestConversationsV1Bridge.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("serviceId") + private String serviceId; + + @JsonCreator + public Builder(@JsonProperty("serviceId") final String serviceId) { + this.serviceId = serviceId; + } + + public CreateConfigurationRequestConversationsV1Bridge build() { + return new CreateConfigurationRequestConversationsV1Bridge( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConfigurationRequestConversationsV1Bridge other = + (CreateConfigurationRequestConversationsV1Bridge) o; + return (Objects.equals(serviceId, other.serviceId)); + } + + @Override + public int hashCode() { + return Objects.hash(serviceId); + } + } + + @JsonDeserialize(builder = ConversationsV2ChannelSetting.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2ChannelSetting { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + @Getter + private final ConversationsV2StatusTimeouts statusTimeouts; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("captureRules") + @Getter + private final List captureRules; + + private ConversationsV2ChannelSetting(Builder builder) { + this.statusTimeouts = builder.statusTimeouts; + this.captureRules = builder.captureRules; + } + + public static Builder builder() { + return new Builder(); + } + + public static ConversationsV2ChannelSetting fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2ChannelSetting.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("statusTimeouts") + private ConversationsV2StatusTimeouts statusTimeouts; + + @JsonProperty("captureRules") + private List captureRules; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + public Builder statusTimeouts( + ConversationsV2StatusTimeouts statusTimeouts + ) { + this.statusTimeouts = statusTimeouts; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("captureRules") + public Builder captureRules( + List captureRules + ) { + this.captureRules = captureRules; + return this; + } + + public ConversationsV2ChannelSetting build() { + return new ConversationsV2ChannelSetting(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2ChannelSetting other = + (ConversationsV2ChannelSetting) o; + return ( + Objects.equals(statusTimeouts, other.statusTimeouts) && + Objects.equals(captureRules, other.captureRules) + ); + } + + @Override + public int hashCode() { + return Objects.hash(statusTimeouts, captureRules); + } + } + + @JsonDeserialize(builder = UpdateConfigurationRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateConfigurationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + @Getter + private final Configuration.ConversationGroupingType conversationGroupingType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + @Getter + private final String memoryStoreId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + @Getter + private final Map< + String, + UpdateConfigurationRequestChannelSettingsValue + > channelSettings; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + @Getter + private final List< + UpdateConfigurationRequestStatusCallbacks + > statusCallbacks; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + @Getter + private final List intelligenceConfigurationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + @Getter + private final Boolean memoryExtractionEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + @Getter + private final CreateConfigurationRequestConversationsV1Bridge conversationsV1Bridge; + + private UpdateConfigurationRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.conversationGroupingType = builder.conversationGroupingType; + this.memoryStoreId = builder.memoryStoreId; + this.channelSettings = builder.channelSettings; + this.statusCallbacks = builder.statusCallbacks; + this.intelligenceConfigurationIds = + builder.intelligenceConfigurationIds; + this.memoryExtractionEnabled = builder.memoryExtractionEnabled; + this.conversationsV1Bridge = builder.conversationsV1Bridge; + } + + public static Builder builder( + final String description, + final Configuration.ConversationGroupingType conversationGroupingType, + final String memoryStoreId, + final Map< + String, + UpdateConfigurationRequestChannelSettingsValue + > channelSettings + ) { + return new Builder( + description, + conversationGroupingType, + memoryStoreId, + channelSettings + ); + } + + public static UpdateConfigurationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateConfigurationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("conversationGroupingType") + private Configuration.ConversationGroupingType conversationGroupingType; + + @JsonProperty("memoryStoreId") + private String memoryStoreId; + + @JsonProperty("channelSettings") + private Map< + String, + UpdateConfigurationRequestChannelSettingsValue + > channelSettings; + + @JsonProperty("statusCallbacks") + private List< + UpdateConfigurationRequestStatusCallbacks + > statusCallbacks; + + @JsonProperty("intelligenceConfigurationIds") + private List intelligenceConfigurationIds; + + @JsonProperty("memoryExtractionEnabled") + private Boolean memoryExtractionEnabled; + + @JsonProperty("conversationsV1Bridge") + private CreateConfigurationRequestConversationsV1Bridge conversationsV1Bridge; + + @JsonCreator + public Builder( + @JsonProperty("description") final String description, + @JsonProperty( + "conversationGroupingType" + ) final Configuration.ConversationGroupingType conversationGroupingType, + @JsonProperty("memoryStoreId") final String memoryStoreId, + @JsonProperty("channelSettings") final Map< + String, + UpdateConfigurationRequestChannelSettingsValue + > channelSettings + ) { + this.description = description; + this.conversationGroupingType = conversationGroupingType; + this.memoryStoreId = memoryStoreId; + this.channelSettings = channelSettings; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + public Builder statusCallbacks( + List statusCallbacks + ) { + this.statusCallbacks = statusCallbacks; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + public Builder intelligenceConfigurationIds( + List intelligenceConfigurationIds + ) { + this.intelligenceConfigurationIds = + intelligenceConfigurationIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + public Builder memoryExtractionEnabled( + Boolean memoryExtractionEnabled + ) { + this.memoryExtractionEnabled = memoryExtractionEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + public Builder conversationsV1Bridge( + CreateConfigurationRequestConversationsV1Bridge conversationsV1Bridge + ) { + this.conversationsV1Bridge = conversationsV1Bridge; + return this; + } + + public UpdateConfigurationRequest build() { + return new UpdateConfigurationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateConfigurationRequest other = (UpdateConfigurationRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals( + conversationGroupingType, + other.conversationGroupingType + ) && + Objects.equals(memoryStoreId, other.memoryStoreId) && + Objects.equals(channelSettings, other.channelSettings) && + Objects.equals(statusCallbacks, other.statusCallbacks) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + memoryExtractionEnabled, + other.memoryExtractionEnabled + ) && + Objects.equals( + conversationsV1Bridge, + other.conversationsV1Bridge + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + displayName, + description, + conversationGroupingType, + memoryStoreId, + channelSettings, + statusCallbacks, + intelligenceConfigurationIds, + memoryExtractionEnabled, + conversationsV1Bridge + ); + } + } + + @JsonDeserialize( + builder = ConversationsV2StatusCallbackConfig.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2StatusCallbackConfig { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final URI url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + @Getter + private final Configuration.Method method; + + private ConversationsV2StatusCallbackConfig(Builder builder) { + this.url = builder.url; + this.method = builder.method; + } + + public static Builder builder(final URI url) { + return new Builder(url); + } + + public static ConversationsV2StatusCallbackConfig fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2StatusCallbackConfig.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("url") + private URI url; + + @JsonProperty("method") + private Configuration.Method method; + + @JsonCreator + public Builder(@JsonProperty("url") final URI url) { + this.url = url; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + public Builder method(Configuration.Method method) { + this.method = method; + return this; + } + + public ConversationsV2StatusCallbackConfig build() { + return new ConversationsV2StatusCallbackConfig(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2StatusCallbackConfig other = + (ConversationsV2StatusCallbackConfig) o; + return ( + Objects.equals(url, other.url) && + Objects.equals(method, other.method) + ); + } + + @Override + public int hashCode() { + return Objects.hash(url, method); + } + } + + @JsonDeserialize(builder = PatchConfigurationRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PatchConfigurationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + @Getter + private final Configuration.ConversationGroupingType conversationGroupingType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + @Getter + private final String memoryStoreId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + @Getter + private final Map< + String, + PatchConfigurationRequestChannelSettingsValue + > channelSettings; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + @Getter + private final List< + UpdateConfigurationRequestStatusCallbacks + > statusCallbacks; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + @Getter + private final List intelligenceConfigurationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + @Getter + private final Boolean memoryExtractionEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + @Getter + private final PatchConfigurationRequestConversationsV1Bridge conversationsV1Bridge; + + private PatchConfigurationRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.conversationGroupingType = builder.conversationGroupingType; + this.memoryStoreId = builder.memoryStoreId; + this.channelSettings = builder.channelSettings; + this.statusCallbacks = builder.statusCallbacks; + this.intelligenceConfigurationIds = + builder.intelligenceConfigurationIds; + this.memoryExtractionEnabled = builder.memoryExtractionEnabled; + this.conversationsV1Bridge = builder.conversationsV1Bridge; + } + + public static Builder builder() { + return new Builder(); + } + + public static PatchConfigurationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + PatchConfigurationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("conversationGroupingType") + private Configuration.ConversationGroupingType conversationGroupingType; + + @JsonProperty("memoryStoreId") + private String memoryStoreId; + + @JsonProperty("channelSettings") + private Map< + String, + PatchConfigurationRequestChannelSettingsValue + > channelSettings; + + @JsonProperty("statusCallbacks") + private List< + UpdateConfigurationRequestStatusCallbacks + > statusCallbacks; + + @JsonProperty("intelligenceConfigurationIds") + private List intelligenceConfigurationIds; + + @JsonProperty("memoryExtractionEnabled") + private Boolean memoryExtractionEnabled; + + @JsonProperty("conversationsV1Bridge") + private PatchConfigurationRequestConversationsV1Bridge conversationsV1Bridge; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + public Builder conversationGroupingType( + Configuration.ConversationGroupingType conversationGroupingType + ) { + this.conversationGroupingType = conversationGroupingType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + public Builder memoryStoreId(String memoryStoreId) { + this.memoryStoreId = memoryStoreId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + public Builder channelSettings( + Map< + String, + PatchConfigurationRequestChannelSettingsValue + > channelSettings + ) { + this.channelSettings = channelSettings; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + public Builder statusCallbacks( + List statusCallbacks + ) { + this.statusCallbacks = statusCallbacks; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + public Builder intelligenceConfigurationIds( + List intelligenceConfigurationIds + ) { + this.intelligenceConfigurationIds = + intelligenceConfigurationIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + public Builder memoryExtractionEnabled( + Boolean memoryExtractionEnabled + ) { + this.memoryExtractionEnabled = memoryExtractionEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + public Builder conversationsV1Bridge( + PatchConfigurationRequestConversationsV1Bridge conversationsV1Bridge + ) { + this.conversationsV1Bridge = conversationsV1Bridge; + return this; + } + + public PatchConfigurationRequest build() { + return new PatchConfigurationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PatchConfigurationRequest other = (PatchConfigurationRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals( + conversationGroupingType, + other.conversationGroupingType + ) && + Objects.equals(memoryStoreId, other.memoryStoreId) && + Objects.equals(channelSettings, other.channelSettings) && + Objects.equals(statusCallbacks, other.statusCallbacks) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + memoryExtractionEnabled, + other.memoryExtractionEnabled + ) && + Objects.equals( + conversationsV1Bridge, + other.conversationsV1Bridge + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + displayName, + description, + conversationGroupingType, + memoryStoreId, + channelSettings, + statusCallbacks, + intelligenceConfigurationIds, + memoryExtractionEnabled, + conversationsV1Bridge + ); + } + } + + @JsonDeserialize(builder = ConversationsV2StatusTimeouts.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2StatusTimeouts { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inactive") + @Getter + private final Integer inactive; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("closed") + @Getter + private final Integer closed; + + private ConversationsV2StatusTimeouts(Builder builder) { + this.inactive = builder.inactive; + this.closed = builder.closed; + } + + public static Builder builder() { + return new Builder(); + } + + public static ConversationsV2StatusTimeouts fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2StatusTimeouts.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("inactive") + private Integer inactive; + + @JsonProperty("closed") + private Integer closed; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inactive") + public Builder inactive(Integer inactive) { + this.inactive = inactive; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("closed") + public Builder closed(Integer closed) { + this.closed = closed; + return this; + } + + public ConversationsV2StatusTimeouts build() { + return new ConversationsV2StatusTimeouts(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2StatusTimeouts other = + (ConversationsV2StatusTimeouts) o; + return ( + Objects.equals(inactive, other.inactive) && + Objects.equals(closed, other.closed) + ); + } + + @Override + public int hashCode() { + return Objects.hash(inactive, closed); + } + } + + @JsonDeserialize(builder = ConversationsV2CaptureRule.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2CaptureRule { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("from") + @Getter + private final String from; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + @Getter + private final String to; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + @Getter + private final Map metadata; + + private ConversationsV2CaptureRule(Builder builder) { + this.from = builder.from; + this.to = builder.to; + this.metadata = builder.metadata; + } + + public static Builder builder(final String from, final String to) { + return new Builder(from, to); + } + + public static ConversationsV2CaptureRule fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2CaptureRule.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("from") + private String from; + + @JsonProperty("to") + private String to; + + @JsonProperty("metadata") + private Map metadata; + + @JsonCreator + public Builder( + @JsonProperty("from") final String from, + @JsonProperty("to") final String to + ) { + this.from = from; + this.to = to; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + public Builder metadata(Map metadata) { + this.metadata = metadata; + return this; + } + + public ConversationsV2CaptureRule build() { + return new ConversationsV2CaptureRule(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2CaptureRule other = (ConversationsV2CaptureRule) o; + return ( + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(metadata, other.metadata) + ); + } + + @Override + public int hashCode() { + return Objects.hash(from, to, metadata); + } + } + + @JsonDeserialize( + builder = PatchConfigurationRequestChannelSettingsValue.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PatchConfigurationRequestChannelSettingsValue { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + @Getter + private final UpdateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("captureRules") + @Getter + private final List< + UpdateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules; + + private PatchConfigurationRequestChannelSettingsValue(Builder builder) { + this.statusTimeouts = builder.statusTimeouts; + this.captureRules = builder.captureRules; + } + + public static Builder builder() { + return new Builder(); + } + + public static PatchConfigurationRequestChannelSettingsValue fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + PatchConfigurationRequestChannelSettingsValue.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("statusTimeouts") + private UpdateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts; + + @JsonProperty("captureRules") + private List< + UpdateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + public Builder statusTimeouts( + UpdateConfigurationRequestChannelSettingsValueStatusTimeouts statusTimeouts + ) { + this.statusTimeouts = statusTimeouts; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("captureRules") + public Builder captureRules( + List< + UpdateConfigurationRequestChannelSettingsValueCaptureRules + > captureRules + ) { + this.captureRules = captureRules; + return this; + } + + public PatchConfigurationRequestChannelSettingsValue build() { + return new PatchConfigurationRequestChannelSettingsValue(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PatchConfigurationRequestChannelSettingsValue other = + (PatchConfigurationRequestChannelSettingsValue) o; + return ( + Objects.equals(statusTimeouts, other.statusTimeouts) && + Objects.equals(captureRules, other.captureRules) + ); + } + + @Override + public int hashCode() { + return Objects.hash(statusTimeouts, captureRules); + } + } + + @JsonDeserialize(builder = CreateConfigurationRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConfigurationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + @Getter + private final Configuration.ConversationGroupingType conversationGroupingType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + @Getter + private final String memoryStoreId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + @Getter + private final Map< + String, + CreateConfigurationRequestChannelSettingsValue + > channelSettings; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + @Getter + private final List< + CreateConfigurationRequestStatusCallbacks + > statusCallbacks; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + @Getter + private final List intelligenceConfigurationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + @Getter + private final Boolean memoryExtractionEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + @Getter + private final CreateConfigurationRequestConversationsV1Bridge conversationsV1Bridge; + + private CreateConfigurationRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.conversationGroupingType = builder.conversationGroupingType; + this.memoryStoreId = builder.memoryStoreId; + this.channelSettings = builder.channelSettings; + this.statusCallbacks = builder.statusCallbacks; + this.intelligenceConfigurationIds = + builder.intelligenceConfigurationIds; + this.memoryExtractionEnabled = builder.memoryExtractionEnabled; + this.conversationsV1Bridge = builder.conversationsV1Bridge; + } + + public static Builder builder( + final String displayName, + final String description, + final Configuration.ConversationGroupingType conversationGroupingType, + final String memoryStoreId + ) { + return new Builder( + displayName, + description, + conversationGroupingType, + memoryStoreId + ); + } + + public static CreateConfigurationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConfigurationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("conversationGroupingType") + private Configuration.ConversationGroupingType conversationGroupingType; + + @JsonProperty("memoryStoreId") + private String memoryStoreId; + + @JsonProperty("channelSettings") + private Map< + String, + CreateConfigurationRequestChannelSettingsValue + > channelSettings; + + @JsonProperty("statusCallbacks") + private List< + CreateConfigurationRequestStatusCallbacks + > statusCallbacks; + + @JsonProperty("intelligenceConfigurationIds") + private List intelligenceConfigurationIds; + + @JsonProperty("memoryExtractionEnabled") + private Boolean memoryExtractionEnabled; + + @JsonProperty("conversationsV1Bridge") + private CreateConfigurationRequestConversationsV1Bridge conversationsV1Bridge; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName, + @JsonProperty("description") final String description, + @JsonProperty( + "conversationGroupingType" + ) final Configuration.ConversationGroupingType conversationGroupingType, + @JsonProperty("memoryStoreId") final String memoryStoreId + ) { + this.displayName = displayName; + this.description = description; + this.conversationGroupingType = conversationGroupingType; + this.memoryStoreId = memoryStoreId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + public Builder channelSettings( + Map< + String, + CreateConfigurationRequestChannelSettingsValue + > channelSettings + ) { + this.channelSettings = channelSettings; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + public Builder statusCallbacks( + List statusCallbacks + ) { + this.statusCallbacks = statusCallbacks; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + public Builder intelligenceConfigurationIds( + List intelligenceConfigurationIds + ) { + this.intelligenceConfigurationIds = + intelligenceConfigurationIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + public Builder memoryExtractionEnabled( + Boolean memoryExtractionEnabled + ) { + this.memoryExtractionEnabled = memoryExtractionEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + public Builder conversationsV1Bridge( + CreateConfigurationRequestConversationsV1Bridge conversationsV1Bridge + ) { + this.conversationsV1Bridge = conversationsV1Bridge; + return this; + } + + public CreateConfigurationRequest build() { + return new CreateConfigurationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConfigurationRequest other = (CreateConfigurationRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals( + conversationGroupingType, + other.conversationGroupingType + ) && + Objects.equals(memoryStoreId, other.memoryStoreId) && + Objects.equals(channelSettings, other.channelSettings) && + Objects.equals(statusCallbacks, other.statusCallbacks) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + memoryExtractionEnabled, + other.memoryExtractionEnabled + ) && + Objects.equals( + conversationsV1Bridge, + other.conversationsV1Bridge + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + displayName, + description, + conversationGroupingType, + memoryStoreId, + channelSettings, + statusCallbacks, + intelligenceConfigurationIds, + memoryExtractionEnabled, + conversationsV1Bridge + ); + } + } + + @JsonDeserialize( + builder = ConversationsV2ConversationsV1Bridge.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2ConversationsV1Bridge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("serviceId") + @Getter + private final String serviceId; + + private ConversationsV2ConversationsV1Bridge(Builder builder) { + this.serviceId = builder.serviceId; + } + + public static Builder builder(final String serviceId) { + return new Builder(serviceId); + } + + public static ConversationsV2ConversationsV1Bridge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2ConversationsV1Bridge.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("serviceId") + private String serviceId; + + @JsonCreator + public Builder(@JsonProperty("serviceId") final String serviceId) { + this.serviceId = serviceId; + } + + public ConversationsV2ConversationsV1Bridge build() { + return new ConversationsV2ConversationsV1Bridge(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2ConversationsV1Bridge other = + (ConversationsV2ConversationsV1Bridge) o; + return (Objects.equals(serviceId, other.serviceId)); + } + + @Override + public int hashCode() { + return Objects.hash(serviceId); + } + } + + @JsonDeserialize( + builder = CreateConfigurationRequestChannelSettingsValueStatusTimeouts.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConfigurationRequestChannelSettingsValueStatusTimeouts { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inactive") + @Getter + private final Integer inactive; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("closed") + @Getter + private final Integer closed; + + private CreateConfigurationRequestChannelSettingsValueStatusTimeouts( + Builder builder + ) { + this.inactive = builder.inactive; + this.closed = builder.closed; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateConfigurationRequestChannelSettingsValueStatusTimeouts fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConfigurationRequestChannelSettingsValueStatusTimeouts.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("inactive") + private Integer inactive; + + @JsonProperty("closed") + private Integer closed; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inactive") + public Builder inactive(Integer inactive) { + this.inactive = inactive; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("closed") + public Builder closed(Integer closed) { + this.closed = closed; + return this; + } + + public CreateConfigurationRequestChannelSettingsValueStatusTimeouts build() { + return new CreateConfigurationRequestChannelSettingsValueStatusTimeouts( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConfigurationRequestChannelSettingsValueStatusTimeouts other = + (CreateConfigurationRequestChannelSettingsValueStatusTimeouts) o; + return ( + Objects.equals(inactive, other.inactive) && + Objects.equals(closed, other.closed) + ); + } + + @Override + public int hashCode() { + return Objects.hash(inactive, closed); + } + } + + @JsonDeserialize( + builder = UpdateConfigurationRequestChannelSettingsValueStatusTimeouts.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateConfigurationRequestChannelSettingsValueStatusTimeouts { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inactive") + @Getter + private final Integer inactive; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("closed") + @Getter + private final Integer closed; + + private UpdateConfigurationRequestChannelSettingsValueStatusTimeouts( + Builder builder + ) { + this.inactive = builder.inactive; + this.closed = builder.closed; + } + + public static Builder builder() { + return new Builder(); + } + + public static UpdateConfigurationRequestChannelSettingsValueStatusTimeouts fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateConfigurationRequestChannelSettingsValueStatusTimeouts.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("inactive") + private Integer inactive; + + @JsonProperty("closed") + private Integer closed; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inactive") + public Builder inactive(Integer inactive) { + this.inactive = inactive; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("closed") + public Builder closed(Integer closed) { + this.closed = closed; + return this; + } + + public UpdateConfigurationRequestChannelSettingsValueStatusTimeouts build() { + return new UpdateConfigurationRequestChannelSettingsValueStatusTimeouts( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateConfigurationRequestChannelSettingsValueStatusTimeouts other = + (UpdateConfigurationRequestChannelSettingsValueStatusTimeouts) o; + return ( + Objects.equals(inactive, other.inactive) && + Objects.equals(closed, other.closed) + ); + } + + @Override + public int hashCode() { + return Objects.hash(inactive, closed); + } + } + + @JsonDeserialize( + builder = ListConfiguration200ResponseConfigurations.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListConfiguration200ResponseConfigurations { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + @Getter + private final Configuration.ConversationsV2ConversationGroupingType conversationGroupingType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + @Getter + private final String memoryStoreId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + @Getter + private final Map< + String, + ConversationsV2ChannelSetting + > channelSettings; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + @Getter + private final List statusCallbacks; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + @Getter + private final List intelligenceConfigurationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitExtractionStrategyIds") + @Getter + private final List traitExtractionStrategyIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observationExtractionStrategyIds") + @Getter + private final List observationExtractionStrategyIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + @Getter + private final Boolean memoryExtractionEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("redactionConfigurationId") + @Getter + private final String redactionConfigurationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + @Getter + private final ConversationsV2ConversationsV1Bridge conversationsV1Bridge; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Long version; + + private ListConfiguration200ResponseConfigurations(Builder builder) { + this.id = builder.id; + this.displayName = builder.displayName; + this.description = builder.description; + this.conversationGroupingType = builder.conversationGroupingType; + this.memoryStoreId = builder.memoryStoreId; + this.channelSettings = builder.channelSettings; + this.statusCallbacks = builder.statusCallbacks; + this.intelligenceConfigurationIds = + builder.intelligenceConfigurationIds; + this.traitExtractionStrategyIds = + builder.traitExtractionStrategyIds; + this.observationExtractionStrategyIds = + builder.observationExtractionStrategyIds; + this.memoryExtractionEnabled = builder.memoryExtractionEnabled; + this.redactionConfigurationId = builder.redactionConfigurationId; + this.conversationsV1Bridge = builder.conversationsV1Bridge; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.version = builder.version; + } + + public static Builder builder( + final String id, + final String displayName, + final String description, + final Configuration.ConversationsV2ConversationGroupingType conversationGroupingType, + final String memoryStoreId + ) { + return new Builder( + id, + displayName, + description, + conversationGroupingType, + memoryStoreId + ); + } + + public static ListConfiguration200ResponseConfigurations fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListConfiguration200ResponseConfigurations.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("conversationGroupingType") + private Configuration.ConversationsV2ConversationGroupingType conversationGroupingType; + + @JsonProperty("memoryStoreId") + private String memoryStoreId; + + @JsonProperty("channelSettings") + private Map channelSettings; + + @JsonProperty("statusCallbacks") + private List statusCallbacks; + + @JsonProperty("intelligenceConfigurationIds") + private List intelligenceConfigurationIds; + + @JsonProperty("traitExtractionStrategyIds") + private List traitExtractionStrategyIds; + + @JsonProperty("observationExtractionStrategyIds") + private List observationExtractionStrategyIds; + + @JsonProperty("memoryExtractionEnabled") + private Boolean memoryExtractionEnabled; + + @JsonProperty("redactionConfigurationId") + private String redactionConfigurationId; + + @JsonProperty("conversationsV1Bridge") + private ConversationsV2ConversationsV1Bridge conversationsV1Bridge; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonProperty("version") + private Long version; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("displayName") final String displayName, + @JsonProperty("description") final String description, + @JsonProperty( + "conversationGroupingType" + ) final Configuration.ConversationsV2ConversationGroupingType conversationGroupingType, + @JsonProperty("memoryStoreId") final String memoryStoreId + ) { + this.id = id; + this.displayName = displayName; + this.description = description; + this.conversationGroupingType = conversationGroupingType; + this.memoryStoreId = memoryStoreId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + public Builder channelSettings( + Map channelSettings + ) { + this.channelSettings = channelSettings; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + public Builder statusCallbacks( + List statusCallbacks + ) { + this.statusCallbacks = statusCallbacks; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + public Builder intelligenceConfigurationIds( + List intelligenceConfigurationIds + ) { + this.intelligenceConfigurationIds = + intelligenceConfigurationIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitExtractionStrategyIds") + public Builder traitExtractionStrategyIds( + List traitExtractionStrategyIds + ) { + this.traitExtractionStrategyIds = traitExtractionStrategyIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observationExtractionStrategyIds") + public Builder observationExtractionStrategyIds( + List observationExtractionStrategyIds + ) { + this.observationExtractionStrategyIds = + observationExtractionStrategyIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + public Builder memoryExtractionEnabled( + Boolean memoryExtractionEnabled + ) { + this.memoryExtractionEnabled = memoryExtractionEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("redactionConfigurationId") + public Builder redactionConfigurationId( + String redactionConfigurationId + ) { + this.redactionConfigurationId = redactionConfigurationId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + public Builder conversationsV1Bridge( + ConversationsV2ConversationsV1Bridge conversationsV1Bridge + ) { + this.conversationsV1Bridge = conversationsV1Bridge; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + public Builder updatedAt(ZonedDateTime updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + public Builder version(Long version) { + this.version = version; + return this; + } + + public ListConfiguration200ResponseConfigurations build() { + return new ListConfiguration200ResponseConfigurations(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListConfiguration200ResponseConfigurations other = + (ListConfiguration200ResponseConfigurations) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals( + conversationGroupingType, + other.conversationGroupingType + ) && + Objects.equals(memoryStoreId, other.memoryStoreId) && + Objects.equals(channelSettings, other.channelSettings) && + Objects.equals(statusCallbacks, other.statusCallbacks) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + traitExtractionStrategyIds, + other.traitExtractionStrategyIds + ) && + Objects.equals( + observationExtractionStrategyIds, + other.observationExtractionStrategyIds + ) && + Objects.equals( + memoryExtractionEnabled, + other.memoryExtractionEnabled + ) && + Objects.equals( + redactionConfigurationId, + other.redactionConfigurationId + ) && + Objects.equals( + conversationsV1Bridge, + other.conversationsV1Bridge + ) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + displayName, + description, + conversationGroupingType, + memoryStoreId, + channelSettings, + statusCallbacks, + intelligenceConfigurationIds, + traitExtractionStrategyIds, + observationExtractionStrategyIds, + memoryExtractionEnabled, + redactionConfigurationId, + conversationsV1Bridge, + createdAt, + updatedAt, + version + ); + } + } + + @JsonDeserialize( + builder = CreateConfigurationRequestStatusCallbacks.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConfigurationRequestStatusCallbacks { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final URI url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + @Getter + private final Configuration.Method method; + + private CreateConfigurationRequestStatusCallbacks(Builder builder) { + this.url = builder.url; + this.method = builder.method; + } + + public static Builder builder(final URI url) { + return new Builder(url); + } + + public static CreateConfigurationRequestStatusCallbacks fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConfigurationRequestStatusCallbacks.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("url") + private URI url; + + @JsonProperty("method") + private Configuration.Method method; + + @JsonCreator + public Builder(@JsonProperty("url") final URI url) { + this.url = url; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + public Builder method(Configuration.Method method) { + this.method = method; + return this; + } + + public CreateConfigurationRequestStatusCallbacks build() { + return new CreateConfigurationRequestStatusCallbacks(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConfigurationRequestStatusCallbacks other = + (CreateConfigurationRequestStatusCallbacks) o; + return ( + Objects.equals(url, other.url) && + Objects.equals(method, other.method) + ); + } + + @Override + public int hashCode() { + return Objects.hash(url, method); + } + } + + @JsonDeserialize( + builder = CreateConfigurationRequestChannelSettingsValueCaptureRules.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConfigurationRequestChannelSettingsValueCaptureRules { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("from") + @Getter + private final String from; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + @Getter + private final String to; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + @Getter + private final Map metadata; + + private CreateConfigurationRequestChannelSettingsValueCaptureRules( + Builder builder + ) { + this.from = builder.from; + this.to = builder.to; + this.metadata = builder.metadata; + } + + public static Builder builder(final String from, final String to) { + return new Builder(from, to); + } + + public static CreateConfigurationRequestChannelSettingsValueCaptureRules fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConfigurationRequestChannelSettingsValueCaptureRules.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("from") + private String from; + + @JsonProperty("to") + private String to; + + @JsonProperty("metadata") + private Map metadata; + + @JsonCreator + public Builder( + @JsonProperty("from") final String from, + @JsonProperty("to") final String to + ) { + this.from = from; + this.to = to; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + public Builder metadata(Map metadata) { + this.metadata = metadata; + return this; + } + + public CreateConfigurationRequestChannelSettingsValueCaptureRules build() { + return new CreateConfigurationRequestChannelSettingsValueCaptureRules( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConfigurationRequestChannelSettingsValueCaptureRules other = + (CreateConfigurationRequestChannelSettingsValueCaptureRules) o; + return ( + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(metadata, other.metadata) + ); + } + + @Override + public int hashCode() { + return Objects.hash(from, to, metadata); + } + } + + /** + * Converts a JSON String into a Configuration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Configuration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Configuration() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConfigurationCreator.java b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationCreator.java new file mode 100644 index 0000000000..caad9dd888 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationCreator.java @@ -0,0 +1,136 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationCreator + extends Creator { + + private String idempotencyKey; + private Configuration.CreateConfigurationRequest createConfigurationRequest; + + public ConfigurationCreator() {} + + public ConfigurationCreator setCreateConfigurationRequest( + final Configuration.CreateConfigurationRequest createConfigurationRequest + ) { + this.createConfigurationRequest = createConfigurationRequest; + return this; + } + + public ConfigurationCreator setIdempotencyKey(final String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/Configurations"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration.CreateConfigurationResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Configuration.CreateConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Configuration.CreateConfigurationResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Configuration.CreateConfigurationResponse content = + Configuration.CreateConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (idempotencyKey != null) { + Serializer.toString( + request, + "Idempotency-Key", + idempotencyKey, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createConfigurationRequest != null) { + request.setBody( + Configuration.toJson(createConfigurationRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConfigurationDeleter.java b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationDeleter.java new file mode 100644 index 0000000000..211e19cf1f --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationDeleter.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ConfigurationDeleter + extends ResourceDeleter< + Configuration, + Configuration.DeleteConfigurationResponse + > { + + private String pathId; + private String idempotencyKey; + + public ConfigurationDeleter(final String pathId) { + this.pathId = pathId; + } + + public ConfigurationDeleter setIdempotencyKey(final String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/Configurations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration.DeleteConfigurationResponse delete( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Configuration.DeleteConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Configuration.DeleteConfigurationResponse + > deleteWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Configuration.DeleteConfigurationResponse content = + Configuration.DeleteConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (idempotencyKey != null) { + Serializer.toString( + request, + "Idempotency-Key", + idempotencyKey, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConfigurationFetcher.java b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationFetcher.java new file mode 100644 index 0000000000..f3f9358bd9 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationFetcher + extends Fetcher { + + private String pathId; + + public ConfigurationFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/Configurations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration.FetchConfigurationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Configuration.FetchConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Configuration.FetchConfigurationResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Configuration.FetchConfigurationResponse content = + Configuration.FetchConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConfigurationPatcher.java b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationPatcher.java new file mode 100644 index 0000000000..a42b2d55e9 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationPatcher.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationPatcher + extends Patcher { + + private String pathId; + private String idempotencyKey; + private Configuration.PatchConfigurationRequest patchConfigurationRequest; + + public ConfigurationPatcher(final String pathId) { + this.pathId = pathId; + } + + public ConfigurationPatcher setPatchConfigurationRequest( + final Configuration.PatchConfigurationRequest patchConfigurationRequest + ) { + this.patchConfigurationRequest = patchConfigurationRequest; + return this; + } + + public ConfigurationPatcher setIdempotencyKey(final String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + return this; + } + + @Override + public Configuration.PatchConfigurationResponse patch( + final TwilioRestClient client + ) { + String path = "/v2/ControlPlane/Configurations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PATCH, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Configuration.PatchConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addHeaderParams(final Request request) { + if (idempotencyKey != null) { + Serializer.toString( + request, + "Idempotency-Key", + idempotencyKey, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (patchConfigurationRequest != null) { + request.setBody( + Configuration.toJson(patchConfigurationRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConfigurationReader.java b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationReader.java new file mode 100644 index 0000000000..7fa5eb6042 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationReader.java @@ -0,0 +1,256 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationReader + extends Reader { + + private Integer pageSize; + private String pageToken; + private String memoryStoreId; + + public ConfigurationReader() {} + + public ConfigurationReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ConfigurationReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ConfigurationReader setMemoryStoreId(final String memoryStoreId) { + this.memoryStoreId = memoryStoreId; + return this; + } + + public ResourceSetResponse< + Configuration.ListConfigurationResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "configurations", + response.getContent(), + Configuration.ListConfigurationResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/Configurations"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "configurations", + response.getContent(), + Configuration.ListConfigurationResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Configuration read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "configurations", + response.getContent(), + Configuration.ListConfigurationResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/ControlPlane/Configurations"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/ControlPlane/Configurations"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (memoryStoreId != null) { + Serializer.toString( + request, + "memoryStoreId", + memoryStoreId, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConfigurationUpdater.java b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationUpdater.java new file mode 100644 index 0000000000..a32d45a4e7 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConfigurationUpdater.java @@ -0,0 +1,141 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationUpdater + extends Updater { + + private String pathId; + private String idempotencyKey; + private Configuration.UpdateConfigurationRequest updateConfigurationRequest; + + public ConfigurationUpdater(final String pathId) { + this.pathId = pathId; + } + + public ConfigurationUpdater setUpdateConfigurationRequest( + final Configuration.UpdateConfigurationRequest updateConfigurationRequest + ) { + this.updateConfigurationRequest = updateConfigurationRequest; + return this; + } + + public ConfigurationUpdater setIdempotencyKey(final String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/Configurations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration.UpdateConfigurationResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Configuration.UpdateConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Configuration.UpdateConfigurationResponse + > updateWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Configuration.UpdateConfigurationResponse content = + Configuration.UpdateConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (idempotencyKey != null) { + Serializer.toString( + request, + "Idempotency-Key", + idempotencyKey, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (updateConfigurationRequest != null) { + request.setBody( + Configuration.toJson(updateConfigurationRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/Conversation.java b/src/main/java/com/twilio/rest/conversations/v2/Conversation.java new file mode 100644 index 0000000000..071e1673d5 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/Conversation.java @@ -0,0 +1,3592 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Conversation extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateConversationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final String actionId; + + @Getter + private final ListConversationByAccount200ResponseConversationsConfiguration configuration; + + @Getter + private final String configurationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final Map metadata; + + @Getter + private final String name; + + @Getter + private final List participants; + + @Getter + private final Conversation.ConversationsV2ConversationStatus status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private CreateConversationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("actionId") final String actionId, + @JsonProperty( + "configuration" + ) final ListConversationByAccount200ResponseConversationsConfiguration configuration, + @JsonProperty("configurationId") final String configurationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("metadata") final Map metadata, + @JsonProperty("name") final String name, + @JsonProperty("participants") final List< + ConversationsV2Participant + > participants, + @JsonProperty( + "status" + ) final Conversation.ConversationsV2ConversationStatus status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.actionId = actionId; + this.configuration = configuration; + this.configurationId = configurationId; + this.createdAt = createdAt; + this.id = id; + this.metadata = metadata; + this.name = name; + this.participants = participants; + this.status = status; + this.updatedAt = updatedAt; + } + + public static CreateConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateConversationResponse other = (CreateConversationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(actionId, other.actionId) && + Objects.equals(configuration, other.configuration) && + Objects.equals(configurationId, other.configurationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(metadata, other.metadata) && + Objects.equals(name, other.name) && + Objects.equals(participants, other.participants) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + actionId, + configuration, + configurationId, + createdAt, + id, + metadata, + name, + participants, + status, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateConversationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final String actionId; + + @Getter + private final ListConversationByAccount200ResponseConversationsConfiguration configuration; + + @Getter + private final String configurationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final Map metadata; + + @Getter + private final String name; + + @Getter + private final List participants; + + @Getter + private final Conversation.ConversationsV2ConversationStatus status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private UpdateConversationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("actionId") final String actionId, + @JsonProperty( + "configuration" + ) final ListConversationByAccount200ResponseConversationsConfiguration configuration, + @JsonProperty("configurationId") final String configurationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("metadata") final Map metadata, + @JsonProperty("name") final String name, + @JsonProperty("participants") final List< + ConversationsV2Participant + > participants, + @JsonProperty( + "status" + ) final Conversation.ConversationsV2ConversationStatus status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.actionId = actionId; + this.configuration = configuration; + this.configurationId = configurationId; + this.createdAt = createdAt; + this.id = id; + this.metadata = metadata; + this.name = name; + this.participants = participants; + this.status = status; + this.updatedAt = updatedAt; + } + + public static UpdateConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateConversationResponse other = (UpdateConversationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(actionId, other.actionId) && + Objects.equals(configuration, other.configuration) && + Objects.equals(configurationId, other.configurationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(metadata, other.metadata) && + Objects.equals(name, other.name) && + Objects.equals(participants, other.participants) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + actionId, + configuration, + configurationId, + createdAt, + id, + metadata, + name, + participants, + status, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteConversationResponse extends Resource { + + @Getter + private final Map related; + + @Getter + private final URI statusUrl; + + @JsonCreator + private DeleteConversationResponse( + @JsonProperty("related") final Map related, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.related = related; + this.statusUrl = statusUrl; + } + + public static DeleteConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteConversationResponse other = (DeleteConversationResponse) o; + return ( + Objects.equals(related, other.related) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(related, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListConversationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final String actionId; + + @Getter + private final ListConversationByAccount200ResponseConversationsConfiguration configuration; + + @Getter + private final String configurationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final Map metadata; + + @Getter + private final String name; + + @Getter + private final List participants; + + @Getter + private final Conversation.ConversationsV2ConversationStatus status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListConversationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("actionId") final String actionId, + @JsonProperty( + "configuration" + ) final ListConversationByAccount200ResponseConversationsConfiguration configuration, + @JsonProperty("configurationId") final String configurationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("metadata") final Map metadata, + @JsonProperty("name") final String name, + @JsonProperty("participants") final List< + ConversationsV2Participant + > participants, + @JsonProperty( + "status" + ) final Conversation.ConversationsV2ConversationStatus status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.actionId = actionId; + this.configuration = configuration; + this.configurationId = configurationId; + this.createdAt = createdAt; + this.id = id; + this.metadata = metadata; + this.name = name; + this.participants = participants; + this.status = status; + this.updatedAt = updatedAt; + } + + public static ListConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListConversationResponse other = (ListConversationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(actionId, other.actionId) && + Objects.equals(configuration, other.configuration) && + Objects.equals(configurationId, other.configurationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(metadata, other.metadata) && + Objects.equals(name, other.name) && + Objects.equals(participants, other.participants) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + actionId, + configuration, + configurationId, + createdAt, + id, + metadata, + name, + participants, + status, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchConversationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final String actionId; + + @Getter + private final ListConversationByAccount200ResponseConversationsConfiguration configuration; + + @Getter + private final String configurationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final Map metadata; + + @Getter + private final String name; + + @Getter + private final List participants; + + @Getter + private final Conversation.ConversationsV2ConversationStatus status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private PatchConversationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("actionId") final String actionId, + @JsonProperty( + "configuration" + ) final ListConversationByAccount200ResponseConversationsConfiguration configuration, + @JsonProperty("configurationId") final String configurationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("metadata") final Map metadata, + @JsonProperty("name") final String name, + @JsonProperty("participants") final List< + ConversationsV2Participant + > participants, + @JsonProperty( + "status" + ) final Conversation.ConversationsV2ConversationStatus status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.actionId = actionId; + this.configuration = configuration; + this.configurationId = configurationId; + this.createdAt = createdAt; + this.id = id; + this.metadata = metadata; + this.name = name; + this.participants = participants; + this.status = status; + this.updatedAt = updatedAt; + } + + public static PatchConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchConversationResponse other = (PatchConversationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(actionId, other.actionId) && + Objects.equals(configuration, other.configuration) && + Objects.equals(configurationId, other.configurationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(metadata, other.metadata) && + Objects.equals(name, other.name) && + Objects.equals(participants, other.participants) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + actionId, + configuration, + configurationId, + createdAt, + id, + metadata, + name, + participants, + status, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchConversationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final String actionId; + + @Getter + private final ListConversationByAccount200ResponseConversationsConfiguration configuration; + + @Getter + private final String configurationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final Map metadata; + + @Getter + private final String name; + + @Getter + private final List participants; + + @Getter + private final Conversation.ConversationsV2ConversationStatus status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchConversationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("actionId") final String actionId, + @JsonProperty( + "configuration" + ) final ListConversationByAccount200ResponseConversationsConfiguration configuration, + @JsonProperty("configurationId") final String configurationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("metadata") final Map metadata, + @JsonProperty("name") final String name, + @JsonProperty("participants") final List< + ConversationsV2Participant + > participants, + @JsonProperty( + "status" + ) final Conversation.ConversationsV2ConversationStatus status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.actionId = actionId; + this.configuration = configuration; + this.configurationId = configurationId; + this.createdAt = createdAt; + this.id = id; + this.metadata = metadata; + this.name = name; + this.participants = participants; + this.status = status; + this.updatedAt = updatedAt; + } + + public static FetchConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchConversationResponse other = (FetchConversationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(actionId, other.actionId) && + Objects.equals(configuration, other.configuration) && + Objects.equals(configurationId, other.configurationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(metadata, other.metadata) && + Objects.equals(name, other.name) && + Objects.equals(participants, other.participants) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + actionId, + configuration, + configurationId, + createdAt, + id, + metadata, + name, + participants, + status, + updatedAt + ); + } + } + + public static ConversationCreator creator() { + return new ConversationCreator(); + } + + public static ConversationDeleter deleter(final String pathId) { + return new ConversationDeleter(pathId); + } + + public static ConversationFetcher fetcher(final String pathId) { + return new ConversationFetcher(pathId); + } + + public static ConversationReader reader() { + return new ConversationReader(); + } + + public static ConversationPatcher patcher(final String pathId) { + return new ConversationPatcher(pathId); + } + + public static ConversationUpdater updater(final String pathId) { + return new ConversationUpdater(pathId); + } + + public enum Status { + ACTIVE("ACTIVE"), + INACTIVE("INACTIVE"), + CLOSED("CLOSED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Type { + HUMAN_AGENT("HUMAN_AGENT"), + CUSTOMER("CUSTOMER"), + AI_AGENT("AI_AGENT"), + AGENT("AGENT"), + UNKNOWN("UNKNOWN"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum ConversationsV2Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + VIDEO("VIDEO"); + + private final String value; + + private ConversationsV2Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2Channel forValue(final String value) { + return Promoter.enumFromString( + value, + ConversationsV2Channel.values() + ); + } + } + + public enum ConversationGroupingType { + GROUP_BY_PROFILE("GROUP_BY_PROFILE"), + GROUP_BY_PARTICIPANT_ADDRESSES("GROUP_BY_PARTICIPANT_ADDRESSES"), + GROUP_BY_PARTICIPANT_ADDRESSES_AND_CHANNEL_TYPE( + "GROUP_BY_PARTICIPANT_ADDRESSES_AND_CHANNEL_TYPE" + ); + + private final String value; + + private ConversationGroupingType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationGroupingType forValue(final String value) { + return Promoter.enumFromString( + value, + ConversationGroupingType.values() + ); + } + } + + public enum ConversationsV2ConversationStatus { + ACTIVE("ACTIVE"), + INACTIVE("INACTIVE"), + CLOSED("CLOSED"); + + private final String value; + + private ConversationsV2ConversationStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2ConversationStatus forValue( + final String value + ) { + return Promoter.enumFromString( + value, + ConversationsV2ConversationStatus.values() + ); + } + } + + public enum ConversationsV2ParticipantType { + HUMAN_AGENT("HUMAN_AGENT"), + CUSTOMER("CUSTOMER"), + AI_AGENT("AI_AGENT"), + AGENT("AGENT"), + UNKNOWN("UNKNOWN"); + + private final String value; + + private ConversationsV2ParticipantType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2ParticipantType forValue( + final String value + ) { + return Promoter.enumFromString( + value, + ConversationsV2ParticipantType.values() + ); + } + } + + public enum Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + VIDEO("VIDEO"); + + private final String value; + + private Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Channel forValue(final String value) { + return Promoter.enumFromString(value, Channel.values()); + } + } + + public enum Method { + POST("POST"), + GET("GET"); + + private final String value; + + private Method(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Method forValue(final String value) { + return Promoter.enumFromString(value, Method.values()); + } + } + + public enum ConversationsV2ConversationGroupingType { + GROUP_BY_PROFILE("GROUP_BY_PROFILE"), + GROUP_BY_PARTICIPANT_ADDRESSES("GROUP_BY_PARTICIPANT_ADDRESSES"), + GROUP_BY_PARTICIPANT_ADDRESSES_AND_CHANNEL_TYPE( + "GROUP_BY_PARTICIPANT_ADDRESSES_AND_CHANNEL_TYPE" + ); + + private final String value; + + private ConversationsV2ConversationGroupingType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2ConversationGroupingType forValue( + final String value + ) { + return Promoter.enumFromString( + value, + ConversationsV2ConversationGroupingType.values() + ); + } + } + + @JsonDeserialize(builder = ConversationWorkflow.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationWorkflow { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("flowId") + @Getter + private final String flowId; + + private ConversationWorkflow(Builder builder) { + this.flowId = builder.flowId; + } + + public static Builder builder(final String flowId) { + return new Builder(flowId); + } + + public static ConversationWorkflow fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ConversationWorkflow.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("flowId") + private String flowId; + + @JsonCreator + public Builder(@JsonProperty("flowId") final String flowId) { + this.flowId = flowId; + } + + public ConversationWorkflow build() { + return new ConversationWorkflow(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationWorkflow other = (ConversationWorkflow) o; + return (Objects.equals(flowId, other.flowId)); + } + + @Override + public int hashCode() { + return Objects.hash(flowId); + } + } + + @JsonDeserialize( + builder = ListConversationByAccount200ResponseConversationsConfiguration.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListConversationByAccount200ResponseConversationsConfiguration { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + @Getter + private final Conversation.ConversationsV2ConversationGroupingType conversationGroupingType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + @Getter + private final String memoryStoreId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + @Getter + private final Map channelSettings; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + @Getter + private final List statusCallbacks; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + @Getter + private final List intelligenceConfigurationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitExtractionStrategyIds") + @Getter + private final List traitExtractionStrategyIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observationExtractionStrategyIds") + @Getter + private final List observationExtractionStrategyIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + @Getter + private final Boolean memoryExtractionEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("redactionConfigurationId") + @Getter + private final String redactionConfigurationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + @Getter + private final ConversationsV2ConversationsV1Bridge conversationsV1Bridge; + + private ListConversationByAccount200ResponseConversationsConfiguration( + Builder builder + ) { + this.displayName = builder.displayName; + this.description = builder.description; + this.conversationGroupingType = builder.conversationGroupingType; + this.memoryStoreId = builder.memoryStoreId; + this.channelSettings = builder.channelSettings; + this.statusCallbacks = builder.statusCallbacks; + this.intelligenceConfigurationIds = + builder.intelligenceConfigurationIds; + this.traitExtractionStrategyIds = + builder.traitExtractionStrategyIds; + this.observationExtractionStrategyIds = + builder.observationExtractionStrategyIds; + this.memoryExtractionEnabled = builder.memoryExtractionEnabled; + this.redactionConfigurationId = builder.redactionConfigurationId; + this.conversationsV1Bridge = builder.conversationsV1Bridge; + } + + public static Builder builder() { + return new Builder(); + } + + public static ListConversationByAccount200ResponseConversationsConfiguration fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListConversationByAccount200ResponseConversationsConfiguration.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("conversationGroupingType") + private Conversation.ConversationsV2ConversationGroupingType conversationGroupingType; + + @JsonProperty("memoryStoreId") + private String memoryStoreId; + + @JsonProperty("channelSettings") + private Map channelSettings; + + @JsonProperty("statusCallbacks") + private List statusCallbacks; + + @JsonProperty("intelligenceConfigurationIds") + private List intelligenceConfigurationIds; + + @JsonProperty("traitExtractionStrategyIds") + private List traitExtractionStrategyIds; + + @JsonProperty("observationExtractionStrategyIds") + private List observationExtractionStrategyIds; + + @JsonProperty("memoryExtractionEnabled") + private Boolean memoryExtractionEnabled; + + @JsonProperty("redactionConfigurationId") + private String redactionConfigurationId; + + @JsonProperty("conversationsV1Bridge") + private ConversationsV2ConversationsV1Bridge conversationsV1Bridge; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + public Builder conversationGroupingType( + Conversation.ConversationsV2ConversationGroupingType conversationGroupingType + ) { + this.conversationGroupingType = conversationGroupingType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + public Builder memoryStoreId(String memoryStoreId) { + this.memoryStoreId = memoryStoreId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + public Builder channelSettings( + Map channelSettings + ) { + this.channelSettings = channelSettings; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + public Builder statusCallbacks( + List statusCallbacks + ) { + this.statusCallbacks = statusCallbacks; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + public Builder intelligenceConfigurationIds( + List intelligenceConfigurationIds + ) { + this.intelligenceConfigurationIds = + intelligenceConfigurationIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitExtractionStrategyIds") + public Builder traitExtractionStrategyIds( + List traitExtractionStrategyIds + ) { + this.traitExtractionStrategyIds = traitExtractionStrategyIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observationExtractionStrategyIds") + public Builder observationExtractionStrategyIds( + List observationExtractionStrategyIds + ) { + this.observationExtractionStrategyIds = + observationExtractionStrategyIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + public Builder memoryExtractionEnabled( + Boolean memoryExtractionEnabled + ) { + this.memoryExtractionEnabled = memoryExtractionEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("redactionConfigurationId") + public Builder redactionConfigurationId( + String redactionConfigurationId + ) { + this.redactionConfigurationId = redactionConfigurationId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationsV1Bridge") + public Builder conversationsV1Bridge( + ConversationsV2ConversationsV1Bridge conversationsV1Bridge + ) { + this.conversationsV1Bridge = conversationsV1Bridge; + return this; + } + + public ListConversationByAccount200ResponseConversationsConfiguration build() { + return new ListConversationByAccount200ResponseConversationsConfiguration( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListConversationByAccount200ResponseConversationsConfiguration other = + (ListConversationByAccount200ResponseConversationsConfiguration) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals( + conversationGroupingType, + other.conversationGroupingType + ) && + Objects.equals(memoryStoreId, other.memoryStoreId) && + Objects.equals(channelSettings, other.channelSettings) && + Objects.equals(statusCallbacks, other.statusCallbacks) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + traitExtractionStrategyIds, + other.traitExtractionStrategyIds + ) && + Objects.equals( + observationExtractionStrategyIds, + other.observationExtractionStrategyIds + ) && + Objects.equals( + memoryExtractionEnabled, + other.memoryExtractionEnabled + ) && + Objects.equals( + redactionConfigurationId, + other.redactionConfigurationId + ) && + Objects.equals( + conversationsV1Bridge, + other.conversationsV1Bridge + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + displayName, + description, + conversationGroupingType, + memoryStoreId, + channelSettings, + statusCallbacks, + intelligenceConfigurationIds, + traitExtractionStrategyIds, + observationExtractionStrategyIds, + memoryExtractionEnabled, + redactionConfigurationId, + conversationsV1Bridge + ); + } + } + + @JsonDeserialize( + builder = CreateConversationWithConfigRequestParticipants.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationWithConfigRequestParticipants { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Conversation.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + @Getter + private final List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses; + + private CreateConversationWithConfigRequestParticipants( + Builder builder + ) { + this.name = builder.name; + this.type = builder.type; + this.profileId = builder.profileId; + this.addresses = builder.addresses; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateConversationWithConfigRequestParticipants fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationWithConfigRequestParticipants.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private Conversation.Type type; + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("addresses") + private List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Conversation.Type type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + public Builder profileId(String profileId) { + this.profileId = profileId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + public Builder addresses( + List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses + ) { + this.addresses = addresses; + return this; + } + + public CreateConversationWithConfigRequestParticipants build() { + return new CreateConversationWithConfigRequestParticipants( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationWithConfigRequestParticipants other = + (CreateConversationWithConfigRequestParticipants) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(type, other.type) && + Objects.equals(profileId, other.profileId) && + Objects.equals(addresses, other.addresses) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, type, profileId, addresses); + } + } + + @JsonDeserialize(builder = PatchConversationByIdRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PatchConversationByIdRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final Conversation.Status status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + @Getter + private final PatchConversationByIdRequestConfiguration configuration; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + @Getter + private final Map metadata; + + private PatchConversationByIdRequest(Builder builder) { + this.name = builder.name; + this.status = builder.status; + this.configuration = builder.configuration; + this.metadata = builder.metadata; + } + + public static Builder builder() { + return new Builder(); + } + + public static PatchConversationByIdRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + PatchConversationByIdRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("status") + private Conversation.Status status; + + @JsonProperty("configuration") + private PatchConversationByIdRequestConfiguration configuration; + + @JsonProperty("metadata") + private Map metadata; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + public Builder status(Conversation.Status status) { + this.status = status; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + public Builder configuration( + PatchConversationByIdRequestConfiguration configuration + ) { + this.configuration = configuration; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + public Builder metadata(Map metadata) { + this.metadata = metadata; + return this; + } + + public PatchConversationByIdRequest build() { + return new PatchConversationByIdRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PatchConversationByIdRequest other = + (PatchConversationByIdRequest) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(status, other.status) && + Objects.equals(configuration, other.configuration) && + Objects.equals(metadata, other.metadata) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, status, configuration, metadata); + } + } + + @JsonDeserialize( + builder = CreateConversationWithConfigRequestConfigurationChannelSettingsValue.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationWithConfigRequestConfigurationChannelSettingsValue { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + @Getter + private final CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts statusTimeouts; + + private CreateConversationWithConfigRequestConfigurationChannelSettingsValue( + Builder builder + ) { + this.statusTimeouts = builder.statusTimeouts; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateConversationWithConfigRequestConfigurationChannelSettingsValue fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationWithConfigRequestConfigurationChannelSettingsValue.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("statusTimeouts") + private CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts statusTimeouts; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusTimeouts") + public Builder statusTimeouts( + CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts statusTimeouts + ) { + this.statusTimeouts = statusTimeouts; + return this; + } + + public CreateConversationWithConfigRequestConfigurationChannelSettingsValue build() { + return new CreateConversationWithConfigRequestConfigurationChannelSettingsValue( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationWithConfigRequestConfigurationChannelSettingsValue other = + (CreateConversationWithConfigRequestConfigurationChannelSettingsValue) o; + return (Objects.equals(statusTimeouts, other.statusTimeouts)); + } + + @Override + public int hashCode() { + return Objects.hash(statusTimeouts); + } + } + + @JsonDeserialize( + builder = CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inactive") + @Getter + private final Integer inactive; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("closed") + @Getter + private final Integer closed; + + private CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts( + Builder builder + ) { + this.inactive = builder.inactive; + this.closed = builder.closed; + } + + public static Builder builder(final Integer closed) { + return new Builder(closed); + } + + public static CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("inactive") + private Integer inactive; + + @JsonProperty("closed") + private Integer closed; + + @JsonCreator + public Builder(@JsonProperty("closed") final Integer closed) { + this.closed = closed; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inactive") + public Builder inactive(Integer inactive) { + this.inactive = inactive; + return this; + } + + public CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts build() { + return new CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts other = + (CreateConversationWithConfigRequestConfigurationChannelSettingsValueStatusTimeouts) o; + return ( + Objects.equals(inactive, other.inactive) && + Objects.equals(closed, other.closed) + ); + } + + @Override + public int hashCode() { + return Objects.hash(inactive, closed); + } + } + + @JsonDeserialize( + builder = ListConversationByAccount200ResponseMeta.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListConversationByAccount200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListConversationByAccount200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static ListConversationByAccount200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListConversationByAccount200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListConversationByAccount200ResponseMeta build() { + return new ListConversationByAccount200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListConversationByAccount200ResponseMeta other = + (ListConversationByAccount200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize( + builder = CreateConversationWithConfigRequestConfiguration.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationWithConfigRequestConfiguration { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + @Getter + private final Conversation.ConversationGroupingType conversationGroupingType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + @Getter + private final String memoryStoreId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + @Getter + private final Map< + String, + CreateConversationWithConfigRequestConfigurationChannelSettingsValue + > channelSettings; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + @Getter + private final Boolean memoryExtractionEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + @Getter + private final List intelligenceConfigurationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitExtractionStrategyIds") + @Getter + private final List traitExtractionStrategyIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observationExtractionStrategyIds") + @Getter + private final List observationExtractionStrategyIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + @Getter + private final List< + CreateConversationWithConfigRequestConfigurationStatusCallbacks + > statusCallbacks; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("workflows") + @Getter + private final List workflows; + + private CreateConversationWithConfigRequestConfiguration( + Builder builder + ) { + this.conversationGroupingType = builder.conversationGroupingType; + this.memoryStoreId = builder.memoryStoreId; + this.channelSettings = builder.channelSettings; + this.memoryExtractionEnabled = builder.memoryExtractionEnabled; + this.intelligenceConfigurationIds = + builder.intelligenceConfigurationIds; + this.traitExtractionStrategyIds = + builder.traitExtractionStrategyIds; + this.observationExtractionStrategyIds = + builder.observationExtractionStrategyIds; + this.statusCallbacks = builder.statusCallbacks; + this.workflows = builder.workflows; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateConversationWithConfigRequestConfiguration fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationWithConfigRequestConfiguration.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("conversationGroupingType") + private Conversation.ConversationGroupingType conversationGroupingType; + + @JsonProperty("memoryStoreId") + private String memoryStoreId; + + @JsonProperty("channelSettings") + private Map< + String, + CreateConversationWithConfigRequestConfigurationChannelSettingsValue + > channelSettings; + + @JsonProperty("memoryExtractionEnabled") + private Boolean memoryExtractionEnabled; + + @JsonProperty("intelligenceConfigurationIds") + private List intelligenceConfigurationIds; + + @JsonProperty("traitExtractionStrategyIds") + private List traitExtractionStrategyIds; + + @JsonProperty("observationExtractionStrategyIds") + private List observationExtractionStrategyIds; + + @JsonProperty("statusCallbacks") + private List< + CreateConversationWithConfigRequestConfigurationStatusCallbacks + > statusCallbacks; + + @JsonProperty("workflows") + private List workflows; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationGroupingType") + public Builder conversationGroupingType( + Conversation.ConversationGroupingType conversationGroupingType + ) { + this.conversationGroupingType = conversationGroupingType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + public Builder memoryStoreId(String memoryStoreId) { + this.memoryStoreId = memoryStoreId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelSettings") + public Builder channelSettings( + Map< + String, + CreateConversationWithConfigRequestConfigurationChannelSettingsValue + > channelSettings + ) { + this.channelSettings = channelSettings; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryExtractionEnabled") + public Builder memoryExtractionEnabled( + Boolean memoryExtractionEnabled + ) { + this.memoryExtractionEnabled = memoryExtractionEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + public Builder intelligenceConfigurationIds( + List intelligenceConfigurationIds + ) { + this.intelligenceConfigurationIds = + intelligenceConfigurationIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitExtractionStrategyIds") + public Builder traitExtractionStrategyIds( + List traitExtractionStrategyIds + ) { + this.traitExtractionStrategyIds = traitExtractionStrategyIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observationExtractionStrategyIds") + public Builder observationExtractionStrategyIds( + List observationExtractionStrategyIds + ) { + this.observationExtractionStrategyIds = + observationExtractionStrategyIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + public Builder statusCallbacks( + List< + CreateConversationWithConfigRequestConfigurationStatusCallbacks + > statusCallbacks + ) { + this.statusCallbacks = statusCallbacks; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("workflows") + public Builder workflows(List workflows) { + this.workflows = workflows; + return this; + } + + public CreateConversationWithConfigRequestConfiguration build() { + return new CreateConversationWithConfigRequestConfiguration( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationWithConfigRequestConfiguration other = + (CreateConversationWithConfigRequestConfiguration) o; + return ( + Objects.equals( + conversationGroupingType, + other.conversationGroupingType + ) && + Objects.equals(memoryStoreId, other.memoryStoreId) && + Objects.equals(channelSettings, other.channelSettings) && + Objects.equals( + memoryExtractionEnabled, + other.memoryExtractionEnabled + ) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + traitExtractionStrategyIds, + other.traitExtractionStrategyIds + ) && + Objects.equals( + observationExtractionStrategyIds, + other.observationExtractionStrategyIds + ) && + Objects.equals(statusCallbacks, other.statusCallbacks) && + Objects.equals(workflows, other.workflows) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + conversationGroupingType, + memoryStoreId, + channelSettings, + memoryExtractionEnabled, + intelligenceConfigurationIds, + traitExtractionStrategyIds, + observationExtractionStrategyIds, + statusCallbacks, + workflows + ); + } + } + + @JsonDeserialize( + builder = CreateConversationWithConfigRequestConfigurationStatusCallbacks.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationWithConfigRequestConfigurationStatusCallbacks { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final URI url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + @Getter + private final Conversation.Method method; + + private CreateConversationWithConfigRequestConfigurationStatusCallbacks( + Builder builder + ) { + this.url = builder.url; + this.method = builder.method; + } + + public static Builder builder(final URI url) { + return new Builder(url); + } + + public static CreateConversationWithConfigRequestConfigurationStatusCallbacks fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationWithConfigRequestConfigurationStatusCallbacks.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("url") + private URI url; + + @JsonProperty("method") + private Conversation.Method method; + + @JsonCreator + public Builder(@JsonProperty("url") final URI url) { + this.url = url; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + public Builder method(Conversation.Method method) { + this.method = method; + return this; + } + + public CreateConversationWithConfigRequestConfigurationStatusCallbacks build() { + return new CreateConversationWithConfigRequestConfigurationStatusCallbacks( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationWithConfigRequestConfigurationStatusCallbacks other = + (CreateConversationWithConfigRequestConfigurationStatusCallbacks) o; + return ( + Objects.equals(url, other.url) && + Objects.equals(method, other.method) + ); + } + + @Override + public int hashCode() { + return Objects.hash(url, method); + } + } + + @JsonDeserialize(builder = ConversationsV2Participant.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2Participant { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountId") + @Getter + private final String accountId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Conversation.ConversationsV2ParticipantType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + @Getter + private final List addresses; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + private ConversationsV2Participant(Builder builder) { + this.id = builder.id; + this.conversationId = builder.conversationId; + this.accountId = builder.accountId; + this.name = builder.name; + this.type = builder.type; + this.profileId = builder.profileId; + this.addresses = builder.addresses; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + } + + public static Builder builder( + final String id, + final String conversationId, + final String accountId + ) { + return new Builder(id, conversationId, accountId); + } + + public static ConversationsV2Participant fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2Participant.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonProperty("accountId") + private String accountId; + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private Conversation.ConversationsV2ParticipantType type; + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("addresses") + private List addresses; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("accountId") final String accountId + ) { + this.id = id; + this.conversationId = conversationId; + this.accountId = accountId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type( + Conversation.ConversationsV2ParticipantType type + ) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + public Builder profileId(String profileId) { + this.profileId = profileId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + public Builder addresses(List addresses) { + this.addresses = addresses; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + public Builder updatedAt(ZonedDateTime updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + public ConversationsV2Participant build() { + return new ConversationsV2Participant(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2Participant other = (ConversationsV2Participant) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(accountId, other.accountId) && + Objects.equals(name, other.name) && + Objects.equals(type, other.type) && + Objects.equals(profileId, other.profileId) && + Objects.equals(addresses, other.addresses) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + conversationId, + accountId, + name, + type, + profileId, + addresses, + createdAt, + updatedAt + ); + } + } + + @JsonDeserialize(builder = UpdateConversationByIdRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateConversationByIdRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final Conversation.Status status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + @Getter + private final Map metadata; + + private UpdateConversationByIdRequest(Builder builder) { + this.name = builder.name; + this.status = builder.status; + this.metadata = builder.metadata; + } + + public static Builder builder(final Conversation.Status status) { + return new Builder(status); + } + + public static UpdateConversationByIdRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateConversationByIdRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("status") + private Conversation.Status status; + + @JsonProperty("metadata") + private Map metadata; + + @JsonCreator + public Builder( + @JsonProperty("status") final Conversation.Status status + ) { + this.status = status; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + public Builder metadata(Map metadata) { + this.metadata = metadata; + return this; + } + + public UpdateConversationByIdRequest build() { + return new UpdateConversationByIdRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateConversationByIdRequest other = + (UpdateConversationByIdRequest) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(status, other.status) && + Objects.equals(metadata, other.metadata) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, status, metadata); + } + } + + @JsonDeserialize( + builder = ConversationsV2StatusCallbackConfig.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2StatusCallbackConfig { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final URI url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + @Getter + private final Conversation.Method method; + + private ConversationsV2StatusCallbackConfig(Builder builder) { + this.url = builder.url; + this.method = builder.method; + } + + public static Builder builder(final URI url) { + return new Builder(url); + } + + public static ConversationsV2StatusCallbackConfig fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2StatusCallbackConfig.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("url") + private URI url; + + @JsonProperty("method") + private Conversation.Method method; + + @JsonCreator + public Builder(@JsonProperty("url") final URI url) { + this.url = url; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + public Builder method(Conversation.Method method) { + this.method = method; + return this; + } + + public ConversationsV2StatusCallbackConfig build() { + return new ConversationsV2StatusCallbackConfig(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2StatusCallbackConfig other = + (ConversationsV2StatusCallbackConfig) o; + return ( + Objects.equals(url, other.url) && + Objects.equals(method, other.method) + ); + } + + @Override + public int hashCode() { + return Objects.hash(url, method); + } + } + + @JsonDeserialize( + builder = PatchConversationByIdRequestConfiguration.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PatchConversationByIdRequestConfiguration { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + @Getter + private final List statusCallbacks; + + private PatchConversationByIdRequestConfiguration(Builder builder) { + this.statusCallbacks = builder.statusCallbacks; + } + + public static Builder builder() { + return new Builder(); + } + + public static PatchConversationByIdRequestConfiguration fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + PatchConversationByIdRequestConfiguration.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("statusCallbacks") + private List statusCallbacks; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbacks") + public Builder statusCallbacks( + List statusCallbacks + ) { + this.statusCallbacks = statusCallbacks; + return this; + } + + public PatchConversationByIdRequestConfiguration build() { + return new PatchConversationByIdRequestConfiguration(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PatchConversationByIdRequestConfiguration other = + (PatchConversationByIdRequestConfiguration) o; + return (Objects.equals(statusCallbacks, other.statusCallbacks)); + } + + @Override + public int hashCode() { + return Objects.hash(statusCallbacks); + } + } + + @JsonDeserialize( + builder = ListConversationByAccount200ResponseConversations.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListConversationByAccount200ResponseConversations { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountId") + @Getter + private final String accountId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configurationId") + @Getter + private final String configurationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final Conversation.ConversationsV2ConversationStatus status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + @Getter + private final ListConversationByAccount200ResponseConversationsConfiguration configuration; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + @Getter + private final Map metadata; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participants") + @Getter + private final List participants; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actionId") + @Getter + private final String actionId; + + private ListConversationByAccount200ResponseConversations( + Builder builder + ) { + this.id = builder.id; + this.accountId = builder.accountId; + this.configurationId = builder.configurationId; + this.status = builder.status; + this.name = builder.name; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.configuration = builder.configuration; + this.metadata = builder.metadata; + this.participants = builder.participants; + this.actionId = builder.actionId; + } + + public static Builder builder(final String id, final String accountId) { + return new Builder(id, accountId); + } + + public static ListConversationByAccount200ResponseConversations fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListConversationByAccount200ResponseConversations.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("accountId") + private String accountId; + + @JsonProperty("configurationId") + private String configurationId; + + @JsonProperty("status") + private Conversation.ConversationsV2ConversationStatus status; + + @JsonProperty("name") + private String name; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonProperty("configuration") + private ListConversationByAccount200ResponseConversationsConfiguration configuration; + + @JsonProperty("metadata") + private Map metadata; + + @JsonProperty("participants") + private List participants; + + @JsonProperty("actionId") + private String actionId; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("accountId") final String accountId + ) { + this.id = id; + this.accountId = accountId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configurationId") + public Builder configurationId(String configurationId) { + this.configurationId = configurationId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + public Builder status( + Conversation.ConversationsV2ConversationStatus status + ) { + this.status = status; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + public Builder updatedAt(ZonedDateTime updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + public Builder configuration( + ListConversationByAccount200ResponseConversationsConfiguration configuration + ) { + this.configuration = configuration; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + public Builder metadata(Map metadata) { + this.metadata = metadata; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participants") + public Builder participants( + List participants + ) { + this.participants = participants; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actionId") + public Builder actionId(String actionId) { + this.actionId = actionId; + return this; + } + + public ListConversationByAccount200ResponseConversations build() { + return new ListConversationByAccount200ResponseConversations( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListConversationByAccount200ResponseConversations other = + (ListConversationByAccount200ResponseConversations) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(accountId, other.accountId) && + Objects.equals(configurationId, other.configurationId) && + Objects.equals(status, other.status) && + Objects.equals(name, other.name) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(configuration, other.configuration) && + Objects.equals(metadata, other.metadata) && + Objects.equals(participants, other.participants) && + Objects.equals(actionId, other.actionId) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + accountId, + configurationId, + status, + name, + createdAt, + updatedAt, + configuration, + metadata, + participants, + actionId + ); + } + } + + @JsonDeserialize( + builder = CreateConversationWithConfigRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationWithConfigRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configurationId") + @Getter + private final String configurationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + @Getter + private final CreateConversationWithConfigRequestConfiguration configuration; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participants") + @Getter + private final List< + CreateConversationWithConfigRequestParticipants + > participants; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + @Getter + private final Map metadata; + + private CreateConversationWithConfigRequest(Builder builder) { + this.configurationId = builder.configurationId; + this.name = builder.name; + this.configuration = builder.configuration; + this.participants = builder.participants; + this.metadata = builder.metadata; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateConversationWithConfigRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationWithConfigRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("configurationId") + private String configurationId; + + @JsonProperty("name") + private String name; + + @JsonProperty("configuration") + private CreateConversationWithConfigRequestConfiguration configuration; + + @JsonProperty("participants") + private List< + CreateConversationWithConfigRequestParticipants + > participants; + + @JsonProperty("metadata") + private Map metadata; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configurationId") + public Builder configurationId(String configurationId) { + this.configurationId = configurationId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + public Builder configuration( + CreateConversationWithConfigRequestConfiguration configuration + ) { + this.configuration = configuration; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participants") + public Builder participants( + List< + CreateConversationWithConfigRequestParticipants + > participants + ) { + this.participants = participants; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + public Builder metadata(Map metadata) { + this.metadata = metadata; + return this; + } + + public CreateConversationWithConfigRequest build() { + return new CreateConversationWithConfigRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationWithConfigRequest other = + (CreateConversationWithConfigRequest) o; + return ( + Objects.equals(configurationId, other.configurationId) && + Objects.equals(name, other.name) && + Objects.equals(configuration, other.configuration) && + Objects.equals(participants, other.participants) && + Objects.equals(metadata, other.metadata) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + configurationId, + name, + configuration, + participants, + metadata + ); + } + } + + @JsonDeserialize( + builder = ConversationsV2ConversationsV1Bridge.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2ConversationsV1Bridge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("serviceId") + @Getter + private final String serviceId; + + private ConversationsV2ConversationsV1Bridge(Builder builder) { + this.serviceId = builder.serviceId; + } + + public static Builder builder(final String serviceId) { + return new Builder(serviceId); + } + + public static ConversationsV2ConversationsV1Bridge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConversationsV2ConversationsV1Bridge.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("serviceId") + private String serviceId; + + @JsonCreator + public Builder(@JsonProperty("serviceId") final String serviceId) { + this.serviceId = serviceId; + } + + public ConversationsV2ConversationsV1Bridge build() { + return new ConversationsV2ConversationsV1Bridge(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2ConversationsV1Bridge other = + (ConversationsV2ConversationsV1Bridge) o; + return (Objects.equals(serviceId, other.serviceId)); + } + + @Override + public int hashCode() { + return Objects.hash(serviceId); + } + } + + @JsonDeserialize(builder = ConversationsV2Address.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2Address { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Conversation.ConversationsV2Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + @Getter + private final String channelId; + + private ConversationsV2Address(Builder builder) { + this.channel = builder.channel; + this.address = builder.address; + this.channelId = builder.channelId; + } + + public static Builder builder( + final Conversation.ConversationsV2Channel channel, + final String address + ) { + return new Builder(channel, address); + } + + public static ConversationsV2Address fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ConversationsV2Address.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("channel") + private Conversation.ConversationsV2Channel channel; + + @JsonProperty("address") + private String address; + + @JsonProperty("channelId") + private String channelId; + + @JsonCreator + public Builder( + @JsonProperty( + "channel" + ) final Conversation.ConversationsV2Channel channel, + @JsonProperty("address") final String address + ) { + this.channel = channel; + this.address = address; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + public Builder channelId(String channelId) { + this.channelId = channelId; + return this; + } + + public ConversationsV2Address build() { + return new ConversationsV2Address(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2Address other = (ConversationsV2Address) o; + return ( + Objects.equals(channel, other.channel) && + Objects.equals(address, other.address) && + Objects.equals(channelId, other.channelId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(channel, address, channelId); + } + } + + @JsonDeserialize( + builder = CreateConversationWithConfigRequestParticipantsAddresses.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationWithConfigRequestParticipantsAddresses { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Conversation.Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + @Getter + private final String channelId; + + private CreateConversationWithConfigRequestParticipantsAddresses( + Builder builder + ) { + this.channel = builder.channel; + this.address = builder.address; + this.channelId = builder.channelId; + } + + public static Builder builder( + final Conversation.Channel channel, + final String address + ) { + return new Builder(channel, address); + } + + public static CreateConversationWithConfigRequestParticipantsAddresses fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationWithConfigRequestParticipantsAddresses.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("channel") + private Conversation.Channel channel; + + @JsonProperty("address") + private String address; + + @JsonProperty("channelId") + private String channelId; + + @JsonCreator + public Builder( + @JsonProperty("channel") final Conversation.Channel channel, + @JsonProperty("address") final String address + ) { + this.channel = channel; + this.address = address; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + public Builder channelId(String channelId) { + this.channelId = channelId; + return this; + } + + public CreateConversationWithConfigRequestParticipantsAddresses build() { + return new CreateConversationWithConfigRequestParticipantsAddresses( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationWithConfigRequestParticipantsAddresses other = + (CreateConversationWithConfigRequestParticipantsAddresses) o; + return ( + Objects.equals(channel, other.channel) && + Objects.equals(address, other.address) && + Objects.equals(channelId, other.channelId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(channel, address, channelId); + } + } + + /** + * Converts a JSON String into a Conversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Conversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Conversation() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConversationCreator.java b/src/main/java/com/twilio/rest/conversations/v2/ConversationCreator.java new file mode 100644 index 0000000000..ec802a98c1 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConversationCreator.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationCreator + extends Creator { + + private Conversation.CreateConversationWithConfigRequest createConversationWithConfigRequest; + + public ConversationCreator() {} + + public ConversationCreator setCreateConversationWithConfigRequest( + final Conversation.CreateConversationWithConfigRequest createConversationWithConfigRequest + ) { + this.createConversationWithConfigRequest = + createConversationWithConfigRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations"; + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation.CreateConversationResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Conversation.CreateConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Conversation.CreateConversationResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Conversation.CreateConversationResponse content = + Conversation.CreateConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createConversationWithConfigRequest != null) { + request.setBody( + Conversation.toJson( + createConversationWithConfigRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConversationDeleter.java b/src/main/java/com/twilio/rest/conversations/v2/ConversationDeleter.java new file mode 100644 index 0000000000..bb1045bf2b --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConversationDeleter.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ConversationDeleter + extends ResourceDeleter< + Conversation, + Conversation.DeleteConversationResponse + > { + + private String pathId; + private String idempotencyKey; + + public ConversationDeleter(final String pathId) { + this.pathId = pathId; + } + + public ConversationDeleter setIdempotencyKey(final String idempotencyKey) { + this.idempotencyKey = idempotencyKey; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.CONVERSATIONS.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation.DeleteConversationResponse delete( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Conversation.DeleteConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Conversation.DeleteConversationResponse + > deleteWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Conversation.DeleteConversationResponse content = + Conversation.DeleteConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (idempotencyKey != null) { + Serializer.toString( + request, + "Idempotency-Key", + idempotencyKey, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConversationFetcher.java b/src/main/java/com/twilio/rest/conversations/v2/ConversationFetcher.java new file mode 100644 index 0000000000..b584b85766 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConversationFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationFetcher + extends Fetcher { + + private String pathId; + + public ConversationFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation.FetchConversationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Conversation.FetchConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Conversation.FetchConversationResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Conversation.FetchConversationResponse content = + Conversation.FetchConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConversationPatcher.java b/src/main/java/com/twilio/rest/conversations/v2/ConversationPatcher.java new file mode 100644 index 0000000000..a86b31d3a6 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConversationPatcher.java @@ -0,0 +1,99 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationPatcher + extends Patcher { + + private String pathId; + private Conversation.PatchConversationByIdRequest patchConversationByIdRequest; + + public ConversationPatcher(final String pathId) { + this.pathId = pathId; + } + + public ConversationPatcher setPatchConversationByIdRequest( + final Conversation.PatchConversationByIdRequest patchConversationByIdRequest + ) { + this.patchConversationByIdRequest = patchConversationByIdRequest; + return this; + } + + @Override + public Conversation.PatchConversationResponse patch( + final TwilioRestClient client + ) { + String path = "/v2/Conversations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PATCH, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Conversation.PatchConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (patchConversationByIdRequest != null) { + request.setBody( + Conversation.toJson(patchConversationByIdRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConversationReader.java b/src/main/java/com/twilio/rest/conversations/v2/ConversationReader.java new file mode 100644 index 0000000000..5013c12e15 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConversationReader.java @@ -0,0 +1,281 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class ConversationReader + extends Reader { + + private List status; + private String channelId; + private Integer pageSize; + private String pageToken; + + public ConversationReader() {} + + public ConversationReader setStatus( + final List status + ) { + this.status = status; + return this; + } + + public ConversationReader setStatus(final Conversation.Status status) { + return setStatus(Promoter.listOfOne(status)); + } + + public ConversationReader setChannelId(final String channelId) { + this.channelId = channelId; + return this; + } + + public ConversationReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ConversationReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse< + Conversation.ListConversationResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + Conversation.ListConversationResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Conversations"; + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + Conversation.ListConversationResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Conversation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "conversations", + response.getContent(), + Conversation.ListConversationResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/Conversations"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/Conversations"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (status != null) { + for (Conversation.Status param : status) { + Serializer.toString( + request, + "status", + param, + ParameterType.QUERY + ); + } + } + + if (channelId != null) { + Serializer.toString( + request, + "channelId", + channelId, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ConversationUpdater.java b/src/main/java/com/twilio/rest/conversations/v2/ConversationUpdater.java new file mode 100644 index 0000000000..0e034d3254 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ConversationUpdater.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationUpdater + extends Updater { + + private String pathId; + private Conversation.UpdateConversationByIdRequest updateConversationByIdRequest; + + public ConversationUpdater(final String pathId) { + this.pathId = pathId; + } + + public ConversationUpdater setUpdateConversationByIdRequest( + final Conversation.UpdateConversationByIdRequest updateConversationByIdRequest + ) { + this.updateConversationByIdRequest = updateConversationByIdRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation.UpdateConversationResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Conversation.UpdateConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Conversation.UpdateConversationResponse + > updateWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Conversation.UpdateConversationResponse content = + Conversation.UpdateConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (updateConversationByIdRequest != null) { + request.setBody( + Conversation.toJson(updateConversationByIdRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/Operation.java b/src/main/java/com/twilio/rest/conversations/v2/Operation.java new file mode 100644 index 0000000000..2169a68cec --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/Operation.java @@ -0,0 +1,598 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Operation extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateOperationResponse extends Resource { + + @JsonCreator + private CreateOperationResponse() {} + + public static CreateOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateOperationResponse other = (CreateOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateOperationResponse extends Resource { + + @JsonCreator + private UpdateOperationResponse() {} + + public static UpdateOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateOperationResponse other = (UpdateOperationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteOperationResponse extends Resource { + + @JsonCreator + private DeleteOperationResponse() {} + + public static DeleteOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteOperationResponse other = (DeleteOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListOperationResponse extends Resource { + + @JsonCreator + private ListOperationResponse() {} + + public static ListOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListOperationResponse other = (ListOperationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchOperationResponse extends Resource { + + @JsonCreator + private PatchOperationResponse() {} + + public static PatchOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchOperationResponse other = (PatchOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchOperationResponse extends Resource { + + @Getter + private final ZonedDateTime completedAt; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final FetchOperationStatus200ResponseError error; + + @Getter + private final String operationId; + + @Getter + private final Map related; + + @Getter + private final Operation.ConversationsV2OperationStatusValue status; + + @Getter + private final URI statusUrl; + + @JsonCreator + private FetchOperationResponse( + @JsonProperty("completedAt") final ZonedDateTime completedAt, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty( + "error" + ) final FetchOperationStatus200ResponseError error, + @JsonProperty("operationId") final String operationId, + @JsonProperty("related") final Map related, + @JsonProperty( + "status" + ) final Operation.ConversationsV2OperationStatusValue status, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.completedAt = completedAt; + this.createdAt = createdAt; + this.error = error; + this.operationId = operationId; + this.related = related; + this.status = status; + this.statusUrl = statusUrl; + } + + public static FetchOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchOperationResponse other = (FetchOperationResponse) o; + return ( + Objects.equals(completedAt, other.completedAt) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(error, other.error) && + Objects.equals(operationId, other.operationId) && + Objects.equals(related, other.related) && + Objects.equals(status, other.status) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + completedAt, + createdAt, + error, + operationId, + related, + status, + statusUrl + ); + } + } + + public static OperationFetcher fetcher(final String pathId) { + return new OperationFetcher(pathId); + } + + public enum ConversationsV2OperationStatusValue { + PENDING("PENDING"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private ConversationsV2OperationStatusValue(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2OperationStatusValue forValue( + final String value + ) { + return Promoter.enumFromString( + value, + ConversationsV2OperationStatusValue.values() + ); + } + } + + @JsonDeserialize( + builder = FetchOperationStatus200ResponseError.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class FetchOperationStatus200ResponseError { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final URI type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final Integer status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + @Getter + private final String detail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("instance") + @Getter + private final URI instance; + + private FetchOperationStatus200ResponseError(Builder builder) { + this.type = builder.type; + this.title = builder.title; + this.status = builder.status; + this.detail = builder.detail; + this.instance = builder.instance; + } + + public static Builder builder() { + return new Builder(); + } + + public static FetchOperationStatus200ResponseError fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + FetchOperationStatus200ResponseError.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private URI type; + + @JsonProperty("title") + private String title; + + @JsonProperty("status") + private Integer status; + + @JsonProperty("detail") + private String detail; + + @JsonProperty("instance") + private URI instance; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(URI type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + public Builder title(String title) { + this.title = title; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + public Builder status(Integer status) { + this.status = status; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + public Builder detail(String detail) { + this.detail = detail; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("instance") + public Builder instance(URI instance) { + this.instance = instance; + return this; + } + + public FetchOperationStatus200ResponseError build() { + return new FetchOperationStatus200ResponseError(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FetchOperationStatus200ResponseError other = + (FetchOperationStatus200ResponseError) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(title, other.title) && + Objects.equals(status, other.status) && + Objects.equals(detail, other.detail) && + Objects.equals(instance, other.instance) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, title, status, detail, instance); + } + } + + /** + * Converts a JSON String into a Operation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Operation object represented by the provided JSON + */ + public static Operation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Operation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Operation object represented by the provided JSON + */ + public static Operation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Operation() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/OperationFetcher.java b/src/main/java/com/twilio/rest/conversations/v2/OperationFetcher.java new file mode 100644 index 0000000000..3af463c36c --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/OperationFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperationFetcher + extends Fetcher { + + private String pathId; + + public OperationFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/Operations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Operation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Operation.FetchOperationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Operation.FetchOperationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Operation.FetchOperationResponse content = + Operation.FetchOperationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/Participant.java b/src/main/java/com/twilio/rest/conversations/v2/Participant.java new file mode 100644 index 0000000000..e84ec861b2 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/Participant.java @@ -0,0 +1,1622 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Participant extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateParticipantResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final List addresses; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final String profileId; + + @Getter + private final Participant.ConversationsV2ParticipantType type; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private CreateParticipantResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("addresses") final List< + ConversationsV2Address + > addresses, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("profileId") final String profileId, + @JsonProperty( + "type" + ) final Participant.ConversationsV2ParticipantType type, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.addresses = addresses; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.name = name; + this.profileId = profileId; + this.type = type; + this.updatedAt = updatedAt; + } + + public static CreateParticipantResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateParticipantResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateParticipantResponse other = (CreateParticipantResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(addresses, other.addresses) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(profileId, other.profileId) && + Objects.equals(type, other.type) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + addresses, + conversationId, + createdAt, + id, + name, + profileId, + type, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateParticipantResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final List addresses; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final String profileId; + + @Getter + private final Participant.ConversationsV2ParticipantType type; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private UpdateParticipantResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("addresses") final List< + ConversationsV2Address + > addresses, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("profileId") final String profileId, + @JsonProperty( + "type" + ) final Participant.ConversationsV2ParticipantType type, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.addresses = addresses; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.name = name; + this.profileId = profileId; + this.type = type; + this.updatedAt = updatedAt; + } + + public static UpdateParticipantResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateParticipantResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateParticipantResponse other = (UpdateParticipantResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(addresses, other.addresses) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(profileId, other.profileId) && + Objects.equals(type, other.type) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + addresses, + conversationId, + createdAt, + id, + name, + profileId, + type, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteParticipantResponse extends Resource { + + @JsonCreator + private DeleteParticipantResponse() {} + + public static DeleteParticipantResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteParticipantResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteParticipantResponse other = (DeleteParticipantResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListParticipantResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final List addresses; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final String profileId; + + @Getter + private final Participant.ConversationsV2ParticipantType type; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListParticipantResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("addresses") final List< + ConversationsV2Address + > addresses, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("profileId") final String profileId, + @JsonProperty( + "type" + ) final Participant.ConversationsV2ParticipantType type, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.addresses = addresses; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.name = name; + this.profileId = profileId; + this.type = type; + this.updatedAt = updatedAt; + } + + public static ListParticipantResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListParticipantResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListParticipantResponse other = (ListParticipantResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(addresses, other.addresses) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(profileId, other.profileId) && + Objects.equals(type, other.type) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + addresses, + conversationId, + createdAt, + id, + name, + profileId, + type, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchParticipantResponse extends Resource { + + @JsonCreator + private PatchParticipantResponse() {} + + public static PatchParticipantResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchParticipantResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchParticipantResponse other = (PatchParticipantResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchParticipantResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final List addresses; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final String profileId; + + @Getter + private final Participant.ConversationsV2ParticipantType type; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchParticipantResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("addresses") final List< + ConversationsV2Address + > addresses, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("profileId") final String profileId, + @JsonProperty( + "type" + ) final Participant.ConversationsV2ParticipantType type, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.addresses = addresses; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.name = name; + this.profileId = profileId; + this.type = type; + this.updatedAt = updatedAt; + } + + public static FetchParticipantResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchParticipantResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchParticipantResponse other = (FetchParticipantResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(addresses, other.addresses) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(profileId, other.profileId) && + Objects.equals(type, other.type) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + addresses, + conversationId, + createdAt, + id, + name, + profileId, + type, + updatedAt + ); + } + } + + public static ParticipantCreator creator(final String pathConversationId) { + return new ParticipantCreator(pathConversationId); + } + + public static ParticipantFetcher fetcher( + final String pathConversationId, + final String pathId + ) { + return new ParticipantFetcher(pathConversationId, pathId); + } + + public static ParticipantReader reader(final String pathConversationId) { + return new ParticipantReader(pathConversationId); + } + + public static ParticipantUpdater updater( + final String pathConversationId, + final String pathId + ) { + return new ParticipantUpdater(pathConversationId, pathId); + } + + public enum Type { + HUMAN_AGENT("HUMAN_AGENT"), + CUSTOMER("CUSTOMER"), + AI_AGENT("AI_AGENT"), + AGENT("AGENT"), + UNKNOWN("UNKNOWN"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum ConversationsV2Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + VIDEO("VIDEO"); + + private final String value; + + private ConversationsV2Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2Channel forValue(final String value) { + return Promoter.enumFromString( + value, + ConversationsV2Channel.values() + ); + } + } + + public enum ConversationsV2ParticipantType { + HUMAN_AGENT("HUMAN_AGENT"), + CUSTOMER("CUSTOMER"), + AI_AGENT("AI_AGENT"), + AGENT("AGENT"), + UNKNOWN("UNKNOWN"); + + private final String value; + + private ConversationsV2ParticipantType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationsV2ParticipantType forValue( + final String value + ) { + return Promoter.enumFromString( + value, + ConversationsV2ParticipantType.values() + ); + } + } + + public enum Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + VIDEO("VIDEO"); + + private final String value; + + private Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Channel forValue(final String value) { + return Promoter.enumFromString(value, Channel.values()); + } + } + + @JsonDeserialize( + builder = ListParticipantByConversation200ResponseMeta.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListParticipantByConversation200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListParticipantByConversation200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static ListParticipantByConversation200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListParticipantByConversation200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListParticipantByConversation200ResponseMeta build() { + return new ListParticipantByConversation200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListParticipantByConversation200ResponseMeta other = + (ListParticipantByConversation200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize( + builder = UpdateParticipantInConversationRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateParticipantInConversationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Participant.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + @Getter + private final List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses; + + private UpdateParticipantInConversationRequest(Builder builder) { + this.name = builder.name; + this.type = builder.type; + this.profileId = builder.profileId; + this.addresses = builder.addresses; + } + + public static Builder builder() { + return new Builder(); + } + + public static UpdateParticipantInConversationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateParticipantInConversationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private Participant.Type type; + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("addresses") + private List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Participant.Type type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + public Builder profileId(String profileId) { + this.profileId = profileId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + public Builder addresses( + List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses + ) { + this.addresses = addresses; + return this; + } + + public UpdateParticipantInConversationRequest build() { + return new UpdateParticipantInConversationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateParticipantInConversationRequest other = + (UpdateParticipantInConversationRequest) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(type, other.type) && + Objects.equals(profileId, other.profileId) && + Objects.equals(addresses, other.addresses) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, type, profileId, addresses); + } + } + + @JsonDeserialize( + builder = CreateParticipantInConversationRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateParticipantInConversationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Participant.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + @Getter + private final List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses; + + private CreateParticipantInConversationRequest(Builder builder) { + this.name = builder.name; + this.type = builder.type; + this.profileId = builder.profileId; + this.addresses = builder.addresses; + } + + public static Builder builder( + final List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses + ) { + return new Builder(addresses); + } + + public static CreateParticipantInConversationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateParticipantInConversationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private Participant.Type type; + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("addresses") + private List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses; + + @JsonCreator + public Builder( + @JsonProperty("addresses") final List< + CreateConversationWithConfigRequestParticipantsAddresses + > addresses + ) { + this.addresses = addresses; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Participant.Type type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + public Builder profileId(String profileId) { + this.profileId = profileId; + return this; + } + + public CreateParticipantInConversationRequest build() { + return new CreateParticipantInConversationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateParticipantInConversationRequest other = + (CreateParticipantInConversationRequest) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(type, other.type) && + Objects.equals(profileId, other.profileId) && + Objects.equals(addresses, other.addresses) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, type, profileId, addresses); + } + } + + @JsonDeserialize( + builder = ListParticipantByConversation200ResponseParticipants.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListParticipantByConversation200ResponseParticipants { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountId") + @Getter + private final String accountId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Participant.ConversationsV2ParticipantType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + @Getter + private final List addresses; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + private ListParticipantByConversation200ResponseParticipants( + Builder builder + ) { + this.id = builder.id; + this.conversationId = builder.conversationId; + this.accountId = builder.accountId; + this.name = builder.name; + this.type = builder.type; + this.profileId = builder.profileId; + this.addresses = builder.addresses; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + } + + public static Builder builder( + final String id, + final String conversationId, + final String accountId + ) { + return new Builder(id, conversationId, accountId); + } + + public static ListParticipantByConversation200ResponseParticipants fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListParticipantByConversation200ResponseParticipants.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonProperty("accountId") + private String accountId; + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private Participant.ConversationsV2ParticipantType type; + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("addresses") + private List addresses; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("accountId") final String accountId + ) { + this.id = id; + this.conversationId = conversationId; + this.accountId = accountId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type( + Participant.ConversationsV2ParticipantType type + ) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + public Builder profileId(String profileId) { + this.profileId = profileId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addresses") + public Builder addresses(List addresses) { + this.addresses = addresses; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + public Builder updatedAt(ZonedDateTime updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + public ListParticipantByConversation200ResponseParticipants build() { + return new ListParticipantByConversation200ResponseParticipants( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListParticipantByConversation200ResponseParticipants other = + (ListParticipantByConversation200ResponseParticipants) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(accountId, other.accountId) && + Objects.equals(name, other.name) && + Objects.equals(type, other.type) && + Objects.equals(profileId, other.profileId) && + Objects.equals(addresses, other.addresses) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + conversationId, + accountId, + name, + type, + profileId, + addresses, + createdAt, + updatedAt + ); + } + } + + @JsonDeserialize(builder = ConversationsV2Address.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationsV2Address { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Participant.ConversationsV2Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + @Getter + private final String channelId; + + private ConversationsV2Address(Builder builder) { + this.channel = builder.channel; + this.address = builder.address; + this.channelId = builder.channelId; + } + + public static Builder builder( + final Participant.ConversationsV2Channel channel, + final String address + ) { + return new Builder(channel, address); + } + + public static ConversationsV2Address fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ConversationsV2Address.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("channel") + private Participant.ConversationsV2Channel channel; + + @JsonProperty("address") + private String address; + + @JsonProperty("channelId") + private String channelId; + + @JsonCreator + public Builder( + @JsonProperty( + "channel" + ) final Participant.ConversationsV2Channel channel, + @JsonProperty("address") final String address + ) { + this.channel = channel; + this.address = address; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + public Builder channelId(String channelId) { + this.channelId = channelId; + return this; + } + + public ConversationsV2Address build() { + return new ConversationsV2Address(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationsV2Address other = (ConversationsV2Address) o; + return ( + Objects.equals(channel, other.channel) && + Objects.equals(address, other.address) && + Objects.equals(channelId, other.channelId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(channel, address, channelId); + } + } + + @JsonDeserialize( + builder = CreateConversationWithConfigRequestParticipantsAddresses.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConversationWithConfigRequestParticipantsAddresses { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Participant.Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + @Getter + private final String channelId; + + private CreateConversationWithConfigRequestParticipantsAddresses( + Builder builder + ) { + this.channel = builder.channel; + this.address = builder.address; + this.channelId = builder.channelId; + } + + public static Builder builder( + final Participant.Channel channel, + final String address + ) { + return new Builder(channel, address); + } + + public static CreateConversationWithConfigRequestParticipantsAddresses fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConversationWithConfigRequestParticipantsAddresses.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("channel") + private Participant.Channel channel; + + @JsonProperty("address") + private String address; + + @JsonProperty("channelId") + private String channelId; + + @JsonCreator + public Builder( + @JsonProperty("channel") final Participant.Channel channel, + @JsonProperty("address") final String address + ) { + this.channel = channel; + this.address = address; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + public Builder channelId(String channelId) { + this.channelId = channelId; + return this; + } + + public CreateConversationWithConfigRequestParticipantsAddresses build() { + return new CreateConversationWithConfigRequestParticipantsAddresses( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConversationWithConfigRequestParticipantsAddresses other = + (CreateConversationWithConfigRequestParticipantsAddresses) o; + return ( + Objects.equals(channel, other.channel) && + Objects.equals(address, other.address) && + Objects.equals(channelId, other.channelId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(channel, address, channelId); + } + } + + /** + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Participant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Participant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Participant() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ParticipantCreator.java b/src/main/java/com/twilio/rest/conversations/v2/ParticipantCreator.java new file mode 100644 index 0000000000..993aa808fb --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ParticipantCreator.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantCreator + extends Creator { + + private String pathConversationId; + private Participant.CreateParticipantInConversationRequest createParticipantInConversationRequest; + + public ParticipantCreator(final String pathConversationId) { + this.pathConversationId = pathConversationId; + } + + public ParticipantCreator setCreateParticipantInConversationRequest( + final Participant.CreateParticipantInConversationRequest createParticipantInConversationRequest + ) { + this.createParticipantInConversationRequest = + createParticipantInConversationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Participants"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant.CreateParticipantResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Participant.CreateParticipantResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Participant.CreateParticipantResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Participant.CreateParticipantResponse content = + Participant.CreateParticipantResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createParticipantInConversationRequest != null) { + request.setBody( + Participant.toJson( + createParticipantInConversationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ParticipantFetcher.java b/src/main/java/com/twilio/rest/conversations/v2/ParticipantFetcher.java new file mode 100644 index 0000000000..c3e264174a --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ParticipantFetcher.java @@ -0,0 +1,110 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantFetcher + extends Fetcher { + + private String pathConversationId; + private String pathId; + + public ParticipantFetcher( + final String pathConversationId, + final String pathId + ) { + this.pathConversationId = pathConversationId; + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Participants/{id}"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant.FetchParticipantResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Participant.FetchParticipantResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Participant.FetchParticipantResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Participant.FetchParticipantResponse content = + Participant.FetchParticipantResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ParticipantReader.java b/src/main/java/com/twilio/rest/conversations/v2/ParticipantReader.java new file mode 100644 index 0000000000..052d931674 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ParticipantReader.java @@ -0,0 +1,262 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantReader + extends Reader { + + private String pathConversationId; + private Integer pageSize; + private String pageToken; + + public ParticipantReader(final String pathConversationId) { + this.pathConversationId = pathConversationId; + } + + public ParticipantReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ParticipantReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse< + Participant.ListParticipantResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.ListParticipantResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Participants"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.ListParticipantResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "participants", + response.getContent(), + Participant.ListParticipantResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/Conversations/{ConversationId}/Participants"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/Conversations/{ConversationId}/Participants"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.CONVERSATIONS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/conversations/v2/ParticipantUpdater.java b/src/main/java/com/twilio/rest/conversations/v2/ParticipantUpdater.java new file mode 100644 index 0000000000..f0d373ce12 --- /dev/null +++ b/src/main/java/com/twilio/rest/conversations/v2/ParticipantUpdater.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Conversation Orchestrator + * Manage configurations, conversations, participants, and communications. Create configurations to define capture rules and channel settings, then use conversations to group related communications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.conversations.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantUpdater + extends Updater { + + private String pathConversationId; + private String pathId; + private Participant.UpdateParticipantInConversationRequest updateParticipantInConversationRequest; + + public ParticipantUpdater( + final String pathConversationId, + final String pathId + ) { + this.pathConversationId = pathConversationId; + this.pathId = pathId; + } + + public ParticipantUpdater setUpdateParticipantInConversationRequest( + final Participant.UpdateParticipantInConversationRequest updateParticipantInConversationRequest + ) { + this.updateParticipantInConversationRequest = + updateParticipantInConversationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Conversations/{ConversationId}/Participants/{id}"; + + path = + path.replace( + "{" + "ConversationId" + "}", + this.pathConversationId.toString() + ); + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.CONVERSATIONS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant.UpdateParticipantResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Participant.UpdateParticipantResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Participant.UpdateParticipantResponse + > updateWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Participant.UpdateParticipantResponse content = + Participant.UpdateParticipantResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (updateParticipantInConversationRequest != null) { + request.setBody( + Participant.toJson( + updateParticipantInConversationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/EventType.java b/src/main/java/com/twilio/rest/events/v1/EventType.java new file mode 100644 index 0000000000..1e8b9ee2f8 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/EventType.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EventType extends Resource { + + public static EventTypeFetcher fetcher(final String pathType) { + return new EventTypeFetcher(pathType); + } + + public static EventTypeReader reader() { + return new EventTypeReader(); + } + + /** + * Converts a JSON String into a EventType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EventType object represented by the provided JSON + */ + public static EventType fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EventType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EventType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EventType object represented by the provided JSON + */ + public static EventType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EventType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String documentationUrl; + + @Getter + private final Map links; + + @Getter + private final String schemaId; + + @Getter + private final String status; + + @Getter + private final String type; + + @Getter + private final URI url; + + @JsonCreator + private EventType( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("documentation_url") final String documentationUrl, + @JsonProperty("links") final Map links, + @JsonProperty("schema_id") final String schemaId, + @JsonProperty("status") final String status, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.documentationUrl = documentationUrl; + this.links = links; + this.schemaId = schemaId; + this.status = status; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EventType other = (EventType) o; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(documentationUrl, other.documentationUrl) && + Objects.equals(links, other.links) && + Objects.equals(schemaId, other.schemaId) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dateCreated, + dateUpdated, + description, + documentationUrl, + links, + schemaId, + status, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/EventTypeFetcher.java b/src/main/java/com/twilio/rest/events/v1/EventTypeFetcher.java new file mode 100644 index 0000000000..dbae66fe20 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/EventTypeFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EventTypeFetcher extends Fetcher { + + private String pathType; + + public EventTypeFetcher(final String pathType) { + this.pathType = pathType; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Types/{Type}"; + + path = path.replace("{" + "Type" + "}", this.pathType.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EventType fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EventType fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EventType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EventType content = EventType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/EventTypeReader.java b/src/main/java/com/twilio/rest/events/v1/EventTypeReader.java new file mode 100644 index 0000000000..d9d23e9c68 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/EventTypeReader.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EventTypeReader extends Reader { + + private String schemaId; + private Long pageSize; + + public EventTypeReader() {} + + public EventTypeReader setSchemaId(final String schemaId) { + this.schemaId = schemaId; + return this; + } + + public EventTypeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "types", + response.getContent(), + EventType.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Types"; + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "types", + response.getContent(), + EventType.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "EventType read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "types", + response.getContent(), + EventType.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (schemaId != null) { + Serializer.toString( + request, + "SchemaId", + schemaId, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/Schema.java b/src/main/java/com/twilio/rest/events/v1/Schema.java new file mode 100644 index 0000000000..097ccd217c --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/Schema.java @@ -0,0 +1,173 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Schema extends Resource { + + public static SchemaFetcher fetcher(final String pathId) { + return new SchemaFetcher(pathId); + } + + /** + * Converts a JSON String into a Schema object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Schema object represented by the provided JSON + */ + public static Schema fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Schema.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Schema object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Schema object represented by the provided JSON + */ + public static Schema fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Schema.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String id; + + @Getter + private final Integer latestVersion; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime latestVersionDateCreated; + + @Getter + private final Map links; + + @Getter + private final URI url; + + @JsonCreator + private Schema( + @JsonProperty("id") final String id, + @JsonProperty("latest_version") final Integer latestVersion, + @JsonProperty("latest_version_date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime latestVersionDateCreated, + @JsonProperty("links") final Map links, + @JsonProperty("url") final URI url + ) { + this.id = id; + this.latestVersion = latestVersion; + this.latestVersionDateCreated = latestVersionDateCreated; + this.links = links; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Schema other = (Schema) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(latestVersion, other.latestVersion) && + Objects.equals( + latestVersionDateCreated, + other.latestVersionDateCreated + ) && + Objects.equals(links, other.links) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + latestVersion, + latestVersionDateCreated, + links, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SchemaFetcher.java b/src/main/java/com/twilio/rest/events/v1/SchemaFetcher.java new file mode 100644 index 0000000000..0e88e4a38a --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SchemaFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SchemaFetcher extends Fetcher { + + private String pathId; + + public SchemaFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Schemas/{Id}"; + + path = path.replace("{" + "Id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Schema fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Schema fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Schema.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Schema content = Schema.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/Sink.java b/src/main/java/com/twilio/rest/events/v1/Sink.java new file mode 100644 index 0000000000..861c745141 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/Sink.java @@ -0,0 +1,274 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Sink extends Resource { + + public static SinkCreator creator( + final String description, + final Object sinkConfiguration, + final Sink.SinkType sinkType + ) { + return new SinkCreator(description, sinkConfiguration, sinkType); + } + + public static SinkDeleter deleter(final String pathSid) { + return new SinkDeleter(pathSid); + } + + public static SinkFetcher fetcher(final String pathSid) { + return new SinkFetcher(pathSid); + } + + public static SinkReader reader() { + return new SinkReader(); + } + + public static SinkUpdater updater( + final String pathSid, + final String description + ) { + return new SinkUpdater(pathSid, description); + } + + public enum Status { + INITIALIZED("initialized"), + VALIDATING("validating"), + ACTIVE("active"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum SinkType { + KINESIS("kinesis"), + WEBHOOK("webhook"), + SEGMENT("segment"), + EMAIL("email"); + + private final String value; + + private SinkType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static SinkType forValue(final String value) { + return Promoter.enumFromString(value, SinkType.values()); + } + } + + /** + * Converts a JSON String into a Sink object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sink object represented by the provided JSON + */ + public static Sink fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Sink.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Sink object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sink object represented by the provided JSON + */ + public static Sink fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Sink.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final Object sinkConfiguration; + + @Getter + private final Sink.SinkType sinkType; + + @Getter + private final Sink.Status status; + + @Getter + private final URI url; + + @JsonCreator + private Sink( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("sink_configuration") final Object sinkConfiguration, + @JsonProperty("sink_type") final Sink.SinkType sinkType, + @JsonProperty("status") final Sink.Status status, + @JsonProperty("url") final URI url + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.links = links; + this.sid = sid; + this.sinkConfiguration = sinkConfiguration; + this.sinkType = sinkType; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Sink other = (Sink) o; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(sinkConfiguration, other.sinkConfiguration) && + Objects.equals(sinkType, other.sinkType) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dateCreated, + dateUpdated, + description, + links, + sid, + sinkConfiguration, + sinkType, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SinkCreator.java b/src/main/java/com/twilio/rest/events/v1/SinkCreator.java new file mode 100644 index 0000000000..536f1486e9 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SinkCreator.java @@ -0,0 +1,148 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SinkCreator extends Creator { + + private String description; + private Object sinkConfiguration; + private Sink.SinkType sinkType; + + public SinkCreator( + final String description, + final Object sinkConfiguration, + final Sink.SinkType sinkType + ) { + this.description = description; + this.sinkConfiguration = sinkConfiguration; + this.sinkType = sinkType; + } + + public SinkCreator setDescription(final String description) { + this.description = description; + return this; + } + + public SinkCreator setSinkConfiguration(final Object sinkConfiguration) { + this.sinkConfiguration = sinkConfiguration; + return this; + } + + public SinkCreator setSinkType(final Sink.SinkType sinkType) { + this.sinkType = sinkType; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sinks"; + + Request request = new Request( + HttpMethod.POST, + Domains.EVENTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Sink creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Sink create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Sink.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Sink content = Sink.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (sinkConfiguration != null) { + Serializer.toString( + request, + "SinkConfiguration", + sinkConfiguration, + ParameterType.URLENCODED + ); + } + + if (sinkType != null) { + Serializer.toString( + request, + "SinkType", + sinkType, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SinkDeleter.java b/src/main/java/com/twilio/rest/events/v1/SinkDeleter.java new file mode 100644 index 0000000000..59ed6c142d --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SinkDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class SinkDeleter extends Deleter { + + private String pathSid; + + public SinkDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sinks/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Sink delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SinkFetcher.java b/src/main/java/com/twilio/rest/events/v1/SinkFetcher.java new file mode 100644 index 0000000000..0d921c62f8 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SinkFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SinkFetcher extends Fetcher { + + private String pathSid; + + public SinkFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sinks/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Sink fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Sink fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Sink.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Sink content = Sink.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SinkReader.java b/src/main/java/com/twilio/rest/events/v1/SinkReader.java new file mode 100644 index 0000000000..4441b8d3b1 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SinkReader.java @@ -0,0 +1,218 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SinkReader extends Reader { + + private Boolean inUse; + private String status; + private Long pageSize; + + public SinkReader() {} + + public SinkReader setInUse(final Boolean inUse) { + this.inUse = inUse; + return this; + } + + public SinkReader setStatus(final String status) { + this.status = status; + return this; + } + + public SinkReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sinks", + response.getContent(), + Sink.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Sinks"; + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sinks", + response.getContent(), + Sink.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Sink read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "sinks", + response.getContent(), + Sink.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (inUse != null) { + Serializer.toString(request, "InUse", inUse, ParameterType.QUERY); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SinkUpdater.java b/src/main/java/com/twilio/rest/events/v1/SinkUpdater.java new file mode 100644 index 0000000000..4a8b697b21 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SinkUpdater.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SinkUpdater extends Updater { + + private String pathSid; + private String description; + + public SinkUpdater(final String pathSid, final String description) { + this.pathSid = pathSid; + this.description = description; + } + + public SinkUpdater setDescription(final String description) { + this.description = description; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sinks/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.EVENTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Sink update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Sink update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Sink.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Sink content = Sink.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/Subscription.java b/src/main/java/com/twilio/rest/events/v1/Subscription.java new file mode 100644 index 0000000000..52d157a1c5 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/Subscription.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Subscription extends Resource { + + public static SubscriptionCreator creator( + final String description, + final String sinkSid, + final List types + ) { + return new SubscriptionCreator(description, sinkSid, types); + } + + public static SubscriptionDeleter deleter(final String pathSid) { + return new SubscriptionDeleter(pathSid); + } + + public static SubscriptionFetcher fetcher(final String pathSid) { + return new SubscriptionFetcher(pathSid); + } + + public static SubscriptionReader reader() { + return new SubscriptionReader(); + } + + public static SubscriptionUpdater updater(final String pathSid) { + return new SubscriptionUpdater(pathSid); + } + + /** + * Converts a JSON String into a Subscription object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Subscription object represented by the provided JSON + */ + public static Subscription fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Subscription.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Subscription object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Subscription object represented by the provided JSON + */ + public static Subscription fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Subscription.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final String sinkSid; + + @Getter + private final URI url; + + @JsonCreator + private Subscription( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("sink_sid") final String sinkSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.links = links; + this.sid = sid; + this.sinkSid = sinkSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Subscription other = (Subscription) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(sinkSid, other.sinkSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + description, + links, + sid, + sinkSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionCreator.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionCreator.java new file mode 100644 index 0000000000..51d992a971 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionCreator.java @@ -0,0 +1,159 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class SubscriptionCreator extends Creator { + + private String description; + private String sinkSid; + private List types; + + public SubscriptionCreator( + final String description, + final String sinkSid, + final List types + ) { + this.description = description; + this.sinkSid = sinkSid; + this.types = types; + } + + public SubscriptionCreator setDescription(final String description) { + this.description = description; + return this; + } + + public SubscriptionCreator setSinkSid(final String sinkSid) { + this.sinkSid = sinkSid; + return this; + } + + public SubscriptionCreator setTypes(final List types) { + this.types = types; + return this; + } + + public SubscriptionCreator setTypes(final Object types) { + return setTypes(Promoter.listOfOne(types)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Subscriptions"; + + Request request = new Request( + HttpMethod.POST, + Domains.EVENTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Subscription creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Subscription create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Subscription content = Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (sinkSid != null) { + Serializer.toString( + request, + "SinkSid", + sinkSid, + ParameterType.URLENCODED + ); + } + + if (types != null) { + for (Object param : types) { + Serializer.toString( + request, + "Types", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionDeleter.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionDeleter.java new file mode 100644 index 0000000000..17edec371f --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class SubscriptionDeleter extends Deleter { + + private String pathSid; + + public SubscriptionDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Subscriptions/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Subscription delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionFetcher.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionFetcher.java new file mode 100644 index 0000000000..836d472341 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SubscriptionFetcher extends Fetcher { + + private String pathSid; + + public SubscriptionFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Subscriptions/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Subscription fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Subscription fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Subscription content = Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionReader.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionReader.java new file mode 100644 index 0000000000..ffdd9dff3e --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionReader.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SubscriptionReader extends Reader { + + private String sinkSid; + private Long pageSize; + + public SubscriptionReader() {} + + public SubscriptionReader setSinkSid(final String sinkSid) { + this.sinkSid = sinkSid; + return this; + } + + public SubscriptionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "subscriptions", + response.getContent(), + Subscription.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Subscriptions"; + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "subscriptions", + response.getContent(), + Subscription.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Subscription read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "subscriptions", + response.getContent(), + Subscription.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (sinkSid != null) { + Serializer.toString( + request, + "SinkSid", + sinkSid, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/SubscriptionUpdater.java b/src/main/java/com/twilio/rest/events/v1/SubscriptionUpdater.java new file mode 100644 index 0000000000..ee46564386 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/SubscriptionUpdater.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SubscriptionUpdater extends Updater { + + private String pathSid; + private String description; + + public SubscriptionUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public SubscriptionUpdater setDescription(final String description) { + this.description = description; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Subscriptions/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.EVENTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Subscription update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Subscription update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Subscription content = Subscription.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersion.java b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersion.java new file mode 100644 index 0000000000..ab60a0d20c --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersion.java @@ -0,0 +1,170 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.schema; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SchemaVersion extends Resource { + + public static SchemaVersionFetcher fetcher( + final String pathId, + final Integer pathSchemaVersion + ) { + return new SchemaVersionFetcher(pathId, pathSchemaVersion); + } + + public static SchemaVersionReader reader(final String pathId) { + return new SchemaVersionReader(pathId); + } + + /** + * Converts a JSON String into a SchemaVersion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SchemaVersion object represented by the provided JSON + */ + public static SchemaVersion fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SchemaVersion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SchemaVersion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SchemaVersion object represented by the provided JSON + */ + public static SchemaVersion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SchemaVersion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String id; + + @Getter + private final URI raw; + + @Getter + private final Integer schemaVersion; + + @Getter + private final URI url; + + @JsonCreator + private SchemaVersion( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("id") final String id, + @JsonProperty("raw") final URI raw, + @JsonProperty("schema_version") final Integer schemaVersion, + @JsonProperty("url") final URI url + ) { + this.dateCreated = dateCreated; + this.id = id; + this.raw = raw; + this.schemaVersion = schemaVersion; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SchemaVersion other = (SchemaVersion) o; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(id, other.id) && + Objects.equals(raw, other.raw) && + Objects.equals(schemaVersion, other.schemaVersion) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(dateCreated, id, raw, schemaVersion, url); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionFetcher.java b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionFetcher.java new file mode 100644 index 0000000000..89ad41ce22 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.schema; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SchemaVersionFetcher extends Fetcher { + + private String pathId; + private Integer pathSchemaVersion; + + public SchemaVersionFetcher( + final String pathId, + final Integer pathSchemaVersion + ) { + this.pathId = pathId; + this.pathSchemaVersion = pathSchemaVersion; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Schemas/{Id}/Versions/{SchemaVersion}"; + + path = path.replace("{" + "Id" + "}", this.pathId.toString()); + path = + path.replace( + "{" + "SchemaVersion" + "}", + this.pathSchemaVersion.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SchemaVersion fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SchemaVersion fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SchemaVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SchemaVersion content = SchemaVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionReader.java b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionReader.java new file mode 100644 index 0000000000..0d23624df3 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/schema/SchemaVersionReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.schema; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SchemaVersionReader extends Reader { + + private String pathId; + private Long pageSize; + + public SchemaVersionReader(final String pathId) { + this.pathId = pathId; + } + + public SchemaVersionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "schema_versions", + response.getContent(), + SchemaVersion.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Schemas/{Id}/Versions"; + + path = path.replace("{" + "Id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "schema_versions", + response.getContent(), + SchemaVersion.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SchemaVersion read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "schema_versions", + response.getContent(), + SchemaVersion.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/sink/SinkTest.java b/src/main/java/com/twilio/rest/events/v1/sink/SinkTest.java new file mode 100644 index 0000000000..5d99cd18c7 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/sink/SinkTest.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.sink; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SinkTest extends Resource { + + public static SinkTestCreator creator(final String pathSid) { + return new SinkTestCreator(pathSid); + } + + /** + * Converts a JSON String into a SinkTest object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SinkTest object represented by the provided JSON + */ + public static SinkTest fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SinkTest.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SinkTest object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SinkTest object represented by the provided JSON + */ + public static SinkTest fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SinkTest.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String result; + + @JsonCreator + private SinkTest(@JsonProperty("result") final String result) { + this.result = result; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SinkTest other = (SinkTest) o; + return (Objects.equals(result, other.result)); + } + + @Override + public int hashCode() { + return Objects.hash(result); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/sink/SinkTestCreator.java b/src/main/java/com/twilio/rest/events/v1/sink/SinkTestCreator.java new file mode 100644 index 0000000000..24150d0b1c --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/sink/SinkTestCreator.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.sink; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SinkTestCreator extends Creator { + + private String pathSid; + + public SinkTestCreator(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sinks/{Sid}/Test"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SinkTest creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SinkTest create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SinkTest.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SinkTest content = SinkTest.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/sink/SinkValidate.java b/src/main/java/com/twilio/rest/events/v1/sink/SinkValidate.java new file mode 100644 index 0000000000..6f8618a260 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/sink/SinkValidate.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.sink; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SinkValidate extends Resource { + + public static SinkValidateCreator creator( + final String pathSid, + final String testId + ) { + return new SinkValidateCreator(pathSid, testId); + } + + /** + * Converts a JSON String into a SinkValidate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SinkValidate object represented by the provided JSON + */ + public static SinkValidate fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SinkValidate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SinkValidate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SinkValidate object represented by the provided JSON + */ + public static SinkValidate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SinkValidate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String result; + + @JsonCreator + private SinkValidate(@JsonProperty("result") final String result) { + this.result = result; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SinkValidate other = (SinkValidate) o; + return (Objects.equals(result, other.result)); + } + + @Override + public int hashCode() { + return Objects.hash(result); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/sink/SinkValidateCreator.java b/src/main/java/com/twilio/rest/events/v1/sink/SinkValidateCreator.java new file mode 100644 index 0000000000..bb35eff51a --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/sink/SinkValidateCreator.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.sink; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SinkValidateCreator extends Creator { + + private String pathSid; + private String testId; + + public SinkValidateCreator(final String pathSid, final String testId) { + this.pathSid = pathSid; + this.testId = testId; + } + + public SinkValidateCreator setTestId(final String testId) { + this.testId = testId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sinks/{Sid}/Validate"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.EVENTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SinkValidate creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SinkValidate create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SinkValidate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SinkValidate content = SinkValidate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (testId != null) { + Serializer.toString( + request, + "TestId", + testId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEvent.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEvent.java new file mode 100644 index 0000000000..067f8370ff --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEvent.java @@ -0,0 +1,191 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.subscription; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SubscribedEvent extends Resource { + + public static SubscribedEventCreator creator( + final String pathSubscriptionSid, + final String type + ) { + return new SubscribedEventCreator(pathSubscriptionSid, type); + } + + public static SubscribedEventDeleter deleter( + final String pathSubscriptionSid, + final String pathType + ) { + return new SubscribedEventDeleter(pathSubscriptionSid, pathType); + } + + public static SubscribedEventFetcher fetcher( + final String pathSubscriptionSid, + final String pathType + ) { + return new SubscribedEventFetcher(pathSubscriptionSid, pathType); + } + + public static SubscribedEventReader reader( + final String pathSubscriptionSid + ) { + return new SubscribedEventReader(pathSubscriptionSid); + } + + public static SubscribedEventUpdater updater( + final String pathSubscriptionSid, + final String pathType + ) { + return new SubscribedEventUpdater(pathSubscriptionSid, pathType); + } + + /** + * Converts a JSON String into a SubscribedEvent object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SubscribedEvent object represented by the provided JSON + */ + public static SubscribedEvent fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SubscribedEvent.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SubscribedEvent object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SubscribedEvent object represented by the provided JSON + */ + public static SubscribedEvent fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SubscribedEvent.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Integer schemaVersion; + + @Getter + private final String subscriptionSid; + + @Getter + private final String type; + + @Getter + private final URI url; + + @JsonCreator + private SubscribedEvent( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("schema_version") final Integer schemaVersion, + @JsonProperty("subscription_sid") final String subscriptionSid, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.schemaVersion = schemaVersion; + this.subscriptionSid = subscriptionSid; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SubscribedEvent other = (SubscribedEvent) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(schemaVersion, other.schemaVersion) && + Objects.equals(subscriptionSid, other.subscriptionSid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + schemaVersion, + subscriptionSid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventCreator.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventCreator.java new file mode 100644 index 0000000000..9eb7a3abca --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventCreator.java @@ -0,0 +1,143 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.subscription; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SubscribedEventCreator extends Creator { + + private String pathSubscriptionSid; + private String type; + private Integer schemaVersion; + + public SubscribedEventCreator( + final String pathSubscriptionSid, + final String type + ) { + this.pathSubscriptionSid = pathSubscriptionSid; + this.type = type; + } + + public SubscribedEventCreator setType(final String type) { + this.type = type; + return this; + } + + public SubscribedEventCreator setSchemaVersion( + final Integer schemaVersion + ) { + this.schemaVersion = schemaVersion; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents"; + + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.EVENTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SubscribedEvent creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SubscribedEvent create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SubscribedEvent content = SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (schemaVersion != null) { + Serializer.toString( + request, + "SchemaVersion", + schemaVersion, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventDeleter.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventDeleter.java new file mode 100644 index 0000000000..e89cdffe0b --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventDeleter.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.subscription; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class SubscribedEventDeleter extends Deleter { + + private String pathSubscriptionSid; + private String pathType; + + public SubscribedEventDeleter( + final String pathSubscriptionSid, + final String pathType + ) { + this.pathSubscriptionSid = pathSubscriptionSid; + this.pathType = pathType; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; + + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.pathType.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SubscribedEvent delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventFetcher.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventFetcher.java new file mode 100644 index 0000000000..8241964ad7 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventFetcher.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.subscription; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SubscribedEventFetcher extends Fetcher { + + private String pathSubscriptionSid; + private String pathType; + + public SubscribedEventFetcher( + final String pathSubscriptionSid, + final String pathType + ) { + this.pathSubscriptionSid = pathSubscriptionSid; + this.pathType = pathType; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; + + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.pathType.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SubscribedEvent fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SubscribedEvent fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SubscribedEvent content = SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventReader.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventReader.java new file mode 100644 index 0000000000..5caacfbc45 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.subscription; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SubscribedEventReader extends Reader { + + private String pathSubscriptionSid; + private Long pageSize; + + public SubscribedEventReader(final String pathSubscriptionSid) { + this.pathSubscriptionSid = pathSubscriptionSid; + } + + public SubscribedEventReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "types", + response.getContent(), + SubscribedEvent.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents"; + + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.EVENTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "types", + response.getContent(), + SubscribedEvent.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SubscribedEvent read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "types", + response.getContent(), + SubscribedEvent.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventUpdater.java b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventUpdater.java new file mode 100644 index 0000000000..a06e8d3628 --- /dev/null +++ b/src/main/java/com/twilio/rest/events/v1/subscription/SubscribedEventUpdater.java @@ -0,0 +1,131 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Events + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.events.v1.subscription; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SubscribedEventUpdater extends Updater { + + private String pathSubscriptionSid; + private String pathType; + private Integer schemaVersion; + + public SubscribedEventUpdater( + final String pathSubscriptionSid, + final String pathType + ) { + this.pathSubscriptionSid = pathSubscriptionSid; + this.pathType = pathType; + } + + public SubscribedEventUpdater setSchemaVersion( + final Integer schemaVersion + ) { + this.schemaVersion = schemaVersion; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Subscriptions/{SubscriptionSid}/SubscribedEvents/{Type}"; + + path = + path.replace( + "{" + "SubscriptionSid" + "}", + this.pathSubscriptionSid.toString() + ); + path = path.replace("{" + "Type" + "}", this.pathType.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.EVENTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SubscribedEvent update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SubscribedEvent update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SubscribedEvent content = SubscribedEvent.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (schemaVersion != null) { + Serializer.toString( + request, + "SchemaVersion", + schemaVersion, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/fax/v1/Fax.java b/src/main/java/com/twilio/rest/fax/v1/Fax.java deleted file mode 100644 index d7a1a6ce05..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/Fax.java +++ /dev/null @@ -1,559 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; -import java.net.URI; -import java.util.Currency; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Fax extends Resource { - private static final long serialVersionUID = 272370485490742L; - - public enum Direction { - INBOUND("inbound"), - OUTBOUND("outbound"); - - private final String value; - - private Direction(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Direction from a string. - * @param value string value - * @return generated Direction - */ - @JsonCreator - public static Direction forValue(final String value) { - return Promoter.enumFromString(value, Direction.values()); - } - } - - public enum Quality { - STANDARD("standard"), - FINE("fine"), - SUPERFINE("superfine"); - - private final String value; - - private Quality(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Quality from a string. - * @param value string value - * @return generated Quality - */ - @JsonCreator - public static Quality forValue(final String value) { - return Promoter.enumFromString(value, Quality.values()); - } - } - - public enum Status { - QUEUED("queued"), - PROCESSING("processing"), - SENDING("sending"), - DELIVERED("delivered"), - RECEIVING("receiving"), - RECEIVED("received"), - NO_ANSWER("no-answer"), - BUSY("busy"), - FAILED("failed"), - CANCELED("canceled"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - - public enum UpdateStatus { - CANCELED("canceled"); - - private final String value; - - private UpdateStatus(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a UpdateStatus from a string. - * @param value string value - * @return generated UpdateStatus - */ - @JsonCreator - public static UpdateStatus forValue(final String value) { - return Promoter.enumFromString(value, UpdateStatus.values()); - } - } - - /** - * Create a FaxFetcher to execute fetch. - * - * @param pathSid A string that uniquely identifies this fax. - * @return FaxFetcher capable of executing the fetch - */ - public static FaxFetcher fetcher(final String pathSid) { - return new FaxFetcher(pathSid); - } - - /** - * Create a FaxReader to execute read. - * - * @return FaxReader capable of executing the read - */ - public static FaxReader reader() { - return new FaxReader(); - } - - /** - * Create a FaxCreator to execute create. - * - * @param to The phone number or SIP address to send the fax to - * @param mediaUrl URL that points to the fax media - * @return FaxCreator capable of executing the create - */ - public static FaxCreator creator(final String to, - final URI mediaUrl) { - return new FaxCreator(to, mediaUrl); - } - - /** - * Create a FaxUpdater to execute update. - * - * @param pathSid A string that uniquely identifies this fax. - * @return FaxUpdater capable of executing the update - */ - public static FaxUpdater updater(final String pathSid) { - return new FaxUpdater(pathSid); - } - - /** - * Create a FaxDeleter to execute delete. - * - * @param pathSid A string that uniquely identifies this fax. - * @return FaxDeleter capable of executing the delete - */ - public static FaxDeleter deleter(final String pathSid) { - return new FaxDeleter(pathSid); - } - - /** - * Converts a JSON String into a Fax object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Fax object represented by the provided JSON - */ - public static Fax fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Fax.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Fax object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Fax object represented by the provided JSON - */ - public static Fax fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Fax.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String from; - private final String to; - private final Fax.Quality quality; - private final String mediaSid; - private final String mediaUrl; - private final Integer numPages; - private final Integer duration; - private final Fax.Status status; - private final Fax.Direction direction; - private final String apiVersion; - private final BigDecimal price; - private final Currency priceUnit; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final Map links; - private final URI url; - - @JsonCreator - private Fax(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("from") - final String from, - @JsonProperty("to") - final String to, - @JsonProperty("quality") - final Fax.Quality quality, - @JsonProperty("media_sid") - final String mediaSid, - @JsonProperty("media_url") - final String mediaUrl, - @JsonProperty("num_pages") - final Integer numPages, - @JsonProperty("duration") - final Integer duration, - @JsonProperty("status") - final Fax.Status status, - @JsonProperty("direction") - final Fax.Direction direction, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("price") - final BigDecimal price, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("links") - final Map links, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.from = from; - this.to = to; - this.quality = quality; - this.mediaSid = mediaSid; - this.mediaUrl = mediaUrl; - this.numPages = numPages; - this.duration = duration; - this.status = status; - this.direction = direction; - this.apiVersion = apiVersion; - this.price = price; - this.priceUnit = priceUnit; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.links = links; - this.url = url; - } - - /** - * Returns The A string that uniquely identifies this fax.. - * - * @return A string that uniquely identifies this fax. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account SID. - * - * @return Account SID - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The party that sent the fax. - * - * @return The party that sent the fax - */ - public final String getFrom() { - return this.from; - } - - /** - * Returns The The party that received the fax. - * - * @return The party that received the fax - */ - public final String getTo() { - return this.to; - } - - /** - * Returns The The quality of this fax. - * - * @return The quality of this fax - */ - public final Fax.Quality getQuality() { - return this.quality; - } - - /** - * Returns The Media SID. - * - * @return Media SID - */ - public final String getMediaSid() { - return this.mediaSid; - } - - /** - * Returns The URL pointing to fax media. - * - * @return URL pointing to fax media - */ - public final String getMediaUrl() { - return this.mediaUrl; - } - - /** - * Returns The Number of pages. - * - * @return Number of pages - */ - public final Integer getNumPages() { - return this.numPages; - } - - /** - * Returns The The time taken to transmit the fax. - * - * @return The time taken to transmit the fax - */ - public final Integer getDuration() { - return this.duration; - } - - /** - * Returns The The status of this fax. - * - * @return The status of this fax - */ - public final Fax.Status getStatus() { - return this.status; - } - - /** - * Returns The The direction of this fax. - * - * @return The direction of this fax - */ - public final Fax.Direction getDirection() { - return this.direction; - } - - /** - * Returns The The API version used. - * - * @return The API version used - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The Fax transmission price. - * - * @return Fax transmission price - */ - public final BigDecimal getPrice() { - return this.price; - } - - /** - * Returns The Currency used for billing. - * - * @return Currency used for billing - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The date this fax was created. - * - * @return The date this fax was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this fax was updated. - * - * @return The date this fax was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Nested resource URLs. - * - * @return Nested resource URLs - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The The URL of this resource. - * - * @return The URL of this resource - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Fax other = (Fax) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(from, other.from) && - Objects.equals(to, other.to) && - Objects.equals(quality, other.quality) && - Objects.equals(mediaSid, other.mediaSid) && - Objects.equals(mediaUrl, other.mediaUrl) && - Objects.equals(numPages, other.numPages) && - Objects.equals(duration, other.duration) && - Objects.equals(status, other.status) && - Objects.equals(direction, other.direction) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(price, other.price) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(links, other.links) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - from, - to, - quality, - mediaSid, - mediaUrl, - numPages, - duration, - status, - direction, - apiVersion, - price, - priceUnit, - dateCreated, - dateUpdated, - links, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("from", from) - .add("to", to) - .add("quality", quality) - .add("mediaSid", mediaSid) - .add("mediaUrl", mediaUrl) - .add("numPages", numPages) - .add("duration", duration) - .add("status", status) - .add("direction", direction) - .add("apiVersion", apiVersion) - .add("price", price) - .add("priceUnit", priceUnit) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("links", links) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/FaxCreator.java b/src/main/java/com/twilio/rest/fax/v1/FaxCreator.java deleted file mode 100644 index 86fc285509..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/FaxCreator.java +++ /dev/null @@ -1,230 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class FaxCreator extends Creator { - private final String to; - private final URI mediaUrl; - private Fax.Quality quality; - private URI statusCallback; - private String from; - private String sipAuthUsername; - private String sipAuthPassword; - private Boolean storeMedia; - private Integer ttl; - - /** - * Construct a new FaxCreator. - * - * @param to The phone number or SIP address to send the fax to - * @param mediaUrl URL that points to the fax media - */ - public FaxCreator(final String to, - final URI mediaUrl) { - this.to = to; - this.mediaUrl = mediaUrl; - } - - /** - * A [quality - * value](https://www.twilio.com/docs/api/fax/rest/faxes#fax-quality-values), - * which defaults to `fine`. - * - * @param quality The quality of this fax - * @return this - */ - public FaxCreator setQuality(final Fax.Quality quality) { - this.quality = quality; - return this; - } - - /** - * A [status - * callback](https://www.twilio.com/docs/api/fax/rest/faxes#fax-status-callback) - * URL that will receive a POST when the status of the fax changes. - * - * @param statusCallback URL for fax status callbacks - * @return this - */ - public FaxCreator setStatusCallback(final URI statusCallback) { - this.statusCallback = statusCallback; - return this; - } - - /** - * A [status - * callback](https://www.twilio.com/docs/api/fax/rest/faxes#fax-status-callback) - * URL that will receive a POST when the status of the fax changes. - * - * @param statusCallback URL for fax status callbacks - * @return this - */ - public FaxCreator setStatusCallback(final String statusCallback) { - return setStatusCallback(Promoter.uriFromString(statusCallback)); - } - - /** - * The phone number to use as the caller id, E.164-formatted. If using a phone - * number, it must be a Twilio number or a verified outgoing caller id for your - * account. If sending to a SIP address, this can be any alphanumeric string - * (plus the characters `+`, `_`, `.`, and `-`) to use in the From header of the - * SIP request.. - * - * @param from Twilio number from which to originate the fax - * @return this - */ - public FaxCreator setFrom(final String from) { - this.from = from; - return this; - } - - /** - * The username to use for authentication when sending to a SIP address.. - * - * @param sipAuthUsername Username for SIP authentication - * @return this - */ - public FaxCreator setSipAuthUsername(final String sipAuthUsername) { - this.sipAuthUsername = sipAuthUsername; - return this; - } - - /** - * The password to use for authentication when sending to a SIP address.. - * - * @param sipAuthPassword Password for SIP authentication - * @return this - */ - public FaxCreator setSipAuthPassword(final String sipAuthPassword) { - this.sipAuthPassword = sipAuthPassword; - return this; - } - - /** - * Whether or not to store a copy of the sent media on Twilio's servers for - * later retrieval (defaults to `true`). - * - * @param storeMedia Whether or not to store media - * @return this - */ - public FaxCreator setStoreMedia(final Boolean storeMedia) { - this.storeMedia = storeMedia; - return this; - } - - /** - * How many minutes from when a fax was initiated should Twilio attempt to send - * a fax.. - * - * @param ttl How many minutes to attempt a fax - * @return this - */ - public FaxCreator setTtl(final Integer ttl) { - this.ttl = ttl; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Fax - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Fax create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.FAX.toString(), - "/v1/Faxes", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fax creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Fax.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (to != null) { - request.addPostParam("To", to); - } - - if (mediaUrl != null) { - request.addPostParam("MediaUrl", mediaUrl.toString()); - } - - if (quality != null) { - request.addPostParam("Quality", quality.toString()); - } - - if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); - } - - if (from != null) { - request.addPostParam("From", from); - } - - if (sipAuthUsername != null) { - request.addPostParam("SipAuthUsername", sipAuthUsername); - } - - if (sipAuthPassword != null) { - request.addPostParam("SipAuthPassword", sipAuthPassword); - } - - if (storeMedia != null) { - request.addPostParam("StoreMedia", storeMedia.toString()); - } - - if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/FaxDeleter.java b/src/main/java/com/twilio/rest/fax/v1/FaxDeleter.java deleted file mode 100644 index 71cb02e331..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/FaxDeleter.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class FaxDeleter extends Deleter { - private final String pathSid; - - /** - * Construct a new FaxDeleter. - * - * @param pathSid A string that uniquely identifies this fax. - */ - public FaxDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.FAX.toString(), - "/v1/Faxes/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fax delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/FaxFetcher.java b/src/main/java/com/twilio/rest/fax/v1/FaxFetcher.java deleted file mode 100644 index 2aa1893d4e..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/FaxFetcher.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class FaxFetcher extends Fetcher { - private final String pathSid; - - /** - * Construct a new FaxFetcher. - * - * @param pathSid A string that uniquely identifies this fax. - */ - public FaxFetcher(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Fax - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Fax fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.FAX.toString(), - "/v1/Faxes/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fax fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Fax.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/FaxReader.java b/src/main/java/com/twilio/rest/fax/v1/FaxReader.java deleted file mode 100644 index 4115cba2d4..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/FaxReader.java +++ /dev/null @@ -1,232 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class FaxReader extends Reader { - private String from; - private String to; - private DateTime dateCreatedOnOrBefore; - private DateTime dateCreatedAfter; - - /** - * Filters the returned list to only include faxes sent from the supplied - * number, given in E.164 format.. - * - * @param from Include only faxes sent from - * @return this - */ - public FaxReader setFrom(final String from) { - this.from = from; - return this; - } - - /** - * Filters the returned list to only include faxes sent to the supplied number, - * given in E.164 format.. - * - * @param to Include only faxes sent to - * @return this - */ - public FaxReader setTo(final String to) { - this.to = to; - return this; - } - - /** - * Filters the returned list to only include faxes created on or before the - * supplied date, given in ISO 8601 format.. - * - * @param dateCreatedOnOrBefore Include only faxes created on or before - * @return this - */ - public FaxReader setDateCreatedOnOrBefore(final DateTime dateCreatedOnOrBefore) { - this.dateCreatedOnOrBefore = dateCreatedOnOrBefore; - return this; - } - - /** - * Filters the returned list to only include faxes created after the supplied - * date, given in ISO 8601 format.. - * - * @param dateCreatedAfter Include only faxes created after - * @return this - */ - public FaxReader setDateCreatedAfter(final DateTime dateCreatedAfter) { - this.dateCreatedAfter = dateCreatedAfter; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Fax ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Fax ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.FAX.toString(), - "/v1/Faxes", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Fax ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.FAX.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.FAX.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Fax Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fax read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "faxes", - response.getContent(), - Fax.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (from != null) { - request.addQueryParam("From", from); - } - - if (to != null) { - request.addQueryParam("To", to); - } - - if (dateCreatedOnOrBefore != null) { - request.addQueryParam("DateCreatedOnOrBefore", dateCreatedOnOrBefore.toString()); - } - - if (dateCreatedAfter != null) { - request.addQueryParam("DateCreatedAfter", dateCreatedAfter.toString()); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/FaxUpdater.java b/src/main/java/com/twilio/rest/fax/v1/FaxUpdater.java deleted file mode 100644 index 1b8fc92ffd..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/FaxUpdater.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class FaxUpdater extends Updater { - private final String pathSid; - private Fax.UpdateStatus status; - - /** - * Construct a new FaxUpdater. - * - * @param pathSid A string that uniquely identifies this fax. - */ - public FaxUpdater(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * The updated status of this fax. The only valid option is `canceled`. This may - * fail if the status has already started transmission.. - * - * @param status The updated status of this fax - * @return this - */ - public FaxUpdater setStatus(final Fax.UpdateStatus status) { - this.status = status; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Fax - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Fax update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.FAX.toString(), - "/v1/Faxes/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fax update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Fax.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (status != null) { - request.addPostParam("Status", status.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/fax/FaxMedia.java b/src/main/java/com/twilio/rest/fax/v1/fax/FaxMedia.java deleted file mode 100644 index 154bf02894..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/fax/FaxMedia.java +++ /dev/null @@ -1,254 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1.fax; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class FaxMedia extends Resource { - private static final long serialVersionUID = 8543753722336L; - - /** - * Create a FaxMediaFetcher to execute fetch. - * - * @param pathFaxSid Fax SID - * @param pathSid A string that uniquely identifies this fax media - * @return FaxMediaFetcher capable of executing the fetch - */ - public static FaxMediaFetcher fetcher(final String pathFaxSid, - final String pathSid) { - return new FaxMediaFetcher(pathFaxSid, pathSid); - } - - /** - * Create a FaxMediaReader to execute read. - * - * @param pathFaxSid Fax SID - * @return FaxMediaReader capable of executing the read - */ - public static FaxMediaReader reader(final String pathFaxSid) { - return new FaxMediaReader(pathFaxSid); - } - - /** - * Create a FaxMediaDeleter to execute delete. - * - * @param pathFaxSid Fax SID - * @param pathSid A string that uniquely identifies this fax media - * @return FaxMediaDeleter capable of executing the delete - */ - public static FaxMediaDeleter deleter(final String pathFaxSid, - final String pathSid) { - return new FaxMediaDeleter(pathFaxSid, pathSid); - } - - /** - * Converts a JSON String into a FaxMedia object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FaxMedia object represented by the provided JSON - */ - public static FaxMedia fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, FaxMedia.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a FaxMedia object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FaxMedia object represented by the provided JSON - */ - public static FaxMedia fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, FaxMedia.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String faxSid; - private final String contentType; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private FaxMedia(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("fax_sid") - final String faxSid, - @JsonProperty("content_type") - final String contentType, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.faxSid = faxSid; - this.contentType = contentType; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - } - - /** - * Returns The A string that uniquely identifies this fax media. - * - * @return A string that uniquely identifies this fax media - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account SID. - * - * @return Account SID - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Fax SID. - * - * @return Fax SID - */ - public final String getFaxSid() { - return this.faxSid; - } - - /** - * Returns The Media content type. - * - * @return Media content type - */ - public final String getContentType() { - return this.contentType; - } - - /** - * Returns The The date this fax media was created. - * - * @return The date this fax media was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this fax media was updated. - * - * @return The date this fax media was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource. - * - * @return The URL of this resource - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - FaxMedia other = (FaxMedia) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(faxSid, other.faxSid) && - Objects.equals(contentType, other.contentType) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - faxSid, - contentType, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("faxSid", faxSid) - .add("contentType", contentType) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaDeleter.java b/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaDeleter.java deleted file mode 100644 index 4ff86f1546..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaDeleter.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1.fax; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class FaxMediaDeleter extends Deleter { - private final String pathFaxSid; - private final String pathSid; - - /** - * Construct a new FaxMediaDeleter. - * - * @param pathFaxSid Fax SID - * @param pathSid A string that uniquely identifies this fax media - */ - public FaxMediaDeleter(final String pathFaxSid, - final String pathSid) { - this.pathFaxSid = pathFaxSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.FAX.toString(), - "/v1/Faxes/" + this.pathFaxSid + "/Media/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FaxMedia delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaFetcher.java b/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaFetcher.java deleted file mode 100644 index 4318d4b2f0..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaFetcher.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1.fax; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class FaxMediaFetcher extends Fetcher { - private final String pathFaxSid; - private final String pathSid; - - /** - * Construct a new FaxMediaFetcher. - * - * @param pathFaxSid Fax SID - * @param pathSid A string that uniquely identifies this fax media - */ - public FaxMediaFetcher(final String pathFaxSid, - final String pathSid) { - this.pathFaxSid = pathFaxSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched FaxMedia - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public FaxMedia fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.FAX.toString(), - "/v1/Faxes/" + this.pathFaxSid + "/Media/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FaxMedia fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return FaxMedia.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaReader.java b/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaReader.java deleted file mode 100644 index fc569d412d..0000000000 --- a/src/main/java/com/twilio/rest/fax/v1/fax/FaxMediaReader.java +++ /dev/null @@ -1,172 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.fax.v1.fax; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class FaxMediaReader extends Reader { - private final String pathFaxSid; - - /** - * Construct a new FaxMediaReader. - * - * @param pathFaxSid Fax SID - */ - public FaxMediaReader(final String pathFaxSid) { - this.pathFaxSid = pathFaxSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return FaxMedia ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return FaxMedia ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.FAX.toString(), - "/v1/Faxes/" + this.pathFaxSid + "/Media", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return FaxMedia ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.FAX.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.FAX.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of FaxMedia Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FaxMedia read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "media", - response.getContent(), - FaxMedia.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Assessments.java b/src/main/java/com/twilio/rest/flexapi/v1/Assessments.java new file mode 100644 index 0000000000..425d882dbc --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/Assessments.java @@ -0,0 +1,265 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Assessments extends Resource { + + public static AssessmentsCreator creator( + final String categorySid, + final String categoryName, + final String segmentId, + final String agentId, + final BigDecimal offset, + final String metricId, + final String metricName, + final String answerText, + final String answerId, + final String questionnaireSid + ) { + return new AssessmentsCreator( + categorySid, + categoryName, + segmentId, + agentId, + offset, + metricId, + metricName, + answerText, + answerId, + questionnaireSid + ); + } + + public static AssessmentsReader reader() { + return new AssessmentsReader(); + } + + public static AssessmentsUpdater updater( + final String pathAssessmentSid, + final BigDecimal offset, + final String answerText, + final String answerId + ) { + return new AssessmentsUpdater( + pathAssessmentSid, + offset, + answerText, + answerId + ); + } + + /** + * Converts a JSON String into a Assessments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Assessments object represented by the provided JSON + */ + public static Assessments fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Assessments.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Assessments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Assessments object represented by the provided JSON + */ + public static Assessments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Assessments.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String agentId; + + @Getter + private final String answerId; + + @Getter + private final String answerText; + + @Getter + private final Object assessment; + + @Getter + private final String assessmentSid; + + @Getter + private final String offset; + + @Getter + private final Boolean report; + + @Getter + private final String segmentId; + + @Getter + private final String timestamp; + + @Getter + private final URI url; + + @Getter + private final String userEmail; + + @Getter + private final String userName; + + @Getter + private final String weight; + + @JsonCreator + private Assessments( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("agent_id") final String agentId, + @JsonProperty("answer_id") final String answerId, + @JsonProperty("answer_text") final String answerText, + @JsonProperty("assessment") final Object assessment, + @JsonProperty("assessment_sid") final String assessmentSid, + @JsonProperty("offset") final String offset, + @JsonProperty("report") final Boolean report, + @JsonProperty("segment_id") final String segmentId, + @JsonProperty("timestamp") final String timestamp, + @JsonProperty("url") final URI url, + @JsonProperty("user_email") final String userEmail, + @JsonProperty("user_name") final String userName, + @JsonProperty("weight") final String weight + ) { + this.accountSid = accountSid; + this.agentId = agentId; + this.answerId = answerId; + this.answerText = answerText; + this.assessment = assessment; + this.assessmentSid = assessmentSid; + this.offset = offset; + this.report = report; + this.segmentId = segmentId; + this.timestamp = timestamp; + this.url = url; + this.userEmail = userEmail; + this.userName = userName; + this.weight = weight; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Assessments other = (Assessments) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(agentId, other.agentId) && + Objects.equals(answerId, other.answerId) && + Objects.equals(answerText, other.answerText) && + Objects.equals(assessment, other.assessment) && + Objects.equals(assessmentSid, other.assessmentSid) && + Objects.equals(offset, other.offset) && + Objects.equals(report, other.report) && + Objects.equals(segmentId, other.segmentId) && + Objects.equals(timestamp, other.timestamp) && + Objects.equals(url, other.url) && + Objects.equals(userEmail, other.userEmail) && + Objects.equals(userName, other.userName) && + Objects.equals(weight, other.weight) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + agentId, + answerId, + answerText, + assessment, + assessmentSid, + offset, + report, + segmentId, + timestamp, + url, + userEmail, + userName, + weight + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsCreator.java new file mode 100644 index 0000000000..69352091d6 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsCreator.java @@ -0,0 +1,291 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.math.BigDecimal; + +public class AssessmentsCreator extends Creator { + + private String authorization; + private String categorySid; + private String categoryName; + private String segmentId; + private String agentId; + private BigDecimal offset; + private String metricId; + private String metricName; + private String answerText; + private String answerId; + private String questionnaireSid; + + public AssessmentsCreator( + final String categorySid, + final String categoryName, + final String segmentId, + final String agentId, + final BigDecimal offset, + final String metricId, + final String metricName, + final String answerText, + final String answerId, + final String questionnaireSid + ) { + this.categorySid = categorySid; + this.categoryName = categoryName; + this.segmentId = segmentId; + this.agentId = agentId; + this.offset = offset; + this.metricId = metricId; + this.metricName = metricName; + this.answerText = answerText; + this.answerId = answerId; + this.questionnaireSid = questionnaireSid; + } + + public AssessmentsCreator setCategorySid(final String categorySid) { + this.categorySid = categorySid; + return this; + } + + public AssessmentsCreator setCategoryName(final String categoryName) { + this.categoryName = categoryName; + return this; + } + + public AssessmentsCreator setSegmentId(final String segmentId) { + this.segmentId = segmentId; + return this; + } + + public AssessmentsCreator setAgentId(final String agentId) { + this.agentId = agentId; + return this; + } + + public AssessmentsCreator setOffset(final BigDecimal offset) { + this.offset = offset; + return this; + } + + public AssessmentsCreator setMetricId(final String metricId) { + this.metricId = metricId; + return this; + } + + public AssessmentsCreator setMetricName(final String metricName) { + this.metricName = metricName; + return this; + } + + public AssessmentsCreator setAnswerText(final String answerText) { + this.answerText = answerText; + return this; + } + + public AssessmentsCreator setAnswerId(final String answerId) { + this.answerId = answerId; + return this; + } + + public AssessmentsCreator setQuestionnaireSid( + final String questionnaireSid + ) { + this.questionnaireSid = questionnaireSid; + return this; + } + + public AssessmentsCreator setAuthorization(final String authorization) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Assessments"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Assessments creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Assessments create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Assessments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Assessments content = Assessments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (categorySid != null) { + Serializer.toString( + request, + "CategorySid", + categorySid, + ParameterType.URLENCODED + ); + } + + if (categoryName != null) { + Serializer.toString( + request, + "CategoryName", + categoryName, + ParameterType.URLENCODED + ); + } + + if (segmentId != null) { + Serializer.toString( + request, + "SegmentId", + segmentId, + ParameterType.URLENCODED + ); + } + + if (agentId != null) { + Serializer.toString( + request, + "AgentId", + agentId, + ParameterType.URLENCODED + ); + } + + if (offset != null) { + Serializer.toString( + request, + "Offset", + offset, + ParameterType.URLENCODED + ); + } + + if (metricId != null) { + Serializer.toString( + request, + "MetricId", + metricId, + ParameterType.URLENCODED + ); + } + + if (metricName != null) { + Serializer.toString( + request, + "MetricName", + metricName, + ParameterType.URLENCODED + ); + } + + if (answerText != null) { + Serializer.toString( + request, + "AnswerText", + answerText, + ParameterType.URLENCODED + ); + } + + if (answerId != null) { + Serializer.toString( + request, + "AnswerId", + answerId, + ParameterType.URLENCODED + ); + } + + if (questionnaireSid != null) { + Serializer.toString( + request, + "QuestionnaireSid", + questionnaireSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsReader.java b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsReader.java new file mode 100644 index 0000000000..b825d67ec4 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsReader.java @@ -0,0 +1,235 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssessmentsReader extends Reader { + + private String segmentId; + private Long pageSize; + private String authorization; + + public AssessmentsReader() {} + + public AssessmentsReader setSegmentId(final String segmentId) { + this.segmentId = segmentId; + return this; + } + + public AssessmentsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public AssessmentsReader setAuthorization(final String authorization) { + this.authorization = authorization; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "assessments", + response.getContent(), + Assessments.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Assessments"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "assessments", + response.getContent(), + Assessments.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Assessments read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "assessments", + response.getContent(), + Assessments.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (segmentId != null) { + Serializer.toString( + request, + "SegmentId", + segmentId, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsUpdater.java new file mode 100644 index 0000000000..906175555a --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/AssessmentsUpdater.java @@ -0,0 +1,180 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.math.BigDecimal; + +public class AssessmentsUpdater extends Updater { + + private String pathAssessmentSid; + private String authorization; + private BigDecimal offset; + private String answerText; + private String answerId; + + public AssessmentsUpdater( + final String pathAssessmentSid, + final BigDecimal offset, + final String answerText, + final String answerId + ) { + this.pathAssessmentSid = pathAssessmentSid; + this.offset = offset; + this.answerText = answerText; + this.answerId = answerId; + } + + public AssessmentsUpdater setOffset(final BigDecimal offset) { + this.offset = offset; + return this; + } + + public AssessmentsUpdater setAnswerText(final String answerText) { + this.answerText = answerText; + return this; + } + + public AssessmentsUpdater setAnswerId(final String answerId) { + this.answerId = answerId; + return this; + } + + public AssessmentsUpdater setAuthorization(final String authorization) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Insights/QualityManagement/Assessments/{AssessmentSid}"; + + path = + path.replace( + "{" + "AssessmentSid" + "}", + this.pathAssessmentSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Assessments update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Assessments update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Assessments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Assessments content = Assessments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (offset != null) { + Serializer.toString( + request, + "Offset", + offset, + ParameterType.URLENCODED + ); + } + + if (answerText != null) { + Serializer.toString( + request, + "AnswerText", + answerText, + ParameterType.URLENCODED + ); + } + + if (answerId != null) { + Serializer.toString( + request, + "AnswerId", + answerId, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Channel.java b/src/main/java/com/twilio/rest/flexapi/v1/Channel.java new file mode 100644 index 0000000000..d479130867 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/Channel.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Channel extends Resource { + + public static ChannelCreator creator( + final String flexFlowSid, + final String identity, + final String chatUserFriendlyName, + final String chatFriendlyName + ) { + return new ChannelCreator( + flexFlowSid, + identity, + chatUserFriendlyName, + chatFriendlyName + ); + } + + public static ChannelDeleter deleter(final String pathSid) { + return new ChannelDeleter(pathSid); + } + + public static ChannelFetcher fetcher(final String pathSid) { + return new ChannelFetcher(pathSid); + } + + public static ChannelReader reader() { + return new ChannelReader(); + } + + /** + * Converts a JSON String into a Channel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Channel.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Channel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Channel object represented by the provided JSON + */ + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Channel.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String flexFlowSid; + + @Getter + private final String sid; + + @Getter + private final String taskSid; + + @Getter + private final URI url; + + @Getter + private final String userSid; + + @JsonCreator + private Channel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("flex_flow_sid") final String flexFlowSid, + @JsonProperty("sid") final String sid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("url") final URI url, + @JsonProperty("user_sid") final String userSid + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.flexFlowSid = flexFlowSid; + this.sid = sid; + this.taskSid = taskSid; + this.url = url; + this.userSid = userSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Channel other = (Channel) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(flexFlowSid, other.flexFlowSid) && + Objects.equals(sid, other.sid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(url, other.url) && + Objects.equals(userSid, other.userSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + flexFlowSid, + sid, + taskSid, + url, + userSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ChannelCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/ChannelCreator.java new file mode 100644 index 0000000000..69f43481c0 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/ChannelCreator.java @@ -0,0 +1,257 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelCreator extends Creator { + + private String flexFlowSid; + private String identity; + private String chatUserFriendlyName; + private String chatFriendlyName; + private String target; + private String chatUniqueName; + private String preEngagementData; + private String taskSid; + private String taskAttributes; + private Boolean longLived; + + public ChannelCreator( + final String flexFlowSid, + final String identity, + final String chatUserFriendlyName, + final String chatFriendlyName + ) { + this.flexFlowSid = flexFlowSid; + this.identity = identity; + this.chatUserFriendlyName = chatUserFriendlyName; + this.chatFriendlyName = chatFriendlyName; + } + + public ChannelCreator setFlexFlowSid(final String flexFlowSid) { + this.flexFlowSid = flexFlowSid; + return this; + } + + public ChannelCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public ChannelCreator setChatUserFriendlyName( + final String chatUserFriendlyName + ) { + this.chatUserFriendlyName = chatUserFriendlyName; + return this; + } + + public ChannelCreator setChatFriendlyName(final String chatFriendlyName) { + this.chatFriendlyName = chatFriendlyName; + return this; + } + + public ChannelCreator setTarget(final String target) { + this.target = target; + return this; + } + + public ChannelCreator setChatUniqueName(final String chatUniqueName) { + this.chatUniqueName = chatUniqueName; + return this; + } + + public ChannelCreator setPreEngagementData(final String preEngagementData) { + this.preEngagementData = preEngagementData; + return this; + } + + public ChannelCreator setTaskSid(final String taskSid) { + this.taskSid = taskSid; + return this; + } + + public ChannelCreator setTaskAttributes(final String taskAttributes) { + this.taskAttributes = taskAttributes; + return this; + } + + public ChannelCreator setLongLived(final Boolean longLived) { + this.longLived = longLived; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Channels"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Channel create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Channel.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (flexFlowSid != null) { + Serializer.toString( + request, + "FlexFlowSid", + flexFlowSid, + ParameterType.URLENCODED + ); + } + + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + + if (chatUserFriendlyName != null) { + Serializer.toString( + request, + "ChatUserFriendlyName", + chatUserFriendlyName, + ParameterType.URLENCODED + ); + } + + if (chatFriendlyName != null) { + Serializer.toString( + request, + "ChatFriendlyName", + chatFriendlyName, + ParameterType.URLENCODED + ); + } + + if (target != null) { + Serializer.toString( + request, + "Target", + target, + ParameterType.URLENCODED + ); + } + + if (chatUniqueName != null) { + Serializer.toString( + request, + "ChatUniqueName", + chatUniqueName, + ParameterType.URLENCODED + ); + } + + if (preEngagementData != null) { + Serializer.toString( + request, + "PreEngagementData", + preEngagementData, + ParameterType.URLENCODED + ); + } + + if (taskSid != null) { + Serializer.toString( + request, + "TaskSid", + taskSid, + ParameterType.URLENCODED + ); + } + + if (taskAttributes != null) { + Serializer.toString( + request, + "TaskAttributes", + taskAttributes, + ParameterType.URLENCODED + ); + } + + if (longLived != null) { + Serializer.toString( + request, + "LongLived", + longLived, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ChannelDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/ChannelDeleter.java new file mode 100644 index 0000000000..bf2f25fa1b --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/ChannelDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ChannelDeleter extends Deleter { + + private String pathSid; + + public ChannelDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Channels/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ChannelFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/ChannelFetcher.java new file mode 100644 index 0000000000..25f301fe13 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/ChannelFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelFetcher extends Fetcher { + + private String pathSid; + + public ChannelFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Channels/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Channel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Channel.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ChannelReader.java b/src/main/java/com/twilio/rest/flexapi/v1/ChannelReader.java new file mode 100644 index 0000000000..49b7bb5cfe --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/ChannelReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelReader extends Reader { + + private Long pageSize; + + public ChannelReader() {} + + public ChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flex_chat_channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Channels"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flex_chat_channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "flex_chat_channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Configuration.java b/src/main/java/com/twilio/rest/flexapi/v1/Configuration.java new file mode 100644 index 0000000000..edb7dc91cb --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/Configuration.java @@ -0,0 +1,589 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Configuration extends Resource { + + public static ConfigurationFetcher fetcher() { + return new ConfigurationFetcher(); + } + + public static ConfigurationUpdater updater() { + return new ConfigurationUpdater(); + } + + public enum Status { + OK("ok"), + INPROGRESS("inprogress"), + NOTSTARTED("notstarted"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a Configuration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Configuration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object agentConvEndMethods; + + @Getter + private final Object attributes; + + @Getter + private final Boolean callRecordingEnabled; + + @Getter + private final String callRecordingWebhookUrl; + + @Getter + private final List channelConfigs; + + @Getter + private final String chatServiceInstanceSid; + + @Getter + private final Object citrixVoiceVdi; + + @Getter + private final Object crmAttributes; + + @Getter + private final String crmCallbackUrl; + + @Getter + private final Boolean crmEnabled; + + @Getter + private final String crmFallbackUrl; + + @Getter + private final String crmType; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Object debuggerIntegration; + + @Getter + private final Boolean flexInsightsDrilldown; + + @Getter + private final Object flexInsightsHr; + + @Getter + private final String flexInstanceSid; + + @Getter + private final String flexServiceInstanceSid; + + @Getter + private final Object flexUiStatusReport; + + @Getter + private final String flexUrl; + + @Getter + private final List integrations; + + @Getter + private final Object markdown; + + @Getter + private final String messagingServiceInstanceSid; + + @Getter + private final Object notifications; + + @Getter + private final Object offlineConfig; + + @Getter + private final Object outboundCallFlows; + + @Getter + private final Object pluginServiceAttributes; + + @Getter + private final Boolean pluginServiceEnabled; + + @Getter + private final Object publicAttributes; + + @Getter + private final Object queueStatsConfiguration; + + @Getter + private final String runtimeDomain; + + @Getter + private final List serverlessServiceSids; + + @Getter + private final String serviceVersion; + + @Getter + private final Configuration.Status status; + + @Getter + private final String taskrouterOfflineActivitySid; + + @Getter + private final List taskrouterSkills; + + @Getter + private final String taskrouterTargetTaskqueueSid; + + @Getter + private final String taskrouterTargetWorkflowSid; + + @Getter + private final List taskrouterTaskqueues; + + @Getter + private final Object taskrouterWorkerAttributes; + + @Getter + private final Object taskrouterWorkerChannels; + + @Getter + private final String taskrouterWorkspaceSid; + + @Getter + private final Object uiAttributes; + + @Getter + private final Object uiDependencies; + + @Getter + private final String uiLanguage; + + @Getter + private final String uiVersion; + + @Getter + private final URI url; + + @JsonCreator + private Configuration( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "agent_conv_end_methods" + ) final Object agentConvEndMethods, + @JsonProperty("attributes") final Object attributes, + @JsonProperty( + "call_recording_enabled" + ) final Boolean callRecordingEnabled, + @JsonProperty( + "call_recording_webhook_url" + ) final String callRecordingWebhookUrl, + @JsonProperty("channel_configs") final List channelConfigs, + @JsonProperty( + "chat_service_instance_sid" + ) final String chatServiceInstanceSid, + @JsonProperty("citrix_voice_vdi") final Object citrixVoiceVdi, + @JsonProperty("crm_attributes") final Object crmAttributes, + @JsonProperty("crm_callback_url") final String crmCallbackUrl, + @JsonProperty("crm_enabled") final Boolean crmEnabled, + @JsonProperty("crm_fallback_url") final String crmFallbackUrl, + @JsonProperty("crm_type") final String crmType, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("debugger_integration") final Object debuggerIntegration, + @JsonProperty( + "flex_insights_drilldown" + ) final Boolean flexInsightsDrilldown, + @JsonProperty("flex_insights_hr") final Object flexInsightsHr, + @JsonProperty("flex_instance_sid") final String flexInstanceSid, + @JsonProperty( + "flex_service_instance_sid" + ) final String flexServiceInstanceSid, + @JsonProperty("flex_ui_status_report") final Object flexUiStatusReport, + @JsonProperty("flex_url") final String flexUrl, + @JsonProperty("integrations") final List integrations, + @JsonProperty("markdown") final Object markdown, + @JsonProperty( + "messaging_service_instance_sid" + ) final String messagingServiceInstanceSid, + @JsonProperty("notifications") final Object notifications, + @JsonProperty("offline_config") final Object offlineConfig, + @JsonProperty("outbound_call_flows") final Object outboundCallFlows, + @JsonProperty( + "plugin_service_attributes" + ) final Object pluginServiceAttributes, + @JsonProperty( + "plugin_service_enabled" + ) final Boolean pluginServiceEnabled, + @JsonProperty("public_attributes") final Object publicAttributes, + @JsonProperty( + "queue_stats_configuration" + ) final Object queueStatsConfiguration, + @JsonProperty("runtime_domain") final String runtimeDomain, + @JsonProperty("serverless_service_sids") final List< + String + > serverlessServiceSids, + @JsonProperty("service_version") final String serviceVersion, + @JsonProperty("status") final Configuration.Status status, + @JsonProperty( + "taskrouter_offline_activity_sid" + ) final String taskrouterOfflineActivitySid, + @JsonProperty("taskrouter_skills") final List taskrouterSkills, + @JsonProperty( + "taskrouter_target_taskqueue_sid" + ) final String taskrouterTargetTaskqueueSid, + @JsonProperty( + "taskrouter_target_workflow_sid" + ) final String taskrouterTargetWorkflowSid, + @JsonProperty("taskrouter_taskqueues") final List< + Object + > taskrouterTaskqueues, + @JsonProperty( + "taskrouter_worker_attributes" + ) final Object taskrouterWorkerAttributes, + @JsonProperty( + "taskrouter_worker_channels" + ) final Object taskrouterWorkerChannels, + @JsonProperty( + "taskrouter_workspace_sid" + ) final String taskrouterWorkspaceSid, + @JsonProperty("ui_attributes") final Object uiAttributes, + @JsonProperty("ui_dependencies") final Object uiDependencies, + @JsonProperty("ui_language") final String uiLanguage, + @JsonProperty("ui_version") final String uiVersion, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.agentConvEndMethods = agentConvEndMethods; + this.attributes = attributes; + this.callRecordingEnabled = callRecordingEnabled; + this.callRecordingWebhookUrl = callRecordingWebhookUrl; + this.channelConfigs = channelConfigs; + this.chatServiceInstanceSid = chatServiceInstanceSid; + this.citrixVoiceVdi = citrixVoiceVdi; + this.crmAttributes = crmAttributes; + this.crmCallbackUrl = crmCallbackUrl; + this.crmEnabled = crmEnabled; + this.crmFallbackUrl = crmFallbackUrl; + this.crmType = crmType; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.debuggerIntegration = debuggerIntegration; + this.flexInsightsDrilldown = flexInsightsDrilldown; + this.flexInsightsHr = flexInsightsHr; + this.flexInstanceSid = flexInstanceSid; + this.flexServiceInstanceSid = flexServiceInstanceSid; + this.flexUiStatusReport = flexUiStatusReport; + this.flexUrl = flexUrl; + this.integrations = integrations; + this.markdown = markdown; + this.messagingServiceInstanceSid = messagingServiceInstanceSid; + this.notifications = notifications; + this.offlineConfig = offlineConfig; + this.outboundCallFlows = outboundCallFlows; + this.pluginServiceAttributes = pluginServiceAttributes; + this.pluginServiceEnabled = pluginServiceEnabled; + this.publicAttributes = publicAttributes; + this.queueStatsConfiguration = queueStatsConfiguration; + this.runtimeDomain = runtimeDomain; + this.serverlessServiceSids = serverlessServiceSids; + this.serviceVersion = serviceVersion; + this.status = status; + this.taskrouterOfflineActivitySid = taskrouterOfflineActivitySid; + this.taskrouterSkills = taskrouterSkills; + this.taskrouterTargetTaskqueueSid = taskrouterTargetTaskqueueSid; + this.taskrouterTargetWorkflowSid = taskrouterTargetWorkflowSid; + this.taskrouterTaskqueues = taskrouterTaskqueues; + this.taskrouterWorkerAttributes = taskrouterWorkerAttributes; + this.taskrouterWorkerChannels = taskrouterWorkerChannels; + this.taskrouterWorkspaceSid = taskrouterWorkspaceSid; + this.uiAttributes = uiAttributes; + this.uiDependencies = uiDependencies; + this.uiLanguage = uiLanguage; + this.uiVersion = uiVersion; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Configuration other = (Configuration) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(agentConvEndMethods, other.agentConvEndMethods) && + Objects.equals(attributes, other.attributes) && + Objects.equals(callRecordingEnabled, other.callRecordingEnabled) && + Objects.equals( + callRecordingWebhookUrl, + other.callRecordingWebhookUrl + ) && + Objects.equals(channelConfigs, other.channelConfigs) && + Objects.equals( + chatServiceInstanceSid, + other.chatServiceInstanceSid + ) && + Objects.equals(citrixVoiceVdi, other.citrixVoiceVdi) && + Objects.equals(crmAttributes, other.crmAttributes) && + Objects.equals(crmCallbackUrl, other.crmCallbackUrl) && + Objects.equals(crmEnabled, other.crmEnabled) && + Objects.equals(crmFallbackUrl, other.crmFallbackUrl) && + Objects.equals(crmType, other.crmType) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(debuggerIntegration, other.debuggerIntegration) && + Objects.equals( + flexInsightsDrilldown, + other.flexInsightsDrilldown + ) && + Objects.equals(flexInsightsHr, other.flexInsightsHr) && + Objects.equals(flexInstanceSid, other.flexInstanceSid) && + Objects.equals( + flexServiceInstanceSid, + other.flexServiceInstanceSid + ) && + Objects.equals(flexUiStatusReport, other.flexUiStatusReport) && + Objects.equals(flexUrl, other.flexUrl) && + Objects.equals(integrations, other.integrations) && + Objects.equals(markdown, other.markdown) && + Objects.equals( + messagingServiceInstanceSid, + other.messagingServiceInstanceSid + ) && + Objects.equals(notifications, other.notifications) && + Objects.equals(offlineConfig, other.offlineConfig) && + Objects.equals(outboundCallFlows, other.outboundCallFlows) && + Objects.equals( + pluginServiceAttributes, + other.pluginServiceAttributes + ) && + Objects.equals(pluginServiceEnabled, other.pluginServiceEnabled) && + Objects.equals(publicAttributes, other.publicAttributes) && + Objects.equals( + queueStatsConfiguration, + other.queueStatsConfiguration + ) && + Objects.equals(runtimeDomain, other.runtimeDomain) && + Objects.equals( + serverlessServiceSids, + other.serverlessServiceSids + ) && + Objects.equals(serviceVersion, other.serviceVersion) && + Objects.equals(status, other.status) && + Objects.equals( + taskrouterOfflineActivitySid, + other.taskrouterOfflineActivitySid + ) && + Objects.equals(taskrouterSkills, other.taskrouterSkills) && + Objects.equals( + taskrouterTargetTaskqueueSid, + other.taskrouterTargetTaskqueueSid + ) && + Objects.equals( + taskrouterTargetWorkflowSid, + other.taskrouterTargetWorkflowSid + ) && + Objects.equals(taskrouterTaskqueues, other.taskrouterTaskqueues) && + Objects.equals( + taskrouterWorkerAttributes, + other.taskrouterWorkerAttributes + ) && + Objects.equals( + taskrouterWorkerChannels, + other.taskrouterWorkerChannels + ) && + Objects.equals( + taskrouterWorkspaceSid, + other.taskrouterWorkspaceSid + ) && + Objects.equals(uiAttributes, other.uiAttributes) && + Objects.equals(uiDependencies, other.uiDependencies) && + Objects.equals(uiLanguage, other.uiLanguage) && + Objects.equals(uiVersion, other.uiVersion) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + agentConvEndMethods, + attributes, + callRecordingEnabled, + callRecordingWebhookUrl, + channelConfigs, + chatServiceInstanceSid, + citrixVoiceVdi, + crmAttributes, + crmCallbackUrl, + crmEnabled, + crmFallbackUrl, + crmType, + dateCreated, + dateUpdated, + debuggerIntegration, + flexInsightsDrilldown, + flexInsightsHr, + flexInstanceSid, + flexServiceInstanceSid, + flexUiStatusReport, + flexUrl, + integrations, + markdown, + messagingServiceInstanceSid, + notifications, + offlineConfig, + outboundCallFlows, + pluginServiceAttributes, + pluginServiceEnabled, + publicAttributes, + queueStatsConfiguration, + runtimeDomain, + serverlessServiceSids, + serviceVersion, + status, + taskrouterOfflineActivitySid, + taskrouterSkills, + taskrouterTargetTaskqueueSid, + taskrouterTargetWorkflowSid, + taskrouterTaskqueues, + taskrouterWorkerAttributes, + taskrouterWorkerChannels, + taskrouterWorkspaceSid, + uiAttributes, + uiDependencies, + uiLanguage, + uiVersion, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationFetcher.java new file mode 100644 index 0000000000..721927cc19 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationFetcher extends Fetcher { + + private String uiVersion; + + public ConfigurationFetcher() {} + + public ConfigurationFetcher setUiVersion(final String uiVersion) { + this.uiVersion = uiVersion; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Configuration content = Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (uiVersion != null) { + Serializer.toString( + request, + "UiVersion", + uiVersion, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationUpdater.java new file mode 100644 index 0000000000..88688835ff --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/ConfigurationUpdater.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationUpdater extends Updater { + + private Object body; + + public ConfigurationUpdater() {} + + public ConfigurationUpdater setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Configuration"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Configuration content = Configuration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody(Configuration.toJson(body, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlow.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlow.java new file mode 100644 index 0000000000..402a7f8554 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlow.java @@ -0,0 +1,308 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class FlexFlow extends Resource { + + public static FlexFlowCreator creator( + final String friendlyName, + final String chatServiceSid, + final FlexFlow.ChannelType channelType + ) { + return new FlexFlowCreator(friendlyName, chatServiceSid, channelType); + } + + public static FlexFlowDeleter deleter(final String pathSid) { + return new FlexFlowDeleter(pathSid); + } + + public static FlexFlowFetcher fetcher(final String pathSid) { + return new FlexFlowFetcher(pathSid); + } + + public static FlexFlowReader reader() { + return new FlexFlowReader(); + } + + public static FlexFlowUpdater updater(final String pathSid) { + return new FlexFlowUpdater(pathSid); + } + + public enum ChannelType { + WEB("web"), + SMS("sms"), + FACEBOOK("facebook"), + WHATSAPP("whatsapp"), + LINE("line"), + CUSTOM("custom"); + + private final String value; + + private ChannelType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ChannelType forValue(final String value) { + return Promoter.enumFromString(value, ChannelType.values()); + } + } + + public enum IntegrationType { + STUDIO("studio"), + EXTERNAL("external"), + TASK("task"); + + private final String value; + + private IntegrationType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static IntegrationType forValue(final String value) { + return Promoter.enumFromString(value, IntegrationType.values()); + } + } + + /** + * Converts a JSON String into a FlexFlow object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlexFlow object represented by the provided JSON + */ + public static FlexFlow fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlexFlow.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a FlexFlow object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlexFlow object represented by the provided JSON + */ + public static FlexFlow fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlexFlow.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final FlexFlow.ChannelType channelType; + + @Getter + private final String chatServiceSid; + + @Getter + private final String contactIdentity; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Boolean enabled; + + @Getter + private final String friendlyName; + + @Getter + private final Object integration; + + @Getter + private final FlexFlow.IntegrationType integrationType; + + @Getter + private final Boolean janitorEnabled; + + @Getter + private final Boolean longLived; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private FlexFlow( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_type") final FlexFlow.ChannelType channelType, + @JsonProperty("chat_service_sid") final String chatServiceSid, + @JsonProperty("contact_identity") final String contactIdentity, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("integration") final Object integration, + @JsonProperty( + "integration_type" + ) final FlexFlow.IntegrationType integrationType, + @JsonProperty("janitor_enabled") final Boolean janitorEnabled, + @JsonProperty("long_lived") final Boolean longLived, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelType = channelType; + this.chatServiceSid = chatServiceSid; + this.contactIdentity = contactIdentity; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.enabled = enabled; + this.friendlyName = friendlyName; + this.integration = integration; + this.integrationType = integrationType; + this.janitorEnabled = janitorEnabled; + this.longLived = longLived; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FlexFlow other = (FlexFlow) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelType, other.channelType) && + Objects.equals(chatServiceSid, other.chatServiceSid) && + Objects.equals(contactIdentity, other.contactIdentity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(enabled, other.enabled) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(integration, other.integration) && + Objects.equals(integrationType, other.integrationType) && + Objects.equals(janitorEnabled, other.janitorEnabled) && + Objects.equals(longLived, other.longLived) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + channelType, + chatServiceSid, + contactIdentity, + dateCreated, + dateUpdated, + enabled, + friendlyName, + integration, + integrationType, + janitorEnabled, + longLived, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowCreator.java new file mode 100644 index 0000000000..f0c071461c --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowCreator.java @@ -0,0 +1,387 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class FlexFlowCreator extends Creator { + + private String friendlyName; + private String chatServiceSid; + private FlexFlow.ChannelType channelType; + private String contactIdentity; + private Boolean enabled; + private FlexFlow.IntegrationType integrationType; + private String integrationFlowSid; + private URI integrationUrl; + private String integrationWorkspaceSid; + private String integrationWorkflowSid; + private String integrationChannel; + private Integer integrationTimeout; + private Integer integrationPriority; + private Boolean integrationCreationOnMessage; + private Boolean longLived; + private Boolean janitorEnabled; + private Integer integrationRetryCount; + + public FlexFlowCreator( + final String friendlyName, + final String chatServiceSid, + final FlexFlow.ChannelType channelType + ) { + this.friendlyName = friendlyName; + this.chatServiceSid = chatServiceSid; + this.channelType = channelType; + } + + public FlexFlowCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public FlexFlowCreator setChatServiceSid(final String chatServiceSid) { + this.chatServiceSid = chatServiceSid; + return this; + } + + public FlexFlowCreator setChannelType( + final FlexFlow.ChannelType channelType + ) { + this.channelType = channelType; + return this; + } + + public FlexFlowCreator setContactIdentity(final String contactIdentity) { + this.contactIdentity = contactIdentity; + return this; + } + + public FlexFlowCreator setEnabled(final Boolean enabled) { + this.enabled = enabled; + return this; + } + + public FlexFlowCreator setIntegrationType( + final FlexFlow.IntegrationType integrationType + ) { + this.integrationType = integrationType; + return this; + } + + public FlexFlowCreator setIntegrationFlowSid( + final String integrationFlowSid + ) { + this.integrationFlowSid = integrationFlowSid; + return this; + } + + public FlexFlowCreator setIntegrationUrl(final URI integrationUrl) { + this.integrationUrl = integrationUrl; + return this; + } + + public FlexFlowCreator setIntegrationUrl(final String integrationUrl) { + return setIntegrationUrl(Promoter.uriFromString(integrationUrl)); + } + + public FlexFlowCreator setIntegrationWorkspaceSid( + final String integrationWorkspaceSid + ) { + this.integrationWorkspaceSid = integrationWorkspaceSid; + return this; + } + + public FlexFlowCreator setIntegrationWorkflowSid( + final String integrationWorkflowSid + ) { + this.integrationWorkflowSid = integrationWorkflowSid; + return this; + } + + public FlexFlowCreator setIntegrationChannel( + final String integrationChannel + ) { + this.integrationChannel = integrationChannel; + return this; + } + + public FlexFlowCreator setIntegrationTimeout( + final Integer integrationTimeout + ) { + this.integrationTimeout = integrationTimeout; + return this; + } + + public FlexFlowCreator setIntegrationPriority( + final Integer integrationPriority + ) { + this.integrationPriority = integrationPriority; + return this; + } + + public FlexFlowCreator setIntegrationCreationOnMessage( + final Boolean integrationCreationOnMessage + ) { + this.integrationCreationOnMessage = integrationCreationOnMessage; + return this; + } + + public FlexFlowCreator setLongLived(final Boolean longLived) { + this.longLived = longLived; + return this; + } + + public FlexFlowCreator setJanitorEnabled(final Boolean janitorEnabled) { + this.janitorEnabled = janitorEnabled; + return this; + } + + public FlexFlowCreator setIntegrationRetryCount( + final Integer integrationRetryCount + ) { + this.integrationRetryCount = integrationRetryCount; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/FlexFlows"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlexFlow creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlexFlow create(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlexFlow content = FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (chatServiceSid != null) { + Serializer.toString( + request, + "ChatServiceSid", + chatServiceSid, + ParameterType.URLENCODED + ); + } + + if (channelType != null) { + Serializer.toString( + request, + "ChannelType", + channelType, + ParameterType.URLENCODED + ); + } + + if (contactIdentity != null) { + Serializer.toString( + request, + "ContactIdentity", + contactIdentity, + ParameterType.URLENCODED + ); + } + + if (enabled != null) { + Serializer.toString( + request, + "Enabled", + enabled, + ParameterType.URLENCODED + ); + } + + if (integrationType != null) { + Serializer.toString( + request, + "IntegrationType", + integrationType, + ParameterType.URLENCODED + ); + } + + if (integrationFlowSid != null) { + Serializer.toString( + request, + "Integration.FlowSid", + integrationFlowSid, + ParameterType.URLENCODED + ); + } + + if (integrationUrl != null) { + Serializer.toString( + request, + "Integration.Url", + integrationUrl, + ParameterType.URLENCODED + ); + } + + if (integrationWorkspaceSid != null) { + Serializer.toString( + request, + "Integration.WorkspaceSid", + integrationWorkspaceSid, + ParameterType.URLENCODED + ); + } + + if (integrationWorkflowSid != null) { + Serializer.toString( + request, + "Integration.WorkflowSid", + integrationWorkflowSid, + ParameterType.URLENCODED + ); + } + + if (integrationChannel != null) { + Serializer.toString( + request, + "Integration.Channel", + integrationChannel, + ParameterType.URLENCODED + ); + } + + if (integrationTimeout != null) { + Serializer.toString( + request, + "Integration.Timeout", + integrationTimeout, + ParameterType.URLENCODED + ); + } + + if (integrationPriority != null) { + Serializer.toString( + request, + "Integration.Priority", + integrationPriority, + ParameterType.URLENCODED + ); + } + + if (integrationCreationOnMessage != null) { + Serializer.toString( + request, + "Integration.CreationOnMessage", + integrationCreationOnMessage, + ParameterType.URLENCODED + ); + } + + if (longLived != null) { + Serializer.toString( + request, + "LongLived", + longLived, + ParameterType.URLENCODED + ); + } + + if (janitorEnabled != null) { + Serializer.toString( + request, + "JanitorEnabled", + janitorEnabled, + ParameterType.URLENCODED + ); + } + + if (integrationRetryCount != null) { + Serializer.toString( + request, + "Integration.RetryCount", + integrationRetryCount, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowDeleter.java new file mode 100644 index 0000000000..9d0a806dbe --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class FlexFlowDeleter extends Deleter { + + private String pathSid; + + public FlexFlowDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/FlexFlows/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlexFlow delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowFetcher.java new file mode 100644 index 0000000000..ad8115dbc8 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlexFlowFetcher extends Fetcher { + + private String pathSid; + + public FlexFlowFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/FlexFlows/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlexFlow fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlexFlow fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlexFlow content = FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowReader.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowReader.java new file mode 100644 index 0000000000..f5ed9a6bce --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowReader.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlexFlowReader extends Reader { + + private String friendlyName; + private Long pageSize; + + public FlexFlowReader() {} + + public FlexFlowReader setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public FlexFlowReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flex_flows", + response.getContent(), + FlexFlow.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/FlexFlows"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flex_flows", + response.getContent(), + FlexFlow.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "FlexFlow read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "flex_flows", + response.getContent(), + FlexFlow.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowUpdater.java new file mode 100644 index 0000000000..eaacad6e92 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/FlexFlowUpdater.java @@ -0,0 +1,384 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class FlexFlowUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private String chatServiceSid; + private FlexFlow.ChannelType channelType; + private String contactIdentity; + private Boolean enabled; + private FlexFlow.IntegrationType integrationType; + private String integrationFlowSid; + private URI integrationUrl; + private String integrationWorkspaceSid; + private String integrationWorkflowSid; + private String integrationChannel; + private Integer integrationTimeout; + private Integer integrationPriority; + private Boolean integrationCreationOnMessage; + private Boolean longLived; + private Boolean janitorEnabled; + private Integer integrationRetryCount; + + public FlexFlowUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public FlexFlowUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public FlexFlowUpdater setChatServiceSid(final String chatServiceSid) { + this.chatServiceSid = chatServiceSid; + return this; + } + + public FlexFlowUpdater setChannelType( + final FlexFlow.ChannelType channelType + ) { + this.channelType = channelType; + return this; + } + + public FlexFlowUpdater setContactIdentity(final String contactIdentity) { + this.contactIdentity = contactIdentity; + return this; + } + + public FlexFlowUpdater setEnabled(final Boolean enabled) { + this.enabled = enabled; + return this; + } + + public FlexFlowUpdater setIntegrationType( + final FlexFlow.IntegrationType integrationType + ) { + this.integrationType = integrationType; + return this; + } + + public FlexFlowUpdater setIntegrationFlowSid( + final String integrationFlowSid + ) { + this.integrationFlowSid = integrationFlowSid; + return this; + } + + public FlexFlowUpdater setIntegrationUrl(final URI integrationUrl) { + this.integrationUrl = integrationUrl; + return this; + } + + public FlexFlowUpdater setIntegrationUrl(final String integrationUrl) { + return setIntegrationUrl(Promoter.uriFromString(integrationUrl)); + } + + public FlexFlowUpdater setIntegrationWorkspaceSid( + final String integrationWorkspaceSid + ) { + this.integrationWorkspaceSid = integrationWorkspaceSid; + return this; + } + + public FlexFlowUpdater setIntegrationWorkflowSid( + final String integrationWorkflowSid + ) { + this.integrationWorkflowSid = integrationWorkflowSid; + return this; + } + + public FlexFlowUpdater setIntegrationChannel( + final String integrationChannel + ) { + this.integrationChannel = integrationChannel; + return this; + } + + public FlexFlowUpdater setIntegrationTimeout( + final Integer integrationTimeout + ) { + this.integrationTimeout = integrationTimeout; + return this; + } + + public FlexFlowUpdater setIntegrationPriority( + final Integer integrationPriority + ) { + this.integrationPriority = integrationPriority; + return this; + } + + public FlexFlowUpdater setIntegrationCreationOnMessage( + final Boolean integrationCreationOnMessage + ) { + this.integrationCreationOnMessage = integrationCreationOnMessage; + return this; + } + + public FlexFlowUpdater setLongLived(final Boolean longLived) { + this.longLived = longLived; + return this; + } + + public FlexFlowUpdater setJanitorEnabled(final Boolean janitorEnabled) { + this.janitorEnabled = janitorEnabled; + return this; + } + + public FlexFlowUpdater setIntegrationRetryCount( + final Integer integrationRetryCount + ) { + this.integrationRetryCount = integrationRetryCount; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/FlexFlows/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlexFlow update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlexFlow update(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlexFlow content = FlexFlow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (chatServiceSid != null) { + Serializer.toString( + request, + "ChatServiceSid", + chatServiceSid, + ParameterType.URLENCODED + ); + } + + if (channelType != null) { + Serializer.toString( + request, + "ChannelType", + channelType, + ParameterType.URLENCODED + ); + } + + if (contactIdentity != null) { + Serializer.toString( + request, + "ContactIdentity", + contactIdentity, + ParameterType.URLENCODED + ); + } + + if (enabled != null) { + Serializer.toString( + request, + "Enabled", + enabled, + ParameterType.URLENCODED + ); + } + + if (integrationType != null) { + Serializer.toString( + request, + "IntegrationType", + integrationType, + ParameterType.URLENCODED + ); + } + + if (integrationFlowSid != null) { + Serializer.toString( + request, + "Integration.FlowSid", + integrationFlowSid, + ParameterType.URLENCODED + ); + } + + if (integrationUrl != null) { + Serializer.toString( + request, + "Integration.Url", + integrationUrl, + ParameterType.URLENCODED + ); + } + + if (integrationWorkspaceSid != null) { + Serializer.toString( + request, + "Integration.WorkspaceSid", + integrationWorkspaceSid, + ParameterType.URLENCODED + ); + } + + if (integrationWorkflowSid != null) { + Serializer.toString( + request, + "Integration.WorkflowSid", + integrationWorkflowSid, + ParameterType.URLENCODED + ); + } + + if (integrationChannel != null) { + Serializer.toString( + request, + "Integration.Channel", + integrationChannel, + ParameterType.URLENCODED + ); + } + + if (integrationTimeout != null) { + Serializer.toString( + request, + "Integration.Timeout", + integrationTimeout, + ParameterType.URLENCODED + ); + } + + if (integrationPriority != null) { + Serializer.toString( + request, + "Integration.Priority", + integrationPriority, + ParameterType.URLENCODED + ); + } + + if (integrationCreationOnMessage != null) { + Serializer.toString( + request, + "Integration.CreationOnMessage", + integrationCreationOnMessage, + ParameterType.URLENCODED + ); + } + + if (longLived != null) { + Serializer.toString( + request, + "LongLived", + longLived, + ParameterType.URLENCODED + ); + } + + if (janitorEnabled != null) { + Serializer.toString( + request, + "JanitorEnabled", + janitorEnabled, + ParameterType.URLENCODED + ); + } + + if (integrationRetryCount != null) { + Serializer.toString( + request, + "Integration.RetryCount", + integrationRetryCount, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsComment.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsComment.java new file mode 100644 index 0000000000..331546fda1 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsComment.java @@ -0,0 +1,235 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsAssessmentsComment extends Resource { + + public static InsightsAssessmentsCommentCreator creator( + final String categoryId, + final String categoryName, + final String comment, + final String segmentId, + final String agentId, + final BigDecimal offset + ) { + return new InsightsAssessmentsCommentCreator( + categoryId, + categoryName, + comment, + segmentId, + agentId, + offset + ); + } + + public static InsightsAssessmentsCommentReader reader() { + return new InsightsAssessmentsCommentReader(); + } + + /** + * Converts a JSON String into a InsightsAssessmentsComment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsAssessmentsComment object represented by the provided JSON + */ + public static InsightsAssessmentsComment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InsightsAssessmentsComment.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsAssessmentsComment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsAssessmentsComment object represented by the provided JSON + */ + public static InsightsAssessmentsComment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InsightsAssessmentsComment.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String agentId; + + @Getter + private final String assessmentSid; + + @Getter + private final Object comment; + + @Getter + private final String offset; + + @Getter + private final Boolean report; + + @Getter + private final String segmentId; + + @Getter + private final String timestamp; + + @Getter + private final URI url; + + @Getter + private final String userEmail; + + @Getter + private final String userName; + + @Getter + private final String weight; + + @JsonCreator + private InsightsAssessmentsComment( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("agent_id") final String agentId, + @JsonProperty("assessment_sid") final String assessmentSid, + @JsonProperty("comment") final Object comment, + @JsonProperty("offset") final String offset, + @JsonProperty("report") final Boolean report, + @JsonProperty("segment_id") final String segmentId, + @JsonProperty("timestamp") final String timestamp, + @JsonProperty("url") final URI url, + @JsonProperty("user_email") final String userEmail, + @JsonProperty("user_name") final String userName, + @JsonProperty("weight") final String weight + ) { + this.accountSid = accountSid; + this.agentId = agentId; + this.assessmentSid = assessmentSid; + this.comment = comment; + this.offset = offset; + this.report = report; + this.segmentId = segmentId; + this.timestamp = timestamp; + this.url = url; + this.userEmail = userEmail; + this.userName = userName; + this.weight = weight; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsAssessmentsComment other = (InsightsAssessmentsComment) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(agentId, other.agentId) && + Objects.equals(assessmentSid, other.assessmentSid) && + Objects.equals(comment, other.comment) && + Objects.equals(offset, other.offset) && + Objects.equals(report, other.report) && + Objects.equals(segmentId, other.segmentId) && + Objects.equals(timestamp, other.timestamp) && + Objects.equals(url, other.url) && + Objects.equals(userEmail, other.userEmail) && + Objects.equals(userName, other.userName) && + Objects.equals(weight, other.weight) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + agentId, + assessmentSid, + comment, + offset, + report, + segmentId, + timestamp, + url, + userEmail, + userName, + weight + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentCreator.java new file mode 100644 index 0000000000..9b1f918d8e --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentCreator.java @@ -0,0 +1,233 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.math.BigDecimal; + +public class InsightsAssessmentsCommentCreator + extends Creator { + + private String authorization; + private String categoryId; + private String categoryName; + private String comment; + private String segmentId; + private String agentId; + private BigDecimal offset; + + public InsightsAssessmentsCommentCreator( + final String categoryId, + final String categoryName, + final String comment, + final String segmentId, + final String agentId, + final BigDecimal offset + ) { + this.categoryId = categoryId; + this.categoryName = categoryName; + this.comment = comment; + this.segmentId = segmentId; + this.agentId = agentId; + this.offset = offset; + } + + public InsightsAssessmentsCommentCreator setCategoryId( + final String categoryId + ) { + this.categoryId = categoryId; + return this; + } + + public InsightsAssessmentsCommentCreator setCategoryName( + final String categoryName + ) { + this.categoryName = categoryName; + return this; + } + + public InsightsAssessmentsCommentCreator setComment(final String comment) { + this.comment = comment; + return this; + } + + public InsightsAssessmentsCommentCreator setSegmentId( + final String segmentId + ) { + this.segmentId = segmentId; + return this; + } + + public InsightsAssessmentsCommentCreator setAgentId(final String agentId) { + this.agentId = agentId; + return this; + } + + public InsightsAssessmentsCommentCreator setOffset( + final BigDecimal offset + ) { + this.offset = offset; + return this; + } + + public InsightsAssessmentsCommentCreator setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Assessments/Comments"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsAssessmentsComment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsAssessmentsComment create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InsightsAssessmentsComment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsAssessmentsComment content = + InsightsAssessmentsComment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (categoryId != null) { + Serializer.toString( + request, + "CategoryId", + categoryId, + ParameterType.URLENCODED + ); + } + + if (categoryName != null) { + Serializer.toString( + request, + "CategoryName", + categoryName, + ParameterType.URLENCODED + ); + } + + if (comment != null) { + Serializer.toString( + request, + "Comment", + comment, + ParameterType.URLENCODED + ); + } + + if (segmentId != null) { + Serializer.toString( + request, + "SegmentId", + segmentId, + ParameterType.URLENCODED + ); + } + + if (agentId != null) { + Serializer.toString( + request, + "AgentId", + agentId, + ParameterType.URLENCODED + ); + } + + if (offset != null) { + Serializer.toString( + request, + "Offset", + offset, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentReader.java new file mode 100644 index 0000000000..2d560b705c --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsAssessmentsCommentReader.java @@ -0,0 +1,259 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsAssessmentsCommentReader + extends Reader { + + private String segmentId; + private String agentId; + private Long pageSize; + private String authorization; + + public InsightsAssessmentsCommentReader() {} + + public InsightsAssessmentsCommentReader setSegmentId( + final String segmentId + ) { + this.segmentId = segmentId; + return this; + } + + public InsightsAssessmentsCommentReader setAgentId(final String agentId) { + this.agentId = agentId; + return this; + } + + public InsightsAssessmentsCommentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public InsightsAssessmentsCommentReader setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "comments", + response.getContent(), + InsightsAssessmentsComment.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Assessments/Comments"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "comments", + response.getContent(), + InsightsAssessmentsComment.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InsightsAssessmentsComment read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "comments", + response.getContent(), + InsightsAssessmentsComment.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (segmentId != null) { + Serializer.toString( + request, + "SegmentId", + segmentId, + ParameterType.QUERY + ); + } + + if (agentId != null) { + Serializer.toString( + request, + "AgentId", + agentId, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversations.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversations.java new file mode 100644 index 0000000000..4aa1b99644 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversations.java @@ -0,0 +1,149 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsConversations extends Resource { + + public static InsightsConversationsReader reader() { + return new InsightsConversationsReader(); + } + + /** + * Converts a JSON String into a InsightsConversations object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsConversations object represented by the provided JSON + */ + public static InsightsConversations fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsConversations.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsConversations object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsConversations object represented by the provided JSON + */ + public static InsightsConversations fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsConversations.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountId; + + @Getter + private final String conversationId; + + @Getter + private final Integer segmentCount; + + @Getter + private final List segments; + + @JsonCreator + private InsightsConversations( + @JsonProperty("account_id") final String accountId, + @JsonProperty("conversation_id") final String conversationId, + @JsonProperty("segment_count") final Integer segmentCount, + @JsonProperty("segments") final List segments + ) { + this.accountId = accountId; + this.conversationId = conversationId; + this.segmentCount = segmentCount; + this.segments = segments; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsConversations other = (InsightsConversations) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(segmentCount, other.segmentCount) && + Objects.equals(segments, other.segments) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountId, conversationId, segmentCount, segments); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversationsReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversationsReader.java new file mode 100644 index 0000000000..325e5f3031 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsConversationsReader.java @@ -0,0 +1,241 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsConversationsReader extends Reader { + + private String segmentId; + private Long pageSize; + private String authorization; + + public InsightsConversationsReader() {} + + public InsightsConversationsReader setSegmentId(final String segmentId) { + this.segmentId = segmentId; + return this; + } + + public InsightsConversationsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public InsightsConversationsReader setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + InsightsConversations.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Insights/Conversations"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conversations", + response.getContent(), + InsightsConversations.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InsightsConversations read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conversations", + response.getContent(), + InsightsConversations.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (segmentId != null) { + Serializer.toString( + request, + "SegmentId", + segmentId, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnaires.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnaires.java new file mode 100644 index 0000000000..263e16a5ee --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnaires.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsQuestionnaires extends Resource { + + public static InsightsQuestionnairesCreator creator(final String name) { + return new InsightsQuestionnairesCreator(name); + } + + public static InsightsQuestionnairesDeleter deleter( + final String pathQuestionnaireSid + ) { + return new InsightsQuestionnairesDeleter(pathQuestionnaireSid); + } + + public static InsightsQuestionnairesFetcher fetcher( + final String pathQuestionnaireSid + ) { + return new InsightsQuestionnairesFetcher(pathQuestionnaireSid); + } + + public static InsightsQuestionnairesReader reader() { + return new InsightsQuestionnairesReader(); + } + + public static InsightsQuestionnairesUpdater updater( + final String pathQuestionnaireSid, + final Boolean active + ) { + return new InsightsQuestionnairesUpdater(pathQuestionnaireSid, active); + } + + /** + * Converts a JSON String into a InsightsQuestionnaires object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnaires object represented by the provided JSON + */ + public static InsightsQuestionnaires fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsQuestionnaires.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsQuestionnaires object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnaires object represented by the provided JSON + */ + public static InsightsQuestionnaires fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsQuestionnaires.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean active; + + @Getter + private final String description; + + @Getter + private final String name; + + @Getter + private final String questionnaireSid; + + @Getter + private final List questions; + + @Getter + private final URI url; + + @JsonCreator + private InsightsQuestionnaires( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("active") final Boolean active, + @JsonProperty("description") final String description, + @JsonProperty("name") final String name, + @JsonProperty("questionnaire_sid") final String questionnaireSid, + @JsonProperty("questions") final List questions, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.active = active; + this.description = description; + this.name = name; + this.questionnaireSid = questionnaireSid; + this.questions = questions; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsQuestionnaires other = (InsightsQuestionnaires) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(active, other.active) && + Objects.equals(description, other.description) && + Objects.equals(name, other.name) && + Objects.equals(questionnaireSid, other.questionnaireSid) && + Objects.equals(questions, other.questions) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + active, + description, + name, + questionnaireSid, + questions, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategory.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategory.java new file mode 100644 index 0000000000..6d0ce4b941 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategory.java @@ -0,0 +1,175 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsQuestionnairesCategory extends Resource { + + public static InsightsQuestionnairesCategoryCreator creator( + final String name + ) { + return new InsightsQuestionnairesCategoryCreator(name); + } + + public static InsightsQuestionnairesCategoryDeleter deleter( + final String pathCategorySid + ) { + return new InsightsQuestionnairesCategoryDeleter(pathCategorySid); + } + + public static InsightsQuestionnairesCategoryReader reader() { + return new InsightsQuestionnairesCategoryReader(); + } + + public static InsightsQuestionnairesCategoryUpdater updater( + final String pathCategorySid, + final String name + ) { + return new InsightsQuestionnairesCategoryUpdater(pathCategorySid, name); + } + + /** + * Converts a JSON String into a InsightsQuestionnairesCategory object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnairesCategory object represented by the provided JSON + */ + public static InsightsQuestionnairesCategory fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InsightsQuestionnairesCategory.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsQuestionnairesCategory object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnairesCategory object represented by the provided JSON + */ + public static InsightsQuestionnairesCategory fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InsightsQuestionnairesCategory.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String categorySid; + + @Getter + private final String name; + + @Getter + private final URI url; + + @JsonCreator + private InsightsQuestionnairesCategory( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("category_sid") final String categorySid, + @JsonProperty("name") final String name, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.categorySid = categorySid; + this.name = name; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsQuestionnairesCategory other = + (InsightsQuestionnairesCategory) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(categorySid, other.categorySid) && + Objects.equals(name, other.name) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, categorySid, name, url); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryCreator.java new file mode 100644 index 0000000000..295ed208d7 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryCreator.java @@ -0,0 +1,139 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsQuestionnairesCategoryCreator + extends Creator { + + private String authorization; + private String name; + + public InsightsQuestionnairesCategoryCreator(final String name) { + this.name = name; + } + + public InsightsQuestionnairesCategoryCreator setName(final String name) { + this.name = name; + return this; + } + + public InsightsQuestionnairesCategoryCreator setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Categories"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnairesCategory creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsQuestionnairesCategory create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return InsightsQuestionnairesCategory.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsQuestionnairesCategory content = + InsightsQuestionnairesCategory.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (name != null) { + Serializer.toString( + request, + "Name", + name, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryDeleter.java new file mode 100644 index 0000000000..96780b9c1f --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryDeleter.java @@ -0,0 +1,124 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class InsightsQuestionnairesCategoryDeleter + extends Deleter { + + private String pathCategorySid; + private String authorization; + + public InsightsQuestionnairesCategoryDeleter(final String pathCategorySid) { + this.pathCategorySid = pathCategorySid; + } + + public InsightsQuestionnairesCategoryDeleter setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Categories/{CategorySid}"; + + path = + path.replace( + "{" + "CategorySid" + "}", + this.pathCategorySid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnairesCategory delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryReader.java new file mode 100644 index 0000000000..08dd13f8c0 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryReader.java @@ -0,0 +1,226 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsQuestionnairesCategoryReader + extends Reader { + + private Long pageSize; + private String authorization; + + public InsightsQuestionnairesCategoryReader() {} + + public InsightsQuestionnairesCategoryReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public InsightsQuestionnairesCategoryReader setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "categories", + response.getContent(), + InsightsQuestionnairesCategory.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Categories"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "categories", + response.getContent(), + InsightsQuestionnairesCategory.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnairesCategory read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "categories", + response.getContent(), + InsightsQuestionnairesCategory.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryUpdater.java new file mode 100644 index 0000000000..d6453e9aea --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCategoryUpdater.java @@ -0,0 +1,150 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsQuestionnairesCategoryUpdater + extends Updater { + + private String pathCategorySid; + private String authorization; + private String name; + + public InsightsQuestionnairesCategoryUpdater( + final String pathCategorySid, + final String name + ) { + this.pathCategorySid = pathCategorySid; + this.name = name; + } + + public InsightsQuestionnairesCategoryUpdater setName(final String name) { + this.name = name; + return this; + } + + public InsightsQuestionnairesCategoryUpdater setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Categories/{CategorySid}"; + + path = + path.replace( + "{" + "CategorySid" + "}", + this.pathCategorySid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnairesCategory update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsQuestionnairesCategory update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return InsightsQuestionnairesCategory.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsQuestionnairesCategory content = + InsightsQuestionnairesCategory.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (name != null) { + Serializer.toString( + request, + "Name", + name, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCreator.java new file mode 100644 index 0000000000..2dc14da917 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesCreator.java @@ -0,0 +1,195 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class InsightsQuestionnairesCreator + extends Creator { + + private String authorization; + private String name; + private String description; + private Boolean active; + private List questionSids; + + public InsightsQuestionnairesCreator(final String name) { + this.name = name; + } + + public InsightsQuestionnairesCreator setName(final String name) { + this.name = name; + return this; + } + + public InsightsQuestionnairesCreator setDescription( + final String description + ) { + this.description = description; + return this; + } + + public InsightsQuestionnairesCreator setActive(final Boolean active) { + this.active = active; + return this; + } + + public InsightsQuestionnairesCreator setQuestionSids( + final List questionSids + ) { + this.questionSids = questionSids; + return this; + } + + public InsightsQuestionnairesCreator setQuestionSids( + final String questionSids + ) { + return setQuestionSids(Promoter.listOfOne(questionSids)); + } + + public InsightsQuestionnairesCreator setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Questionnaires"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnaires creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsQuestionnaires create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsQuestionnaires content = InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (name != null) { + Serializer.toString( + request, + "Name", + name, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (active != null) { + Serializer.toString( + request, + "Active", + active, + ParameterType.URLENCODED + ); + } + + if (questionSids != null) { + for (String param : questionSids) { + Serializer.toString( + request, + "QuestionSids", + param, + ParameterType.URLENCODED + ); + } + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesDeleter.java new file mode 100644 index 0000000000..83811a0973 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesDeleter.java @@ -0,0 +1,125 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class InsightsQuestionnairesDeleter + extends Deleter { + + private String pathQuestionnaireSid; + private String authorization; + + public InsightsQuestionnairesDeleter(final String pathQuestionnaireSid) { + this.pathQuestionnaireSid = pathQuestionnaireSid; + } + + public InsightsQuestionnairesDeleter setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; + + path = + path.replace( + "{" + "QuestionnaireSid" + "}", + this.pathQuestionnaireSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnaires delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesFetcher.java new file mode 100644 index 0000000000..2fd62094b1 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesFetcher.java @@ -0,0 +1,124 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsQuestionnairesFetcher + extends Fetcher { + + private String pathQuestionnaireSid; + private String authorization; + + public InsightsQuestionnairesFetcher(final String pathQuestionnaireSid) { + this.pathQuestionnaireSid = pathQuestionnaireSid; + } + + public InsightsQuestionnairesFetcher setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; + + path = + path.replace( + "{" + "QuestionnaireSid" + "}", + this.pathQuestionnaireSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnaires fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsQuestionnaires fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsQuestionnaires content = InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestion.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestion.java new file mode 100644 index 0000000000..2d2b8ebe46 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestion.java @@ -0,0 +1,233 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsQuestionnairesQuestion extends Resource { + + public static InsightsQuestionnairesQuestionCreator creator( + final String categorySid, + final String question, + final String answerSetId, + final Boolean allowNa + ) { + return new InsightsQuestionnairesQuestionCreator( + categorySid, + question, + answerSetId, + allowNa + ); + } + + public static InsightsQuestionnairesQuestionDeleter deleter( + final String pathQuestionSid + ) { + return new InsightsQuestionnairesQuestionDeleter(pathQuestionSid); + } + + public static InsightsQuestionnairesQuestionReader reader() { + return new InsightsQuestionnairesQuestionReader(); + } + + public static InsightsQuestionnairesQuestionUpdater updater( + final String pathQuestionSid, + final Boolean allowNa + ) { + return new InsightsQuestionnairesQuestionUpdater( + pathQuestionSid, + allowNa + ); + } + + /** + * Converts a JSON String into a InsightsQuestionnairesQuestion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnairesQuestion object represented by the provided JSON + */ + public static InsightsQuestionnairesQuestion fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InsightsQuestionnairesQuestion.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsQuestionnairesQuestion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsQuestionnairesQuestion object represented by the provided JSON + */ + public static InsightsQuestionnairesQuestion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InsightsQuestionnairesQuestion.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean allowNa; + + @Getter + private final Object answerSet; + + @Getter + private final String answerSetId; + + @Getter + private final Object category; + + @Getter + private final String description; + + @Getter + private final String question; + + @Getter + private final String questionSid; + + @Getter + private final URI url; + + @Getter + private final Integer usage; + + @JsonCreator + private InsightsQuestionnairesQuestion( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("allow_na") final Boolean allowNa, + @JsonProperty("answer_set") final Object answerSet, + @JsonProperty("answer_set_id") final String answerSetId, + @JsonProperty("category") final Object category, + @JsonProperty("description") final String description, + @JsonProperty("question") final String question, + @JsonProperty("question_sid") final String questionSid, + @JsonProperty("url") final URI url, + @JsonProperty("usage") final Integer usage + ) { + this.accountSid = accountSid; + this.allowNa = allowNa; + this.answerSet = answerSet; + this.answerSetId = answerSetId; + this.category = category; + this.description = description; + this.question = question; + this.questionSid = questionSid; + this.url = url; + this.usage = usage; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsQuestionnairesQuestion other = + (InsightsQuestionnairesQuestion) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(allowNa, other.allowNa) && + Objects.equals(answerSet, other.answerSet) && + Objects.equals(answerSetId, other.answerSetId) && + Objects.equals(category, other.category) && + Objects.equals(description, other.description) && + Objects.equals(question, other.question) && + Objects.equals(questionSid, other.questionSid) && + Objects.equals(url, other.url) && + Objects.equals(usage, other.usage) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + allowNa, + answerSet, + answerSetId, + category, + description, + question, + questionSid, + url, + usage + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionCreator.java new file mode 100644 index 0000000000..2cccd166a9 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionCreator.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsQuestionnairesQuestionCreator + extends Creator { + + private String authorization; + private String categorySid; + private String question; + private String answerSetId; + private Boolean allowNa; + private String description; + + public InsightsQuestionnairesQuestionCreator( + final String categorySid, + final String question, + final String answerSetId, + final Boolean allowNa + ) { + this.categorySid = categorySid; + this.question = question; + this.answerSetId = answerSetId; + this.allowNa = allowNa; + } + + public InsightsQuestionnairesQuestionCreator setCategorySid( + final String categorySid + ) { + this.categorySid = categorySid; + return this; + } + + public InsightsQuestionnairesQuestionCreator setQuestion( + final String question + ) { + this.question = question; + return this; + } + + public InsightsQuestionnairesQuestionCreator setAnswerSetId( + final String answerSetId + ) { + this.answerSetId = answerSetId; + return this; + } + + public InsightsQuestionnairesQuestionCreator setAllowNa( + final Boolean allowNa + ) { + this.allowNa = allowNa; + return this; + } + + public InsightsQuestionnairesQuestionCreator setDescription( + final String description + ) { + this.description = description; + return this; + } + + public InsightsQuestionnairesQuestionCreator setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Questions"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnairesQuestion creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsQuestionnairesQuestion create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return InsightsQuestionnairesQuestion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsQuestionnairesQuestion content = + InsightsQuestionnairesQuestion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (categorySid != null) { + Serializer.toString( + request, + "CategorySid", + categorySid, + ParameterType.URLENCODED + ); + } + + if (question != null) { + Serializer.toString( + request, + "Question", + question, + ParameterType.URLENCODED + ); + } + + if (answerSetId != null) { + Serializer.toString( + request, + "AnswerSetId", + answerSetId, + ParameterType.URLENCODED + ); + } + + if (allowNa != null) { + Serializer.toString( + request, + "AllowNa", + allowNa, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionDeleter.java new file mode 100644 index 0000000000..7bafe90f45 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionDeleter.java @@ -0,0 +1,124 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class InsightsQuestionnairesQuestionDeleter + extends Deleter { + + private String pathQuestionSid; + private String authorization; + + public InsightsQuestionnairesQuestionDeleter(final String pathQuestionSid) { + this.pathQuestionSid = pathQuestionSid; + } + + public InsightsQuestionnairesQuestionDeleter setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Questions/{QuestionSid}"; + + path = + path.replace( + "{" + "QuestionSid" + "}", + this.pathQuestionSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnairesQuestion delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionReader.java new file mode 100644 index 0000000000..287e5977a6 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionReader.java @@ -0,0 +1,253 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class InsightsQuestionnairesQuestionReader + extends Reader { + + private List categorySid; + private Long pageSize; + private String authorization; + + public InsightsQuestionnairesQuestionReader() {} + + public InsightsQuestionnairesQuestionReader setCategorySid( + final List categorySid + ) { + this.categorySid = categorySid; + return this; + } + + public InsightsQuestionnairesQuestionReader setCategorySid( + final String categorySid + ) { + return setCategorySid(Promoter.listOfOne(categorySid)); + } + + public InsightsQuestionnairesQuestionReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public InsightsQuestionnairesQuestionReader setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "questions", + response.getContent(), + InsightsQuestionnairesQuestion.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Questions"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "questions", + response.getContent(), + InsightsQuestionnairesQuestion.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnairesQuestion read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "questions", + response.getContent(), + InsightsQuestionnairesQuestion.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (categorySid != null) { + for (String param : categorySid) { + Serializer.toString( + request, + "CategorySid", + param, + ParameterType.QUERY + ); + } + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionUpdater.java new file mode 100644 index 0000000000..0ae1289dc3 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesQuestionUpdater.java @@ -0,0 +1,220 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsQuestionnairesQuestionUpdater + extends Updater { + + private String pathQuestionSid; + private String authorization; + private Boolean allowNa; + private String categorySid; + private String question; + private String description; + private String answerSetId; + + public InsightsQuestionnairesQuestionUpdater( + final String pathQuestionSid, + final Boolean allowNa + ) { + this.pathQuestionSid = pathQuestionSid; + this.allowNa = allowNa; + } + + public InsightsQuestionnairesQuestionUpdater setAllowNa( + final Boolean allowNa + ) { + this.allowNa = allowNa; + return this; + } + + public InsightsQuestionnairesQuestionUpdater setCategorySid( + final String categorySid + ) { + this.categorySid = categorySid; + return this; + } + + public InsightsQuestionnairesQuestionUpdater setQuestion( + final String question + ) { + this.question = question; + return this; + } + + public InsightsQuestionnairesQuestionUpdater setDescription( + final String description + ) { + this.description = description; + return this; + } + + public InsightsQuestionnairesQuestionUpdater setAnswerSetId( + final String answerSetId + ) { + this.answerSetId = answerSetId; + return this; + } + + public InsightsQuestionnairesQuestionUpdater setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Questions/{QuestionSid}"; + + path = + path.replace( + "{" + "QuestionSid" + "}", + this.pathQuestionSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnairesQuestion update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsQuestionnairesQuestion update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return InsightsQuestionnairesQuestion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsQuestionnairesQuestion content = + InsightsQuestionnairesQuestion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (allowNa != null) { + Serializer.toString( + request, + "AllowNa", + allowNa, + ParameterType.URLENCODED + ); + } + + if (categorySid != null) { + Serializer.toString( + request, + "CategorySid", + categorySid, + ParameterType.URLENCODED + ); + } + + if (question != null) { + Serializer.toString( + request, + "Question", + question, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (answerSetId != null) { + Serializer.toString( + request, + "AnswerSetId", + answerSetId, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesReader.java new file mode 100644 index 0000000000..599d4f35e9 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesReader.java @@ -0,0 +1,244 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsQuestionnairesReader + extends Reader { + + private Boolean includeInactive; + private Long pageSize; + private String authorization; + + public InsightsQuestionnairesReader() {} + + public InsightsQuestionnairesReader setIncludeInactive( + final Boolean includeInactive + ) { + this.includeInactive = includeInactive; + return this; + } + + public InsightsQuestionnairesReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public InsightsQuestionnairesReader setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "questionnaires", + response.getContent(), + InsightsQuestionnaires.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Questionnaires"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "questionnaires", + response.getContent(), + InsightsQuestionnaires.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnaires read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "questionnaires", + response.getContent(), + InsightsQuestionnaires.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (includeInactive != null) { + Serializer.toString( + request, + "IncludeInactive", + includeInactive, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesUpdater.java new file mode 100644 index 0000000000..1140691938 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsQuestionnairesUpdater.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class InsightsQuestionnairesUpdater + extends Updater { + + private String pathQuestionnaireSid; + private String authorization; + private Boolean active; + private String name; + private String description; + private List questionSids; + + public InsightsQuestionnairesUpdater( + final String pathQuestionnaireSid, + final Boolean active + ) { + this.pathQuestionnaireSid = pathQuestionnaireSid; + this.active = active; + } + + public InsightsQuestionnairesUpdater setActive(final Boolean active) { + this.active = active; + return this; + } + + public InsightsQuestionnairesUpdater setName(final String name) { + this.name = name; + return this; + } + + public InsightsQuestionnairesUpdater setDescription( + final String description + ) { + this.description = description; + return this; + } + + public InsightsQuestionnairesUpdater setQuestionSids( + final List questionSids + ) { + this.questionSids = questionSids; + return this; + } + + public InsightsQuestionnairesUpdater setQuestionSids( + final String questionSids + ) { + return setQuestionSids(Promoter.listOfOne(questionSids)); + } + + public InsightsQuestionnairesUpdater setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Insights/QualityManagement/Questionnaires/{QuestionnaireSid}"; + + path = + path.replace( + "{" + "QuestionnaireSid" + "}", + this.pathQuestionnaireSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsQuestionnaires update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsQuestionnaires update(final TwilioRestClient client) { + Response response = makeRequest(client); + return InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsQuestionnaires content = InsightsQuestionnaires.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (active != null) { + Serializer.toString( + request, + "Active", + active, + ParameterType.URLENCODED + ); + } + + if (name != null) { + Serializer.toString( + request, + "Name", + name, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (questionSids != null) { + for (String param : questionSids) { + Serializer.toString( + request, + "QuestionSids", + param, + ParameterType.URLENCODED + ); + } + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegments.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegments.java new file mode 100644 index 0000000000..dbcefd53e3 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegments.java @@ -0,0 +1,297 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsSegments extends Resource { + + public static InsightsSegmentsReader reader() { + return new InsightsSegmentsReader(); + } + + /** + * Converts a JSON String into a InsightsSegments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsSegments object represented by the provided JSON + */ + public static InsightsSegments fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsSegments.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsSegments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsSegments object represented by the provided JSON + */ + public static InsightsSegments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsSegments.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountId; + + @Getter + private final String agentId; + + @Getter + private final String agentLink; + + @Getter + private final String agentName; + + @Getter + private final String agentPhone; + + @Getter + private final String agentTeamName; + + @Getter + private final String agentTeamNameInHierarchy; + + @Getter + private final Object assessmentPercentage; + + @Getter + private final Object assessmentType; + + @Getter + private final String customerLink; + + @Getter + private final String customerName; + + @Getter + private final String customerPhone; + + @Getter + private final String date; + + @Getter + private final String externalContact; + + @Getter + private final String externalId; + + @Getter + private final String externalSegmentLink; + + @Getter + private final String externalSegmentLinkId; + + @Getter + private final Object media; + + @Getter + private final String queue; + + @Getter + private final String segmentId; + + @Getter + private final String segmentRecordingOffset; + + @Getter + private final URI url; + + @JsonCreator + private InsightsSegments( + @JsonProperty("account_id") final String accountId, + @JsonProperty("agent_id") final String agentId, + @JsonProperty("agent_link") final String agentLink, + @JsonProperty("agent_name") final String agentName, + @JsonProperty("agent_phone") final String agentPhone, + @JsonProperty("agent_team_name") final String agentTeamName, + @JsonProperty( + "agent_team_name_in_hierarchy" + ) final String agentTeamNameInHierarchy, + @JsonProperty( + "assessment_percentage" + ) final Object assessmentPercentage, + @JsonProperty("assessment_type") final Object assessmentType, + @JsonProperty("customer_link") final String customerLink, + @JsonProperty("customer_name") final String customerName, + @JsonProperty("customer_phone") final String customerPhone, + @JsonProperty("date") final String date, + @JsonProperty("external_contact") final String externalContact, + @JsonProperty("external_id") final String externalId, + @JsonProperty("external_segment_link") final String externalSegmentLink, + @JsonProperty( + "external_segment_link_id" + ) final String externalSegmentLinkId, + @JsonProperty("media") final Object media, + @JsonProperty("queue") final String queue, + @JsonProperty("segment_id") final String segmentId, + @JsonProperty( + "segment_recording_offset" + ) final String segmentRecordingOffset, + @JsonProperty("url") final URI url + ) { + this.accountId = accountId; + this.agentId = agentId; + this.agentLink = agentLink; + this.agentName = agentName; + this.agentPhone = agentPhone; + this.agentTeamName = agentTeamName; + this.agentTeamNameInHierarchy = agentTeamNameInHierarchy; + this.assessmentPercentage = assessmentPercentage; + this.assessmentType = assessmentType; + this.customerLink = customerLink; + this.customerName = customerName; + this.customerPhone = customerPhone; + this.date = date; + this.externalContact = externalContact; + this.externalId = externalId; + this.externalSegmentLink = externalSegmentLink; + this.externalSegmentLinkId = externalSegmentLinkId; + this.media = media; + this.queue = queue; + this.segmentId = segmentId; + this.segmentRecordingOffset = segmentRecordingOffset; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsSegments other = (InsightsSegments) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(agentId, other.agentId) && + Objects.equals(agentLink, other.agentLink) && + Objects.equals(agentName, other.agentName) && + Objects.equals(agentPhone, other.agentPhone) && + Objects.equals(agentTeamName, other.agentTeamName) && + Objects.equals( + agentTeamNameInHierarchy, + other.agentTeamNameInHierarchy + ) && + Objects.equals(assessmentPercentage, other.assessmentPercentage) && + Objects.equals(assessmentType, other.assessmentType) && + Objects.equals(customerLink, other.customerLink) && + Objects.equals(customerName, other.customerName) && + Objects.equals(customerPhone, other.customerPhone) && + Objects.equals(date, other.date) && + Objects.equals(externalContact, other.externalContact) && + Objects.equals(externalId, other.externalId) && + Objects.equals(externalSegmentLink, other.externalSegmentLink) && + Objects.equals( + externalSegmentLinkId, + other.externalSegmentLinkId + ) && + Objects.equals(media, other.media) && + Objects.equals(queue, other.queue) && + Objects.equals(segmentId, other.segmentId) && + Objects.equals( + segmentRecordingOffset, + other.segmentRecordingOffset + ) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + agentId, + agentLink, + agentName, + agentPhone, + agentTeamName, + agentTeamNameInHierarchy, + assessmentPercentage, + assessmentType, + customerLink, + customerName, + customerPhone, + date, + externalContact, + externalId, + externalSegmentLink, + externalSegmentLinkId, + media, + queue, + segmentId, + segmentRecordingOffset, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegmentsReader.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegmentsReader.java new file mode 100644 index 0000000000..0597af1116 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSegmentsReader.java @@ -0,0 +1,260 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class InsightsSegmentsReader extends Reader { + + private String segmentId; + private List reservationId; + private Long pageSize; + private String authorization; + + public InsightsSegmentsReader() {} + + public InsightsSegmentsReader setSegmentId(final String segmentId) { + this.segmentId = segmentId; + return this; + } + + public InsightsSegmentsReader setReservationId( + final List reservationId + ) { + this.reservationId = reservationId; + return this; + } + + public InsightsSegmentsReader setReservationId(final String reservationId) { + return setReservationId(Promoter.listOfOne(reservationId)); + } + + public InsightsSegmentsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public InsightsSegmentsReader setAuthorization(final String authorization) { + this.authorization = authorization; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "segments", + response.getContent(), + InsightsSegments.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Insights/Segments"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "segments", + response.getContent(), + InsightsSegments.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InsightsSegments read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "segments", + response.getContent(), + InsightsSegments.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (segmentId != null) { + Serializer.toString( + request, + "SegmentId", + segmentId, + ParameterType.QUERY + ); + } + + if (reservationId != null) { + for (String param : reservationId) { + Serializer.toString( + request, + "ReservationId", + param, + ParameterType.QUERY + ); + } + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSession.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSession.java new file mode 100644 index 0000000000..8d0fbed33f --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSession.java @@ -0,0 +1,161 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsSession extends Resource { + + public static InsightsSessionCreator creator() { + return new InsightsSessionCreator(); + } + + /** + * Converts a JSON String into a InsightsSession object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsSession object represented by the provided JSON + */ + public static InsightsSession fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsSession.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsSession object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsSession object represented by the provided JSON + */ + public static InsightsSession fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsSession.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String baseUrl; + + @Getter + private final String sessionExpiry; + + @Getter + private final String sessionId; + + @Getter + private final URI url; + + @Getter + private final String workspaceId; + + @JsonCreator + private InsightsSession( + @JsonProperty("base_url") final String baseUrl, + @JsonProperty("session_expiry") final String sessionExpiry, + @JsonProperty("session_id") final String sessionId, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_id") final String workspaceId + ) { + this.baseUrl = baseUrl; + this.sessionExpiry = sessionExpiry; + this.sessionId = sessionId; + this.url = url; + this.workspaceId = workspaceId; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsSession other = (InsightsSession) o; + return ( + Objects.equals(baseUrl, other.baseUrl) && + Objects.equals(sessionExpiry, other.sessionExpiry) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(url, other.url) && + Objects.equals(workspaceId, other.workspaceId) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + baseUrl, + sessionExpiry, + sessionId, + url, + workspaceId + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSessionCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSessionCreator.java new file mode 100644 index 0000000000..6ae73952ce --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSessionCreator.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsSessionCreator extends Creator { + + private String authorization; + + public InsightsSessionCreator() {} + + public InsightsSessionCreator setAuthorization(final String authorization) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/Session"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsSession creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsSession create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InsightsSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsSession content = InsightsSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSets.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSets.java new file mode 100644 index 0000000000..0d4f5db287 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSets.java @@ -0,0 +1,167 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsSettingsAnswerSets extends Resource { + + public static InsightsSettingsAnswerSetsFetcher fetcher() { + return new InsightsSettingsAnswerSetsFetcher(); + } + + /** + * Converts a JSON String into a InsightsSettingsAnswerSets object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsSettingsAnswerSets object represented by the provided JSON + */ + public static InsightsSettingsAnswerSets fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InsightsSettingsAnswerSets.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsSettingsAnswerSets object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsSettingsAnswerSets object represented by the provided JSON + */ + public static InsightsSettingsAnswerSets fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InsightsSettingsAnswerSets.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object answerSetCategories; + + @Getter + private final Object answerSets; + + @Getter + private final Object notApplicable; + + @Getter + private final URI url; + + @JsonCreator + private InsightsSettingsAnswerSets( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("answer_set_categories") final Object answerSetCategories, + @JsonProperty("answer_sets") final Object answerSets, + @JsonProperty("not_applicable") final Object notApplicable, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.answerSetCategories = answerSetCategories; + this.answerSets = answerSets; + this.notApplicable = notApplicable; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsSettingsAnswerSets other = (InsightsSettingsAnswerSets) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(answerSetCategories, other.answerSetCategories) && + Objects.equals(answerSets, other.answerSets) && + Objects.equals(notApplicable, other.notApplicable) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + answerSetCategories, + answerSets, + notApplicable, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSetsFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSetsFetcher.java new file mode 100644 index 0000000000..dff43cab34 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsAnswerSetsFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsSettingsAnswerSetsFetcher + extends Fetcher { + + private String authorization; + + public InsightsSettingsAnswerSetsFetcher() {} + + public InsightsSettingsAnswerSetsFetcher setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Settings/AnswerSets"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsSettingsAnswerSets fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsSettingsAnswerSets fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InsightsSettingsAnswerSets.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsSettingsAnswerSets content = + InsightsSettingsAnswerSets.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsComment.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsComment.java new file mode 100644 index 0000000000..68a11dad9b --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsComment.java @@ -0,0 +1,143 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsSettingsComment extends Resource { + + public static InsightsSettingsCommentFetcher fetcher() { + return new InsightsSettingsCommentFetcher(); + } + + /** + * Converts a JSON String into a InsightsSettingsComment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsSettingsComment object represented by the provided JSON + */ + public static InsightsSettingsComment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsSettingsComment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsSettingsComment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsSettingsComment object represented by the provided JSON + */ + public static InsightsSettingsComment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsSettingsComment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object comments; + + @Getter + private final URI url; + + @JsonCreator + private InsightsSettingsComment( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("comments") final Object comments, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.comments = comments; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsSettingsComment other = (InsightsSettingsComment) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(comments, other.comments) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, comments, url); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsCommentFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsCommentFetcher.java new file mode 100644 index 0000000000..c18b36f9f5 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsSettingsCommentFetcher.java @@ -0,0 +1,114 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsSettingsCommentFetcher + extends Fetcher { + + private String authorization; + + public InsightsSettingsCommentFetcher() {} + + public InsightsSettingsCommentFetcher setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/QualityManagement/Settings/CommentTags"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsSettingsComment fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsSettingsComment fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InsightsSettingsComment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsSettingsComment content = InsightsSettingsComment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRoles.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRoles.java new file mode 100644 index 0000000000..e877828be2 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRoles.java @@ -0,0 +1,137 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InsightsUserRoles extends Resource { + + public static InsightsUserRolesFetcher fetcher() { + return new InsightsUserRolesFetcher(); + } + + /** + * Converts a JSON String into a InsightsUserRoles object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InsightsUserRoles object represented by the provided JSON + */ + public static InsightsUserRoles fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsUserRoles.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InsightsUserRoles object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InsightsUserRoles object represented by the provided JSON + */ + public static InsightsUserRoles fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InsightsUserRoles.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List roles; + + @Getter + private final URI url; + + @JsonCreator + private InsightsUserRoles( + @JsonProperty("roles") final List roles, + @JsonProperty("url") final URI url + ) { + this.roles = roles; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsUserRoles other = (InsightsUserRoles) o; + return ( + Objects.equals(roles, other.roles) && Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(roles, url); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRolesFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRolesFetcher.java new file mode 100644 index 0000000000..8f1769395d --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InsightsUserRolesFetcher.java @@ -0,0 +1,113 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InsightsUserRolesFetcher extends Fetcher { + + private String authorization; + + public InsightsUserRolesFetcher() {} + + public InsightsUserRolesFetcher setAuthorization( + final String authorization + ) { + this.authorization = authorization; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Insights/UserRoles"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InsightsUserRoles fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InsightsUserRoles fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InsightsUserRoles.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InsightsUserRoles content = InsightsUserRoles.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (authorization != null) { + Serializer.toString( + request, + "Authorization", + authorization, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Interaction.java b/src/main/java/com/twilio/rest/flexapi/v1/Interaction.java new file mode 100644 index 0000000000..7a57afd515 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/Interaction.java @@ -0,0 +1,189 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Interaction extends Resource { + + public static InteractionCreator creator(final Object channel) { + return new InteractionCreator(channel); + } + + public static InteractionFetcher fetcher(final String pathSid) { + return new InteractionFetcher(pathSid); + } + + public static InteractionUpdater updater(final String pathSid) { + return new InteractionUpdater(pathSid); + } + + /** + * Converts a JSON String into a Interaction object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Interaction object represented by the provided JSON + */ + public static Interaction fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Interaction.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Interaction object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Interaction object represented by the provided JSON + */ + public static Interaction fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Interaction.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object channel; + + @Getter + private final String interactionContextSid; + + @Getter + private final Map links; + + @Getter + private final Object routing; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final String webhookTtid; + + @JsonCreator + private Interaction( + @JsonProperty("channel") final Object channel, + @JsonProperty( + "interaction_context_sid" + ) final String interactionContextSid, + @JsonProperty("links") final Map links, + @JsonProperty("routing") final Object routing, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_ttid") final String webhookTtid + ) { + this.channel = channel; + this.interactionContextSid = interactionContextSid; + this.links = links; + this.routing = routing; + this.sid = sid; + this.url = url; + this.webhookTtid = webhookTtid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Interaction other = (Interaction) o; + return ( + Objects.equals(channel, other.channel) && + Objects.equals( + interactionContextSid, + other.interactionContextSid + ) && + Objects.equals(links, other.links) && + Objects.equals(routing, other.routing) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(webhookTtid, other.webhookTtid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + channel, + interactionContextSid, + links, + routing, + sid, + url, + webhookTtid + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InteractionCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/InteractionCreator.java new file mode 100644 index 0000000000..62eea596fd --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InteractionCreator.java @@ -0,0 +1,162 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionCreator extends Creator { + + private Object channel; + private Object routing; + private String interactionContextSid; + private String webhookTtid; + + public InteractionCreator(final Object channel) { + this.channel = channel; + } + + public InteractionCreator setChannel(final Object channel) { + this.channel = channel; + return this; + } + + public InteractionCreator setRouting(final Object routing) { + this.routing = routing; + return this; + } + + public InteractionCreator setInteractionContextSid( + final String interactionContextSid + ) { + this.interactionContextSid = interactionContextSid; + return this; + } + + public InteractionCreator setWebhookTtid(final String webhookTtid) { + this.webhookTtid = webhookTtid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Interactions"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Interaction creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Interaction create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Interaction content = Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (channel != null) { + Serializer.toString( + request, + "Channel", + channel, + ParameterType.URLENCODED + ); + } + + if (routing != null) { + Serializer.toString( + request, + "Routing", + routing, + ParameterType.URLENCODED + ); + } + + if (interactionContextSid != null) { + Serializer.toString( + request, + "InteractionContextSid", + interactionContextSid, + ParameterType.URLENCODED + ); + } + + if (webhookTtid != null) { + Serializer.toString( + request, + "WebhookTtid", + webhookTtid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InteractionFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/InteractionFetcher.java new file mode 100644 index 0000000000..2b1df1be6b --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InteractionFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionFetcher extends Fetcher { + + private String pathSid; + + public InteractionFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Interactions/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Interaction fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Interaction fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Interaction content = Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/InteractionUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/InteractionUpdater.java new file mode 100644 index 0000000000..63ea3106bd --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/InteractionUpdater.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionUpdater extends Updater { + + private String pathSid; + private String webhookTtid; + + public InteractionUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public InteractionUpdater setWebhookTtid(final String webhookTtid) { + this.webhookTtid = webhookTtid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Interactions/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Interaction update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Interaction update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Interaction content = Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (webhookTtid != null) { + Serializer.toString( + request, + "WebhookTtid", + webhookTtid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/Plugin.java b/src/main/java/com/twilio/rest/flexapi/v1/Plugin.java new file mode 100644 index 0000000000..b34ae52904 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/Plugin.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Plugin extends Resource { + + public static PluginCreator creator(final String uniqueName) { + return new PluginCreator(uniqueName); + } + + public static PluginFetcher fetcher(final String pathSid) { + return new PluginFetcher(pathSid); + } + + public static PluginReader reader() { + return new PluginReader(); + } + + public static PluginUpdater updater(final String pathSid) { + return new PluginUpdater(pathSid); + } + + /** + * Converts a JSON String into a Plugin object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Plugin object represented by the provided JSON + */ + public static Plugin fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Plugin.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Plugin object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Plugin object represented by the provided JSON + */ + public static Plugin fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Plugin.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean archived; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private Plugin( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("archived") final Boolean archived, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.archived = archived; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.friendlyName = friendlyName; + this.links = links; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Plugin other = (Plugin) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(archived, other.archived) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + archived, + dateCreated, + dateUpdated, + description, + friendlyName, + links, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginArchive.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginArchive.java new file mode 100644 index 0000000000..ea961673b8 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginArchive.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PluginArchive extends Resource { + + public static PluginArchiveUpdater updater(final String pathSid) { + return new PluginArchiveUpdater(pathSid); + } + + /** + * Converts a JSON String into a PluginArchive object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PluginArchive object represented by the provided JSON + */ + public static PluginArchive fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginArchive.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PluginArchive object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PluginArchive object represented by the provided JSON + */ + public static PluginArchive fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginArchive.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean archived; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private PluginArchive( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("archived") final Boolean archived, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.archived = archived; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.friendlyName = friendlyName; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PluginArchive other = (PluginArchive) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(archived, other.archived) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + archived, + dateCreated, + dateUpdated, + description, + friendlyName, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginArchiveUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginArchiveUpdater.java new file mode 100644 index 0000000000..867b3f6168 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginArchiveUpdater.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginArchiveUpdater extends Updater { + + private String pathSid; + private String flexMetadata; + + public PluginArchiveUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public PluginArchiveUpdater setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Plugins/{Sid}/Archive"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginArchive update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginArchive update(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginArchive.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginArchive content = PluginArchive.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginConfiguration.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfiguration.java new file mode 100644 index 0000000000..7b3afc72db --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfiguration.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PluginConfiguration extends Resource { + + public static PluginConfigurationCreator creator(final String name) { + return new PluginConfigurationCreator(name); + } + + public static PluginConfigurationFetcher fetcher(final String pathSid) { + return new PluginConfigurationFetcher(pathSid); + } + + public static PluginConfigurationReader reader() { + return new PluginConfigurationReader(); + } + + /** + * Converts a JSON String into a PluginConfiguration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PluginConfiguration object represented by the provided JSON + */ + public static PluginConfiguration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginConfiguration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PluginConfiguration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PluginConfiguration object represented by the provided JSON + */ + public static PluginConfiguration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginConfiguration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean archived; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String description; + + @Getter + private final Map links; + + @Getter + private final String name; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private PluginConfiguration( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("archived") final Boolean archived, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("description") final String description, + @JsonProperty("links") final Map links, + @JsonProperty("name") final String name, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.archived = archived; + this.dateCreated = dateCreated; + this.description = description; + this.links = links; + this.name = name; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PluginConfiguration other = (PluginConfiguration) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(archived, other.archived) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(description, other.description) && + Objects.equals(links, other.links) && + Objects.equals(name, other.name) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + archived, + dateCreated, + description, + links, + name, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationArchive.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationArchive.java new file mode 100644 index 0000000000..6d2577f46a --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationArchive.java @@ -0,0 +1,191 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PluginConfigurationArchive extends Resource { + + public static PluginConfigurationArchiveUpdater updater( + final String pathSid + ) { + return new PluginConfigurationArchiveUpdater(pathSid); + } + + /** + * Converts a JSON String into a PluginConfigurationArchive object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PluginConfigurationArchive object represented by the provided JSON + */ + public static PluginConfigurationArchive fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PluginConfigurationArchive.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PluginConfigurationArchive object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PluginConfigurationArchive object represented by the provided JSON + */ + public static PluginConfigurationArchive fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PluginConfigurationArchive.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean archived; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String description; + + @Getter + private final String name; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private PluginConfigurationArchive( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("archived") final Boolean archived, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("description") final String description, + @JsonProperty("name") final String name, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.archived = archived; + this.dateCreated = dateCreated; + this.description = description; + this.name = name; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PluginConfigurationArchive other = (PluginConfigurationArchive) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(archived, other.archived) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(description, other.description) && + Objects.equals(name, other.name) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + archived, + dateCreated, + description, + name, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationArchiveUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationArchiveUpdater.java new file mode 100644 index 0000000000..7274b1dd3a --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationArchiveUpdater.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginConfigurationArchiveUpdater + extends Updater { + + private String pathSid; + private String flexMetadata; + + public PluginConfigurationArchiveUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public PluginConfigurationArchiveUpdater setFlexMetadata( + final String flexMetadata + ) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Configurations/{Sid}/Archive"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginConfigurationArchive update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginConfigurationArchive update(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginConfigurationArchive.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginConfigurationArchive content = + PluginConfigurationArchive.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationCreator.java new file mode 100644 index 0000000000..3a15f9763c --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationCreator.java @@ -0,0 +1,173 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class PluginConfigurationCreator extends Creator { + + private String flexMetadata; + private String name; + private List plugins; + private String description; + + public PluginConfigurationCreator(final String name) { + this.name = name; + } + + public PluginConfigurationCreator setName(final String name) { + this.name = name; + return this; + } + + public PluginConfigurationCreator setPlugins(final List plugins) { + this.plugins = plugins; + return this; + } + + public PluginConfigurationCreator setPlugins(final Object plugins) { + return setPlugins(Promoter.listOfOne(plugins)); + } + + public PluginConfigurationCreator setDescription(final String description) { + this.description = description; + return this; + } + + public PluginConfigurationCreator setFlexMetadata( + final String flexMetadata + ) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Configurations"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginConfiguration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginConfiguration create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginConfiguration content = PluginConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (name != null) { + Serializer.toString( + request, + "Name", + name, + ParameterType.URLENCODED + ); + } + + if (plugins != null) { + for (Object param : plugins) { + Serializer.toString( + request, + "Plugins", + param, + ParameterType.URLENCODED + ); + } + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationFetcher.java new file mode 100644 index 0000000000..a4d1a0ba4e --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationFetcher.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginConfigurationFetcher extends Fetcher { + + private String pathSid; + private String flexMetadata; + + public PluginConfigurationFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + public PluginConfigurationFetcher setFlexMetadata( + final String flexMetadata + ) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Configurations/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginConfiguration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginConfiguration fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginConfiguration content = PluginConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationReader.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationReader.java new file mode 100644 index 0000000000..4b934ca622 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginConfigurationReader.java @@ -0,0 +1,224 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginConfigurationReader extends Reader { + + private Long pageSize; + private String flexMetadata; + + public PluginConfigurationReader() {} + + public PluginConfigurationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public PluginConfigurationReader setFlexMetadata( + final String flexMetadata + ) { + this.flexMetadata = flexMetadata; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "configurations", + response.getContent(), + PluginConfiguration.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Configurations"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "configurations", + response.getContent(), + PluginConfiguration.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PluginConfiguration read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "configurations", + response.getContent(), + PluginConfiguration.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginCreator.java new file mode 100644 index 0000000000..7ebb978030 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginCreator.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginCreator extends Creator { + + private String flexMetadata; + private String uniqueName; + private String friendlyName; + private String description; + + public PluginCreator(final String uniqueName) { + this.uniqueName = uniqueName; + } + + public PluginCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public PluginCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public PluginCreator setDescription(final String description) { + this.description = description; + return this; + } + + public PluginCreator setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Plugins"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Plugin creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Plugin create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Plugin.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Plugin content = Plugin.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginFetcher.java new file mode 100644 index 0000000000..5792bcf482 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginFetcher.java @@ -0,0 +1,113 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginFetcher extends Fetcher { + + private String pathSid; + private String flexMetadata; + + public PluginFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + public PluginFetcher setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Plugins/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Plugin fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Plugin fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Plugin.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Plugin content = Plugin.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginReader.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginReader.java new file mode 100644 index 0000000000..1653b3be89 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginReader.java @@ -0,0 +1,216 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginReader extends Reader { + + private Long pageSize; + private String flexMetadata; + + public PluginReader() {} + + public PluginReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public PluginReader setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "plugins", + response.getContent(), + Plugin.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Plugins"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "plugins", + response.getContent(), + Plugin.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Plugin read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "plugins", + response.getContent(), + Plugin.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginRelease.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginRelease.java new file mode 100644 index 0000000000..0df94aabb9 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginRelease.java @@ -0,0 +1,177 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PluginRelease extends Resource { + + public static PluginReleaseCreator creator(final String configurationId) { + return new PluginReleaseCreator(configurationId); + } + + public static PluginReleaseFetcher fetcher(final String pathSid) { + return new PluginReleaseFetcher(pathSid); + } + + public static PluginReleaseReader reader() { + return new PluginReleaseReader(); + } + + /** + * Converts a JSON String into a PluginRelease object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PluginRelease object represented by the provided JSON + */ + public static PluginRelease fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginRelease.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PluginRelease object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PluginRelease object represented by the provided JSON + */ + public static PluginRelease fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginRelease.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String configurationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private PluginRelease( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("configuration_sid") final String configurationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.configurationSid = configurationSid; + this.dateCreated = dateCreated; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PluginRelease other = (PluginRelease) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(configurationSid, other.configurationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + configurationSid, + dateCreated, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseCreator.java new file mode 100644 index 0000000000..22731832f5 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseCreator.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginReleaseCreator extends Creator { + + private String flexMetadata; + private String configurationId; + + public PluginReleaseCreator(final String configurationId) { + this.configurationId = configurationId; + } + + public PluginReleaseCreator setConfigurationId( + final String configurationId + ) { + this.configurationId = configurationId; + return this; + } + + public PluginReleaseCreator setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Releases"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginRelease creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginRelease create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginRelease.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginRelease content = PluginRelease.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (configurationId != null) { + Serializer.toString( + request, + "ConfigurationId", + configurationId, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseFetcher.java new file mode 100644 index 0000000000..0ac85d1934 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseFetcher.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginReleaseFetcher extends Fetcher { + + private String pathSid; + private String flexMetadata; + + public PluginReleaseFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + public PluginReleaseFetcher setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Releases/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginRelease fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginRelease fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginRelease.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginRelease content = PluginRelease.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseReader.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseReader.java new file mode 100644 index 0000000000..73a724be83 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginReleaseReader.java @@ -0,0 +1,220 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginReleaseReader extends Reader { + + private Long pageSize; + private String flexMetadata; + + public PluginReleaseReader() {} + + public PluginReleaseReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public PluginReleaseReader setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "releases", + response.getContent(), + PluginRelease.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Releases"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "releases", + response.getContent(), + PluginRelease.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PluginRelease read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "releases", + response.getContent(), + PluginRelease.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginUpdater.java new file mode 100644 index 0000000000..3fff051ace --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginUpdater.java @@ -0,0 +1,148 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginUpdater extends Updater { + + private String pathSid; + private String flexMetadata; + private String friendlyName; + private String description; + + public PluginUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public PluginUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public PluginUpdater setDescription(final String description) { + this.description = description; + return this; + } + + public PluginUpdater setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Plugins/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Plugin update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Plugin update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Plugin.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Plugin content = Plugin.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginVersionArchive.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginVersionArchive.java new file mode 100644 index 0000000000..ccc553d2db --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginVersionArchive.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PluginVersionArchive extends Resource { + + public static PluginVersionArchiveUpdater updater( + final String pathPluginSid, + final String pathSid + ) { + return new PluginVersionArchiveUpdater(pathPluginSid, pathSid); + } + + /** + * Converts a JSON String into a PluginVersionArchive object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PluginVersionArchive object represented by the provided JSON + */ + public static PluginVersionArchive fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginVersionArchive.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PluginVersionArchive object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PluginVersionArchive object represented by the provided JSON + */ + public static PluginVersionArchive fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginVersionArchive.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean archived; + + @Getter + private final String changelog; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String pluginSid; + + @Getter + private final URI pluginUrl; + + @Getter + private final Boolean _private; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final String version; + + @JsonCreator + private PluginVersionArchive( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("archived") final Boolean archived, + @JsonProperty("changelog") final String changelog, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("plugin_sid") final String pluginSid, + @JsonProperty("plugin_url") final URI pluginUrl, + @JsonProperty("private") final Boolean _private, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("version") final String version + ) { + this.accountSid = accountSid; + this.archived = archived; + this.changelog = changelog; + this.dateCreated = dateCreated; + this.pluginSid = pluginSid; + this.pluginUrl = pluginUrl; + this._private = _private; + this.sid = sid; + this.url = url; + this.version = version; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PluginVersionArchive other = (PluginVersionArchive) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(archived, other.archived) && + Objects.equals(changelog, other.changelog) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(pluginSid, other.pluginSid) && + Objects.equals(pluginUrl, other.pluginUrl) && + Objects.equals(_private, other._private) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + archived, + changelog, + dateCreated, + pluginSid, + pluginUrl, + _private, + sid, + url, + version + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/PluginVersionArchiveUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/PluginVersionArchiveUpdater.java new file mode 100644 index 0000000000..3ff241ba2a --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/PluginVersionArchiveUpdater.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginVersionArchiveUpdater extends Updater { + + private String pathPluginSid; + private String pathSid; + private String flexMetadata; + + public PluginVersionArchiveUpdater( + final String pathPluginSid, + final String pathSid + ) { + this.pathPluginSid = pathPluginSid; + this.pathSid = pathSid; + } + + public PluginVersionArchiveUpdater setFlexMetadata( + final String flexMetadata + ) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/PluginService/Plugins/{PluginSid}/Versions/{Sid}/Archive"; + + path = + path.replace( + "{" + "PluginSid" + "}", + this.pathPluginSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginVersionArchive update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginVersionArchive update(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginVersionArchive.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginVersionArchive content = PluginVersionArchive.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ProvisioningStatus.java b/src/main/java/com/twilio/rest/flexapi/v1/ProvisioningStatus.java new file mode 100644 index 0000000000..8fe7015815 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/ProvisioningStatus.java @@ -0,0 +1,162 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ProvisioningStatus extends Resource { + + public static ProvisioningStatusFetcher fetcher() { + return new ProvisioningStatusFetcher(); + } + + public enum Status { + ACTIVE("active"), + IN_PROGRESS("in-progress"), + NOT_CONFIGURED("not-configured"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a ProvisioningStatus object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ProvisioningStatus object represented by the provided JSON + */ + public static ProvisioningStatus fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ProvisioningStatus.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ProvisioningStatus object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ProvisioningStatus object represented by the provided JSON + */ + public static ProvisioningStatus fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ProvisioningStatus.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final ProvisioningStatus.Status status; + + @Getter + private final URI url; + + @JsonCreator + private ProvisioningStatus( + @JsonProperty("status") final ProvisioningStatus.Status status, + @JsonProperty("url") final URI url + ) { + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ProvisioningStatus other = (ProvisioningStatus) o; + return ( + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(status, url); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/ProvisioningStatusFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/ProvisioningStatusFetcher.java new file mode 100644 index 0000000000..bbb8cf82f6 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/ProvisioningStatusFetcher.java @@ -0,0 +1,90 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ProvisioningStatusFetcher extends Fetcher { + + public ProvisioningStatusFetcher() {} + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/account/provision/status"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ProvisioningStatus fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ProvisioningStatus fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ProvisioningStatus.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ProvisioningStatus content = ProvisioningStatus.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannel.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannel.java new file mode 100644 index 0000000000..e65122396e --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannel.java @@ -0,0 +1,229 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class WebChannel extends Resource { + + public static WebChannelCreator creator( + final String flexFlowSid, + final String identity, + final String customerFriendlyName, + final String chatFriendlyName + ) { + return new WebChannelCreator( + flexFlowSid, + identity, + customerFriendlyName, + chatFriendlyName + ); + } + + public static WebChannelDeleter deleter(final String pathSid) { + return new WebChannelDeleter(pathSid); + } + + public static WebChannelFetcher fetcher(final String pathSid) { + return new WebChannelFetcher(pathSid); + } + + public static WebChannelReader reader() { + return new WebChannelReader(); + } + + public static WebChannelUpdater updater(final String pathSid) { + return new WebChannelUpdater(pathSid); + } + + public enum ChatStatus { + INACTIVE("inactive"); + + private final String value; + + private ChatStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ChatStatus forValue(final String value) { + return Promoter.enumFromString(value, ChatStatus.values()); + } + } + + /** + * Converts a JSON String into a WebChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WebChannel object represented by the provided JSON + */ + public static WebChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, WebChannel.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a WebChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WebChannel object represented by the provided JSON + */ + public static WebChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, WebChannel.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String flexFlowSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private WebChannel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("flex_flow_sid") final String flexFlowSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.flexFlowSid = flexFlowSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + WebChannel other = (WebChannel) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(flexFlowSid, other.flexFlowSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + flexFlowSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelCreator.java new file mode 100644 index 0000000000..3720fdb9cb --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelCreator.java @@ -0,0 +1,204 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebChannelCreator extends Creator { + + private String flexFlowSid; + private String identity; + private String customerFriendlyName; + private String chatFriendlyName; + private String chatUniqueName; + private String preEngagementData; + + public WebChannelCreator( + final String flexFlowSid, + final String identity, + final String customerFriendlyName, + final String chatFriendlyName + ) { + this.flexFlowSid = flexFlowSid; + this.identity = identity; + this.customerFriendlyName = customerFriendlyName; + this.chatFriendlyName = chatFriendlyName; + } + + public WebChannelCreator setFlexFlowSid(final String flexFlowSid) { + this.flexFlowSid = flexFlowSid; + return this; + } + + public WebChannelCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public WebChannelCreator setCustomerFriendlyName( + final String customerFriendlyName + ) { + this.customerFriendlyName = customerFriendlyName; + return this; + } + + public WebChannelCreator setChatFriendlyName( + final String chatFriendlyName + ) { + this.chatFriendlyName = chatFriendlyName; + return this; + } + + public WebChannelCreator setChatUniqueName(final String chatUniqueName) { + this.chatUniqueName = chatUniqueName; + return this; + } + + public WebChannelCreator setPreEngagementData( + final String preEngagementData + ) { + this.preEngagementData = preEngagementData; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/WebChannels"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "WebChannel creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public WebChannel create(final TwilioRestClient client) { + Response response = makeRequest(client); + return WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WebChannel content = WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (flexFlowSid != null) { + Serializer.toString( + request, + "FlexFlowSid", + flexFlowSid, + ParameterType.URLENCODED + ); + } + + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + + if (customerFriendlyName != null) { + Serializer.toString( + request, + "CustomerFriendlyName", + customerFriendlyName, + ParameterType.URLENCODED + ); + } + + if (chatFriendlyName != null) { + Serializer.toString( + request, + "ChatFriendlyName", + chatFriendlyName, + ParameterType.URLENCODED + ); + } + + if (chatUniqueName != null) { + Serializer.toString( + request, + "ChatUniqueName", + chatUniqueName, + ParameterType.URLENCODED + ); + } + + if (preEngagementData != null) { + Serializer.toString( + request, + "PreEngagementData", + preEngagementData, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelDeleter.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelDeleter.java new file mode 100644 index 0000000000..fc922fec3e --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class WebChannelDeleter extends Deleter { + + private String pathSid; + + public WebChannelDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/WebChannels/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "WebChannel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelFetcher.java new file mode 100644 index 0000000000..7a4edd0bcf --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebChannelFetcher extends Fetcher { + + private String pathSid; + + public WebChannelFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/WebChannels/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "WebChannel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public WebChannel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WebChannel content = WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelReader.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelReader.java new file mode 100644 index 0000000000..952d1088ca --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebChannelReader extends Reader { + + private Long pageSize; + + public WebChannelReader() {} + + public WebChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flex_chat_channels", + response.getContent(), + WebChannel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/WebChannels"; + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flex_chat_channels", + response.getContent(), + WebChannel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "WebChannel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "flex_chat_channels", + response.getContent(), + WebChannel.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/WebChannelUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelUpdater.java new file mode 100644 index 0000000000..c292546777 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/WebChannelUpdater.java @@ -0,0 +1,137 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebChannelUpdater extends Updater { + + private String pathSid; + private WebChannel.ChatStatus chatStatus; + private String postEngagementData; + + public WebChannelUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public WebChannelUpdater setChatStatus( + final WebChannel.ChatStatus chatStatus + ) { + this.chatStatus = chatStatus; + return this; + } + + public WebChannelUpdater setPostEngagementData( + final String postEngagementData + ) { + this.postEngagementData = postEngagementData; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/WebChannels/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "WebChannel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public WebChannel update(final TwilioRestClient client) { + Response response = makeRequest(client); + return WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WebChannel content = WebChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (chatStatus != null) { + Serializer.toString( + request, + "ChatStatus", + chatStatus, + ParameterType.URLENCODED + ); + } + + if (postEngagementData != null) { + Serializer.toString( + request, + "PostEngagementData", + postEngagementData, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannel.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannel.java new file mode 100644 index 0000000000..19f5ff0057 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannel.java @@ -0,0 +1,280 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InteractionChannel extends Resource { + + public static InteractionChannelFetcher fetcher( + final String pathInteractionSid, + final String pathSid + ) { + return new InteractionChannelFetcher(pathInteractionSid, pathSid); + } + + public static InteractionChannelReader reader( + final String pathInteractionSid + ) { + return new InteractionChannelReader(pathInteractionSid); + } + + public static InteractionChannelUpdater updater( + final String pathInteractionSid, + final String pathSid, + final InteractionChannel.UpdateChannelStatus status + ) { + return new InteractionChannelUpdater( + pathInteractionSid, + pathSid, + status + ); + } + + public enum Type { + VOICE("voice"), + SMS("sms"), + EMAIL("email"), + WEB("web"), + WHATSAPP("whatsapp"), + CHAT("chat"), + MESSENGER("messenger"), + GBM("gbm"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum ChannelStatus { + SETUP("setup"), + ACTIVE("active"), + FAILED("failed"), + CLOSED("closed"), + INACTIVE("inactive"), + PAUSE("pause"), + TRANSFER("transfer"); + + private final String value; + + private ChannelStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ChannelStatus forValue(final String value) { + return Promoter.enumFromString(value, ChannelStatus.values()); + } + } + + public enum UpdateChannelStatus { + CLOSED("closed"), + INACTIVE("inactive"); + + private final String value; + + private UpdateChannelStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static UpdateChannelStatus forValue(final String value) { + return Promoter.enumFromString(value, UpdateChannelStatus.values()); + } + } + + /** + * Converts a JSON String into a InteractionChannel object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannel object represented by the provided JSON + */ + public static InteractionChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InteractionChannel.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InteractionChannel object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannel object represented by the provided JSON + */ + public static InteractionChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InteractionChannel.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Integer errorCode; + + @Getter + private final String errorMessage; + + @Getter + private final String interactionSid; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final InteractionChannel.ChannelStatus status; + + @Getter + private final InteractionChannel.Type type; + + @Getter + private final URI url; + + @JsonCreator + private InteractionChannel( + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("error_message") final String errorMessage, + @JsonProperty("interaction_sid") final String interactionSid, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final InteractionChannel.ChannelStatus status, + @JsonProperty("type") final InteractionChannel.Type type, + @JsonProperty("url") final URI url + ) { + this.errorCode = errorCode; + this.errorMessage = errorMessage; + this.interactionSid = interactionSid; + this.links = links; + this.sid = sid; + this.status = status; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InteractionChannel other = (InteractionChannel) o; + return ( + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorMessage, other.errorMessage) && + Objects.equals(interactionSid, other.interactionSid) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + errorCode, + errorMessage, + interactionSid, + links, + sid, + status, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelFetcher.java new file mode 100644 index 0000000000..162c6edb34 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionChannelFetcher extends Fetcher { + + private String pathInteractionSid; + private String pathSid; + + public InteractionChannelFetcher( + final String pathInteractionSid, + final String pathSid + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Interactions/{InteractionSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InteractionChannel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InteractionChannel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InteractionChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InteractionChannel content = InteractionChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelReader.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelReader.java new file mode 100644 index 0000000000..45ae8a3c68 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionChannelReader extends Reader { + + private String pathInteractionSid; + private Long pageSize; + + public InteractionChannelReader(final String pathInteractionSid) { + this.pathInteractionSid = pathInteractionSid; + } + + public InteractionChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + InteractionChannel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Interactions/{InteractionSid}/Channels"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + InteractionChannel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InteractionChannel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + InteractionChannel.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelUpdater.java new file mode 100644 index 0000000000..23c34a88cb --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/InteractionChannelUpdater.java @@ -0,0 +1,147 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionChannelUpdater extends Updater { + + private String pathInteractionSid; + private String pathSid; + private InteractionChannel.UpdateChannelStatus status; + private Object routing; + + public InteractionChannelUpdater( + final String pathInteractionSid, + final String pathSid, + final InteractionChannel.UpdateChannelStatus status + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathSid = pathSid; + this.status = status; + } + + public InteractionChannelUpdater setStatus( + final InteractionChannel.UpdateChannelStatus status + ) { + this.status = status; + return this; + } + + public InteractionChannelUpdater setRouting(final Object routing) { + this.routing = routing; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Interactions/{InteractionSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InteractionChannel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InteractionChannel update(final TwilioRestClient client) { + Response response = makeRequest(client); + return InteractionChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InteractionChannel content = InteractionChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (routing != null) { + Serializer.toString( + request, + "Routing", + routing, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInvite.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInvite.java new file mode 100644 index 0000000000..3549ec67b3 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInvite.java @@ -0,0 +1,173 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InteractionChannelInvite extends Resource { + + public static InteractionChannelInviteCreator creator( + final String pathInteractionSid, + final String pathChannelSid, + final Object routing + ) { + return new InteractionChannelInviteCreator( + pathInteractionSid, + pathChannelSid, + routing + ); + } + + public static InteractionChannelInviteReader reader( + final String pathInteractionSid, + final String pathChannelSid + ) { + return new InteractionChannelInviteReader( + pathInteractionSid, + pathChannelSid + ); + } + + /** + * Converts a JSON String into a InteractionChannelInvite object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannelInvite object represented by the provided JSON + */ + public static InteractionChannelInvite fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InteractionChannelInvite.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InteractionChannelInvite object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannelInvite object represented by the provided JSON + */ + public static InteractionChannelInvite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InteractionChannelInvite.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String channelSid; + + @Getter + private final String interactionSid; + + @Getter + private final Object routing; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private InteractionChannelInvite( + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("interaction_sid") final String interactionSid, + @JsonProperty("routing") final Object routing, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.channelSid = channelSid; + this.interactionSid = interactionSid; + this.routing = routing; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InteractionChannelInvite other = (InteractionChannelInvite) o; + return ( + Objects.equals(channelSid, other.channelSid) && + Objects.equals(interactionSid, other.interactionSid) && + Objects.equals(routing, other.routing) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(channelSid, interactionSid, routing, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteCreator.java new file mode 100644 index 0000000000..6be65af399 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteCreator.java @@ -0,0 +1,136 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionChannelInviteCreator + extends Creator { + + private String pathInteractionSid; + private String pathChannelSid; + private Object routing; + + public InteractionChannelInviteCreator( + final String pathInteractionSid, + final String pathChannelSid, + final Object routing + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathChannelSid = pathChannelSid; + this.routing = routing; + } + + public InteractionChannelInviteCreator setRouting(final Object routing) { + this.routing = routing; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InteractionChannelInvite creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InteractionChannelInvite create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InteractionChannelInvite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InteractionChannelInvite content = InteractionChannelInvite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (routing != null) { + Serializer.toString( + request, + "Routing", + routing, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteReader.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteReader.java new file mode 100644 index 0000000000..ebb5c58c25 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelInviteReader.java @@ -0,0 +1,227 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionChannelInviteReader + extends Reader { + + private String pathInteractionSid; + private String pathChannelSid; + private Long pageSize; + + public InteractionChannelInviteReader( + final String pathInteractionSid, + final String pathChannelSid + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathChannelSid = pathChannelSid; + } + + public InteractionChannelInviteReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + InteractionChannelInvite.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + InteractionChannelInvite.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InteractionChannelInvite read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "invites", + response.getContent(), + InteractionChannelInvite.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipant.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipant.java new file mode 100644 index 0000000000..79feb15320 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipant.java @@ -0,0 +1,255 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InteractionChannelParticipant extends Resource { + + public static InteractionChannelParticipantCreator creator( + final String pathInteractionSid, + final String pathChannelSid, + final InteractionChannelParticipant.Type type, + final Object mediaProperties + ) { + return new InteractionChannelParticipantCreator( + pathInteractionSid, + pathChannelSid, + type, + mediaProperties + ); + } + + public static InteractionChannelParticipantReader reader( + final String pathInteractionSid, + final String pathChannelSid + ) { + return new InteractionChannelParticipantReader( + pathInteractionSid, + pathChannelSid + ); + } + + public static InteractionChannelParticipantUpdater updater( + final String pathInteractionSid, + final String pathChannelSid, + final String pathSid, + final InteractionChannelParticipant.Status status + ) { + return new InteractionChannelParticipantUpdater( + pathInteractionSid, + pathChannelSid, + pathSid, + status + ); + } + + public enum Status { + CLOSED("closed"), + WRAPUP("wrapup"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Type { + SUPERVISOR("supervisor"), + CUSTOMER("customer"), + EXTERNAL("external"), + AGENT("agent"), + UNKNOWN("unknown"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + /** + * Converts a JSON String into a InteractionChannelParticipant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannelParticipant object represented by the provided JSON + */ + public static InteractionChannelParticipant fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InteractionChannelParticipant.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InteractionChannelParticipant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InteractionChannelParticipant object represented by the provided JSON + */ + public static InteractionChannelParticipant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + InteractionChannelParticipant.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String channelSid; + + @Getter + private final String interactionSid; + + @Getter + private final Object routingProperties; + + @Getter + private final String sid; + + @Getter + private final InteractionChannelParticipant.Type type; + + @Getter + private final URI url; + + @JsonCreator + private InteractionChannelParticipant( + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("interaction_sid") final String interactionSid, + @JsonProperty("routing_properties") final Object routingProperties, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final InteractionChannelParticipant.Type type, + @JsonProperty("url") final URI url + ) { + this.channelSid = channelSid; + this.interactionSid = interactionSid; + this.routingProperties = routingProperties; + this.sid = sid; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InteractionChannelParticipant other = (InteractionChannelParticipant) o; + return ( + Objects.equals(channelSid, other.channelSid) && + Objects.equals(interactionSid, other.interactionSid) && + Objects.equals(routingProperties, other.routingProperties) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + channelSid, + interactionSid, + routingProperties, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantCreator.java new file mode 100644 index 0000000000..e147273102 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantCreator.java @@ -0,0 +1,175 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionChannelParticipantCreator + extends Creator { + + private String pathInteractionSid; + private String pathChannelSid; + private InteractionChannelParticipant.Type type; + private Object mediaProperties; + private Object routingProperties; + + public InteractionChannelParticipantCreator( + final String pathInteractionSid, + final String pathChannelSid, + final InteractionChannelParticipant.Type type, + final Object mediaProperties + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathChannelSid = pathChannelSid; + this.type = type; + this.mediaProperties = mediaProperties; + } + + public InteractionChannelParticipantCreator setType( + final InteractionChannelParticipant.Type type + ) { + this.type = type; + return this; + } + + public InteractionChannelParticipantCreator setMediaProperties( + final Object mediaProperties + ) { + this.mediaProperties = mediaProperties; + return this; + } + + public InteractionChannelParticipantCreator setRoutingProperties( + final Object routingProperties + ) { + this.routingProperties = routingProperties; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InteractionChannelParticipant creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InteractionChannelParticipant create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InteractionChannelParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InteractionChannelParticipant content = + InteractionChannelParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (mediaProperties != null) { + Serializer.toString( + request, + "MediaProperties", + mediaProperties, + ParameterType.URLENCODED + ); + } + + if (routingProperties != null) { + Serializer.toString( + request, + "RoutingProperties", + routingProperties, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantReader.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantReader.java new file mode 100644 index 0000000000..d0fa967f89 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantReader.java @@ -0,0 +1,226 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionChannelParticipantReader + extends Reader { + + private String pathInteractionSid; + private String pathChannelSid; + private Long pageSize; + + public InteractionChannelParticipantReader( + final String pathInteractionSid, + final String pathChannelSid + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathChannelSid = pathChannelSid; + } + + public InteractionChannelParticipantReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + InteractionChannelParticipant.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + InteractionChannelParticipant.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InteractionChannelParticipant read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "participants", + response.getContent(), + InteractionChannelParticipant.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantUpdater.java new file mode 100644 index 0000000000..389aa34d06 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionChannelParticipantUpdater.java @@ -0,0 +1,143 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionChannelParticipantUpdater + extends Updater { + + private String pathInteractionSid; + private String pathChannelSid; + private String pathSid; + private InteractionChannelParticipant.Status status; + + public InteractionChannelParticipantUpdater( + final String pathInteractionSid, + final String pathChannelSid, + final String pathSid, + final InteractionChannelParticipant.Status status + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathChannelSid = pathChannelSid; + this.pathSid = pathSid; + this.status = status; + } + + public InteractionChannelParticipantUpdater setStatus( + final InteractionChannelParticipant.Status status + ) { + this.status = status; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InteractionChannelParticipant update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InteractionChannelParticipant update(final TwilioRestClient client) { + Response response = makeRequest(client); + return InteractionChannelParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InteractionChannelParticipant content = + InteractionChannelParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransfer.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransfer.java new file mode 100644 index 0000000000..3d34b94c6d --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransfer.java @@ -0,0 +1,320 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InteractionTransfer extends Resource { + + public static InteractionTransferCreator creator( + final String pathInteractionSid, + final String pathChannelSid + ) { + return new InteractionTransferCreator( + pathInteractionSid, + pathChannelSid + ); + } + + public static InteractionTransferFetcher fetcher( + final String pathInteractionSid, + final String pathChannelSid, + final String pathSid + ) { + return new InteractionTransferFetcher( + pathInteractionSid, + pathChannelSid, + pathSid + ); + } + + public static InteractionTransferUpdater updater( + final String pathInteractionSid, + final String pathChannelSid, + final String pathSid + ) { + return new InteractionTransferUpdater( + pathInteractionSid, + pathChannelSid, + pathSid + ); + } + + public enum TransferStatus { + ACTIVE("active"), + FAILED("failed"), + COMPLETED("completed"); + + private final String value; + + private TransferStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TransferStatus forValue(final String value) { + return Promoter.enumFromString(value, TransferStatus.values()); + } + } + + public enum TransferType { + WARM("warm"), + COLD("cold"), + EXTERNAL("external"); + + private final String value; + + private TransferType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TransferType forValue(final String value) { + return Promoter.enumFromString(value, TransferType.values()); + } + } + + /** + * Converts a JSON String into a InteractionTransfer object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InteractionTransfer object represented by the provided JSON + */ + public static InteractionTransfer fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InteractionTransfer.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InteractionTransfer object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InteractionTransfer object represented by the provided JSON + */ + public static InteractionTransfer fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InteractionTransfer.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String channelSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String executionSid; + + @Getter + private final String from; + + @Getter + private final String instanceSid; + + @Getter + private final String interactionSid; + + @Getter + private final String noteSid; + + @Getter + private final String sid; + + @Getter + private final InteractionTransfer.TransferStatus status; + + @Getter + private final String summarySid; + + @Getter + private final String to; + + @Getter + private final InteractionTransfer.TransferType type; + + @Getter + private final URI url; + + @JsonCreator + private InteractionTransfer( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("from") final String from, + @JsonProperty("instance_sid") final String instanceSid, + @JsonProperty("interaction_sid") final String interactionSid, + @JsonProperty("note_sid") final String noteSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final InteractionTransfer.TransferStatus status, + @JsonProperty("summary_sid") final String summarySid, + @JsonProperty("to") final String to, + @JsonProperty("type") final InteractionTransfer.TransferType type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.executionSid = executionSid; + this.from = from; + this.instanceSid = instanceSid; + this.interactionSid = interactionSid; + this.noteSid = noteSid; + this.sid = sid; + this.status = status; + this.summarySid = summarySid; + this.to = to; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InteractionTransfer other = (InteractionTransfer) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(from, other.from) && + Objects.equals(instanceSid, other.instanceSid) && + Objects.equals(interactionSid, other.interactionSid) && + Objects.equals(noteSid, other.noteSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(summarySid, other.summarySid) && + Objects.equals(to, other.to) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + channelSid, + dateCreated, + dateUpdated, + executionSid, + from, + instanceSid, + interactionSid, + noteSid, + sid, + status, + summarySid, + to, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferCreator.java new file mode 100644 index 0000000000..dde7a3bece --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferCreator.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionTransferCreator extends Creator { + + private String pathInteractionSid; + private String pathChannelSid; + private Object body; + + public InteractionTransferCreator( + final String pathInteractionSid, + final String pathChannelSid + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathChannelSid = pathChannelSid; + } + + public InteractionTransferCreator setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Transfers"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InteractionTransfer creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InteractionTransfer create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InteractionTransfer.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InteractionTransfer content = InteractionTransfer.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody(InteractionTransfer.toJson(body, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferFetcher.java new file mode 100644 index 0000000000..ffaf4c297c --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionTransferFetcher extends Fetcher { + + private String pathInteractionSid; + private String pathChannelSid; + private String pathSid; + + public InteractionTransferFetcher( + final String pathInteractionSid, + final String pathChannelSid, + final String pathSid + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathChannelSid = pathChannelSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Transfers/{Sid}"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InteractionTransfer fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InteractionTransfer fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InteractionTransfer.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InteractionTransfer content = InteractionTransfer.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferUpdater.java b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferUpdater.java new file mode 100644 index 0000000000..6c5a6144c7 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/interaction/interactionchannel/InteractionTransferUpdater.java @@ -0,0 +1,132 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.interaction.interactionchannel; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InteractionTransferUpdater extends Updater { + + private String pathInteractionSid; + private String pathChannelSid; + private String pathSid; + private Object body; + + public InteractionTransferUpdater( + final String pathInteractionSid, + final String pathChannelSid, + final String pathSid + ) { + this.pathInteractionSid = pathInteractionSid; + this.pathChannelSid = pathChannelSid; + this.pathSid = pathSid; + } + + public InteractionTransferUpdater setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Interactions/{InteractionSid}/Channels/{ChannelSid}/Transfers/{Sid}"; + + path = + path.replace( + "{" + "InteractionSid" + "}", + this.pathInteractionSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InteractionTransfer update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InteractionTransfer update(final TwilioRestClient client) { + Response response = makeRequest(client); + return InteractionTransfer.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InteractionTransfer content = InteractionTransfer.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody(InteractionTransfer.toJson(body, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersions.java b/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersions.java new file mode 100644 index 0000000000..f50ed25f7d --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersions.java @@ -0,0 +1,226 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.plugin; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PluginVersions extends Resource { + + public static PluginVersionsCreator creator( + final String pathPluginSid, + final String version, + final URI pluginUrl + ) { + return new PluginVersionsCreator(pathPluginSid, version, pluginUrl); + } + + public static PluginVersionsFetcher fetcher( + final String pathPluginSid, + final String pathSid + ) { + return new PluginVersionsFetcher(pathPluginSid, pathSid); + } + + public static PluginVersionsReader reader(final String pathPluginSid) { + return new PluginVersionsReader(pathPluginSid); + } + + /** + * Converts a JSON String into a PluginVersions object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PluginVersions object represented by the provided JSON + */ + public static PluginVersions fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginVersions.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PluginVersions object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PluginVersions object represented by the provided JSON + */ + public static PluginVersions fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PluginVersions.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean archived; + + @Getter + private final String changelog; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String pluginSid; + + @Getter + private final URI pluginUrl; + + @Getter + private final Boolean _private; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final Boolean validated; + + @Getter + private final String version; + + @JsonCreator + private PluginVersions( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("archived") final Boolean archived, + @JsonProperty("changelog") final String changelog, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("plugin_sid") final String pluginSid, + @JsonProperty("plugin_url") final URI pluginUrl, + @JsonProperty("private") final Boolean _private, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("validated") final Boolean validated, + @JsonProperty("version") final String version + ) { + this.accountSid = accountSid; + this.archived = archived; + this.changelog = changelog; + this.dateCreated = dateCreated; + this.pluginSid = pluginSid; + this.pluginUrl = pluginUrl; + this._private = _private; + this.sid = sid; + this.url = url; + this.validated = validated; + this.version = version; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PluginVersions other = (PluginVersions) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(archived, other.archived) && + Objects.equals(changelog, other.changelog) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(pluginSid, other.pluginSid) && + Objects.equals(pluginUrl, other.pluginUrl) && + Objects.equals(_private, other._private) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(validated, other.validated) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + archived, + changelog, + dateCreated, + pluginSid, + pluginUrl, + _private, + sid, + url, + validated, + version + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsCreator.java b/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsCreator.java new file mode 100644 index 0000000000..7df437064b --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsCreator.java @@ -0,0 +1,229 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.plugin; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class PluginVersionsCreator extends Creator { + + private String pathPluginSid; + private String flexMetadata; + private String version; + private URI pluginUrl; + private String changelog; + private Boolean _private; + private String cliVersion; + private String validateStatus; + + public PluginVersionsCreator( + final String pathPluginSid, + final String version, + final URI pluginUrl + ) { + this.pathPluginSid = pathPluginSid; + this.version = version; + this.pluginUrl = pluginUrl; + } + + public PluginVersionsCreator setVersion(final String version) { + this.version = version; + return this; + } + + public PluginVersionsCreator setPluginUrl(final URI pluginUrl) { + this.pluginUrl = pluginUrl; + return this; + } + + public PluginVersionsCreator setPluginUrl(final String pluginUrl) { + return setPluginUrl(Promoter.uriFromString(pluginUrl)); + } + + public PluginVersionsCreator setChangelog(final String changelog) { + this.changelog = changelog; + return this; + } + + public PluginVersionsCreator set_private(final Boolean _private) { + this._private = _private; + return this; + } + + public PluginVersionsCreator setCliVersion(final String cliVersion) { + this.cliVersion = cliVersion; + return this; + } + + public PluginVersionsCreator setValidateStatus( + final String validateStatus + ) { + this.validateStatus = validateStatus; + return this; + } + + public PluginVersionsCreator setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Plugins/{PluginSid}/Versions"; + + path = + path.replace( + "{" + "PluginSid" + "}", + this.pathPluginSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginVersions creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginVersions create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginVersions.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginVersions content = PluginVersions.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (version != null) { + Serializer.toString( + request, + "Version", + version, + ParameterType.URLENCODED + ); + } + + if (pluginUrl != null) { + Serializer.toString( + request, + "PluginUrl", + pluginUrl, + ParameterType.URLENCODED + ); + } + + if (changelog != null) { + Serializer.toString( + request, + "Changelog", + changelog, + ParameterType.URLENCODED + ); + } + + if (_private != null) { + Serializer.toString( + request, + "Private", + _private, + ParameterType.URLENCODED + ); + } + + if (cliVersion != null) { + Serializer.toString( + request, + "CliVersion", + cliVersion, + ParameterType.URLENCODED + ); + } + + if (validateStatus != null) { + Serializer.toString( + request, + "ValidateStatus", + validateStatus, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsFetcher.java new file mode 100644 index 0000000000..77dad11728 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsFetcher.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.plugin; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginVersionsFetcher extends Fetcher { + + private String pathPluginSid; + private String pathSid; + private String flexMetadata; + + public PluginVersionsFetcher( + final String pathPluginSid, + final String pathSid + ) { + this.pathPluginSid = pathPluginSid; + this.pathSid = pathSid; + } + + public PluginVersionsFetcher setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Plugins/{PluginSid}/Versions/{Sid}"; + + path = + path.replace( + "{" + "PluginSid" + "}", + this.pathPluginSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PluginVersions fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PluginVersions fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PluginVersions.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PluginVersions content = PluginVersions.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsReader.java b/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsReader.java new file mode 100644 index 0000000000..323da4f9a1 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/plugin/PluginVersionsReader.java @@ -0,0 +1,229 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.plugin; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PluginVersionsReader extends Reader { + + private String pathPluginSid; + private Long pageSize; + private String flexMetadata; + + public PluginVersionsReader(final String pathPluginSid) { + this.pathPluginSid = pathPluginSid; + } + + public PluginVersionsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public PluginVersionsReader setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "plugin_versions", + response.getContent(), + PluginVersions.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/PluginService/Plugins/{PluginSid}/Versions"; + + path = + path.replace( + "{" + "PluginSid" + "}", + this.pathPluginSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "plugin_versions", + response.getContent(), + PluginVersions.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PluginVersions read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "plugin_versions", + response.getContent(), + PluginVersions.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPlugin.java b/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPlugin.java new file mode 100644 index 0000000000..89fc5ffa3e --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPlugin.java @@ -0,0 +1,260 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.pluginconfiguration; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ConfiguredPlugin extends Resource { + + public static ConfiguredPluginFetcher fetcher( + final String pathConfigurationSid, + final String pathPluginSid + ) { + return new ConfiguredPluginFetcher(pathConfigurationSid, pathPluginSid); + } + + public static ConfiguredPluginReader reader( + final String pathConfigurationSid + ) { + return new ConfiguredPluginReader(pathConfigurationSid); + } + + /** + * Converts a JSON String into a ConfiguredPlugin object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ConfiguredPlugin object represented by the provided JSON + */ + public static ConfiguredPlugin fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ConfiguredPlugin.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ConfiguredPlugin object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ConfiguredPlugin object represented by the provided JSON + */ + public static ConfiguredPlugin fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ConfiguredPlugin.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String changelog; + + @Getter + private final String configurationSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final Integer phase; + + @Getter + private final Boolean pluginArchived; + + @Getter + private final String pluginSid; + + @Getter + private final String pluginUrl; + + @Getter + private final Boolean pluginVersionArchived; + + @Getter + private final String pluginVersionSid; + + @Getter + private final Boolean _private; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @Getter + private final String version; + + @JsonCreator + private ConfiguredPlugin( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("changelog") final String changelog, + @JsonProperty("configuration_sid") final String configurationSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("phase") final Integer phase, + @JsonProperty("plugin_archived") final Boolean pluginArchived, + @JsonProperty("plugin_sid") final String pluginSid, + @JsonProperty("plugin_url") final String pluginUrl, + @JsonProperty( + "plugin_version_archived" + ) final Boolean pluginVersionArchived, + @JsonProperty("plugin_version_sid") final String pluginVersionSid, + @JsonProperty("private") final Boolean _private, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("version") final String version + ) { + this.accountSid = accountSid; + this.changelog = changelog; + this.configurationSid = configurationSid; + this.dateCreated = dateCreated; + this.description = description; + this.friendlyName = friendlyName; + this.phase = phase; + this.pluginArchived = pluginArchived; + this.pluginSid = pluginSid; + this.pluginUrl = pluginUrl; + this.pluginVersionArchived = pluginVersionArchived; + this.pluginVersionSid = pluginVersionSid; + this._private = _private; + this.uniqueName = uniqueName; + this.url = url; + this.version = version; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConfiguredPlugin other = (ConfiguredPlugin) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(changelog, other.changelog) && + Objects.equals(configurationSid, other.configurationSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phase, other.phase) && + Objects.equals(pluginArchived, other.pluginArchived) && + Objects.equals(pluginSid, other.pluginSid) && + Objects.equals(pluginUrl, other.pluginUrl) && + Objects.equals( + pluginVersionArchived, + other.pluginVersionArchived + ) && + Objects.equals(pluginVersionSid, other.pluginVersionSid) && + Objects.equals(_private, other._private) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + changelog, + configurationSid, + dateCreated, + description, + friendlyName, + phase, + pluginArchived, + pluginSid, + pluginUrl, + pluginVersionArchived, + pluginVersionSid, + _private, + uniqueName, + url, + version + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPluginFetcher.java b/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPluginFetcher.java new file mode 100644 index 0000000000..265657d8ff --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPluginFetcher.java @@ -0,0 +1,131 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.pluginconfiguration; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfiguredPluginFetcher extends Fetcher { + + private String pathConfigurationSid; + private String pathPluginSid; + private String flexMetadata; + + public ConfiguredPluginFetcher( + final String pathConfigurationSid, + final String pathPluginSid + ) { + this.pathConfigurationSid = pathConfigurationSid; + this.pathPluginSid = pathPluginSid; + } + + public ConfiguredPluginFetcher setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/PluginService/Configurations/{ConfigurationSid}/Plugins/{PluginSid}"; + + path = + path.replace( + "{" + "ConfigurationSid" + "}", + this.pathConfigurationSid.toString() + ); + path = + path.replace( + "{" + "PluginSid" + "}", + this.pathPluginSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConfiguredPlugin fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ConfiguredPlugin fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ConfiguredPlugin.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ConfiguredPlugin content = ConfiguredPlugin.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPluginReader.java b/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPluginReader.java new file mode 100644 index 0000000000..69f37b9768 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v1/pluginconfiguration/ConfiguredPluginReader.java @@ -0,0 +1,230 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v1.pluginconfiguration; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfiguredPluginReader extends Reader { + + private String pathConfigurationSid; + private Long pageSize; + private String flexMetadata; + + public ConfiguredPluginReader(final String pathConfigurationSid) { + this.pathConfigurationSid = pathConfigurationSid; + } + + public ConfiguredPluginReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ConfiguredPluginReader setFlexMetadata(final String flexMetadata) { + this.flexMetadata = flexMetadata; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "plugins", + response.getContent(), + ConfiguredPlugin.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/PluginService/Configurations/{ConfigurationSid}/Plugins"; + + path = + path.replace( + "{" + "ConfigurationSid" + "}", + this.pathConfigurationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "plugins", + response.getContent(), + ConfiguredPlugin.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ConfiguredPlugin read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "plugins", + response.getContent(), + ConfiguredPlugin.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (flexMetadata != null) { + Serializer.toString( + request, + "Flex-Metadata", + flexMetadata, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v2/FlexUser.java b/src/main/java/com/twilio/rest/flexapi/v2/FlexUser.java new file mode 100644 index 0000000000..91bb628e92 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v2/FlexUser.java @@ -0,0 +1,255 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class FlexUser extends Resource { + + public static FlexUserFetcher fetcher( + final String pathInstanceSid, + final String pathFlexUserSid + ) { + return new FlexUserFetcher(pathInstanceSid, pathFlexUserSid); + } + + public static FlexUserUpdater updater( + final String pathInstanceSid, + final String pathFlexUserSid + ) { + return new FlexUserUpdater(pathInstanceSid, pathFlexUserSid); + } + + /** + * Converts a JSON String into a FlexUser object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlexUser object represented by the provided JSON + */ + public static FlexUser fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlexUser.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a FlexUser object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlexUser object represented by the provided JSON + */ + public static FlexUser fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlexUser.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime createdDate; + + @Getter + private final String email; + + @Getter + private final String flexTeamSid; + + @Getter + private final String flexUserSid; + + @Getter + private final String instanceSid; + + @Getter + private final String locale; + + @Getter + private final List roles; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime updatedDate; + + @Getter + private final URI url; + + @Getter + private final String userSid; + + @Getter + private final String username; + + @Getter + private final Integer version; + + @Getter + private final String workerSid; + + @Getter + private final String workspaceSid; + + @JsonCreator + private FlexUser( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("created_date") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime createdDate, + @JsonProperty("email") final String email, + @JsonProperty("flex_team_sid") final String flexTeamSid, + @JsonProperty("flex_user_sid") final String flexUserSid, + @JsonProperty("instance_sid") final String instanceSid, + @JsonProperty("locale") final String locale, + @JsonProperty("roles") final List roles, + @JsonProperty("updated_date") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime updatedDate, + @JsonProperty("url") final URI url, + @JsonProperty("user_sid") final String userSid, + @JsonProperty("username") final String username, + @JsonProperty("version") final Integer version, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { + this.accountSid = accountSid; + this.createdDate = createdDate; + this.email = email; + this.flexTeamSid = flexTeamSid; + this.flexUserSid = flexUserSid; + this.instanceSid = instanceSid; + this.locale = locale; + this.roles = roles; + this.updatedDate = updatedDate; + this.url = url; + this.userSid = userSid; + this.username = username; + this.version = version; + this.workerSid = workerSid; + this.workspaceSid = workspaceSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FlexUser other = (FlexUser) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(createdDate, other.createdDate) && + Objects.equals(email, other.email) && + Objects.equals(flexTeamSid, other.flexTeamSid) && + Objects.equals(flexUserSid, other.flexUserSid) && + Objects.equals(instanceSid, other.instanceSid) && + Objects.equals(locale, other.locale) && + Objects.equals(roles, other.roles) && + Objects.equals(updatedDate, other.updatedDate) && + Objects.equals(url, other.url) && + Objects.equals(userSid, other.userSid) && + Objects.equals(username, other.username) && + Objects.equals(version, other.version) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + createdDate, + email, + flexTeamSid, + flexUserSid, + instanceSid, + locale, + roles, + updatedDate, + url, + userSid, + username, + version, + workerSid, + workspaceSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v2/FlexUserFetcher.java b/src/main/java/com/twilio/rest/flexapi/v2/FlexUserFetcher.java new file mode 100644 index 0000000000..3cd3f27651 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v2/FlexUserFetcher.java @@ -0,0 +1,110 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlexUserFetcher extends Fetcher { + + private String pathInstanceSid; + private String pathFlexUserSid; + + public FlexUserFetcher( + final String pathInstanceSid, + final String pathFlexUserSid + ) { + this.pathInstanceSid = pathInstanceSid; + this.pathFlexUserSid = pathFlexUserSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Instances/{InstanceSid}/Users/{FlexUserSid}"; + + path = + path.replace( + "{" + "InstanceSid" + "}", + this.pathInstanceSid.toString() + ); + path = + path.replace( + "{" + "FlexUserSid" + "}", + this.pathFlexUserSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.FLEXAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlexUser fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlexUser fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlexUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlexUser content = FlexUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v2/FlexUserUpdater.java b/src/main/java/com/twilio/rest/flexapi/v2/FlexUserUpdater.java new file mode 100644 index 0000000000..d444cd4738 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v2/FlexUserUpdater.java @@ -0,0 +1,162 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlexUserUpdater extends Updater { + + private String pathInstanceSid; + private String pathFlexUserSid; + private String email; + private String userSid; + private String locale; + + public FlexUserUpdater( + final String pathInstanceSid, + final String pathFlexUserSid + ) { + this.pathInstanceSid = pathInstanceSid; + this.pathFlexUserSid = pathFlexUserSid; + } + + public FlexUserUpdater setEmail(final String email) { + this.email = email; + return this; + } + + public FlexUserUpdater setUserSid(final String userSid) { + this.userSid = userSid; + return this; + } + + public FlexUserUpdater setLocale(final String locale) { + this.locale = locale; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Instances/{InstanceSid}/Users/{FlexUserSid}"; + + path = + path.replace( + "{" + "InstanceSid" + "}", + this.pathInstanceSid.toString() + ); + path = + path.replace( + "{" + "FlexUserSid" + "}", + this.pathFlexUserSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlexUser update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlexUser update(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlexUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlexUser content = FlexUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + + if (userSid != null) { + Serializer.toString( + request, + "UserSid", + userSid, + ParameterType.URLENCODED + ); + } + + if (locale != null) { + Serializer.toString( + request, + "Locale", + locale, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v2/WebChannels.java b/src/main/java/com/twilio/rest/flexapi/v2/WebChannels.java new file mode 100644 index 0000000000..254afcdb27 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v2/WebChannels.java @@ -0,0 +1,136 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class WebChannels extends Resource { + + public static WebChannelsCreator creator(final String addressSid) { + return new WebChannelsCreator(addressSid); + } + + /** + * Converts a JSON String into a WebChannels object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return WebChannels object represented by the provided JSON + */ + public static WebChannels fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, WebChannels.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a WebChannels object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return WebChannels object represented by the provided JSON + */ + public static WebChannels fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, WebChannels.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String conversationSid; + + @Getter + private final String identity; + + @JsonCreator + private WebChannels( + @JsonProperty("conversation_sid") final String conversationSid, + @JsonProperty("identity") final String identity + ) { + this.conversationSid = conversationSid; + this.identity = identity; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + WebChannels other = (WebChannels) o; + return ( + Objects.equals(conversationSid, other.conversationSid) && + Objects.equals(identity, other.identity) + ); + } + + @Override + public int hashCode() { + return Objects.hash(conversationSid, identity); + } +} diff --git a/src/main/java/com/twilio/rest/flexapi/v2/WebChannelsCreator.java b/src/main/java/com/twilio/rest/flexapi/v2/WebChannelsCreator.java new file mode 100644 index 0000000000..ed1176bad1 --- /dev/null +++ b/src/main/java/com/twilio/rest/flexapi/v2/WebChannelsCreator.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Flex + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.flexapi.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebChannelsCreator extends Creator { + + private String uiVersion; + private String addressSid; + private String chatFriendlyName; + private String customerFriendlyName; + private String preEngagementData; + private String identity; + + public WebChannelsCreator(final String addressSid) { + this.addressSid = addressSid; + } + + public WebChannelsCreator setAddressSid(final String addressSid) { + this.addressSid = addressSid; + return this; + } + + public WebChannelsCreator setChatFriendlyName( + final String chatFriendlyName + ) { + this.chatFriendlyName = chatFriendlyName; + return this; + } + + public WebChannelsCreator setCustomerFriendlyName( + final String customerFriendlyName + ) { + this.customerFriendlyName = customerFriendlyName; + return this; + } + + public WebChannelsCreator setPreEngagementData( + final String preEngagementData + ) { + this.preEngagementData = preEngagementData; + return this; + } + + public WebChannelsCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public WebChannelsCreator setUiVersion(final String uiVersion) { + this.uiVersion = uiVersion; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/WebChats"; + + Request request = new Request( + HttpMethod.POST, + Domains.FLEXAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "WebChannels creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public WebChannels create(final TwilioRestClient client) { + Response response = makeRequest(client); + return WebChannels.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WebChannels content = WebChannels.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (addressSid != null) { + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); + } + + if (chatFriendlyName != null) { + Serializer.toString( + request, + "ChatFriendlyName", + chatFriendlyName, + ParameterType.URLENCODED + ); + } + + if (customerFriendlyName != null) { + Serializer.toString( + request, + "CustomerFriendlyName", + customerFriendlyName, + ParameterType.URLENCODED + ); + } + + if (preEngagementData != null) { + Serializer.toString( + request, + "PreEngagementData", + preEngagementData, + ParameterType.URLENCODED + ); + } + + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (uiVersion != null) { + Serializer.toString( + request, + "Ui-Version", + uiVersion, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/frontlineapi/v1/User.java b/src/main/java/com/twilio/rest/frontlineapi/v1/User.java new file mode 100644 index 0000000000..6ab556910a --- /dev/null +++ b/src/main/java/com/twilio/rest/frontlineapi/v1/User.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Frontline + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.frontlineapi.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class User extends Resource { + + public static UserFetcher fetcher(final String pathSid) { + return new UserFetcher(pathSid); + } + + public static UserUpdater updater(final String pathSid) { + return new UserUpdater(pathSid); + } + + public enum StateType { + ACTIVE("active"), + DEACTIVATED("deactivated"); + + private final String value; + + private StateType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static StateType forValue(final String value) { + return Promoter.enumFromString(value, StateType.values()); + } + } + + /** + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String avatar; + + @Getter + private final String friendlyName; + + @Getter + private final String identity; + + @Getter + private final Boolean isAvailable; + + @Getter + private final String sid; + + @Getter + private final User.StateType state; + + @Getter + private final URI url; + + @JsonCreator + private User( + @JsonProperty("avatar") final String avatar, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity") final String identity, + @JsonProperty("is_available") final Boolean isAvailable, + @JsonProperty("sid") final String sid, + @JsonProperty("state") final User.StateType state, + @JsonProperty("url") final URI url + ) { + this.avatar = avatar; + this.friendlyName = friendlyName; + this.identity = identity; + this.isAvailable = isAvailable; + this.sid = sid; + this.state = state; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + User other = (User) o; + return ( + Objects.equals(avatar, other.avatar) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identity, other.identity) && + Objects.equals(isAvailable, other.isAvailable) && + Objects.equals(sid, other.sid) && + Objects.equals(state, other.state) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + avatar, + friendlyName, + identity, + isAvailable, + sid, + state, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/frontlineapi/v1/UserFetcher.java b/src/main/java/com/twilio/rest/frontlineapi/v1/UserFetcher.java new file mode 100644 index 0000000000..aa7eba1e74 --- /dev/null +++ b/src/main/java/com/twilio/rest/frontlineapi/v1/UserFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Frontline + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.frontlineapi.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserFetcher extends Fetcher { + + private String pathSid; + + public UserFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.FRONTLINEAPI.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/frontlineapi/v1/UserUpdater.java b/src/main/java/com/twilio/rest/frontlineapi/v1/UserUpdater.java new file mode 100644 index 0000000000..d83d94579d --- /dev/null +++ b/src/main/java/com/twilio/rest/frontlineapi/v1/UserUpdater.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Frontline + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.frontlineapi.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private String avatar; + private User.StateType state; + private Boolean isAvailable; + + public UserUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public UserUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public UserUpdater setAvatar(final String avatar) { + this.avatar = avatar; + return this; + } + + public UserUpdater setState(final User.StateType state) { + this.state = state; + return this; + } + + public UserUpdater setIsAvailable(final Boolean isAvailable) { + this.isAvailable = isAvailable; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Users/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.FRONTLINEAPI.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User update(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (avatar != null) { + Serializer.toString( + request, + "Avatar", + avatar, + ParameterType.URLENCODED + ); + } + + if (state != null) { + Serializer.toString( + request, + "State", + state, + ParameterType.URLENCODED + ); + } + + if (isAvailable != null) { + Serializer.toString( + request, + "IsAvailable", + isAvailable, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/ApiKey.java b/src/main/java/com/twilio/rest/iam/v1/ApiKey.java new file mode 100644 index 0000000000..c89615d477 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/ApiKey.java @@ -0,0 +1,174 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ApiKey extends Resource { + + public static ApiKeyDeleter deleter(final String pathSid) { + return new ApiKeyDeleter(pathSid); + } + + public static ApiKeyFetcher fetcher(final String pathSid) { + return new ApiKeyFetcher(pathSid); + } + + public static ApiKeyUpdater updater(final String pathSid) { + return new ApiKeyUpdater(pathSid); + } + + /** + * Converts a JSON String into a ApiKey object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ApiKey object represented by the provided JSON + */ + public static ApiKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ApiKey.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ApiKey object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ApiKey object represented by the provided JSON + */ + public static ApiKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ApiKey.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Object policy; + + @Getter + private final String sid; + + @JsonCreator + private ApiKey( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("policy") final Object policy, + @JsonProperty("sid") final String sid + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.policy = policy; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ApiKey other = (ApiKey) o; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(policy, other.policy) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dateCreated, + dateUpdated, + friendlyName, + policy, + sid + ); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/ApiKeyDeleter.java b/src/main/java/com/twilio/rest/iam/v1/ApiKeyDeleter.java new file mode 100644 index 0000000000..a19d21672a --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/ApiKeyDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ApiKeyDeleter extends Deleter { + + private String pathSid; + + public ApiKeyDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Keys/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.IAM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ApiKey delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/ApiKeyFetcher.java b/src/main/java/com/twilio/rest/iam/v1/ApiKeyFetcher.java new file mode 100644 index 0000000000..9cb9396d52 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/ApiKeyFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ApiKeyFetcher extends Fetcher { + + private String pathSid; + + public ApiKeyFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Keys/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.IAM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ApiKey fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ApiKey fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ApiKey.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ApiKey content = ApiKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/ApiKeyUpdater.java b/src/main/java/com/twilio/rest/iam/v1/ApiKeyUpdater.java new file mode 100644 index 0000000000..943d9a32d1 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/ApiKeyUpdater.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ApiKeyUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private Object policy; + + public ApiKeyUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public ApiKeyUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ApiKeyUpdater setPolicy(final Object policy) { + this.policy = policy; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Keys/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.IAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ApiKey update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ApiKey update(final TwilioRestClient client) { + Response response = makeRequest(client); + return ApiKey.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ApiKey content = ApiKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (policy != null) { + Serializer.toString( + request, + "Policy", + policy, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/GetApiKeys.java b/src/main/java/com/twilio/rest/iam/v1/GetApiKeys.java new file mode 100644 index 0000000000..ce8832761c --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/GetApiKeys.java @@ -0,0 +1,161 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class GetApiKeys extends Resource { + + public static GetApiKeysReader reader(final String accountSid) { + return new GetApiKeysReader(accountSid); + } + + /** + * Converts a JSON String into a GetApiKeys object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return GetApiKeys object represented by the provided JSON + */ + public static GetApiKeys fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, GetApiKeys.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a GetApiKeys object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return GetApiKeys object represented by the provided JSON + */ + public static GetApiKeys fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, GetApiKeys.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final List flags; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @JsonCreator + private GetApiKeys( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("flags") final List flags, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.flags = flags; + this.friendlyName = friendlyName; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + GetApiKeys other = (GetApiKeys) o; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(flags, other.flags) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash(dateCreated, dateUpdated, flags, friendlyName, sid); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/GetApiKeysReader.java b/src/main/java/com/twilio/rest/iam/v1/GetApiKeysReader.java new file mode 100644 index 0000000000..844758a1c6 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/GetApiKeysReader.java @@ -0,0 +1,219 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class GetApiKeysReader extends Reader { + + private String accountSid; + private Long pageSize; + + public GetApiKeysReader(final String accountSid) { + this.accountSid = accountSid; + } + + public GetApiKeysReader setAccountSid(final String accountSid) { + this.accountSid = accountSid; + return this; + } + + public GetApiKeysReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "keys", + response.getContent(), + GetApiKeys.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Keys"; + + Request request = new Request( + HttpMethod.GET, + Domains.IAM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "keys", + response.getContent(), + GetApiKeys.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "GetApiKeys read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "keys", + response.getContent(), + GetApiKeys.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (accountSid != null) { + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/NewApiKey.java b/src/main/java/com/twilio/rest/iam/v1/NewApiKey.java new file mode 100644 index 0000000000..21c592eded --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/NewApiKey.java @@ -0,0 +1,173 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class NewApiKey extends Resource { + + public static NewApiKeyCreator creator(final String accountSid) { + return new NewApiKeyCreator(accountSid); + } + + /** + * Converts a JSON String into a NewApiKey object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return NewApiKey object represented by the provided JSON + */ + public static NewApiKey fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, NewApiKey.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a NewApiKey object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return NewApiKey object represented by the provided JSON + */ + public static NewApiKey fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, NewApiKey.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Object policy; + + @Getter + private final String secret; + + @Getter + private final String sid; + + @JsonCreator + private NewApiKey( + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.RFC2822Deserializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("policy") final Object policy, + @JsonProperty("secret") final String secret, + @JsonProperty("sid") final String sid + ) { + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.policy = policy; + this.secret = secret; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NewApiKey other = (NewApiKey) o; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(policy, other.policy) && + Objects.equals(secret, other.secret) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dateCreated, + dateUpdated, + friendlyName, + policy, + secret, + sid + ); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/NewApiKeyCreator.java b/src/main/java/com/twilio/rest/iam/v1/NewApiKeyCreator.java new file mode 100644 index 0000000000..5716fcb9cf --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/NewApiKeyCreator.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NewApiKeyCreator extends Creator { + + private String accountSid; + private String friendlyName; + private String keyType; + private Object policy; + + public NewApiKeyCreator(final String accountSid) { + this.accountSid = accountSid; + } + + public NewApiKeyCreator setAccountSid(final String accountSid) { + this.accountSid = accountSid; + return this; + } + + public NewApiKeyCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public NewApiKeyCreator setKeyType(final String keyType) { + this.keyType = keyType; + return this; + } + + public NewApiKeyCreator setPolicy(final Object policy) { + this.policy = policy; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Keys"; + + Request request = new Request( + HttpMethod.POST, + Domains.IAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "NewApiKey creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public NewApiKey create(final TwilioRestClient client) { + Response response = makeRequest(client); + return NewApiKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + NewApiKey content = NewApiKey.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (accountSid != null) { + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (keyType != null) { + Serializer.toString( + request, + "KeyType", + keyType, + ParameterType.URLENCODED + ); + } + + if (policy != null) { + Serializer.toString( + request, + "Policy", + policy, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/OAuthApp.java b/src/main/java/com/twilio/rest/iam/v1/OAuthApp.java new file mode 100644 index 0000000000..7fb4691556 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/OAuthApp.java @@ -0,0 +1,798 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class OAuthApp extends Resource { + + public static OAuthAppCreator creator( + final OAuthApp.IamV1AccountVendorOauthAppCreateRequest iamV1AccountVendorOauthAppCreateRequest + ) { + return new OAuthAppCreator(iamV1AccountVendorOauthAppCreateRequest); + } + + public static OAuthAppDeleter deleter(final String pathSid) { + return new OAuthAppDeleter(pathSid); + } + + public static OAuthAppUpdater updater( + final String pathSid, + final OAuthApp.IamV1AccountVendorOauthAppUpdateRequest iamV1AccountVendorOauthAppUpdateRequest + ) { + return new OAuthAppUpdater( + pathSid, + iamV1AccountVendorOauthAppUpdateRequest + ); + } + + public enum TokenEndpointAuthMethod { + CLIENT_SECRET_BASIC("client_secret_basic"); + + private final String value; + + private TokenEndpointAuthMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TokenEndpointAuthMethod forValue(final String value) { + return Promoter.enumFromString( + value, + TokenEndpointAuthMethod.values() + ); + } + } + + @JsonDeserialize( + builder = IamV1OrganizationVendorOauthAppUpdateRequestPolicy.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IamV1OrganizationVendorOauthAppUpdateRequestPolicy { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("allow") + @Getter + private final List allow; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("deny") + @Getter + private final List deny; + + private IamV1OrganizationVendorOauthAppUpdateRequestPolicy( + Builder builder + ) { + this.allow = builder.allow; + this.deny = builder.deny; + } + + public static Builder builder() { + return new Builder(); + } + + public static IamV1OrganizationVendorOauthAppUpdateRequestPolicy fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IamV1OrganizationVendorOauthAppUpdateRequestPolicy.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("allow") + private List allow; + + @JsonProperty("deny") + private List deny; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("allow") + public Builder allow(List allow) { + this.allow = allow; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("deny") + public Builder deny(List deny) { + this.deny = deny; + return this; + } + + public IamV1OrganizationVendorOauthAppUpdateRequestPolicy build() { + return new IamV1OrganizationVendorOauthAppUpdateRequestPolicy( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IamV1OrganizationVendorOauthAppUpdateRequestPolicy other = + (IamV1OrganizationVendorOauthAppUpdateRequestPolicy) o; + return ( + Objects.equals(allow, other.allow) && + Objects.equals(deny, other.deny) + ); + } + + @Override + public int hashCode() { + return Objects.hash(allow, deny); + } + } + + @JsonDeserialize( + builder = IamV1AccountVendorOauthAppCreateRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IamV1AccountVendorOauthAppCreateRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("owner_sid") + @Getter + private final String ownerSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("client_sid") + @Getter + private final String clientSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("token_endpoint_auth_method") + @Getter + private final OAuthApp.TokenEndpointAuthMethod tokenEndpointAuthMethod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + @Getter + private final IamV1OrganizationVendoroauthappPolicy policy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("access_token_ttl") + @Getter + private final Integer accessTokenTtl; + + private IamV1AccountVendorOauthAppCreateRequest(Builder builder) { + this.type = builder.type; + this.friendlyName = builder.friendlyName; + this.ownerSid = builder.ownerSid; + this.description = builder.description; + this.clientSid = builder.clientSid; + this.tokenEndpointAuthMethod = builder.tokenEndpointAuthMethod; + this.policy = builder.policy; + this.accessTokenTtl = builder.accessTokenTtl; + } + + public static Builder builder() { + return new Builder(); + } + + public static IamV1AccountVendorOauthAppCreateRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IamV1AccountVendorOauthAppCreateRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private String type; + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonProperty("owner_sid") + private String ownerSid; + + @JsonProperty("description") + private String description; + + @JsonProperty("client_sid") + private String clientSid; + + @JsonProperty("token_endpoint_auth_method") + private OAuthApp.TokenEndpointAuthMethod tokenEndpointAuthMethod; + + @JsonProperty("policy") + private IamV1OrganizationVendoroauthappPolicy policy; + + @JsonProperty("access_token_ttl") + private Integer accessTokenTtl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("owner_sid") + public Builder ownerSid(String ownerSid) { + this.ownerSid = ownerSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("client_sid") + public Builder clientSid(String clientSid) { + this.clientSid = clientSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("token_endpoint_auth_method") + public Builder tokenEndpointAuthMethod( + OAuthApp.TokenEndpointAuthMethod tokenEndpointAuthMethod + ) { + this.tokenEndpointAuthMethod = tokenEndpointAuthMethod; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + public Builder policy( + IamV1OrganizationVendoroauthappPolicy policy + ) { + this.policy = policy; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("access_token_ttl") + public Builder accessTokenTtl(Integer accessTokenTtl) { + this.accessTokenTtl = accessTokenTtl; + return this; + } + + public IamV1AccountVendorOauthAppCreateRequest build() { + return new IamV1AccountVendorOauthAppCreateRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IamV1AccountVendorOauthAppCreateRequest other = + (IamV1AccountVendorOauthAppCreateRequest) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(ownerSid, other.ownerSid) && + Objects.equals(description, other.description) && + Objects.equals(clientSid, other.clientSid) && + Objects.equals( + tokenEndpointAuthMethod, + other.tokenEndpointAuthMethod + ) && + Objects.equals(policy, other.policy) && + Objects.equals(accessTokenTtl, other.accessTokenTtl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + type, + friendlyName, + ownerSid, + description, + clientSid, + tokenEndpointAuthMethod, + policy, + accessTokenTtl + ); + } + } + + @JsonDeserialize( + builder = IamV1OrganizationVendoroauthappPolicy.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IamV1OrganizationVendoroauthappPolicy { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("allow") + @Getter + private final List allow; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("deny") + @Getter + private final List deny; + + private IamV1OrganizationVendoroauthappPolicy(Builder builder) { + this.allow = builder.allow; + this.deny = builder.deny; + } + + public static Builder builder() { + return new Builder(); + } + + public static IamV1OrganizationVendoroauthappPolicy fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IamV1OrganizationVendoroauthappPolicy.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("allow") + private List allow; + + @JsonProperty("deny") + private List deny; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("allow") + public Builder allow(List allow) { + this.allow = allow; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("deny") + public Builder deny(List deny) { + this.deny = deny; + return this; + } + + public IamV1OrganizationVendoroauthappPolicy build() { + return new IamV1OrganizationVendoroauthappPolicy(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IamV1OrganizationVendoroauthappPolicy other = + (IamV1OrganizationVendoroauthappPolicy) o; + return ( + Objects.equals(allow, other.allow) && + Objects.equals(deny, other.deny) + ); + } + + @Override + public int hashCode() { + return Objects.hash(allow, deny); + } + } + + @JsonDeserialize( + builder = IamV1AccountVendorOauthAppUpdateRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IamV1AccountVendorOauthAppUpdateRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + @Getter + private final IamV1OrganizationVendorOauthAppUpdateRequestPolicy policy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("access_token_ttl") + @Getter + private final Integer accessTokenTtl; + + private IamV1AccountVendorOauthAppUpdateRequest(Builder builder) { + this.type = builder.type; + this.friendlyName = builder.friendlyName; + this.description = builder.description; + this.policy = builder.policy; + this.accessTokenTtl = builder.accessTokenTtl; + } + + public static Builder builder() { + return new Builder(); + } + + public static IamV1AccountVendorOauthAppUpdateRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IamV1AccountVendorOauthAppUpdateRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private String type; + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonProperty("description") + private String description; + + @JsonProperty("policy") + private IamV1OrganizationVendorOauthAppUpdateRequestPolicy policy; + + @JsonProperty("access_token_ttl") + private Integer accessTokenTtl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + public Builder policy( + IamV1OrganizationVendorOauthAppUpdateRequestPolicy policy + ) { + this.policy = policy; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("access_token_ttl") + public Builder accessTokenTtl(Integer accessTokenTtl) { + this.accessTokenTtl = accessTokenTtl; + return this; + } + + public IamV1AccountVendorOauthAppUpdateRequest build() { + return new IamV1AccountVendorOauthAppUpdateRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IamV1AccountVendorOauthAppUpdateRequest other = + (IamV1AccountVendorOauthAppUpdateRequest) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(description, other.description) && + Objects.equals(policy, other.policy) && + Objects.equals(accessTokenTtl, other.accessTokenTtl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + type, + friendlyName, + description, + policy, + accessTokenTtl + ); + } + } + + /** + * Converts a JSON String into a OAuthApp object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OAuthApp object represented by the provided JSON + */ + public static OAuthApp fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OAuthApp.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a OAuthApp object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OAuthApp object represented by the provided JSON + */ + public static OAuthApp fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OAuthApp.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Integer accessTokenTtl; + + @Getter + private final String createdBy; + + @Getter + private final String creatorSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final IamV1OrganizationVendoroauthappPolicy policy; + + @Getter + private final String secret; + + @Getter + private final String sid; + + @Getter + private final String status; + + @Getter + private final String type; + + @JsonCreator + private OAuthApp( + @JsonProperty("access_token_ttl") final Integer accessTokenTtl, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("creator_sid") final String creatorSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "policy" + ) final IamV1OrganizationVendoroauthappPolicy policy, + @JsonProperty("secret") final String secret, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final String status, + @JsonProperty("type") final String type + ) { + this.accessTokenTtl = accessTokenTtl; + this.createdBy = createdBy; + this.creatorSid = creatorSid; + this.dateCreated = dateCreated; + this.description = description; + this.friendlyName = friendlyName; + this.policy = policy; + this.secret = secret; + this.sid = sid; + this.status = status; + this.type = type; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OAuthApp other = (OAuthApp) o; + return ( + Objects.equals(accessTokenTtl, other.accessTokenTtl) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(creatorSid, other.creatorSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(policy, other.policy) && + Objects.equals(secret, other.secret) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accessTokenTtl, + createdBy, + creatorSid, + dateCreated, + description, + friendlyName, + policy, + secret, + sid, + status, + type + ); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/OAuthAppCreator.java b/src/main/java/com/twilio/rest/iam/v1/OAuthAppCreator.java new file mode 100644 index 0000000000..9e410e33e1 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/OAuthAppCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OAuthAppCreator extends Creator { + + private OAuthApp.IamV1AccountVendorOauthAppCreateRequest iamV1AccountVendorOauthAppCreateRequest; + + public OAuthAppCreator( + final OAuthApp.IamV1AccountVendorOauthAppCreateRequest iamV1AccountVendorOauthAppCreateRequest + ) { + this.iamV1AccountVendorOauthAppCreateRequest = + iamV1AccountVendorOauthAppCreateRequest; + } + + public OAuthAppCreator setIamV1AccountVendorOauthAppCreateRequest( + final OAuthApp.IamV1AccountVendorOauthAppCreateRequest iamV1AccountVendorOauthAppCreateRequest + ) { + this.iamV1AccountVendorOauthAppCreateRequest = + iamV1AccountVendorOauthAppCreateRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Account/OAuthApps"; + + Request request = new Request( + HttpMethod.POST, + Domains.IAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OAuthApp creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public OAuthApp create(final TwilioRestClient client) { + Response response = makeRequest(client); + return OAuthApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OAuthApp content = OAuthApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (iamV1AccountVendorOauthAppCreateRequest != null) { + request.setBody( + OAuthApp.toJson( + iamV1AccountVendorOauthAppCreateRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/OAuthAppDeleter.java b/src/main/java/com/twilio/rest/iam/v1/OAuthAppDeleter.java new file mode 100644 index 0000000000..a7b5187a9d --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/OAuthAppDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class OAuthAppDeleter extends Deleter { + + private String pathSid; + + public OAuthAppDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Account/OAuthApps/{sid}"; + + path = path.replace("{" + "sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.IAM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OAuthApp delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/OAuthAppUpdater.java b/src/main/java/com/twilio/rest/iam/v1/OAuthAppUpdater.java new file mode 100644 index 0000000000..57bc5e779d --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/OAuthAppUpdater.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OAuthAppUpdater extends Updater { + + private String pathSid; + private OAuthApp.IamV1AccountVendorOauthAppUpdateRequest iamV1AccountVendorOauthAppUpdateRequest; + + public OAuthAppUpdater( + final String pathSid, + final OAuthApp.IamV1AccountVendorOauthAppUpdateRequest iamV1AccountVendorOauthAppUpdateRequest + ) { + this.pathSid = pathSid; + this.iamV1AccountVendorOauthAppUpdateRequest = + iamV1AccountVendorOauthAppUpdateRequest; + } + + public OAuthAppUpdater setIamV1AccountVendorOauthAppUpdateRequest( + final OAuthApp.IamV1AccountVendorOauthAppUpdateRequest iamV1AccountVendorOauthAppUpdateRequest + ) { + this.iamV1AccountVendorOauthAppUpdateRequest = + iamV1AccountVendorOauthAppUpdateRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Account/OAuthApps/{sid}"; + + path = path.replace("{" + "sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.IAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OAuthApp update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public OAuthApp update(final TwilioRestClient client) { + Response response = makeRequest(client); + return OAuthApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OAuthApp content = OAuthApp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (iamV1AccountVendorOauthAppUpdateRequest != null) { + request.setBody( + OAuthApp.toJson( + iamV1AccountVendorOauthAppUpdateRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/RolePermission.java b/src/main/java/com/twilio/rest/iam/v1/RolePermission.java new file mode 100644 index 0000000000..fae32d5a14 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/RolePermission.java @@ -0,0 +1,167 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class RolePermission extends Resource { + + public static RolePermissionReader reader(final String pathRoleSid) { + return new RolePermissionReader(pathRoleSid); + } + + /** + * Converts a JSON String into a RolePermission object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return RolePermission object represented by the provided JSON + */ + public static RolePermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RolePermission.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a RolePermission object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return RolePermission object represented by the provided JSON + */ + public static RolePermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RolePermission.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String action; + + @Getter + private final String externalDescription; + + @Getter + private final String namespace; + + @Getter + private final String product; + + @Getter + private final String resource; + + @Getter + private final String sid; + + @JsonCreator + private RolePermission( + @JsonProperty("action") final String action, + @JsonProperty("externalDescription") final String externalDescription, + @JsonProperty("namespace") final String namespace, + @JsonProperty("product") final String product, + @JsonProperty("resource") final String resource, + @JsonProperty("sid") final String sid + ) { + this.action = action; + this.externalDescription = externalDescription; + this.namespace = namespace; + this.product = product; + this.resource = resource; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RolePermission other = (RolePermission) o; + return ( + Objects.equals(action, other.action) && + Objects.equals(externalDescription, other.externalDescription) && + Objects.equals(namespace, other.namespace) && + Objects.equals(product, other.product) && + Objects.equals(resource, other.resource) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + action, + externalDescription, + namespace, + product, + resource, + sid + ); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/RolePermissionReader.java b/src/main/java/com/twilio/rest/iam/v1/RolePermissionReader.java new file mode 100644 index 0000000000..e1c31d8e8f --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/RolePermissionReader.java @@ -0,0 +1,209 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RolePermissionReader extends Reader { + + private String pathRoleSid; + private Integer pageSize; + + public RolePermissionReader(final String pathRoleSid) { + this.pathRoleSid = pathRoleSid; + } + + public RolePermissionReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "permissions", + response.getContent(), + RolePermission.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Roles/{RoleSid}/Permissions"; + + path = path.replace("{" + "RoleSid" + "}", this.pathRoleSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.IAM.toString(), + path + ); + request.setAuth(NoAuthStrategy.getInstance()); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "permissions", + response.getContent(), + RolePermission.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "RolePermission read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "permissions", + response.getContent(), + RolePermission.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/Token.java b/src/main/java/com/twilio/rest/iam/v1/Token.java new file mode 100644 index 0000000000..793fd22271 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/Token.java @@ -0,0 +1,163 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Token extends Resource { + + public static TokenCreator creator( + final String grantType, + final String clientId + ) { + return new TokenCreator(grantType, clientId); + } + + /** + * Converts a JSON String into a Token object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Token.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Token object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Token.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accessToken; + + @Getter + private final Long expiresIn; + + @Getter + private final String idToken; + + @Getter + private final String refreshToken; + + @Getter + private final String tokenType; + + @JsonCreator + private Token( + @JsonProperty("access_token") final String accessToken, + @JsonProperty("expires_in") final Long expiresIn, + @JsonProperty("id_token") final String idToken, + @JsonProperty("refresh_token") final String refreshToken, + @JsonProperty("token_type") final String tokenType + ) { + this.accessToken = accessToken; + this.expiresIn = expiresIn; + this.idToken = idToken; + this.refreshToken = refreshToken; + this.tokenType = tokenType; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Token other = (Token) o; + return ( + Objects.equals(accessToken, other.accessToken) && + Objects.equals(expiresIn, other.expiresIn) && + Objects.equals(idToken, other.idToken) && + Objects.equals(refreshToken, other.refreshToken) && + Objects.equals(tokenType, other.tokenType) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accessToken, + expiresIn, + idToken, + refreshToken, + tokenType + ); + } +} diff --git a/src/main/java/com/twilio/rest/iam/v1/TokenCreator.java b/src/main/java/com/twilio/rest/iam/v1/TokenCreator.java new file mode 100644 index 0000000000..8b1d747c34 --- /dev/null +++ b/src/main/java/com/twilio/rest/iam/v1/TokenCreator.java @@ -0,0 +1,220 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.iam.v1; + +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TokenCreator extends Creator { + + private String grantType; + private String clientId; + private String clientSecret; + private String code; + private String redirectUri; + private String audience; + private String refreshToken; + private String scope; + + public TokenCreator(final String grantType, final String clientId) { + this.grantType = grantType; + this.clientId = clientId; + } + + public TokenCreator setGrantType(final String grantType) { + this.grantType = grantType; + return this; + } + + public TokenCreator setClientId(final String clientId) { + this.clientId = clientId; + return this; + } + + public TokenCreator setClientSecret(final String clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + public TokenCreator setCode(final String code) { + this.code = code; + return this; + } + + public TokenCreator setRedirectUri(final String redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + public TokenCreator setAudience(final String audience) { + this.audience = audience; + return this; + } + + public TokenCreator setRefreshToken(final String refreshToken) { + this.refreshToken = refreshToken; + return this; + } + + public TokenCreator setScope(final String scope) { + this.scope = scope; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/token"; + + Request request = new Request( + HttpMethod.POST, + Domains.IAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + request.setAuth(NoAuthStrategy.getInstance()); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Token creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Token create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Token.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Token content = Token.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (grantType != null) { + Serializer.toString( + request, + "grant_type", + grantType, + ParameterType.URLENCODED + ); + } + + if (clientId != null) { + Serializer.toString( + request, + "client_id", + clientId, + ParameterType.URLENCODED + ); + } + + if (clientSecret != null) { + Serializer.toString( + request, + "client_secret", + clientSecret, + ParameterType.URLENCODED + ); + } + + if (code != null) { + Serializer.toString( + request, + "code", + code, + ParameterType.URLENCODED + ); + } + + if (redirectUri != null) { + Serializer.toString( + request, + "redirect_uri", + redirectUri, + ParameterType.URLENCODED + ); + } + + if (audience != null) { + Serializer.toString( + request, + "audience", + audience, + ParameterType.URLENCODED + ); + } + + if (refreshToken != null) { + Serializer.toString( + request, + "refresh_token", + refreshToken, + ParameterType.URLENCODED + ); + } + + if (scope != null) { + Serializer.toString( + request, + "scope", + scope, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/Call.java b/src/main/java/com/twilio/rest/insights/v1/Call.java new file mode 100644 index 0000000000..000bc1163c --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/Call.java @@ -0,0 +1,144 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Call extends Resource { + + public static CallFetcher fetcher(final String pathSid) { + return new CallFetcher(pathSid); + } + + /** + * Converts a JSON String into a Call object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Call object represented by the provided JSON + */ + public static Call fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Call.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Call object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Call object represented by the provided JSON + */ + public static Call fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Call.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Call( + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.links = links; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Call other = (Call) o; + return ( + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(links, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/CallFetcher.java b/src/main/java/com/twilio/rest/insights/v1/CallFetcher.java new file mode 100644 index 0000000000..6de9e1857d --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/CallFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CallFetcher extends Fetcher { + + private String pathSid; + + public CallFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Voice/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Call fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Call fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Call.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Call content = Call.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/CallSummaries.java b/src/main/java/com/twilio/rest/insights/v1/CallSummaries.java new file mode 100644 index 0000000000..ec3de74d69 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/CallSummaries.java @@ -0,0 +1,1138 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CallSummaries extends Resource { + + public static CallSummariesReader reader() { + return new CallSummariesReader(); + } + + public enum SortBy { + START_TIME("start_time"), + END_TIME("end_time"); + + private final String value; + + private SortBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static SortBy forValue(final String value) { + return Promoter.enumFromString(value, SortBy.values()); + } + } + + public enum CallType { + CARRIER("carrier"), + SIP("sip"), + TRUNKING("trunking"), + CLIENT("client"), + WHATSAPP("whatsapp"); + + private final String value; + + private CallType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallType forValue(final String value) { + return Promoter.enumFromString(value, CallType.values()); + } + } + + public enum ProcessingStateRequest { + COMPLETED("completed"), + STARTED("started"), + PARTIAL("partial"), + ALL("all"); + + private final String value; + + private ProcessingStateRequest(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ProcessingStateRequest forValue(final String value) { + return Promoter.enumFromString( + value, + ProcessingStateRequest.values() + ); + } + } + + public enum CallState { + RINGING("ringing"), + COMPLETED("completed"), + BUSY("busy"), + FAIL("fail"), + NOANSWER("noanswer"), + CANCELED("canceled"), + ANSWERED("answered"), + UNDIALED("undialed"); + + private final String value; + + private CallState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallState forValue(final String value) { + return Promoter.enumFromString(value, CallState.values()); + } + } + + public enum AnsweredBy { + UNKNOWN("unknown"), + MACHINE_START("machine_start"), + MACHINE_END_BEEP("machine_end_beep"), + MACHINE_END_SILENCE("machine_end_silence"), + MACHINE_END_OTHER("machine_end_other"), + HUMAN("human"), + FAX("fax"); + + private final String value; + + private AnsweredBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static AnsweredBy forValue(final String value) { + return Promoter.enumFromString(value, AnsweredBy.values()); + } + } + + public enum ProcessingState { + COMPLETE("complete"), + PARTIAL("partial"); + + private final String value; + + private ProcessingState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ProcessingState forValue(final String value) { + return Promoter.enumFromString(value, ProcessingState.values()); + } + } + + public enum CallSummaryCrelaySessionState { + UNKNOWN("unknown"), + FAILURE("failure"), + ENDED("ended"), + HUNG_UP("hung_up"); + + private final String value; + + private CallSummaryCrelaySessionState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallSummaryCrelaySessionState forValue( + final String value + ) { + return Promoter.enumFromString( + value, + CallSummaryCrelaySessionState.values() + ); + } + } + + @JsonDeserialize(builder = CallSummaryCrelayRateStats.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryCrelayRateStats { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("min") + @Getter + private final Float min; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("max") + @Getter + private final Float max; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("avg") + @Getter + private final Float avg; + + private CallSummaryCrelayRateStats(Builder builder) { + this.min = builder.min; + this.max = builder.max; + this.avg = builder.avg; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryCrelayRateStats fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryCrelayRateStats.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("min") + private Float min; + + @JsonProperty("max") + private Float max; + + @JsonProperty("avg") + private Float avg; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("min") + public Builder min(Float min) { + this.min = min; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("max") + public Builder max(Float max) { + this.max = max; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("avg") + public Builder avg(Float avg) { + this.avg = avg; + return this; + } + + public CallSummaryCrelayRateStats build() { + return new CallSummaryCrelayRateStats(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryCrelayRateStats other = (CallSummaryCrelayRateStats) o; + return ( + Objects.equals(min, other.min) && + Objects.equals(max, other.max) && + Objects.equals(avg, other.avg) + ); + } + + @Override + public int hashCode() { + return Objects.hash(min, max, avg); + } + } + + @JsonDeserialize(builder = CallSummaryCrelayInterruptions.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryCrelayInterruptions { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_to_agent") + @Getter + private final Integer customerToAgent; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("agent_to_customer") + @Getter + private final Integer agentToCustomer; + + private CallSummaryCrelayInterruptions(Builder builder) { + this.customerToAgent = builder.customerToAgent; + this.agentToCustomer = builder.agentToCustomer; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryCrelayInterruptions fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryCrelayInterruptions.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("customer_to_agent") + private Integer customerToAgent; + + @JsonProperty("agent_to_customer") + private Integer agentToCustomer; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_to_agent") + public Builder customerToAgent(Integer customerToAgent) { + this.customerToAgent = customerToAgent; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("agent_to_customer") + public Builder agentToCustomer(Integer agentToCustomer) { + this.agentToCustomer = agentToCustomer; + return this; + } + + public CallSummaryCrelayInterruptions build() { + return new CallSummaryCrelayInterruptions(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryCrelayInterruptions other = + (CallSummaryCrelayInterruptions) o; + return ( + Objects.equals(customerToAgent, other.customerToAgent) && + Objects.equals(agentToCustomer, other.agentToCustomer) + ); + } + + @Override + public int hashCode() { + return Objects.hash(customerToAgent, agentToCustomer); + } + } + + @JsonDeserialize(builder = CallSummaryCrelayTokenStats.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryCrelayTokenStats { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total") + @Getter + private final Integer total; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tokens_per_second") + @Getter + private final CallSummaryCrelayRateStats tokensPerSecond; + + private CallSummaryCrelayTokenStats(Builder builder) { + this.total = builder.total; + this.tokensPerSecond = builder.tokensPerSecond; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryCrelayTokenStats fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryCrelayTokenStats.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total") + private Integer total; + + @JsonProperty("tokens_per_second") + private CallSummaryCrelayRateStats tokensPerSecond; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total") + public Builder total(Integer total) { + this.total = total; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tokens_per_second") + public Builder tokensPerSecond( + CallSummaryCrelayRateStats tokensPerSecond + ) { + this.tokensPerSecond = tokensPerSecond; + return this; + } + + public CallSummaryCrelayTokenStats build() { + return new CallSummaryCrelayTokenStats(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryCrelayTokenStats other = (CallSummaryCrelayTokenStats) o; + return ( + Objects.equals(total, other.total) && + Objects.equals(tokensPerSecond, other.tokensPerSecond) + ); + } + + @Override + public int hashCode() { + return Objects.hash(total, tokensPerSecond); + } + } + + @JsonDeserialize(builder = CallSummaryAgentSessionSummary.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryAgentSessionSummary { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_id") + @Getter + private final String sessionId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_latency_ms") + @Getter + private final CallSummaryCrelayRateStats ttsLatencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stt_latency_ms") + @Getter + private final CallSummaryCrelayRateStats sttLatencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("network_latency_ms") + @Getter + private final CallSummaryCrelayRateStats networkLatencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_to_first_audio_ms") + @Getter + private final CallSummaryCrelayRateStats timeToFirstAudioMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("application_latency_ms") + @Getter + private final CallSummaryCrelayRateStats applicationLatencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tokens") + @Getter + private final CallSummaryCrelayTokenStats tokens; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words") + @Getter + private final CallSummaryCrelayWordStats words; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("turns") + @Getter + private final Integer turns; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("interruptions") + @Getter + private final CallSummaryCrelayInterruptions interruptions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_state") + @Getter + private final CallSummaries.CallSummaryCrelaySessionState sessionState; + + private CallSummaryAgentSessionSummary(Builder builder) { + this.sessionId = builder.sessionId; + this.ttsLatencyMs = builder.ttsLatencyMs; + this.sttLatencyMs = builder.sttLatencyMs; + this.networkLatencyMs = builder.networkLatencyMs; + this.timeToFirstAudioMs = builder.timeToFirstAudioMs; + this.applicationLatencyMs = builder.applicationLatencyMs; + this.tokens = builder.tokens; + this.words = builder.words; + this.turns = builder.turns; + this.interruptions = builder.interruptions; + this.sessionState = builder.sessionState; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryAgentSessionSummary fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryAgentSessionSummary.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("session_id") + private String sessionId; + + @JsonProperty("tts_latency_ms") + private CallSummaryCrelayRateStats ttsLatencyMs; + + @JsonProperty("stt_latency_ms") + private CallSummaryCrelayRateStats sttLatencyMs; + + @JsonProperty("network_latency_ms") + private CallSummaryCrelayRateStats networkLatencyMs; + + @JsonProperty("time_to_first_audio_ms") + private CallSummaryCrelayRateStats timeToFirstAudioMs; + + @JsonProperty("application_latency_ms") + private CallSummaryCrelayRateStats applicationLatencyMs; + + @JsonProperty("tokens") + private CallSummaryCrelayTokenStats tokens; + + @JsonProperty("words") + private CallSummaryCrelayWordStats words; + + @JsonProperty("turns") + private Integer turns; + + @JsonProperty("interruptions") + private CallSummaryCrelayInterruptions interruptions; + + @JsonProperty("session_state") + private CallSummaries.CallSummaryCrelaySessionState sessionState; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_id") + public Builder sessionId(String sessionId) { + this.sessionId = sessionId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_latency_ms") + public Builder ttsLatencyMs( + CallSummaryCrelayRateStats ttsLatencyMs + ) { + this.ttsLatencyMs = ttsLatencyMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stt_latency_ms") + public Builder sttLatencyMs( + CallSummaryCrelayRateStats sttLatencyMs + ) { + this.sttLatencyMs = sttLatencyMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("network_latency_ms") + public Builder networkLatencyMs( + CallSummaryCrelayRateStats networkLatencyMs + ) { + this.networkLatencyMs = networkLatencyMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_to_first_audio_ms") + public Builder timeToFirstAudioMs( + CallSummaryCrelayRateStats timeToFirstAudioMs + ) { + this.timeToFirstAudioMs = timeToFirstAudioMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("application_latency_ms") + public Builder applicationLatencyMs( + CallSummaryCrelayRateStats applicationLatencyMs + ) { + this.applicationLatencyMs = applicationLatencyMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tokens") + public Builder tokens(CallSummaryCrelayTokenStats tokens) { + this.tokens = tokens; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words") + public Builder words(CallSummaryCrelayWordStats words) { + this.words = words; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("turns") + public Builder turns(Integer turns) { + this.turns = turns; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("interruptions") + public Builder interruptions( + CallSummaryCrelayInterruptions interruptions + ) { + this.interruptions = interruptions; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_state") + public Builder sessionState( + CallSummaries.CallSummaryCrelaySessionState sessionState + ) { + this.sessionState = sessionState; + return this; + } + + public CallSummaryAgentSessionSummary build() { + return new CallSummaryAgentSessionSummary(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryAgentSessionSummary other = + (CallSummaryAgentSessionSummary) o; + return ( + Objects.equals(sessionId, other.sessionId) && + Objects.equals(ttsLatencyMs, other.ttsLatencyMs) && + Objects.equals(sttLatencyMs, other.sttLatencyMs) && + Objects.equals(networkLatencyMs, other.networkLatencyMs) && + Objects.equals(timeToFirstAudioMs, other.timeToFirstAudioMs) && + Objects.equals( + applicationLatencyMs, + other.applicationLatencyMs + ) && + Objects.equals(tokens, other.tokens) && + Objects.equals(words, other.words) && + Objects.equals(turns, other.turns) && + Objects.equals(interruptions, other.interruptions) && + Objects.equals(sessionState, other.sessionState) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + sessionId, + ttsLatencyMs, + sttLatencyMs, + networkLatencyMs, + timeToFirstAudioMs, + applicationLatencyMs, + tokens, + words, + turns, + interruptions, + sessionState + ); + } + } + + @JsonDeserialize(builder = CallSummaryCrelayWordStats.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryCrelayWordStats { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total") + @Getter + private final Integer total; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words_per_minute") + @Getter + private final CallSummaryCrelayRateStats wordsPerMinute; + + private CallSummaryCrelayWordStats(Builder builder) { + this.total = builder.total; + this.wordsPerMinute = builder.wordsPerMinute; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryCrelayWordStats fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryCrelayWordStats.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total") + private Integer total; + + @JsonProperty("words_per_minute") + private CallSummaryCrelayRateStats wordsPerMinute; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total") + public Builder total(Integer total) { + this.total = total; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words_per_minute") + public Builder wordsPerMinute( + CallSummaryCrelayRateStats wordsPerMinute + ) { + this.wordsPerMinute = wordsPerMinute; + return this; + } + + public CallSummaryCrelayWordStats build() { + return new CallSummaryCrelayWordStats(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryCrelayWordStats other = (CallSummaryCrelayWordStats) o; + return ( + Objects.equals(total, other.total) && + Objects.equals(wordsPerMinute, other.wordsPerMinute) + ); + } + + @Override + public int hashCode() { + return Objects.hash(total, wordsPerMinute); + } + } + + /** + * Converts a JSON String into a CallSummaries object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CallSummaries object represented by the provided JSON + */ + public static CallSummaries fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CallSummaries.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CallSummaries object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CallSummaries object represented by the provided JSON + */ + public static CallSummaries fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CallSummaries.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final List agentSessionSummaries; + + @Getter + private final Object annotation; + + @Getter + private final CallSummaries.AnsweredBy answeredBy; + + @Getter + private final Object attributes; + + @Getter + private final String callSid; + + @Getter + private final CallSummaries.CallState callState; + + @Getter + private final CallSummaries.CallType callType; + + @Getter + private final Object carrierEdge; + + @Getter + private final Object clientEdge; + + @Getter + private final Integer connectDuration; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime createdTime; + + @Getter + private final Integer duration; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; + + @Getter + private final Object from; + + @Getter + private final CallSummaries.ProcessingState processingState; + + @Getter + private final Object properties; + + @Getter + private final Object sdkEdge; + + @Getter + private final Object sipEdge; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime startTime; + + @Getter + private final List tags; + + @Getter + private final Object to; + + @Getter + private final Object trust; + + @Getter + private final URI url; + + @JsonCreator + private CallSummaries( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("agent_session_summaries") final List< + CallSummaryAgentSessionSummary + > agentSessionSummaries, + @JsonProperty("annotation") final Object annotation, + @JsonProperty("answered_by") final CallSummaries.AnsweredBy answeredBy, + @JsonProperty("attributes") final Object attributes, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("call_state") final CallSummaries.CallState callState, + @JsonProperty("call_type") final CallSummaries.CallType callType, + @JsonProperty("carrier_edge") final Object carrierEdge, + @JsonProperty("client_edge") final Object clientEdge, + @JsonProperty("connect_duration") final Integer connectDuration, + @JsonProperty("created_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime createdTime, + @JsonProperty("duration") final Integer duration, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty("from") final Object from, + @JsonProperty( + "processing_state" + ) final CallSummaries.ProcessingState processingState, + @JsonProperty("properties") final Object properties, + @JsonProperty("sdk_edge") final Object sdkEdge, + @JsonProperty("sip_edge") final Object sipEdge, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime startTime, + @JsonProperty("tags") final List tags, + @JsonProperty("to") final Object to, + @JsonProperty("trust") final Object trust, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.agentSessionSummaries = agentSessionSummaries; + this.annotation = annotation; + this.answeredBy = answeredBy; + this.attributes = attributes; + this.callSid = callSid; + this.callState = callState; + this.callType = callType; + this.carrierEdge = carrierEdge; + this.clientEdge = clientEdge; + this.connectDuration = connectDuration; + this.createdTime = createdTime; + this.duration = duration; + this.endTime = endTime; + this.from = from; + this.processingState = processingState; + this.properties = properties; + this.sdkEdge = sdkEdge; + this.sipEdge = sipEdge; + this.startTime = startTime; + this.tags = tags; + this.to = to; + this.trust = trust; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaries other = (CallSummaries) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + agentSessionSummaries, + other.agentSessionSummaries + ) && + Objects.equals(annotation, other.annotation) && + Objects.equals(answeredBy, other.answeredBy) && + Objects.equals(attributes, other.attributes) && + Objects.equals(callSid, other.callSid) && + Objects.equals(callState, other.callState) && + Objects.equals(callType, other.callType) && + Objects.equals(carrierEdge, other.carrierEdge) && + Objects.equals(clientEdge, other.clientEdge) && + Objects.equals(connectDuration, other.connectDuration) && + Objects.equals(createdTime, other.createdTime) && + Objects.equals(duration, other.duration) && + Objects.equals(endTime, other.endTime) && + Objects.equals(from, other.from) && + Objects.equals(processingState, other.processingState) && + Objects.equals(properties, other.properties) && + Objects.equals(sdkEdge, other.sdkEdge) && + Objects.equals(sipEdge, other.sipEdge) && + Objects.equals(startTime, other.startTime) && + Objects.equals(tags, other.tags) && + Objects.equals(to, other.to) && + Objects.equals(trust, other.trust) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + agentSessionSummaries, + annotation, + answeredBy, + attributes, + callSid, + callState, + callType, + carrierEdge, + clientEdge, + connectDuration, + createdTime, + duration, + endTime, + from, + processingState, + properties, + sdkEdge, + sipEdge, + startTime, + tags, + to, + trust, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/CallSummariesReader.java b/src/main/java/com/twilio/rest/insights/v1/CallSummariesReader.java new file mode 100644 index 0000000000..3df478da4d --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/CallSummariesReader.java @@ -0,0 +1,756 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CallSummariesReader extends Reader { + + private String from; + private String to; + private String fromCarrier; + private String toCarrier; + private String fromCountryCode; + private String toCountryCode; + private Boolean verifiedCaller; + private Boolean hasTag; + private String startTime; + private String endTime; + private String callType; + private String callState; + private String direction; + private CallSummaries.ProcessingStateRequest processingState; + private CallSummaries.SortBy sortBy; + private String subaccount; + private Boolean abnormalSession; + private CallSummaries.AnsweredBy answeredBy; + private String answeredByAnnotation; + private String connectivityIssueAnnotation; + private String qualityIssueAnnotation; + private Boolean spamAnnotation; + private String callScoreAnnotation; + private Boolean brandedEnabled; + private Boolean voiceIntegrityEnabled; + private String brandedBundleSid; + private Boolean brandedLogo; + private String brandedType; + private String brandedUseCase; + private String brandedCallReason; + private String voiceIntegrityBundleSid; + private String voiceIntegrityUseCase; + private String businessProfileIdentity; + private String businessProfileIndustry; + private String businessProfileBundleSid; + private String businessProfileType; + private Long pageSize; + + public CallSummariesReader() {} + + public CallSummariesReader setFrom(final String from) { + this.from = from; + return this; + } + + public CallSummariesReader setTo(final String to) { + this.to = to; + return this; + } + + public CallSummariesReader setFromCarrier(final String fromCarrier) { + this.fromCarrier = fromCarrier; + return this; + } + + public CallSummariesReader setToCarrier(final String toCarrier) { + this.toCarrier = toCarrier; + return this; + } + + public CallSummariesReader setFromCountryCode( + final String fromCountryCode + ) { + this.fromCountryCode = fromCountryCode; + return this; + } + + public CallSummariesReader setToCountryCode(final String toCountryCode) { + this.toCountryCode = toCountryCode; + return this; + } + + public CallSummariesReader setVerifiedCaller(final Boolean verifiedCaller) { + this.verifiedCaller = verifiedCaller; + return this; + } + + public CallSummariesReader setHasTag(final Boolean hasTag) { + this.hasTag = hasTag; + return this; + } + + public CallSummariesReader setStartTime(final String startTime) { + this.startTime = startTime; + return this; + } + + public CallSummariesReader setEndTime(final String endTime) { + this.endTime = endTime; + return this; + } + + public CallSummariesReader setCallType(final String callType) { + this.callType = callType; + return this; + } + + public CallSummariesReader setCallState(final String callState) { + this.callState = callState; + return this; + } + + public CallSummariesReader setDirection(final String direction) { + this.direction = direction; + return this; + } + + public CallSummariesReader setProcessingState( + final CallSummaries.ProcessingStateRequest processingState + ) { + this.processingState = processingState; + return this; + } + + public CallSummariesReader setSortBy(final CallSummaries.SortBy sortBy) { + this.sortBy = sortBy; + return this; + } + + public CallSummariesReader setSubaccount(final String subaccount) { + this.subaccount = subaccount; + return this; + } + + public CallSummariesReader setAbnormalSession( + final Boolean abnormalSession + ) { + this.abnormalSession = abnormalSession; + return this; + } + + public CallSummariesReader setAnsweredBy( + final CallSummaries.AnsweredBy answeredBy + ) { + this.answeredBy = answeredBy; + return this; + } + + public CallSummariesReader setAnsweredByAnnotation( + final String answeredByAnnotation + ) { + this.answeredByAnnotation = answeredByAnnotation; + return this; + } + + public CallSummariesReader setConnectivityIssueAnnotation( + final String connectivityIssueAnnotation + ) { + this.connectivityIssueAnnotation = connectivityIssueAnnotation; + return this; + } + + public CallSummariesReader setQualityIssueAnnotation( + final String qualityIssueAnnotation + ) { + this.qualityIssueAnnotation = qualityIssueAnnotation; + return this; + } + + public CallSummariesReader setSpamAnnotation(final Boolean spamAnnotation) { + this.spamAnnotation = spamAnnotation; + return this; + } + + public CallSummariesReader setCallScoreAnnotation( + final String callScoreAnnotation + ) { + this.callScoreAnnotation = callScoreAnnotation; + return this; + } + + public CallSummariesReader setBrandedEnabled(final Boolean brandedEnabled) { + this.brandedEnabled = brandedEnabled; + return this; + } + + public CallSummariesReader setVoiceIntegrityEnabled( + final Boolean voiceIntegrityEnabled + ) { + this.voiceIntegrityEnabled = voiceIntegrityEnabled; + return this; + } + + public CallSummariesReader setBrandedBundleSid( + final String brandedBundleSid + ) { + this.brandedBundleSid = brandedBundleSid; + return this; + } + + public CallSummariesReader setBrandedLogo(final Boolean brandedLogo) { + this.brandedLogo = brandedLogo; + return this; + } + + public CallSummariesReader setBrandedType(final String brandedType) { + this.brandedType = brandedType; + return this; + } + + public CallSummariesReader setBrandedUseCase(final String brandedUseCase) { + this.brandedUseCase = brandedUseCase; + return this; + } + + public CallSummariesReader setBrandedCallReason( + final String brandedCallReason + ) { + this.brandedCallReason = brandedCallReason; + return this; + } + + public CallSummariesReader setVoiceIntegrityBundleSid( + final String voiceIntegrityBundleSid + ) { + this.voiceIntegrityBundleSid = voiceIntegrityBundleSid; + return this; + } + + public CallSummariesReader setVoiceIntegrityUseCase( + final String voiceIntegrityUseCase + ) { + this.voiceIntegrityUseCase = voiceIntegrityUseCase; + return this; + } + + public CallSummariesReader setBusinessProfileIdentity( + final String businessProfileIdentity + ) { + this.businessProfileIdentity = businessProfileIdentity; + return this; + } + + public CallSummariesReader setBusinessProfileIndustry( + final String businessProfileIndustry + ) { + this.businessProfileIndustry = businessProfileIndustry; + return this; + } + + public CallSummariesReader setBusinessProfileBundleSid( + final String businessProfileBundleSid + ) { + this.businessProfileBundleSid = businessProfileBundleSid; + return this; + } + + public CallSummariesReader setBusinessProfileType( + final String businessProfileType + ) { + this.businessProfileType = businessProfileType; + return this; + } + + public CallSummariesReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "call_summaries", + response.getContent(), + CallSummaries.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Voice/Summaries"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "call_summaries", + response.getContent(), + CallSummaries.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CallSummaries read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "call_summaries", + response.getContent(), + CallSummaries.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (from != null) { + Serializer.toString(request, "From", from, ParameterType.QUERY); + } + + if (to != null) { + Serializer.toString(request, "To", to, ParameterType.QUERY); + } + + if (fromCarrier != null) { + Serializer.toString( + request, + "FromCarrier", + fromCarrier, + ParameterType.QUERY + ); + } + + if (toCarrier != null) { + Serializer.toString( + request, + "ToCarrier", + toCarrier, + ParameterType.QUERY + ); + } + + if (fromCountryCode != null) { + Serializer.toString( + request, + "FromCountryCode", + fromCountryCode, + ParameterType.QUERY + ); + } + + if (toCountryCode != null) { + Serializer.toString( + request, + "ToCountryCode", + toCountryCode, + ParameterType.QUERY + ); + } + + if (verifiedCaller != null) { + Serializer.toString( + request, + "VerifiedCaller", + verifiedCaller, + ParameterType.QUERY + ); + } + + if (hasTag != null) { + Serializer.toString(request, "HasTag", hasTag, ParameterType.QUERY); + } + + if (startTime != null) { + Serializer.toString( + request, + "StartTime", + startTime, + ParameterType.QUERY + ); + } + + if (endTime != null) { + Serializer.toString( + request, + "EndTime", + endTime, + ParameterType.QUERY + ); + } + + if (callType != null) { + Serializer.toString( + request, + "CallType", + callType, + ParameterType.QUERY + ); + } + + if (callState != null) { + Serializer.toString( + request, + "CallState", + callState, + ParameterType.QUERY + ); + } + + if (direction != null) { + Serializer.toString( + request, + "Direction", + direction, + ParameterType.QUERY + ); + } + + if (processingState != null) { + Serializer.toString( + request, + "ProcessingState", + processingState, + ParameterType.QUERY + ); + } + + if (sortBy != null) { + Serializer.toString(request, "SortBy", sortBy, ParameterType.QUERY); + } + + if (subaccount != null) { + Serializer.toString( + request, + "Subaccount", + subaccount, + ParameterType.QUERY + ); + } + + if (abnormalSession != null) { + Serializer.toString( + request, + "AbnormalSession", + abnormalSession, + ParameterType.QUERY + ); + } + + if (answeredBy != null) { + Serializer.toString( + request, + "AnsweredBy", + answeredBy, + ParameterType.QUERY + ); + } + + if (answeredByAnnotation != null) { + Serializer.toString( + request, + "AnsweredByAnnotation", + answeredByAnnotation, + ParameterType.QUERY + ); + } + + if (connectivityIssueAnnotation != null) { + Serializer.toString( + request, + "ConnectivityIssueAnnotation", + connectivityIssueAnnotation, + ParameterType.QUERY + ); + } + + if (qualityIssueAnnotation != null) { + Serializer.toString( + request, + "QualityIssueAnnotation", + qualityIssueAnnotation, + ParameterType.QUERY + ); + } + + if (spamAnnotation != null) { + Serializer.toString( + request, + "SpamAnnotation", + spamAnnotation, + ParameterType.QUERY + ); + } + + if (callScoreAnnotation != null) { + Serializer.toString( + request, + "CallScoreAnnotation", + callScoreAnnotation, + ParameterType.QUERY + ); + } + + if (brandedEnabled != null) { + Serializer.toString( + request, + "BrandedEnabled", + brandedEnabled, + ParameterType.QUERY + ); + } + + if (voiceIntegrityEnabled != null) { + Serializer.toString( + request, + "VoiceIntegrityEnabled", + voiceIntegrityEnabled, + ParameterType.QUERY + ); + } + + if (brandedBundleSid != null) { + Serializer.toString( + request, + "BrandedBundleSid", + brandedBundleSid, + ParameterType.QUERY + ); + } + + if (brandedLogo != null) { + Serializer.toString( + request, + "BrandedLogo", + brandedLogo, + ParameterType.QUERY + ); + } + + if (brandedType != null) { + Serializer.toString( + request, + "BrandedType", + brandedType, + ParameterType.QUERY + ); + } + + if (brandedUseCase != null) { + Serializer.toString( + request, + "BrandedUseCase", + brandedUseCase, + ParameterType.QUERY + ); + } + + if (brandedCallReason != null) { + Serializer.toString( + request, + "BrandedCallReason", + brandedCallReason, + ParameterType.QUERY + ); + } + + if (voiceIntegrityBundleSid != null) { + Serializer.toString( + request, + "VoiceIntegrityBundleSid", + voiceIntegrityBundleSid, + ParameterType.QUERY + ); + } + + if (voiceIntegrityUseCase != null) { + Serializer.toString( + request, + "VoiceIntegrityUseCase", + voiceIntegrityUseCase, + ParameterType.QUERY + ); + } + + if (businessProfileIdentity != null) { + Serializer.toString( + request, + "BusinessProfileIdentity", + businessProfileIdentity, + ParameterType.QUERY + ); + } + + if (businessProfileIndustry != null) { + Serializer.toString( + request, + "BusinessProfileIndustry", + businessProfileIndustry, + ParameterType.QUERY + ); + } + + if (businessProfileBundleSid != null) { + Serializer.toString( + request, + "BusinessProfileBundleSid", + businessProfileBundleSid, + ParameterType.QUERY + ); + } + + if (businessProfileType != null) { + Serializer.toString( + request, + "BusinessProfileType", + businessProfileType, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/Conference.java b/src/main/java/com/twilio/rest/insights/v1/Conference.java new file mode 100644 index 0000000000..adc096f6fe --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/Conference.java @@ -0,0 +1,492 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Conference extends Resource { + + public static ConferenceFetcher fetcher(final String pathConferenceSid) { + return new ConferenceFetcher(pathConferenceSid); + } + + public static ConferenceReader reader() { + return new ConferenceReader(); + } + + public enum ConferenceStatus { + IN_PROGRESS("in_progress"), + NOT_STARTED("not_started"), + COMPLETED("completed"), + SUMMARY_TIMEOUT("summary_timeout"); + + private final String value; + + private ConferenceStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConferenceStatus forValue(final String value) { + return Promoter.enumFromString(value, ConferenceStatus.values()); + } + } + + public enum ConferenceEndReason { + LAST_PARTICIPANT_LEFT("last_participant_left"), + CONFERENCE_ENDED_VIA_API("conference_ended_via_api"), + PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_LEFT( + "participant_with_end_conference_on_exit_left" + ), + LAST_PARTICIPANT_KICKED("last_participant_kicked"), + PARTICIPANT_WITH_END_CONFERENCE_ON_EXIT_KICKED( + "participant_with_end_conference_on_exit_kicked" + ); + + private final String value; + + private ConferenceEndReason(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConferenceEndReason forValue(final String value) { + return Promoter.enumFromString(value, ConferenceEndReason.values()); + } + } + + public enum ConferenceTag { + INVALID_REQUESTED_REGION("invalid_requested_region"), + DUPLICATE_IDENTITY("duplicate_identity"), + START_FAILURE("start_failure"), + REGION_CONFIGURATION_ISSUES("region_configuration_issues"), + QUALITY_WARNINGS("quality_warnings"), + PARTICIPANT_BEHAVIOR_ISSUES("participant_behavior_issues"), + HIGH_PACKET_LOSS("high_packet_loss"), + HIGH_JITTER("high_jitter"), + HIGH_LATENCY("high_latency"), + LOW_MOS("low_mos"), + DETECTED_SILENCE("detected_silence"), + NO_CONCURRENT_PARTICIPANTS("no_concurrent_participants"); + + private final String value; + + private ConferenceTag(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConferenceTag forValue(final String value) { + return Promoter.enumFromString(value, ConferenceTag.values()); + } + } + + public enum Region { + US1("us1"), + US2("us2"), + AU1("au1"), + BR1("br1"), + IE1("ie1"), + JP1("jp1"), + SG1("sg1"), + DE1("de1"), + IN1("in1"); + + private final String value; + + private Region(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Region forValue(final String value) { + return Promoter.enumFromString(value, Region.values()); + } + } + + public enum Tag { + INVALID_REQUESTED_REGION("invalid_requested_region"), + DUPLICATE_IDENTITY("duplicate_identity"), + START_FAILURE("start_failure"), + REGION_CONFIGURATION_ISSUES("region_configuration_issues"), + QUALITY_WARNINGS("quality_warnings"), + PARTICIPANT_BEHAVIOR_ISSUES("participant_behavior_issues"), + HIGH_PACKET_LOSS("high_packet_loss"), + HIGH_JITTER("high_jitter"), + HIGH_LATENCY("high_latency"), + LOW_MOS("low_mos"), + DETECTED_SILENCE("detected_silence"), + NO_CONCURRENT_PARTICIPANTS("no_concurrent_participants"); + + private final String value; + + private Tag(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Tag forValue(final String value) { + return Promoter.enumFromString(value, Tag.values()); + } + } + + public enum ProcessingState { + COMPLETE("complete"), + IN_PROGRESS("in_progress"), + TIMEOUT("timeout"); + + private final String value; + + private ProcessingState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ProcessingState forValue(final String value) { + return Promoter.enumFromString(value, ProcessingState.values()); + } + } + + /** + * Converts a JSON String into a Conference object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conference object represented by the provided JSON + */ + public static Conference fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conference.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Conference object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conference object represented by the provided JSON + */ + public static Conference fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conference.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String conferenceSid; + + @Getter + private final Integer connectDurationSeconds; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime createTime; + + @Getter + private final Object detectedIssues; + + @Getter + private final Integer durationSeconds; + + @Getter + private final Conference.ConferenceEndReason endReason; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; + + @Getter + private final String endedBy; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final Integer maxConcurrentParticipants; + + @Getter + private final Integer maxParticipants; + + @Getter + private final Conference.Region mixerRegion; + + @Getter + private final Conference.Region mixerRegionRequested; + + @Getter + private final Conference.ProcessingState processingState; + + @Getter + private final Boolean recordingEnabled; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime startTime; + + @Getter + private final Conference.ConferenceStatus status; + + @Getter + private final Object tagInfo; + + @Getter + private final List tags; + + @Getter + private final Integer uniqueParticipants; + + @Getter + private final URI url; + + @JsonCreator + private Conference( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty( + "connect_duration_seconds" + ) final Integer connectDurationSeconds, + @JsonProperty("create_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime createTime, + @JsonProperty("detected_issues") final Object detectedIssues, + @JsonProperty("duration_seconds") final Integer durationSeconds, + @JsonProperty( + "end_reason" + ) final Conference.ConferenceEndReason endReason, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty("ended_by") final String endedBy, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty( + "max_concurrent_participants" + ) final Integer maxConcurrentParticipants, + @JsonProperty("max_participants") final Integer maxParticipants, + @JsonProperty("mixer_region") final Conference.Region mixerRegion, + @JsonProperty( + "mixer_region_requested" + ) final Conference.Region mixerRegionRequested, + @JsonProperty( + "processing_state" + ) final Conference.ProcessingState processingState, + @JsonProperty("recording_enabled") final Boolean recordingEnabled, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime startTime, + @JsonProperty("status") final Conference.ConferenceStatus status, + @JsonProperty("tag_info") final Object tagInfo, + @JsonProperty("tags") final List tags, + @JsonProperty("unique_participants") final Integer uniqueParticipants, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.conferenceSid = conferenceSid; + this.connectDurationSeconds = connectDurationSeconds; + this.createTime = createTime; + this.detectedIssues = detectedIssues; + this.durationSeconds = durationSeconds; + this.endReason = endReason; + this.endTime = endTime; + this.endedBy = endedBy; + this.friendlyName = friendlyName; + this.links = links; + this.maxConcurrentParticipants = maxConcurrentParticipants; + this.maxParticipants = maxParticipants; + this.mixerRegion = mixerRegion; + this.mixerRegionRequested = mixerRegionRequested; + this.processingState = processingState; + this.recordingEnabled = recordingEnabled; + this.startTime = startTime; + this.status = status; + this.tagInfo = tagInfo; + this.tags = tags; + this.uniqueParticipants = uniqueParticipants; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Conference other = (Conference) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals( + connectDurationSeconds, + other.connectDurationSeconds + ) && + Objects.equals(createTime, other.createTime) && + Objects.equals(detectedIssues, other.detectedIssues) && + Objects.equals(durationSeconds, other.durationSeconds) && + Objects.equals(endReason, other.endReason) && + Objects.equals(endTime, other.endTime) && + Objects.equals(endedBy, other.endedBy) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals( + maxConcurrentParticipants, + other.maxConcurrentParticipants + ) && + Objects.equals(maxParticipants, other.maxParticipants) && + Objects.equals(mixerRegion, other.mixerRegion) && + Objects.equals(mixerRegionRequested, other.mixerRegionRequested) && + Objects.equals(processingState, other.processingState) && + Objects.equals(recordingEnabled, other.recordingEnabled) && + Objects.equals(startTime, other.startTime) && + Objects.equals(status, other.status) && + Objects.equals(tagInfo, other.tagInfo) && + Objects.equals(tags, other.tags) && + Objects.equals(uniqueParticipants, other.uniqueParticipants) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + conferenceSid, + connectDurationSeconds, + createTime, + detectedIssues, + durationSeconds, + endReason, + endTime, + endedBy, + friendlyName, + links, + maxConcurrentParticipants, + maxParticipants, + mixerRegion, + mixerRegionRequested, + processingState, + recordingEnabled, + startTime, + status, + tagInfo, + tags, + uniqueParticipants, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/ConferenceFetcher.java b/src/main/java/com/twilio/rest/insights/v1/ConferenceFetcher.java new file mode 100644 index 0000000000..550cfcda00 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/ConferenceFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConferenceFetcher extends Fetcher { + + private String pathConferenceSid; + + public ConferenceFetcher(final String pathConferenceSid) { + this.pathConferenceSid = pathConferenceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Conferences/{ConferenceSid}"; + + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conference fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conference fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Conference content = Conference.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/ConferenceReader.java b/src/main/java/com/twilio/rest/insights/v1/ConferenceReader.java new file mode 100644 index 0000000000..39b41d58cc --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/ConferenceReader.java @@ -0,0 +1,342 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConferenceReader extends Reader { + + private String conferenceSid; + private String friendlyName; + private String status; + private String createdAfter; + private String createdBefore; + private String mixerRegion; + private String tags; + private String subaccount; + private String detectedIssues; + private String endReason; + private Long pageSize; + + public ConferenceReader() {} + + public ConferenceReader setConferenceSid(final String conferenceSid) { + this.conferenceSid = conferenceSid; + return this; + } + + public ConferenceReader setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ConferenceReader setStatus(final String status) { + this.status = status; + return this; + } + + public ConferenceReader setCreatedAfter(final String createdAfter) { + this.createdAfter = createdAfter; + return this; + } + + public ConferenceReader setCreatedBefore(final String createdBefore) { + this.createdBefore = createdBefore; + return this; + } + + public ConferenceReader setMixerRegion(final String mixerRegion) { + this.mixerRegion = mixerRegion; + return this; + } + + public ConferenceReader setTags(final String tags) { + this.tags = tags; + return this; + } + + public ConferenceReader setSubaccount(final String subaccount) { + this.subaccount = subaccount; + return this; + } + + public ConferenceReader setDetectedIssues(final String detectedIssues) { + this.detectedIssues = detectedIssues; + return this; + } + + public ConferenceReader setEndReason(final String endReason) { + this.endReason = endReason; + return this; + } + + public ConferenceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conferences", + response.getContent(), + Conference.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Conferences"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "conferences", + response.getContent(), + Conference.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Conference read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "conferences", + response.getContent(), + Conference.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (conferenceSid != null) { + Serializer.toString( + request, + "ConferenceSid", + conferenceSid, + ParameterType.QUERY + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (createdAfter != null) { + Serializer.toString( + request, + "CreatedAfter", + createdAfter, + ParameterType.QUERY + ); + } + + if (createdBefore != null) { + Serializer.toString( + request, + "CreatedBefore", + createdBefore, + ParameterType.QUERY + ); + } + + if (mixerRegion != null) { + Serializer.toString( + request, + "MixerRegion", + mixerRegion, + ParameterType.QUERY + ); + } + + if (tags != null) { + Serializer.toString(request, "Tags", tags, ParameterType.QUERY); + } + + if (subaccount != null) { + Serializer.toString( + request, + "Subaccount", + subaccount, + ParameterType.QUERY + ); + } + + if (detectedIssues != null) { + Serializer.toString( + request, + "DetectedIssues", + detectedIssues, + ParameterType.QUERY + ); + } + + if (endReason != null) { + Serializer.toString( + request, + "EndReason", + endReason, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/Room.java b/src/main/java/com/twilio/rest/insights/v1/Room.java new file mode 100644 index 0000000000..8c077a535a --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/Room.java @@ -0,0 +1,572 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.http.HttpMethod; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Room extends Resource { + + public static RoomFetcher fetcher(final String pathRoomSid) { + return new RoomFetcher(pathRoomSid); + } + + public static RoomReader reader() { + return new RoomReader(); + } + + public enum Codec { + VP8("VP8"), + H264("H264"), + VP9("VP9"), + OPUS("opus"); + + private final String value; + + private Codec(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Codec forValue(final String value) { + return Promoter.enumFromString(value, Codec.values()); + } + } + + public enum RoomType { + GO("go"), + PEER_TO_PEER("peer_to_peer"), + GROUP("group"), + GROUP_SMALL("group_small"); + + private final String value; + + private RoomType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RoomType forValue(final String value) { + return Promoter.enumFromString(value, RoomType.values()); + } + } + + public enum RoomStatus { + IN_PROGRESS("in_progress"), + COMPLETED("completed"); + + private final String value; + + private RoomStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RoomStatus forValue(final String value) { + return Promoter.enumFromString(value, RoomStatus.values()); + } + } + + public enum EndReason { + ROOM_ENDED_VIA_API("room_ended_via_api"), + TIMEOUT("timeout"); + + private final String value; + + private EndReason(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EndReason forValue(final String value) { + return Promoter.enumFromString(value, EndReason.values()); + } + } + + public enum TwilioRealm { + US1("us1"), + US2("us2"), + AU1("au1"), + BR1("br1"), + IE1("ie1"), + JP1("jp1"), + SG1("sg1"), + IN1("in1"), + DE1("de1"), + GLL("gll"); + + private final String value; + + private TwilioRealm(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TwilioRealm forValue(final String value) { + return Promoter.enumFromString(value, TwilioRealm.values()); + } + } + + public enum RoomCodec { + VP8("VP8"), + H264("H264"), + VP9("VP9"), + OPUS("opus"); + + private final String value; + + private RoomCodec(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RoomCodec forValue(final String value) { + return Promoter.enumFromString(value, RoomCodec.values()); + } + } + + public enum CreatedMethod { + SDK("sdk"), + AD_HOC("ad_hoc"), + API("api"); + + private final String value; + + private CreatedMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CreatedMethod forValue(final String value) { + return Promoter.enumFromString(value, CreatedMethod.values()); + } + } + + public enum ProcessingState { + COMPLETE("complete"), + IN_PROGRESS("in_progress"), + TIMEOUT("timeout"), + NOT_STARTED("not_started"); + + private final String value; + + private ProcessingState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ProcessingState forValue(final String value) { + return Promoter.enumFromString(value, ProcessingState.values()); + } + } + + public enum EdgeLocation { + ASHBURN("ashburn"), + DUBLIN("dublin"), + FRANKFURT("frankfurt"), + SINGAPORE("singapore"), + SYDNEY("sydney"), + SAO_PAULO("sao_paulo"), + ROAMING("roaming"), + UMATILLA("umatilla"), + TOKYO("tokyo"); + + private final String value; + + private EdgeLocation(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EdgeLocation forValue(final String value) { + return Promoter.enumFromString(value, EdgeLocation.values()); + } + } + + /** + * Converts a JSON String into a Room object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Room object represented by the provided JSON + */ + public static Room fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Room.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Room object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Room object represented by the provided JSON + */ + public static Room fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Room.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final List codecs; + + @Getter + private final Integer concurrentParticipants; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime createTime; + + @Getter + private final Room.CreatedMethod createdMethod; + + @Getter + private final Long durationSec; + + @Getter + private final Room.EdgeLocation edgeLocation; + + @Getter + private final Room.EndReason endReason; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; + + @Getter + private final Map links; + + @Getter + private final Integer maxConcurrentParticipants; + + @Getter + private final Integer maxParticipants; + + @Getter + private final Room.TwilioRealm mediaRegion; + + @Getter + private final Room.ProcessingState processingState; + + @Getter + private final Boolean recordingEnabled; + + @Getter + private final String roomName; + + @Getter + private final String roomSid; + + @Getter + private final Room.RoomStatus roomStatus; + + @Getter + private final Room.RoomType roomType; + + @Getter + private final URI statusCallback; + + @Getter + private final HttpMethod statusCallbackMethod; + + @Getter + private final Long totalParticipantDurationSec; + + @Getter + private final Long totalRecordingDurationSec; + + @Getter + private final Integer uniqueParticipantIdentities; + + @Getter + private final Integer uniqueParticipants; + + @Getter + private final URI url; + + @JsonCreator + private Room( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("codecs") final List codecs, + @JsonProperty( + "concurrent_participants" + ) final Integer concurrentParticipants, + @JsonProperty("create_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime createTime, + @JsonProperty("created_method") final Room.CreatedMethod createdMethod, + @JsonProperty("duration_sec") final Long durationSec, + @JsonProperty("edge_location") final Room.EdgeLocation edgeLocation, + @JsonProperty("end_reason") final Room.EndReason endReason, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty("links") final Map links, + @JsonProperty( + "max_concurrent_participants" + ) final Integer maxConcurrentParticipants, + @JsonProperty("max_participants") final Integer maxParticipants, + @JsonProperty("media_region") final Room.TwilioRealm mediaRegion, + @JsonProperty( + "processing_state" + ) final Room.ProcessingState processingState, + @JsonProperty("recording_enabled") final Boolean recordingEnabled, + @JsonProperty("room_name") final String roomName, + @JsonProperty("room_sid") final String roomSid, + @JsonProperty("room_status") final Room.RoomStatus roomStatus, + @JsonProperty("room_type") final Room.RoomType roomType, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty( + "total_participant_duration_sec" + ) final Long totalParticipantDurationSec, + @JsonProperty( + "total_recording_duration_sec" + ) final Long totalRecordingDurationSec, + @JsonProperty( + "unique_participant_identities" + ) final Integer uniqueParticipantIdentities, + @JsonProperty("unique_participants") final Integer uniqueParticipants, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.codecs = codecs; + this.concurrentParticipants = concurrentParticipants; + this.createTime = createTime; + this.createdMethod = createdMethod; + this.durationSec = durationSec; + this.edgeLocation = edgeLocation; + this.endReason = endReason; + this.endTime = endTime; + this.links = links; + this.maxConcurrentParticipants = maxConcurrentParticipants; + this.maxParticipants = maxParticipants; + this.mediaRegion = mediaRegion; + this.processingState = processingState; + this.recordingEnabled = recordingEnabled; + this.roomName = roomName; + this.roomSid = roomSid; + this.roomStatus = roomStatus; + this.roomType = roomType; + this.statusCallback = statusCallback; + this.statusCallbackMethod = statusCallbackMethod; + this.totalParticipantDurationSec = totalParticipantDurationSec; + this.totalRecordingDurationSec = totalRecordingDurationSec; + this.uniqueParticipantIdentities = uniqueParticipantIdentities; + this.uniqueParticipants = uniqueParticipants; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Room other = (Room) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(codecs, other.codecs) && + Objects.equals( + concurrentParticipants, + other.concurrentParticipants + ) && + Objects.equals(createTime, other.createTime) && + Objects.equals(createdMethod, other.createdMethod) && + Objects.equals(durationSec, other.durationSec) && + Objects.equals(edgeLocation, other.edgeLocation) && + Objects.equals(endReason, other.endReason) && + Objects.equals(endTime, other.endTime) && + Objects.equals(links, other.links) && + Objects.equals( + maxConcurrentParticipants, + other.maxConcurrentParticipants + ) && + Objects.equals(maxParticipants, other.maxParticipants) && + Objects.equals(mediaRegion, other.mediaRegion) && + Objects.equals(processingState, other.processingState) && + Objects.equals(recordingEnabled, other.recordingEnabled) && + Objects.equals(roomName, other.roomName) && + Objects.equals(roomSid, other.roomSid) && + Objects.equals(roomStatus, other.roomStatus) && + Objects.equals(roomType, other.roomType) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals( + totalParticipantDurationSec, + other.totalParticipantDurationSec + ) && + Objects.equals( + totalRecordingDurationSec, + other.totalRecordingDurationSec + ) && + Objects.equals( + uniqueParticipantIdentities, + other.uniqueParticipantIdentities + ) && + Objects.equals(uniqueParticipants, other.uniqueParticipants) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + codecs, + concurrentParticipants, + createTime, + createdMethod, + durationSec, + edgeLocation, + endReason, + endTime, + links, + maxConcurrentParticipants, + maxParticipants, + mediaRegion, + processingState, + recordingEnabled, + roomName, + roomSid, + roomStatus, + roomType, + statusCallback, + statusCallbackMethod, + totalParticipantDurationSec, + totalRecordingDurationSec, + uniqueParticipantIdentities, + uniqueParticipants, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/RoomFetcher.java b/src/main/java/com/twilio/rest/insights/v1/RoomFetcher.java new file mode 100644 index 0000000000..3a6edbb608 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/RoomFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RoomFetcher extends Fetcher { + + private String pathRoomSid; + + public RoomFetcher(final String pathRoomSid) { + this.pathRoomSid = pathRoomSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Video/Rooms/{RoomSid}"; + + path = path.replace("{" + "RoomSid" + "}", this.pathRoomSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Room fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Room fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Room.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Room content = Room.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/RoomReader.java b/src/main/java/com/twilio/rest/insights/v1/RoomReader.java new file mode 100644 index 0000000000..07a035a56c --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/RoomReader.java @@ -0,0 +1,288 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; + +public class RoomReader extends Reader { + + private List roomType; + private List codec; + private String roomName; + private ZonedDateTime createdAfter; + private ZonedDateTime createdBefore; + private Long pageSize; + + public RoomReader() {} + + public RoomReader setRoomType(final List roomType) { + this.roomType = roomType; + return this; + } + + public RoomReader setRoomType(final Room.RoomType roomType) { + return setRoomType(Promoter.listOfOne(roomType)); + } + + public RoomReader setCodec(final List codec) { + this.codec = codec; + return this; + } + + public RoomReader setCodec(final Room.Codec codec) { + return setCodec(Promoter.listOfOne(codec)); + } + + public RoomReader setRoomName(final String roomName) { + this.roomName = roomName; + return this; + } + + public RoomReader setCreatedAfter(final ZonedDateTime createdAfter) { + this.createdAfter = createdAfter; + return this; + } + + public RoomReader setCreatedBefore(final ZonedDateTime createdBefore) { + this.createdBefore = createdBefore; + return this; + } + + public RoomReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "rooms", + response.getContent(), + Room.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Video/Rooms"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "rooms", + response.getContent(), + Room.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Room read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "rooms", + response.getContent(), + Room.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (roomType != null) { + for (Room.RoomType param : roomType) { + Serializer.toString( + request, + "RoomType", + param, + ParameterType.QUERY + ); + } + } + + if (codec != null) { + for (Room.Codec param : codec) { + Serializer.toString( + request, + "Codec", + param, + ParameterType.QUERY + ); + } + } + + if (roomName != null) { + Serializer.toString( + request, + "RoomName", + roomName, + ParameterType.QUERY + ); + } + + if (createdAfter != null) { + Serializer.toString( + request, + "CreatedAfter", + createdAfter, + ParameterType.QUERY + ); + } + + if (createdBefore != null) { + Serializer.toString( + request, + "CreatedBefore", + createdBefore, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/Setting.java b/src/main/java/com/twilio/rest/insights/v1/Setting.java new file mode 100644 index 0000000000..fdba8d3250 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/Setting.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Setting extends Resource { + + public static SettingFetcher fetcher() { + return new SettingFetcher(); + } + + public static SettingUpdater updater() { + return new SettingUpdater(); + } + + /** + * Converts a JSON String into a Setting object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Setting object represented by the provided JSON + */ + public static Setting fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Setting.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Setting object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Setting object represented by the provided JSON + */ + public static Setting fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Setting.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean advancedFeatures; + + @Getter + private final URI url; + + @Getter + private final Boolean voiceTrace; + + @JsonCreator + private Setting( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("advanced_features") final Boolean advancedFeatures, + @JsonProperty("url") final URI url, + @JsonProperty("voice_trace") final Boolean voiceTrace + ) { + this.accountSid = accountSid; + this.advancedFeatures = advancedFeatures; + this.url = url; + this.voiceTrace = voiceTrace; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Setting other = (Setting) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(advancedFeatures, other.advancedFeatures) && + Objects.equals(url, other.url) && + Objects.equals(voiceTrace, other.voiceTrace) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, advancedFeatures, url, voiceTrace); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/SettingFetcher.java b/src/main/java/com/twilio/rest/insights/v1/SettingFetcher.java new file mode 100644 index 0000000000..c166c44b6e --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/SettingFetcher.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SettingFetcher extends Fetcher { + + private String subaccountSid; + + public SettingFetcher() {} + + public SettingFetcher setSubaccountSid(final String subaccountSid) { + this.subaccountSid = subaccountSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Voice/Settings"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Setting fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Setting fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Setting.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Setting content = Setting.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (subaccountSid != null) { + Serializer.toString( + request, + "SubaccountSid", + subaccountSid, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/SettingUpdater.java b/src/main/java/com/twilio/rest/insights/v1/SettingUpdater.java new file mode 100644 index 0000000000..175fa4a567 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/SettingUpdater.java @@ -0,0 +1,140 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SettingUpdater extends Updater { + + private Boolean advancedFeatures; + private Boolean voiceTrace; + private String subaccountSid; + + public SettingUpdater() {} + + public SettingUpdater setAdvancedFeatures(final Boolean advancedFeatures) { + this.advancedFeatures = advancedFeatures; + return this; + } + + public SettingUpdater setVoiceTrace(final Boolean voiceTrace) { + this.voiceTrace = voiceTrace; + return this; + } + + public SettingUpdater setSubaccountSid(final String subaccountSid) { + this.subaccountSid = subaccountSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Voice/Settings"; + + Request request = new Request( + HttpMethod.POST, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Setting update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Setting update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Setting.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Setting content = Setting.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (advancedFeatures != null) { + Serializer.toString( + request, + "AdvancedFeatures", + advancedFeatures, + ParameterType.URLENCODED + ); + } + + if (voiceTrace != null) { + Serializer.toString( + request, + "VoiceTrace", + voiceTrace, + ParameterType.URLENCODED + ); + } + + if (subaccountSid != null) { + Serializer.toString( + request, + "SubaccountSid", + subaccountSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/Annotation.java b/src/main/java/com/twilio/rest/insights/v1/call/Annotation.java new file mode 100644 index 0000000000..593fb48efa --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/Annotation.java @@ -0,0 +1,252 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Annotation extends Resource { + + public static AnnotationFetcher fetcher(final String pathCallSid) { + return new AnnotationFetcher(pathCallSid); + } + + public static AnnotationUpdater updater(final String pathCallSid) { + return new AnnotationUpdater(pathCallSid); + } + + public enum AnsweredBy { + UNKNOWN_ANSWERED_BY("unknown_answered_by"), + HUMAN("human"), + MACHINE("machine"); + + private final String value; + + private AnsweredBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static AnsweredBy forValue(final String value) { + return Promoter.enumFromString(value, AnsweredBy.values()); + } + } + + public enum ConnectivityIssue { + UNKNOWN_CONNECTIVITY_ISSUE("unknown_connectivity_issue"), + NO_CONNECTIVITY_ISSUE("no_connectivity_issue"), + INVALID_NUMBER("invalid_number"), + CALLER_ID("caller_id"), + DROPPED_CALL("dropped_call"), + NUMBER_REACHABILITY("number_reachability"); + + private final String value; + + private ConnectivityIssue(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConnectivityIssue forValue(final String value) { + return Promoter.enumFromString(value, ConnectivityIssue.values()); + } + } + + /** + * Converts a JSON String into a Annotation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Annotation object represented by the provided JSON + */ + public static Annotation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Annotation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Annotation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Annotation object represented by the provided JSON + */ + public static Annotation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Annotation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Annotation.AnsweredBy answeredBy; + + @Getter + private final Integer callScore; + + @Getter + private final String callSid; + + @Getter + private final String comment; + + @Getter + private final Annotation.ConnectivityIssue connectivityIssue; + + @Getter + private final String incident; + + @Getter + private final List qualityIssues; + + @Getter + private final Boolean spam; + + @Getter + private final URI url; + + @JsonCreator + private Annotation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("answered_by") final Annotation.AnsweredBy answeredBy, + @JsonProperty("call_score") final Integer callScore, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("comment") final String comment, + @JsonProperty( + "connectivity_issue" + ) final Annotation.ConnectivityIssue connectivityIssue, + @JsonProperty("incident") final String incident, + @JsonProperty("quality_issues") final List qualityIssues, + @JsonProperty("spam") final Boolean spam, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.answeredBy = answeredBy; + this.callScore = callScore; + this.callSid = callSid; + this.comment = comment; + this.connectivityIssue = connectivityIssue; + this.incident = incident; + this.qualityIssues = qualityIssues; + this.spam = spam; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Annotation other = (Annotation) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(answeredBy, other.answeredBy) && + Objects.equals(callScore, other.callScore) && + Objects.equals(callSid, other.callSid) && + Objects.equals(comment, other.comment) && + Objects.equals(connectivityIssue, other.connectivityIssue) && + Objects.equals(incident, other.incident) && + Objects.equals(qualityIssues, other.qualityIssues) && + Objects.equals(spam, other.spam) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + answeredBy, + callScore, + callSid, + comment, + connectivityIssue, + incident, + qualityIssues, + spam, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/AnnotationFetcher.java b/src/main/java/com/twilio/rest/insights/v1/call/AnnotationFetcher.java new file mode 100644 index 0000000000..be9d1f551d --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/AnnotationFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AnnotationFetcher extends Fetcher { + + private String pathCallSid; + + public AnnotationFetcher(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Voice/{CallSid}/Annotation"; + + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Annotation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Annotation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Annotation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Annotation content = Annotation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/AnnotationUpdater.java b/src/main/java/com/twilio/rest/insights/v1/call/AnnotationUpdater.java new file mode 100644 index 0000000000..8063e5f6be --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/AnnotationUpdater.java @@ -0,0 +1,212 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AnnotationUpdater extends Updater { + + private String pathCallSid; + private Annotation.AnsweredBy answeredBy; + private Annotation.ConnectivityIssue connectivityIssue; + private String qualityIssues; + private Boolean spam; + private Integer callScore; + private String comment; + private String incident; + + public AnnotationUpdater(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + public AnnotationUpdater setAnsweredBy( + final Annotation.AnsweredBy answeredBy + ) { + this.answeredBy = answeredBy; + return this; + } + + public AnnotationUpdater setConnectivityIssue( + final Annotation.ConnectivityIssue connectivityIssue + ) { + this.connectivityIssue = connectivityIssue; + return this; + } + + public AnnotationUpdater setQualityIssues(final String qualityIssues) { + this.qualityIssues = qualityIssues; + return this; + } + + public AnnotationUpdater setSpam(final Boolean spam) { + this.spam = spam; + return this; + } + + public AnnotationUpdater setCallScore(final Integer callScore) { + this.callScore = callScore; + return this; + } + + public AnnotationUpdater setComment(final String comment) { + this.comment = comment; + return this; + } + + public AnnotationUpdater setIncident(final String incident) { + this.incident = incident; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Voice/{CallSid}/Annotation"; + + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Annotation update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Annotation update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Annotation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Annotation content = Annotation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (answeredBy != null) { + Serializer.toString( + request, + "AnsweredBy", + answeredBy, + ParameterType.URLENCODED + ); + } + + if (connectivityIssue != null) { + Serializer.toString( + request, + "ConnectivityIssue", + connectivityIssue, + ParameterType.URLENCODED + ); + } + + if (qualityIssues != null) { + Serializer.toString( + request, + "QualityIssues", + qualityIssues, + ParameterType.URLENCODED + ); + } + + if (spam != null) { + Serializer.toString( + request, + "Spam", + spam, + ParameterType.URLENCODED + ); + } + + if (callScore != null) { + Serializer.toString( + request, + "CallScore", + callScore, + ParameterType.URLENCODED + ); + } + + if (comment != null) { + Serializer.toString( + request, + "Comment", + comment, + ParameterType.URLENCODED + ); + } + + if (incident != null) { + Serializer.toString( + request, + "Incident", + incident, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/CallSummary.java b/src/main/java/com/twilio/rest/insights/v1/call/CallSummary.java new file mode 100644 index 0000000000..8f2480e227 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/CallSummary.java @@ -0,0 +1,1091 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CallSummary extends Resource { + + public static CallSummaryFetcher fetcher(final String pathCallSid) { + return new CallSummaryFetcher(pathCallSid); + } + + public enum CallType { + CARRIER("carrier"), + SIP("sip"), + TRUNKING("trunking"), + CLIENT("client"), + WHATSAPP("whatsapp"); + + private final String value; + + private CallType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallType forValue(final String value) { + return Promoter.enumFromString(value, CallType.values()); + } + } + + public enum CallState { + RINGING("ringing"), + COMPLETED("completed"), + BUSY("busy"), + FAIL("fail"), + NOANSWER("noanswer"), + CANCELED("canceled"), + ANSWERED("answered"), + UNDIALED("undialed"); + + private final String value; + + private CallState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallState forValue(final String value) { + return Promoter.enumFromString(value, CallState.values()); + } + } + + public enum AnsweredBy { + UNKNOWN("unknown"), + MACHINE_START("machine_start"), + MACHINE_END_BEEP("machine_end_beep"), + MACHINE_END_SILENCE("machine_end_silence"), + MACHINE_END_OTHER("machine_end_other"), + HUMAN("human"), + FAX("fax"); + + private final String value; + + private AnsweredBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static AnsweredBy forValue(final String value) { + return Promoter.enumFromString(value, AnsweredBy.values()); + } + } + + public enum ProcessingState { + COMPLETE("complete"), + PARTIAL("partial"); + + private final String value; + + private ProcessingState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ProcessingState forValue(final String value) { + return Promoter.enumFromString(value, ProcessingState.values()); + } + } + + public enum CallSummaryCrelaySessionState { + UNKNOWN("unknown"), + FAILURE("failure"), + ENDED("ended"), + HUNG_UP("hung_up"); + + private final String value; + + private CallSummaryCrelaySessionState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallSummaryCrelaySessionState forValue( + final String value + ) { + return Promoter.enumFromString( + value, + CallSummaryCrelaySessionState.values() + ); + } + } + + @JsonDeserialize(builder = CallSummaryCrelayRateStats.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryCrelayRateStats { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("min") + @Getter + private final Float min; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("max") + @Getter + private final Float max; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("avg") + @Getter + private final Float avg; + + private CallSummaryCrelayRateStats(Builder builder) { + this.min = builder.min; + this.max = builder.max; + this.avg = builder.avg; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryCrelayRateStats fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryCrelayRateStats.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("min") + private Float min; + + @JsonProperty("max") + private Float max; + + @JsonProperty("avg") + private Float avg; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("min") + public Builder min(Float min) { + this.min = min; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("max") + public Builder max(Float max) { + this.max = max; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("avg") + public Builder avg(Float avg) { + this.avg = avg; + return this; + } + + public CallSummaryCrelayRateStats build() { + return new CallSummaryCrelayRateStats(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryCrelayRateStats other = (CallSummaryCrelayRateStats) o; + return ( + Objects.equals(min, other.min) && + Objects.equals(max, other.max) && + Objects.equals(avg, other.avg) + ); + } + + @Override + public int hashCode() { + return Objects.hash(min, max, avg); + } + } + + @JsonDeserialize(builder = CallSummaryCrelayInterruptions.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryCrelayInterruptions { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_to_agent") + @Getter + private final Integer customerToAgent; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("agent_to_customer") + @Getter + private final Integer agentToCustomer; + + private CallSummaryCrelayInterruptions(Builder builder) { + this.customerToAgent = builder.customerToAgent; + this.agentToCustomer = builder.agentToCustomer; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryCrelayInterruptions fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryCrelayInterruptions.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("customer_to_agent") + private Integer customerToAgent; + + @JsonProperty("agent_to_customer") + private Integer agentToCustomer; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_to_agent") + public Builder customerToAgent(Integer customerToAgent) { + this.customerToAgent = customerToAgent; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("agent_to_customer") + public Builder agentToCustomer(Integer agentToCustomer) { + this.agentToCustomer = agentToCustomer; + return this; + } + + public CallSummaryCrelayInterruptions build() { + return new CallSummaryCrelayInterruptions(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryCrelayInterruptions other = + (CallSummaryCrelayInterruptions) o; + return ( + Objects.equals(customerToAgent, other.customerToAgent) && + Objects.equals(agentToCustomer, other.agentToCustomer) + ); + } + + @Override + public int hashCode() { + return Objects.hash(customerToAgent, agentToCustomer); + } + } + + @JsonDeserialize(builder = CallSummaryCrelayTokenStats.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryCrelayTokenStats { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total") + @Getter + private final Integer total; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tokens_per_second") + @Getter + private final CallSummaryCrelayRateStats tokensPerSecond; + + private CallSummaryCrelayTokenStats(Builder builder) { + this.total = builder.total; + this.tokensPerSecond = builder.tokensPerSecond; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryCrelayTokenStats fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryCrelayTokenStats.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total") + private Integer total; + + @JsonProperty("tokens_per_second") + private CallSummaryCrelayRateStats tokensPerSecond; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total") + public Builder total(Integer total) { + this.total = total; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tokens_per_second") + public Builder tokensPerSecond( + CallSummaryCrelayRateStats tokensPerSecond + ) { + this.tokensPerSecond = tokensPerSecond; + return this; + } + + public CallSummaryCrelayTokenStats build() { + return new CallSummaryCrelayTokenStats(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryCrelayTokenStats other = (CallSummaryCrelayTokenStats) o; + return ( + Objects.equals(total, other.total) && + Objects.equals(tokensPerSecond, other.tokensPerSecond) + ); + } + + @Override + public int hashCode() { + return Objects.hash(total, tokensPerSecond); + } + } + + @JsonDeserialize(builder = CallSummaryAgentSessionSummary.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryAgentSessionSummary { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_id") + @Getter + private final String sessionId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_latency_ms") + @Getter + private final CallSummaryCrelayRateStats ttsLatencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stt_latency_ms") + @Getter + private final CallSummaryCrelayRateStats sttLatencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("network_latency_ms") + @Getter + private final CallSummaryCrelayRateStats networkLatencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_to_first_audio_ms") + @Getter + private final CallSummaryCrelayRateStats timeToFirstAudioMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("application_latency_ms") + @Getter + private final CallSummaryCrelayRateStats applicationLatencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tokens") + @Getter + private final CallSummaryCrelayTokenStats tokens; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words") + @Getter + private final CallSummaryCrelayWordStats words; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("turns") + @Getter + private final Integer turns; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("interruptions") + @Getter + private final CallSummaryCrelayInterruptions interruptions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_state") + @Getter + private final CallSummary.CallSummaryCrelaySessionState sessionState; + + private CallSummaryAgentSessionSummary(Builder builder) { + this.sessionId = builder.sessionId; + this.ttsLatencyMs = builder.ttsLatencyMs; + this.sttLatencyMs = builder.sttLatencyMs; + this.networkLatencyMs = builder.networkLatencyMs; + this.timeToFirstAudioMs = builder.timeToFirstAudioMs; + this.applicationLatencyMs = builder.applicationLatencyMs; + this.tokens = builder.tokens; + this.words = builder.words; + this.turns = builder.turns; + this.interruptions = builder.interruptions; + this.sessionState = builder.sessionState; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryAgentSessionSummary fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryAgentSessionSummary.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("session_id") + private String sessionId; + + @JsonProperty("tts_latency_ms") + private CallSummaryCrelayRateStats ttsLatencyMs; + + @JsonProperty("stt_latency_ms") + private CallSummaryCrelayRateStats sttLatencyMs; + + @JsonProperty("network_latency_ms") + private CallSummaryCrelayRateStats networkLatencyMs; + + @JsonProperty("time_to_first_audio_ms") + private CallSummaryCrelayRateStats timeToFirstAudioMs; + + @JsonProperty("application_latency_ms") + private CallSummaryCrelayRateStats applicationLatencyMs; + + @JsonProperty("tokens") + private CallSummaryCrelayTokenStats tokens; + + @JsonProperty("words") + private CallSummaryCrelayWordStats words; + + @JsonProperty("turns") + private Integer turns; + + @JsonProperty("interruptions") + private CallSummaryCrelayInterruptions interruptions; + + @JsonProperty("session_state") + private CallSummary.CallSummaryCrelaySessionState sessionState; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_id") + public Builder sessionId(String sessionId) { + this.sessionId = sessionId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_latency_ms") + public Builder ttsLatencyMs( + CallSummaryCrelayRateStats ttsLatencyMs + ) { + this.ttsLatencyMs = ttsLatencyMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stt_latency_ms") + public Builder sttLatencyMs( + CallSummaryCrelayRateStats sttLatencyMs + ) { + this.sttLatencyMs = sttLatencyMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("network_latency_ms") + public Builder networkLatencyMs( + CallSummaryCrelayRateStats networkLatencyMs + ) { + this.networkLatencyMs = networkLatencyMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_to_first_audio_ms") + public Builder timeToFirstAudioMs( + CallSummaryCrelayRateStats timeToFirstAudioMs + ) { + this.timeToFirstAudioMs = timeToFirstAudioMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("application_latency_ms") + public Builder applicationLatencyMs( + CallSummaryCrelayRateStats applicationLatencyMs + ) { + this.applicationLatencyMs = applicationLatencyMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tokens") + public Builder tokens(CallSummaryCrelayTokenStats tokens) { + this.tokens = tokens; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words") + public Builder words(CallSummaryCrelayWordStats words) { + this.words = words; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("turns") + public Builder turns(Integer turns) { + this.turns = turns; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("interruptions") + public Builder interruptions( + CallSummaryCrelayInterruptions interruptions + ) { + this.interruptions = interruptions; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_state") + public Builder sessionState( + CallSummary.CallSummaryCrelaySessionState sessionState + ) { + this.sessionState = sessionState; + return this; + } + + public CallSummaryAgentSessionSummary build() { + return new CallSummaryAgentSessionSummary(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryAgentSessionSummary other = + (CallSummaryAgentSessionSummary) o; + return ( + Objects.equals(sessionId, other.sessionId) && + Objects.equals(ttsLatencyMs, other.ttsLatencyMs) && + Objects.equals(sttLatencyMs, other.sttLatencyMs) && + Objects.equals(networkLatencyMs, other.networkLatencyMs) && + Objects.equals(timeToFirstAudioMs, other.timeToFirstAudioMs) && + Objects.equals( + applicationLatencyMs, + other.applicationLatencyMs + ) && + Objects.equals(tokens, other.tokens) && + Objects.equals(words, other.words) && + Objects.equals(turns, other.turns) && + Objects.equals(interruptions, other.interruptions) && + Objects.equals(sessionState, other.sessionState) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + sessionId, + ttsLatencyMs, + sttLatencyMs, + networkLatencyMs, + timeToFirstAudioMs, + applicationLatencyMs, + tokens, + words, + turns, + interruptions, + sessionState + ); + } + } + + @JsonDeserialize(builder = CallSummaryCrelayWordStats.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallSummaryCrelayWordStats { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total") + @Getter + private final Integer total; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words_per_minute") + @Getter + private final CallSummaryCrelayRateStats wordsPerMinute; + + private CallSummaryCrelayWordStats(Builder builder) { + this.total = builder.total; + this.wordsPerMinute = builder.wordsPerMinute; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallSummaryCrelayWordStats fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CallSummaryCrelayWordStats.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total") + private Integer total; + + @JsonProperty("words_per_minute") + private CallSummaryCrelayRateStats wordsPerMinute; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total") + public Builder total(Integer total) { + this.total = total; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("words_per_minute") + public Builder wordsPerMinute( + CallSummaryCrelayRateStats wordsPerMinute + ) { + this.wordsPerMinute = wordsPerMinute; + return this; + } + + public CallSummaryCrelayWordStats build() { + return new CallSummaryCrelayWordStats(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummaryCrelayWordStats other = (CallSummaryCrelayWordStats) o; + return ( + Objects.equals(total, other.total) && + Objects.equals(wordsPerMinute, other.wordsPerMinute) + ); + } + + @Override + public int hashCode() { + return Objects.hash(total, wordsPerMinute); + } + } + + /** + * Converts a JSON String into a CallSummary object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CallSummary object represented by the provided JSON + */ + public static CallSummary fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CallSummary.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CallSummary object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CallSummary object represented by the provided JSON + */ + public static CallSummary fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CallSummary.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final List agentSessionSummaries; + + @Getter + private final Object annotation; + + @Getter + private final CallSummary.AnsweredBy answeredBy; + + @Getter + private final Object attributes; + + @Getter + private final String callSid; + + @Getter + private final CallSummary.CallState callState; + + @Getter + private final CallSummary.CallType callType; + + @Getter + private final Object carrierEdge; + + @Getter + private final Object clientEdge; + + @Getter + private final Integer connectDuration; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime createdTime; + + @Getter + private final Integer duration; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; + + @Getter + private final Object from; + + @Getter + private final CallSummary.ProcessingState processingState; + + @Getter + private final Object properties; + + @Getter + private final Object sdkEdge; + + @Getter + private final Object sipEdge; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime startTime; + + @Getter + private final List tags; + + @Getter + private final Object to; + + @Getter + private final Object trust; + + @Getter + private final URI url; + + @JsonCreator + private CallSummary( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("agent_session_summaries") final List< + CallSummaryAgentSessionSummary + > agentSessionSummaries, + @JsonProperty("annotation") final Object annotation, + @JsonProperty("answered_by") final CallSummary.AnsweredBy answeredBy, + @JsonProperty("attributes") final Object attributes, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("call_state") final CallSummary.CallState callState, + @JsonProperty("call_type") final CallSummary.CallType callType, + @JsonProperty("carrier_edge") final Object carrierEdge, + @JsonProperty("client_edge") final Object clientEdge, + @JsonProperty("connect_duration") final Integer connectDuration, + @JsonProperty("created_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime createdTime, + @JsonProperty("duration") final Integer duration, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty("from") final Object from, + @JsonProperty( + "processing_state" + ) final CallSummary.ProcessingState processingState, + @JsonProperty("properties") final Object properties, + @JsonProperty("sdk_edge") final Object sdkEdge, + @JsonProperty("sip_edge") final Object sipEdge, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime startTime, + @JsonProperty("tags") final List tags, + @JsonProperty("to") final Object to, + @JsonProperty("trust") final Object trust, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.agentSessionSummaries = agentSessionSummaries; + this.annotation = annotation; + this.answeredBy = answeredBy; + this.attributes = attributes; + this.callSid = callSid; + this.callState = callState; + this.callType = callType; + this.carrierEdge = carrierEdge; + this.clientEdge = clientEdge; + this.connectDuration = connectDuration; + this.createdTime = createdTime; + this.duration = duration; + this.endTime = endTime; + this.from = from; + this.processingState = processingState; + this.properties = properties; + this.sdkEdge = sdkEdge; + this.sipEdge = sipEdge; + this.startTime = startTime; + this.tags = tags; + this.to = to; + this.trust = trust; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallSummary other = (CallSummary) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + agentSessionSummaries, + other.agentSessionSummaries + ) && + Objects.equals(annotation, other.annotation) && + Objects.equals(answeredBy, other.answeredBy) && + Objects.equals(attributes, other.attributes) && + Objects.equals(callSid, other.callSid) && + Objects.equals(callState, other.callState) && + Objects.equals(callType, other.callType) && + Objects.equals(carrierEdge, other.carrierEdge) && + Objects.equals(clientEdge, other.clientEdge) && + Objects.equals(connectDuration, other.connectDuration) && + Objects.equals(createdTime, other.createdTime) && + Objects.equals(duration, other.duration) && + Objects.equals(endTime, other.endTime) && + Objects.equals(from, other.from) && + Objects.equals(processingState, other.processingState) && + Objects.equals(properties, other.properties) && + Objects.equals(sdkEdge, other.sdkEdge) && + Objects.equals(sipEdge, other.sipEdge) && + Objects.equals(startTime, other.startTime) && + Objects.equals(tags, other.tags) && + Objects.equals(to, other.to) && + Objects.equals(trust, other.trust) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + agentSessionSummaries, + annotation, + answeredBy, + attributes, + callSid, + callState, + callType, + carrierEdge, + clientEdge, + connectDuration, + createdTime, + duration, + endTime, + from, + processingState, + properties, + sdkEdge, + sipEdge, + startTime, + tags, + to, + trust, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/CallSummaryFetcher.java b/src/main/java/com/twilio/rest/insights/v1/call/CallSummaryFetcher.java new file mode 100644 index 0000000000..6c0f3d689f --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/CallSummaryFetcher.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CallSummaryFetcher extends Fetcher { + + private String pathCallSid; + private CallSummary.ProcessingState processingState; + + public CallSummaryFetcher(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + public CallSummaryFetcher setProcessingState( + final CallSummary.ProcessingState processingState + ) { + this.processingState = processingState; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Voice/{CallSid}/Summary"; + + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CallSummary fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CallSummary fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return CallSummary.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CallSummary content = CallSummary.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (processingState != null) { + Serializer.toString( + request, + "ProcessingState", + processingState, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/Event.java b/src/main/java/com/twilio/rest/insights/v1/call/Event.java new file mode 100644 index 0000000000..ed378df8af --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/Event.java @@ -0,0 +1,1241 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Event extends Resource { + + public static EventReader reader(final String pathCallSid) { + return new EventReader(pathCallSid); + } + + public enum Type { + DTMF("DTMF"), + SPEECH("SPEECH"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum TwilioEdge { + UNKNOWN_EDGE("unknown_edge"), + CARRIER_EDGE("carrier_edge"), + SIP_EDGE("sip_edge"), + SDK_EDGE("sdk_edge"), + CLIENT_EDGE("client_edge"); + + private final String value; + + private TwilioEdge(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TwilioEdge forValue(final String value) { + return Promoter.enumFromString(value, TwilioEdge.values()); + } + } + + public enum EndStatus { + UNKNOWN("unknown"), + FAILURE("failure"), + ENDED("ended"), + HUNG_UP("hung_up"); + + private final String value; + + private EndStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EndStatus forValue(final String value) { + return Promoter.enumFromString(value, EndStatus.values()); + } + } + + public enum Level { + UNKNOWN("UNKNOWN"), + DEBUG("DEBUG"), + INFO("INFO"), + WARNING("WARNING"), + ERROR("ERROR"); + + private final String value; + + private Level(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Level forValue(final String value) { + return Promoter.enumFromString(value, Level.values()); + } + } + + @JsonDeserialize(builder = ConfigurationEvent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConfigurationEvent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configurations") + @Getter + private final Map configurations; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("languages") + @Getter + private final Map languages; + + private ConfigurationEvent(Builder builder) { + this.configurations = builder.configurations; + this.languages = builder.languages; + } + + public static Builder builder() { + return new Builder(); + } + + public static ConfigurationEvent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ConfigurationEvent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("configurations") + private Map configurations; + + @JsonProperty("languages") + private Map languages; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configurations") + public Builder configurations(Map configurations) { + this.configurations = configurations; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("languages") + public Builder languages( + Map languages + ) { + this.languages = languages; + return this; + } + + public ConfigurationEvent build() { + return new ConfigurationEvent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConfigurationEvent other = (ConfigurationEvent) o; + return ( + Objects.equals(configurations, other.configurations) && + Objects.equals(languages, other.languages) + ); + } + + @Override + public int hashCode() { + return Objects.hash(configurations, languages); + } + } + + @JsonDeserialize(builder = ConfigurationEventLanguagesValue.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConfigurationEventLanguagesValue { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_provider") + @Getter + private final String ttsProvider; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("voice") + @Getter + private final String voice; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("transcription_provider") + @Getter + private final String transcriptionProvider; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("speech_model") + @Getter + private final String speechModel; + + private ConfigurationEventLanguagesValue(Builder builder) { + this.ttsProvider = builder.ttsProvider; + this.voice = builder.voice; + this.transcriptionProvider = builder.transcriptionProvider; + this.speechModel = builder.speechModel; + } + + public static Builder builder() { + return new Builder(); + } + + public static ConfigurationEventLanguagesValue fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ConfigurationEventLanguagesValue.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("tts_provider") + private String ttsProvider; + + @JsonProperty("voice") + private String voice; + + @JsonProperty("transcription_provider") + private String transcriptionProvider; + + @JsonProperty("speech_model") + private String speechModel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_provider") + public Builder ttsProvider(String ttsProvider) { + this.ttsProvider = ttsProvider; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("voice") + public Builder voice(String voice) { + this.voice = voice; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("transcription_provider") + public Builder transcriptionProvider(String transcriptionProvider) { + this.transcriptionProvider = transcriptionProvider; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("speech_model") + public Builder speechModel(String speechModel) { + this.speechModel = speechModel; + return this; + } + + public ConfigurationEventLanguagesValue build() { + return new ConfigurationEventLanguagesValue(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConfigurationEventLanguagesValue other = + (ConfigurationEventLanguagesValue) o; + return ( + Objects.equals(ttsProvider, other.ttsProvider) && + Objects.equals(voice, other.voice) && + Objects.equals( + transcriptionProvider, + other.transcriptionProvider + ) && + Objects.equals(speechModel, other.speechModel) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + ttsProvider, + voice, + transcriptionProvider, + speechModel + ); + } + } + + @JsonDeserialize(builder = CallWrapUpEvent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallWrapUpEvent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("duration_in_seconds") + @Getter + private final Integer durationInSeconds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_status") + @Getter + private final Event.EndStatus endStatus; + + private CallWrapUpEvent(Builder builder) { + this.durationInSeconds = builder.durationInSeconds; + this.endStatus = builder.endStatus; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallWrapUpEvent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CallWrapUpEvent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("duration_in_seconds") + private Integer durationInSeconds; + + @JsonProperty("end_status") + private Event.EndStatus endStatus; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("duration_in_seconds") + public Builder durationInSeconds(Integer durationInSeconds) { + this.durationInSeconds = durationInSeconds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_status") + public Builder endStatus(Event.EndStatus endStatus) { + this.endStatus = endStatus; + return this; + } + + public CallWrapUpEvent build() { + return new CallWrapUpEvent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallWrapUpEvent other = (CallWrapUpEvent) o; + return ( + Objects.equals(durationInSeconds, other.durationInSeconds) && + Objects.equals(endStatus, other.endStatus) + ); + } + + @Override + public int hashCode() { + return Objects.hash(durationInSeconds, endStatus); + } + } + + @JsonDeserialize(builder = LanguageChangedEvent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LanguageChangedEvent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_language_code") + @Getter + private final String ttsLanguageCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("transcription_language_code") + @Getter + private final String transcriptionLanguageCode; + + private LanguageChangedEvent(Builder builder) { + this.ttsLanguageCode = builder.ttsLanguageCode; + this.transcriptionLanguageCode = builder.transcriptionLanguageCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static LanguageChangedEvent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LanguageChangedEvent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("tts_language_code") + private String ttsLanguageCode; + + @JsonProperty("transcription_language_code") + private String transcriptionLanguageCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_language_code") + public Builder ttsLanguageCode(String ttsLanguageCode) { + this.ttsLanguageCode = ttsLanguageCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("transcription_language_code") + public Builder transcriptionLanguageCode( + String transcriptionLanguageCode + ) { + this.transcriptionLanguageCode = transcriptionLanguageCode; + return this; + } + + public LanguageChangedEvent build() { + return new LanguageChangedEvent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LanguageChangedEvent other = (LanguageChangedEvent) o; + return ( + Objects.equals(ttsLanguageCode, other.ttsLanguageCode) && + Objects.equals( + transcriptionLanguageCode, + other.transcriptionLanguageCode + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash(ttsLanguageCode, transcriptionLanguageCode); + } + } + + @JsonDeserialize(builder = ErrorEvent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ErrorEvent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("message") + @Getter + private final String message; + + private ErrorEvent(Builder builder) { + this.errorCode = builder.errorCode; + this.message = builder.message; + } + + public static Builder builder() { + return new Builder(); + } + + public static ErrorEvent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ErrorEvent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonProperty("message") + private String message; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("message") + public Builder message(String message) { + this.message = message; + return this; + } + + public ErrorEvent build() { + return new ErrorEvent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ErrorEvent other = (ErrorEvent) o; + return ( + Objects.equals(errorCode, other.errorCode) && + Objects.equals(message, other.message) + ); + } + + @Override + public int hashCode() { + return Objects.hash(errorCode, message); + } + } + + @JsonDeserialize(builder = LastTokenReceivedEvent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LastTokenReceivedEvent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_tokens") + @Getter + private final Integer totalTokens; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_words") + @Getter + private final Integer totalWords; + + private LastTokenReceivedEvent(Builder builder) { + this.totalTokens = builder.totalTokens; + this.totalWords = builder.totalWords; + } + + public static Builder builder() { + return new Builder(); + } + + public static LastTokenReceivedEvent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LastTokenReceivedEvent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total_tokens") + private Integer totalTokens; + + @JsonProperty("total_words") + private Integer totalWords; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_tokens") + public Builder totalTokens(Integer totalTokens) { + this.totalTokens = totalTokens; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_words") + public Builder totalWords(Integer totalWords) { + this.totalWords = totalWords; + return this; + } + + public LastTokenReceivedEvent build() { + return new LastTokenReceivedEvent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LastTokenReceivedEvent other = (LastTokenReceivedEvent) o; + return ( + Objects.equals(totalTokens, other.totalTokens) && + Objects.equals(totalWords, other.totalWords) + ); + } + + @Override + public int hashCode() { + return Objects.hash(totalTokens, totalWords); + } + } + + @JsonDeserialize(builder = InterruptEvent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InterruptEvent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Event.Type type; + + private InterruptEvent(Builder builder) { + this.type = builder.type; + } + + public static Builder builder() { + return new Builder(); + } + + public static InterruptEvent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, InterruptEvent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Event.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Event.Type type) { + this.type = type; + return this; + } + + public InterruptEvent build() { + return new InterruptEvent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InterruptEvent other = (InterruptEvent) o; + return (Objects.equals(type, other.type)); + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + } + + @JsonDeserialize( + builder = InsightsV1CallEventConversationRelayData.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV1CallEventConversationRelayData { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_id") + @Getter + private final String sessionId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sequence_number") + @Getter + private final Integer sequenceNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_latency") + @Getter + private final LatencyEvent ttsLatency; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stt_latency") + @Getter + private final LatencyEvent sttLatency; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("interrupt") + @Getter + private final InterruptEvent interrupt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_token_received") + @Getter + private final LastTokenReceivedEvent lastTokenReceived; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configurations") + @Getter + private final ConfigurationEvent configurations; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("language_changed") + @Getter + private final LanguageChangedEvent languageChanged; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_wrap_up") + @Getter + private final CallWrapUpEvent callWrapUp; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error") + @Getter + private final ErrorEvent error; + + private InsightsV1CallEventConversationRelayData(Builder builder) { + this.sessionId = builder.sessionId; + this.sequenceNumber = builder.sequenceNumber; + this.ttsLatency = builder.ttsLatency; + this.sttLatency = builder.sttLatency; + this.interrupt = builder.interrupt; + this.lastTokenReceived = builder.lastTokenReceived; + this.configurations = builder.configurations; + this.languageChanged = builder.languageChanged; + this.callWrapUp = builder.callWrapUp; + this.error = builder.error; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV1CallEventConversationRelayData fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV1CallEventConversationRelayData.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("session_id") + private String sessionId; + + @JsonProperty("sequence_number") + private Integer sequenceNumber; + + @JsonProperty("tts_latency") + private LatencyEvent ttsLatency; + + @JsonProperty("stt_latency") + private LatencyEvent sttLatency; + + @JsonProperty("interrupt") + private InterruptEvent interrupt; + + @JsonProperty("last_token_received") + private LastTokenReceivedEvent lastTokenReceived; + + @JsonProperty("configurations") + private ConfigurationEvent configurations; + + @JsonProperty("language_changed") + private LanguageChangedEvent languageChanged; + + @JsonProperty("call_wrap_up") + private CallWrapUpEvent callWrapUp; + + @JsonProperty("error") + private ErrorEvent error; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("session_id") + public Builder sessionId(String sessionId) { + this.sessionId = sessionId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sequence_number") + public Builder sequenceNumber(Integer sequenceNumber) { + this.sequenceNumber = sequenceNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("tts_latency") + public Builder ttsLatency(LatencyEvent ttsLatency) { + this.ttsLatency = ttsLatency; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stt_latency") + public Builder sttLatency(LatencyEvent sttLatency) { + this.sttLatency = sttLatency; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("interrupt") + public Builder interrupt(InterruptEvent interrupt) { + this.interrupt = interrupt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_token_received") + public Builder lastTokenReceived( + LastTokenReceivedEvent lastTokenReceived + ) { + this.lastTokenReceived = lastTokenReceived; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configurations") + public Builder configurations(ConfigurationEvent configurations) { + this.configurations = configurations; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("language_changed") + public Builder languageChanged( + LanguageChangedEvent languageChanged + ) { + this.languageChanged = languageChanged; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_wrap_up") + public Builder callWrapUp(CallWrapUpEvent callWrapUp) { + this.callWrapUp = callWrapUp; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error") + public Builder error(ErrorEvent error) { + this.error = error; + return this; + } + + public InsightsV1CallEventConversationRelayData build() { + return new InsightsV1CallEventConversationRelayData(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV1CallEventConversationRelayData other = + (InsightsV1CallEventConversationRelayData) o; + return ( + Objects.equals(sessionId, other.sessionId) && + Objects.equals(sequenceNumber, other.sequenceNumber) && + Objects.equals(ttsLatency, other.ttsLatency) && + Objects.equals(sttLatency, other.sttLatency) && + Objects.equals(interrupt, other.interrupt) && + Objects.equals(lastTokenReceived, other.lastTokenReceived) && + Objects.equals(configurations, other.configurations) && + Objects.equals(languageChanged, other.languageChanged) && + Objects.equals(callWrapUp, other.callWrapUp) && + Objects.equals(error, other.error) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + sessionId, + sequenceNumber, + ttsLatency, + sttLatency, + interrupt, + lastTokenReceived, + configurations, + languageChanged, + callWrapUp, + error + ); + } + } + + @JsonDeserialize(builder = LatencyEvent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LatencyEvent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("latency_ms") + @Getter + private final Integer latencyMs; + + private LatencyEvent(Builder builder) { + this.latencyMs = builder.latencyMs; + } + + public static Builder builder() { + return new Builder(); + } + + public static LatencyEvent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LatencyEvent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("latency_ms") + private Integer latencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("latency_ms") + public Builder latencyMs(Integer latencyMs) { + this.latencyMs = latencyMs; + return this; + } + + public LatencyEvent build() { + return new LatencyEvent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LatencyEvent other = (LatencyEvent) o; + return (Objects.equals(latencyMs, other.latencyMs)); + } + + @Override + public int hashCode() { + return Objects.hash(latencyMs); + } + } + + /** + * Converts a JSON String into a Event object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Event.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Event object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Event object represented by the provided JSON + */ + public static Event fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Event.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final Object carrierEdge; + + @Getter + private final Object clientEdge; + + @Getter + private final InsightsV1CallEventConversationRelayData conversationRelayData; + + @Getter + private final Event.TwilioEdge edge; + + @Getter + private final String group; + + @Getter + private final Event.Level level; + + @Getter + private final String name; + + @Getter + private final Object sdkEdge; + + @Getter + private final Object sipEdge; + + @Getter + private final String timestamp; + + @JsonCreator + private Event( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("carrier_edge") final Object carrierEdge, + @JsonProperty("client_edge") final Object clientEdge, + @JsonProperty( + "conversation_relay_data" + ) final InsightsV1CallEventConversationRelayData conversationRelayData, + @JsonProperty("edge") final Event.TwilioEdge edge, + @JsonProperty("group") final String group, + @JsonProperty("level") final Event.Level level, + @JsonProperty("name") final String name, + @JsonProperty("sdk_edge") final Object sdkEdge, + @JsonProperty("sip_edge") final Object sipEdge, + @JsonProperty("timestamp") final String timestamp + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.carrierEdge = carrierEdge; + this.clientEdge = clientEdge; + this.conversationRelayData = conversationRelayData; + this.edge = edge; + this.group = group; + this.level = level; + this.name = name; + this.sdkEdge = sdkEdge; + this.sipEdge = sipEdge; + this.timestamp = timestamp; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Event other = (Event) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(carrierEdge, other.carrierEdge) && + Objects.equals(clientEdge, other.clientEdge) && + Objects.equals( + conversationRelayData, + other.conversationRelayData + ) && + Objects.equals(edge, other.edge) && + Objects.equals(group, other.group) && + Objects.equals(level, other.level) && + Objects.equals(name, other.name) && + Objects.equals(sdkEdge, other.sdkEdge) && + Objects.equals(sipEdge, other.sipEdge) && + Objects.equals(timestamp, other.timestamp) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + callSid, + carrierEdge, + clientEdge, + conversationRelayData, + edge, + group, + level, + name, + sdkEdge, + sipEdge, + timestamp + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/EventReader.java b/src/main/java/com/twilio/rest/insights/v1/call/EventReader.java new file mode 100644 index 0000000000..342384e6bd --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/EventReader.java @@ -0,0 +1,213 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EventReader extends Reader { + + private String pathCallSid; + private Event.TwilioEdge edge; + private Long pageSize; + + public EventReader(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + public EventReader setEdge(final Event.TwilioEdge edge) { + this.edge = edge; + return this; + } + + public EventReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Voice/{CallSid}/Events"; + + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Event read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (edge != null) { + Serializer.toString(request, "Edge", edge, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/Metric.java b/src/main/java/com/twilio/rest/insights/v1/call/Metric.java new file mode 100644 index 0000000000..f38914be0a --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/Metric.java @@ -0,0 +1,237 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Metric extends Resource { + + public static MetricReader reader(final String pathCallSid) { + return new MetricReader(pathCallSid); + } + + public enum TwilioEdge { + UNKNOWN_EDGE("unknown_edge"), + CARRIER_EDGE("carrier_edge"), + SIP_EDGE("sip_edge"), + SDK_EDGE("sdk_edge"), + CLIENT_EDGE("client_edge"); + + private final String value; + + private TwilioEdge(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TwilioEdge forValue(final String value) { + return Promoter.enumFromString(value, TwilioEdge.values()); + } + } + + public enum StreamDirection { + UNKNOWN("unknown"), + INBOUND("inbound"), + OUTBOUND("outbound"), + BOTH("both"); + + private final String value; + + private StreamDirection(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static StreamDirection forValue(final String value) { + return Promoter.enumFromString(value, StreamDirection.values()); + } + } + + /** + * Converts a JSON String into a Metric object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Metric object represented by the provided JSON + */ + public static Metric fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Metric.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Metric object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Metric object represented by the provided JSON + */ + public static Metric fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Metric.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final Object carrierEdge; + + @Getter + private final Object clientEdge; + + @Getter + private final Metric.StreamDirection direction; + + @Getter + private final Metric.TwilioEdge edge; + + @Getter + private final Object sdkEdge; + + @Getter + private final Object sipEdge; + + @Getter + private final String timestamp; + + @JsonCreator + private Metric( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("call_sid") final String callSid, + @JsonProperty("carrier_edge") final Object carrierEdge, + @JsonProperty("client_edge") final Object clientEdge, + @JsonProperty("direction") final Metric.StreamDirection direction, + @JsonProperty("edge") final Metric.TwilioEdge edge, + @JsonProperty("sdk_edge") final Object sdkEdge, + @JsonProperty("sip_edge") final Object sipEdge, + @JsonProperty("timestamp") final String timestamp + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.carrierEdge = carrierEdge; + this.clientEdge = clientEdge; + this.direction = direction; + this.edge = edge; + this.sdkEdge = sdkEdge; + this.sipEdge = sipEdge; + this.timestamp = timestamp; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Metric other = (Metric) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(carrierEdge, other.carrierEdge) && + Objects.equals(clientEdge, other.clientEdge) && + Objects.equals(direction, other.direction) && + Objects.equals(edge, other.edge) && + Objects.equals(sdkEdge, other.sdkEdge) && + Objects.equals(sipEdge, other.sipEdge) && + Objects.equals(timestamp, other.timestamp) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + callSid, + carrierEdge, + clientEdge, + direction, + edge, + sdkEdge, + sipEdge, + timestamp + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/call/MetricReader.java b/src/main/java/com/twilio/rest/insights/v1/call/MetricReader.java new file mode 100644 index 0000000000..e3e2ca663d --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/call/MetricReader.java @@ -0,0 +1,228 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.call; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MetricReader extends Reader { + + private String pathCallSid; + private Metric.TwilioEdge edge; + private Metric.StreamDirection direction; + private Long pageSize; + + public MetricReader(final String pathCallSid) { + this.pathCallSid = pathCallSid; + } + + public MetricReader setEdge(final Metric.TwilioEdge edge) { + this.edge = edge; + return this; + } + + public MetricReader setDirection(final Metric.StreamDirection direction) { + this.direction = direction; + return this; + } + + public MetricReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "metrics", + response.getContent(), + Metric.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Voice/{CallSid}/Metrics"; + + path = path.replace("{" + "CallSid" + "}", this.pathCallSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "metrics", + response.getContent(), + Metric.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Metric read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "metrics", + response.getContent(), + Metric.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (edge != null) { + Serializer.toString(request, "Edge", edge, ParameterType.QUERY); + } + + if (direction != null) { + Serializer.toString( + request, + "Direction", + direction, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipant.java b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipant.java new file mode 100644 index 0000000000..2b79db1105 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipant.java @@ -0,0 +1,505 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.conference; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ConferenceParticipant extends Resource { + + public static ConferenceParticipantFetcher fetcher( + final String pathConferenceSid, + final String pathParticipantSid + ) { + return new ConferenceParticipantFetcher( + pathConferenceSid, + pathParticipantSid + ); + } + + public static ConferenceParticipantReader reader( + final String pathConferenceSid + ) { + return new ConferenceParticipantReader(pathConferenceSid); + } + + public enum CallDirection { + INBOUND("inbound"), + OUTBOUND("outbound"); + + private final String value; + + private CallDirection(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallDirection forValue(final String value) { + return Promoter.enumFromString(value, CallDirection.values()); + } + } + + public enum JitterBufferSize { + LARGE("large"), + SMALL("small"), + MEDIUM("medium"), + OFF("off"); + + private final String value; + + private JitterBufferSize(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static JitterBufferSize forValue(final String value) { + return Promoter.enumFromString(value, JitterBufferSize.values()); + } + } + + public enum CallType { + CARRIER("carrier"), + CLIENT("client"), + SIP("sip"); + + private final String value; + + private CallType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallType forValue(final String value) { + return Promoter.enumFromString(value, CallType.values()); + } + } + + public enum CallStatus { + ANSWERED("answered"), + COMPLETED("completed"), + BUSY("busy"), + FAIL("fail"), + NOANSWER("noanswer"), + RINGING("ringing"), + CANCELED("canceled"); + + private final String value; + + private CallStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallStatus forValue(final String value) { + return Promoter.enumFromString(value, CallStatus.values()); + } + } + + public enum Region { + US1("us1"), + US2("us2"), + AU1("au1"), + BR1("br1"), + IE1("ie1"), + JP1("jp1"), + SG1("sg1"), + DE1("de1"), + IN1("in1"); + + private final String value; + + private Region(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Region forValue(final String value) { + return Promoter.enumFromString(value, Region.values()); + } + } + + public enum ProcessingState { + COMPLETE("complete"), + IN_PROGRESS("in_progress"), + TIMEOUT("timeout"); + + private final String value; + + private ProcessingState(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ProcessingState forValue(final String value) { + return Promoter.enumFromString(value, ProcessingState.values()); + } + } + + /** + * Converts a JSON String into a ConferenceParticipant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ConferenceParticipant object represented by the provided JSON + */ + public static ConferenceParticipant fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ConferenceParticipant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ConferenceParticipant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ConferenceParticipant object represented by the provided JSON + */ + public static ConferenceParticipant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ConferenceParticipant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final ConferenceParticipant.CallDirection callDirection; + + @Getter + private final String callSid; + + @Getter + private final ConferenceParticipant.CallStatus callStatus; + + @Getter + private final ConferenceParticipant.CallType callType; + + @Getter + private final List coachedParticipants; + + @Getter + private final ConferenceParticipant.Region conferenceRegion; + + @Getter + private final String conferenceSid; + + @Getter + private final String countryCode; + + @Getter + private final Integer durationSeconds; + + @Getter + private final Object events; + + @Getter + private final String from; + + @Getter + private final Boolean isCoach; + + @Getter + private final Boolean isModerator; + + @Getter + private final ConferenceParticipant.JitterBufferSize jitterBufferSize; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime joinTime; + + @Getter + private final String label; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime leaveTime; + + @Getter + private final Object metrics; + + @Getter + private final Integer outboundQueueLength; + + @Getter + private final Integer outboundTimeInQueue; + + @Getter + private final ConferenceParticipant.Region participantRegion; + + @Getter + private final String participantSid; + + @Getter + private final ConferenceParticipant.ProcessingState processingState; + + @Getter + private final Object properties; + + @Getter + private final String to; + + @Getter + private final URI url; + + @JsonCreator + private ConferenceParticipant( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "call_direction" + ) final ConferenceParticipant.CallDirection callDirection, + @JsonProperty("call_sid") final String callSid, + @JsonProperty( + "call_status" + ) final ConferenceParticipant.CallStatus callStatus, + @JsonProperty( + "call_type" + ) final ConferenceParticipant.CallType callType, + @JsonProperty("coached_participants") final List< + String + > coachedParticipants, + @JsonProperty( + "conference_region" + ) final ConferenceParticipant.Region conferenceRegion, + @JsonProperty("conference_sid") final String conferenceSid, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("duration_seconds") final Integer durationSeconds, + @JsonProperty("events") final Object events, + @JsonProperty("from") final String from, + @JsonProperty("is_coach") final Boolean isCoach, + @JsonProperty("is_moderator") final Boolean isModerator, + @JsonProperty( + "jitter_buffer_size" + ) final ConferenceParticipant.JitterBufferSize jitterBufferSize, + @JsonProperty("join_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime joinTime, + @JsonProperty("label") final String label, + @JsonProperty("leave_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime leaveTime, + @JsonProperty("metrics") final Object metrics, + @JsonProperty( + "outbound_queue_length" + ) final Integer outboundQueueLength, + @JsonProperty( + "outbound_time_in_queue" + ) final Integer outboundTimeInQueue, + @JsonProperty( + "participant_region" + ) final ConferenceParticipant.Region participantRegion, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty( + "processing_state" + ) final ConferenceParticipant.ProcessingState processingState, + @JsonProperty("properties") final Object properties, + @JsonProperty("to") final String to, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.callDirection = callDirection; + this.callSid = callSid; + this.callStatus = callStatus; + this.callType = callType; + this.coachedParticipants = coachedParticipants; + this.conferenceRegion = conferenceRegion; + this.conferenceSid = conferenceSid; + this.countryCode = countryCode; + this.durationSeconds = durationSeconds; + this.events = events; + this.from = from; + this.isCoach = isCoach; + this.isModerator = isModerator; + this.jitterBufferSize = jitterBufferSize; + this.joinTime = joinTime; + this.label = label; + this.leaveTime = leaveTime; + this.metrics = metrics; + this.outboundQueueLength = outboundQueueLength; + this.outboundTimeInQueue = outboundTimeInQueue; + this.participantRegion = participantRegion; + this.participantSid = participantSid; + this.processingState = processingState; + this.properties = properties; + this.to = to; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConferenceParticipant other = (ConferenceParticipant) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callDirection, other.callDirection) && + Objects.equals(callSid, other.callSid) && + Objects.equals(callStatus, other.callStatus) && + Objects.equals(callType, other.callType) && + Objects.equals(coachedParticipants, other.coachedParticipants) && + Objects.equals(conferenceRegion, other.conferenceRegion) && + Objects.equals(conferenceSid, other.conferenceSid) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(durationSeconds, other.durationSeconds) && + Objects.equals(events, other.events) && + Objects.equals(from, other.from) && + Objects.equals(isCoach, other.isCoach) && + Objects.equals(isModerator, other.isModerator) && + Objects.equals(jitterBufferSize, other.jitterBufferSize) && + Objects.equals(joinTime, other.joinTime) && + Objects.equals(label, other.label) && + Objects.equals(leaveTime, other.leaveTime) && + Objects.equals(metrics, other.metrics) && + Objects.equals(outboundQueueLength, other.outboundQueueLength) && + Objects.equals(outboundTimeInQueue, other.outboundTimeInQueue) && + Objects.equals(participantRegion, other.participantRegion) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(processingState, other.processingState) && + Objects.equals(properties, other.properties) && + Objects.equals(to, other.to) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + callDirection, + callSid, + callStatus, + callType, + coachedParticipants, + conferenceRegion, + conferenceSid, + countryCode, + durationSeconds, + events, + from, + isCoach, + isModerator, + jitterBufferSize, + joinTime, + label, + leaveTime, + metrics, + outboundQueueLength, + outboundTimeInQueue, + participantRegion, + participantSid, + processingState, + properties, + to, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantFetcher.java b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantFetcher.java new file mode 100644 index 0000000000..520c891469 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantFetcher.java @@ -0,0 +1,142 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.conference; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConferenceParticipantFetcher + extends Fetcher { + + private String pathConferenceSid; + private String pathParticipantSid; + private String events; + private String metrics; + + public ConferenceParticipantFetcher( + final String pathConferenceSid, + final String pathParticipantSid + ) { + this.pathConferenceSid = pathConferenceSid; + this.pathParticipantSid = pathParticipantSid; + } + + public ConferenceParticipantFetcher setEvents(final String events) { + this.events = events; + return this; + } + + public ConferenceParticipantFetcher setMetrics(final String metrics) { + this.metrics = metrics; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Conferences/{ConferenceSid}/Participants/{ParticipantSid}"; + + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConferenceParticipant fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ConferenceParticipant fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ConferenceParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ConferenceParticipant content = ConferenceParticipant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (events != null) { + Serializer.toString(request, "Events", events, ParameterType.QUERY); + } + + if (metrics != null) { + Serializer.toString( + request, + "Metrics", + metrics, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantReader.java b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantReader.java new file mode 100644 index 0000000000..8632d43a37 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/conference/ConferenceParticipantReader.java @@ -0,0 +1,252 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.conference; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConferenceParticipantReader extends Reader { + + private String pathConferenceSid; + private String participantSid; + private String label; + private String events; + private Long pageSize; + + public ConferenceParticipantReader(final String pathConferenceSid) { + this.pathConferenceSid = pathConferenceSid; + } + + public ConferenceParticipantReader setParticipantSid( + final String participantSid + ) { + this.participantSid = participantSid; + return this; + } + + public ConferenceParticipantReader setLabel(final String label) { + this.label = label; + return this; + } + + public ConferenceParticipantReader setEvents(final String events) { + this.events = events; + return this; + } + + public ConferenceParticipantReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + ConferenceParticipant.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Conferences/{ConferenceSid}/Participants"; + + path = + path.replace( + "{" + "ConferenceSid" + "}", + this.pathConferenceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + ConferenceParticipant.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ConferenceParticipant read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "participants", + response.getContent(), + ConferenceParticipant.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (participantSid != null) { + Serializer.toString( + request, + "ParticipantSid", + participantSid, + ParameterType.QUERY + ); + } + + if (label != null) { + Serializer.toString(request, "Label", label, ParameterType.QUERY); + } + + if (events != null) { + Serializer.toString(request, "Events", events, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/room/Participant.java b/src/main/java/com/twilio/rest/insights/v1/room/Participant.java new file mode 100644 index 0000000000..bcc5c9488f --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/room/Participant.java @@ -0,0 +1,396 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.room; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Participant extends Resource { + + public static ParticipantFetcher fetcher( + final String pathRoomSid, + final String pathParticipantSid + ) { + return new ParticipantFetcher(pathRoomSid, pathParticipantSid); + } + + public static ParticipantReader reader(final String pathRoomSid) { + return new ParticipantReader(pathRoomSid); + } + + public enum Codec { + VP8("VP8"), + H264("H264"), + VP9("VP9"), + OPUS("opus"); + + private final String value; + + private Codec(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Codec forValue(final String value) { + return Promoter.enumFromString(value, Codec.values()); + } + } + + public enum RoomStatus { + IN_PROGRESS("in_progress"), + CONNECTED("connected"), + COMPLETED("completed"), + DISCONNECTED("disconnected"); + + private final String value; + + private RoomStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RoomStatus forValue(final String value) { + return Promoter.enumFromString(value, RoomStatus.values()); + } + } + + public enum TwilioRealm { + US1("us1"), + US2("us2"), + AU1("au1"), + BR1("br1"), + IE1("ie1"), + JP1("jp1"), + SG1("sg1"), + IN1("in1"), + DE1("de1"), + GLL("gll"); + + private final String value; + + private TwilioRealm(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TwilioRealm forValue(final String value) { + return Promoter.enumFromString(value, TwilioRealm.values()); + } + } + + public enum ParticipantCodec { + VP8("VP8"), + H264("H264"), + VP9("VP9"), + OPUS("opus"); + + private final String value; + + private ParticipantCodec(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ParticipantCodec forValue(final String value) { + return Promoter.enumFromString(value, ParticipantCodec.values()); + } + } + + public enum EdgeLocation { + ASHBURN("ashburn"), + DUBLIN("dublin"), + FRANKFURT("frankfurt"), + SINGAPORE("singapore"), + SYDNEY("sydney"), + SAO_PAULO("sao_paulo"), + ROAMING("roaming"), + UMATILLA("umatilla"), + TOKYO("tokyo"); + + private final String value; + + private EdgeLocation(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EdgeLocation forValue(final String value) { + return Promoter.enumFromString(value, EdgeLocation.values()); + } + } + + /** + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Participant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Participant object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Participant object represented by the provided JSON + */ + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Participant.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final List codecs; + + @Getter + private final Long durationSec; + + @Getter + private final Participant.EdgeLocation edgeLocation; + + @Getter + private final String endReason; + + @Getter + private final Integer errorCode; + + @Getter + private final String errorCodeUrl; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime joinTime; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime leaveTime; + + @Getter + private final Participant.TwilioRealm mediaRegion; + + @Getter + private final String participantIdentity; + + @Getter + private final String participantSid; + + @Getter + private final Object properties; + + @Getter + private final Object publisherInfo; + + @Getter + private final String roomSid; + + @Getter + private final Participant.RoomStatus status; + + @Getter + private final URI url; + + @JsonCreator + private Participant( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("codecs") final List codecs, + @JsonProperty("duration_sec") final Long durationSec, + @JsonProperty( + "edge_location" + ) final Participant.EdgeLocation edgeLocation, + @JsonProperty("end_reason") final String endReason, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("error_code_url") final String errorCodeUrl, + @JsonProperty("join_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime joinTime, + @JsonProperty("leave_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime leaveTime, + @JsonProperty("media_region") final Participant.TwilioRealm mediaRegion, + @JsonProperty("participant_identity") final String participantIdentity, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("properties") final Object properties, + @JsonProperty("publisher_info") final Object publisherInfo, + @JsonProperty("room_sid") final String roomSid, + @JsonProperty("status") final Participant.RoomStatus status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.codecs = codecs; + this.durationSec = durationSec; + this.edgeLocation = edgeLocation; + this.endReason = endReason; + this.errorCode = errorCode; + this.errorCodeUrl = errorCodeUrl; + this.joinTime = joinTime; + this.leaveTime = leaveTime; + this.mediaRegion = mediaRegion; + this.participantIdentity = participantIdentity; + this.participantSid = participantSid; + this.properties = properties; + this.publisherInfo = publisherInfo; + this.roomSid = roomSid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Participant other = (Participant) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(codecs, other.codecs) && + Objects.equals(durationSec, other.durationSec) && + Objects.equals(edgeLocation, other.edgeLocation) && + Objects.equals(endReason, other.endReason) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorCodeUrl, other.errorCodeUrl) && + Objects.equals(joinTime, other.joinTime) && + Objects.equals(leaveTime, other.leaveTime) && + Objects.equals(mediaRegion, other.mediaRegion) && + Objects.equals(participantIdentity, other.participantIdentity) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(properties, other.properties) && + Objects.equals(publisherInfo, other.publisherInfo) && + Objects.equals(roomSid, other.roomSid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + codecs, + durationSec, + edgeLocation, + endReason, + errorCode, + errorCodeUrl, + joinTime, + leaveTime, + mediaRegion, + participantIdentity, + participantSid, + properties, + publisherInfo, + roomSid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/room/ParticipantFetcher.java b/src/main/java/com/twilio/rest/insights/v1/room/ParticipantFetcher.java new file mode 100644 index 0000000000..02ee0fc85d --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/room/ParticipantFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.room; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantFetcher extends Fetcher { + + private String pathRoomSid; + private String pathParticipantSid; + + public ParticipantFetcher( + final String pathRoomSid, + final String pathParticipantSid + ) { + this.pathRoomSid = pathRoomSid; + this.pathParticipantSid = pathParticipantSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Video/Rooms/{RoomSid}/Participants/{ParticipantSid}"; + + path = path.replace("{" + "RoomSid" + "}", this.pathRoomSid.toString()); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Participant fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v1/room/ParticipantReader.java b/src/main/java/com/twilio/rest/insights/v1/room/ParticipantReader.java new file mode 100644 index 0000000000..db2e750d85 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v1/room/ParticipantReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v1.room; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ParticipantReader extends Reader { + + private String pathRoomSid; + private Long pageSize; + + public ParticipantReader(final String pathRoomSid) { + this.pathRoomSid = pathRoomSid; + } + + public ParticipantReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Video/Rooms/{RoomSid}/Participants"; + + path = path.replace("{" + "RoomSid" + "}", this.pathRoomSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/Inbound.java b/src/main/java/com/twilio/rest/insights/v2/Inbound.java new file mode 100644 index 0000000000..38ede773b2 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/Inbound.java @@ -0,0 +1,316 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Inbound extends Resource { + + public static InboundReader reader(final String pathReportId) { + return new InboundReader(pathReportId); + } + + @JsonDeserialize( + builder = InsightsV2InboundPhoneNumberReportCallStatePercentage.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2InboundPhoneNumberReportCallStatePercentage { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("completed") + @Getter + private final Float completed; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fail") + @Getter + private final Float fail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("busy") + @Getter + private final Float busy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("noanswer") + @Getter + private final Float noanswer; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("canceled") + @Getter + private final Float canceled; + + private InsightsV2InboundPhoneNumberReportCallStatePercentage( + Builder builder + ) { + this.completed = builder.completed; + this.fail = builder.fail; + this.busy = builder.busy; + this.noanswer = builder.noanswer; + this.canceled = builder.canceled; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2InboundPhoneNumberReportCallStatePercentage fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2InboundPhoneNumberReportCallStatePercentage.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("completed") + private Float completed; + + @JsonProperty("fail") + private Float fail; + + @JsonProperty("busy") + private Float busy; + + @JsonProperty("noanswer") + private Float noanswer; + + @JsonProperty("canceled") + private Float canceled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("completed") + public Builder completed(Float completed) { + this.completed = completed; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fail") + public Builder fail(Float fail) { + this.fail = fail; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("busy") + public Builder busy(Float busy) { + this.busy = busy; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("noanswer") + public Builder noanswer(Float noanswer) { + this.noanswer = noanswer; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("canceled") + public Builder canceled(Float canceled) { + this.canceled = canceled; + return this; + } + + public InsightsV2InboundPhoneNumberReportCallStatePercentage build() { + return new InsightsV2InboundPhoneNumberReportCallStatePercentage( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2InboundPhoneNumberReportCallStatePercentage other = + (InsightsV2InboundPhoneNumberReportCallStatePercentage) o; + return ( + Objects.equals(completed, other.completed) && + Objects.equals(fail, other.fail) && + Objects.equals(busy, other.busy) && + Objects.equals(noanswer, other.noanswer) && + Objects.equals(canceled, other.canceled) + ); + } + + @Override + public int hashCode() { + return Objects.hash(completed, fail, busy, noanswer, canceled); + } + } + + /** + * Converts a JSON String into a Inbound object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Inbound object represented by the provided JSON + */ + public static Inbound fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Inbound.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Inbound object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Inbound object represented by the provided JSON + */ + public static Inbound fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Inbound.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Float callAnswerScore; + + @Getter + private final InsightsV2InboundPhoneNumberReportCallStatePercentage callStatePercentage; + + @Getter + private final String handle; + + @Getter + private final Float silentCallsPercentage; + + @Getter + private final Integer totalCalls; + + @JsonCreator + private Inbound( + @JsonProperty("call_answer_score") final Float callAnswerScore, + @JsonProperty( + "call_state_percentage" + ) final InsightsV2InboundPhoneNumberReportCallStatePercentage callStatePercentage, + @JsonProperty("handle") final String handle, + @JsonProperty( + "silent_calls_percentage" + ) final Float silentCallsPercentage, + @JsonProperty("total_calls") final Integer totalCalls + ) { + this.callAnswerScore = callAnswerScore; + this.callStatePercentage = callStatePercentage; + this.handle = handle; + this.silentCallsPercentage = silentCallsPercentage; + this.totalCalls = totalCalls; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Inbound other = (Inbound) o; + return ( + Objects.equals(callAnswerScore, other.callAnswerScore) && + Objects.equals(callStatePercentage, other.callStatePercentage) && + Objects.equals(handle, other.handle) && + Objects.equals( + silentCallsPercentage, + other.silentCallsPercentage + ) && + Objects.equals(totalCalls, other.totalCalls) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + callAnswerScore, + callStatePercentage, + handle, + silentCallsPercentage, + totalCalls + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/InboundReader.java b/src/main/java/com/twilio/rest/insights/v2/InboundReader.java new file mode 100644 index 0000000000..b003948af0 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/InboundReader.java @@ -0,0 +1,208 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InboundReader extends Reader { + + private String pathReportId; + private Long pageSize; + + public InboundReader(final String pathReportId) { + this.pathReportId = pathReportId; + } + + public InboundReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "reports", + response.getContent(), + Inbound.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Reports/PhoneNumbers/Inbound/{reportId}"; + + path = + path.replace("{" + "reportId" + "}", this.pathReportId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "reports", + response.getContent(), + Inbound.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Inbound read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "reports", + response.getContent(), + Inbound.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/InboundReport.java b/src/main/java/com/twilio/rest/insights/v2/InboundReport.java new file mode 100644 index 0000000000..d7e8d42616 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/InboundReport.java @@ -0,0 +1,698 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InboundReport extends Resource { + + public static InboundReportCreator creator() { + return new InboundReportCreator(); + } + + public enum ReportStatus { + CREATED("created"), + RUNNING("running"), + COMPLETED("completed"); + + private final String value; + + private ReportStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ReportStatus forValue(final String value) { + return Promoter.enumFromString(value, ReportStatus.values()); + } + } + + @JsonDeserialize(builder = PhoneNumberReportFilter.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PhoneNumberReportFilter { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + @Getter + private final List values; + + private PhoneNumberReportFilter(Builder builder) { + this.key = builder.key; + this.values = builder.values; + } + + public static Builder builder() { + return new Builder(); + } + + public static PhoneNumberReportFilter fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, PhoneNumberReportFilter.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("values") + private List values; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + public Builder values(List values) { + this.values = values; + return this; + } + + public PhoneNumberReportFilter build() { + return new PhoneNumberReportFilter(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PhoneNumberReportFilter other = (PhoneNumberReportFilter) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, values); + } + } + + @JsonDeserialize( + builder = InsightsV2CreatePhoneNumbersReportRequestTimeRange.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2CreatePhoneNumbersReportRequestTimeRange { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + @Getter + private final ZonedDateTime startDatetime; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + @Getter + private final ZonedDateTime endDatetime; + + private InsightsV2CreatePhoneNumbersReportRequestTimeRange( + Builder builder + ) { + this.startDatetime = builder.startDatetime; + this.endDatetime = builder.endDatetime; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2CreatePhoneNumbersReportRequestTimeRange fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2CreatePhoneNumbersReportRequestTimeRange.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("start_datetime") + private ZonedDateTime startDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("end_datetime") + private ZonedDateTime endDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + public Builder startDatetime(ZonedDateTime startDatetime) { + this.startDatetime = startDatetime; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + public Builder endDatetime(ZonedDateTime endDatetime) { + this.endDatetime = endDatetime; + return this; + } + + public InsightsV2CreatePhoneNumbersReportRequestTimeRange build() { + return new InsightsV2CreatePhoneNumbersReportRequestTimeRange( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2CreatePhoneNumbersReportRequestTimeRange other = + (InsightsV2CreatePhoneNumbersReportRequestTimeRange) o; + return ( + Objects.equals(startDatetime, other.startDatetime) && + Objects.equals(endDatetime, other.endDatetime) + ); + } + + @Override + public int hashCode() { + return Objects.hash(startDatetime, endDatetime); + } + } + + @JsonDeserialize(builder = ReportFilter.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReportFilter { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + @Getter + private final List values; + + private ReportFilter(Builder builder) { + this.key = builder.key; + this.values = builder.values; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReportFilter fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ReportFilter.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("values") + private List values; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + public Builder values(List values) { + this.values = values; + return this; + } + + public ReportFilter build() { + return new ReportFilter(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReportFilter other = (ReportFilter) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, values); + } + } + + @JsonDeserialize( + builder = InsightsV2CreatePhoneNumbersReportRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2CreatePhoneNumbersReportRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_range") + @Getter + private final InsightsV2CreatePhoneNumbersReportRequestTimeRange timeRange; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + @Getter + private final List filters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("size") + @Getter + private final Integer size; + + private InsightsV2CreatePhoneNumbersReportRequest(Builder builder) { + this.timeRange = builder.timeRange; + this.filters = builder.filters; + this.size = builder.size; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2CreatePhoneNumbersReportRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2CreatePhoneNumbersReportRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("time_range") + private InsightsV2CreatePhoneNumbersReportRequestTimeRange timeRange; + + @JsonProperty("filters") + private List filters; + + @JsonProperty("size") + private Integer size; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_range") + public Builder timeRange( + InsightsV2CreatePhoneNumbersReportRequestTimeRange timeRange + ) { + this.timeRange = timeRange; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + public Builder filters(List filters) { + this.filters = filters; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("size") + public Builder size(Integer size) { + this.size = size; + return this; + } + + public InsightsV2CreatePhoneNumbersReportRequest build() { + return new InsightsV2CreatePhoneNumbersReportRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2CreatePhoneNumbersReportRequest other = + (InsightsV2CreatePhoneNumbersReportRequest) o; + return ( + Objects.equals(timeRange, other.timeRange) && + Objects.equals(filters, other.filters) && + Objects.equals(size, other.size) + ); + } + + @Override + public int hashCode() { + return Objects.hash(timeRange, filters, size); + } + } + + @JsonDeserialize(builder = ReportMetadata.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReportMetadata { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + @Getter + private final ZonedDateTime startDatetime; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + @Getter + private final ZonedDateTime endDatetime; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + @Getter + private final List filters; + + private ReportMetadata(Builder builder) { + this.startDatetime = builder.startDatetime; + this.endDatetime = builder.endDatetime; + this.filters = builder.filters; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReportMetadata fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ReportMetadata.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("start_datetime") + private ZonedDateTime startDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("end_datetime") + private ZonedDateTime endDatetime; + + @JsonProperty("filters") + private List filters; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + public Builder startDatetime(ZonedDateTime startDatetime) { + this.startDatetime = startDatetime; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + public Builder endDatetime(ZonedDateTime endDatetime) { + this.endDatetime = endDatetime; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + public Builder filters(List filters) { + this.filters = filters; + return this; + } + + public ReportMetadata build() { + return new ReportMetadata(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReportMetadata other = (ReportMetadata) o; + return ( + Objects.equals(startDatetime, other.startDatetime) && + Objects.equals(endDatetime, other.endDatetime) && + Objects.equals(filters, other.filters) + ); + } + + @Override + public int hashCode() { + return Objects.hash(startDatetime, endDatetime, filters); + } + } + + /** + * Converts a JSON String into a InboundReport object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InboundReport object represented by the provided JSON + */ + public static InboundReport fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InboundReport.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InboundReport object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InboundReport object represented by the provided JSON + */ + public static InboundReport fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InboundReport.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String reportId; + + @Getter + private final ReportMetadata requestMeta; + + @Getter + private final InboundReport.ReportStatus status; + + @Getter + private final URI url; + + @JsonCreator + private InboundReport( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("report_id") final String reportId, + @JsonProperty("request_meta") final ReportMetadata requestMeta, + @JsonProperty("status") final InboundReport.ReportStatus status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.reportId = reportId; + this.requestMeta = requestMeta; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InboundReport other = (InboundReport) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(reportId, other.reportId) && + Objects.equals(requestMeta, other.requestMeta) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, reportId, requestMeta, status, url); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/InboundReportCreator.java b/src/main/java/com/twilio/rest/insights/v2/InboundReportCreator.java new file mode 100644 index 0000000000..ea1b99a481 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/InboundReportCreator.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InboundReportCreator extends Creator { + + private InboundReport.InsightsV2CreatePhoneNumbersReportRequest insightsV2CreatePhoneNumbersReportRequest; + + public InboundReportCreator() {} + + public InboundReportCreator setInsightsV2CreatePhoneNumbersReportRequest( + final InboundReport.InsightsV2CreatePhoneNumbersReportRequest insightsV2CreatePhoneNumbersReportRequest + ) { + this.insightsV2CreatePhoneNumbersReportRequest = + insightsV2CreatePhoneNumbersReportRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Reports/PhoneNumbers/Inbound"; + + Request request = new Request( + HttpMethod.POST, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InboundReport creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InboundReport create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InboundReport.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InboundReport content = InboundReport.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (insightsV2CreatePhoneNumbersReportRequest != null) { + request.setBody( + InboundReport.toJson( + insightsV2CreatePhoneNumbersReportRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/Outbound.java b/src/main/java/com/twilio/rest/insights/v2/Outbound.java new file mode 100644 index 0000000000..4b6ee8e123 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/Outbound.java @@ -0,0 +1,739 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Outbound extends Resource { + + public static OutboundReader reader(final String pathReportId) { + return new OutboundReader(pathReportId); + } + + @JsonDeserialize( + builder = InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + @Getter + private final Integer totalCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answered_by_human_percentage") + @Getter + private final Float answeredByHumanPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answered_by_machine_percentage") + @Getter + private final Float answeredByMachinePercentage; + + private InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection( + Builder builder + ) { + this.totalCalls = builder.totalCalls; + this.answeredByHumanPercentage = builder.answeredByHumanPercentage; + this.answeredByMachinePercentage = + builder.answeredByMachinePercentage; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total_calls") + private Integer totalCalls; + + @JsonProperty("answered_by_human_percentage") + private Float answeredByHumanPercentage; + + @JsonProperty("answered_by_machine_percentage") + private Float answeredByMachinePercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + public Builder totalCalls(Integer totalCalls) { + this.totalCalls = totalCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answered_by_human_percentage") + public Builder answeredByHumanPercentage( + Float answeredByHumanPercentage + ) { + this.answeredByHumanPercentage = answeredByHumanPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answered_by_machine_percentage") + public Builder answeredByMachinePercentage( + Float answeredByMachinePercentage + ) { + this.answeredByMachinePercentage = answeredByMachinePercentage; + return this; + } + + public InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection build() { + return new InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection other = + (InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection) o; + return ( + Objects.equals(totalCalls, other.totalCalls) && + Objects.equals( + answeredByHumanPercentage, + other.answeredByHumanPercentage + ) && + Objects.equals( + answeredByMachinePercentage, + other.answeredByMachinePercentage + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + totalCalls, + answeredByHumanPercentage, + answeredByMachinePercentage + ); + } + } + + @JsonDeserialize(builder = CountyCarrierValue.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CountyCarrierValue { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country") + @Getter + private final String country; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carriers") + @Getter + private final List carriers; + + private CountyCarrierValue(Builder builder) { + this.country = builder.country; + this.carriers = builder.carriers; + } + + public static Builder builder() { + return new Builder(); + } + + public static CountyCarrierValue fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CountyCarrierValue.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("country") + private String country; + + @JsonProperty("carriers") + private List carriers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country") + public Builder country(String country) { + this.country = country; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carriers") + public Builder carriers(List carriers) { + this.carriers = carriers; + return this; + } + + public CountyCarrierValue build() { + return new CountyCarrierValue(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CountyCarrierValue other = (CountyCarrierValue) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(carriers, other.carriers) + ); + } + + @Override + public int hashCode() { + return Objects.hash(country, carriers); + } + } + + @JsonDeserialize(builder = CountyCarrierValueCarriers.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CountyCarrierValueCarriers { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier") + @Getter + private final String carrier; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + @Getter + private final Integer totalCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls") + @Getter + private final Integer blockedCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls_percentage") + @Getter + private final Float blockedCallsPercentage; + + private CountyCarrierValueCarriers(Builder builder) { + this.carrier = builder.carrier; + this.totalCalls = builder.totalCalls; + this.blockedCalls = builder.blockedCalls; + this.blockedCallsPercentage = builder.blockedCallsPercentage; + } + + public static Builder builder() { + return new Builder(); + } + + public static CountyCarrierValueCarriers fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CountyCarrierValueCarriers.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("carrier") + private String carrier; + + @JsonProperty("total_calls") + private Integer totalCalls; + + @JsonProperty("blocked_calls") + private Integer blockedCalls; + + @JsonProperty("blocked_calls_percentage") + private Float blockedCallsPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier") + public Builder carrier(String carrier) { + this.carrier = carrier; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + public Builder totalCalls(Integer totalCalls) { + this.totalCalls = totalCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls") + public Builder blockedCalls(Integer blockedCalls) { + this.blockedCalls = blockedCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls_percentage") + public Builder blockedCallsPercentage( + Float blockedCallsPercentage + ) { + this.blockedCallsPercentage = blockedCallsPercentage; + return this; + } + + public CountyCarrierValueCarriers build() { + return new CountyCarrierValueCarriers(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CountyCarrierValueCarriers other = (CountyCarrierValueCarriers) o; + return ( + Objects.equals(carrier, other.carrier) && + Objects.equals(totalCalls, other.totalCalls) && + Objects.equals(blockedCalls, other.blockedCalls) && + Objects.equals( + blockedCallsPercentage, + other.blockedCallsPercentage + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + carrier, + totalCalls, + blockedCalls, + blockedCallsPercentage + ); + } + } + + @JsonDeserialize( + builder = InsightsV2OutboundPhoneNumberReportCallStatePercentage.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2OutboundPhoneNumberReportCallStatePercentage { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("completed") + @Getter + private final Float completed; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fail") + @Getter + private final Float fail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("busy") + @Getter + private final Float busy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("noanswer") + @Getter + private final Float noanswer; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("canceled") + @Getter + private final Float canceled; + + private InsightsV2OutboundPhoneNumberReportCallStatePercentage( + Builder builder + ) { + this.completed = builder.completed; + this.fail = builder.fail; + this.busy = builder.busy; + this.noanswer = builder.noanswer; + this.canceled = builder.canceled; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2OutboundPhoneNumberReportCallStatePercentage fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2OutboundPhoneNumberReportCallStatePercentage.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("completed") + private Float completed; + + @JsonProperty("fail") + private Float fail; + + @JsonProperty("busy") + private Float busy; + + @JsonProperty("noanswer") + private Float noanswer; + + @JsonProperty("canceled") + private Float canceled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("completed") + public Builder completed(Float completed) { + this.completed = completed; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fail") + public Builder fail(Float fail) { + this.fail = fail; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("busy") + public Builder busy(Float busy) { + this.busy = busy; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("noanswer") + public Builder noanswer(Float noanswer) { + this.noanswer = noanswer; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("canceled") + public Builder canceled(Float canceled) { + this.canceled = canceled; + return this; + } + + public InsightsV2OutboundPhoneNumberReportCallStatePercentage build() { + return new InsightsV2OutboundPhoneNumberReportCallStatePercentage( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2OutboundPhoneNumberReportCallStatePercentage other = + (InsightsV2OutboundPhoneNumberReportCallStatePercentage) o; + return ( + Objects.equals(completed, other.completed) && + Objects.equals(fail, other.fail) && + Objects.equals(busy, other.busy) && + Objects.equals(noanswer, other.noanswer) && + Objects.equals(canceled, other.canceled) + ); + } + + @Override + public int hashCode() { + return Objects.hash(completed, fail, busy, noanswer, canceled); + } + } + + /** + * Converts a JSON String into a Outbound object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Outbound object represented by the provided JSON + */ + public static Outbound fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Outbound.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Outbound object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Outbound object represented by the provided JSON + */ + public static Outbound fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Outbound.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Map answerRateDeviceType; + + @Getter + private final InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection answeringMachineDetection; + + @Getter + private final List blockedCallsByCarrier; + + @Getter + private final Float callAnswerScore; + + @Getter + private final InsightsV2OutboundPhoneNumberReportCallStatePercentage callStatePercentage; + + @Getter + private final Map callsByDeviceType; + + @Getter + private final String handle; + + @Getter + private final Float longDurationCallsPercentage; + + @Getter + private final Float potentialRobocallsPercentage; + + @Getter + private final Float shortDurationCallsPercentage; + + @Getter + private final Float silentCallsPercentage; + + @Getter + private final Integer totalCalls; + + @JsonCreator + private Outbound( + @JsonProperty("answer_rate_device_type") final Map< + String, + Float + > answerRateDeviceType, + @JsonProperty( + "answering_machine_detection" + ) final InsightsV2OutboundPhoneNumberReportAnsweringMachineDetection answeringMachineDetection, + @JsonProperty("blocked_calls_by_carrier") final List< + CountyCarrierValue + > blockedCallsByCarrier, + @JsonProperty("call_answer_score") final Float callAnswerScore, + @JsonProperty( + "call_state_percentage" + ) final InsightsV2OutboundPhoneNumberReportCallStatePercentage callStatePercentage, + @JsonProperty("calls_by_device_type") final Map< + String, + Integer + > callsByDeviceType, + @JsonProperty("handle") final String handle, + @JsonProperty( + "long_duration_calls_percentage" + ) final Float longDurationCallsPercentage, + @JsonProperty( + "potential_robocalls_percentage" + ) final Float potentialRobocallsPercentage, + @JsonProperty( + "short_duration_calls_percentage" + ) final Float shortDurationCallsPercentage, + @JsonProperty( + "silent_calls_percentage" + ) final Float silentCallsPercentage, + @JsonProperty("total_calls") final Integer totalCalls + ) { + this.answerRateDeviceType = answerRateDeviceType; + this.answeringMachineDetection = answeringMachineDetection; + this.blockedCallsByCarrier = blockedCallsByCarrier; + this.callAnswerScore = callAnswerScore; + this.callStatePercentage = callStatePercentage; + this.callsByDeviceType = callsByDeviceType; + this.handle = handle; + this.longDurationCallsPercentage = longDurationCallsPercentage; + this.potentialRobocallsPercentage = potentialRobocallsPercentage; + this.shortDurationCallsPercentage = shortDurationCallsPercentage; + this.silentCallsPercentage = silentCallsPercentage; + this.totalCalls = totalCalls; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Outbound other = (Outbound) o; + return ( + Objects.equals(answerRateDeviceType, other.answerRateDeviceType) && + Objects.equals( + answeringMachineDetection, + other.answeringMachineDetection + ) && + Objects.equals( + blockedCallsByCarrier, + other.blockedCallsByCarrier + ) && + Objects.equals(callAnswerScore, other.callAnswerScore) && + Objects.equals(callStatePercentage, other.callStatePercentage) && + Objects.equals(callsByDeviceType, other.callsByDeviceType) && + Objects.equals(handle, other.handle) && + Objects.equals( + longDurationCallsPercentage, + other.longDurationCallsPercentage + ) && + Objects.equals( + potentialRobocallsPercentage, + other.potentialRobocallsPercentage + ) && + Objects.equals( + shortDurationCallsPercentage, + other.shortDurationCallsPercentage + ) && + Objects.equals( + silentCallsPercentage, + other.silentCallsPercentage + ) && + Objects.equals(totalCalls, other.totalCalls) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + answerRateDeviceType, + answeringMachineDetection, + blockedCallsByCarrier, + callAnswerScore, + callStatePercentage, + callsByDeviceType, + handle, + longDurationCallsPercentage, + potentialRobocallsPercentage, + shortDurationCallsPercentage, + silentCallsPercentage, + totalCalls + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/OutboundReader.java b/src/main/java/com/twilio/rest/insights/v2/OutboundReader.java new file mode 100644 index 0000000000..2bf266aa00 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/OutboundReader.java @@ -0,0 +1,208 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OutboundReader extends Reader { + + private String pathReportId; + private Long pageSize; + + public OutboundReader(final String pathReportId) { + this.pathReportId = pathReportId; + } + + public OutboundReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "reports", + response.getContent(), + Outbound.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Reports/PhoneNumbers/Outbound/{reportId}"; + + path = + path.replace("{" + "reportId" + "}", this.pathReportId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "reports", + response.getContent(), + Outbound.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Outbound read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "reports", + response.getContent(), + Outbound.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/OutboundReport.java b/src/main/java/com/twilio/rest/insights/v2/OutboundReport.java new file mode 100644 index 0000000000..90afb48746 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/OutboundReport.java @@ -0,0 +1,698 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class OutboundReport extends Resource { + + public static OutboundReportCreator creator() { + return new OutboundReportCreator(); + } + + public enum ReportStatus { + CREATED("created"), + RUNNING("running"), + COMPLETED("completed"); + + private final String value; + + private ReportStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ReportStatus forValue(final String value) { + return Promoter.enumFromString(value, ReportStatus.values()); + } + } + + @JsonDeserialize(builder = PhoneNumberReportFilter.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PhoneNumberReportFilter { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + @Getter + private final List values; + + private PhoneNumberReportFilter(Builder builder) { + this.key = builder.key; + this.values = builder.values; + } + + public static Builder builder() { + return new Builder(); + } + + public static PhoneNumberReportFilter fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, PhoneNumberReportFilter.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("values") + private List values; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + public Builder values(List values) { + this.values = values; + return this; + } + + public PhoneNumberReportFilter build() { + return new PhoneNumberReportFilter(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PhoneNumberReportFilter other = (PhoneNumberReportFilter) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, values); + } + } + + @JsonDeserialize( + builder = InsightsV2CreatePhoneNumbersReportRequestTimeRange.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2CreatePhoneNumbersReportRequestTimeRange { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + @Getter + private final ZonedDateTime startDatetime; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + @Getter + private final ZonedDateTime endDatetime; + + private InsightsV2CreatePhoneNumbersReportRequestTimeRange( + Builder builder + ) { + this.startDatetime = builder.startDatetime; + this.endDatetime = builder.endDatetime; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2CreatePhoneNumbersReportRequestTimeRange fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2CreatePhoneNumbersReportRequestTimeRange.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("start_datetime") + private ZonedDateTime startDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("end_datetime") + private ZonedDateTime endDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + public Builder startDatetime(ZonedDateTime startDatetime) { + this.startDatetime = startDatetime; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + public Builder endDatetime(ZonedDateTime endDatetime) { + this.endDatetime = endDatetime; + return this; + } + + public InsightsV2CreatePhoneNumbersReportRequestTimeRange build() { + return new InsightsV2CreatePhoneNumbersReportRequestTimeRange( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2CreatePhoneNumbersReportRequestTimeRange other = + (InsightsV2CreatePhoneNumbersReportRequestTimeRange) o; + return ( + Objects.equals(startDatetime, other.startDatetime) && + Objects.equals(endDatetime, other.endDatetime) + ); + } + + @Override + public int hashCode() { + return Objects.hash(startDatetime, endDatetime); + } + } + + @JsonDeserialize(builder = ReportFilter.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReportFilter { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + @Getter + private final List values; + + private ReportFilter(Builder builder) { + this.key = builder.key; + this.values = builder.values; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReportFilter fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ReportFilter.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("values") + private List values; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + public Builder values(List values) { + this.values = values; + return this; + } + + public ReportFilter build() { + return new ReportFilter(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReportFilter other = (ReportFilter) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, values); + } + } + + @JsonDeserialize( + builder = InsightsV2CreatePhoneNumbersReportRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2CreatePhoneNumbersReportRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_range") + @Getter + private final InsightsV2CreatePhoneNumbersReportRequestTimeRange timeRange; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + @Getter + private final List filters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("size") + @Getter + private final Integer size; + + private InsightsV2CreatePhoneNumbersReportRequest(Builder builder) { + this.timeRange = builder.timeRange; + this.filters = builder.filters; + this.size = builder.size; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2CreatePhoneNumbersReportRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2CreatePhoneNumbersReportRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("time_range") + private InsightsV2CreatePhoneNumbersReportRequestTimeRange timeRange; + + @JsonProperty("filters") + private List filters; + + @JsonProperty("size") + private Integer size; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_range") + public Builder timeRange( + InsightsV2CreatePhoneNumbersReportRequestTimeRange timeRange + ) { + this.timeRange = timeRange; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + public Builder filters(List filters) { + this.filters = filters; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("size") + public Builder size(Integer size) { + this.size = size; + return this; + } + + public InsightsV2CreatePhoneNumbersReportRequest build() { + return new InsightsV2CreatePhoneNumbersReportRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2CreatePhoneNumbersReportRequest other = + (InsightsV2CreatePhoneNumbersReportRequest) o; + return ( + Objects.equals(timeRange, other.timeRange) && + Objects.equals(filters, other.filters) && + Objects.equals(size, other.size) + ); + } + + @Override + public int hashCode() { + return Objects.hash(timeRange, filters, size); + } + } + + @JsonDeserialize(builder = ReportMetadata.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReportMetadata { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + @Getter + private final ZonedDateTime startDatetime; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + @Getter + private final ZonedDateTime endDatetime; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + @Getter + private final List filters; + + private ReportMetadata(Builder builder) { + this.startDatetime = builder.startDatetime; + this.endDatetime = builder.endDatetime; + this.filters = builder.filters; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReportMetadata fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ReportMetadata.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("start_datetime") + private ZonedDateTime startDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("end_datetime") + private ZonedDateTime endDatetime; + + @JsonProperty("filters") + private List filters; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + public Builder startDatetime(ZonedDateTime startDatetime) { + this.startDatetime = startDatetime; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + public Builder endDatetime(ZonedDateTime endDatetime) { + this.endDatetime = endDatetime; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + public Builder filters(List filters) { + this.filters = filters; + return this; + } + + public ReportMetadata build() { + return new ReportMetadata(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReportMetadata other = (ReportMetadata) o; + return ( + Objects.equals(startDatetime, other.startDatetime) && + Objects.equals(endDatetime, other.endDatetime) && + Objects.equals(filters, other.filters) + ); + } + + @Override + public int hashCode() { + return Objects.hash(startDatetime, endDatetime, filters); + } + } + + /** + * Converts a JSON String into a OutboundReport object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OutboundReport object represented by the provided JSON + */ + public static OutboundReport fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OutboundReport.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a OutboundReport object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OutboundReport object represented by the provided JSON + */ + public static OutboundReport fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OutboundReport.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String reportId; + + @Getter + private final ReportMetadata requestMeta; + + @Getter + private final OutboundReport.ReportStatus status; + + @Getter + private final URI url; + + @JsonCreator + private OutboundReport( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("report_id") final String reportId, + @JsonProperty("request_meta") final ReportMetadata requestMeta, + @JsonProperty("status") final OutboundReport.ReportStatus status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.reportId = reportId; + this.requestMeta = requestMeta; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OutboundReport other = (OutboundReport) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(reportId, other.reportId) && + Objects.equals(requestMeta, other.requestMeta) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, reportId, requestMeta, status, url); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/OutboundReportCreator.java b/src/main/java/com/twilio/rest/insights/v2/OutboundReportCreator.java new file mode 100644 index 0000000000..92ffd2096d --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/OutboundReportCreator.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OutboundReportCreator extends Creator { + + private OutboundReport.InsightsV2CreatePhoneNumbersReportRequest insightsV2CreatePhoneNumbersReportRequest; + + public OutboundReportCreator() {} + + public OutboundReportCreator setInsightsV2CreatePhoneNumbersReportRequest( + final OutboundReport.InsightsV2CreatePhoneNumbersReportRequest insightsV2CreatePhoneNumbersReportRequest + ) { + this.insightsV2CreatePhoneNumbersReportRequest = + insightsV2CreatePhoneNumbersReportRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Reports/PhoneNumbers/Outbound"; + + Request request = new Request( + HttpMethod.POST, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OutboundReport creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public OutboundReport create(final TwilioRestClient client) { + Response response = makeRequest(client); + return OutboundReport.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OutboundReport content = OutboundReport.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (insightsV2CreatePhoneNumbersReportRequest != null) { + request.setBody( + OutboundReport.toJson( + insightsV2CreatePhoneNumbersReportRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/Report.java b/src/main/java/com/twilio/rest/insights/v2/Report.java new file mode 100644 index 0000000000..d31e78ebb1 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/Report.java @@ -0,0 +1,3300 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Report extends Resource { + + public static ReportCreator creator() { + return new ReportCreator(); + } + + public static ReportFetcher fetcher(final String pathReportId) { + return new ReportFetcher(pathReportId); + } + + public enum ReportStatus { + CREATED("created"), + RUNNING("running"), + COMPLETED("completed"); + + private final String value; + + private ReportStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ReportStatus forValue(final String value) { + return Promoter.enumFromString(value, ReportStatus.values()); + } + } + + @JsonDeserialize(builder = CountyCarrierValue.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CountyCarrierValue { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country") + @Getter + private final String country; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carriers") + @Getter + private final List carriers; + + private CountyCarrierValue(Builder builder) { + this.country = builder.country; + this.carriers = builder.carriers; + } + + public static Builder builder() { + return new Builder(); + } + + public static CountyCarrierValue fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CountyCarrierValue.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("country") + private String country; + + @JsonProperty("carriers") + private List carriers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country") + public Builder country(String country) { + this.country = country; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carriers") + public Builder carriers(List carriers) { + this.carriers = carriers; + return this; + } + + public CountyCarrierValue build() { + return new CountyCarrierValue(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CountyCarrierValue other = (CountyCarrierValue) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(carriers, other.carriers) + ); + } + + @Override + public int hashCode() { + return Objects.hash(country, carriers); + } + } + + @JsonDeserialize(builder = CountyCarrierValueCarriers.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CountyCarrierValueCarriers { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier") + @Getter + private final String carrier; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + @Getter + private final Integer totalCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls") + @Getter + private final Integer blockedCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls_percentage") + @Getter + private final Float blockedCallsPercentage; + + private CountyCarrierValueCarriers(Builder builder) { + this.carrier = builder.carrier; + this.totalCalls = builder.totalCalls; + this.blockedCalls = builder.blockedCalls; + this.blockedCallsPercentage = builder.blockedCallsPercentage; + } + + public static Builder builder() { + return new Builder(); + } + + public static CountyCarrierValueCarriers fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CountyCarrierValueCarriers.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("carrier") + private String carrier; + + @JsonProperty("total_calls") + private Integer totalCalls; + + @JsonProperty("blocked_calls") + private Integer blockedCalls; + + @JsonProperty("blocked_calls_percentage") + private Float blockedCallsPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier") + public Builder carrier(String carrier) { + this.carrier = carrier; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + public Builder totalCalls(Integer totalCalls) { + this.totalCalls = totalCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls") + public Builder blockedCalls(Integer blockedCalls) { + this.blockedCalls = blockedCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls_percentage") + public Builder blockedCallsPercentage( + Float blockedCallsPercentage + ) { + this.blockedCallsPercentage = blockedCallsPercentage; + return this; + } + + public CountyCarrierValueCarriers build() { + return new CountyCarrierValueCarriers(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CountyCarrierValueCarriers other = (CountyCarrierValueCarriers) o; + return ( + Objects.equals(carrier, other.carrier) && + Objects.equals(totalCalls, other.totalCalls) && + Objects.equals(blockedCalls, other.blockedCalls) && + Objects.equals( + blockedCallsPercentage, + other.blockedCallsPercentage + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + carrier, + totalCalls, + blockedCalls, + blockedCallsPercentage + ); + } + } + + @JsonDeserialize( + builder = AccountReportAnsweringMachineDetection.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportAnsweringMachineDetection { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + @Getter + private final Integer totalCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answered_by_human_percentage") + @Getter + private final Float answeredByHumanPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answered_by_machine_percentage") + @Getter + private final Float answeredByMachinePercentage; + + private AccountReportAnsweringMachineDetection(Builder builder) { + this.totalCalls = builder.totalCalls; + this.answeredByHumanPercentage = builder.answeredByHumanPercentage; + this.answeredByMachinePercentage = + builder.answeredByMachinePercentage; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportAnsweringMachineDetection fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountReportAnsweringMachineDetection.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total_calls") + private Integer totalCalls; + + @JsonProperty("answered_by_human_percentage") + private Float answeredByHumanPercentage; + + @JsonProperty("answered_by_machine_percentage") + private Float answeredByMachinePercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + public Builder totalCalls(Integer totalCalls) { + this.totalCalls = totalCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answered_by_human_percentage") + public Builder answeredByHumanPercentage( + Float answeredByHumanPercentage + ) { + this.answeredByHumanPercentage = answeredByHumanPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answered_by_machine_percentage") + public Builder answeredByMachinePercentage( + Float answeredByMachinePercentage + ) { + this.answeredByMachinePercentage = answeredByMachinePercentage; + return this; + } + + public AccountReportAnsweringMachineDetection build() { + return new AccountReportAnsweringMachineDetection(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportAnsweringMachineDetection other = + (AccountReportAnsweringMachineDetection) o; + return ( + Objects.equals(totalCalls, other.totalCalls) && + Objects.equals( + answeredByHumanPercentage, + other.answeredByHumanPercentage + ) && + Objects.equals( + answeredByMachinePercentage, + other.answeredByMachinePercentage + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + totalCalls, + answeredByHumanPercentage, + answeredByMachinePercentage + ); + } + } + + @JsonDeserialize(builder = AccountReportCallType.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportCallType { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier") + @Getter + private final Integer carrier; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sip") + @Getter + private final Integer sip; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("trunking") + @Getter + private final Integer trunking; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("client") + @Getter + private final Integer client; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("whatsapp") + @Getter + private final Integer whatsapp; + + private AccountReportCallType(Builder builder) { + this.carrier = builder.carrier; + this.sip = builder.sip; + this.trunking = builder.trunking; + this.client = builder.client; + this.whatsapp = builder.whatsapp; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportCallType fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, AccountReportCallType.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("carrier") + private Integer carrier; + + @JsonProperty("sip") + private Integer sip; + + @JsonProperty("trunking") + private Integer trunking; + + @JsonProperty("client") + private Integer client; + + @JsonProperty("whatsapp") + private Integer whatsapp; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier") + public Builder carrier(Integer carrier) { + this.carrier = carrier; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sip") + public Builder sip(Integer sip) { + this.sip = sip; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("trunking") + public Builder trunking(Integer trunking) { + this.trunking = trunking; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("client") + public Builder client(Integer client) { + this.client = client; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("whatsapp") + public Builder whatsapp(Integer whatsapp) { + this.whatsapp = whatsapp; + return this; + } + + public AccountReportCallType build() { + return new AccountReportCallType(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportCallType other = (AccountReportCallType) o; + return ( + Objects.equals(carrier, other.carrier) && + Objects.equals(sip, other.sip) && + Objects.equals(trunking, other.trunking) && + Objects.equals(client, other.client) && + Objects.equals(whatsapp, other.whatsapp) + ); + } + + @Override + public int hashCode() { + return Objects.hash(carrier, sip, trunking, client, whatsapp); + } + } + + @JsonDeserialize(builder = VoiceIntegrityCallsPerBundle.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class VoiceIntegrityCallsPerBundle { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bundle_sid") + @Getter + private final String bundleSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled_phonenumbers") + @Getter + private final Integer enabledPhonenumbers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + @Getter + private final Integer totalCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answer_rate") + @Getter + private final Float answerRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("human_answer_rate") + @Getter + private final Float humanAnswerRate; + + private VoiceIntegrityCallsPerBundle(Builder builder) { + this.bundleSid = builder.bundleSid; + this.enabledPhonenumbers = builder.enabledPhonenumbers; + this.totalCalls = builder.totalCalls; + this.answerRate = builder.answerRate; + this.humanAnswerRate = builder.humanAnswerRate; + } + + public static Builder builder() { + return new Builder(); + } + + public static VoiceIntegrityCallsPerBundle fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + VoiceIntegrityCallsPerBundle.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("bundle_sid") + private String bundleSid; + + @JsonProperty("enabled_phonenumbers") + private Integer enabledPhonenumbers; + + @JsonProperty("total_calls") + private Integer totalCalls; + + @JsonProperty("answer_rate") + private Float answerRate; + + @JsonProperty("human_answer_rate") + private Float humanAnswerRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bundle_sid") + public Builder bundleSid(String bundleSid) { + this.bundleSid = bundleSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled_phonenumbers") + public Builder enabledPhonenumbers(Integer enabledPhonenumbers) { + this.enabledPhonenumbers = enabledPhonenumbers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + public Builder totalCalls(Integer totalCalls) { + this.totalCalls = totalCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answer_rate") + public Builder answerRate(Float answerRate) { + this.answerRate = answerRate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("human_answer_rate") + public Builder humanAnswerRate(Float humanAnswerRate) { + this.humanAnswerRate = humanAnswerRate; + return this; + } + + public VoiceIntegrityCallsPerBundle build() { + return new VoiceIntegrityCallsPerBundle(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + VoiceIntegrityCallsPerBundle other = + (VoiceIntegrityCallsPerBundle) o; + return ( + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals( + enabledPhonenumbers, + other.enabledPhonenumbers + ) && + Objects.equals(totalCalls, other.totalCalls) && + Objects.equals(answerRate, other.answerRate) && + Objects.equals(humanAnswerRate, other.humanAnswerRate) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + bundleSid, + enabledPhonenumbers, + totalCalls, + answerRate, + humanAnswerRate + ); + } + } + + @JsonDeserialize(builder = AccountReportCallDirection.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportCallDirection { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outbound") + @Getter + private final Integer outbound; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inbound") + @Getter + private final Integer inbound; + + private AccountReportCallDirection(Builder builder) { + this.outbound = builder.outbound; + this.inbound = builder.inbound; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportCallDirection fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountReportCallDirection.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("outbound") + private Integer outbound; + + @JsonProperty("inbound") + private Integer inbound; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outbound") + public Builder outbound(Integer outbound) { + this.outbound = outbound; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inbound") + public Builder inbound(Integer inbound) { + this.inbound = inbound; + return this; + } + + public AccountReportCallDirection build() { + return new AccountReportCallDirection(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportCallDirection other = (AccountReportCallDirection) o; + return ( + Objects.equals(outbound, other.outbound) && + Objects.equals(inbound, other.inbound) + ); + } + + @Override + public int hashCode() { + return Objects.hash(outbound, inbound); + } + } + + @JsonDeserialize(builder = StirShaken.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class StirShaken { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_count") + @Getter + private final StirShakenCallCount callCount; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("percentage") + @Getter + private final StirShakenPercentage percentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answer_rate") + @Getter + private final StirShakenAnswerRate answerRate; + + private StirShaken(Builder builder) { + this.callCount = builder.callCount; + this.percentage = builder.percentage; + this.answerRate = builder.answerRate; + } + + public static Builder builder() { + return new Builder(); + } + + public static StirShaken fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, StirShaken.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("call_count") + private StirShakenCallCount callCount; + + @JsonProperty("percentage") + private StirShakenPercentage percentage; + + @JsonProperty("answer_rate") + private StirShakenAnswerRate answerRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_count") + public Builder callCount(StirShakenCallCount callCount) { + this.callCount = callCount; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("percentage") + public Builder percentage(StirShakenPercentage percentage) { + this.percentage = percentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answer_rate") + public Builder answerRate(StirShakenAnswerRate answerRate) { + this.answerRate = answerRate; + return this; + } + + public StirShaken build() { + return new StirShaken(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + StirShaken other = (StirShaken) o; + return ( + Objects.equals(callCount, other.callCount) && + Objects.equals(percentage, other.percentage) && + Objects.equals(answerRate, other.answerRate) + ); + } + + @Override + public int hashCode() { + return Objects.hash(callCount, percentage, answerRate); + } + } + + @JsonDeserialize(builder = StirShakenCallCount.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class StirShakenCallCount { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_a") + @Getter + private final Integer stshA; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_b") + @Getter + private final Integer stshB; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_c") + @Getter + private final Integer stshC; + + private StirShakenCallCount(Builder builder) { + this.stshA = builder.stshA; + this.stshB = builder.stshB; + this.stshC = builder.stshC; + } + + public static Builder builder() { + return new Builder(); + } + + public static StirShakenCallCount fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, StirShakenCallCount.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("stsh_a") + private Integer stshA; + + @JsonProperty("stsh_b") + private Integer stshB; + + @JsonProperty("stsh_c") + private Integer stshC; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_a") + public Builder stshA(Integer stshA) { + this.stshA = stshA; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_b") + public Builder stshB(Integer stshB) { + this.stshB = stshB; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_c") + public Builder stshC(Integer stshC) { + this.stshC = stshC; + return this; + } + + public StirShakenCallCount build() { + return new StirShakenCallCount(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + StirShakenCallCount other = (StirShakenCallCount) o; + return ( + Objects.equals(stshA, other.stshA) && + Objects.equals(stshB, other.stshB) && + Objects.equals(stshC, other.stshC) + ); + } + + @Override + public int hashCode() { + return Objects.hash(stshA, stshB, stshC); + } + } + + @JsonDeserialize( + builder = InsightsV2CreateAccountReportRequestTimeRange.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2CreateAccountReportRequestTimeRange { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + @Getter + private final ZonedDateTime startDatetime; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + @Getter + private final ZonedDateTime endDatetime; + + private InsightsV2CreateAccountReportRequestTimeRange(Builder builder) { + this.startDatetime = builder.startDatetime; + this.endDatetime = builder.endDatetime; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2CreateAccountReportRequestTimeRange fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2CreateAccountReportRequestTimeRange.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("start_datetime") + private ZonedDateTime startDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("end_datetime") + private ZonedDateTime endDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + public Builder startDatetime(ZonedDateTime startDatetime) { + this.startDatetime = startDatetime; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + public Builder endDatetime(ZonedDateTime endDatetime) { + this.endDatetime = endDatetime; + return this; + } + + public InsightsV2CreateAccountReportRequestTimeRange build() { + return new InsightsV2CreateAccountReportRequestTimeRange(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2CreateAccountReportRequestTimeRange other = + (InsightsV2CreateAccountReportRequestTimeRange) o; + return ( + Objects.equals(startDatetime, other.startDatetime) && + Objects.equals(endDatetime, other.endDatetime) + ); + } + + @Override + public int hashCode() { + return Objects.hash(startDatetime, endDatetime); + } + } + + @JsonDeserialize(builder = ReportFilter.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReportFilter { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + @Getter + private final List values; + + private ReportFilter(Builder builder) { + this.key = builder.key; + this.values = builder.values; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReportFilter fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ReportFilter.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("values") + private List values; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + public Builder values(List values) { + this.values = values; + return this; + } + + public ReportFilter build() { + return new ReportFilter(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReportFilter other = (ReportFilter) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, values); + } + } + + @JsonDeserialize(builder = BrandedUseCaseDetail.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class BrandedUseCaseDetail { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("use_case") + @Getter + private final String useCase; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled_phonenumbers") + @Getter + private final Integer enabledPhonenumbers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + @Getter + private final Integer totalCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answer_rate") + @Getter + private final Float answerRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("human_answer_rate") + @Getter + private final Float humanAnswerRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("engagement_rate") + @Getter + private final Float engagementRate; + + private BrandedUseCaseDetail(Builder builder) { + this.useCase = builder.useCase; + this.enabledPhonenumbers = builder.enabledPhonenumbers; + this.totalCalls = builder.totalCalls; + this.answerRate = builder.answerRate; + this.humanAnswerRate = builder.humanAnswerRate; + this.engagementRate = builder.engagementRate; + } + + public static Builder builder() { + return new Builder(); + } + + public static BrandedUseCaseDetail fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, BrandedUseCaseDetail.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("use_case") + private String useCase; + + @JsonProperty("enabled_phonenumbers") + private Integer enabledPhonenumbers; + + @JsonProperty("total_calls") + private Integer totalCalls; + + @JsonProperty("answer_rate") + private Float answerRate; + + @JsonProperty("human_answer_rate") + private Float humanAnswerRate; + + @JsonProperty("engagement_rate") + private Float engagementRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("use_case") + public Builder useCase(String useCase) { + this.useCase = useCase; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled_phonenumbers") + public Builder enabledPhonenumbers(Integer enabledPhonenumbers) { + this.enabledPhonenumbers = enabledPhonenumbers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + public Builder totalCalls(Integer totalCalls) { + this.totalCalls = totalCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answer_rate") + public Builder answerRate(Float answerRate) { + this.answerRate = answerRate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("human_answer_rate") + public Builder humanAnswerRate(Float humanAnswerRate) { + this.humanAnswerRate = humanAnswerRate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("engagement_rate") + public Builder engagementRate(Float engagementRate) { + this.engagementRate = engagementRate; + return this; + } + + public BrandedUseCaseDetail build() { + return new BrandedUseCaseDetail(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BrandedUseCaseDetail other = (BrandedUseCaseDetail) o; + return ( + Objects.equals(useCase, other.useCase) && + Objects.equals( + enabledPhonenumbers, + other.enabledPhonenumbers + ) && + Objects.equals(totalCalls, other.totalCalls) && + Objects.equals(answerRate, other.answerRate) && + Objects.equals(humanAnswerRate, other.humanAnswerRate) && + Objects.equals(engagementRate, other.engagementRate) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + useCase, + enabledPhonenumbers, + totalCalls, + answerRate, + humanAnswerRate, + engagementRate + ); + } + } + + @JsonDeserialize(builder = AccountReportNetworkIssuesSdk.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportNetworkIssuesSdk { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ice_failures_percentage") + @Getter + private final Float iceFailuresPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_latency_percentage") + @Getter + private final Float highLatencyPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_packet_loss_percentage") + @Getter + private final Float highPacketLossPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_jitter_percentage") + @Getter + private final Float highJitterPercentage; + + private AccountReportNetworkIssuesSdk(Builder builder) { + this.iceFailuresPercentage = builder.iceFailuresPercentage; + this.highLatencyPercentage = builder.highLatencyPercentage; + this.highPacketLossPercentage = builder.highPacketLossPercentage; + this.highJitterPercentage = builder.highJitterPercentage; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportNetworkIssuesSdk fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountReportNetworkIssuesSdk.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("ice_failures_percentage") + private Float iceFailuresPercentage; + + @JsonProperty("high_latency_percentage") + private Float highLatencyPercentage; + + @JsonProperty("high_packet_loss_percentage") + private Float highPacketLossPercentage; + + @JsonProperty("high_jitter_percentage") + private Float highJitterPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ice_failures_percentage") + public Builder iceFailuresPercentage(Float iceFailuresPercentage) { + this.iceFailuresPercentage = iceFailuresPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_latency_percentage") + public Builder highLatencyPercentage(Float highLatencyPercentage) { + this.highLatencyPercentage = highLatencyPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_packet_loss_percentage") + public Builder highPacketLossPercentage( + Float highPacketLossPercentage + ) { + this.highPacketLossPercentage = highPacketLossPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_jitter_percentage") + public Builder highJitterPercentage(Float highJitterPercentage) { + this.highJitterPercentage = highJitterPercentage; + return this; + } + + public AccountReportNetworkIssuesSdk build() { + return new AccountReportNetworkIssuesSdk(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportNetworkIssuesSdk other = + (AccountReportNetworkIssuesSdk) o; + return ( + Objects.equals( + iceFailuresPercentage, + other.iceFailuresPercentage + ) && + Objects.equals( + highLatencyPercentage, + other.highLatencyPercentage + ) && + Objects.equals( + highPacketLossPercentage, + other.highPacketLossPercentage + ) && + Objects.equals(highJitterPercentage, other.highJitterPercentage) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + iceFailuresPercentage, + highLatencyPercentage, + highPacketLossPercentage, + highJitterPercentage + ); + } + } + + @JsonDeserialize( + builder = AccountReportNetworkIssuesTwilioGateway.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportNetworkIssuesTwilioGateway { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_latency_percentage") + @Getter + private final Float highLatencyPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_packet_loss_percentage") + @Getter + private final Float highPacketLossPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_jitter_percentage") + @Getter + private final Float highJitterPercentage; + + private AccountReportNetworkIssuesTwilioGateway(Builder builder) { + this.highLatencyPercentage = builder.highLatencyPercentage; + this.highPacketLossPercentage = builder.highPacketLossPercentage; + this.highJitterPercentage = builder.highJitterPercentage; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportNetworkIssuesTwilioGateway fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountReportNetworkIssuesTwilioGateway.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("high_latency_percentage") + private Float highLatencyPercentage; + + @JsonProperty("high_packet_loss_percentage") + private Float highPacketLossPercentage; + + @JsonProperty("high_jitter_percentage") + private Float highJitterPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_latency_percentage") + public Builder highLatencyPercentage(Float highLatencyPercentage) { + this.highLatencyPercentage = highLatencyPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_packet_loss_percentage") + public Builder highPacketLossPercentage( + Float highPacketLossPercentage + ) { + this.highPacketLossPercentage = highPacketLossPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("high_jitter_percentage") + public Builder highJitterPercentage(Float highJitterPercentage) { + this.highJitterPercentage = highJitterPercentage; + return this; + } + + public AccountReportNetworkIssuesTwilioGateway build() { + return new AccountReportNetworkIssuesTwilioGateway(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportNetworkIssuesTwilioGateway other = + (AccountReportNetworkIssuesTwilioGateway) o; + return ( + Objects.equals( + highLatencyPercentage, + other.highLatencyPercentage + ) && + Objects.equals( + highPacketLossPercentage, + other.highPacketLossPercentage + ) && + Objects.equals(highJitterPercentage, other.highJitterPercentage) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + highLatencyPercentage, + highPacketLossPercentage, + highJitterPercentage + ); + } + } + + @JsonDeserialize( + builder = AccountReportKYTOutboundCarrierCalling.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportKYTOutboundCarrierCalling { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("unique_calling_numbers") + @Getter + private final Integer uniqueCallingNumbers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("unique_called_numbers") + @Getter + private final Integer uniqueCalledNumbers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls_by_carrier") + @Getter + private final List blockedCallsByCarrier; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("short_duration_calls_percentage") + @Getter + private final Float shortDurationCallsPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("long_duration_calls_percentage") + @Getter + private final Float longDurationCallsPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("potential_robocalls_percentage") + @Getter + private final Float potentialRobocallsPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("branded_calling") + @Getter + private final BrandedCalling brandedCalling; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("voice_integrity") + @Getter + private final VoiceIntegrity voiceIntegrity; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stir_shaken") + @Getter + private final StirShaken stirShaken; + + private AccountReportKYTOutboundCarrierCalling(Builder builder) { + this.uniqueCallingNumbers = builder.uniqueCallingNumbers; + this.uniqueCalledNumbers = builder.uniqueCalledNumbers; + this.blockedCallsByCarrier = builder.blockedCallsByCarrier; + this.shortDurationCallsPercentage = + builder.shortDurationCallsPercentage; + this.longDurationCallsPercentage = + builder.longDurationCallsPercentage; + this.potentialRobocallsPercentage = + builder.potentialRobocallsPercentage; + this.brandedCalling = builder.brandedCalling; + this.voiceIntegrity = builder.voiceIntegrity; + this.stirShaken = builder.stirShaken; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportKYTOutboundCarrierCalling fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountReportKYTOutboundCarrierCalling.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("unique_calling_numbers") + private Integer uniqueCallingNumbers; + + @JsonProperty("unique_called_numbers") + private Integer uniqueCalledNumbers; + + @JsonProperty("blocked_calls_by_carrier") + private List blockedCallsByCarrier; + + @JsonProperty("short_duration_calls_percentage") + private Float shortDurationCallsPercentage; + + @JsonProperty("long_duration_calls_percentage") + private Float longDurationCallsPercentage; + + @JsonProperty("potential_robocalls_percentage") + private Float potentialRobocallsPercentage; + + @JsonProperty("branded_calling") + private BrandedCalling brandedCalling; + + @JsonProperty("voice_integrity") + private VoiceIntegrity voiceIntegrity; + + @JsonProperty("stir_shaken") + private StirShaken stirShaken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("unique_calling_numbers") + public Builder uniqueCallingNumbers(Integer uniqueCallingNumbers) { + this.uniqueCallingNumbers = uniqueCallingNumbers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("unique_called_numbers") + public Builder uniqueCalledNumbers(Integer uniqueCalledNumbers) { + this.uniqueCalledNumbers = uniqueCalledNumbers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("blocked_calls_by_carrier") + public Builder blockedCallsByCarrier( + List blockedCallsByCarrier + ) { + this.blockedCallsByCarrier = blockedCallsByCarrier; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("short_duration_calls_percentage") + public Builder shortDurationCallsPercentage( + Float shortDurationCallsPercentage + ) { + this.shortDurationCallsPercentage = + shortDurationCallsPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("long_duration_calls_percentage") + public Builder longDurationCallsPercentage( + Float longDurationCallsPercentage + ) { + this.longDurationCallsPercentage = longDurationCallsPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("potential_robocalls_percentage") + public Builder potentialRobocallsPercentage( + Float potentialRobocallsPercentage + ) { + this.potentialRobocallsPercentage = + potentialRobocallsPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("branded_calling") + public Builder brandedCalling(BrandedCalling brandedCalling) { + this.brandedCalling = brandedCalling; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("voice_integrity") + public Builder voiceIntegrity(VoiceIntegrity voiceIntegrity) { + this.voiceIntegrity = voiceIntegrity; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stir_shaken") + public Builder stirShaken(StirShaken stirShaken) { + this.stirShaken = stirShaken; + return this; + } + + public AccountReportKYTOutboundCarrierCalling build() { + return new AccountReportKYTOutboundCarrierCalling(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportKYTOutboundCarrierCalling other = + (AccountReportKYTOutboundCarrierCalling) o; + return ( + Objects.equals( + uniqueCallingNumbers, + other.uniqueCallingNumbers + ) && + Objects.equals( + uniqueCalledNumbers, + other.uniqueCalledNumbers + ) && + Objects.equals( + blockedCallsByCarrier, + other.blockedCallsByCarrier + ) && + Objects.equals( + shortDurationCallsPercentage, + other.shortDurationCallsPercentage + ) && + Objects.equals( + longDurationCallsPercentage, + other.longDurationCallsPercentage + ) && + Objects.equals( + potentialRobocallsPercentage, + other.potentialRobocallsPercentage + ) && + Objects.equals(brandedCalling, other.brandedCalling) && + Objects.equals(voiceIntegrity, other.voiceIntegrity) && + Objects.equals(stirShaken, other.stirShaken) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + uniqueCallingNumbers, + uniqueCalledNumbers, + blockedCallsByCarrier, + shortDurationCallsPercentage, + longDurationCallsPercentage, + potentialRobocallsPercentage, + brandedCalling, + voiceIntegrity, + stirShaken + ); + } + } + + @JsonDeserialize(builder = AccountReport.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReport { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_deliverability_score") + @Getter + private final Float callDeliverabilityScore; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_answer_score") + @Getter + private final Float callAnswerScore; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + @Getter + private final Integer totalCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_direction") + @Getter + private final AccountReportCallDirection callDirection; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_state") + @Getter + private final AccountReportCallState callState; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_type") + @Getter + private final AccountReportCallType callType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("aloc") + @Getter + private final Float aloc; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio_edge_location") + @Getter + private final Map twilioEdgeLocation; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_country_code") + @Getter + private final Map callerCountryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("callee_country_code") + @Getter + private final Map calleeCountryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("average_queue_time_ms") + @Getter + private final Float averageQueueTimeMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("silent_calls_percentage") + @Getter + private final Float silentCallsPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("network_issues") + @Getter + private final AccountReportNetworkIssues networkIssues; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("KYT") + @Getter + private final AccountReportKYT KYT; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answering_machine_detection") + @Getter + private final AccountReportAnsweringMachineDetection answeringMachineDetection; + + private AccountReport(Builder builder) { + this.callDeliverabilityScore = builder.callDeliverabilityScore; + this.callAnswerScore = builder.callAnswerScore; + this.totalCalls = builder.totalCalls; + this.callDirection = builder.callDirection; + this.callState = builder.callState; + this.callType = builder.callType; + this.aloc = builder.aloc; + this.twilioEdgeLocation = builder.twilioEdgeLocation; + this.callerCountryCode = builder.callerCountryCode; + this.calleeCountryCode = builder.calleeCountryCode; + this.averageQueueTimeMs = builder.averageQueueTimeMs; + this.silentCallsPercentage = builder.silentCallsPercentage; + this.networkIssues = builder.networkIssues; + this.KYT = builder.KYT; + this.answeringMachineDetection = builder.answeringMachineDetection; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReport fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, AccountReport.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("call_deliverability_score") + private Float callDeliverabilityScore; + + @JsonProperty("call_answer_score") + private Float callAnswerScore; + + @JsonProperty("total_calls") + private Integer totalCalls; + + @JsonProperty("call_direction") + private AccountReportCallDirection callDirection; + + @JsonProperty("call_state") + private AccountReportCallState callState; + + @JsonProperty("call_type") + private AccountReportCallType callType; + + @JsonProperty("aloc") + private Float aloc; + + @JsonProperty("twilio_edge_location") + private Map twilioEdgeLocation; + + @JsonProperty("caller_country_code") + private Map callerCountryCode; + + @JsonProperty("callee_country_code") + private Map calleeCountryCode; + + @JsonProperty("average_queue_time_ms") + private Float averageQueueTimeMs; + + @JsonProperty("silent_calls_percentage") + private Float silentCallsPercentage; + + @JsonProperty("network_issues") + private AccountReportNetworkIssues networkIssues; + + @JsonProperty("KYT") + private AccountReportKYT KYT; + + @JsonProperty("answering_machine_detection") + private AccountReportAnsweringMachineDetection answeringMachineDetection; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_deliverability_score") + public Builder callDeliverabilityScore( + Float callDeliverabilityScore + ) { + this.callDeliverabilityScore = callDeliverabilityScore; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_answer_score") + public Builder callAnswerScore(Float callAnswerScore) { + this.callAnswerScore = callAnswerScore; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_calls") + public Builder totalCalls(Integer totalCalls) { + this.totalCalls = totalCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_direction") + public Builder callDirection( + AccountReportCallDirection callDirection + ) { + this.callDirection = callDirection; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_state") + public Builder callState(AccountReportCallState callState) { + this.callState = callState; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_type") + public Builder callType(AccountReportCallType callType) { + this.callType = callType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("aloc") + public Builder aloc(Float aloc) { + this.aloc = aloc; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio_edge_location") + public Builder twilioEdgeLocation( + Map twilioEdgeLocation + ) { + this.twilioEdgeLocation = twilioEdgeLocation; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_country_code") + public Builder callerCountryCode( + Map callerCountryCode + ) { + this.callerCountryCode = callerCountryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("callee_country_code") + public Builder calleeCountryCode( + Map calleeCountryCode + ) { + this.calleeCountryCode = calleeCountryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("average_queue_time_ms") + public Builder averageQueueTimeMs(Float averageQueueTimeMs) { + this.averageQueueTimeMs = averageQueueTimeMs; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("silent_calls_percentage") + public Builder silentCallsPercentage(Float silentCallsPercentage) { + this.silentCallsPercentage = silentCallsPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("network_issues") + public Builder networkIssues( + AccountReportNetworkIssues networkIssues + ) { + this.networkIssues = networkIssues; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("KYT") + public Builder KYT(AccountReportKYT KYT) { + this.KYT = KYT; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answering_machine_detection") + public Builder answeringMachineDetection( + AccountReportAnsweringMachineDetection answeringMachineDetection + ) { + this.answeringMachineDetection = answeringMachineDetection; + return this; + } + + public AccountReport build() { + return new AccountReport(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReport other = (AccountReport) o; + return ( + Objects.equals( + callDeliverabilityScore, + other.callDeliverabilityScore + ) && + Objects.equals(callAnswerScore, other.callAnswerScore) && + Objects.equals(totalCalls, other.totalCalls) && + Objects.equals(callDirection, other.callDirection) && + Objects.equals(callState, other.callState) && + Objects.equals(callType, other.callType) && + Objects.equals(aloc, other.aloc) && + Objects.equals(twilioEdgeLocation, other.twilioEdgeLocation) && + Objects.equals(callerCountryCode, other.callerCountryCode) && + Objects.equals(calleeCountryCode, other.calleeCountryCode) && + Objects.equals(averageQueueTimeMs, other.averageQueueTimeMs) && + Objects.equals( + silentCallsPercentage, + other.silentCallsPercentage + ) && + Objects.equals(networkIssues, other.networkIssues) && + Objects.equals(KYT, other.KYT) && + Objects.equals( + answeringMachineDetection, + other.answeringMachineDetection + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + callDeliverabilityScore, + callAnswerScore, + totalCalls, + callDirection, + callState, + callType, + aloc, + twilioEdgeLocation, + callerCountryCode, + calleeCountryCode, + averageQueueTimeMs, + silentCallsPercentage, + networkIssues, + KYT, + answeringMachineDetection + ); + } + } + + @JsonDeserialize(builder = StirShakenAnswerRate.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class StirShakenAnswerRate { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_a") + @Getter + private final Float stshA; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_b") + @Getter + private final Float stshB; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_c") + @Getter + private final Float stshC; + + private StirShakenAnswerRate(Builder builder) { + this.stshA = builder.stshA; + this.stshB = builder.stshB; + this.stshC = builder.stshC; + } + + public static Builder builder() { + return new Builder(); + } + + public static StirShakenAnswerRate fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, StirShakenAnswerRate.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("stsh_a") + private Float stshA; + + @JsonProperty("stsh_b") + private Float stshB; + + @JsonProperty("stsh_c") + private Float stshC; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_a") + public Builder stshA(Float stshA) { + this.stshA = stshA; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_b") + public Builder stshB(Float stshB) { + this.stshB = stshB; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_c") + public Builder stshC(Float stshC) { + this.stshC = stshC; + return this; + } + + public StirShakenAnswerRate build() { + return new StirShakenAnswerRate(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + StirShakenAnswerRate other = (StirShakenAnswerRate) o; + return ( + Objects.equals(stshA, other.stshA) && + Objects.equals(stshB, other.stshB) && + Objects.equals(stshC, other.stshC) + ); + } + + @Override + public int hashCode() { + return Objects.hash(stshA, stshB, stshC); + } + } + + @JsonDeserialize( + builder = InsightsV2CreateAccountReportRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsV2CreateAccountReportRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_range") + @Getter + private final InsightsV2CreateAccountReportRequestTimeRange timeRange; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + @Getter + private final List filters; + + private InsightsV2CreateAccountReportRequest(Builder builder) { + this.timeRange = builder.timeRange; + this.filters = builder.filters; + } + + public static Builder builder() { + return new Builder(); + } + + public static InsightsV2CreateAccountReportRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsV2CreateAccountReportRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("time_range") + private InsightsV2CreateAccountReportRequestTimeRange timeRange; + + @JsonProperty("filters") + private List filters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time_range") + public Builder timeRange( + InsightsV2CreateAccountReportRequestTimeRange timeRange + ) { + this.timeRange = timeRange; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + public Builder filters(List filters) { + this.filters = filters; + return this; + } + + public InsightsV2CreateAccountReportRequest build() { + return new InsightsV2CreateAccountReportRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsV2CreateAccountReportRequest other = + (InsightsV2CreateAccountReportRequest) o; + return ( + Objects.equals(timeRange, other.timeRange) && + Objects.equals(filters, other.filters) + ); + } + + @Override + public int hashCode() { + return Objects.hash(timeRange, filters); + } + } + + @JsonDeserialize(builder = VoiceIntegrity.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class VoiceIntegrity { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled_calls") + @Getter + private final Integer enabledCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled_percentage") + @Getter + private final Float enabledPercentage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("calls_per_bundle") + @Getter + private final List callsPerBundle; + + private VoiceIntegrity(Builder builder) { + this.enabledCalls = builder.enabledCalls; + this.enabledPercentage = builder.enabledPercentage; + this.callsPerBundle = builder.callsPerBundle; + } + + public static Builder builder() { + return new Builder(); + } + + public static VoiceIntegrity fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, VoiceIntegrity.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("enabled_calls") + private Integer enabledCalls; + + @JsonProperty("enabled_percentage") + private Float enabledPercentage; + + @JsonProperty("calls_per_bundle") + private List callsPerBundle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled_calls") + public Builder enabledCalls(Integer enabledCalls) { + this.enabledCalls = enabledCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled_percentage") + public Builder enabledPercentage(Float enabledPercentage) { + this.enabledPercentage = enabledPercentage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("calls_per_bundle") + public Builder callsPerBundle( + List callsPerBundle + ) { + this.callsPerBundle = callsPerBundle; + return this; + } + + public VoiceIntegrity build() { + return new VoiceIntegrity(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + VoiceIntegrity other = (VoiceIntegrity) o; + return ( + Objects.equals(enabledCalls, other.enabledCalls) && + Objects.equals(enabledPercentage, other.enabledPercentage) && + Objects.equals(callsPerBundle, other.callsPerBundle) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + enabledCalls, + enabledPercentage, + callsPerBundle + ); + } + } + + @JsonDeserialize(builder = StirShakenPercentage.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class StirShakenPercentage { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_a") + @Getter + private final Float stshA; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_b") + @Getter + private final Float stshB; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_c") + @Getter + private final Float stshC; + + private StirShakenPercentage(Builder builder) { + this.stshA = builder.stshA; + this.stshB = builder.stshB; + this.stshC = builder.stshC; + } + + public static Builder builder() { + return new Builder(); + } + + public static StirShakenPercentage fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, StirShakenPercentage.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("stsh_a") + private Float stshA; + + @JsonProperty("stsh_b") + private Float stshB; + + @JsonProperty("stsh_c") + private Float stshC; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_a") + public Builder stshA(Float stshA) { + this.stshA = stshA; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_b") + public Builder stshB(Float stshB) { + this.stshB = stshB; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stsh_c") + public Builder stshC(Float stshC) { + this.stshC = stshC; + return this; + } + + public StirShakenPercentage build() { + return new StirShakenPercentage(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + StirShakenPercentage other = (StirShakenPercentage) o; + return ( + Objects.equals(stshA, other.stshA) && + Objects.equals(stshB, other.stshB) && + Objects.equals(stshC, other.stshC) + ); + } + + @Override + public int hashCode() { + return Objects.hash(stshA, stshB, stshC); + } + } + + @JsonDeserialize(builder = AccountReportKYT.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportKYT { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outbound_carrier_calling") + @Getter + private final AccountReportKYTOutboundCarrierCalling outboundCarrierCalling; + + private AccountReportKYT(Builder builder) { + this.outboundCarrierCalling = builder.outboundCarrierCalling; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportKYT fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, AccountReportKYT.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("outbound_carrier_calling") + private AccountReportKYTOutboundCarrierCalling outboundCarrierCalling; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outbound_carrier_calling") + public Builder outboundCarrierCalling( + AccountReportKYTOutboundCarrierCalling outboundCarrierCalling + ) { + this.outboundCarrierCalling = outboundCarrierCalling; + return this; + } + + public AccountReportKYT build() { + return new AccountReportKYT(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportKYT other = (AccountReportKYT) o; + return ( + Objects.equals( + outboundCarrierCalling, + other.outboundCarrierCalling + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash(outboundCarrierCalling); + } + } + + @JsonDeserialize(builder = BrandedCalling.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class BrandedCalling { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_branded_calls") + @Getter + private final Integer totalBrandedCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("percent_branded_calls") + @Getter + private final Float percentBrandedCalls; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answer_rate") + @Getter + private final Float answerRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("human_answer_rate") + @Getter + private final Float humanAnswerRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("engagement_rate") + @Getter + private final Float engagementRate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("by_use_case") + @Getter + private final List byUseCase; + + private BrandedCalling(Builder builder) { + this.totalBrandedCalls = builder.totalBrandedCalls; + this.percentBrandedCalls = builder.percentBrandedCalls; + this.answerRate = builder.answerRate; + this.humanAnswerRate = builder.humanAnswerRate; + this.engagementRate = builder.engagementRate; + this.byUseCase = builder.byUseCase; + } + + public static Builder builder() { + return new Builder(); + } + + public static BrandedCalling fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, BrandedCalling.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total_branded_calls") + private Integer totalBrandedCalls; + + @JsonProperty("percent_branded_calls") + private Float percentBrandedCalls; + + @JsonProperty("answer_rate") + private Float answerRate; + + @JsonProperty("human_answer_rate") + private Float humanAnswerRate; + + @JsonProperty("engagement_rate") + private Float engagementRate; + + @JsonProperty("by_use_case") + private List byUseCase; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_branded_calls") + public Builder totalBrandedCalls(Integer totalBrandedCalls) { + this.totalBrandedCalls = totalBrandedCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("percent_branded_calls") + public Builder percentBrandedCalls(Float percentBrandedCalls) { + this.percentBrandedCalls = percentBrandedCalls; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("answer_rate") + public Builder answerRate(Float answerRate) { + this.answerRate = answerRate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("human_answer_rate") + public Builder humanAnswerRate(Float humanAnswerRate) { + this.humanAnswerRate = humanAnswerRate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("engagement_rate") + public Builder engagementRate(Float engagementRate) { + this.engagementRate = engagementRate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("by_use_case") + public Builder byUseCase(List byUseCase) { + this.byUseCase = byUseCase; + return this; + } + + public BrandedCalling build() { + return new BrandedCalling(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BrandedCalling other = (BrandedCalling) o; + return ( + Objects.equals(totalBrandedCalls, other.totalBrandedCalls) && + Objects.equals( + percentBrandedCalls, + other.percentBrandedCalls + ) && + Objects.equals(answerRate, other.answerRate) && + Objects.equals(humanAnswerRate, other.humanAnswerRate) && + Objects.equals(engagementRate, other.engagementRate) && + Objects.equals(byUseCase, other.byUseCase) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + totalBrandedCalls, + percentBrandedCalls, + answerRate, + humanAnswerRate, + engagementRate, + byUseCase + ); + } + } + + @JsonDeserialize(builder = AccountReportCallState.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportCallState { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("completed") + @Getter + private final Integer completed; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fail") + @Getter + private final Integer fail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("busy") + @Getter + private final Integer busy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("noanswer") + @Getter + private final Integer noanswer; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("canceled") + @Getter + private final Integer canceled; + + private AccountReportCallState(Builder builder) { + this.completed = builder.completed; + this.fail = builder.fail; + this.busy = builder.busy; + this.noanswer = builder.noanswer; + this.canceled = builder.canceled; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportCallState fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, AccountReportCallState.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("completed") + private Integer completed; + + @JsonProperty("fail") + private Integer fail; + + @JsonProperty("busy") + private Integer busy; + + @JsonProperty("noanswer") + private Integer noanswer; + + @JsonProperty("canceled") + private Integer canceled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("completed") + public Builder completed(Integer completed) { + this.completed = completed; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fail") + public Builder fail(Integer fail) { + this.fail = fail; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("busy") + public Builder busy(Integer busy) { + this.busy = busy; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("noanswer") + public Builder noanswer(Integer noanswer) { + this.noanswer = noanswer; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("canceled") + public Builder canceled(Integer canceled) { + this.canceled = canceled; + return this; + } + + public AccountReportCallState build() { + return new AccountReportCallState(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportCallState other = (AccountReportCallState) o; + return ( + Objects.equals(completed, other.completed) && + Objects.equals(fail, other.fail) && + Objects.equals(busy, other.busy) && + Objects.equals(noanswer, other.noanswer) && + Objects.equals(canceled, other.canceled) + ); + } + + @Override + public int hashCode() { + return Objects.hash(completed, fail, busy, noanswer, canceled); + } + } + + @JsonDeserialize(builder = AccountReportNetworkIssues.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class AccountReportNetworkIssues { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sdk") + @Getter + private final AccountReportNetworkIssuesSdk sdk; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio_gateway") + @Getter + private final AccountReportNetworkIssuesTwilioGateway twilioGateway; + + private AccountReportNetworkIssues(Builder builder) { + this.sdk = builder.sdk; + this.twilioGateway = builder.twilioGateway; + } + + public static Builder builder() { + return new Builder(); + } + + public static AccountReportNetworkIssues fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + AccountReportNetworkIssues.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("sdk") + private AccountReportNetworkIssuesSdk sdk; + + @JsonProperty("twilio_gateway") + private AccountReportNetworkIssuesTwilioGateway twilioGateway; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sdk") + public Builder sdk(AccountReportNetworkIssuesSdk sdk) { + this.sdk = sdk; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio_gateway") + public Builder twilioGateway( + AccountReportNetworkIssuesTwilioGateway twilioGateway + ) { + this.twilioGateway = twilioGateway; + return this; + } + + public AccountReportNetworkIssues build() { + return new AccountReportNetworkIssues(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AccountReportNetworkIssues other = (AccountReportNetworkIssues) o; + return ( + Objects.equals(sdk, other.sdk) && + Objects.equals(twilioGateway, other.twilioGateway) + ); + } + + @Override + public int hashCode() { + return Objects.hash(sdk, twilioGateway); + } + } + + @JsonDeserialize(builder = ReportMetadata.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReportMetadata { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + @Getter + private final ZonedDateTime startDatetime; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + @Getter + private final ZonedDateTime endDatetime; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + @Getter + private final List filters; + + private ReportMetadata(Builder builder) { + this.startDatetime = builder.startDatetime; + this.endDatetime = builder.endDatetime; + this.filters = builder.filters; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReportMetadata fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ReportMetadata.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("start_datetime") + private ZonedDateTime startDatetime; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("end_datetime") + private ZonedDateTime endDatetime; + + @JsonProperty("filters") + private List filters; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("start_datetime") + public Builder startDatetime(ZonedDateTime startDatetime) { + this.startDatetime = startDatetime; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("end_datetime") + public Builder endDatetime(ZonedDateTime endDatetime) { + this.endDatetime = endDatetime; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + public Builder filters(List filters) { + this.filters = filters; + return this; + } + + public ReportMetadata build() { + return new ReportMetadata(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReportMetadata other = (ReportMetadata) o; + return ( + Objects.equals(startDatetime, other.startDatetime) && + Objects.equals(endDatetime, other.endDatetime) && + Objects.equals(filters, other.filters) + ); + } + + @Override + public int hashCode() { + return Objects.hash(startDatetime, endDatetime, filters); + } + } + + /** + * Converts a JSON String into a Report object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Report object represented by the provided JSON + */ + public static Report fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Report.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Report object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Report object represented by the provided JSON + */ + public static Report fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Report.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final AccountReport report; + + @Getter + private final String reportId; + + @Getter + private final ReportMetadata requestMeta; + + @Getter + private final Report.ReportStatus status; + + @Getter + private final URI url; + + @JsonCreator + private Report( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("report") final AccountReport report, + @JsonProperty("report_id") final String reportId, + @JsonProperty("request_meta") final ReportMetadata requestMeta, + @JsonProperty("status") final Report.ReportStatus status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.report = report; + this.reportId = reportId; + this.requestMeta = requestMeta; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Report other = (Report) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(report, other.report) && + Objects.equals(reportId, other.reportId) && + Objects.equals(requestMeta, other.requestMeta) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + report, + reportId, + requestMeta, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/ReportCreator.java b/src/main/java/com/twilio/rest/insights/v2/ReportCreator.java new file mode 100644 index 0000000000..fdae16e759 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/ReportCreator.java @@ -0,0 +1,113 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ReportCreator extends Creator { + + private Report.InsightsV2CreateAccountReportRequest insightsV2CreateAccountReportRequest; + + public ReportCreator() {} + + public ReportCreator setInsightsV2CreateAccountReportRequest( + final Report.InsightsV2CreateAccountReportRequest insightsV2CreateAccountReportRequest + ) { + this.insightsV2CreateAccountReportRequest = + insightsV2CreateAccountReportRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Reports"; + + Request request = new Request( + HttpMethod.POST, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Report creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Report create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Report.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Report content = Report.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (insightsV2CreateAccountReportRequest != null) { + request.setBody( + Report.toJson( + insightsV2CreateAccountReportRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v2/ReportFetcher.java b/src/main/java/com/twilio/rest/insights/v2/ReportFetcher.java new file mode 100644 index 0000000000..fc9445039c --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v2/ReportFetcher.java @@ -0,0 +1,94 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Sample/reference Twilio API. + * This is the reference API for the rest-proxy server. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ReportFetcher extends Fetcher { + + private String pathReportId; + + public ReportFetcher(final String pathReportId) { + this.pathReportId = pathReportId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Reports/{reportId}"; + + path = + path.replace("{" + "reportId" + "}", this.pathReportId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Report fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Report fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Report.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Report content = Report.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/CustomFieldMapping.java b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMapping.java new file mode 100644 index 0000000000..a8651c9506 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMapping.java @@ -0,0 +1,1513 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CustomFieldMapping extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateCustomFieldMappingResponse extends Resource { + + @Getter + private final CustomFieldMapping.MappingCategory category; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final EntityMetadata entityMetadata; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private CreateCustomFieldMappingResponse( + @JsonProperty( + "category" + ) final CustomFieldMapping.MappingCategory category, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("entityMetadata") final EntityMetadata entityMetadata, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.category = category; + this.createdAt = createdAt; + this.description = description; + this.entityMetadata = entityMetadata; + this.id = id; + this.name = name; + this.updatedAt = updatedAt; + } + + public static CreateCustomFieldMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateCustomFieldMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateCustomFieldMappingResponse other = + (CreateCustomFieldMappingResponse) o; + return ( + Objects.equals(category, other.category) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(entityMetadata, other.entityMetadata) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + category, + createdAt, + description, + entityMetadata, + id, + name, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateCustomFieldMappingResponse extends Resource { + + @JsonCreator + private UpdateCustomFieldMappingResponse() {} + + public static UpdateCustomFieldMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateCustomFieldMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateCustomFieldMappingResponse other = + (UpdateCustomFieldMappingResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteCustomFieldMappingResponse extends Resource { + + @JsonCreator + private DeleteCustomFieldMappingResponse() {} + + public static DeleteCustomFieldMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteCustomFieldMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteCustomFieldMappingResponse other = + (DeleteCustomFieldMappingResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListCustomFieldMappingResponse extends Resource { + + @Getter + private final CustomFieldMapping.MappingCategory category; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final EntityMetadata entityMetadata; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListCustomFieldMappingResponse( + @JsonProperty( + "category" + ) final CustomFieldMapping.MappingCategory category, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("entityMetadata") final EntityMetadata entityMetadata, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.category = category; + this.createdAt = createdAt; + this.description = description; + this.entityMetadata = entityMetadata; + this.id = id; + this.name = name; + this.updatedAt = updatedAt; + } + + public static ListCustomFieldMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListCustomFieldMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListCustomFieldMappingResponse other = + (ListCustomFieldMappingResponse) o; + return ( + Objects.equals(category, other.category) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(entityMetadata, other.entityMetadata) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + category, + createdAt, + description, + entityMetadata, + id, + name, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchCustomFieldMappingResponse extends Resource { + + @Getter + private final CustomFieldMapping.MappingCategory category; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final EntityMetadata entityMetadata; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private PatchCustomFieldMappingResponse( + @JsonProperty( + "category" + ) final CustomFieldMapping.MappingCategory category, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("entityMetadata") final EntityMetadata entityMetadata, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.category = category; + this.createdAt = createdAt; + this.description = description; + this.entityMetadata = entityMetadata; + this.id = id; + this.name = name; + this.updatedAt = updatedAt; + } + + public static PatchCustomFieldMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchCustomFieldMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchCustomFieldMappingResponse other = + (PatchCustomFieldMappingResponse) o; + return ( + Objects.equals(category, other.category) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(entityMetadata, other.entityMetadata) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + category, + createdAt, + description, + entityMetadata, + id, + name, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchCustomFieldMappingResponse extends Resource { + + @Getter + private final CustomFieldMapping.MappingCategory category; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final EntityMetadata entityMetadata; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchCustomFieldMappingResponse( + @JsonProperty( + "category" + ) final CustomFieldMapping.MappingCategory category, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("entityMetadata") final EntityMetadata entityMetadata, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.category = category; + this.createdAt = createdAt; + this.description = description; + this.entityMetadata = entityMetadata; + this.id = id; + this.name = name; + this.updatedAt = updatedAt; + } + + public static FetchCustomFieldMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchCustomFieldMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchCustomFieldMappingResponse other = + (FetchCustomFieldMappingResponse) o; + return ( + Objects.equals(category, other.category) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(entityMetadata, other.entityMetadata) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + category, + createdAt, + description, + entityMetadata, + id, + name, + updatedAt + ); + } + } + + public static CustomFieldMappingCreator creator( + final CustomFieldMapping.CustomFieldMappingRequest customFieldMappingRequest + ) { + return new CustomFieldMappingCreator(customFieldMappingRequest); + } + + public static CustomFieldMappingFetcher fetcher( + final String pathMappingId + ) { + return new CustomFieldMappingFetcher(pathMappingId); + } + + public static CustomFieldMappingReader reader() { + return new CustomFieldMappingReader(); + } + + public static CustomFieldMappingPatcher patcher( + final String pathMappingId, + final CustomFieldMapping.CustomFieldMappingUpdateRequest customFieldMappingUpdateRequest + ) { + return new CustomFieldMappingPatcher( + pathMappingId, + customFieldMappingUpdateRequest + ); + } + + public enum SourceType { + INTELLIGENCE_OPERATOR("INTELLIGENCE_OPERATOR"); + + private final String value; + + private SourceType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static SourceType forValue(final String value) { + return Promoter.enumFromString(value, SourceType.values()); + } + } + + public enum MappingCategory { + MEASURE("MEASURE"); + + private final String value; + + private MappingCategory(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static MappingCategory forValue(final String value) { + return Promoter.enumFromString(value, MappingCategory.values()); + } + } + + @JsonDeserialize(builder = CustomFieldMappingUpdateRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CustomFieldMappingUpdateRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("entityMetadata") + @Getter + private final EntityMetadataUpdate entityMetadata; + + private CustomFieldMappingUpdateRequest(Builder builder) { + this.entityMetadata = builder.entityMetadata; + } + + public static Builder builder() { + return new Builder(); + } + + public static CustomFieldMappingUpdateRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CustomFieldMappingUpdateRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("entityMetadata") + private EntityMetadataUpdate entityMetadata; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("entityMetadata") + public Builder entityMetadata(EntityMetadataUpdate entityMetadata) { + this.entityMetadata = entityMetadata; + return this; + } + + public CustomFieldMappingUpdateRequest build() { + return new CustomFieldMappingUpdateRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomFieldMappingUpdateRequest other = + (CustomFieldMappingUpdateRequest) o; + return (Objects.equals(entityMetadata, other.entityMetadata)); + } + + @Override + public int hashCode() { + return Objects.hash(entityMetadata); + } + } + + @JsonDeserialize(builder = IntelligenceOperatorSource.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IntelligenceOperatorSource { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operatorId") + @Getter + private final String operatorId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operatorName") + @Getter + private final String operatorName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + @Getter + private final String field; + + private IntelligenceOperatorSource(Builder builder) { + this.operatorId = builder.operatorId; + this.operatorName = builder.operatorName; + this.field = builder.field; + } + + public static Builder builder( + final String operatorId, + final String field + ) { + return new Builder(operatorId, field); + } + + public static IntelligenceOperatorSource fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IntelligenceOperatorSource.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("operatorId") + private String operatorId; + + @JsonProperty("operatorName") + private String operatorName; + + @JsonProperty("field") + private String field; + + @JsonCreator + public Builder( + @JsonProperty("operatorId") final String operatorId, + @JsonProperty("field") final String field + ) { + this.operatorId = operatorId; + this.field = field; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operatorName") + public Builder operatorName(String operatorName) { + this.operatorName = operatorName; + return this; + } + + public IntelligenceOperatorSource build() { + return new IntelligenceOperatorSource(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IntelligenceOperatorSource other = (IntelligenceOperatorSource) o; + return ( + Objects.equals(operatorId, other.operatorId) && + Objects.equals(operatorName, other.operatorName) && + Objects.equals(field, other.field) + ); + } + + @Override + public int hashCode() { + return Objects.hash(operatorId, operatorName, field); + } + } + + @JsonDeserialize(builder = PaginationMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PaginationMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private PaginationMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static PaginationMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, PaginationMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public PaginationMeta build() { + return new PaginationMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PaginationMeta other = (PaginationMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize(builder = EntityMetadataUpdate.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class EntityMetadataUpdate { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sourceType") + @Getter + private final CustomFieldMapping.SourceType sourceType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceOperator") + @Getter + private final IntelligenceOperatorSourceUpdate intelligenceOperator; + + private EntityMetadataUpdate(Builder builder) { + this.sourceType = builder.sourceType; + this.intelligenceOperator = builder.intelligenceOperator; + } + + public static Builder builder( + final CustomFieldMapping.SourceType sourceType + ) { + return new Builder(sourceType); + } + + public static EntityMetadataUpdate fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, EntityMetadataUpdate.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("sourceType") + private CustomFieldMapping.SourceType sourceType; + + @JsonProperty("intelligenceOperator") + private IntelligenceOperatorSourceUpdate intelligenceOperator; + + @JsonCreator + public Builder( + @JsonProperty( + "sourceType" + ) final CustomFieldMapping.SourceType sourceType + ) { + this.sourceType = sourceType; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceOperator") + public Builder intelligenceOperator( + IntelligenceOperatorSourceUpdate intelligenceOperator + ) { + this.intelligenceOperator = intelligenceOperator; + return this; + } + + public EntityMetadataUpdate build() { + return new EntityMetadataUpdate(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EntityMetadataUpdate other = (EntityMetadataUpdate) o; + return ( + Objects.equals(sourceType, other.sourceType) && + Objects.equals(intelligenceOperator, other.intelligenceOperator) + ); + } + + @Override + public int hashCode() { + return Objects.hash(sourceType, intelligenceOperator); + } + } + + @JsonDeserialize(builder = CustomFieldMappingRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CustomFieldMappingRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("category") + @Getter + private final CustomFieldMapping.MappingCategory category; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("entityMetadata") + @Getter + private final EntityMetadata entityMetadata; + + private CustomFieldMappingRequest(Builder builder) { + this.category = builder.category; + this.name = builder.name; + this.description = builder.description; + this.entityMetadata = builder.entityMetadata; + } + + public static Builder builder( + final CustomFieldMapping.MappingCategory category, + final String name, + final EntityMetadata entityMetadata + ) { + return new Builder(category, name, entityMetadata); + } + + public static CustomFieldMappingRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CustomFieldMappingRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("category") + private CustomFieldMapping.MappingCategory category; + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("entityMetadata") + private EntityMetadata entityMetadata; + + @JsonCreator + public Builder( + @JsonProperty( + "category" + ) final CustomFieldMapping.MappingCategory category, + @JsonProperty("name") final String name, + @JsonProperty( + "entityMetadata" + ) final EntityMetadata entityMetadata + ) { + this.category = category; + this.name = name; + this.entityMetadata = entityMetadata; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public CustomFieldMappingRequest build() { + return new CustomFieldMappingRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomFieldMappingRequest other = (CustomFieldMappingRequest) o; + return ( + Objects.equals(category, other.category) && + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(entityMetadata, other.entityMetadata) + ); + } + + @Override + public int hashCode() { + return Objects.hash(category, name, description, entityMetadata); + } + } + + @JsonDeserialize(builder = EntityMetadata.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class EntityMetadata { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sourceType") + @Getter + private final CustomFieldMapping.SourceType sourceType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceOperator") + @Getter + private final IntelligenceOperatorSource intelligenceOperator; + + private EntityMetadata(Builder builder) { + this.sourceType = builder.sourceType; + this.intelligenceOperator = builder.intelligenceOperator; + } + + public static Builder builder( + final CustomFieldMapping.SourceType sourceType + ) { + return new Builder(sourceType); + } + + public static EntityMetadata fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, EntityMetadata.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("sourceType") + private CustomFieldMapping.SourceType sourceType; + + @JsonProperty("intelligenceOperator") + private IntelligenceOperatorSource intelligenceOperator; + + @JsonCreator + public Builder( + @JsonProperty( + "sourceType" + ) final CustomFieldMapping.SourceType sourceType + ) { + this.sourceType = sourceType; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceOperator") + public Builder intelligenceOperator( + IntelligenceOperatorSource intelligenceOperator + ) { + this.intelligenceOperator = intelligenceOperator; + return this; + } + + public EntityMetadata build() { + return new EntityMetadata(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EntityMetadata other = (EntityMetadata) o; + return ( + Objects.equals(sourceType, other.sourceType) && + Objects.equals(intelligenceOperator, other.intelligenceOperator) + ); + } + + @Override + public int hashCode() { + return Objects.hash(sourceType, intelligenceOperator); + } + } + + @JsonDeserialize(builder = IntelligenceOperatorSourceUpdate.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IntelligenceOperatorSourceUpdate { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + @Getter + private final String field; + + private IntelligenceOperatorSourceUpdate(Builder builder) { + this.field = builder.field; + } + + public static Builder builder() { + return new Builder(); + } + + public static IntelligenceOperatorSourceUpdate fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IntelligenceOperatorSourceUpdate.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("field") + private String field; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + public Builder field(String field) { + this.field = field; + return this; + } + + public IntelligenceOperatorSourceUpdate build() { + return new IntelligenceOperatorSourceUpdate(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IntelligenceOperatorSourceUpdate other = + (IntelligenceOperatorSourceUpdate) o; + return (Objects.equals(field, other.field)); + } + + @Override + public int hashCode() { + return Objects.hash(field); + } + } + + @JsonDeserialize(builder = CustomFieldMappingResponse.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CustomFieldMappingResponse { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("category") + @Getter + private final CustomFieldMapping.MappingCategory category; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("entityMetadata") + @Getter + private final EntityMetadata entityMetadata; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + private CustomFieldMappingResponse(Builder builder) { + this.id = builder.id; + this.category = builder.category; + this.name = builder.name; + this.description = builder.description; + this.entityMetadata = builder.entityMetadata; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + } + + public static Builder builder( + final CustomFieldMapping.MappingCategory category, + final String name, + final EntityMetadata entityMetadata + ) { + return new Builder(category, name, entityMetadata); + } + + public static CustomFieldMappingResponse fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CustomFieldMappingResponse.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("category") + private CustomFieldMapping.MappingCategory category; + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("entityMetadata") + private EntityMetadata entityMetadata; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonCreator + public Builder( + @JsonProperty( + "category" + ) final CustomFieldMapping.MappingCategory category, + @JsonProperty("name") final String name, + @JsonProperty( + "entityMetadata" + ) final EntityMetadata entityMetadata + ) { + this.category = category; + this.name = name; + this.entityMetadata = entityMetadata; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + public Builder updatedAt(ZonedDateTime updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + public CustomFieldMappingResponse build() { + return new CustomFieldMappingResponse(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomFieldMappingResponse other = (CustomFieldMappingResponse) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(category, other.category) && + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(entityMetadata, other.entityMetadata) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + category, + name, + description, + entityMetadata, + createdAt, + updatedAt + ); + } + } + + /** + * Converts a JSON String into a CustomFieldMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomFieldMapping object represented by the provided JSON + */ + public static CustomFieldMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CustomFieldMapping.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CustomFieldMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomFieldMapping object represented by the provided JSON + */ + public static CustomFieldMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CustomFieldMapping.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private CustomFieldMapping() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingCreator.java b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingCreator.java new file mode 100644 index 0000000000..9b4ed47ed3 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingCreator.java @@ -0,0 +1,124 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomFieldMappingCreator + extends Creator { + + private CustomFieldMapping.CustomFieldMappingRequest customFieldMappingRequest; + + public CustomFieldMappingCreator( + final CustomFieldMapping.CustomFieldMappingRequest customFieldMappingRequest + ) { + this.customFieldMappingRequest = customFieldMappingRequest; + } + + public CustomFieldMappingCreator setCustomFieldMappingRequest( + final CustomFieldMapping.CustomFieldMappingRequest customFieldMappingRequest + ) { + this.customFieldMappingRequest = customFieldMappingRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v3/ControlPlane/ConversationInsights/CustomFieldMappings"; + + Request request = new Request( + HttpMethod.POST, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomFieldMapping creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomFieldMapping.CreateCustomFieldMappingResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomFieldMapping.CreateCustomFieldMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + CustomFieldMapping.CreateCustomFieldMappingResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + CustomFieldMapping.CreateCustomFieldMappingResponse content = + CustomFieldMapping.CreateCustomFieldMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (customFieldMappingRequest != null) { + request.setBody( + CustomFieldMapping.toJson( + customFieldMappingRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingFetcher.java b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingFetcher.java new file mode 100644 index 0000000000..a5cd156b89 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingFetcher.java @@ -0,0 +1,105 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomFieldMappingFetcher + extends Fetcher { + + private String pathMappingId; + + public CustomFieldMappingFetcher(final String pathMappingId) { + this.pathMappingId = pathMappingId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v3/ControlPlane/ConversationInsights/CustomFieldMappings/{mappingId}"; + + path = + path.replace( + "{" + "mappingId" + "}", + this.pathMappingId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomFieldMapping fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomFieldMapping.FetchCustomFieldMappingResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomFieldMapping.FetchCustomFieldMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + CustomFieldMapping.FetchCustomFieldMappingResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + CustomFieldMapping.FetchCustomFieldMappingResponse content = + CustomFieldMapping.FetchCustomFieldMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingPatcher.java b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingPatcher.java new file mode 100644 index 0000000000..a01873f880 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingPatcher.java @@ -0,0 +1,131 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomFieldMappingPatcher + extends Patcher { + + private String pathMappingId; + private String ifMatch; + private CustomFieldMapping.CustomFieldMappingUpdateRequest customFieldMappingUpdateRequest; + + public CustomFieldMappingPatcher( + final String pathMappingId, + final CustomFieldMapping.CustomFieldMappingUpdateRequest customFieldMappingUpdateRequest + ) { + this.pathMappingId = pathMappingId; + this.customFieldMappingUpdateRequest = customFieldMappingUpdateRequest; + } + + public CustomFieldMappingPatcher setCustomFieldMappingUpdateRequest( + final CustomFieldMapping.CustomFieldMappingUpdateRequest customFieldMappingUpdateRequest + ) { + this.customFieldMappingUpdateRequest = customFieldMappingUpdateRequest; + return this; + } + + public CustomFieldMappingPatcher setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + @Override + public CustomFieldMapping.PatchCustomFieldMappingResponse patch( + final TwilioRestClient client + ) { + String path = + "/v3/ControlPlane/ConversationInsights/CustomFieldMappings/{mappingId}"; + + path = + path.replace( + "{" + "mappingId" + "}", + this.pathMappingId.toString() + ); + + Request request = new Request( + HttpMethod.PATCH, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomFieldMapping patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return CustomFieldMapping.PatchCustomFieldMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (customFieldMappingUpdateRequest != null) { + request.setBody( + CustomFieldMapping.toJson( + customFieldMappingUpdateRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingReader.java b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingReader.java new file mode 100644 index 0000000000..befbeea35e --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingReader.java @@ -0,0 +1,246 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomFieldMappingReader + extends Reader { + + private Integer pageSize; + private String pageToken; + + public CustomFieldMappingReader() {} + + public CustomFieldMappingReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public CustomFieldMappingReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse< + CustomFieldMapping.ListCustomFieldMappingResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = + Page.fromJson( + "items", + response.getContent(), + CustomFieldMapping.ListCustomFieldMappingResponse.class, + client.getObjectMapper() + ); + ResourceSet< + CustomFieldMapping.ListCustomFieldMappingResponse + > resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v3/ControlPlane/ConversationInsights/CustomFieldMappings"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = + Page.fromJson( + "items", + response.getContent(), + CustomFieldMapping.ListCustomFieldMappingResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CustomFieldMapping read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page< + CustomFieldMapping.ListCustomFieldMappingResponse + > pageForRequest(final TwilioRestClient client, final Request request) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "items", + response.getContent(), + CustomFieldMapping.ListCustomFieldMappingResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = + "/v3/ControlPlane/ConversationInsights/CustomFieldMappings"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = + "/v3/ControlPlane/ConversationInsights/CustomFieldMappings"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingsCapacity.java b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingsCapacity.java new file mode 100644 index 0000000000..9cd4894399 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingsCapacity.java @@ -0,0 +1,475 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CustomFieldMappingsCapacity extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateCustomFieldMappingsCapacityResponse + extends Resource { + + @JsonCreator + private CreateCustomFieldMappingsCapacityResponse() {} + + public static CreateCustomFieldMappingsCapacityResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateCustomFieldMappingsCapacityResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateCustomFieldMappingsCapacityResponse other = + (CreateCustomFieldMappingsCapacityResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateCustomFieldMappingsCapacityResponse + extends Resource { + + @JsonCreator + private UpdateCustomFieldMappingsCapacityResponse() {} + + public static UpdateCustomFieldMappingsCapacityResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateCustomFieldMappingsCapacityResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateCustomFieldMappingsCapacityResponse other = + (UpdateCustomFieldMappingsCapacityResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteCustomFieldMappingsCapacityResponse + extends Resource { + + @JsonCreator + private DeleteCustomFieldMappingsCapacityResponse() {} + + public static DeleteCustomFieldMappingsCapacityResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteCustomFieldMappingsCapacityResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteCustomFieldMappingsCapacityResponse other = + (DeleteCustomFieldMappingsCapacityResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListCustomFieldMappingsCapacityResponse + extends Resource { + + @JsonCreator + private ListCustomFieldMappingsCapacityResponse() {} + + public static ListCustomFieldMappingsCapacityResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListCustomFieldMappingsCapacityResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListCustomFieldMappingsCapacityResponse other = + (ListCustomFieldMappingsCapacityResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchCustomFieldMappingsCapacityResponse + extends Resource { + + @JsonCreator + private PatchCustomFieldMappingsCapacityResponse() {} + + public static PatchCustomFieldMappingsCapacityResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchCustomFieldMappingsCapacityResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchCustomFieldMappingsCapacityResponse other = + (PatchCustomFieldMappingsCapacityResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchCustomFieldMappingsCapacityResponse + extends Resource { + + @Getter + private final CategoryCapacity measure; + + @JsonCreator + private FetchCustomFieldMappingsCapacityResponse( + @JsonProperty("measure") final CategoryCapacity measure + ) { + this.measure = measure; + } + + public static FetchCustomFieldMappingsCapacityResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchCustomFieldMappingsCapacityResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchCustomFieldMappingsCapacityResponse other = + (FetchCustomFieldMappingsCapacityResponse) o; + return Objects.equals(measure, other.measure); + } + + @Override + public int hashCode() { + return Objects.hash(measure); + } + } + + public static CustomFieldMappingsCapacityFetcher fetcher() { + return new CustomFieldMappingsCapacityFetcher(); + } + + @JsonDeserialize(builder = CategoryCapacity.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CategoryCapacity { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("consumed") + @Getter + private final Integer consumed; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("remaining") + @Getter + private final Integer remaining; + + private CategoryCapacity(Builder builder) { + this.consumed = builder.consumed; + this.remaining = builder.remaining; + } + + public static Builder builder( + final Integer consumed, + final Integer remaining + ) { + return new Builder(consumed, remaining); + } + + public static CategoryCapacity fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CategoryCapacity.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("consumed") + private Integer consumed; + + @JsonProperty("remaining") + private Integer remaining; + + @JsonCreator + public Builder( + @JsonProperty("consumed") final Integer consumed, + @JsonProperty("remaining") final Integer remaining + ) { + this.consumed = consumed; + this.remaining = remaining; + } + + public CategoryCapacity build() { + return new CategoryCapacity(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CategoryCapacity other = (CategoryCapacity) o; + return ( + Objects.equals(consumed, other.consumed) && + Objects.equals(remaining, other.remaining) + ); + } + + @Override + public int hashCode() { + return Objects.hash(consumed, remaining); + } + } + + /** + * Converts a JSON String into a CustomFieldMappingsCapacity object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomFieldMappingsCapacity object represented by the provided JSON + */ + public static CustomFieldMappingsCapacity fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomFieldMappingsCapacity.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CustomFieldMappingsCapacity object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomFieldMappingsCapacity object represented by the provided JSON + */ + public static CustomFieldMappingsCapacity fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomFieldMappingsCapacity.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private CustomFieldMappingsCapacity() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingsCapacityFetcher.java b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingsCapacityFetcher.java new file mode 100644 index 0000000000..9c4dd48e63 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/CustomFieldMappingsCapacityFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomFieldMappingsCapacityFetcher + extends Fetcher< + CustomFieldMappingsCapacity.FetchCustomFieldMappingsCapacityResponse + > { + + public CustomFieldMappingsCapacityFetcher() {} + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v3/ControlPlane/ConversationInsights/CustomFieldMappingsCapacity"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomFieldMappingsCapacity fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomFieldMappingsCapacity.FetchCustomFieldMappingsCapacityResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomFieldMappingsCapacity.FetchCustomFieldMappingsCapacityResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + CustomFieldMappingsCapacity.FetchCustomFieldMappingsCapacityResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + CustomFieldMappingsCapacity.FetchCustomFieldMappingsCapacityResponse content = + CustomFieldMappingsCapacity.FetchCustomFieldMappingsCapacityResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/Metadata.java b/src/main/java/com/twilio/rest/insights/v3/Metadata.java new file mode 100644 index 0000000000..5b902e7c9b --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/Metadata.java @@ -0,0 +1,724 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Metadata extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateMetadataResponse extends Resource { + + @JsonCreator + private CreateMetadataResponse() {} + + public static CreateMetadataResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateMetadataResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateMetadataResponse other = (CreateMetadataResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateMetadataResponse extends Resource { + + @JsonCreator + private UpdateMetadataResponse() {} + + public static UpdateMetadataResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateMetadataResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateMetadataResponse other = (UpdateMetadataResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteMetadataResponse extends Resource { + + @JsonCreator + private DeleteMetadataResponse() {} + + public static DeleteMetadataResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteMetadataResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteMetadataResponse other = (DeleteMetadataResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListMetadataResponse extends Resource { + + @JsonCreator + private ListMetadataResponse() {} + + public static ListMetadataResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListMetadataResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListMetadataResponse other = (ListMetadataResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchMetadataResponse extends Resource { + + @JsonCreator + private PatchMetadataResponse() {} + + public static PatchMetadataResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchMetadataResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchMetadataResponse other = (PatchMetadataResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchMetadataResponse extends Resource { + + @Getter + private final List cubes; + + @Getter + private final String domain; + + @JsonCreator + private FetchMetadataResponse( + @JsonProperty("cubes") final List< + InsightsMetadataResponseCubes + > cubes, + @JsonProperty("domain") final String domain + ) { + this.cubes = cubes; + this.domain = domain; + } + + public static FetchMetadataResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchMetadataResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchMetadataResponse other = (FetchMetadataResponse) o; + return ( + Objects.equals(cubes, other.cubes) && + Objects.equals(domain, other.domain) + ); + } + + @Override + public int hashCode() { + return Objects.hash(cubes, domain); + } + } + + public static MetadataFetcher fetcher() { + return new MetadataFetcher(); + } + + @JsonDeserialize(builder = InsightsMetadataResponseCubes.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsMetadataResponseCubes { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("measures") + @Getter + private final List measures; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dimensions") + @Getter + private final List dimensions; + + private InsightsMetadataResponseCubes(Builder builder) { + this.name = builder.name; + this.description = builder.description; + this.measures = builder.measures; + this.dimensions = builder.dimensions; + } + + public static Builder builder( + final String name, + final List measures, + final List dimensions + ) { + return new Builder(name, measures, dimensions); + } + + public static InsightsMetadataResponseCubes fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsMetadataResponseCubes.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("measures") + private List measures; + + @JsonProperty("dimensions") + private List dimensions; + + @JsonCreator + public Builder( + @JsonProperty("name") final String name, + @JsonProperty("measures") final List< + InsightsMetadataResponseCubesMeasures + > measures, + @JsonProperty("dimensions") final List< + InsightsMetadataResponseCubesDimensions + > dimensions + ) { + this.name = name; + this.measures = measures; + this.dimensions = dimensions; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public InsightsMetadataResponseCubes build() { + return new InsightsMetadataResponseCubes(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsMetadataResponseCubes other = + (InsightsMetadataResponseCubes) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(measures, other.measures) && + Objects.equals(dimensions, other.dimensions) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, description, measures, dimensions); + } + } + + @JsonDeserialize( + builder = InsightsMetadataResponseCubesDimensions.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsMetadataResponseCubesDimensions { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + private InsightsMetadataResponseCubesDimensions(Builder builder) { + this.name = builder.name; + this.description = builder.description; + this.type = builder.type; + } + + public static Builder builder(final String name, final String type) { + return new Builder(name, type); + } + + public static InsightsMetadataResponseCubesDimensions fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsMetadataResponseCubesDimensions.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("type") + private String type; + + @JsonCreator + public Builder( + @JsonProperty("name") final String name, + @JsonProperty("type") final String type + ) { + this.name = name; + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public InsightsMetadataResponseCubesDimensions build() { + return new InsightsMetadataResponseCubesDimensions(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsMetadataResponseCubesDimensions other = + (InsightsMetadataResponseCubesDimensions) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(type, other.type) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, description, type); + } + } + + @JsonDeserialize( + builder = InsightsMetadataResponseCubesMeasures.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsMetadataResponseCubesMeasures { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("aggregation") + @Getter + private final String aggregation; + + private InsightsMetadataResponseCubesMeasures(Builder builder) { + this.name = builder.name; + this.description = builder.description; + this.type = builder.type; + this.aggregation = builder.aggregation; + } + + public static Builder builder(final String name, final String type) { + return new Builder(name, type); + } + + public static InsightsMetadataResponseCubesMeasures fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + InsightsMetadataResponseCubesMeasures.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("type") + private String type; + + @JsonProperty("aggregation") + private String aggregation; + + @JsonCreator + public Builder( + @JsonProperty("name") final String name, + @JsonProperty("type") final String type + ) { + this.name = name; + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("aggregation") + public Builder aggregation(String aggregation) { + this.aggregation = aggregation; + return this; + } + + public InsightsMetadataResponseCubesMeasures build() { + return new InsightsMetadataResponseCubesMeasures(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsMetadataResponseCubesMeasures other = + (InsightsMetadataResponseCubesMeasures) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(type, other.type) && + Objects.equals(aggregation, other.aggregation) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, description, type, aggregation); + } + } + + /** + * Converts a JSON String into a Metadata object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Metadata object represented by the provided JSON + */ + public static Metadata fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Metadata.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Metadata object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Metadata object represented by the provided JSON + */ + public static Metadata fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Metadata.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Metadata() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/MetadataFetcher.java b/src/main/java/com/twilio/rest/insights/v3/MetadataFetcher.java new file mode 100644 index 0000000000..b20b119889 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/MetadataFetcher.java @@ -0,0 +1,91 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MetadataFetcher extends Fetcher { + + public MetadataFetcher() {} + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/InsightsDomains/Conversations/Metadata"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Metadata fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Metadata.FetchMetadataResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Metadata.FetchMetadataResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Metadata.FetchMetadataResponse content = + Metadata.FetchMetadataResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/Query.java b/src/main/java/com/twilio/rest/insights/v3/Query.java new file mode 100644 index 0000000000..1da8494fd3 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/Query.java @@ -0,0 +1,1037 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Query extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateQueryResponse extends Resource { + + @Getter + private final String domain; + + @Getter + private final List> items; + + @Getter + private final PaginationMeta meta; + + @JsonCreator + private CreateQueryResponse( + @JsonProperty("domain") final String domain, + @JsonProperty("items") final List> items, + @JsonProperty("meta") final PaginationMeta meta + ) { + this.domain = domain; + this.items = items; + this.meta = meta; + } + + public static CreateQueryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateQueryResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateQueryResponse other = (CreateQueryResponse) o; + return ( + Objects.equals(domain, other.domain) && + Objects.equals(items, other.items) && + Objects.equals(meta, other.meta) + ); + } + + @Override + public int hashCode() { + return Objects.hash(domain, items, meta); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateQueryResponse extends Resource { + + @JsonCreator + private UpdateQueryResponse() {} + + public static UpdateQueryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateQueryResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateQueryResponse other = (UpdateQueryResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteQueryResponse extends Resource { + + @JsonCreator + private DeleteQueryResponse() {} + + public static DeleteQueryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteQueryResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteQueryResponse other = (DeleteQueryResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListQueryResponse extends Resource { + + @JsonCreator + private ListQueryResponse() {} + + public static ListQueryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListQueryResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListQueryResponse other = (ListQueryResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchQueryResponse extends Resource { + + @JsonCreator + private PatchQueryResponse() {} + + public static PatchQueryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchQueryResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchQueryResponse other = (PatchQueryResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchQueryResponse extends Resource { + + @Getter + private final String domain; + + @Getter + private final List> items; + + @Getter + private final PaginationMeta meta; + + @JsonCreator + private FetchQueryResponse( + @JsonProperty("domain") final String domain, + @JsonProperty("items") final List> items, + @JsonProperty("meta") final PaginationMeta meta + ) { + this.domain = domain; + this.items = items; + this.meta = meta; + } + + public static FetchQueryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchQueryResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchQueryResponse other = (FetchQueryResponse) o; + return ( + Objects.equals(domain, other.domain) && + Objects.equals(items, other.items) && + Objects.equals(meta, other.meta) + ); + } + + @Override + public int hashCode() { + return Objects.hash(domain, items, meta); + } + } + + public static QueryCreator creator( + final Query.InsightsQueryRequest insightsQueryRequest + ) { + return new QueryCreator(insightsQueryRequest); + } + + public static QueryFetcher fetcher(final String pageToken) { + return new QueryFetcher(pageToken); + } + + public enum Op { + AND("AND"), + OR("OR"), + EQ("EQ"), + NE("NE"), + GT("GT"), + LT("LT"), + IN("IN"); + + private final String value; + + private Op(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Op forValue(final String value) { + return Promoter.enumFromString(value, Op.values()); + } + } + + public enum Direction { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private Direction(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Direction forValue(final String value) { + return Promoter.enumFromString(value, Direction.values()); + } + } + + @JsonDeserialize(builder = InsightsQueryRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsQueryRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("domain") + @Getter + private final String domain; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("query") + @Getter + private final QueryDefinition query; + + private InsightsQueryRequest(Builder builder) { + this.domain = builder.domain; + this.query = builder.query; + } + + public static Builder builder(final QueryDefinition query) { + return new Builder(query); + } + + public static InsightsQueryRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, InsightsQueryRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("domain") + private String domain; + + @JsonProperty("query") + private QueryDefinition query; + + @JsonCreator + public Builder(@JsonProperty("query") final QueryDefinition query) { + this.query = query; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("domain") + public Builder domain(String domain) { + this.domain = domain; + return this; + } + + public InsightsQueryRequest build() { + return new InsightsQueryRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsQueryRequest other = (InsightsQueryRequest) o; + return ( + Objects.equals(domain, other.domain) && + Objects.equals(query, other.query) + ); + } + + @Override + public int hashCode() { + return Objects.hash(domain, query); + } + } + + @JsonDeserialize(builder = QueryDefinition.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryDefinition { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("measures") + @Getter + private final List measures; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dimensions") + @Getter + private final List dimensions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + @Getter + private final List filters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("orderBy") + @Getter + private final List orderBy; + + private QueryDefinition(Builder builder) { + this.measures = builder.measures; + this.dimensions = builder.dimensions; + this.filters = builder.filters; + this.orderBy = builder.orderBy; + } + + public static Builder builder() { + return new Builder(); + } + + public static QueryDefinition fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, QueryDefinition.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("measures") + private List measures; + + @JsonProperty("dimensions") + private List dimensions; + + @JsonProperty("filters") + private List filters; + + @JsonProperty("orderBy") + private List orderBy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("measures") + public Builder measures(List measures) { + this.measures = measures; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dimensions") + public Builder dimensions(List dimensions) { + this.dimensions = dimensions; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + public Builder filters(List filters) { + this.filters = filters; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("orderBy") + public Builder orderBy(List orderBy) { + this.orderBy = orderBy; + return this; + } + + public QueryDefinition build() { + return new QueryDefinition(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryDefinition other = (QueryDefinition) o; + return ( + Objects.equals(measures, other.measures) && + Objects.equals(dimensions, other.dimensions) && + Objects.equals(filters, other.filters) && + Objects.equals(orderBy, other.orderBy) + ); + } + + @Override + public int hashCode() { + return Objects.hash(measures, dimensions, filters, orderBy); + } + } + + @JsonDeserialize(builder = PaginationMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PaginationMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private PaginationMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static PaginationMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, PaginationMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public PaginationMeta build() { + return new PaginationMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PaginationMeta other = (PaginationMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize(builder = QueryDefinitionFilters.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryDefinitionFilters { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("op") + @Getter + private final Query.Op op; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("expressions") + @Getter + private final List expressions; + + private QueryDefinitionFilters(Builder builder) { + this.op = builder.op; + this.expressions = builder.expressions; + } + + public static Builder builder( + final List expressions + ) { + return new Builder(expressions); + } + + public static QueryDefinitionFilters fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, QueryDefinitionFilters.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("op") + private Query.Op op; + + @JsonProperty("expressions") + private List expressions; + + @JsonCreator + public Builder( + @JsonProperty("expressions") final List< + QueryDefinitionFiltersExpressions + > expressions + ) { + this.expressions = expressions; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("op") + public Builder op(Query.Op op) { + this.op = op; + return this; + } + + public QueryDefinitionFilters build() { + return new QueryDefinitionFilters(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryDefinitionFilters other = (QueryDefinitionFilters) o; + return ( + Objects.equals(op, other.op) && + Objects.equals(expressions, other.expressions) + ); + } + + @Override + public int hashCode() { + return Objects.hash(op, expressions); + } + } + + @JsonDeserialize(builder = QueryDefinitionFiltersExpressions.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryDefinitionFiltersExpressions { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("op") + @Getter + private final Query.Op op; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + @Getter + private final String field; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + @Getter + private final List values; + + private QueryDefinitionFiltersExpressions(Builder builder) { + this.op = builder.op; + this.field = builder.field; + this.values = builder.values; + } + + public static Builder builder(final Query.Op op, final String field) { + return new Builder(op, field); + } + + public static QueryDefinitionFiltersExpressions fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + QueryDefinitionFiltersExpressions.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("op") + private Query.Op op; + + @JsonProperty("field") + private String field; + + @JsonProperty("values") + private List values; + + @JsonCreator + public Builder( + @JsonProperty("op") final Query.Op op, + @JsonProperty("field") final String field + ) { + this.op = op; + this.field = field; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + public Builder values(List values) { + this.values = values; + return this; + } + + public QueryDefinitionFiltersExpressions build() { + return new QueryDefinitionFiltersExpressions(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryDefinitionFiltersExpressions other = + (QueryDefinitionFiltersExpressions) o; + return ( + Objects.equals(op, other.op) && + Objects.equals(field, other.field) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(op, field, values); + } + } + + @JsonDeserialize(builder = QueryDefinitionOrderBy.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryDefinitionOrderBy { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + @Getter + private final String field; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("direction") + @Getter + private final Query.Direction direction; + + private QueryDefinitionOrderBy(Builder builder) { + this.field = builder.field; + this.direction = builder.direction; + } + + public static Builder builder() { + return new Builder(); + } + + public static QueryDefinitionOrderBy fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, QueryDefinitionOrderBy.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("field") + private String field; + + @JsonProperty("direction") + private Query.Direction direction; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + public Builder field(String field) { + this.field = field; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("direction") + public Builder direction(Query.Direction direction) { + this.direction = direction; + return this; + } + + public QueryDefinitionOrderBy build() { + return new QueryDefinitionOrderBy(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryDefinitionOrderBy other = (QueryDefinitionOrderBy) o; + return ( + Objects.equals(field, other.field) && + Objects.equals(direction, other.direction) + ); + } + + @Override + public int hashCode() { + return Objects.hash(field, direction); + } + } + + /** + * Converts a JSON String into a Query object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Query object represented by the provided JSON + */ + public static Query fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Query.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Query object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Query object represented by the provided JSON + */ + public static Query fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Query.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Query() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/QueryCreator.java b/src/main/java/com/twilio/rest/insights/v3/QueryCreator.java new file mode 100644 index 0000000000..78977b8f1f --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/QueryCreator.java @@ -0,0 +1,132 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class QueryCreator extends Creator { + + private Integer pageSize; + private Query.InsightsQueryRequest insightsQueryRequest; + + public QueryCreator(final Query.InsightsQueryRequest insightsQueryRequest) { + this.insightsQueryRequest = insightsQueryRequest; + } + + public QueryCreator setInsightsQueryRequest( + final Query.InsightsQueryRequest insightsQueryRequest + ) { + this.insightsQueryRequest = insightsQueryRequest; + return this; + } + + public QueryCreator setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/InsightsDomains/Conversations/Query"; + + Request request = new Request( + HttpMethod.POST, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addQueryParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Query creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Query.CreateQueryResponse create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Query.CreateQueryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Query.CreateQueryResponse content = Query.CreateQueryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (insightsQueryRequest != null) { + request.setBody(Query.toJson(insightsQueryRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/QueryFetcher.java b/src/main/java/com/twilio/rest/insights/v3/QueryFetcher.java new file mode 100644 index 0000000000..928ec7a155 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/QueryFetcher.java @@ -0,0 +1,113 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class QueryFetcher extends Fetcher { + + private String pageToken; + + public QueryFetcher(final String pageToken) { + this.pageToken = pageToken; + } + + public QueryFetcher setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/InsightsDomains/Conversations/Query"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Query fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Query.FetchQueryResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Query.FetchQueryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Query.FetchQueryResponse content = Query.FetchQueryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/QueryJob.java b/src/main/java/com/twilio/rest/insights/v3/QueryJob.java new file mode 100644 index 0000000000..62cda89f96 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/QueryJob.java @@ -0,0 +1,1563 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class QueryJob extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateQueryJobResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String operationId; + + @Getter + private final QueryJob.LongRunningOperationStatus status; + + @Getter + private final URI statusUrl; + + @JsonCreator + private CreateQueryJobResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("operationId") final String operationId, + @JsonProperty( + "status" + ) final QueryJob.LongRunningOperationStatus status, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.createdAt = createdAt; + this.operationId = operationId; + this.status = status; + this.statusUrl = statusUrl; + } + + public static CreateQueryJobResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateQueryJobResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateQueryJobResponse other = (CreateQueryJobResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(operationId, other.operationId) && + Objects.equals(status, other.status) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(createdAt, operationId, status, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateQueryJobResponse extends Resource { + + @JsonCreator + private UpdateQueryJobResponse() {} + + public static UpdateQueryJobResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateQueryJobResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateQueryJobResponse other = (UpdateQueryJobResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteQueryJobResponse extends Resource { + + @JsonCreator + private DeleteQueryJobResponse() {} + + public static DeleteQueryJobResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteQueryJobResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteQueryJobResponse other = (DeleteQueryJobResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListQueryJobResponse extends Resource { + + @Getter + private final ZonedDateTime completedAt; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final OperationError error; + + @Getter + private final String operationId; + + @Getter + private final String resultId; + + @Getter + private final String resultRetentionPeriod; + + @Getter + private final URI resultUrl; + + @Getter + private final QueryJob.LongRunningOperationStatus status; + + @Getter + private final URI statusUrl; + + @JsonCreator + private ListQueryJobResponse( + @JsonProperty("completedAt") final ZonedDateTime completedAt, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("error") final OperationError error, + @JsonProperty("operationId") final String operationId, + @JsonProperty("resultId") final String resultId, + @JsonProperty( + "resultRetentionPeriod" + ) final String resultRetentionPeriod, + @JsonProperty("resultUrl") final URI resultUrl, + @JsonProperty( + "status" + ) final QueryJob.LongRunningOperationStatus status, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.completedAt = completedAt; + this.createdAt = createdAt; + this.error = error; + this.operationId = operationId; + this.resultId = resultId; + this.resultRetentionPeriod = resultRetentionPeriod; + this.resultUrl = resultUrl; + this.status = status; + this.statusUrl = statusUrl; + } + + public static ListQueryJobResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListQueryJobResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListQueryJobResponse other = (ListQueryJobResponse) o; + return ( + Objects.equals(completedAt, other.completedAt) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(error, other.error) && + Objects.equals(operationId, other.operationId) && + Objects.equals(resultId, other.resultId) && + Objects.equals( + resultRetentionPeriod, + other.resultRetentionPeriod + ) && + Objects.equals(resultUrl, other.resultUrl) && + Objects.equals(status, other.status) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + completedAt, + createdAt, + error, + operationId, + resultId, + resultRetentionPeriod, + resultUrl, + status, + statusUrl + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchQueryJobResponse extends Resource { + + @JsonCreator + private PatchQueryJobResponse() {} + + public static PatchQueryJobResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchQueryJobResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchQueryJobResponse other = (PatchQueryJobResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchQueryJobResponse extends Resource { + + @Getter + private final ZonedDateTime completedAt; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final OperationError error; + + @Getter + private final String operationId; + + @Getter + private final String resultId; + + @Getter + private final String resultRetentionPeriod; + + @Getter + private final URI resultUrl; + + @Getter + private final QueryJob.LongRunningOperationStatus status; + + @Getter + private final URI statusUrl; + + @JsonCreator + private FetchQueryJobResponse( + @JsonProperty("completedAt") final ZonedDateTime completedAt, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("error") final OperationError error, + @JsonProperty("operationId") final String operationId, + @JsonProperty("resultId") final String resultId, + @JsonProperty( + "resultRetentionPeriod" + ) final String resultRetentionPeriod, + @JsonProperty("resultUrl") final URI resultUrl, + @JsonProperty( + "status" + ) final QueryJob.LongRunningOperationStatus status, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.completedAt = completedAt; + this.createdAt = createdAt; + this.error = error; + this.operationId = operationId; + this.resultId = resultId; + this.resultRetentionPeriod = resultRetentionPeriod; + this.resultUrl = resultUrl; + this.status = status; + this.statusUrl = statusUrl; + } + + public static FetchQueryJobResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchQueryJobResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchQueryJobResponse other = (FetchQueryJobResponse) o; + return ( + Objects.equals(completedAt, other.completedAt) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(error, other.error) && + Objects.equals(operationId, other.operationId) && + Objects.equals(resultId, other.resultId) && + Objects.equals( + resultRetentionPeriod, + other.resultRetentionPeriod + ) && + Objects.equals(resultUrl, other.resultUrl) && + Objects.equals(status, other.status) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + completedAt, + createdAt, + error, + operationId, + resultId, + resultRetentionPeriod, + resultUrl, + status, + statusUrl + ); + } + } + + public static QueryJobCreator creator( + final QueryJob.InsightsQueryRequest insightsQueryRequest + ) { + return new QueryJobCreator(insightsQueryRequest); + } + + public static QueryJobFetcher fetcher(final String pathOperationId) { + return new QueryJobFetcher(pathOperationId); + } + + public static QueryJobReader reader() { + return new QueryJobReader(); + } + + public enum Op { + AND("AND"), + OR("OR"), + EQ("EQ"), + NE("NE"), + GT("GT"), + LT("LT"), + IN("IN"); + + private final String value; + + private Op(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Op forValue(final String value) { + return Promoter.enumFromString(value, Op.values()); + } + } + + public enum LongRunningOperationStatus { + PENDING("PENDING"), + RUNNING("RUNNING"), + CANCELLED("CANCELLED"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private LongRunningOperationStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static LongRunningOperationStatus forValue(final String value) { + return Promoter.enumFromString( + value, + LongRunningOperationStatus.values() + ); + } + } + + public enum Direction { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private Direction(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Direction forValue(final String value) { + return Promoter.enumFromString(value, Direction.values()); + } + } + + @JsonDeserialize(builder = InsightsQueryRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class InsightsQueryRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("domain") + @Getter + private final String domain; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("query") + @Getter + private final QueryDefinition query; + + private InsightsQueryRequest(Builder builder) { + this.domain = builder.domain; + this.query = builder.query; + } + + public static Builder builder(final QueryDefinition query) { + return new Builder(query); + } + + public static InsightsQueryRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, InsightsQueryRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("domain") + private String domain; + + @JsonProperty("query") + private QueryDefinition query; + + @JsonCreator + public Builder(@JsonProperty("query") final QueryDefinition query) { + this.query = query; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("domain") + public Builder domain(String domain) { + this.domain = domain; + return this; + } + + public InsightsQueryRequest build() { + return new InsightsQueryRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InsightsQueryRequest other = (InsightsQueryRequest) o; + return ( + Objects.equals(domain, other.domain) && + Objects.equals(query, other.query) + ); + } + + @Override + public int hashCode() { + return Objects.hash(domain, query); + } + } + + @JsonDeserialize(builder = QueryDefinition.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryDefinition { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("measures") + @Getter + private final List measures; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dimensions") + @Getter + private final List dimensions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + @Getter + private final List filters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("orderBy") + @Getter + private final List orderBy; + + private QueryDefinition(Builder builder) { + this.measures = builder.measures; + this.dimensions = builder.dimensions; + this.filters = builder.filters; + this.orderBy = builder.orderBy; + } + + public static Builder builder() { + return new Builder(); + } + + public static QueryDefinition fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, QueryDefinition.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("measures") + private List measures; + + @JsonProperty("dimensions") + private List dimensions; + + @JsonProperty("filters") + private List filters; + + @JsonProperty("orderBy") + private List orderBy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("measures") + public Builder measures(List measures) { + this.measures = measures; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dimensions") + public Builder dimensions(List dimensions) { + this.dimensions = dimensions; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filters") + public Builder filters(List filters) { + this.filters = filters; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("orderBy") + public Builder orderBy(List orderBy) { + this.orderBy = orderBy; + return this; + } + + public QueryDefinition build() { + return new QueryDefinition(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryDefinition other = (QueryDefinition) o; + return ( + Objects.equals(measures, other.measures) && + Objects.equals(dimensions, other.dimensions) && + Objects.equals(filters, other.filters) && + Objects.equals(orderBy, other.orderBy) + ); + } + + @Override + public int hashCode() { + return Objects.hash(measures, dimensions, filters, orderBy); + } + } + + @JsonDeserialize(builder = PaginationMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PaginationMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private PaginationMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static PaginationMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, PaginationMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public PaginationMeta build() { + return new PaginationMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PaginationMeta other = (PaginationMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize(builder = QueryDefinitionFilters.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryDefinitionFilters { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("op") + @Getter + private final QueryJob.Op op; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("expressions") + @Getter + private final List expressions; + + private QueryDefinitionFilters(Builder builder) { + this.op = builder.op; + this.expressions = builder.expressions; + } + + public static Builder builder( + final List expressions + ) { + return new Builder(expressions); + } + + public static QueryDefinitionFilters fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, QueryDefinitionFilters.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("op") + private QueryJob.Op op; + + @JsonProperty("expressions") + private List expressions; + + @JsonCreator + public Builder( + @JsonProperty("expressions") final List< + QueryDefinitionFiltersExpressions + > expressions + ) { + this.expressions = expressions; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("op") + public Builder op(QueryJob.Op op) { + this.op = op; + return this; + } + + public QueryDefinitionFilters build() { + return new QueryDefinitionFilters(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryDefinitionFilters other = (QueryDefinitionFilters) o; + return ( + Objects.equals(op, other.op) && + Objects.equals(expressions, other.expressions) + ); + } + + @Override + public int hashCode() { + return Objects.hash(op, expressions); + } + } + + @JsonDeserialize(builder = QueryDefinitionFiltersExpressions.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryDefinitionFiltersExpressions { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("op") + @Getter + private final QueryJob.Op op; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + @Getter + private final String field; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + @Getter + private final List values; + + private QueryDefinitionFiltersExpressions(Builder builder) { + this.op = builder.op; + this.field = builder.field; + this.values = builder.values; + } + + public static Builder builder( + final QueryJob.Op op, + final String field + ) { + return new Builder(op, field); + } + + public static QueryDefinitionFiltersExpressions fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + QueryDefinitionFiltersExpressions.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("op") + private QueryJob.Op op; + + @JsonProperty("field") + private String field; + + @JsonProperty("values") + private List values; + + @JsonCreator + public Builder( + @JsonProperty("op") final QueryJob.Op op, + @JsonProperty("field") final String field + ) { + this.op = op; + this.field = field; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + public Builder values(List values) { + this.values = values; + return this; + } + + public QueryDefinitionFiltersExpressions build() { + return new QueryDefinitionFiltersExpressions(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryDefinitionFiltersExpressions other = + (QueryDefinitionFiltersExpressions) o; + return ( + Objects.equals(op, other.op) && + Objects.equals(field, other.field) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(op, field, values); + } + } + + @JsonDeserialize(builder = QueryDefinitionOrderBy.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryDefinitionOrderBy { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + @Getter + private final String field; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("direction") + @Getter + private final QueryJob.Direction direction; + + private QueryDefinitionOrderBy(Builder builder) { + this.field = builder.field; + this.direction = builder.direction; + } + + public static Builder builder() { + return new Builder(); + } + + public static QueryDefinitionOrderBy fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, QueryDefinitionOrderBy.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("field") + private String field; + + @JsonProperty("direction") + private QueryJob.Direction direction; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + public Builder field(String field) { + this.field = field; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("direction") + public Builder direction(QueryJob.Direction direction) { + this.direction = direction; + return this; + } + + public QueryDefinitionOrderBy build() { + return new QueryDefinitionOrderBy(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryDefinitionOrderBy other = (QueryDefinitionOrderBy) o; + return ( + Objects.equals(field, other.field) && + Objects.equals(direction, other.direction) + ); + } + + @Override + public int hashCode() { + return Objects.hash(field, direction); + } + } + + @JsonDeserialize(builder = QueryJobStatusResponse.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class QueryJobStatusResponse { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operationId") + @Getter + private final String operationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final QueryJob.LongRunningOperationStatus status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusUrl") + @Getter + private final URI statusUrl; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("completedAt") + @Getter + private final ZonedDateTime completedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error") + @Getter + private final OperationError error; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resultUrl") + @Getter + private final URI resultUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resultId") + @Getter + private final String resultId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resultRetentionPeriod") + @Getter + private final String resultRetentionPeriod; + + private QueryJobStatusResponse(Builder builder) { + this.operationId = builder.operationId; + this.status = builder.status; + this.statusUrl = builder.statusUrl; + this.createdAt = builder.createdAt; + this.completedAt = builder.completedAt; + this.error = builder.error; + this.resultUrl = builder.resultUrl; + this.resultId = builder.resultId; + this.resultRetentionPeriod = builder.resultRetentionPeriod; + } + + public static Builder builder( + final String operationId, + final QueryJob.LongRunningOperationStatus status, + final ZonedDateTime createdAt + ) { + return new Builder(operationId, status, createdAt); + } + + public static QueryJobStatusResponse fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, QueryJobStatusResponse.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("operationId") + private String operationId; + + @JsonProperty("status") + private QueryJob.LongRunningOperationStatus status; + + @JsonProperty("statusUrl") + private URI statusUrl; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("completedAt") + private ZonedDateTime completedAt; + + @JsonProperty("error") + private OperationError error; + + @JsonProperty("resultUrl") + private URI resultUrl; + + @JsonProperty("resultId") + private String resultId; + + @JsonProperty("resultRetentionPeriod") + private String resultRetentionPeriod; + + @JsonCreator + public Builder( + @JsonProperty("operationId") final String operationId, + @JsonProperty( + "status" + ) final QueryJob.LongRunningOperationStatus status, + @JsonProperty("createdAt") final ZonedDateTime createdAt + ) { + this.operationId = operationId; + this.status = status; + this.createdAt = createdAt; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusUrl") + public Builder statusUrl(URI statusUrl) { + this.statusUrl = statusUrl; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("completedAt") + public Builder completedAt(ZonedDateTime completedAt) { + this.completedAt = completedAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error") + public Builder error(OperationError error) { + this.error = error; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resultUrl") + public Builder resultUrl(URI resultUrl) { + this.resultUrl = resultUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resultId") + public Builder resultId(String resultId) { + this.resultId = resultId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resultRetentionPeriod") + public Builder resultRetentionPeriod(String resultRetentionPeriod) { + this.resultRetentionPeriod = resultRetentionPeriod; + return this; + } + + public QueryJobStatusResponse build() { + return new QueryJobStatusResponse(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + QueryJobStatusResponse other = (QueryJobStatusResponse) o; + return ( + Objects.equals(operationId, other.operationId) && + Objects.equals(status, other.status) && + Objects.equals(statusUrl, other.statusUrl) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(completedAt, other.completedAt) && + Objects.equals(error, other.error) && + Objects.equals(resultUrl, other.resultUrl) && + Objects.equals(resultId, other.resultId) && + Objects.equals( + resultRetentionPeriod, + other.resultRetentionPeriod + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + operationId, + status, + statusUrl, + createdAt, + completedAt, + error, + resultUrl, + resultId, + resultRetentionPeriod + ); + } + } + + @JsonDeserialize(builder = OperationError.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperationError { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + @Getter + private final Integer code; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("message") + @Getter + private final String message; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("httpStatusCode") + @Getter + private final Integer httpStatusCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + @Getter + private final String detail; + + private OperationError(Builder builder) { + this.code = builder.code; + this.message = builder.message; + this.httpStatusCode = builder.httpStatusCode; + this.detail = builder.detail; + } + + public static Builder builder( + final Integer code, + final String message, + final Integer httpStatusCode + ) { + return new Builder(code, message, httpStatusCode); + } + + public static OperationError fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperationError.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("code") + private Integer code; + + @JsonProperty("message") + private String message; + + @JsonProperty("httpStatusCode") + private Integer httpStatusCode; + + @JsonProperty("detail") + private String detail; + + @JsonCreator + public Builder( + @JsonProperty("code") final Integer code, + @JsonProperty("message") final String message, + @JsonProperty("httpStatusCode") final Integer httpStatusCode + ) { + this.code = code; + this.message = message; + this.httpStatusCode = httpStatusCode; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + public Builder detail(String detail) { + this.detail = detail; + return this; + } + + public OperationError build() { + return new OperationError(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperationError other = (OperationError) o; + return ( + Objects.equals(code, other.code) && + Objects.equals(message, other.message) && + Objects.equals(httpStatusCode, other.httpStatusCode) && + Objects.equals(detail, other.detail) + ); + } + + @Override + public int hashCode() { + return Objects.hash(code, message, httpStatusCode, detail); + } + } + + /** + * Converts a JSON String into a QueryJob object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return QueryJob object represented by the provided JSON + */ + public static QueryJob fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, QueryJob.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a QueryJob object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return QueryJob object represented by the provided JSON + */ + public static QueryJob fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, QueryJob.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private QueryJob() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/QueryJobCreator.java b/src/main/java/com/twilio/rest/insights/v3/QueryJobCreator.java new file mode 100644 index 0000000000..b4fa23992d --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/QueryJobCreator.java @@ -0,0 +1,140 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.UUID; + +public class QueryJobCreator extends Creator { + + private UUID idempotencyKey; + private QueryJob.InsightsQueryRequest insightsQueryRequest; + + public QueryJobCreator( + final QueryJob.InsightsQueryRequest insightsQueryRequest + ) { + this.insightsQueryRequest = insightsQueryRequest; + } + + public QueryJobCreator setInsightsQueryRequest( + final QueryJob.InsightsQueryRequest insightsQueryRequest + ) { + this.insightsQueryRequest = insightsQueryRequest; + return this; + } + + public QueryJobCreator setIdempotencyKey(final UUID idempotencyKey) { + this.idempotencyKey = idempotencyKey; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/InsightsDomains/Conversations/QueryJobs"; + + Request request = new Request( + HttpMethod.POST, + Domains.INSIGHTS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "QueryJob creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public QueryJob.CreateQueryJobResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return QueryJob.CreateQueryJobResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + QueryJob.CreateQueryJobResponse content = + QueryJob.CreateQueryJobResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (idempotencyKey != null) { + Serializer.toString( + request, + "Idempotency-Key", + idempotencyKey, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (insightsQueryRequest != null) { + request.setBody( + QueryJob.toJson(insightsQueryRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/QueryJobFetcher.java b/src/main/java/com/twilio/rest/insights/v3/QueryJobFetcher.java new file mode 100644 index 0000000000..dd9ef62148 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/QueryJobFetcher.java @@ -0,0 +1,102 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class QueryJobFetcher extends Fetcher { + + private String pathOperationId; + + public QueryJobFetcher(final String pathOperationId) { + this.pathOperationId = pathOperationId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v3/InsightsDomains/Conversations/QueryJobs/{operationId}"; + + path = + path.replace( + "{" + "operationId" + "}", + this.pathOperationId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "QueryJob fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public QueryJob.FetchQueryJobResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return QueryJob.FetchQueryJobResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + QueryJob.FetchQueryJobResponse content = + QueryJob.FetchQueryJobResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/QueryJobReader.java b/src/main/java/com/twilio/rest/insights/v3/QueryJobReader.java new file mode 100644 index 0000000000..dfd3dc03f1 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/QueryJobReader.java @@ -0,0 +1,252 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class QueryJobReader extends Reader { + + private Integer pageSize; + private String pageToken; + private QueryJob.LongRunningOperationStatus status; + + public QueryJobReader() {} + + public QueryJobReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public QueryJobReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public QueryJobReader setStatus( + final QueryJob.LongRunningOperationStatus status + ) { + this.status = status; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + QueryJob.ListQueryJobResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v3/InsightsDomains/Conversations/QueryJobs"; + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + QueryJob.ListQueryJobResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "QueryJob read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "items", + response.getContent(), + QueryJob.ListQueryJobResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/InsightsDomains/Conversations/QueryJobs"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/InsightsDomains/Conversations/QueryJobs"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (status != null) { + Serializer.toString(request, "status", status, ParameterType.QUERY); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/Result.java b/src/main/java/com/twilio/rest/insights/v3/Result.java new file mode 100644 index 0000000000..3701dd879b --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/Result.java @@ -0,0 +1,489 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Result extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateResultResponse extends Resource { + + @JsonCreator + private CreateResultResponse() {} + + public static CreateResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateResultResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateResultResponse other = (CreateResultResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateResultResponse extends Resource { + + @JsonCreator + private UpdateResultResponse() {} + + public static UpdateResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateResultResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateResultResponse other = (UpdateResultResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteResultResponse extends Resource { + + @JsonCreator + private DeleteResultResponse() {} + + public static DeleteResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteResultResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteResultResponse other = (DeleteResultResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListResultResponse extends Resource { + + @JsonCreator + private ListResultResponse() {} + + public static ListResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListResultResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListResultResponse other = (ListResultResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchResultResponse extends Resource { + + @JsonCreator + private PatchResultResponse() {} + + public static PatchResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchResultResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchResultResponse other = (PatchResultResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchResultResponse extends Resource { + + @Getter + private final String domain; + + @Getter + private final List> items; + + @Getter + private final PaginationMeta meta; + + @JsonCreator + private FetchResultResponse( + @JsonProperty("domain") final String domain, + @JsonProperty("items") final List> items, + @JsonProperty("meta") final PaginationMeta meta + ) { + this.domain = domain; + this.items = items; + this.meta = meta; + } + + public static FetchResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchResultResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchResultResponse other = (FetchResultResponse) o; + return ( + Objects.equals(domain, other.domain) && + Objects.equals(items, other.items) && + Objects.equals(meta, other.meta) + ); + } + + @Override + public int hashCode() { + return Objects.hash(domain, items, meta); + } + } + + public static ResultFetcher fetcher(final String pathOperationId) { + return new ResultFetcher(pathOperationId); + } + + @JsonDeserialize(builder = PaginationMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PaginationMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private PaginationMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static PaginationMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, PaginationMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public PaginationMeta build() { + return new PaginationMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PaginationMeta other = (PaginationMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + /** + * Converts a JSON String into a Result object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Result object represented by the provided JSON + */ + public static Result fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Result.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Result object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Result object represented by the provided JSON + */ + public static Result fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Result.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Result() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/insights/v3/ResultFetcher.java b/src/main/java/com/twilio/rest/insights/v3/ResultFetcher.java new file mode 100644 index 0000000000..3a35c63ca5 --- /dev/null +++ b/src/main/java/com/twilio/rest/insights/v3/ResultFetcher.java @@ -0,0 +1,137 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Insights + * The Twilio Insights v3 API provides semantic query access to Conversations analytics data. Resources include synchronous Query, Metadata, and asynchronous QueryJobs for long-running queries. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.insights.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ResultFetcher extends Fetcher { + + private String pathOperationId; + private Integer pageSize; + private String pageToken; + + public ResultFetcher(final String pathOperationId) { + this.pathOperationId = pathOperationId; + } + + public ResultFetcher setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResultFetcher setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v3/InsightsDomains/Conversations/QueryJobs/{operationId}/Results"; + + path = + path.replace( + "{" + "operationId" + "}", + this.pathOperationId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INSIGHTS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Result fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Result.FetchResultResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Result.FetchResultResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Result.FetchResultResponse content = + Result.FetchResultResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/CustomOperator.java b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperator.java new file mode 100644 index 0000000000..36f366a6c3 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperator.java @@ -0,0 +1,276 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CustomOperator extends Resource { + + public static CustomOperatorCreator creator( + final String friendlyName, + final String operatorType, + final Object config + ) { + return new CustomOperatorCreator(friendlyName, operatorType, config); + } + + public static CustomOperatorDeleter deleter(final String pathSid) { + return new CustomOperatorDeleter(pathSid); + } + + public static CustomOperatorFetcher fetcher(final String pathSid) { + return new CustomOperatorFetcher(pathSid); + } + + public static CustomOperatorReader reader() { + return new CustomOperatorReader(); + } + + public static CustomOperatorUpdater updater( + final String pathSid, + final String friendlyName, + final Object config + ) { + return new CustomOperatorUpdater(pathSid, friendlyName, config); + } + + public enum Availability { + INTERNAL("internal"), + BETA("beta"), + PUBLIC("public"), + RETIRED("retired"), + GENERAL_AVAILABILITY("general-availability"), + DEPRECATED("deprecated"); + + private final String value; + + private Availability(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Availability forValue(final String value) { + return Promoter.enumFromString(value, Availability.values()); + } + } + + /** + * Converts a JSON String into a CustomOperator object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomOperator object represented by the provided JSON + */ + public static CustomOperator fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CustomOperator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CustomOperator object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomOperator object represented by the provided JSON + */ + public static CustomOperator fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CustomOperator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String author; + + @Getter + private final CustomOperator.Availability availability; + + @Getter + private final Object config; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final String operatorType; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final Integer version; + + @JsonCreator + private CustomOperator( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("author") final String author, + @JsonProperty( + "availability" + ) final CustomOperator.Availability availability, + @JsonProperty("config") final Object config, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("operator_type") final String operatorType, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("version") final Integer version + ) { + this.accountSid = accountSid; + this.author = author; + this.availability = availability; + this.config = config; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.friendlyName = friendlyName; + this.operatorType = operatorType; + this.sid = sid; + this.url = url; + this.version = version; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomOperator other = (CustomOperator) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(author, other.author) && + Objects.equals(availability, other.availability) && + Objects.equals(config, other.config) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(operatorType, other.operatorType) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + author, + availability, + config, + dateCreated, + dateUpdated, + description, + friendlyName, + operatorType, + sid, + url, + version + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorCreator.java b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorCreator.java new file mode 100644 index 0000000000..c3e8e3f66f --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorCreator.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomOperatorCreator extends Creator { + + private String friendlyName; + private String operatorType; + private Object config; + + public CustomOperatorCreator( + final String friendlyName, + final String operatorType, + final Object config + ) { + this.friendlyName = friendlyName; + this.operatorType = operatorType; + this.config = config; + } + + public CustomOperatorCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public CustomOperatorCreator setOperatorType(final String operatorType) { + this.operatorType = operatorType; + return this; + } + + public CustomOperatorCreator setConfig(final Object config) { + this.config = config; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Operators/Custom"; + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomOperator creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomOperator create(final TwilioRestClient client) { + Response response = makeRequest(client); + return CustomOperator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomOperator content = CustomOperator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (operatorType != null) { + Serializer.toString( + request, + "OperatorType", + operatorType, + ParameterType.URLENCODED + ); + } + + if (config != null) { + Serializer.toString( + request, + "Config", + config, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorDeleter.java b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorDeleter.java new file mode 100644 index 0000000000..e83edf2e85 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class CustomOperatorDeleter extends Deleter { + + private String pathSid; + + public CustomOperatorDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Operators/Custom/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomOperator delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorFetcher.java new file mode 100644 index 0000000000..ae0d921d9e --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomOperatorFetcher extends Fetcher { + + private String pathSid; + + public CustomOperatorFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Operators/Custom/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomOperator fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomOperator fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return CustomOperator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomOperator content = CustomOperator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorReader.java b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorReader.java new file mode 100644 index 0000000000..5384a59897 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorReader.java @@ -0,0 +1,234 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomOperatorReader extends Reader { + + private CustomOperator.Availability availability; + private String languageCode; + private Long pageSize; + + public CustomOperatorReader() {} + + public CustomOperatorReader setAvailability( + final CustomOperator.Availability availability + ) { + this.availability = availability; + return this; + } + + public CustomOperatorReader setLanguageCode(final String languageCode) { + this.languageCode = languageCode; + return this; + } + + public CustomOperatorReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operators", + response.getContent(), + CustomOperator.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Operators/Custom"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operators", + response.getContent(), + CustomOperator.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CustomOperator read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "operators", + response.getContent(), + CustomOperator.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (availability != null) { + Serializer.toString( + request, + "Availability", + availability, + ParameterType.QUERY + ); + } + + if (languageCode != null) { + Serializer.toString( + request, + "LanguageCode", + languageCode, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorUpdater.java b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorUpdater.java new file mode 100644 index 0000000000..a8f54fac7c --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/CustomOperatorUpdater.java @@ -0,0 +1,157 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomOperatorUpdater extends Updater { + + private String pathSid; + private String ifMatch; + private String friendlyName; + private Object config; + + public CustomOperatorUpdater( + final String pathSid, + final String friendlyName, + final Object config + ) { + this.pathSid = pathSid; + this.friendlyName = friendlyName; + this.config = config; + } + + public CustomOperatorUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public CustomOperatorUpdater setConfig(final Object config) { + this.config = config; + return this; + } + + public CustomOperatorUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Operators/Custom/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomOperator update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomOperator update(final TwilioRestClient client) { + Response response = makeRequest(client); + return CustomOperator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomOperator content = CustomOperator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (config != null) { + Serializer.toString( + request, + "Config", + config, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/Operator.java b/src/main/java/com/twilio/rest/intelligence/v2/Operator.java new file mode 100644 index 0000000000..57ad89c250 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/Operator.java @@ -0,0 +1,254 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Operator extends Resource { + + public static OperatorFetcher fetcher(final String pathSid) { + return new OperatorFetcher(pathSid); + } + + public static OperatorReader reader() { + return new OperatorReader(); + } + + public enum Availability { + INTERNAL("internal"), + BETA("beta"), + PUBLIC("public"), + DEPRECATED("deprecated"), + GENERAL_AVAILABILITY("general-availability"), + RETIRED("retired"); + + private final String value; + + private Availability(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Availability forValue(final String value) { + return Promoter.enumFromString(value, Availability.values()); + } + } + + /** + * Converts a JSON String into a Operator object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Operator object represented by the provided JSON + */ + public static Operator fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Operator object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Operator object represented by the provided JSON + */ + public static Operator fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String author; + + @Getter + private final Operator.Availability availability; + + @Getter + private final Object config; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final String operatorType; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final Integer version; + + @JsonCreator + private Operator( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("author") final String author, + @JsonProperty("availability") final Operator.Availability availability, + @JsonProperty("config") final Object config, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("operator_type") final String operatorType, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("version") final Integer version + ) { + this.accountSid = accountSid; + this.author = author; + this.availability = availability; + this.config = config; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.friendlyName = friendlyName; + this.operatorType = operatorType; + this.sid = sid; + this.url = url; + this.version = version; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Operator other = (Operator) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(author, other.author) && + Objects.equals(availability, other.availability) && + Objects.equals(config, other.config) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(operatorType, other.operatorType) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + author, + availability, + config, + dateCreated, + dateUpdated, + description, + friendlyName, + operatorType, + sid, + url, + version + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachment.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachment.java new file mode 100644 index 0000000000..b812dc8d6a --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachment.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class OperatorAttachment extends Resource { + + public static OperatorAttachmentCreator creator( + final String pathServiceSid, + final String pathOperatorSid + ) { + return new OperatorAttachmentCreator(pathServiceSid, pathOperatorSid); + } + + public static OperatorAttachmentDeleter deleter( + final String pathServiceSid, + final String pathOperatorSid + ) { + return new OperatorAttachmentDeleter(pathServiceSid, pathOperatorSid); + } + + /** + * Converts a JSON String into a OperatorAttachment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OperatorAttachment object represented by the provided JSON + */ + public static OperatorAttachment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorAttachment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a OperatorAttachment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OperatorAttachment object represented by the provided JSON + */ + public static OperatorAttachment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorAttachment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String operatorSid; + + @Getter + private final String serviceSid; + + @Getter + private final URI url; + + @JsonCreator + private OperatorAttachment( + @JsonProperty("operator_sid") final String operatorSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url + ) { + this.operatorSid = operatorSid; + this.serviceSid = serviceSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorAttachment other = (OperatorAttachment) o; + return ( + Objects.equals(operatorSid, other.operatorSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(operatorSid, serviceSid, url); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentCreator.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentCreator.java new file mode 100644 index 0000000000..83a1d9ef67 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentCreator.java @@ -0,0 +1,110 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorAttachmentCreator extends Creator { + + private String pathServiceSid; + private String pathOperatorSid; + + public OperatorAttachmentCreator( + final String pathServiceSid, + final String pathOperatorSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathOperatorSid = pathOperatorSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Operators/{OperatorSid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "OperatorSid" + "}", + this.pathOperatorSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OperatorAttachment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public OperatorAttachment create(final TwilioRestClient client) { + Response response = makeRequest(client); + return OperatorAttachment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OperatorAttachment content = OperatorAttachment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentDeleter.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentDeleter.java new file mode 100644 index 0000000000..5e1db60c7a --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentDeleter.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class OperatorAttachmentDeleter extends Deleter { + + private String pathServiceSid; + private String pathOperatorSid; + + public OperatorAttachmentDeleter( + final String pathServiceSid, + final String pathOperatorSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathOperatorSid = pathOperatorSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Operators/{OperatorSid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "OperatorSid" + "}", + this.pathOperatorSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OperatorAttachment delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachments.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachments.java new file mode 100644 index 0000000000..0d359dacb5 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachments.java @@ -0,0 +1,146 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class OperatorAttachments extends Resource { + + public static OperatorAttachmentsFetcher fetcher( + final String pathServiceSid + ) { + return new OperatorAttachmentsFetcher(pathServiceSid); + } + + /** + * Converts a JSON String into a OperatorAttachments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OperatorAttachments object represented by the provided JSON + */ + public static OperatorAttachments fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorAttachments.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a OperatorAttachments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OperatorAttachments object represented by the provided JSON + */ + public static OperatorAttachments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorAttachments.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List operatorSids; + + @Getter + private final String serviceSid; + + @Getter + private final URI url; + + @JsonCreator + private OperatorAttachments( + @JsonProperty("operator_sids") final List operatorSids, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url + ) { + this.operatorSids = operatorSids; + this.serviceSid = serviceSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorAttachments other = (OperatorAttachments) o; + return ( + Objects.equals(operatorSids, other.operatorSids) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(operatorSids, serviceSid, url); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentsFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentsFetcher.java new file mode 100644 index 0000000000..6b9faeb7c7 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorAttachmentsFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorAttachmentsFetcher extends Fetcher { + + private String pathServiceSid; + + public OperatorAttachmentsFetcher(final String pathServiceSid) { + this.pathServiceSid = pathServiceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Operators"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OperatorAttachments fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public OperatorAttachments fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return OperatorAttachments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OperatorAttachments content = OperatorAttachments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorFetcher.java new file mode 100644 index 0000000000..ae2e153c08 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorFetcher extends Fetcher { + + private String pathSid; + + public OperatorFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Operators/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Operator fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Operator fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Operator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Operator content = Operator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorReader.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorReader.java new file mode 100644 index 0000000000..b0f75ac683 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorReader.java @@ -0,0 +1,234 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorReader extends Reader { + + private Operator.Availability availability; + private String languageCode; + private Long pageSize; + + public OperatorReader() {} + + public OperatorReader setAvailability( + final Operator.Availability availability + ) { + this.availability = availability; + return this; + } + + public OperatorReader setLanguageCode(final String languageCode) { + this.languageCode = languageCode; + return this; + } + + public OperatorReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operators", + response.getContent(), + Operator.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Operators"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operators", + response.getContent(), + Operator.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Operator read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "operators", + response.getContent(), + Operator.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (availability != null) { + Serializer.toString( + request, + "Availability", + availability, + ParameterType.QUERY + ); + } + + if (languageCode != null) { + Serializer.toString( + request, + "LanguageCode", + languageCode, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorType.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorType.java new file mode 100644 index 0000000000..bb7a5f4a1e --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorType.java @@ -0,0 +1,318 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class OperatorType extends Resource { + + public static OperatorTypeFetcher fetcher(final String pathSid) { + return new OperatorTypeFetcher(pathSid); + } + + public static OperatorTypeReader reader() { + return new OperatorTypeReader(); + } + + public enum Availability { + INTERNAL("internal"), + BETA("beta"), + GENERAL_AVAILABILITY("general-availability"), + RETIRED("retired"), + DEPRECATED("deprecated"); + + private final String value; + + private Availability(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Availability forValue(final String value) { + return Promoter.enumFromString(value, Availability.values()); + } + } + + public enum OutputType { + TEXT_CLASSIFICATION("text-classification"), + TEXT_EXTRACTION("text-extraction"), + TEXT_EXTRACTION_NORMALIZED("text-extraction-normalized"), + TEXT_GENERATION("text-generation"), + JSON("json"); + + private final String value; + + private OutputType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OutputType forValue(final String value) { + return Promoter.enumFromString(value, OutputType.values()); + } + } + + public enum Provider { + TWILIO("twilio"), + AMAZON("amazon"), + OPENAI("openai"); + + private final String value; + + private Provider(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Provider forValue(final String value) { + return Promoter.enumFromString(value, Provider.values()); + } + } + + /** + * Converts a JSON String into a OperatorType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OperatorType object represented by the provided JSON + */ + public static OperatorType fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a OperatorType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OperatorType object represented by the provided JSON + */ + public static OperatorType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final OperatorType.Availability availability; + + @Getter + private final Object configSchema; + + @Getter + private final Boolean configurable; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final URI docsLink; + + @Getter + private final String friendlyName; + + @Getter + private final String name; + + @Getter + private final OperatorType.OutputType outputType; + + @Getter + private final OperatorType.Provider provider; + + @Getter + private final String sid; + + @Getter + private final List supportedLanguages; + + @Getter + private final URI url; + + @JsonCreator + private OperatorType( + @JsonProperty( + "availability" + ) final OperatorType.Availability availability, + @JsonProperty("config_schema") final Object configSchema, + @JsonProperty("configurable") final Boolean configurable, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("docs_link") final URI docsLink, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("name") final String name, + @JsonProperty("output_type") final OperatorType.OutputType outputType, + @JsonProperty("provider") final OperatorType.Provider provider, + @JsonProperty("sid") final String sid, + @JsonProperty("supported_languages") final List< + String + > supportedLanguages, + @JsonProperty("url") final URI url + ) { + this.availability = availability; + this.configSchema = configSchema; + this.configurable = configurable; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.docsLink = docsLink; + this.friendlyName = friendlyName; + this.name = name; + this.outputType = outputType; + this.provider = provider; + this.sid = sid; + this.supportedLanguages = supportedLanguages; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorType other = (OperatorType) o; + return ( + Objects.equals(availability, other.availability) && + Objects.equals(configSchema, other.configSchema) && + Objects.equals(configurable, other.configurable) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(docsLink, other.docsLink) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(name, other.name) && + Objects.equals(outputType, other.outputType) && + Objects.equals(provider, other.provider) && + Objects.equals(sid, other.sid) && + Objects.equals(supportedLanguages, other.supportedLanguages) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + availability, + configSchema, + configurable, + dateCreated, + dateUpdated, + description, + docsLink, + friendlyName, + name, + outputType, + provider, + sid, + supportedLanguages, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorTypeFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorTypeFetcher.java new file mode 100644 index 0000000000..e0523fcb95 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorTypeFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorTypeFetcher extends Fetcher { + + private String pathSid; + + public OperatorTypeFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/OperatorTypes/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OperatorType fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public OperatorType fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return OperatorType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OperatorType content = OperatorType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/OperatorTypeReader.java b/src/main/java/com/twilio/rest/intelligence/v2/OperatorTypeReader.java new file mode 100644 index 0000000000..92dd5e9597 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/OperatorTypeReader.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorTypeReader extends Reader { + + private Long pageSize; + private String languageCode; + + public OperatorTypeReader() {} + + public OperatorTypeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public OperatorTypeReader setLanguageCode(final String languageCode) { + this.languageCode = languageCode; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operator_types", + response.getContent(), + OperatorType.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/OperatorTypes"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operator_types", + response.getContent(), + OperatorType.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "OperatorType read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "operator_types", + response.getContent(), + OperatorType.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (languageCode != null) { + Serializer.toString( + request, + "LanguageCode", + languageCode, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperator.java b/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperator.java new file mode 100644 index 0000000000..3fdcb6a12f --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperator.java @@ -0,0 +1,255 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PrebuiltOperator extends Resource { + + public static PrebuiltOperatorFetcher fetcher(final String pathSid) { + return new PrebuiltOperatorFetcher(pathSid); + } + + public static PrebuiltOperatorReader reader() { + return new PrebuiltOperatorReader(); + } + + public enum Availability { + INTERNAL("internal"), + BETA("beta"), + PUBLIC("public"), + RETIRED("retired"), + GENERAL_AVAILABILITY("general-availability"); + + private final String value; + + private Availability(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Availability forValue(final String value) { + return Promoter.enumFromString(value, Availability.values()); + } + } + + /** + * Converts a JSON String into a PrebuiltOperator object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PrebuiltOperator object represented by the provided JSON + */ + public static PrebuiltOperator fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PrebuiltOperator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PrebuiltOperator object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PrebuiltOperator object represented by the provided JSON + */ + public static PrebuiltOperator fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PrebuiltOperator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String author; + + @Getter + private final PrebuiltOperator.Availability availability; + + @Getter + private final Object config; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final String operatorType; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final Integer version; + + @JsonCreator + private PrebuiltOperator( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("author") final String author, + @JsonProperty( + "availability" + ) final PrebuiltOperator.Availability availability, + @JsonProperty("config") final Object config, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("operator_type") final String operatorType, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("version") final Integer version + ) { + this.accountSid = accountSid; + this.author = author; + this.availability = availability; + this.config = config; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.friendlyName = friendlyName; + this.operatorType = operatorType; + this.sid = sid; + this.url = url; + this.version = version; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PrebuiltOperator other = (PrebuiltOperator) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(author, other.author) && + Objects.equals(availability, other.availability) && + Objects.equals(config, other.config) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(operatorType, other.operatorType) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + author, + availability, + config, + dateCreated, + dateUpdated, + description, + friendlyName, + operatorType, + sid, + url, + version + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperatorFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperatorFetcher.java new file mode 100644 index 0000000000..52b5ddbd41 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperatorFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PrebuiltOperatorFetcher extends Fetcher { + + private String pathSid; + + public PrebuiltOperatorFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Operators/PreBuilt/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PrebuiltOperator fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PrebuiltOperator fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PrebuiltOperator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PrebuiltOperator content = PrebuiltOperator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperatorReader.java b/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperatorReader.java new file mode 100644 index 0000000000..3306c8b44e --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/PrebuiltOperatorReader.java @@ -0,0 +1,234 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PrebuiltOperatorReader extends Reader { + + private PrebuiltOperator.Availability availability; + private String languageCode; + private Long pageSize; + + public PrebuiltOperatorReader() {} + + public PrebuiltOperatorReader setAvailability( + final PrebuiltOperator.Availability availability + ) { + this.availability = availability; + return this; + } + + public PrebuiltOperatorReader setLanguageCode(final String languageCode) { + this.languageCode = languageCode; + return this; + } + + public PrebuiltOperatorReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operators", + response.getContent(), + PrebuiltOperator.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Operators/PreBuilt"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operators", + response.getContent(), + PrebuiltOperator.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PrebuiltOperator read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "operators", + response.getContent(), + PrebuiltOperator.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (availability != null) { + Serializer.toString( + request, + "Availability", + availability, + ParameterType.QUERY + ); + } + + if (languageCode != null) { + Serializer.toString( + request, + "LanguageCode", + languageCode, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/Service.java b/src/main/java/com/twilio/rest/intelligence/v2/Service.java new file mode 100644 index 0000000000..e00a7b8b30 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/Service.java @@ -0,0 +1,312 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.http.HttpMethod; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Service extends Resource { + + public static ServiceCreator creator(final String uniqueName) { + return new ServiceCreator(uniqueName); + } + + public static ServiceDeleter deleter(final String pathSid) { + return new ServiceDeleter(pathSid); + } + + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); + } + + public static ServiceReader reader() { + return new ServiceReader(); + } + + public static ServiceUpdater updater(final String pathSid) { + return new ServiceUpdater(pathSid); + } + + public enum HttpMethod { + GET("GET"), + POST("POST"), + NULL("NULL"); + + private final String value; + + private HttpMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static HttpMethod forValue(final String value) { + return Promoter.enumFromString(value, HttpMethod.values()); + } + } + + /** + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Service.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Service.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean autoRedaction; + + @Getter + private final Boolean autoTranscribe; + + @Getter + private final Boolean dataLogging; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String encryptionCredentialSid; + + @Getter + private final String friendlyName; + + @Getter + private final String languageCode; + + @Getter + private final Boolean mediaRedaction; + + @Getter + private final List readOnlyAttachedOperatorSids; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @Getter + private final Integer version; + + @Getter + private final Service.HttpMethod webhookHttpMethod; + + @Getter + private final String webhookUrl; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("auto_redaction") final Boolean autoRedaction, + @JsonProperty("auto_transcribe") final Boolean autoTranscribe, + @JsonProperty("data_logging") final Boolean dataLogging, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "encryption_credential_sid" + ) final String encryptionCredentialSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("language_code") final String languageCode, + @JsonProperty("media_redaction") final Boolean mediaRedaction, + @JsonProperty("read_only_attached_operator_sids") final List< + String + > readOnlyAttachedOperatorSids, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("version") final Integer version, + @JsonProperty( + "webhook_http_method" + ) final Service.HttpMethod webhookHttpMethod, + @JsonProperty("webhook_url") final String webhookUrl + ) { + this.accountSid = accountSid; + this.autoRedaction = autoRedaction; + this.autoTranscribe = autoTranscribe; + this.dataLogging = dataLogging; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.encryptionCredentialSid = encryptionCredentialSid; + this.friendlyName = friendlyName; + this.languageCode = languageCode; + this.mediaRedaction = mediaRedaction; + this.readOnlyAttachedOperatorSids = readOnlyAttachedOperatorSids; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + this.version = version; + this.webhookHttpMethod = webhookHttpMethod; + this.webhookUrl = webhookUrl; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Service other = (Service) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(autoRedaction, other.autoRedaction) && + Objects.equals(autoTranscribe, other.autoTranscribe) && + Objects.equals(dataLogging, other.dataLogging) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + encryptionCredentialSid, + other.encryptionCredentialSid + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(languageCode, other.languageCode) && + Objects.equals(mediaRedaction, other.mediaRedaction) && + Objects.equals( + readOnlyAttachedOperatorSids, + other.readOnlyAttachedOperatorSids + ) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(version, other.version) && + Objects.equals(webhookHttpMethod, other.webhookHttpMethod) && + Objects.equals(webhookUrl, other.webhookUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + autoRedaction, + autoTranscribe, + dataLogging, + dateCreated, + dateUpdated, + encryptionCredentialSid, + friendlyName, + languageCode, + mediaRedaction, + readOnlyAttachedOperatorSids, + sid, + uniqueName, + url, + version, + webhookHttpMethod, + webhookUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceCreator.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceCreator.java new file mode 100644 index 0000000000..653a419edb --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceCreator.java @@ -0,0 +1,251 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceCreator extends Creator { + + private String uniqueName; + private Boolean autoTranscribe; + private Boolean dataLogging; + private String friendlyName; + private String languageCode; + private Boolean autoRedaction; + private Boolean mediaRedaction; + private String webhookUrl; + private Service.HttpMethod webhookHttpMethod; + private String encryptionCredentialSid; + + public ServiceCreator(final String uniqueName) { + this.uniqueName = uniqueName; + } + + public ServiceCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public ServiceCreator setAutoTranscribe(final Boolean autoTranscribe) { + this.autoTranscribe = autoTranscribe; + return this; + } + + public ServiceCreator setDataLogging(final Boolean dataLogging) { + this.dataLogging = dataLogging; + return this; + } + + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ServiceCreator setLanguageCode(final String languageCode) { + this.languageCode = languageCode; + return this; + } + + public ServiceCreator setAutoRedaction(final Boolean autoRedaction) { + this.autoRedaction = autoRedaction; + return this; + } + + public ServiceCreator setMediaRedaction(final Boolean mediaRedaction) { + this.mediaRedaction = mediaRedaction; + return this; + } + + public ServiceCreator setWebhookUrl(final String webhookUrl) { + this.webhookUrl = webhookUrl; + return this; + } + + public ServiceCreator setWebhookHttpMethod( + final Service.HttpMethod webhookHttpMethod + ) { + this.webhookHttpMethod = webhookHttpMethod; + return this; + } + + public ServiceCreator setEncryptionCredentialSid( + final String encryptionCredentialSid + ) { + this.encryptionCredentialSid = encryptionCredentialSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services"; + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (autoTranscribe != null) { + Serializer.toString( + request, + "AutoTranscribe", + autoTranscribe, + ParameterType.URLENCODED + ); + } + + if (dataLogging != null) { + Serializer.toString( + request, + "DataLogging", + dataLogging, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (languageCode != null) { + Serializer.toString( + request, + "LanguageCode", + languageCode, + ParameterType.URLENCODED + ); + } + + if (autoRedaction != null) { + Serializer.toString( + request, + "AutoRedaction", + autoRedaction, + ParameterType.URLENCODED + ); + } + + if (mediaRedaction != null) { + Serializer.toString( + request, + "MediaRedaction", + mediaRedaction, + ParameterType.URLENCODED + ); + } + + if (webhookUrl != null) { + Serializer.toString( + request, + "WebhookUrl", + webhookUrl, + ParameterType.URLENCODED + ); + } + + if (webhookHttpMethod != null) { + Serializer.toString( + request, + "WebhookHttpMethod", + webhookHttpMethod, + ParameterType.URLENCODED + ); + } + + if (encryptionCredentialSid != null) { + Serializer.toString( + request, + "EncryptionCredentialSid", + encryptionCredentialSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceDeleter.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceDeleter.java new file mode 100644 index 0000000000..bf93532622 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ServiceDeleter extends Deleter { + + private String pathSid; + + public ServiceDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceFetcher.java new file mode 100644 index 0000000000..b8de60f09f --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceFetcher extends Fetcher { + + private String pathSid; + + public ServiceFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceReader.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceReader.java new file mode 100644 index 0000000000..17632c7516 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceReader extends Reader { + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/ServiceUpdater.java b/src/main/java/com/twilio/rest/intelligence/v2/ServiceUpdater.java new file mode 100644 index 0000000000..1b8ff75283 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/ServiceUpdater.java @@ -0,0 +1,257 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceUpdater extends Updater { + + private String pathSid; + private String ifMatch; + private Boolean autoTranscribe; + private Boolean dataLogging; + private String friendlyName; + private String uniqueName; + private Boolean autoRedaction; + private Boolean mediaRedaction; + private String webhookUrl; + private Service.HttpMethod webhookHttpMethod; + private String encryptionCredentialSid; + + public ServiceUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public ServiceUpdater setAutoTranscribe(final Boolean autoTranscribe) { + this.autoTranscribe = autoTranscribe; + return this; + } + + public ServiceUpdater setDataLogging(final Boolean dataLogging) { + this.dataLogging = dataLogging; + return this; + } + + public ServiceUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ServiceUpdater setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public ServiceUpdater setAutoRedaction(final Boolean autoRedaction) { + this.autoRedaction = autoRedaction; + return this; + } + + public ServiceUpdater setMediaRedaction(final Boolean mediaRedaction) { + this.mediaRedaction = mediaRedaction; + return this; + } + + public ServiceUpdater setWebhookUrl(final String webhookUrl) { + this.webhookUrl = webhookUrl; + return this; + } + + public ServiceUpdater setWebhookHttpMethod( + final Service.HttpMethod webhookHttpMethod + ) { + this.webhookHttpMethod = webhookHttpMethod; + return this; + } + + public ServiceUpdater setEncryptionCredentialSid( + final String encryptionCredentialSid + ) { + this.encryptionCredentialSid = encryptionCredentialSid; + return this; + } + + public ServiceUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (autoTranscribe != null) { + Serializer.toString( + request, + "AutoTranscribe", + autoTranscribe, + ParameterType.URLENCODED + ); + } + + if (dataLogging != null) { + Serializer.toString( + request, + "DataLogging", + dataLogging, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (autoRedaction != null) { + Serializer.toString( + request, + "AutoRedaction", + autoRedaction, + ParameterType.URLENCODED + ); + } + + if (mediaRedaction != null) { + Serializer.toString( + request, + "MediaRedaction", + mediaRedaction, + ParameterType.URLENCODED + ); + } + + if (webhookUrl != null) { + Serializer.toString( + request, + "WebhookUrl", + webhookUrl, + ParameterType.URLENCODED + ); + } + + if (webhookHttpMethod != null) { + Serializer.toString( + request, + "WebhookHttpMethod", + webhookHttpMethod, + ParameterType.URLENCODED + ); + } + + if (encryptionCredentialSid != null) { + Serializer.toString( + request, + "EncryptionCredentialSid", + encryptionCredentialSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/Transcript.java b/src/main/java/com/twilio/rest/intelligence/v2/Transcript.java new file mode 100644 index 0000000000..262e86b688 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/Transcript.java @@ -0,0 +1,305 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Transcript extends Resource { + + public static TranscriptCreator creator( + final String serviceSid, + final Object channel + ) { + return new TranscriptCreator(serviceSid, channel); + } + + public static TranscriptDeleter deleter(final String pathSid) { + return new TranscriptDeleter(pathSid); + } + + public static TranscriptFetcher fetcher(final String pathSid) { + return new TranscriptFetcher(pathSid); + } + + public static TranscriptReader reader() { + return new TranscriptReader(); + } + + public enum Status { + QUEUED("queued"), + IN_PROGRESS("in-progress"), + COMPLETED("completed"), + NEW("new"), + FAILED("failed"), + CANCELED("canceled"), + ERROR("error"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a Transcript object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Transcript object represented by the provided JSON + */ + public static Transcript fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Transcript.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Transcript object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Transcript object represented by the provided JSON + */ + public static Transcript fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Transcript.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object channel; + + @Getter + private final String customerKey; + + @Getter + private final Boolean dataLogging; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Integer duration; + + @Getter + private final String encryptionCredentialSid; + + @Getter + private final String languageCode; + + @Getter + private final Map links; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime mediaStartTime; + + @Getter + private final Boolean redaction; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final Transcript.Status status; + + @Getter + private final URI url; + + @JsonCreator + private Transcript( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel") final Object channel, + @JsonProperty("customer_key") final String customerKey, + @JsonProperty("data_logging") final Boolean dataLogging, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("duration") final Integer duration, + @JsonProperty( + "encryption_credential_sid" + ) final String encryptionCredentialSid, + @JsonProperty("language_code") final String languageCode, + @JsonProperty("links") final Map links, + @JsonProperty("media_start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime mediaStartTime, + @JsonProperty("redaction") final Boolean redaction, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Transcript.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channel = channel; + this.customerKey = customerKey; + this.dataLogging = dataLogging; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.duration = duration; + this.encryptionCredentialSid = encryptionCredentialSid; + this.languageCode = languageCode; + this.links = links; + this.mediaStartTime = mediaStartTime; + this.redaction = redaction; + this.serviceSid = serviceSid; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Transcript other = (Transcript) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channel, other.channel) && + Objects.equals(customerKey, other.customerKey) && + Objects.equals(dataLogging, other.dataLogging) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(duration, other.duration) && + Objects.equals( + encryptionCredentialSid, + other.encryptionCredentialSid + ) && + Objects.equals(languageCode, other.languageCode) && + Objects.equals(links, other.links) && + Objects.equals(mediaStartTime, other.mediaStartTime) && + Objects.equals(redaction, other.redaction) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + channel, + customerKey, + dataLogging, + dateCreated, + dateUpdated, + duration, + encryptionCredentialSid, + languageCode, + links, + mediaStartTime, + redaction, + serviceSid, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptCreator.java b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptCreator.java new file mode 100644 index 0000000000..f80f4926c8 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptCreator.java @@ -0,0 +1,164 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class TranscriptCreator extends Creator { + + private String serviceSid; + private Object channel; + private String customerKey; + private ZonedDateTime mediaStartTime; + + public TranscriptCreator(final String serviceSid, final Object channel) { + this.serviceSid = serviceSid; + this.channel = channel; + } + + public TranscriptCreator setServiceSid(final String serviceSid) { + this.serviceSid = serviceSid; + return this; + } + + public TranscriptCreator setChannel(final Object channel) { + this.channel = channel; + return this; + } + + public TranscriptCreator setCustomerKey(final String customerKey) { + this.customerKey = customerKey; + return this; + } + + public TranscriptCreator setMediaStartTime( + final ZonedDateTime mediaStartTime + ) { + this.mediaStartTime = mediaStartTime; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Transcripts"; + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Transcript creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Transcript create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Transcript.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Transcript content = Transcript.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (serviceSid != null) { + Serializer.toString( + request, + "ServiceSid", + serviceSid, + ParameterType.URLENCODED + ); + } + + if (channel != null) { + Serializer.toString( + request, + "Channel", + channel, + ParameterType.URLENCODED + ); + } + + if (customerKey != null) { + Serializer.toString( + request, + "CustomerKey", + customerKey, + ParameterType.URLENCODED + ); + } + + if (mediaStartTime != null) { + Serializer.toString( + request, + "MediaStartTime", + mediaStartTime, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptDeleter.java b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptDeleter.java new file mode 100644 index 0000000000..e911f3421d --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class TranscriptDeleter extends Deleter { + + private String pathSid; + + public TranscriptDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Transcripts/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Transcript delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptFetcher.java new file mode 100644 index 0000000000..19d77abdec --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TranscriptFetcher extends Fetcher { + + private String pathSid; + + public TranscriptFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Transcripts/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Transcript fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Transcript fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Transcript.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Transcript content = Transcript.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/TranscriptReader.java b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptReader.java new file mode 100644 index 0000000000..5bf20d03e8 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/TranscriptReader.java @@ -0,0 +1,319 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TranscriptReader extends Reader { + + private String serviceSid; + private String beforeStartTime; + private String afterStartTime; + private String beforeDateCreated; + private String afterDateCreated; + private String status; + private String languageCode; + private String sourceSid; + private Long pageSize; + + public TranscriptReader() {} + + public TranscriptReader setServiceSid(final String serviceSid) { + this.serviceSid = serviceSid; + return this; + } + + public TranscriptReader setBeforeStartTime(final String beforeStartTime) { + this.beforeStartTime = beforeStartTime; + return this; + } + + public TranscriptReader setAfterStartTime(final String afterStartTime) { + this.afterStartTime = afterStartTime; + return this; + } + + public TranscriptReader setBeforeDateCreated( + final String beforeDateCreated + ) { + this.beforeDateCreated = beforeDateCreated; + return this; + } + + public TranscriptReader setAfterDateCreated(final String afterDateCreated) { + this.afterDateCreated = afterDateCreated; + return this; + } + + public TranscriptReader setStatus(final String status) { + this.status = status; + return this; + } + + public TranscriptReader setLanguageCode(final String languageCode) { + this.languageCode = languageCode; + return this; + } + + public TranscriptReader setSourceSid(final String sourceSid) { + this.sourceSid = sourceSid; + return this; + } + + public TranscriptReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "transcripts", + response.getContent(), + Transcript.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Transcripts"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "transcripts", + response.getContent(), + Transcript.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Transcript read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "transcripts", + response.getContent(), + Transcript.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (serviceSid != null) { + Serializer.toString( + request, + "ServiceSid", + serviceSid, + ParameterType.QUERY + ); + } + + if (beforeStartTime != null) { + Serializer.toString( + request, + "BeforeStartTime", + beforeStartTime, + ParameterType.QUERY + ); + } + + if (afterStartTime != null) { + Serializer.toString( + request, + "AfterStartTime", + afterStartTime, + ParameterType.QUERY + ); + } + + if (beforeDateCreated != null) { + Serializer.toString( + request, + "BeforeDateCreated", + beforeDateCreated, + ParameterType.QUERY + ); + } + + if (afterDateCreated != null) { + Serializer.toString( + request, + "AfterDateCreated", + afterDateCreated, + ParameterType.QUERY + ); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (languageCode != null) { + Serializer.toString( + request, + "LanguageCode", + languageCode, + ParameterType.QUERY + ); + } + + if (sourceSid != null) { + Serializer.toString( + request, + "SourceSid", + sourceSid, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedOperatorResults.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedOperatorResults.java new file mode 100644 index 0000000000..315de50da2 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedOperatorResults.java @@ -0,0 +1,146 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EncryptedOperatorResults extends Resource { + + public static EncryptedOperatorResultsFetcher fetcher( + final String pathTranscriptSid + ) { + return new EncryptedOperatorResultsFetcher(pathTranscriptSid); + } + + /** + * Converts a JSON String into a EncryptedOperatorResults object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EncryptedOperatorResults object represented by the provided JSON + */ + public static EncryptedOperatorResults fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EncryptedOperatorResults.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EncryptedOperatorResults object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EncryptedOperatorResults object represented by the provided JSON + */ + public static EncryptedOperatorResults fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EncryptedOperatorResults.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List locations; + + @Getter + private final String transcriptSid; + + @Getter + private final URI url; + + @JsonCreator + private EncryptedOperatorResults( + @JsonProperty("locations") final List locations, + @JsonProperty("transcript_sid") final String transcriptSid, + @JsonProperty("url") final URI url + ) { + this.locations = locations; + this.transcriptSid = transcriptSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EncryptedOperatorResults other = (EncryptedOperatorResults) o; + return ( + Objects.equals(locations, other.locations) && + Objects.equals(transcriptSid, other.transcriptSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(locations, transcriptSid, url); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedOperatorResultsFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedOperatorResultsFetcher.java new file mode 100644 index 0000000000..1c3b2cf520 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedOperatorResultsFetcher.java @@ -0,0 +1,122 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EncryptedOperatorResultsFetcher + extends Fetcher { + + private String pathTranscriptSid; + private Boolean redacted; + + public EncryptedOperatorResultsFetcher(final String pathTranscriptSid) { + this.pathTranscriptSid = pathTranscriptSid; + } + + public EncryptedOperatorResultsFetcher setRedacted(final Boolean redacted) { + this.redacted = redacted; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Transcripts/{TranscriptSid}/OperatorResults/Encrypted"; + + path = + path.replace( + "{" + "TranscriptSid" + "}", + this.pathTranscriptSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EncryptedOperatorResults fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EncryptedOperatorResults fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EncryptedOperatorResults.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EncryptedOperatorResults content = EncryptedOperatorResults.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (redacted != null) { + Serializer.toString( + request, + "Redacted", + redacted, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedSentences.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedSentences.java new file mode 100644 index 0000000000..3d5550a7e0 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedSentences.java @@ -0,0 +1,145 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EncryptedSentences extends Resource { + + public static EncryptedSentencesFetcher fetcher( + final String pathTranscriptSid + ) { + return new EncryptedSentencesFetcher(pathTranscriptSid); + } + + /** + * Converts a JSON String into a EncryptedSentences object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EncryptedSentences object represented by the provided JSON + */ + public static EncryptedSentences fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EncryptedSentences.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EncryptedSentences object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EncryptedSentences object represented by the provided JSON + */ + public static EncryptedSentences fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EncryptedSentences.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final URI location; + + @Getter + private final String transcriptSid; + + @Getter + private final URI url; + + @JsonCreator + private EncryptedSentences( + @JsonProperty("location") final URI location, + @JsonProperty("transcript_sid") final String transcriptSid, + @JsonProperty("url") final URI url + ) { + this.location = location; + this.transcriptSid = transcriptSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EncryptedSentences other = (EncryptedSentences) o; + return ( + Objects.equals(location, other.location) && + Objects.equals(transcriptSid, other.transcriptSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(location, transcriptSid, url); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedSentencesFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedSentencesFetcher.java new file mode 100644 index 0000000000..2a5b62648a --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/EncryptedSentencesFetcher.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EncryptedSentencesFetcher extends Fetcher { + + private String pathTranscriptSid; + private Boolean redacted; + + public EncryptedSentencesFetcher(final String pathTranscriptSid) { + this.pathTranscriptSid = pathTranscriptSid; + } + + public EncryptedSentencesFetcher setRedacted(final Boolean redacted) { + this.redacted = redacted; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Transcripts/{TranscriptSid}/Sentences/Encrypted"; + + path = + path.replace( + "{" + "TranscriptSid" + "}", + this.pathTranscriptSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EncryptedSentences fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EncryptedSentences fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EncryptedSentences.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EncryptedSentences content = EncryptedSentences.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (redacted != null) { + Serializer.toString( + request, + "Redacted", + redacted, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/Media.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/Media.java new file mode 100644 index 0000000000..3fd0bbeb1b --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/Media.java @@ -0,0 +1,155 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Media extends Resource { + + public static MediaFetcher fetcher(final String pathSid) { + return new MediaFetcher(pathSid); + } + + /** + * Converts a JSON String into a Media object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Media object represented by the provided JSON + */ + public static Media fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Media.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Media object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Media object represented by the provided JSON + */ + public static Media fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Media.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final URI mediaUrl; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Media( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("media_url") final URI mediaUrl, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.mediaUrl = mediaUrl; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Media other = (Media) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(mediaUrl, other.mediaUrl) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, mediaUrl, serviceSid, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/MediaFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/MediaFetcher.java new file mode 100644 index 0000000000..cd9b41ff4c --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/MediaFetcher.java @@ -0,0 +1,113 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MediaFetcher extends Fetcher { + + private String pathSid; + private Boolean redacted; + + public MediaFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + public MediaFetcher setRedacted(final Boolean redacted) { + this.redacted = redacted; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Transcripts/{Sid}/Media"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Media fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Media fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Media.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Media content = Media.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (redacted != null) { + Serializer.toString( + request, + "Redacted", + redacted, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResult.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResult.java new file mode 100644 index 0000000000..a3e1cb2a2a --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResult.java @@ -0,0 +1,284 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class OperatorResult extends Resource { + + public static OperatorResultFetcher fetcher( + final String pathTranscriptSid, + final String pathOperatorSid + ) { + return new OperatorResultFetcher(pathTranscriptSid, pathOperatorSid); + } + + public static OperatorResultReader reader(final String pathTranscriptSid) { + return new OperatorResultReader(pathTranscriptSid); + } + + public enum OperatorType { + CONVERSATION_CLASSIFY("conversation-classify"), + UTTERANCE_CLASSIFY("utterance-classify"), + EXTRACT("extract"), + EXTRACT_NORMALIZE("extract-normalize"), + PII_EXTRACT("pii-extract"), + TEXT_GENERATION("text-generation"), + JSON("json"); + + private final String value; + + private OperatorType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OperatorType forValue(final String value) { + return Promoter.enumFromString(value, OperatorType.values()); + } + } + + /** + * Converts a JSON String into a OperatorResult object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OperatorResult object represented by the provided JSON + */ + public static OperatorResult fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorResult.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a OperatorResult object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OperatorResult object represented by the provided JSON + */ + public static OperatorResult fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorResult.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean extractMatch; + + @Getter + private final Object extractResults; + + @Getter + private final Object jsonResults; + + @Getter + private final Object labelProbabilities; + + @Getter + private final BigDecimal matchProbability; + + @Getter + private final String name; + + @Getter + private final String normalizedResult; + + @Getter + private final String operatorSid; + + @Getter + private final OperatorResult.OperatorType operatorType; + + @Getter + private final String predictedLabel; + + @Getter + private final BigDecimal predictedProbability; + + @Getter + private final Object textGenerationResults; + + @Getter + private final String transcriptSid; + + @Getter + private final URI url; + + @Getter + private final Boolean utteranceMatch; + + @Getter + private final List utteranceResults; + + @JsonCreator + private OperatorResult( + @JsonProperty("extract_match") final Boolean extractMatch, + @JsonProperty("extract_results") final Object extractResults, + @JsonProperty("json_results") final Object jsonResults, + @JsonProperty("label_probabilities") final Object labelProbabilities, + @JsonProperty("match_probability") final BigDecimal matchProbability, + @JsonProperty("name") final String name, + @JsonProperty("normalized_result") final String normalizedResult, + @JsonProperty("operator_sid") final String operatorSid, + @JsonProperty( + "operator_type" + ) final OperatorResult.OperatorType operatorType, + @JsonProperty("predicted_label") final String predictedLabel, + @JsonProperty( + "predicted_probability" + ) final BigDecimal predictedProbability, + @JsonProperty( + "text_generation_results" + ) final Object textGenerationResults, + @JsonProperty("transcript_sid") final String transcriptSid, + @JsonProperty("url") final URI url, + @JsonProperty("utterance_match") final Boolean utteranceMatch, + @JsonProperty("utterance_results") final List utteranceResults + ) { + this.extractMatch = extractMatch; + this.extractResults = extractResults; + this.jsonResults = jsonResults; + this.labelProbabilities = labelProbabilities; + this.matchProbability = matchProbability; + this.name = name; + this.normalizedResult = normalizedResult; + this.operatorSid = operatorSid; + this.operatorType = operatorType; + this.predictedLabel = predictedLabel; + this.predictedProbability = predictedProbability; + this.textGenerationResults = textGenerationResults; + this.transcriptSid = transcriptSid; + this.url = url; + this.utteranceMatch = utteranceMatch; + this.utteranceResults = utteranceResults; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorResult other = (OperatorResult) o; + return ( + Objects.equals(extractMatch, other.extractMatch) && + Objects.equals(extractResults, other.extractResults) && + Objects.equals(jsonResults, other.jsonResults) && + Objects.equals(labelProbabilities, other.labelProbabilities) && + Objects.equals(matchProbability, other.matchProbability) && + Objects.equals(name, other.name) && + Objects.equals(normalizedResult, other.normalizedResult) && + Objects.equals(operatorSid, other.operatorSid) && + Objects.equals(operatorType, other.operatorType) && + Objects.equals(predictedLabel, other.predictedLabel) && + Objects.equals(predictedProbability, other.predictedProbability) && + Objects.equals( + textGenerationResults, + other.textGenerationResults + ) && + Objects.equals(transcriptSid, other.transcriptSid) && + Objects.equals(url, other.url) && + Objects.equals(utteranceMatch, other.utteranceMatch) && + Objects.equals(utteranceResults, other.utteranceResults) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + extractMatch, + extractResults, + jsonResults, + labelProbabilities, + matchProbability, + name, + normalizedResult, + operatorSid, + operatorType, + predictedLabel, + predictedProbability, + textGenerationResults, + transcriptSid, + url, + utteranceMatch, + utteranceResults + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultFetcher.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultFetcher.java new file mode 100644 index 0000000000..bf8d8da526 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultFetcher.java @@ -0,0 +1,131 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorResultFetcher extends Fetcher { + + private String pathTranscriptSid; + private String pathOperatorSid; + private Boolean redacted; + + public OperatorResultFetcher( + final String pathTranscriptSid, + final String pathOperatorSid + ) { + this.pathTranscriptSid = pathTranscriptSid; + this.pathOperatorSid = pathOperatorSid; + } + + public OperatorResultFetcher setRedacted(final Boolean redacted) { + this.redacted = redacted; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Transcripts/{TranscriptSid}/OperatorResults/{OperatorSid}"; + + path = + path.replace( + "{" + "TranscriptSid" + "}", + this.pathTranscriptSid.toString() + ); + path = + path.replace( + "{" + "OperatorSid" + "}", + this.pathOperatorSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OperatorResult fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public OperatorResult fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return OperatorResult.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OperatorResult content = OperatorResult.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (redacted != null) { + Serializer.toString( + request, + "Redacted", + redacted, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultReader.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultReader.java new file mode 100644 index 0000000000..e1e5daf08f --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/OperatorResultReader.java @@ -0,0 +1,226 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorResultReader extends Reader { + + private String pathTranscriptSid; + private Boolean redacted; + private Long pageSize; + + public OperatorResultReader(final String pathTranscriptSid) { + this.pathTranscriptSid = pathTranscriptSid; + } + + public OperatorResultReader setRedacted(final Boolean redacted) { + this.redacted = redacted; + return this; + } + + public OperatorResultReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operator_results", + response.getContent(), + OperatorResult.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Transcripts/{TranscriptSid}/OperatorResults"; + + path = + path.replace( + "{" + "TranscriptSid" + "}", + this.pathTranscriptSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "operator_results", + response.getContent(), + OperatorResult.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "OperatorResult read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "operator_results", + response.getContent(), + OperatorResult.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (redacted != null) { + Serializer.toString( + request, + "Redacted", + redacted, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/Sentence.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/Sentence.java new file mode 100644 index 0000000000..7d59e0052d --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/Sentence.java @@ -0,0 +1,182 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Sentence extends Resource { + + public static SentenceReader reader(final String pathTranscriptSid) { + return new SentenceReader(pathTranscriptSid); + } + + /** + * Converts a JSON String into a Sentence object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sentence object represented by the provided JSON + */ + public static Sentence fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Sentence.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Sentence object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sentence object represented by the provided JSON + */ + public static Sentence fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Sentence.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String confidence; + + @Getter + private final String endTime; + + @Getter + private final Integer mediaChannel; + + @Getter + private final Integer sentenceIndex; + + @Getter + private final String sid; + + @Getter + private final String startTime; + + @Getter + private final String transcript; + + @Getter + private final List words; + + @JsonCreator + private Sentence( + @JsonProperty("confidence") final String confidence, + @JsonProperty("end_time") final String endTime, + @JsonProperty("media_channel") final Integer mediaChannel, + @JsonProperty("sentence_index") final Integer sentenceIndex, + @JsonProperty("sid") final String sid, + @JsonProperty("start_time") final String startTime, + @JsonProperty("transcript") final String transcript, + @JsonProperty("words") final List words + ) { + this.confidence = confidence; + this.endTime = endTime; + this.mediaChannel = mediaChannel; + this.sentenceIndex = sentenceIndex; + this.sid = sid; + this.startTime = startTime; + this.transcript = transcript; + this.words = words; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Sentence other = (Sentence) o; + return ( + Objects.equals(confidence, other.confidence) && + Objects.equals(endTime, other.endTime) && + Objects.equals(mediaChannel, other.mediaChannel) && + Objects.equals(sentenceIndex, other.sentenceIndex) && + Objects.equals(sid, other.sid) && + Objects.equals(startTime, other.startTime) && + Objects.equals(transcript, other.transcript) && + Objects.equals(words, other.words) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + confidence, + endTime, + mediaChannel, + sentenceIndex, + sid, + startTime, + transcript, + words + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v2/transcript/SentenceReader.java b/src/main/java/com/twilio/rest/intelligence/v2/transcript/SentenceReader.java new file mode 100644 index 0000000000..43d3335063 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v2/transcript/SentenceReader.java @@ -0,0 +1,241 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Intelligence + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v2.transcript; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SentenceReader extends Reader { + + private String pathTranscriptSid; + private Boolean redacted; + private Boolean wordTimestamps; + private Long pageSize; + + public SentenceReader(final String pathTranscriptSid) { + this.pathTranscriptSid = pathTranscriptSid; + } + + public SentenceReader setRedacted(final Boolean redacted) { + this.redacted = redacted; + return this; + } + + public SentenceReader setWordTimestamps(final Boolean wordTimestamps) { + this.wordTimestamps = wordTimestamps; + return this; + } + + public SentenceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sentences", + response.getContent(), + Sentence.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Transcripts/{TranscriptSid}/Sentences"; + + path = + path.replace( + "{" + "TranscriptSid" + "}", + this.pathTranscriptSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sentences", + response.getContent(), + Sentence.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Sentence read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "sentences", + response.getContent(), + Sentence.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (redacted != null) { + Serializer.toString( + request, + "Redacted", + redacted, + ParameterType.QUERY + ); + } + + if (wordTimestamps != null) { + Serializer.toString( + request, + "WordTimestamps", + wordTimestamps, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/Configuration.java b/src/main/java/com/twilio/rest/intelligence/v3/Configuration.java new file mode 100644 index 0000000000..a4c3e45c22 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/Configuration.java @@ -0,0 +1,2141 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Configuration extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateConfigurationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final List rules; + + @Getter + private final Integer version; + + @JsonCreator + private CreateConfigurationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("rules") final List rules, + @JsonProperty("version") final Integer version + ) { + this.accountId = accountId; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.displayName = displayName; + this.id = id; + this.rules = rules; + this.version = version; + } + + public static CreateConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateConfigurationResponse other = (CreateConfigurationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(rules, other.rules) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + dateCreated, + dateUpdated, + description, + displayName, + id, + rules, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateConfigurationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final List rules; + + @Getter + private final Integer version; + + @JsonCreator + private UpdateConfigurationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("rules") final List rules, + @JsonProperty("version") final Integer version + ) { + this.accountId = accountId; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.displayName = displayName; + this.id = id; + this.rules = rules; + this.version = version; + } + + public static UpdateConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateConfigurationResponse other = (UpdateConfigurationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(rules, other.rules) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + dateCreated, + dateUpdated, + description, + displayName, + id, + rules, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteConfigurationResponse extends Resource { + + @JsonCreator + private DeleteConfigurationResponse() {} + + public static DeleteConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteConfigurationResponse other = (DeleteConfigurationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListConfigurationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final List rules; + + @Getter + private final Integer version; + + @JsonCreator + private ListConfigurationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("rules") final List rules, + @JsonProperty("version") final Integer version + ) { + this.accountId = accountId; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.displayName = displayName; + this.id = id; + this.rules = rules; + this.version = version; + } + + public static ListConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListConfigurationResponse other = (ListConfigurationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(rules, other.rules) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + dateCreated, + dateUpdated, + description, + displayName, + id, + rules, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchConfigurationResponse extends Resource { + + @JsonCreator + private PatchConfigurationResponse() {} + + public static PatchConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchConfigurationResponse other = (PatchConfigurationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchConfigurationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final List rules; + + @Getter + private final Integer version; + + @JsonCreator + private FetchConfigurationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("rules") final List rules, + @JsonProperty("version") final Integer version + ) { + this.accountId = accountId; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.displayName = displayName; + this.id = id; + this.rules = rules; + this.version = version; + } + + public static FetchConfigurationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchConfigurationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchConfigurationResponse other = (FetchConfigurationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(rules, other.rules) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + dateCreated, + dateUpdated, + description, + displayName, + id, + rules, + version + ); + } + } + + public static ConfigurationCreator creator( + final Configuration.CreateConfigurationRequest createConfigurationRequest + ) { + return new ConfigurationCreator(createConfigurationRequest); + } + + public static ConfigurationDeleter deleter(final String pathId) { + return new ConfigurationDeleter(pathId); + } + + public static ConfigurationFetcher fetcher(final String pathId) { + return new ConfigurationFetcher(pathId); + } + + public static ConfigurationReader reader() { + return new ConfigurationReader(); + } + + public static ConfigurationUpdater updater( + final String pathId, + final Configuration.UpdateConfigurationRequest updateConfigurationRequest + ) { + return new ConfigurationUpdater(pathId, updateConfigurationRequest); + } + + public enum Type { + WEBHOOK("WEBHOOK"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum Method { + POST("POST"); + + private final String value; + + private Method(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Method forValue(final String value) { + return Promoter.enumFromString(value, Method.values()); + } + } + + public enum On { + COMMUNICATION("COMMUNICATION"), + CONVERSATION_END("CONVERSATION_END"), + CONVERSATION_INACTIVE("CONVERSATION_INACTIVE"); + + private final String value; + + private On(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static On forValue(final String value) { + return Promoter.enumFromString(value, On.values()); + } + } + + @JsonDeserialize(builder = Operator.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Operator { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("parameters") + @Getter + private final Object parameters; + + private Operator(Builder builder) { + this.id = builder.id; + this.version = builder.version; + this.parameters = builder.parameters; + } + + public static Builder builder(final String id) { + return new Builder(id); + } + + public static Operator fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Operator.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("version") + private Integer version; + + @JsonProperty("parameters") + private Object parameters; + + @JsonCreator + public Builder(@JsonProperty("id") final String id) { + this.id = id; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + public Builder version(Integer version) { + this.version = version; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("parameters") + public Builder parameters(Object parameters) { + this.parameters = parameters; + return this; + } + + public Operator build() { + return new Operator(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Operator other = (Operator) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(version, other.version) && + Objects.equals(parameters, other.parameters) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, version, parameters); + } + } + + @JsonDeserialize(builder = Context.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Context { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memory") + @Getter + private final ContextMemory memory; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge") + @Getter + private final ContextKnowledge knowledge; + + private Context(Builder builder) { + this.memory = builder.memory; + this.knowledge = builder.knowledge; + } + + public static Builder builder() { + return new Builder(); + } + + public static Context fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Context.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("memory") + private ContextMemory memory; + + @JsonProperty("knowledge") + private ContextKnowledge knowledge; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memory") + public Builder memory(ContextMemory memory) { + this.memory = memory; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge") + public Builder knowledge(ContextKnowledge knowledge) { + this.knowledge = knowledge; + return this; + } + + public Context build() { + return new Context(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Context other = (Context) o; + return ( + Objects.equals(memory, other.memory) && + Objects.equals(knowledge, other.knowledge) + ); + } + + @Override + public int hashCode() { + return Objects.hash(memory, knowledge); + } + } + + @JsonDeserialize(builder = Action.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Action { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Configuration.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("method") + @Getter + private final Configuration.Method method; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final URI url; + + private Action(Builder builder) { + this.type = builder.type; + this.method = builder.method; + this.url = builder.url; + } + + public static Builder builder( + final Configuration.Type type, + final Configuration.Method method, + final URI url + ) { + return new Builder(type, method, url); + } + + public static Action fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Action.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Configuration.Type type; + + @JsonProperty("method") + private Configuration.Method method; + + @JsonProperty("url") + private URI url; + + @JsonCreator + public Builder( + @JsonProperty("type") final Configuration.Type type, + @JsonProperty("method") final Configuration.Method method, + @JsonProperty("url") final URI url + ) { + this.type = type; + this.method = method; + this.url = url; + } + + public Action build() { + return new Action(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Action other = (Action) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(method, other.method) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, method, url); + } + } + + @JsonDeserialize(builder = RuleCreationRequestPayload.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class RuleCreationRequestPayload { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operators") + @Getter + private final List operators; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("triggers") + @Getter + private final List triggers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("context") + @Getter + private final Context context; + + private RuleCreationRequestPayload(Builder builder) { + this.operators = builder.operators; + this.triggers = builder.triggers; + this.actions = builder.actions; + this.context = builder.context; + } + + public static Builder builder( + final List operators, + final List actions + ) { + return new Builder(operators, actions); + } + + public static RuleCreationRequestPayload fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + RuleCreationRequestPayload.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("operators") + private List operators; + + @JsonProperty("triggers") + private List triggers; + + @JsonProperty("actions") + private List actions; + + @JsonProperty("context") + private Context context; + + @JsonCreator + public Builder( + @JsonProperty("operators") final List operators, + @JsonProperty("actions") final List actions + ) { + this.operators = operators; + this.actions = actions; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("triggers") + public Builder triggers(List triggers) { + this.triggers = triggers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("context") + public Builder context(Context context) { + this.context = context; + return this; + } + + public RuleCreationRequestPayload build() { + return new RuleCreationRequestPayload(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RuleCreationRequestPayload other = (RuleCreationRequestPayload) o; + return ( + Objects.equals(operators, other.operators) && + Objects.equals(triggers, other.triggers) && + Objects.equals(actions, other.actions) && + Objects.equals(context, other.context) + ); + } + + @Override + public int hashCode() { + return Objects.hash(operators, triggers, actions, context); + } + } + + @JsonDeserialize(builder = ContextKnowledge.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ContextKnowledge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bases") + @Getter + private final List bases; + + private ContextKnowledge(Builder builder) { + this.bases = builder.bases; + } + + public static Builder builder(final List bases) { + return new Builder(bases); + } + + public static ContextKnowledge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ContextKnowledge.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("bases") + private List bases; + + @JsonCreator + public Builder(@JsonProperty("bases") final List bases) { + this.bases = bases; + } + + public ContextKnowledge build() { + return new ContextKnowledge(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContextKnowledge other = (ContextKnowledge) o; + return (Objects.equals(bases, other.bases)); + } + + @Override + public int hashCode() { + return Objects.hash(bases); + } + } + + @JsonDeserialize(builder = UpdateConfigurationRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateConfigurationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rules") + @Getter + private final List rules; + + private UpdateConfigurationRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.rules = builder.rules; + } + + public static Builder builder( + final String displayName, + final List rules + ) { + return new Builder(displayName, rules); + } + + public static UpdateConfigurationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateConfigurationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("rules") + private List rules; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName, + @JsonProperty("rules") final List< + RuleUpdateRequestPayload + > rules + ) { + this.displayName = displayName; + this.rules = rules; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public UpdateConfigurationRequest build() { + return new UpdateConfigurationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateConfigurationRequest other = (UpdateConfigurationRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(rules, other.rules) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description, rules); + } + } + + @JsonDeserialize(builder = Trigger.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Trigger { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("on") + @Getter + private final Configuration.On on; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("parameters") + @Getter + private final TriggerParameters parameters; + + private Trigger(Builder builder) { + this.on = builder.on; + this.parameters = builder.parameters; + } + + public static Builder builder(final Configuration.On on) { + return new Builder(on); + } + + public static Trigger fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Trigger.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("on") + private Configuration.On on; + + @JsonProperty("parameters") + private TriggerParameters parameters; + + @JsonCreator + public Builder(@JsonProperty("on") final Configuration.On on) { + this.on = on; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("parameters") + public Builder parameters(TriggerParameters parameters) { + this.parameters = parameters; + return this; + } + + public Trigger build() { + return new Trigger(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Trigger other = (Trigger) o; + return ( + Objects.equals(on, other.on) && + Objects.equals(parameters, other.parameters) + ); + } + + @Override + public int hashCode() { + return Objects.hash(on, parameters); + } + } + + @JsonDeserialize(builder = ContextMemory.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ContextMemory { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + @Getter + private final Boolean enabled; + + private ContextMemory(Builder builder) { + this.enabled = builder.enabled; + } + + public static Builder builder() { + return new Builder(); + } + + public static ContextMemory fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ContextMemory.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("enabled") + private Boolean enabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + public Builder enabled(Boolean enabled) { + this.enabled = enabled; + return this; + } + + public ContextMemory build() { + return new ContextMemory(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ContextMemory other = (ContextMemory) o; + return (Objects.equals(enabled, other.enabled)); + } + + @Override + public int hashCode() { + return Objects.hash(enabled); + } + } + + @JsonDeserialize(builder = ListConfigurations200ResponseMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListConfigurations200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListConfigurations200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static ListConfigurations200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListConfigurations200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListConfigurations200ResponseMeta build() { + return new ListConfigurations200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListConfigurations200ResponseMeta other = + (ListConfigurations200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize(builder = CreateConfigurationRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateConfigurationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rules") + @Getter + private final List rules; + + private CreateConfigurationRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.rules = builder.rules; + } + + public static Builder builder( + final String displayName, + final List rules + ) { + return new Builder(displayName, rules); + } + + public static CreateConfigurationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateConfigurationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("rules") + private List rules; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName, + @JsonProperty("rules") final List< + RuleCreationRequestPayload + > rules + ) { + this.displayName = displayName; + this.rules = rules; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public CreateConfigurationRequest build() { + return new CreateConfigurationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateConfigurationRequest other = (CreateConfigurationRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(rules, other.rules) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description, rules); + } + } + + @JsonDeserialize(builder = TriggerParameters.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TriggerParameters { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("count") + @Getter + private final Integer count; + + private TriggerParameters(Builder builder) { + this.count = builder.count; + } + + public static Builder builder() { + return new Builder(); + } + + public static TriggerParameters fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TriggerParameters.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("count") + private Integer count; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("count") + public Builder count(Integer count) { + this.count = count; + return this; + } + + public TriggerParameters build() { + return new TriggerParameters(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TriggerParameters other = (TriggerParameters) o; + return (Objects.equals(count, other.count)); + } + + @Override + public int hashCode() { + return Objects.hash(count); + } + } + + @JsonDeserialize(builder = IntelligenceConfiguration.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IntelligenceConfiguration { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountId") + @Getter + private final String accountId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rules") + @Getter + private final List rules; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateCreated") + @Getter + private final ZonedDateTime dateCreated; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateUpdated") + @Getter + private final ZonedDateTime dateUpdated; + + private IntelligenceConfiguration(Builder builder) { + this.accountId = builder.accountId; + this.id = builder.id; + this.displayName = builder.displayName; + this.description = builder.description; + this.version = builder.version; + this.rules = builder.rules; + this.dateCreated = builder.dateCreated; + this.dateUpdated = builder.dateUpdated; + } + + public static Builder builder( + final String accountId, + final String id, + final String displayName, + final Integer version, + final List rules, + final ZonedDateTime dateCreated, + final ZonedDateTime dateUpdated + ) { + return new Builder( + accountId, + id, + displayName, + version, + rules, + dateCreated, + dateUpdated + ); + } + + public static IntelligenceConfiguration fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IntelligenceConfiguration.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("accountId") + private String accountId; + + @JsonProperty("id") + private String id; + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("version") + private Integer version; + + @JsonProperty("rules") + private List rules; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("dateCreated") + private ZonedDateTime dateCreated; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("dateUpdated") + private ZonedDateTime dateUpdated; + + @JsonCreator + public Builder( + @JsonProperty("accountId") final String accountId, + @JsonProperty("id") final String id, + @JsonProperty("displayName") final String displayName, + @JsonProperty("version") final Integer version, + @JsonProperty("rules") final List rules, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated + ) { + this.accountId = accountId; + this.id = id; + this.displayName = displayName; + this.version = version; + this.rules = rules; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public IntelligenceConfiguration build() { + return new IntelligenceConfiguration(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IntelligenceConfiguration other = (IntelligenceConfiguration) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(id, other.id) && + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(version, other.version) && + Objects.equals(rules, other.rules) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + id, + displayName, + description, + version, + rules, + dateCreated, + dateUpdated + ); + } + } + + @JsonDeserialize(builder = Rule.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Rule { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operators") + @Getter + private final List operators; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("triggers") + @Getter + private final List triggers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("context") + @Getter + private final Context context; + + private Rule(Builder builder) { + this.id = builder.id; + this.operators = builder.operators; + this.triggers = builder.triggers; + this.actions = builder.actions; + this.context = builder.context; + } + + public static Builder builder( + final String id, + final List operators, + final List triggers, + final List actions + ) { + return new Builder(id, operators, triggers, actions); + } + + public static Rule fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Rule.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("operators") + private List operators; + + @JsonProperty("triggers") + private List triggers; + + @JsonProperty("actions") + private List actions; + + @JsonProperty("context") + private Context context; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("operators") final List operators, + @JsonProperty("triggers") final List triggers, + @JsonProperty("actions") final List actions + ) { + this.id = id; + this.operators = operators; + this.triggers = triggers; + this.actions = actions; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("context") + public Builder context(Context context) { + this.context = context; + return this; + } + + public Rule build() { + return new Rule(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Rule other = (Rule) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(operators, other.operators) && + Objects.equals(triggers, other.triggers) && + Objects.equals(actions, other.actions) && + Objects.equals(context, other.context) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, operators, triggers, actions, context); + } + } + + @JsonDeserialize(builder = RuleUpdateRequestPayload.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class RuleUpdateRequestPayload { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operators") + @Getter + private final List operators; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("triggers") + @Getter + private final List triggers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("actions") + @Getter + private final List actions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("context") + @Getter + private final Context context; + + private RuleUpdateRequestPayload(Builder builder) { + this.id = builder.id; + this.operators = builder.operators; + this.triggers = builder.triggers; + this.actions = builder.actions; + this.context = builder.context; + } + + public static Builder builder( + final List operators, + final List actions + ) { + return new Builder(operators, actions); + } + + public static RuleUpdateRequestPayload fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, RuleUpdateRequestPayload.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("operators") + private List operators; + + @JsonProperty("triggers") + private List triggers; + + @JsonProperty("actions") + private List actions; + + @JsonProperty("context") + private Context context; + + @JsonCreator + public Builder( + @JsonProperty("operators") final List operators, + @JsonProperty("actions") final List actions + ) { + this.operators = operators; + this.actions = actions; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("triggers") + public Builder triggers(List triggers) { + this.triggers = triggers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("context") + public Builder context(Context context) { + this.context = context; + return this; + } + + public RuleUpdateRequestPayload build() { + return new RuleUpdateRequestPayload(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RuleUpdateRequestPayload other = (RuleUpdateRequestPayload) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(operators, other.operators) && + Objects.equals(triggers, other.triggers) && + Objects.equals(actions, other.actions) && + Objects.equals(context, other.context) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, operators, triggers, actions, context); + } + } + + /** + * Converts a JSON String into a Configuration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Configuration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Configuration object represented by the provided JSON + */ + public static Configuration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Configuration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Configuration() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationCreator.java b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationCreator.java new file mode 100644 index 0000000000..c157d3dd2f --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationCreator.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationCreator + extends Creator { + + private Configuration.CreateConfigurationRequest createConfigurationRequest; + + public ConfigurationCreator( + final Configuration.CreateConfigurationRequest createConfigurationRequest + ) { + this.createConfigurationRequest = createConfigurationRequest; + } + + public ConfigurationCreator setCreateConfigurationRequest( + final Configuration.CreateConfigurationRequest createConfigurationRequest + ) { + this.createConfigurationRequest = createConfigurationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Configurations"; + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration.CreateConfigurationResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Configuration.CreateConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Configuration.CreateConfigurationResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Configuration.CreateConfigurationResponse content = + Configuration.CreateConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createConfigurationRequest != null) { + request.setBody( + Configuration.toJson(createConfigurationRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationDeleter.java b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationDeleter.java new file mode 100644 index 0000000000..6050507c81 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ConfigurationDeleter extends Deleter { + + private String pathId; + + public ConfigurationDeleter(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Configurations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationFetcher.java b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationFetcher.java new file mode 100644 index 0000000000..f66e427f82 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationFetcher + extends Fetcher { + + private String pathId; + + public ConfigurationFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Configurations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration.FetchConfigurationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Configuration.FetchConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Configuration.FetchConfigurationResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Configuration.FetchConfigurationResponse content = + Configuration.FetchConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationReader.java b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationReader.java new file mode 100644 index 0000000000..6e2ba86362 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationReader.java @@ -0,0 +1,241 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationReader + extends Reader { + + private Integer pageSize; + private String pageToken; + + public ConfigurationReader() {} + + public ConfigurationReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ConfigurationReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse< + Configuration.ListConfigurationResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + Configuration.ListConfigurationResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Configurations"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + Configuration.ListConfigurationResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Configuration read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "items", + response.getContent(), + Configuration.ListConfigurationResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/ControlPlane/Configurations"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/ControlPlane/Configurations"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationUpdater.java b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationUpdater.java new file mode 100644 index 0000000000..af99533c73 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/ConfigurationUpdater.java @@ -0,0 +1,125 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConfigurationUpdater + extends Updater { + + private String pathId; + private Configuration.UpdateConfigurationRequest updateConfigurationRequest; + + public ConfigurationUpdater( + final String pathId, + final Configuration.UpdateConfigurationRequest updateConfigurationRequest + ) { + this.pathId = pathId; + this.updateConfigurationRequest = updateConfigurationRequest; + } + + public ConfigurationUpdater setUpdateConfigurationRequest( + final Configuration.UpdateConfigurationRequest updateConfigurationRequest + ) { + this.updateConfigurationRequest = updateConfigurationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Configurations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Configuration update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Configuration.UpdateConfigurationResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Configuration.UpdateConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Configuration.UpdateConfigurationResponse + > updateWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Configuration.UpdateConfigurationResponse content = + Configuration.UpdateConfigurationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (updateConfigurationRequest != null) { + request.setBody( + Configuration.toJson(updateConfigurationRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/Conversation.java b/src/main/java/com/twilio/rest/intelligence/v3/Conversation.java new file mode 100644 index 0000000000..56e2dffeca --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/Conversation.java @@ -0,0 +1,1399 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Conversation extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateConversationResponse extends Resource { + + @JsonCreator + private CreateConversationResponse() {} + + public static CreateConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateConversationResponse other = (CreateConversationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateConversationResponse extends Resource { + + @JsonCreator + private UpdateConversationResponse() {} + + public static UpdateConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateConversationResponse other = (UpdateConversationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteConversationResponse extends Resource { + + @JsonCreator + private DeleteConversationResponse() {} + + public static DeleteConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteConversationResponse other = (DeleteConversationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListConversationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final List channelIds; + + @Getter + private final List channels; + + @Getter + private final String conversationConfigurationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final List intelligenceConfigurationIds; + + @Getter + private final String name; + + @Getter + private final List operatorResultIds; + + @Getter + private final List participants; + + @Getter + private final Conversation.ConversationStatus status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListConversationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("channelIds") final List channelIds, + @JsonProperty("channels") final List channels, + @JsonProperty( + "conversationConfigurationId" + ) final String conversationConfigurationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("intelligenceConfigurationIds") final List< + String + > intelligenceConfigurationIds, + @JsonProperty("name") final String name, + @JsonProperty("operatorResultIds") final List< + String + > operatorResultIds, + @JsonProperty("participants") final List participants, + @JsonProperty( + "status" + ) final Conversation.ConversationStatus status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.channelIds = channelIds; + this.channels = channels; + this.conversationConfigurationId = conversationConfigurationId; + this.createdAt = createdAt; + this.id = id; + this.intelligenceConfigurationIds = intelligenceConfigurationIds; + this.name = name; + this.operatorResultIds = operatorResultIds; + this.participants = participants; + this.status = status; + this.updatedAt = updatedAt; + } + + public static ListConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListConversationResponse other = (ListConversationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(channelIds, other.channelIds) && + Objects.equals(channels, other.channels) && + Objects.equals( + conversationConfigurationId, + other.conversationConfigurationId + ) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals(name, other.name) && + Objects.equals(operatorResultIds, other.operatorResultIds) && + Objects.equals(participants, other.participants) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + channelIds, + channels, + conversationConfigurationId, + createdAt, + id, + intelligenceConfigurationIds, + name, + operatorResultIds, + participants, + status, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchConversationResponse extends Resource { + + @JsonCreator + private PatchConversationResponse() {} + + public static PatchConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchConversationResponse other = (PatchConversationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchConversationResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final List channelIds; + + @Getter + private final List channels; + + @Getter + private final List communications; + + @Getter + private final String conversationConfigurationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final List intelligenceConfigurationIds; + + @Getter + private final String name; + + @Getter + private final List operatorResultIds; + + @Getter + private final List participants; + + @Getter + private final Conversation.ConversationStatus status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchConversationResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("channelIds") final List channelIds, + @JsonProperty("channels") final List channels, + @JsonProperty("communications") final List< + Communication + > communications, + @JsonProperty( + "conversationConfigurationId" + ) final String conversationConfigurationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("intelligenceConfigurationIds") final List< + String + > intelligenceConfigurationIds, + @JsonProperty("name") final String name, + @JsonProperty("operatorResultIds") final List< + String + > operatorResultIds, + @JsonProperty("participants") final List participants, + @JsonProperty( + "status" + ) final Conversation.ConversationStatus status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.accountId = accountId; + this.channelIds = channelIds; + this.channels = channels; + this.communications = communications; + this.conversationConfigurationId = conversationConfigurationId; + this.createdAt = createdAt; + this.id = id; + this.intelligenceConfigurationIds = intelligenceConfigurationIds; + this.name = name; + this.operatorResultIds = operatorResultIds; + this.participants = participants; + this.status = status; + this.updatedAt = updatedAt; + } + + public static FetchConversationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchConversationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchConversationResponse other = (FetchConversationResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(channelIds, other.channelIds) && + Objects.equals(channels, other.channels) && + Objects.equals(communications, other.communications) && + Objects.equals( + conversationConfigurationId, + other.conversationConfigurationId + ) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals(name, other.name) && + Objects.equals(operatorResultIds, other.operatorResultIds) && + Objects.equals(participants, other.participants) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + channelIds, + channels, + communications, + conversationConfigurationId, + createdAt, + id, + intelligenceConfigurationIds, + name, + operatorResultIds, + participants, + status, + updatedAt + ); + } + } + + public static ConversationFetcher fetcher(final String pathId) { + return new ConversationFetcher(pathId); + } + + public static ConversationReader reader() { + return new ConversationReader(); + } + + public enum Status { + ACTIVE("ACTIVE"), + INACTIVE("INACTIVE"), + CLOSED("CLOSED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum ConversationChannel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + API("API"), + SYSTEM("SYSTEM"); + + private final String value; + + private ConversationChannel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationChannel forValue(final String value) { + return Promoter.enumFromString(value, ConversationChannel.values()); + } + } + + public enum Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + API("API"), + SYSTEM("SYSTEM"); + + private final String value; + + private Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Channel forValue(final String value) { + return Promoter.enumFromString(value, Channel.values()); + } + } + + public enum ConversationStatus { + ACTIVE("ACTIVE"), + INACTIVE("INACTIVE"), + CLOSED("CLOSED"); + + private final String value; + + private ConversationStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ConversationStatus forValue(final String value) { + return Promoter.enumFromString(value, ConversationStatus.values()); + } + } + + public enum Channels { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + API("API"), + SYSTEM("SYSTEM"); + + private final String value; + + private Channels(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Channels forValue(final String value) { + return Promoter.enumFromString(value, Channels.values()); + } + } + + @JsonDeserialize(builder = ConversationListItem.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ConversationListItem { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountId") + @Getter + private final String accountId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final Conversation.ConversationStatus status; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationIds") + @Getter + private final List intelligenceConfigurationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationConfigurationId") + @Getter + private final String conversationConfigurationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channels") + @Getter + private final List channels; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelIds") + @Getter + private final List channelIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participants") + @Getter + private final List participants; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operatorResultIds") + @Getter + private final List operatorResultIds; + + private ConversationListItem(Builder builder) { + this.id = builder.id; + this.accountId = builder.accountId; + this.name = builder.name; + this.status = builder.status; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.intelligenceConfigurationIds = + builder.intelligenceConfigurationIds; + this.conversationConfigurationId = + builder.conversationConfigurationId; + this.channels = builder.channels; + this.channelIds = builder.channelIds; + this.participants = builder.participants; + this.operatorResultIds = builder.operatorResultIds; + } + + public static Builder builder( + final String id, + final String accountId, + final String name, + final Conversation.ConversationStatus status, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt, + final List intelligenceConfigurationIds, + final String conversationConfigurationId, + final List channels, + final List channelIds, + final List participants, + final List operatorResultIds + ) { + return new Builder( + id, + accountId, + name, + status, + createdAt, + updatedAt, + intelligenceConfigurationIds, + conversationConfigurationId, + channels, + channelIds, + participants, + operatorResultIds + ); + } + + public static ConversationListItem fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ConversationListItem.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("accountId") + private String accountId; + + @JsonProperty("name") + private String name; + + @JsonProperty("status") + private Conversation.ConversationStatus status; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonProperty("intelligenceConfigurationIds") + private List intelligenceConfigurationIds; + + @JsonProperty("conversationConfigurationId") + private String conversationConfigurationId; + + @JsonProperty("channels") + private List channels; + + @JsonProperty("channelIds") + private List channelIds; + + @JsonProperty("participants") + private List participants; + + @JsonProperty("operatorResultIds") + private List operatorResultIds; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("accountId") final String accountId, + @JsonProperty("name") final String name, + @JsonProperty( + "status" + ) final Conversation.ConversationStatus status, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("intelligenceConfigurationIds") final List< + String + > intelligenceConfigurationIds, + @JsonProperty( + "conversationConfigurationId" + ) final String conversationConfigurationId, + @JsonProperty("channels") final List< + Conversation.Channel + > channels, + @JsonProperty("channelIds") final List channelIds, + @JsonProperty("participants") final List< + Participant + > participants, + @JsonProperty("operatorResultIds") final List< + String + > operatorResultIds + ) { + this.id = id; + this.accountId = accountId; + this.name = name; + this.status = status; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.intelligenceConfigurationIds = + intelligenceConfigurationIds; + this.conversationConfigurationId = conversationConfigurationId; + this.channels = channels; + this.channelIds = channelIds; + this.participants = participants; + this.operatorResultIds = operatorResultIds; + } + + public ConversationListItem build() { + return new ConversationListItem(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ConversationListItem other = (ConversationListItem) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(accountId, other.accountId) && + Objects.equals(name, other.name) && + Objects.equals(status, other.status) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals( + intelligenceConfigurationIds, + other.intelligenceConfigurationIds + ) && + Objects.equals( + conversationConfigurationId, + other.conversationConfigurationId + ) && + Objects.equals(channels, other.channels) && + Objects.equals(channelIds, other.channelIds) && + Objects.equals(participants, other.participants) && + Objects.equals(operatorResultIds, other.operatorResultIds) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + accountId, + name, + status, + createdAt, + updatedAt, + intelligenceConfigurationIds, + conversationConfigurationId, + channels, + channelIds, + participants, + operatorResultIds + ); + } + } + + @JsonDeserialize(builder = ListOperators200ResponseMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListOperators200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListOperators200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static ListOperators200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListOperators200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListOperators200ResponseMeta build() { + return new ListOperators200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListOperators200ResponseMeta other = + (ListOperators200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize(builder = Participant.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Participant { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("addressValues") + @Getter + private final List addressValues; + + private Participant(Builder builder) { + this.id = builder.id; + this.name = builder.name; + this.type = builder.type; + this.addressValues = builder.addressValues; + } + + public static Builder builder( + final String id, + final List addressValues + ) { + return new Builder(id, addressValues); + } + + public static Participant fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, Participant.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private String type; + + @JsonProperty("addressValues") + private List addressValues; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("addressValues") final List addressValues + ) { + this.id = id; + this.addressValues = addressValues; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + public Participant build() { + return new Participant(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Participant other = (Participant) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(type, other.type) && + Objects.equals(addressValues, other.addressValues) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, type, addressValues); + } + } + + @JsonDeserialize(builder = Content.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Content { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + @Getter + private final String text; + + private Content(Builder builder) { + this.text = builder.text; + } + + public static Builder builder() { + return new Builder(); + } + + public static Content fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Content.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("text") + private String text; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + public Builder text(String text) { + this.text = text; + return this; + } + + public Content build() { + return new Content(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Content other = (Content) o; + return (Objects.equals(text, other.text)); + } + + @Override + public int hashCode() { + return Objects.hash(text); + } + } + + @JsonDeserialize(builder = Communication.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Communication { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participantId") + @Getter + private final String participantId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final Content content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + private Communication(Builder builder) { + this.id = builder.id; + this.participantId = builder.participantId; + this.content = builder.content; + this.createdAt = builder.createdAt; + } + + public static Builder builder( + final String id, + final String participantId, + final Content content, + final ZonedDateTime createdAt + ) { + return new Builder(id, participantId, content, createdAt); + } + + public static Communication fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, Communication.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("participantId") + private String participantId; + + @JsonProperty("content") + private Content content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("participantId") final String participantId, + @JsonProperty("content") final Content content, + @JsonProperty("createdAt") final ZonedDateTime createdAt + ) { + this.id = id; + this.participantId = participantId; + this.content = content; + this.createdAt = createdAt; + } + + public Communication build() { + return new Communication(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Communication other = (Communication) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(participantId, other.participantId) && + Objects.equals(content, other.content) && + Objects.equals(createdAt, other.createdAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, participantId, content, createdAt); + } + } + + /** + * Converts a JSON String into a Conversation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Conversation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Conversation object represented by the provided JSON + */ + public static Conversation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Conversation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Conversation() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/ConversationFetcher.java b/src/main/java/com/twilio/rest/intelligence/v3/ConversationFetcher.java new file mode 100644 index 0000000000..86e1f336e3 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/ConversationFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationFetcher + extends Fetcher { + + private String pathId; + + public ConversationFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/Conversations/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Conversation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Conversation.FetchConversationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Conversation.FetchConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Conversation.FetchConversationResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Conversation.FetchConversationResponse content = + Conversation.FetchConversationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/ConversationReader.java b/src/main/java/com/twilio/rest/intelligence/v3/ConversationReader.java new file mode 100644 index 0000000000..ebf557031a --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/ConversationReader.java @@ -0,0 +1,393 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; + +public class ConversationReader + extends Reader { + + private Integer pageSize; + private String pageToken; + private ZonedDateTime createdAtBefore; + private ZonedDateTime createdAtAfter; + private Conversation.Status status; + private String channelId; + private List channels; + private String conversationConfigurationId; + private List intelligenceConfigurationIds; + private List operatorIds; + + public ConversationReader() {} + + public ConversationReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ConversationReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ConversationReader setCreatedAtBefore( + final ZonedDateTime createdAtBefore + ) { + this.createdAtBefore = createdAtBefore; + return this; + } + + public ConversationReader setCreatedAtAfter( + final ZonedDateTime createdAtAfter + ) { + this.createdAtAfter = createdAtAfter; + return this; + } + + public ConversationReader setStatus(final Conversation.Status status) { + this.status = status; + return this; + } + + public ConversationReader setChannelId(final String channelId) { + this.channelId = channelId; + return this; + } + + public ConversationReader setChannels( + final List channels + ) { + this.channels = channels; + return this; + } + + public ConversationReader setChannels( + final Conversation.Channels channels + ) { + return setChannels(Promoter.listOfOne(channels)); + } + + public ConversationReader setConversationConfigurationId( + final String conversationConfigurationId + ) { + this.conversationConfigurationId = conversationConfigurationId; + return this; + } + + public ConversationReader setIntelligenceConfigurationIds( + final List intelligenceConfigurationIds + ) { + this.intelligenceConfigurationIds = intelligenceConfigurationIds; + return this; + } + + public ConversationReader setIntelligenceConfigurationIds( + final String intelligenceConfigurationIds + ) { + return setIntelligenceConfigurationIds( + Promoter.listOfOne(intelligenceConfigurationIds) + ); + } + + public ConversationReader setOperatorIds(final List operatorIds) { + this.operatorIds = operatorIds; + return this; + } + + public ConversationReader setOperatorIds(final String operatorIds) { + return setOperatorIds(Promoter.listOfOne(operatorIds)); + } + + public ResourceSetResponse< + Conversation.ListConversationResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + Conversation.ListConversationResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v3/Conversations"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + Conversation.ListConversationResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Conversation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "items", + response.getContent(), + Conversation.ListConversationResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/Conversations"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/Conversations"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (createdAtBefore != null) { + Serializer.toString( + request, + "createdAtBefore", + createdAtBefore, + ParameterType.QUERY + ); + } + + if (createdAtAfter != null) { + Serializer.toString( + request, + "createdAtAfter", + createdAtAfter, + ParameterType.QUERY + ); + } + + if (status != null) { + Serializer.toString(request, "status", status, ParameterType.QUERY); + } + + if (channelId != null) { + Serializer.toString( + request, + "channelId", + channelId, + ParameterType.QUERY + ); + } + + if (channels != null) { + for (Conversation.Channels param : channels) { + Serializer.toString( + request, + "channels", + param, + ParameterType.QUERY + ); + } + } + + if (conversationConfigurationId != null) { + Serializer.toString( + request, + "conversationConfigurationId", + conversationConfigurationId, + ParameterType.QUERY + ); + } + + if (intelligenceConfigurationIds != null) { + for (String param : intelligenceConfigurationIds) { + Serializer.toString( + request, + "intelligenceConfigurationIds", + param, + ParameterType.QUERY + ); + } + } + + if (operatorIds != null) { + for (String param : operatorIds) { + Serializer.toString( + request, + "operatorIds", + param, + ParameterType.QUERY + ); + } + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/Operator.java b/src/main/java/com/twilio/rest/intelligence/v3/Operator.java new file mode 100644 index 0000000000..f8a67bc495 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/Operator.java @@ -0,0 +1,1596 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Operator extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateOperatorResponse extends Resource { + + @Getter + private final Operator.OperatorAuthorEnum author; + + @Getter + private final OperatorContext context; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final Operator.OperatorOutputFormat outputFormat; + + @Getter + private final Object outputSchema; + + @Getter + private final Map parameters; + + @Getter + private final String prompt; + + @Getter + private final List trainingExamples; + + @Getter + private final Integer version; + + @JsonCreator + private CreateOperatorResponse( + @JsonProperty("author") final Operator.OperatorAuthorEnum author, + @JsonProperty("context") final OperatorContext context, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty( + "outputFormat" + ) final Operator.OperatorOutputFormat outputFormat, + @JsonProperty("outputSchema") final Object outputSchema, + @JsonProperty("parameters") final Map< + String, + OperatorParameter + > parameters, + @JsonProperty("prompt") final String prompt, + @JsonProperty("trainingExamples") final List< + OperatorTrainingExample + > trainingExamples, + @JsonProperty("version") final Integer version + ) { + this.author = author; + this.context = context; + this.description = description; + this.displayName = displayName; + this.id = id; + this.outputFormat = outputFormat; + this.outputSchema = outputSchema; + this.parameters = parameters; + this.prompt = prompt; + this.trainingExamples = trainingExamples; + this.version = version; + } + + public static CreateOperatorResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateOperatorResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateOperatorResponse other = (CreateOperatorResponse) o; + return ( + Objects.equals(author, other.author) && + Objects.equals(context, other.context) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(outputSchema, other.outputSchema) && + Objects.equals(parameters, other.parameters) && + Objects.equals(prompt, other.prompt) && + Objects.equals(trainingExamples, other.trainingExamples) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + author, + context, + description, + displayName, + id, + outputFormat, + outputSchema, + parameters, + prompt, + trainingExamples, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateOperatorResponse extends Resource { + + @Getter + private final Operator.OperatorAuthorEnum author; + + @Getter + private final OperatorContext context; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final Operator.OperatorOutputFormat outputFormat; + + @Getter + private final Object outputSchema; + + @Getter + private final Map parameters; + + @Getter + private final String prompt; + + @Getter + private final List trainingExamples; + + @Getter + private final Integer version; + + @JsonCreator + private UpdateOperatorResponse( + @JsonProperty("author") final Operator.OperatorAuthorEnum author, + @JsonProperty("context") final OperatorContext context, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty( + "outputFormat" + ) final Operator.OperatorOutputFormat outputFormat, + @JsonProperty("outputSchema") final Object outputSchema, + @JsonProperty("parameters") final Map< + String, + OperatorParameter + > parameters, + @JsonProperty("prompt") final String prompt, + @JsonProperty("trainingExamples") final List< + OperatorTrainingExample + > trainingExamples, + @JsonProperty("version") final Integer version + ) { + this.author = author; + this.context = context; + this.description = description; + this.displayName = displayName; + this.id = id; + this.outputFormat = outputFormat; + this.outputSchema = outputSchema; + this.parameters = parameters; + this.prompt = prompt; + this.trainingExamples = trainingExamples; + this.version = version; + } + + public static UpdateOperatorResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateOperatorResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateOperatorResponse other = (UpdateOperatorResponse) o; + return ( + Objects.equals(author, other.author) && + Objects.equals(context, other.context) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(outputSchema, other.outputSchema) && + Objects.equals(parameters, other.parameters) && + Objects.equals(prompt, other.prompt) && + Objects.equals(trainingExamples, other.trainingExamples) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + author, + context, + description, + displayName, + id, + outputFormat, + outputSchema, + parameters, + prompt, + trainingExamples, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteOperatorResponse extends Resource { + + @JsonCreator + private DeleteOperatorResponse() {} + + public static DeleteOperatorResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteOperatorResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteOperatorResponse other = (DeleteOperatorResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListOperatorResponse extends Resource { + + @Getter + private final Operator.OperatorAuthorEnum author; + + @Getter + private final OperatorContext context; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final Operator.OperatorOutputFormat outputFormat; + + @Getter + private final Object outputSchema; + + @Getter + private final Map parameters; + + @Getter + private final String prompt; + + @Getter + private final List trainingExamples; + + @Getter + private final Integer version; + + @JsonCreator + private ListOperatorResponse( + @JsonProperty("author") final Operator.OperatorAuthorEnum author, + @JsonProperty("context") final OperatorContext context, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty( + "outputFormat" + ) final Operator.OperatorOutputFormat outputFormat, + @JsonProperty("outputSchema") final Object outputSchema, + @JsonProperty("parameters") final Map< + String, + OperatorParameter + > parameters, + @JsonProperty("prompt") final String prompt, + @JsonProperty("trainingExamples") final List< + OperatorTrainingExample + > trainingExamples, + @JsonProperty("version") final Integer version + ) { + this.author = author; + this.context = context; + this.description = description; + this.displayName = displayName; + this.id = id; + this.outputFormat = outputFormat; + this.outputSchema = outputSchema; + this.parameters = parameters; + this.prompt = prompt; + this.trainingExamples = trainingExamples; + this.version = version; + } + + public static ListOperatorResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListOperatorResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListOperatorResponse other = (ListOperatorResponse) o; + return ( + Objects.equals(author, other.author) && + Objects.equals(context, other.context) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(outputSchema, other.outputSchema) && + Objects.equals(parameters, other.parameters) && + Objects.equals(prompt, other.prompt) && + Objects.equals(trainingExamples, other.trainingExamples) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + author, + context, + description, + displayName, + id, + outputFormat, + outputSchema, + parameters, + prompt, + trainingExamples, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchOperatorResponse extends Resource { + + @JsonCreator + private PatchOperatorResponse() {} + + public static PatchOperatorResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchOperatorResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchOperatorResponse other = (PatchOperatorResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchOperatorResponse extends Resource { + + @Getter + private final Operator.OperatorAuthorEnum author; + + @Getter + private final OperatorContext context; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final Operator.OperatorOutputFormat outputFormat; + + @Getter + private final Object outputSchema; + + @Getter + private final Map parameters; + + @Getter + private final String prompt; + + @Getter + private final List trainingExamples; + + @Getter + private final Integer version; + + @JsonCreator + private FetchOperatorResponse( + @JsonProperty("author") final Operator.OperatorAuthorEnum author, + @JsonProperty("context") final OperatorContext context, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty( + "outputFormat" + ) final Operator.OperatorOutputFormat outputFormat, + @JsonProperty("outputSchema") final Object outputSchema, + @JsonProperty("parameters") final Map< + String, + OperatorParameter + > parameters, + @JsonProperty("prompt") final String prompt, + @JsonProperty("trainingExamples") final List< + OperatorTrainingExample + > trainingExamples, + @JsonProperty("version") final Integer version + ) { + this.author = author; + this.context = context; + this.description = description; + this.displayName = displayName; + this.id = id; + this.outputFormat = outputFormat; + this.outputSchema = outputSchema; + this.parameters = parameters; + this.prompt = prompt; + this.trainingExamples = trainingExamples; + this.version = version; + } + + public static FetchOperatorResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchOperatorResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchOperatorResponse other = (FetchOperatorResponse) o; + return ( + Objects.equals(author, other.author) && + Objects.equals(context, other.context) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(outputSchema, other.outputSchema) && + Objects.equals(parameters, other.parameters) && + Objects.equals(prompt, other.prompt) && + Objects.equals(trainingExamples, other.trainingExamples) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + author, + context, + description, + displayName, + id, + outputFormat, + outputSchema, + parameters, + prompt, + trainingExamples, + version + ); + } + } + + public static OperatorCreator creator( + final Operator.LanguageOperator languageOperator + ) { + return new OperatorCreator(languageOperator); + } + + public static OperatorDeleter deleter(final String pathId) { + return new OperatorDeleter(pathId); + } + + public static OperatorFetcher fetcher(final String pathId) { + return new OperatorFetcher(pathId); + } + + public static OperatorReader reader() { + return new OperatorReader(); + } + + public static OperatorUpdater updater( + final String pathId, + final Operator.LanguageOperator languageOperator + ) { + return new OperatorUpdater(pathId, languageOperator); + } + + public enum Type { + STRING("STRING"), + INTEGER("INTEGER"), + NUMBER("NUMBER"), + BOOLEAN("BOOLEAN"), + KNOWLEDGE_BASE_AND_SOURCE_IDS("KNOWLEDGE_BASE_AND_SOURCE_IDS"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum OperatorOutputFormat { + TEXT("TEXT"), + JSON("JSON"), + CLASSIFICATION("CLASSIFICATION"); + + private final String value; + + private OperatorOutputFormat(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OperatorOutputFormat forValue(final String value) { + return Promoter.enumFromString( + value, + OperatorOutputFormat.values() + ); + } + } + + public enum OperatorAuthorEnum { + SELF("SELF"), + TWILIO("TWILIO"); + + private final String value; + + private OperatorAuthorEnum(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OperatorAuthorEnum forValue(final String value) { + return Promoter.enumFromString(value, OperatorAuthorEnum.values()); + } + } + + @JsonDeserialize(builder = OperatorParameter.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorParameter { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Operator.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("default") + @Getter + private final Object _default; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("required") + @Getter + private final Boolean required; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + private OperatorParameter(Builder builder) { + this.type = builder.type; + this._default = builder._default; + this.required = builder.required; + this.description = builder.description; + } + + public static Builder builder(final Operator.Type type) { + return new Builder(type); + } + + public static OperatorParameter fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorParameter.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Operator.Type type; + + @JsonProperty("default") + private Object _default; + + @JsonProperty("required") + private Boolean required; + + @JsonProperty("description") + private String description; + + @JsonCreator + public Builder(@JsonProperty("type") final Operator.Type type) { + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("default") + public Builder _default(Object _default) { + this._default = _default; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("required") + public Builder required(Boolean required) { + this.required = required; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public OperatorParameter build() { + return new OperatorParameter(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorParameter other = (OperatorParameter) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(_default, other._default) && + Objects.equals(required, other.required) && + Objects.equals(description, other.description) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, _default, required, description); + } + } + + @JsonDeserialize(builder = LanguageOperator.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LanguageOperator { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("author") + @Getter + private final Operator.OperatorAuthorEnum author; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("prompt") + @Getter + private final String prompt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outputFormat") + @Getter + private final Operator.OperatorOutputFormat outputFormat; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outputSchema") + @Getter + private final Object outputSchema; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("trainingExamples") + @Getter + private final List trainingExamples; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("context") + @Getter + private final OperatorContext context; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("parameters") + @Getter + private final Map parameters; + + private LanguageOperator(Builder builder) { + this.id = builder.id; + this.displayName = builder.displayName; + this.description = builder.description; + this.version = builder.version; + this.author = builder.author; + this.prompt = builder.prompt; + this.outputFormat = builder.outputFormat; + this.outputSchema = builder.outputSchema; + this.trainingExamples = builder.trainingExamples; + this.context = builder.context; + this.parameters = builder.parameters; + } + + public static Builder builder() { + return new Builder(); + } + + public static LanguageOperator fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LanguageOperator.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("version") + private Integer version; + + @JsonProperty("author") + private Operator.OperatorAuthorEnum author; + + @JsonProperty("prompt") + private String prompt; + + @JsonProperty("outputFormat") + private Operator.OperatorOutputFormat outputFormat; + + @JsonProperty("outputSchema") + private Object outputSchema; + + @JsonProperty("trainingExamples") + private List trainingExamples; + + @JsonProperty("context") + private OperatorContext context; + + @JsonProperty("parameters") + private Map parameters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + public Builder version(Integer version) { + this.version = version; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("author") + public Builder author(Operator.OperatorAuthorEnum author) { + this.author = author; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("prompt") + public Builder prompt(String prompt) { + this.prompt = prompt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outputFormat") + public Builder outputFormat( + Operator.OperatorOutputFormat outputFormat + ) { + this.outputFormat = outputFormat; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outputSchema") + public Builder outputSchema(Object outputSchema) { + this.outputSchema = outputSchema; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("trainingExamples") + public Builder trainingExamples( + List trainingExamples + ) { + this.trainingExamples = trainingExamples; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("context") + public Builder context(OperatorContext context) { + this.context = context; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("parameters") + public Builder parameters( + Map parameters + ) { + this.parameters = parameters; + return this; + } + + public LanguageOperator build() { + return new LanguageOperator(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LanguageOperator other = (LanguageOperator) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(version, other.version) && + Objects.equals(author, other.author) && + Objects.equals(prompt, other.prompt) && + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(outputSchema, other.outputSchema) && + Objects.equals(trainingExamples, other.trainingExamples) && + Objects.equals(context, other.context) && + Objects.equals(parameters, other.parameters) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + displayName, + description, + version, + author, + prompt, + outputFormat, + outputSchema, + trainingExamples, + context, + parameters + ); + } + } + + @JsonDeserialize(builder = ListOperators200ResponseMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListOperators200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListOperators200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static ListOperators200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListOperators200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListOperators200ResponseMeta build() { + return new ListOperators200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListOperators200ResponseMeta other = + (ListOperators200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize(builder = OperatorContext.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorContext { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memory") + @Getter + private final OperatorContextMemory memory; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge") + @Getter + private final OperatorContextKnowledge knowledge; + + private OperatorContext(Builder builder) { + this.memory = builder.memory; + this.knowledge = builder.knowledge; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperatorContext fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorContext.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("memory") + private OperatorContextMemory memory; + + @JsonProperty("knowledge") + private OperatorContextKnowledge knowledge; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memory") + public Builder memory(OperatorContextMemory memory) { + this.memory = memory; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge") + public Builder knowledge(OperatorContextKnowledge knowledge) { + this.knowledge = knowledge; + return this; + } + + public OperatorContext build() { + return new OperatorContext(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorContext other = (OperatorContext) o; + return ( + Objects.equals(memory, other.memory) && + Objects.equals(knowledge, other.knowledge) + ); + } + + @Override + public int hashCode() { + return Objects.hash(memory, knowledge); + } + } + + @JsonDeserialize(builder = OperatorContextKnowledge.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorContextKnowledge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + @Getter + private final Boolean enabled; + + private OperatorContextKnowledge(Builder builder) { + this.enabled = builder.enabled; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperatorContextKnowledge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorContextKnowledge.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("enabled") + private Boolean enabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + public Builder enabled(Boolean enabled) { + this.enabled = enabled; + return this; + } + + public OperatorContextKnowledge build() { + return new OperatorContextKnowledge(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorContextKnowledge other = (OperatorContextKnowledge) o; + return (Objects.equals(enabled, other.enabled)); + } + + @Override + public int hashCode() { + return Objects.hash(enabled); + } + } + + @JsonDeserialize(builder = OperatorTrainingExample.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorTrainingExample { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("input") + @Getter + private final String input; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("output") + @Getter + private final String output; + + private OperatorTrainingExample(Builder builder) { + this.input = builder.input; + this.output = builder.output; + } + + public static Builder builder(final String input, final String output) { + return new Builder(input, output); + } + + public static OperatorTrainingExample fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorTrainingExample.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("input") + private String input; + + @JsonProperty("output") + private String output; + + @JsonCreator + public Builder( + @JsonProperty("input") final String input, + @JsonProperty("output") final String output + ) { + this.input = input; + this.output = output; + } + + public OperatorTrainingExample build() { + return new OperatorTrainingExample(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorTrainingExample other = (OperatorTrainingExample) o; + return ( + Objects.equals(input, other.input) && + Objects.equals(output, other.output) + ); + } + + @Override + public int hashCode() { + return Objects.hash(input, output); + } + } + + @JsonDeserialize(builder = OperatorContextMemory.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorContextMemory { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + @Getter + private final Boolean enabled; + + private OperatorContextMemory(Builder builder) { + this.enabled = builder.enabled; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperatorContextMemory fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorContextMemory.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("enabled") + private Boolean enabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + public Builder enabled(Boolean enabled) { + this.enabled = enabled; + return this; + } + + public OperatorContextMemory build() { + return new OperatorContextMemory(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorContextMemory other = (OperatorContextMemory) o; + return (Objects.equals(enabled, other.enabled)); + } + + @Override + public int hashCode() { + return Objects.hash(enabled); + } + } + + /** + * Converts a JSON String into a Operator object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Operator object represented by the provided JSON + */ + public static Operator fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Operator object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Operator object represented by the provided JSON + */ + public static Operator fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Operator() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorCreator.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorCreator.java new file mode 100644 index 0000000000..3be3138c37 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorCreator.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorCreator extends Creator { + + private Operator.LanguageOperator languageOperator; + + public OperatorCreator(final Operator.LanguageOperator languageOperator) { + this.languageOperator = languageOperator; + } + + public OperatorCreator setLanguageOperator( + final Operator.LanguageOperator languageOperator + ) { + this.languageOperator = languageOperator; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Operators"; + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Operator creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Operator.CreateOperatorResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Operator.CreateOperatorResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Operator.CreateOperatorResponse content = + Operator.CreateOperatorResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (languageOperator != null) { + request.setBody(Operator.toJson(languageOperator, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorDeleter.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorDeleter.java new file mode 100644 index 0000000000..0a7c3bee9c --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class OperatorDeleter extends Deleter { + + private String pathId; + + public OperatorDeleter(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Operators/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Operator delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorFetcher.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorFetcher.java new file mode 100644 index 0000000000..cf28b18ca2 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorFetcher extends Fetcher { + + private String pathId; + + public OperatorFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Operators/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Operator fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Operator.FetchOperatorResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Operator.FetchOperatorResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Operator.FetchOperatorResponse content = + Operator.FetchOperatorResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorReader.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorReader.java new file mode 100644 index 0000000000..f0201654e2 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorReader.java @@ -0,0 +1,240 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorReader extends Reader { + + private Integer pageSize; + private String pageToken; + + public OperatorReader() {} + + public OperatorReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public OperatorReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + Operator.ListOperatorResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Operators"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + Operator.ListOperatorResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Operator read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "items", + response.getContent(), + Operator.ListOperatorResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/ControlPlane/Operators"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/ControlPlane/Operators"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorResult.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorResult.java new file mode 100644 index 0000000000..ef7d8fb6a9 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorResult.java @@ -0,0 +1,2152 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class OperatorResult extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateOperatorResultResponse extends Resource { + + @JsonCreator + private CreateOperatorResultResponse() {} + + public static CreateOperatorResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateOperatorResultResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateOperatorResultResponse other = + (CreateOperatorResultResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateOperatorResultResponse extends Resource { + + @JsonCreator + private UpdateOperatorResultResponse() {} + + public static UpdateOperatorResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateOperatorResultResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateOperatorResultResponse other = + (UpdateOperatorResultResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteOperatorResultResponse extends Resource { + + @JsonCreator + private DeleteOperatorResultResponse() {} + + public static DeleteOperatorResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteOperatorResultResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteOperatorResultResponse other = + (DeleteOperatorResultResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListOperatorResultResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ExecutionDetails executionDetails; + + @Getter + private final String id; + + @Getter + private final IntelligenceConfigurationReference intelligenceConfiguration; + + @Getter + private final OperatorResultsResponseBaseMetadata metadata; + + @Getter + private final OperatorReference operator; + + @Getter + private final String outputFormat; + + @Getter + private final List referenceIds; + + @Getter + private final Object result; + + @JsonCreator + private ListOperatorResultResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty( + "executionDetails" + ) final ExecutionDetails executionDetails, + @JsonProperty("id") final String id, + @JsonProperty( + "intelligenceConfiguration" + ) final IntelligenceConfigurationReference intelligenceConfiguration, + @JsonProperty( + "metadata" + ) final OperatorResultsResponseBaseMetadata metadata, + @JsonProperty("operator") final OperatorReference operator, + @JsonProperty("outputFormat") final String outputFormat, + @JsonProperty("referenceIds") final List referenceIds, + @JsonProperty("result") final Object result + ) { + this.accountId = accountId; + this.conversationId = conversationId; + this.dateCreated = dateCreated; + this.executionDetails = executionDetails; + this.id = id; + this.intelligenceConfiguration = intelligenceConfiguration; + this.metadata = metadata; + this.operator = operator; + this.outputFormat = outputFormat; + this.referenceIds = referenceIds; + this.result = result; + } + + public static ListOperatorResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListOperatorResultResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListOperatorResultResponse other = (ListOperatorResultResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(executionDetails, other.executionDetails) && + Objects.equals(id, other.id) && + Objects.equals( + intelligenceConfiguration, + other.intelligenceConfiguration + ) && + Objects.equals(metadata, other.metadata) && + Objects.equals(operator, other.operator) && + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(referenceIds, other.referenceIds) && + Objects.equals(result, other.result) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + conversationId, + dateCreated, + executionDetails, + id, + intelligenceConfiguration, + metadata, + operator, + outputFormat, + referenceIds, + result + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchOperatorResultResponse extends Resource { + + @JsonCreator + private PatchOperatorResultResponse() {} + + public static PatchOperatorResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchOperatorResultResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchOperatorResultResponse other = (PatchOperatorResultResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchOperatorResultResponse extends Resource { + + @Getter + private final String accountId; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ExecutionDetails executionDetails; + + @Getter + private final String id; + + @Getter + private final IntelligenceConfigurationReference intelligenceConfiguration; + + @Getter + private final OperatorResultsResponseBaseMetadata metadata; + + @Getter + private final OperatorReference operator; + + @Getter + private final String outputFormat; + + @Getter + private final List referenceIds; + + @Getter + private final Object result; + + @JsonCreator + private FetchOperatorResultResponse( + @JsonProperty("accountId") final String accountId, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty( + "executionDetails" + ) final ExecutionDetails executionDetails, + @JsonProperty("id") final String id, + @JsonProperty( + "intelligenceConfiguration" + ) final IntelligenceConfigurationReference intelligenceConfiguration, + @JsonProperty( + "metadata" + ) final OperatorResultsResponseBaseMetadata metadata, + @JsonProperty("operator") final OperatorReference operator, + @JsonProperty("outputFormat") final String outputFormat, + @JsonProperty("referenceIds") final List referenceIds, + @JsonProperty("result") final Object result + ) { + this.accountId = accountId; + this.conversationId = conversationId; + this.dateCreated = dateCreated; + this.executionDetails = executionDetails; + this.id = id; + this.intelligenceConfiguration = intelligenceConfiguration; + this.metadata = metadata; + this.operator = operator; + this.outputFormat = outputFormat; + this.referenceIds = referenceIds; + this.result = result; + } + + public static FetchOperatorResultResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchOperatorResultResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchOperatorResultResponse other = (FetchOperatorResultResponse) o; + return ( + Objects.equals(accountId, other.accountId) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(executionDetails, other.executionDetails) && + Objects.equals(id, other.id) && + Objects.equals( + intelligenceConfiguration, + other.intelligenceConfiguration + ) && + Objects.equals(metadata, other.metadata) && + Objects.equals(operator, other.operator) && + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(referenceIds, other.referenceIds) && + Objects.equals(result, other.result) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountId, + conversationId, + dateCreated, + executionDetails, + id, + intelligenceConfiguration, + metadata, + operator, + outputFormat, + referenceIds, + result + ); + } + } + + public static OperatorResultDeleter deleter( + final String pathOperatorResultId + ) { + return new OperatorResultDeleter(pathOperatorResultId); + } + + public static OperatorResultFetcher fetcher( + final String pathOperatorResultId + ) { + return new OperatorResultFetcher(pathOperatorResultId); + } + + public static OperatorResultReader reader() { + return new OperatorResultReader(); + } + + @JsonDeserialize(builder = ListOperators200ResponseMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListOperators200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListOperators200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static ListOperators200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListOperators200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListOperators200ResponseMeta build() { + return new ListOperators200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListOperators200ResponseMeta other = + (ListOperators200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize(builder = SystemMetaData.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SystemMetaData { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resolvedModel") + @Getter + private final String resolvedModel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("latencyMs") + @Getter + private final Integer latencyMs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inputCharacters") + @Getter + private final Integer inputCharacters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outputCharacters") + @Getter + private final Integer outputCharacters; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("inputTruncated") + @Getter + private final Boolean inputTruncated; + + private SystemMetaData(Builder builder) { + this.resolvedModel = builder.resolvedModel; + this.latencyMs = builder.latencyMs; + this.inputCharacters = builder.inputCharacters; + this.outputCharacters = builder.outputCharacters; + this.inputTruncated = builder.inputTruncated; + } + + public static Builder builder( + final Integer latencyMs, + final Integer inputCharacters, + final Integer outputCharacters, + final Boolean inputTruncated + ) { + return new Builder( + latencyMs, + inputCharacters, + outputCharacters, + inputTruncated + ); + } + + public static SystemMetaData fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SystemMetaData.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("resolvedModel") + private String resolvedModel; + + @JsonProperty("latencyMs") + private Integer latencyMs; + + @JsonProperty("inputCharacters") + private Integer inputCharacters; + + @JsonProperty("outputCharacters") + private Integer outputCharacters; + + @JsonProperty("inputTruncated") + private Boolean inputTruncated; + + @JsonCreator + public Builder( + @JsonProperty("latencyMs") final Integer latencyMs, + @JsonProperty("inputCharacters") final Integer inputCharacters, + @JsonProperty( + "outputCharacters" + ) final Integer outputCharacters, + @JsonProperty("inputTruncated") final Boolean inputTruncated + ) { + this.latencyMs = latencyMs; + this.inputCharacters = inputCharacters; + this.outputCharacters = outputCharacters; + this.inputTruncated = inputTruncated; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resolvedModel") + public Builder resolvedModel(String resolvedModel) { + this.resolvedModel = resolvedModel; + return this; + } + + public SystemMetaData build() { + return new SystemMetaData(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SystemMetaData other = (SystemMetaData) o; + return ( + Objects.equals(resolvedModel, other.resolvedModel) && + Objects.equals(latencyMs, other.latencyMs) && + Objects.equals(inputCharacters, other.inputCharacters) && + Objects.equals(outputCharacters, other.outputCharacters) && + Objects.equals(inputTruncated, other.inputTruncated) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + resolvedModel, + latencyMs, + inputCharacters, + outputCharacters, + inputTruncated + ); + } + } + + @JsonDeserialize(builder = ExecutionDetailsParticipants.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ExecutionDetailsParticipants { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + private ExecutionDetailsParticipants(Builder builder) { + this.id = builder.id; + this.profileId = builder.profileId; + this.type = builder.type; + } + + public static Builder builder(final String id) { + return new Builder(id); + } + + public static ExecutionDetailsParticipants fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ExecutionDetailsParticipants.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("type") + private String type; + + @JsonCreator + public Builder(@JsonProperty("id") final String id) { + this.id = id; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + public Builder profileId(String profileId) { + this.profileId = profileId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + public ExecutionDetailsParticipants build() { + return new ExecutionDetailsParticipants(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionDetailsParticipants other = + (ExecutionDetailsParticipants) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(profileId, other.profileId) && + Objects.equals(type, other.type) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, profileId, type); + } + } + + @JsonDeserialize(builder = OperatorReference.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorReference { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("parameters") + @Getter + private final Map parameters; + + private OperatorReference(Builder builder) { + this.id = builder.id; + this.version = builder.version; + this.parameters = builder.parameters; + } + + public static Builder builder( + final String id, + final Integer version, + final Map parameters + ) { + return new Builder(id, version, parameters); + } + + public static OperatorReference fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorReference.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("version") + private Integer version; + + @JsonProperty("parameters") + private Map parameters; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("version") final Integer version, + @JsonProperty("parameters") final Map parameters + ) { + this.id = id; + this.version = version; + this.parameters = parameters; + } + + public OperatorReference build() { + return new OperatorReference(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorReference other = (OperatorReference) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(version, other.version) && + Objects.equals(parameters, other.parameters) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, version, parameters); + } + } + + @JsonDeserialize(builder = ResolvedContextKnowledge.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ResolvedContextKnowledge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sources") + @Getter + private final List sources; + + private ResolvedContextKnowledge(Builder builder) { + this.sources = builder.sources; + } + + public static Builder builder( + final List sources + ) { + return new Builder(sources); + } + + public static ResolvedContextKnowledge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ResolvedContextKnowledge.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("sources") + private List sources; + + @JsonCreator + public Builder( + @JsonProperty("sources") final List< + ResolvedContextKnowledgeSources + > sources + ) { + this.sources = sources; + } + + public ResolvedContextKnowledge build() { + return new ResolvedContextKnowledge(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ResolvedContextKnowledge other = (ResolvedContextKnowledge) o; + return (Objects.equals(sources, other.sources)); + } + + @Override + public int hashCode() { + return Objects.hash(sources); + } + } + + @JsonDeserialize(builder = IntelligenceConfigurationReference.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IntelligenceConfigurationReference { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ruleId") + @Getter + private final String ruleId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + private IntelligenceConfigurationReference(Builder builder) { + this.id = builder.id; + this.ruleId = builder.ruleId; + this.version = builder.version; + } + + public static Builder builder( + final String id, + final String ruleId, + final Integer version + ) { + return new Builder(id, ruleId, version); + } + + public static IntelligenceConfigurationReference fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IntelligenceConfigurationReference.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("ruleId") + private String ruleId; + + @JsonProperty("version") + private Integer version; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("ruleId") final String ruleId, + @JsonProperty("version") final Integer version + ) { + this.id = id; + this.ruleId = ruleId; + this.version = version; + } + + public IntelligenceConfigurationReference build() { + return new IntelligenceConfigurationReference(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IntelligenceConfigurationReference other = + (IntelligenceConfigurationReference) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(ruleId, other.ruleId) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, ruleId, version); + } + } + + @JsonDeserialize(builder = TextResultResult.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TextResultResult { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + @Getter + private final String text; + + private TextResultResult(Builder builder) { + this.text = builder.text; + } + + public static Builder builder(final String text) { + return new Builder(text); + } + + public static TextResultResult fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TextResultResult.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("text") + private String text; + + @JsonCreator + public Builder(@JsonProperty("text") final String text) { + this.text = text; + } + + public TextResultResult build() { + return new TextResultResult(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TextResultResult other = (TextResultResult) o; + return (Objects.equals(text, other.text)); + } + + @Override + public int hashCode() { + return Objects.hash(text); + } + } + + @JsonDeserialize(builder = ExecutionDetails.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ExecutionDetails { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("trigger") + @Getter + private final ExecutionDetailsTrigger trigger; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("communications") + @Getter + private final ExecutionDetailsCommunications communications; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channels") + @Getter + private final List channels; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("participants") + @Getter + private final List participants; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resolvedContext") + @Getter + private final ResolvedContext resolvedContext; + + private ExecutionDetails(Builder builder) { + this.trigger = builder.trigger; + this.communications = builder.communications; + this.channels = builder.channels; + this.participants = builder.participants; + this.resolvedContext = builder.resolvedContext; + } + + public static Builder builder( + final ExecutionDetailsTrigger trigger, + final ExecutionDetailsCommunications communications, + final List channels, + final List participants + ) { + return new Builder(trigger, communications, channels, participants); + } + + public static ExecutionDetails fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ExecutionDetails.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("trigger") + private ExecutionDetailsTrigger trigger; + + @JsonProperty("communications") + private ExecutionDetailsCommunications communications; + + @JsonProperty("channels") + private List channels; + + @JsonProperty("participants") + private List participants; + + @JsonProperty("resolvedContext") + private ResolvedContext resolvedContext; + + @JsonCreator + public Builder( + @JsonProperty("trigger") final ExecutionDetailsTrigger trigger, + @JsonProperty( + "communications" + ) final ExecutionDetailsCommunications communications, + @JsonProperty("channels") final List channels, + @JsonProperty("participants") final List< + ExecutionDetailsParticipants + > participants + ) { + this.trigger = trigger; + this.communications = communications; + this.channels = channels; + this.participants = participants; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resolvedContext") + public Builder resolvedContext(ResolvedContext resolvedContext) { + this.resolvedContext = resolvedContext; + return this; + } + + public ExecutionDetails build() { + return new ExecutionDetails(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionDetails other = (ExecutionDetails) o; + return ( + Objects.equals(trigger, other.trigger) && + Objects.equals(communications, other.communications) && + Objects.equals(channels, other.channels) && + Objects.equals(participants, other.participants) && + Objects.equals(resolvedContext, other.resolvedContext) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + trigger, + communications, + channels, + participants, + resolvedContext + ); + } + } + + @JsonDeserialize(builder = ResolvedContextKnowledgeSources.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ResolvedContextKnowledgeSources { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("baseId") + @Getter + private final String baseId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sourceId") + @Getter + private final String sourceId; + + private ResolvedContextKnowledgeSources(Builder builder) { + this.baseId = builder.baseId; + this.sourceId = builder.sourceId; + } + + public static Builder builder( + final String baseId, + final String sourceId + ) { + return new Builder(baseId, sourceId); + } + + public static ResolvedContextKnowledgeSources fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ResolvedContextKnowledgeSources.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("baseId") + private String baseId; + + @JsonProperty("sourceId") + private String sourceId; + + @JsonCreator + public Builder( + @JsonProperty("baseId") final String baseId, + @JsonProperty("sourceId") final String sourceId + ) { + this.baseId = baseId; + this.sourceId = sourceId; + } + + public ResolvedContextKnowledgeSources build() { + return new ResolvedContextKnowledgeSources(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ResolvedContextKnowledgeSources other = + (ResolvedContextKnowledgeSources) o; + return ( + Objects.equals(baseId, other.baseId) && + Objects.equals(sourceId, other.sourceId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(baseId, sourceId); + } + } + + @JsonDeserialize( + builder = OperatorResultsResponseBaseMetadata.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorResultsResponseBaseMetadata { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("system") + @Getter + private final SystemMetaData system; + + private OperatorResultsResponseBaseMetadata(Builder builder) { + this.system = builder.system; + } + + public static Builder builder(final SystemMetaData system) { + return new Builder(system); + } + + public static OperatorResultsResponseBaseMetadata fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + OperatorResultsResponseBaseMetadata.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("system") + private SystemMetaData system; + + @JsonCreator + public Builder( + @JsonProperty("system") final SystemMetaData system + ) { + this.system = system; + } + + public OperatorResultsResponseBaseMetadata build() { + return new OperatorResultsResponseBaseMetadata(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorResultsResponseBaseMetadata other = + (OperatorResultsResponseBaseMetadata) o; + return (Objects.equals(system, other.system)); + } + + @Override + public int hashCode() { + return Objects.hash(system); + } + } + + @JsonDeserialize(builder = ResolvedContext.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ResolvedContext { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memory") + @Getter + private final ResolvedContextMemory memory; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge") + @Getter + private final ResolvedContextKnowledge knowledge; + + private ResolvedContext(Builder builder) { + this.memory = builder.memory; + this.knowledge = builder.knowledge; + } + + public static Builder builder() { + return new Builder(); + } + + public static ResolvedContext fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ResolvedContext.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("memory") + private ResolvedContextMemory memory; + + @JsonProperty("knowledge") + private ResolvedContextKnowledge knowledge; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memory") + public Builder memory(ResolvedContextMemory memory) { + this.memory = memory; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge") + public Builder knowledge(ResolvedContextKnowledge knowledge) { + this.knowledge = knowledge; + return this; + } + + public ResolvedContext build() { + return new ResolvedContext(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ResolvedContext other = (ResolvedContext) o; + return ( + Objects.equals(memory, other.memory) && + Objects.equals(knowledge, other.knowledge) + ); + } + + @Override + public int hashCode() { + return Objects.hash(memory, knowledge); + } + } + + @JsonDeserialize(builder = ExecutionDetailsTrigger.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ExecutionDetailsTrigger { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("on") + @Getter + private final String on; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("timestamp") + @Getter + private final ZonedDateTime timestamp; + + private ExecutionDetailsTrigger(Builder builder) { + this.on = builder.on; + this.timestamp = builder.timestamp; + } + + public static Builder builder( + final String on, + final ZonedDateTime timestamp + ) { + return new Builder(on, timestamp); + } + + public static ExecutionDetailsTrigger fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ExecutionDetailsTrigger.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("on") + private String on; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("timestamp") + private ZonedDateTime timestamp; + + @JsonCreator + public Builder( + @JsonProperty("on") final String on, + @JsonProperty("timestamp") final ZonedDateTime timestamp + ) { + this.on = on; + this.timestamp = timestamp; + } + + public ExecutionDetailsTrigger build() { + return new ExecutionDetailsTrigger(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionDetailsTrigger other = (ExecutionDetailsTrigger) o; + return ( + Objects.equals(on, other.on) && + Objects.equals(timestamp, other.timestamp) + ); + } + + @Override + public int hashCode() { + return Objects.hash(on, timestamp); + } + } + + @JsonDeserialize(builder = ExecutionDetailsCommunications.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ExecutionDetailsCommunications { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("first") + @Getter + private final String first; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last") + @Getter + private final String last; + + private ExecutionDetailsCommunications(Builder builder) { + this.first = builder.first; + this.last = builder.last; + } + + public static Builder builder(final String first, final String last) { + return new Builder(first, last); + } + + public static ExecutionDetailsCommunications fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ExecutionDetailsCommunications.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("first") + private String first; + + @JsonProperty("last") + private String last; + + @JsonCreator + public Builder( + @JsonProperty("first") final String first, + @JsonProperty("last") final String last + ) { + this.first = first; + this.last = last; + } + + public ExecutionDetailsCommunications build() { + return new ExecutionDetailsCommunications(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionDetailsCommunications other = + (ExecutionDetailsCommunications) o; + return ( + Objects.equals(first, other.first) && + Objects.equals(last, other.last) + ); + } + + @Override + public int hashCode() { + return Objects.hash(first, last); + } + } + + @JsonDeserialize(builder = ResolvedContextMemory.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ResolvedContextMemory { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memoryStoreId") + @Getter + private final String memoryStoreId; + + private ResolvedContextMemory(Builder builder) { + this.profileId = builder.profileId; + this.memoryStoreId = builder.memoryStoreId; + } + + public static Builder builder( + final String profileId, + final String memoryStoreId + ) { + return new Builder(profileId, memoryStoreId); + } + + public static ResolvedContextMemory fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ResolvedContextMemory.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("memoryStoreId") + private String memoryStoreId; + + @JsonCreator + public Builder( + @JsonProperty("profileId") final String profileId, + @JsonProperty("memoryStoreId") final String memoryStoreId + ) { + this.profileId = profileId; + this.memoryStoreId = memoryStoreId; + } + + public ResolvedContextMemory build() { + return new ResolvedContextMemory(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ResolvedContextMemory other = (ResolvedContextMemory) o; + return ( + Objects.equals(profileId, other.profileId) && + Objects.equals(memoryStoreId, other.memoryStoreId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(profileId, memoryStoreId); + } + } + + @JsonDeserialize(builder = OperatorResultsResponseV1.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorResultsResponseV1 { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outputFormat") + @Getter + private final String outputFormat; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountId") + @Getter + private final String accountId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfiguration") + @Getter + private final IntelligenceConfigurationReference intelligenceConfiguration; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operator") + @Getter + private final OperatorReference operator; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateCreated") + @Getter + private final ZonedDateTime dateCreated; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("referenceIds") + @Getter + private final List referenceIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("executionDetails") + @Getter + private final ExecutionDetails executionDetails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + @Getter + private final OperatorResultsResponseBaseMetadata metadata; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("result") + @Getter + private final Object result; + + private OperatorResultsResponseV1(Builder builder) { + this.outputFormat = builder.outputFormat; + this.id = builder.id; + this.accountId = builder.accountId; + this.intelligenceConfiguration = builder.intelligenceConfiguration; + this.conversationId = builder.conversationId; + this.operator = builder.operator; + this.dateCreated = builder.dateCreated; + this.referenceIds = builder.referenceIds; + this.executionDetails = builder.executionDetails; + this.metadata = builder.metadata; + this.result = builder.result; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperatorResultsResponseV1 fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + OperatorResultsResponseV1.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("outputFormat") + private String outputFormat; + + @JsonProperty("id") + private String id; + + @JsonProperty("accountId") + private String accountId; + + @JsonProperty("intelligenceConfiguration") + private IntelligenceConfigurationReference intelligenceConfiguration; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonProperty("operator") + private OperatorReference operator; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("dateCreated") + private ZonedDateTime dateCreated; + + @JsonProperty("referenceIds") + private List referenceIds; + + @JsonProperty("executionDetails") + private ExecutionDetails executionDetails; + + @JsonProperty("metadata") + private OperatorResultsResponseBaseMetadata metadata; + + @JsonProperty("result") + private Object result; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("outputFormat") + public Builder outputFormat(String outputFormat) { + this.outputFormat = outputFormat; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accountId") + public Builder accountId(String accountId) { + this.accountId = accountId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfiguration") + public Builder intelligenceConfiguration( + IntelligenceConfigurationReference intelligenceConfiguration + ) { + this.intelligenceConfiguration = intelligenceConfiguration; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + public Builder conversationId(String conversationId) { + this.conversationId = conversationId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operator") + public Builder operator(OperatorReference operator) { + this.operator = operator; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateCreated") + public Builder dateCreated(ZonedDateTime dateCreated) { + this.dateCreated = dateCreated; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("referenceIds") + public Builder referenceIds(List referenceIds) { + this.referenceIds = referenceIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("executionDetails") + public Builder executionDetails(ExecutionDetails executionDetails) { + this.executionDetails = executionDetails; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("metadata") + public Builder metadata( + OperatorResultsResponseBaseMetadata metadata + ) { + this.metadata = metadata; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("result") + public Builder result(Object result) { + this.result = result; + return this; + } + + public OperatorResultsResponseV1 build() { + return new OperatorResultsResponseV1(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorResultsResponseV1 other = (OperatorResultsResponseV1) o; + return ( + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(id, other.id) && + Objects.equals(accountId, other.accountId) && + Objects.equals( + intelligenceConfiguration, + other.intelligenceConfiguration + ) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(operator, other.operator) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(referenceIds, other.referenceIds) && + Objects.equals(executionDetails, other.executionDetails) && + Objects.equals(metadata, other.metadata) && + Objects.equals(result, other.result) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + outputFormat, + id, + accountId, + intelligenceConfiguration, + conversationId, + operator, + dateCreated, + referenceIds, + executionDetails, + metadata, + result + ); + } + } + + /** + * Converts a JSON String into a OperatorResult object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return OperatorResult object represented by the provided JSON + */ + public static OperatorResult fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorResult.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a OperatorResult object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return OperatorResult object represented by the provided JSON + */ + public static OperatorResult fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, OperatorResult.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private OperatorResult() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultDeleter.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultDeleter.java new file mode 100644 index 0000000000..8ee81288fe --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultDeleter.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class OperatorResultDeleter extends Deleter { + + private String pathOperatorResultId; + + public OperatorResultDeleter(final String pathOperatorResultId) { + this.pathOperatorResultId = pathOperatorResultId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/OperatorResults/{operatorResultId}"; + + path = + path.replace( + "{" + "operatorResultId" + "}", + this.pathOperatorResultId.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OperatorResult delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultFetcher.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultFetcher.java new file mode 100644 index 0000000000..88dd3ef53d --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultFetcher.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorResultFetcher + extends Fetcher { + + private String pathOperatorResultId; + + public OperatorResultFetcher(final String pathOperatorResultId) { + this.pathOperatorResultId = pathOperatorResultId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/OperatorResults/{operatorResultId}"; + + path = + path.replace( + "{" + "operatorResultId" + "}", + this.pathOperatorResultId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "OperatorResult fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public OperatorResult.FetchOperatorResultResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return OperatorResult.FetchOperatorResultResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + OperatorResult.FetchOperatorResultResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + OperatorResult.FetchOperatorResultResponse content = + OperatorResult.FetchOperatorResultResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultReader.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultReader.java new file mode 100644 index 0000000000..d4fa29d723 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorResultReader.java @@ -0,0 +1,288 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorResultReader + extends Reader { + + private String conversationId; + private String intelligenceConfigurationId; + private String operatorId; + private Integer pageSize; + private String pageToken; + + public OperatorResultReader() {} + + public OperatorResultReader setConversationId(final String conversationId) { + this.conversationId = conversationId; + return this; + } + + public OperatorResultReader setIntelligenceConfigurationId( + final String intelligenceConfigurationId + ) { + this.intelligenceConfigurationId = intelligenceConfigurationId; + return this; + } + + public OperatorResultReader setOperatorId(final String operatorId) { + this.operatorId = operatorId; + return this; + } + + public OperatorResultReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public OperatorResultReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse< + OperatorResult.ListOperatorResultResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + OperatorResult.ListOperatorResultResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v3/OperatorResults"; + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + OperatorResult.ListOperatorResultResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "OperatorResult read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "items", + response.getContent(), + OperatorResult.ListOperatorResultResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/OperatorResults"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/OperatorResults"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (conversationId != null) { + Serializer.toString( + request, + "conversationId", + conversationId, + ParameterType.QUERY + ); + } + + if (intelligenceConfigurationId != null) { + Serializer.toString( + request, + "intelligenceConfigurationId", + intelligenceConfigurationId, + ParameterType.QUERY + ); + } + + if (operatorId != null) { + Serializer.toString( + request, + "operatorId", + operatorId, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/OperatorUpdater.java b/src/main/java/com/twilio/rest/intelligence/v3/OperatorUpdater.java new file mode 100644 index 0000000000..51b40144c5 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/OperatorUpdater.java @@ -0,0 +1,142 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperatorUpdater extends Updater { + + private String pathId; + private String ifMatch; + private Operator.LanguageOperator languageOperator; + + public OperatorUpdater( + final String pathId, + final Operator.LanguageOperator languageOperator + ) { + this.pathId = pathId; + this.languageOperator = languageOperator; + } + + public OperatorUpdater setLanguageOperator( + final Operator.LanguageOperator languageOperator + ) { + this.languageOperator = languageOperator; + return this; + } + + public OperatorUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Operators/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Operator update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Operator.UpdateOperatorResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Operator.UpdateOperatorResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Operator.UpdateOperatorResponse content = + Operator.UpdateOperatorResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (languageOperator != null) { + request.setBody(Operator.toJson(languageOperator, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/RuleExecution.java b/src/main/java/com/twilio/rest/intelligence/v3/RuleExecution.java new file mode 100644 index 0000000000..ac1e6b2f95 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/RuleExecution.java @@ -0,0 +1,651 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class RuleExecution extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateRuleExecutionResponse extends Resource { + + @JsonCreator + private CreateRuleExecutionResponse() {} + + public static CreateRuleExecutionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateRuleExecutionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateRuleExecutionResponse other = (CreateRuleExecutionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateRuleExecutionResponse extends Resource { + + @JsonCreator + private UpdateRuleExecutionResponse() {} + + public static UpdateRuleExecutionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateRuleExecutionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateRuleExecutionResponse other = (UpdateRuleExecutionResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteRuleExecutionResponse extends Resource { + + @JsonCreator + private DeleteRuleExecutionResponse() {} + + public static DeleteRuleExecutionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteRuleExecutionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteRuleExecutionResponse other = (DeleteRuleExecutionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListRuleExecutionResponse extends Resource { + + @JsonCreator + private ListRuleExecutionResponse() {} + + public static ListRuleExecutionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListRuleExecutionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListRuleExecutionResponse other = (ListRuleExecutionResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchRuleExecutionResponse extends Resource { + + @JsonCreator + private PatchRuleExecutionResponse() {} + + public static PatchRuleExecutionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchRuleExecutionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchRuleExecutionResponse other = (PatchRuleExecutionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchRuleExecutionResponse extends Resource { + + @JsonCreator + private FetchRuleExecutionResponse() {} + + public static FetchRuleExecutionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchRuleExecutionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchRuleExecutionResponse other = (FetchRuleExecutionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + public static RuleExecutionCreator creator( + final RuleExecution.CreateRuleExecutionRequest createRuleExecutionRequest + ) { + return new RuleExecutionCreator(createRuleExecutionRequest); + } + + @JsonDeserialize(builder = CreateRuleExecutionRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateRuleExecutionRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("intelligenceConfigurationId") + @Getter + private final String intelligenceConfigurationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ruleId") + @Getter + private final String ruleId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rule") + @Getter + private final RuleOverride rule; + + private CreateRuleExecutionRequest(Builder builder) { + this.intelligenceConfigurationId = + builder.intelligenceConfigurationId; + this.ruleId = builder.ruleId; + this.conversationId = builder.conversationId; + this.rule = builder.rule; + } + + public static Builder builder( + final String intelligenceConfigurationId, + final String ruleId, + final String conversationId + ) { + return new Builder( + intelligenceConfigurationId, + ruleId, + conversationId + ); + } + + public static CreateRuleExecutionRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateRuleExecutionRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("intelligenceConfigurationId") + private String intelligenceConfigurationId; + + @JsonProperty("ruleId") + private String ruleId; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonProperty("rule") + private RuleOverride rule; + + @JsonCreator + public Builder( + @JsonProperty( + "intelligenceConfigurationId" + ) final String intelligenceConfigurationId, + @JsonProperty("ruleId") final String ruleId, + @JsonProperty("conversationId") final String conversationId + ) { + this.intelligenceConfigurationId = intelligenceConfigurationId; + this.ruleId = ruleId; + this.conversationId = conversationId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rule") + public Builder rule(RuleOverride rule) { + this.rule = rule; + return this; + } + + public CreateRuleExecutionRequest build() { + return new CreateRuleExecutionRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateRuleExecutionRequest other = (CreateRuleExecutionRequest) o; + return ( + Objects.equals( + intelligenceConfigurationId, + other.intelligenceConfigurationId + ) && + Objects.equals(ruleId, other.ruleId) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(rule, other.rule) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + intelligenceConfigurationId, + ruleId, + conversationId, + rule + ); + } + } + + @JsonDeserialize(builder = RuleOverride.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class RuleOverride { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("operators") + @Getter + private final List operators; + + private RuleOverride(Builder builder) { + this.operators = builder.operators; + } + + public static Builder builder(final List operators) { + return new Builder(operators); + } + + public static RuleOverride fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, RuleOverride.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("operators") + private List operators; + + @JsonCreator + public Builder( + @JsonProperty("operators") final List< + OperatorOverride + > operators + ) { + this.operators = operators; + } + + public RuleOverride build() { + return new RuleOverride(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RuleOverride other = (RuleOverride) o; + return (Objects.equals(operators, other.operators)); + } + + @Override + public int hashCode() { + return Objects.hash(operators); + } + } + + @JsonDeserialize(builder = OperatorOverride.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorOverride { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("parameters") + @Getter + private final Map parameters; + + private OperatorOverride(Builder builder) { + this.id = builder.id; + this.parameters = builder.parameters; + } + + public static Builder builder( + final String id, + final Map parameters + ) { + return new Builder(id, parameters); + } + + public static OperatorOverride fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorOverride.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("parameters") + private Map parameters; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("parameters") final Map parameters + ) { + this.id = id; + this.parameters = parameters; + } + + public OperatorOverride build() { + return new OperatorOverride(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorOverride other = (OperatorOverride) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(parameters, other.parameters) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, parameters); + } + } + + /** + * Converts a JSON String into a RuleExecution object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return RuleExecution object represented by the provided JSON + */ + public static RuleExecution fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RuleExecution.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a RuleExecution object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return RuleExecution object represented by the provided JSON + */ + public static RuleExecution fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RuleExecution.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private RuleExecution() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/RuleExecutionCreator.java b/src/main/java/com/twilio/rest/intelligence/v3/RuleExecutionCreator.java new file mode 100644 index 0000000000..f8dedbcf7a --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/RuleExecutionCreator.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RuleExecutionCreator + extends Creator { + + private RuleExecution.CreateRuleExecutionRequest createRuleExecutionRequest; + + public RuleExecutionCreator( + final RuleExecution.CreateRuleExecutionRequest createRuleExecutionRequest + ) { + this.createRuleExecutionRequest = createRuleExecutionRequest; + } + + public RuleExecutionCreator setCreateRuleExecutionRequest( + final RuleExecution.CreateRuleExecutionRequest createRuleExecutionRequest + ) { + this.createRuleExecutionRequest = createRuleExecutionRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/RuleExecutions"; + + Request request = new Request( + HttpMethod.POST, + Domains.INTELLIGENCE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "RuleExecution creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public RuleExecution.CreateRuleExecutionResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return RuleExecution.CreateRuleExecutionResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + RuleExecution.CreateRuleExecutionResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + RuleExecution.CreateRuleExecutionResponse content = + RuleExecution.CreateRuleExecutionResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createRuleExecutionRequest != null) { + request.setBody( + RuleExecution.toJson(createRuleExecutionRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/Version.java b/src/main/java/com/twilio/rest/intelligence/v3/Version.java new file mode 100644 index 0000000000..6ab2662534 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/Version.java @@ -0,0 +1,1342 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Version extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateVersionResponse extends Resource { + + @JsonCreator + private CreateVersionResponse() {} + + public static CreateVersionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateVersionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateVersionResponse other = (CreateVersionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateVersionResponse extends Resource { + + @JsonCreator + private UpdateVersionResponse() {} + + public static UpdateVersionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateVersionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateVersionResponse other = (UpdateVersionResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteVersionResponse extends Resource { + + @JsonCreator + private DeleteVersionResponse() {} + + public static DeleteVersionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteVersionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteVersionResponse other = (DeleteVersionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListVersionResponse extends Resource { + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateDeprecated; + + @Getter + private final ZonedDateTime dateRetired; + + @Getter + private final ZonedDateTime retirementDate; + + @Getter + private final Version.OperatorVersionStatus status; + + @Getter + private final Integer version; + + @JsonCreator + private ListVersionResponse( + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateDeprecated") final ZonedDateTime dateDeprecated, + @JsonProperty("dateRetired") final ZonedDateTime dateRetired, + @JsonProperty("retirementDate") final ZonedDateTime retirementDate, + @JsonProperty("status") final Version.OperatorVersionStatus status, + @JsonProperty("version") final Integer version + ) { + this.dateCreated = dateCreated; + this.dateDeprecated = dateDeprecated; + this.dateRetired = dateRetired; + this.retirementDate = retirementDate; + this.status = status; + this.version = version; + } + + public static ListVersionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListVersionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListVersionResponse other = (ListVersionResponse) o; + return ( + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateDeprecated, other.dateDeprecated) && + Objects.equals(dateRetired, other.dateRetired) && + Objects.equals(retirementDate, other.retirementDate) && + Objects.equals(status, other.status) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dateCreated, + dateDeprecated, + dateRetired, + retirementDate, + status, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchVersionResponse extends Resource { + + @JsonCreator + private PatchVersionResponse() {} + + public static PatchVersionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchVersionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchVersionResponse other = (PatchVersionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchVersionResponse extends Resource { + + @Getter + private final Version.OperatorAuthorEnum author; + + @Getter + private final OperatorContext context; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final Version.OperatorOutputFormat outputFormat; + + @Getter + private final Object outputSchema; + + @Getter + private final Map parameters; + + @Getter + private final String prompt; + + @Getter + private final Version.OperatorVersionStatus status; + + @Getter + private final List trainingExamples; + + @Getter + private final Integer version; + + @JsonCreator + private FetchVersionResponse( + @JsonProperty("author") final Version.OperatorAuthorEnum author, + @JsonProperty("context") final OperatorContext context, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty( + "outputFormat" + ) final Version.OperatorOutputFormat outputFormat, + @JsonProperty("outputSchema") final Object outputSchema, + @JsonProperty("parameters") final Map< + String, + OperatorParameter + > parameters, + @JsonProperty("prompt") final String prompt, + @JsonProperty("status") final Version.OperatorVersionStatus status, + @JsonProperty("trainingExamples") final List< + OperatorTrainingExample + > trainingExamples, + @JsonProperty("version") final Integer version + ) { + this.author = author; + this.context = context; + this.dateCreated = dateCreated; + this.description = description; + this.displayName = displayName; + this.id = id; + this.outputFormat = outputFormat; + this.outputSchema = outputSchema; + this.parameters = parameters; + this.prompt = prompt; + this.status = status; + this.trainingExamples = trainingExamples; + this.version = version; + } + + public static FetchVersionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchVersionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchVersionResponse other = (FetchVersionResponse) o; + return ( + Objects.equals(author, other.author) && + Objects.equals(context, other.context) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(outputFormat, other.outputFormat) && + Objects.equals(outputSchema, other.outputSchema) && + Objects.equals(parameters, other.parameters) && + Objects.equals(prompt, other.prompt) && + Objects.equals(status, other.status) && + Objects.equals(trainingExamples, other.trainingExamples) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + author, + context, + dateCreated, + description, + displayName, + id, + outputFormat, + outputSchema, + parameters, + prompt, + status, + trainingExamples, + version + ); + } + } + + public static VersionFetcher fetcher( + final String pathId, + final Integer pathVersion + ) { + return new VersionFetcher(pathId, pathVersion); + } + + public static VersionReader reader(final String pathId) { + return new VersionReader(pathId); + } + + public enum Type { + STRING("STRING"), + INTEGER("INTEGER"), + NUMBER("NUMBER"), + BOOLEAN("BOOLEAN"), + KNOWLEDGE_BASE_AND_SOURCE_IDS("KNOWLEDGE_BASE_AND_SOURCE_IDS"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum OperatorVersionStatus { + PREVIEW("PREVIEW"), + ACTIVE("ACTIVE"), + DEPRECATED("DEPRECATED"), + RETIRED("RETIRED"); + + private final String value; + + private OperatorVersionStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OperatorVersionStatus forValue(final String value) { + return Promoter.enumFromString( + value, + OperatorVersionStatus.values() + ); + } + } + + public enum OperatorOutputFormat { + TEXT("TEXT"), + JSON("JSON"), + CLASSIFICATION("CLASSIFICATION"); + + private final String value; + + private OperatorOutputFormat(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OperatorOutputFormat forValue(final String value) { + return Promoter.enumFromString( + value, + OperatorOutputFormat.values() + ); + } + } + + public enum OperatorAuthorEnum { + SELF("SELF"), + TWILIO("TWILIO"); + + private final String value; + + private OperatorAuthorEnum(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OperatorAuthorEnum forValue(final String value) { + return Promoter.enumFromString(value, OperatorAuthorEnum.values()); + } + } + + @JsonDeserialize(builder = OperatorParameter.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorParameter { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Version.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("default") + @Getter + private final Object _default; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("required") + @Getter + private final Boolean required; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + private OperatorParameter(Builder builder) { + this.type = builder.type; + this._default = builder._default; + this.required = builder.required; + this.description = builder.description; + } + + public static Builder builder(final Version.Type type) { + return new Builder(type); + } + + public static OperatorParameter fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorParameter.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Version.Type type; + + @JsonProperty("default") + private Object _default; + + @JsonProperty("required") + private Boolean required; + + @JsonProperty("description") + private String description; + + @JsonCreator + public Builder(@JsonProperty("type") final Version.Type type) { + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("default") + public Builder _default(Object _default) { + this._default = _default; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("required") + public Builder required(Boolean required) { + this.required = required; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public OperatorParameter build() { + return new OperatorParameter(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorParameter other = (OperatorParameter) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(_default, other._default) && + Objects.equals(required, other.required) && + Objects.equals(description, other.description) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, _default, required, description); + } + } + + @JsonDeserialize(builder = ListOperators200ResponseMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListOperators200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + private ListOperators200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.previousToken = builder.previousToken; + this.nextToken = builder.nextToken; + } + + public static Builder builder( + final String key, + final Integer pageSize + ) { + return new Builder(key, pageSize); + } + + public static ListOperators200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListOperators200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonCreator + public Builder( + @JsonProperty("key") final String key, + @JsonProperty("pageSize") final Integer pageSize + ) { + this.key = key; + this.pageSize = pageSize; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + public ListOperators200ResponseMeta build() { + return new ListOperators200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListOperators200ResponseMeta other = + (ListOperators200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(previousToken, other.previousToken) && + Objects.equals(nextToken, other.nextToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, previousToken, nextToken); + } + } + + @JsonDeserialize( + builder = ListOperatorVersions200ResponseItems.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListOperatorVersions200ResponseItems { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final Version.OperatorVersionStatus status; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateCreated") + @Getter + private final ZonedDateTime dateCreated; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateDeprecated") + @Getter + private final ZonedDateTime dateDeprecated; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("retirementDate") + @Getter + private final ZonedDateTime retirementDate; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateRetired") + @Getter + private final ZonedDateTime dateRetired; + + private ListOperatorVersions200ResponseItems(Builder builder) { + this.version = builder.version; + this.status = builder.status; + this.dateCreated = builder.dateCreated; + this.dateDeprecated = builder.dateDeprecated; + this.retirementDate = builder.retirementDate; + this.dateRetired = builder.dateRetired; + } + + public static Builder builder( + final Integer version, + final Version.OperatorVersionStatus status, + final ZonedDateTime dateCreated + ) { + return new Builder(version, status, dateCreated); + } + + public static ListOperatorVersions200ResponseItems fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListOperatorVersions200ResponseItems.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("version") + private Integer version; + + @JsonProperty("status") + private Version.OperatorVersionStatus status; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("dateCreated") + private ZonedDateTime dateCreated; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("dateDeprecated") + private ZonedDateTime dateDeprecated; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("retirementDate") + private ZonedDateTime retirementDate; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("dateRetired") + private ZonedDateTime dateRetired; + + @JsonCreator + public Builder( + @JsonProperty("version") final Integer version, + @JsonProperty( + "status" + ) final Version.OperatorVersionStatus status, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated + ) { + this.version = version; + this.status = status; + this.dateCreated = dateCreated; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateDeprecated") + public Builder dateDeprecated(ZonedDateTime dateDeprecated) { + this.dateDeprecated = dateDeprecated; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("retirementDate") + public Builder retirementDate(ZonedDateTime retirementDate) { + this.retirementDate = retirementDate; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dateRetired") + public Builder dateRetired(ZonedDateTime dateRetired) { + this.dateRetired = dateRetired; + return this; + } + + public ListOperatorVersions200ResponseItems build() { + return new ListOperatorVersions200ResponseItems(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListOperatorVersions200ResponseItems other = + (ListOperatorVersions200ResponseItems) o; + return ( + Objects.equals(version, other.version) && + Objects.equals(status, other.status) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateDeprecated, other.dateDeprecated) && + Objects.equals(retirementDate, other.retirementDate) && + Objects.equals(dateRetired, other.dateRetired) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + version, + status, + dateCreated, + dateDeprecated, + retirementDate, + dateRetired + ); + } + } + + @JsonDeserialize(builder = OperatorContext.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorContext { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memory") + @Getter + private final OperatorContextMemory memory; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge") + @Getter + private final OperatorContextKnowledge knowledge; + + private OperatorContext(Builder builder) { + this.memory = builder.memory; + this.knowledge = builder.knowledge; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperatorContext fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorContext.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("memory") + private OperatorContextMemory memory; + + @JsonProperty("knowledge") + private OperatorContextKnowledge knowledge; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("memory") + public Builder memory(OperatorContextMemory memory) { + this.memory = memory; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge") + public Builder knowledge(OperatorContextKnowledge knowledge) { + this.knowledge = knowledge; + return this; + } + + public OperatorContext build() { + return new OperatorContext(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorContext other = (OperatorContext) o; + return ( + Objects.equals(memory, other.memory) && + Objects.equals(knowledge, other.knowledge) + ); + } + + @Override + public int hashCode() { + return Objects.hash(memory, knowledge); + } + } + + @JsonDeserialize(builder = OperatorContextKnowledge.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorContextKnowledge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + @Getter + private final Boolean enabled; + + private OperatorContextKnowledge(Builder builder) { + this.enabled = builder.enabled; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperatorContextKnowledge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorContextKnowledge.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("enabled") + private Boolean enabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + public Builder enabled(Boolean enabled) { + this.enabled = enabled; + return this; + } + + public OperatorContextKnowledge build() { + return new OperatorContextKnowledge(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorContextKnowledge other = (OperatorContextKnowledge) o; + return (Objects.equals(enabled, other.enabled)); + } + + @Override + public int hashCode() { + return Objects.hash(enabled); + } + } + + @JsonDeserialize(builder = OperatorTrainingExample.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorTrainingExample { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("input") + @Getter + private final String input; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("output") + @Getter + private final String output; + + private OperatorTrainingExample(Builder builder) { + this.input = builder.input; + this.output = builder.output; + } + + public static Builder builder(final String input, final String output) { + return new Builder(input, output); + } + + public static OperatorTrainingExample fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorTrainingExample.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("input") + private String input; + + @JsonProperty("output") + private String output; + + @JsonCreator + public Builder( + @JsonProperty("input") final String input, + @JsonProperty("output") final String output + ) { + this.input = input; + this.output = output; + } + + public OperatorTrainingExample build() { + return new OperatorTrainingExample(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorTrainingExample other = (OperatorTrainingExample) o; + return ( + Objects.equals(input, other.input) && + Objects.equals(output, other.output) + ); + } + + @Override + public int hashCode() { + return Objects.hash(input, output); + } + } + + @JsonDeserialize(builder = OperatorContextMemory.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperatorContextMemory { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + @Getter + private final Boolean enabled; + + private OperatorContextMemory(Builder builder) { + this.enabled = builder.enabled; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperatorContextMemory fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperatorContextMemory.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("enabled") + private Boolean enabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enabled") + public Builder enabled(Boolean enabled) { + this.enabled = enabled; + return this; + } + + public OperatorContextMemory build() { + return new OperatorContextMemory(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperatorContextMemory other = (OperatorContextMemory) o; + return (Objects.equals(enabled, other.enabled)); + } + + @Override + public int hashCode() { + return Objects.hash(enabled); + } + } + + /** + * Converts a JSON String into a Version object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Version object represented by the provided JSON + */ + public static Version fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Version.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Version object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Version object represented by the provided JSON + */ + public static Version fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Version.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Version() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/VersionFetcher.java b/src/main/java/com/twilio/rest/intelligence/v3/VersionFetcher.java new file mode 100644 index 0000000000..4cb97aa0c9 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/VersionFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class VersionFetcher extends Fetcher { + + private String pathId; + private Integer pathVersion; + + public VersionFetcher(final String pathId, final Integer pathVersion) { + this.pathId = pathId; + this.pathVersion = pathVersion; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Operators/{id}/Versions/{version}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + path = path.replace("{" + "version" + "}", this.pathVersion.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Version fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Version.FetchVersionResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Version.FetchVersionResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Version.FetchVersionResponse content = + Version.FetchVersionResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/intelligence/v3/VersionReader.java b/src/main/java/com/twilio/rest/intelligence/v3/VersionReader.java new file mode 100644 index 0000000000..94f6a184d5 --- /dev/null +++ b/src/main/java/com/twilio/rest/intelligence/v3/VersionReader.java @@ -0,0 +1,249 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Conversational Intelligence API + * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.intelligence.v3; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class VersionReader extends Reader { + + private String pathId; + private Integer pageSize; + private String pageToken; + + public VersionReader(final String pathId) { + this.pathId = pathId; + } + + public VersionReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public VersionReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + Version.ListVersionResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v3/ControlPlane/Operators/{id}/Versions"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + Version.ListVersionResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Version read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "items", + response.getContent(), + Version.ListVersionResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/ControlPlane/Operators/{id}/Versions"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v3/ControlPlane/Operators/{id}/Versions"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.INTELLIGENCE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/Credential.java b/src/main/java/com/twilio/rest/ipmessaging/v1/Credential.java index f1a73642ac..a618ecd7f8 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/Credential.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/Credential.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; @@ -10,32 +17,52 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Credential extends Resource { - private static final long serialVersionUID = 133884911230690L; + + public static CredentialCreator creator(final Credential.PushService type) { + return new CredentialCreator(type); + } + + public static CredentialDeleter deleter(final String pathSid) { + return new CredentialDeleter(pathSid); + } + + public static CredentialFetcher fetcher(final String pathSid) { + return new CredentialFetcher(pathSid); + } + + public static CredentialReader reader() { + return new CredentialReader(); + } + + public static CredentialUpdater updater(final String pathSid) { + return new CredentialUpdater(pathSid); + } public enum PushService { GCM("gcm"), @@ -48,15 +75,11 @@ private PushService(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a PushService from a string. - * @param value string value - * @return generated PushService - */ @JsonCreator public static PushService forValue(final String value) { return Promoter.enumFromString(value, PushService.values()); @@ -64,63 +87,16 @@ public static PushService forValue(final String value) { } /** - * Create a CredentialReader to execute read. - * - * @return CredentialReader capable of executing the read - */ - public static CredentialReader reader() { - return new CredentialReader(); - } - - /** - * Create a CredentialCreator to execute create. - * - * @param type Credential type, one of "gcm" or "apn" - * @return CredentialCreator capable of executing the create - */ - public static CredentialCreator creator(final Credential.PushService type) { - return new CredentialCreator(type); - } - - /** - * Create a CredentialFetcher to execute fetch. - * - * @param pathSid The sid - * @return CredentialFetcher capable of executing the fetch - */ - public static CredentialFetcher fetcher(final String pathSid) { - return new CredentialFetcher(pathSid); - } - - /** - * Create a CredentialUpdater to execute update. - * - * @param pathSid The sid - * @return CredentialUpdater capable of executing the update - */ - public static CredentialUpdater updater(final String pathSid) { - return new CredentialUpdater(pathSid); - } - - /** - * Create a CredentialDeleter to execute delete. - * - * @param pathSid The sid - * @return CredentialDeleter capable of executing the delete - */ - public static CredentialDeleter deleter(final String pathSid) { - return new CredentialDeleter(pathSid); - } - - /** - * Converts a JSON String into a Credential object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -134,12 +110,15 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a Credential object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -150,119 +129,73 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final Credential.PushService type; + + @Getter private final String sandbox; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final Credential.PushService type; + + @Getter private final URI url; @JsonCreator - private Credential(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Credential.PushService type, - @JsonProperty("sandbox") - final String sandbox, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Credential( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.type = type; this.sandbox = sandbox; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.sid = sid; + this.type = type; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account[/console] responsible for this - * resource.. - * - * @return The unique id of the Account[/console] responsible for this resource. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The human-readable name of this resource.. - * - * @return The human-readable name of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The Indicates which push notifications service this credential is for - * - either gcm or apn. - * - * @return Indicates which push notifications service this credential is for - - * either gcm or apn - */ - public final Credential.PushService getType() { - return this.type; - } - - /** - * Returns The [APN only] true when this resource should use the sandbox APN - * service.. - * - * @return [APN only] true when this resource should use the sandbox APN - * service. - */ - public final String getSandbox() { - return this.sandbox; - } - - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The An absolute URL for this credential resource.. - * - * @return An absolute URL for this credential resource. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -274,40 +207,29 @@ public boolean equals(final Object o) { } Credential other = (Credential) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(sandbox, other.sandbox) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - type, - sandbox, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("sandbox", sandbox) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sandbox, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialCreator.java index bb7db23c72..b19ace211e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,9 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialCreator extends Creator { - private final Credential.PushService type; + + private Credential.PushService type; private String friendlyName; private String certificate; private String privateKey; @@ -26,161 +40,166 @@ public class CredentialCreator extends Creator { private String apiKey; private String secret; - /** - * Construct a new CredentialCreator. - * - * @param type Credential type, one of "gcm" or "apn" - */ public CredentialCreator(final Credential.PushService type) { this.type = type; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ + public CredentialCreator setType(final Credential.PushService type) { + this.type = type; + return this; + } + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate, e.g. `-----BEGIN - * CERTIFICATE-----MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A==-----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate, - * e. - * @return this - */ public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key, e.g. `-----BEGIN - * RSA PRIVATE - * KEY-----MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR\n.-----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key, - * e. - * @return this - */ public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "API key" for project from Google Developer console - * for your GCM Service application credential. - * - * @param apiKey [GCM only] This is the "API key" for project from Google - * Developer console for your GCM Service application credential - * @return this - */ public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * The secret. - * - * @param secret The secret - * @return this - */ public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials"; + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Credentials", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialDeleter.java index b3625362cb..2f1afb9532 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class CredentialDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new CredentialDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialFetcher.java index db6d1bfc45..5be1b8d014 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new CredentialFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialReader.java index b3b81f377b..d59f2f3bb3 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public CredentialReader() {} + + public CredentialReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Credentials"; + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Credentials", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Credential Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credentials", - response.getContent(), - Credential.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialUpdater.java index f7af945678..be8d40428c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/CredentialUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,9 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String certificate; private String privateKey; @@ -26,157 +40,154 @@ public class CredentialUpdater extends Updater { private String apiKey; private String secret; - /** - * Construct a new CredentialUpdater. - * - * @param pathSid The sid - */ public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate, e.g. `-----BEGIN - * CERTIFICATE-----MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A==-----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate, - * e. - * @return this - */ public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key, e.g. `-----BEGIN - * RSA PRIVATE - * KEY-----MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR\n.-----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key, - * e. - * @return this - */ public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "API key" for project from Google Developer console - * for your GCM Service application credential. - * - * @param apiKey [GCM only] This is the "API key" for project from Google - * Developer console for your GCM Service application credential - * @return this - */ public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * The secret. - * - * @param secret The secret - * @return this - */ public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Credential update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/Service.java b/src/main/java/com/twilio/rest/ipmessaging/v1/Service.java index 5e13b45e29..2a8365115e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/Service.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/Service.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; @@ -11,90 +18,63 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Service extends Resource { - private static final long serialVersionUID = 209287578457944L; - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid The sid - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); + public static ServiceCreator creator(final String friendlyName) { + return new ServiceCreator(friendlyName); } - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid The sid - * @return ServiceDeleter capable of executing the delete - */ public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - /** - * Create a ServiceCreator to execute create. - * - * @param friendlyName Human-readable name for this service instance - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator(final String friendlyName) { - return new ServiceCreator(friendlyName); + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); } - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ public static ServiceReader reader() { return new ServiceReader(); } - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid The sid - * @return ServiceUpdater capable of executing the update - */ public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** * Converts a JSON String into a Service object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -108,12 +88,15 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Service object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -124,296 +107,146 @@ public static Service fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String defaultServiceRoleSid; - private final String defaultChannelRoleSid; - private final String defaultChannelCreatorRoleSid; - private final Boolean readStatusEnabled; - private final Boolean reachabilityEnabled; - private final Integer typingIndicatorTimeout; - private final Integer consumptionReportInterval; - private final Map limits; - private final Map webhooks; - private final String preWebhookUrl; - private final String postWebhookUrl; - private final String webhookMethod; - private final List webhookFilters; - private final Map notifications; - private final URI url; - private final Map links; - - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("default_service_role_sid") - final String defaultServiceRoleSid, - @JsonProperty("default_channel_role_sid") - final String defaultChannelRoleSid, - @JsonProperty("default_channel_creator_role_sid") - final String defaultChannelCreatorRoleSid, - @JsonProperty("read_status_enabled") - final Boolean readStatusEnabled, - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled, - @JsonProperty("typing_indicator_timeout") - final Integer typingIndicatorTimeout, - @JsonProperty("consumption_report_interval") - final Integer consumptionReportInterval, - @JsonProperty("limits") - final Map limits, - @JsonProperty("webhooks") - final Map webhooks, - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - @JsonProperty("webhook_method") - final String webhookMethod, - @JsonProperty("webhook_filters") - final List webhookFilters, - @JsonProperty("notifications") - final Map notifications, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.defaultServiceRoleSid = defaultServiceRoleSid; - this.defaultChannelRoleSid = defaultChannelRoleSid; - this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; - this.readStatusEnabled = readStatusEnabled; - this.reachabilityEnabled = reachabilityEnabled; - this.typingIndicatorTimeout = typingIndicatorTimeout; - this.consumptionReportInterval = consumptionReportInterval; - this.limits = limits; - this.webhooks = webhooks; - this.preWebhookUrl = preWebhookUrl; - this.postWebhookUrl = postWebhookUrl; - this.webhookMethod = webhookMethod; - this.webhookFilters = webhookFilters; - this.notifications = notifications; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this service.. - * - * @return The unique id of the Account responsible for this service. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Integer consumptionReportInterval; - /** - * Returns The The human-readable name of this service.. - * - * @return The human-readable name of this service. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String defaultChannelCreatorRoleSid; - /** - * Returns The The service role assigned to users when they are added to the - * service.. - * - * @return The service role assigned to users when they are added to the - * service. - */ - public final String getDefaultServiceRoleSid() { - return this.defaultServiceRoleSid; - } + @Getter + private final String defaultChannelRoleSid; - /** - * Returns The The channel role assigned to users when they are added to a - * channel.. - * - * @return The channel role assigned to users when they are added to a channel. - */ - public final String getDefaultChannelRoleSid() { - return this.defaultChannelRoleSid; - } + @Getter + private final String defaultServiceRoleSid; - /** - * Returns The The channel role assigned to a channel creator when joining a new - * channel.. - * - * @return The channel role assigned to a channel creator when joining a new - * channel. - */ - public final String getDefaultChannelCreatorRoleSid() { - return this.defaultChannelCreatorRoleSid; - } + @Getter + private final String friendlyName; - /** - * Returns The Enable the Message Constumption Horizon feature.. - * - * @return Enable the Message Constumption Horizon feature. - */ - public final Boolean getReadStatusEnabled() { - return this.readStatusEnabled; - } + @Getter + private final Object limits; - /** - * Returns The Indicates whether the the Reachability feature is enabled for - * this Service instance.. - * - * @return Indicates whether the the Reachability feature is enabled for this - * Service instance. - */ - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } + @Getter + private final Map links; - /** - * Returns The The amount of time after a "started typing" event when clients - * should assume that user is no longer typing, even if no "ended typing" - * message was received.. - * - * @return The amount of time after a "started typing" event when clients - * should assume that user is no longer typing, even if no "ended - * typing" message was received. - */ - public final Integer getTypingIndicatorTimeout() { - return this.typingIndicatorTimeout; - } + @Getter + private final Object notifications; - /** - * Returns The The interval between consumption reports submission batches from - * client endpoints.. - * - * @return The interval between consumption reports submission batches from - * client endpoints. - */ - public final Integer getConsumptionReportInterval() { - return this.consumptionReportInterval; - } + @Getter + private final String postWebhookUrl; - /** - * Returns The The limits. - * - * @return The limits - */ - public final Map getLimits() { - return this.limits; - } + @Getter + private final String preWebhookUrl; - /** - * Returns The The webhooks. - * - * @return The webhooks - */ - public final Map getWebhooks() { - return this.webhooks; - } + @Getter + private final Boolean reachabilityEnabled; - /** - * Returns The The webhook URL for PRE-Event webhooks.. - * - * @return The webhook URL for PRE-Event webhooks. - */ - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } + @Getter + private final Boolean readStatusEnabled; - /** - * Returns The The webhook URL for POST-Event webhooks.. - * - * @return The webhook URL for POST-Event webhooks. - */ - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } + @Getter + private final String sid; - /** - * Returns The The webhook request format to use.. - * - * @return The webhook request format to use. - */ - public final String getWebhookMethod() { - return this.webhookMethod; - } + @Getter + private final Integer typingIndicatorTimeout; - /** - * Returns The The list of WebHook events that are enabled for this Service - * instance.. - * - * @return The list of WebHook events that are enabled for this Service - * instance. - */ - public final List getWebhookFilters() { - return this.webhookFilters; - } + @Getter + private final URI url; - /** - * Returns The Notification configuration for the Service instance.. - * - * @return Notification configuration for the Service instance. - */ - public final Map getNotifications() { - return this.notifications; - } + @Getter + private final List webhookFilters; - /** - * Returns The An absolute URL for this service.. - * - * @return An absolute URL for this service. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String webhookMethod; - /** - * Returns The URLs to access the Channels, Roles, and Users for this service.. - * - * @return URLs to access the Channels, Roles, and Users for this service. - */ - public final Map getLinks() { - return this.links; + @Getter + private final Object webhooks; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "consumption_report_interval" + ) final Integer consumptionReportInterval, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "default_channel_creator_role_sid" + ) final String defaultChannelCreatorRoleSid, + @JsonProperty( + "default_channel_role_sid" + ) final String defaultChannelRoleSid, + @JsonProperty( + "default_service_role_sid" + ) final String defaultServiceRoleSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("limits") final Object limits, + @JsonProperty("links") final Map links, + @JsonProperty("notifications") final Object notifications, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty("read_status_enabled") final Boolean readStatusEnabled, + @JsonProperty("sid") final String sid, + @JsonProperty( + "typing_indicator_timeout" + ) final Integer typingIndicatorTimeout, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_filters") final List webhookFilters, + @JsonProperty("webhook_method") final String webhookMethod, + @JsonProperty("webhooks") final Object webhooks + ) { + this.accountSid = accountSid; + this.consumptionReportInterval = consumptionReportInterval; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; + this.defaultChannelRoleSid = defaultChannelRoleSid; + this.defaultServiceRoleSid = defaultServiceRoleSid; + this.friendlyName = friendlyName; + this.limits = limits; + this.links = links; + this.notifications = notifications; + this.postWebhookUrl = postWebhookUrl; + this.preWebhookUrl = preWebhookUrl; + this.reachabilityEnabled = reachabilityEnabled; + this.readStatusEnabled = readStatusEnabled; + this.sid = sid; + this.typingIndicatorTimeout = typingIndicatorTimeout; + this.url = url; + this.webhookFilters = webhookFilters; + this.webhookMethod = webhookMethod; + this.webhooks = webhooks; } @Override @@ -427,79 +260,70 @@ public boolean equals(final Object o) { } Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(defaultServiceRoleSid, other.defaultServiceRoleSid) && - Objects.equals(defaultChannelRoleSid, other.defaultChannelRoleSid) && - Objects.equals(defaultChannelCreatorRoleSid, other.defaultChannelCreatorRoleSid) && - Objects.equals(readStatusEnabled, other.readStatusEnabled) && - Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && - Objects.equals(typingIndicatorTimeout, other.typingIndicatorTimeout) && - Objects.equals(consumptionReportInterval, other.consumptionReportInterval) && - Objects.equals(limits, other.limits) && - Objects.equals(webhooks, other.webhooks) && - Objects.equals(preWebhookUrl, other.preWebhookUrl) && - Objects.equals(postWebhookUrl, other.postWebhookUrl) && - Objects.equals(webhookMethod, other.webhookMethod) && - Objects.equals(webhookFilters, other.webhookFilters) && - Objects.equals(notifications, other.notifications) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + consumptionReportInterval, + other.consumptionReportInterval + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultChannelCreatorRoleSid, + other.defaultChannelCreatorRoleSid + ) && + Objects.equals( + defaultChannelRoleSid, + other.defaultChannelRoleSid + ) && + Objects.equals( + defaultServiceRoleSid, + other.defaultServiceRoleSid + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(limits, other.limits) && + Objects.equals(links, other.links) && + Objects.equals(notifications, other.notifications) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals(readStatusEnabled, other.readStatusEnabled) && + Objects.equals(sid, other.sid) && + Objects.equals( + typingIndicatorTimeout, + other.typingIndicatorTimeout + ) && + Objects.equals(url, other.url) && + Objects.equals(webhookFilters, other.webhookFilters) && + Objects.equals(webhookMethod, other.webhookMethod) && + Objects.equals(webhooks, other.webhooks) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - defaultServiceRoleSid, - defaultChannelRoleSid, - defaultChannelCreatorRoleSid, - readStatusEnabled, - reachabilityEnabled, - typingIndicatorTimeout, - consumptionReportInterval, - limits, - webhooks, - preWebhookUrl, - postWebhookUrl, - webhookMethod, - webhookFilters, - notifications, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("defaultServiceRoleSid", defaultServiceRoleSid) - .add("defaultChannelRoleSid", defaultChannelRoleSid) - .add("defaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid) - .add("readStatusEnabled", readStatusEnabled) - .add("reachabilityEnabled", reachabilityEnabled) - .add("typingIndicatorTimeout", typingIndicatorTimeout) - .add("consumptionReportInterval", consumptionReportInterval) - .add("limits", limits) - .add("webhooks", webhooks) - .add("preWebhookUrl", preWebhookUrl) - .add("postWebhookUrl", postWebhookUrl) - .add("webhookMethod", webhookMethod) - .add("webhookFilters", webhookFilters) - .add("notifications", notifications) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + consumptionReportInterval, + dateCreated, + dateUpdated, + defaultChannelCreatorRoleSid, + defaultChannelRoleSid, + defaultServiceRoleSid, + friendlyName, + limits, + links, + notifications, + postWebhookUrl, + preWebhookUrl, + reachabilityEnabled, + readStatusEnabled, + sid, + typingIndicatorTimeout, + url, + webhookFilters, + webhookMethod, + webhooks + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceCreator.java index c697801ce7..150ee7e5ef 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +27,86 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceCreator extends Creator { - private final String friendlyName; - /** - * Construct a new ServiceCreator. - * - * @param friendlyName Human-readable name for this service instance - */ + private String friendlyName; + public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceDeleter.java index c915029729..a3063eb681 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ServiceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new ServiceDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceFetcher.java index 5f202e829a..71288be92c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new ServiceFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceReader.java index 33646ea463..bea6d762be 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceUpdater.java index e5f1e7c945..f5d598bda2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/ServiceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class ServiceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String defaultServiceRoleSid; private String defaultChannelRoleSid; @@ -45,1382 +58,1103 @@ public class ServiceUpdater extends Updater { private List webhookFilters; private URI webhooksOnMessageSendUrl; private HttpMethod webhooksOnMessageSendMethod; - private String webhooksOnMessageSendFormat; private URI webhooksOnMessageUpdateUrl; private HttpMethod webhooksOnMessageUpdateMethod; - private String webhooksOnMessageUpdateFormat; private URI webhooksOnMessageRemoveUrl; private HttpMethod webhooksOnMessageRemoveMethod; - private String webhooksOnMessageRemoveFormat; private URI webhooksOnChannelAddUrl; private HttpMethod webhooksOnChannelAddMethod; - private String webhooksOnChannelAddFormat; private URI webhooksOnChannelDestroyUrl; private HttpMethod webhooksOnChannelDestroyMethod; - private String webhooksOnChannelDestroyFormat; private URI webhooksOnChannelUpdateUrl; private HttpMethod webhooksOnChannelUpdateMethod; - private String webhooksOnChannelUpdateFormat; private URI webhooksOnMemberAddUrl; private HttpMethod webhooksOnMemberAddMethod; - private String webhooksOnMemberAddFormat; private URI webhooksOnMemberRemoveUrl; private HttpMethod webhooksOnMemberRemoveMethod; - private String webhooksOnMemberRemoveFormat; private URI webhooksOnMessageSentUrl; private HttpMethod webhooksOnMessageSentMethod; - private String webhooksOnMessageSentFormat; private URI webhooksOnMessageUpdatedUrl; private HttpMethod webhooksOnMessageUpdatedMethod; - private String webhooksOnMessageUpdatedFormat; private URI webhooksOnMessageRemovedUrl; private HttpMethod webhooksOnMessageRemovedMethod; - private String webhooksOnMessageRemovedFormat; private URI webhooksOnChannelAddedUrl; private HttpMethod webhooksOnChannelAddedMethod; - private String webhooksOnChannelAddedFormat; private URI webhooksOnChannelDestroyedUrl; private HttpMethod webhooksOnChannelDestroyedMethod; - private String webhooksOnChannelDestroyedFormat; private URI webhooksOnChannelUpdatedUrl; private HttpMethod webhooksOnChannelUpdatedMethod; - private String webhooksOnChannelUpdatedFormat; private URI webhooksOnMemberAddedUrl; private HttpMethod webhooksOnMemberAddedMethod; - private String webhooksOnMemberAddedFormat; private URI webhooksOnMemberRemovedUrl; private HttpMethod webhooksOnMemberRemovedMethod; - private String webhooksOnMemberRemovedFormat; private Integer limitsChannelMembers; private Integer limitsUserChannels; - /** - * Construct a new ServiceUpdater. - * - * @param pathSid The sid - */ public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Human-readable name for this service instance. - * - * @param friendlyName Human-readable name for this service instance - * @return this - */ public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The default_service_role_sid. - * - * @param defaultServiceRoleSid The default_service_role_sid - * @return this - */ - public ServiceUpdater setDefaultServiceRoleSid(final String defaultServiceRoleSid) { + public ServiceUpdater setDefaultServiceRoleSid( + final String defaultServiceRoleSid + ) { this.defaultServiceRoleSid = defaultServiceRoleSid; return this; } - /** - * Channel role assigned on channel join (see - * [Roles](https://www.twilio.com/docs/api/chat/rest/v1/roles) data model for - * the details). - * - * @param defaultChannelRoleSid Channel role assigned on channel join - * @return this - */ - public ServiceUpdater setDefaultChannelRoleSid(final String defaultChannelRoleSid) { + public ServiceUpdater setDefaultChannelRoleSid( + final String defaultChannelRoleSid + ) { this.defaultChannelRoleSid = defaultChannelRoleSid; return this; } - /** - * Channel role assigned to creator of channel when joining for first time. - * - * @param defaultChannelCreatorRoleSid Channel role assigned to creator of - * channel when joining for first time - * @return this - */ - public ServiceUpdater setDefaultChannelCreatorRoleSid(final String defaultChannelCreatorRoleSid) { + public ServiceUpdater setDefaultChannelCreatorRoleSid( + final String defaultChannelCreatorRoleSid + ) { this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; return this; } - /** - * `true` if the member read status feature is enabled, `false` if not. - * Defaults to `true`.. - * - * @param readStatusEnabled true if the member read status feature is enabled, - * false if not. - * @return this - */ - public ServiceUpdater setReadStatusEnabled(final Boolean readStatusEnabled) { + public ServiceUpdater setReadStatusEnabled( + final Boolean readStatusEnabled + ) { this.readStatusEnabled = readStatusEnabled; return this; } - /** - * `true` if the reachability feature should be enabled. Defaults to `false`. - * - * @param reachabilityEnabled true if the reachability feature should be - * enabled. - * @return this - */ - public ServiceUpdater setReachabilityEnabled(final Boolean reachabilityEnabled) { + public ServiceUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } - /** - * ISO 8601 duration indicating the timeout after "started typing" event when - * client should assume that user is not typing anymore even if no "ended - * typing" message received. - * - * @param typingIndicatorTimeout ISO 8601 duration indicating the timeout after - * "started typing" event when client should - * assume that user is not typing anymore even if - * no "ended typing" message received - * @return this - */ - public ServiceUpdater setTypingIndicatorTimeout(final Integer typingIndicatorTimeout) { + public ServiceUpdater setTypingIndicatorTimeout( + final Integer typingIndicatorTimeout + ) { this.typingIndicatorTimeout = typingIndicatorTimeout; return this; } - /** - * ISO 8601 duration indicating the interval between consumption reports sent - * from client endpoints.. - * - * @param consumptionReportInterval ISO 8601 duration indicating the interval - * between consumption reports sent from client - * endpoints. - * @return this - */ - public ServiceUpdater setConsumptionReportInterval(final Integer consumptionReportInterval) { + public ServiceUpdater setConsumptionReportInterval( + final Integer consumptionReportInterval + ) { this.consumptionReportInterval = consumptionReportInterval; return this; } - /** - * The notifications.new_message.enabled. - * - * @param notificationsNewMessageEnabled The notifications.new_message.enabled - * @return this - */ - public ServiceUpdater setNotificationsNewMessageEnabled(final Boolean notificationsNewMessageEnabled) { + public ServiceUpdater setNotificationsNewMessageEnabled( + final Boolean notificationsNewMessageEnabled + ) { this.notificationsNewMessageEnabled = notificationsNewMessageEnabled; return this; } - /** - * The notifications.new_message.template. - * - * @param notificationsNewMessageTemplate The notifications.new_message.template - * @return this - */ - public ServiceUpdater setNotificationsNewMessageTemplate(final String notificationsNewMessageTemplate) { + public ServiceUpdater setNotificationsNewMessageTemplate( + final String notificationsNewMessageTemplate + ) { this.notificationsNewMessageTemplate = notificationsNewMessageTemplate; return this; } - /** - * The notifications.added_to_channel.enabled. - * - * @param notificationsAddedToChannelEnabled The - * notifications.added_to_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelEnabled(final Boolean notificationsAddedToChannelEnabled) { - this.notificationsAddedToChannelEnabled = notificationsAddedToChannelEnabled; + public ServiceUpdater setNotificationsAddedToChannelEnabled( + final Boolean notificationsAddedToChannelEnabled + ) { + this.notificationsAddedToChannelEnabled = + notificationsAddedToChannelEnabled; return this; } - /** - * The notifications.added_to_channel.template. - * - * @param notificationsAddedToChannelTemplate The - * notifications.added_to_channel.template - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelTemplate(final String notificationsAddedToChannelTemplate) { - this.notificationsAddedToChannelTemplate = notificationsAddedToChannelTemplate; + public ServiceUpdater setNotificationsAddedToChannelTemplate( + final String notificationsAddedToChannelTemplate + ) { + this.notificationsAddedToChannelTemplate = + notificationsAddedToChannelTemplate; return this; } - /** - * The notifications.removed_from_channel.enabled. - * - * @param notificationsRemovedFromChannelEnabled The - * notifications.removed_from_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelEnabled(final Boolean notificationsRemovedFromChannelEnabled) { - this.notificationsRemovedFromChannelEnabled = notificationsRemovedFromChannelEnabled; + public ServiceUpdater setNotificationsRemovedFromChannelEnabled( + final Boolean notificationsRemovedFromChannelEnabled + ) { + this.notificationsRemovedFromChannelEnabled = + notificationsRemovedFromChannelEnabled; return this; } - /** - * The notifications.removed_from_channel.template. - * - * @param notificationsRemovedFromChannelTemplate The - * notifications.removed_from_channel.template - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelTemplate(final String notificationsRemovedFromChannelTemplate) { - this.notificationsRemovedFromChannelTemplate = notificationsRemovedFromChannelTemplate; + public ServiceUpdater setNotificationsRemovedFromChannelTemplate( + final String notificationsRemovedFromChannelTemplate + ) { + this.notificationsRemovedFromChannelTemplate = + notificationsRemovedFromChannelTemplate; return this; } - /** - * The notifications.invited_to_channel.enabled. - * - * @param notificationsInvitedToChannelEnabled The - * notifications.invited_to_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelEnabled(final Boolean notificationsInvitedToChannelEnabled) { - this.notificationsInvitedToChannelEnabled = notificationsInvitedToChannelEnabled; + public ServiceUpdater setNotificationsInvitedToChannelEnabled( + final Boolean notificationsInvitedToChannelEnabled + ) { + this.notificationsInvitedToChannelEnabled = + notificationsInvitedToChannelEnabled; return this; } - /** - * The notifications.invited_to_channel.template. - * - * @param notificationsInvitedToChannelTemplate The - * notifications.invited_to_channel.template - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelTemplate(final String notificationsInvitedToChannelTemplate) { - this.notificationsInvitedToChannelTemplate = notificationsInvitedToChannelTemplate; + public ServiceUpdater setNotificationsInvitedToChannelTemplate( + final String notificationsInvitedToChannelTemplate + ) { + this.notificationsInvitedToChannelTemplate = + notificationsInvitedToChannelTemplate; return this; } - /** - * The webhook URL for PRE-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param preWebhookUrl The webhook URL for PRE-Event webhooks. - * @return this - */ public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - /** - * The webhook URL for PRE-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param preWebhookUrl The webhook URL for PRE-Event webhooks. - * @return this - */ public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - /** - * The webhook URL for POST-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param postWebhookUrl The webhook URL for POST-Event webhooks. - * @return this - */ public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - /** - * The webhook URL for POST-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param postWebhookUrl The webhook URL for POST-Event webhooks. - * @return this - */ public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - /** - * The webhook request format to use. Must be POST or GET. See [Webhook - * Events](https://www.twilio.com/docs/api/chat/webhooks) for more details.. - * - * @param webhookMethod The webhook request format to use. - * @return this - */ public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod) { this.webhookMethod = webhookMethod; return this; } - /** - * The list of WebHook events that are enabled for this Service instance. See - * [Webhook Events](https://www.twilio.com/docs/api/chat/webhooks) for more - * details.. - * - * @param webhookFilters The list of WebHook events that are enabled for this - * Service instance. - * @return this - */ public ServiceUpdater setWebhookFilters(final List webhookFilters) { this.webhookFilters = webhookFilters; return this; } - /** - * The list of WebHook events that are enabled for this Service instance. See - * [Webhook Events](https://www.twilio.com/docs/api/chat/webhooks) for more - * details.. - * - * @param webhookFilters The list of WebHook events that are enabled for this - * Service instance. - * @return this - */ public ServiceUpdater setWebhookFilters(final String webhookFilters) { return setWebhookFilters(Promoter.listOfOne(webhookFilters)); } - /** - * The webhooks.on_message_send.url. - * - * @param webhooksOnMessageSendUrl The webhooks.on_message_send.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSendUrl(final URI webhooksOnMessageSendUrl) { + public ServiceUpdater setWebhooksOnMessageSendUrl( + final URI webhooksOnMessageSendUrl + ) { this.webhooksOnMessageSendUrl = webhooksOnMessageSendUrl; return this; } - /** - * The webhooks.on_message_send.url. - * - * @param webhooksOnMessageSendUrl The webhooks.on_message_send.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSendUrl(final String webhooksOnMessageSendUrl) { - return setWebhooksOnMessageSendUrl(Promoter.uriFromString(webhooksOnMessageSendUrl)); + public ServiceUpdater setWebhooksOnMessageSendUrl( + final String webhooksOnMessageSendUrl + ) { + return setWebhooksOnMessageSendUrl( + Promoter.uriFromString(webhooksOnMessageSendUrl) + ); } - /** - * The webhooks.on_message_send.method. - * - * @param webhooksOnMessageSendMethod The webhooks.on_message_send.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSendMethod(final HttpMethod webhooksOnMessageSendMethod) { + public ServiceUpdater setWebhooksOnMessageSendMethod( + final HttpMethod webhooksOnMessageSendMethod + ) { this.webhooksOnMessageSendMethod = webhooksOnMessageSendMethod; return this; } - /** - * The webhooks.on_message_send.format. - * - * @param webhooksOnMessageSendFormat The webhooks.on_message_send.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSendFormat(final String webhooksOnMessageSendFormat) { - this.webhooksOnMessageSendFormat = webhooksOnMessageSendFormat; - return this; - } - - /** - * The webhooks.on_message_update.url. - * - * @param webhooksOnMessageUpdateUrl The webhooks.on_message_update.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdateUrl(final URI webhooksOnMessageUpdateUrl) { + public ServiceUpdater setWebhooksOnMessageUpdateUrl( + final URI webhooksOnMessageUpdateUrl + ) { this.webhooksOnMessageUpdateUrl = webhooksOnMessageUpdateUrl; return this; } - /** - * The webhooks.on_message_update.url. - * - * @param webhooksOnMessageUpdateUrl The webhooks.on_message_update.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdateUrl(final String webhooksOnMessageUpdateUrl) { - return setWebhooksOnMessageUpdateUrl(Promoter.uriFromString(webhooksOnMessageUpdateUrl)); + public ServiceUpdater setWebhooksOnMessageUpdateUrl( + final String webhooksOnMessageUpdateUrl + ) { + return setWebhooksOnMessageUpdateUrl( + Promoter.uriFromString(webhooksOnMessageUpdateUrl) + ); } - /** - * The webhooks.on_message_update.method. - * - * @param webhooksOnMessageUpdateMethod The webhooks.on_message_update.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdateMethod(final HttpMethod webhooksOnMessageUpdateMethod) { + public ServiceUpdater setWebhooksOnMessageUpdateMethod( + final HttpMethod webhooksOnMessageUpdateMethod + ) { this.webhooksOnMessageUpdateMethod = webhooksOnMessageUpdateMethod; return this; } - /** - * The webhooks.on_message_update.format. - * - * @param webhooksOnMessageUpdateFormat The webhooks.on_message_update.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdateFormat(final String webhooksOnMessageUpdateFormat) { - this.webhooksOnMessageUpdateFormat = webhooksOnMessageUpdateFormat; - return this; - } - - /** - * The webhooks.on_message_remove.url. - * - * @param webhooksOnMessageRemoveUrl The webhooks.on_message_remove.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemoveUrl(final URI webhooksOnMessageRemoveUrl) { + public ServiceUpdater setWebhooksOnMessageRemoveUrl( + final URI webhooksOnMessageRemoveUrl + ) { this.webhooksOnMessageRemoveUrl = webhooksOnMessageRemoveUrl; return this; } - /** - * The webhooks.on_message_remove.url. - * - * @param webhooksOnMessageRemoveUrl The webhooks.on_message_remove.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemoveUrl(final String webhooksOnMessageRemoveUrl) { - return setWebhooksOnMessageRemoveUrl(Promoter.uriFromString(webhooksOnMessageRemoveUrl)); + public ServiceUpdater setWebhooksOnMessageRemoveUrl( + final String webhooksOnMessageRemoveUrl + ) { + return setWebhooksOnMessageRemoveUrl( + Promoter.uriFromString(webhooksOnMessageRemoveUrl) + ); } - /** - * The webhooks.on_message_remove.method. - * - * @param webhooksOnMessageRemoveMethod The webhooks.on_message_remove.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemoveMethod(final HttpMethod webhooksOnMessageRemoveMethod) { + public ServiceUpdater setWebhooksOnMessageRemoveMethod( + final HttpMethod webhooksOnMessageRemoveMethod + ) { this.webhooksOnMessageRemoveMethod = webhooksOnMessageRemoveMethod; return this; } - /** - * The webhooks.on_message_remove.format. - * - * @param webhooksOnMessageRemoveFormat The webhooks.on_message_remove.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemoveFormat(final String webhooksOnMessageRemoveFormat) { - this.webhooksOnMessageRemoveFormat = webhooksOnMessageRemoveFormat; - return this; - } - - /** - * The webhooks.on_channel_add.url. - * - * @param webhooksOnChannelAddUrl The webhooks.on_channel_add.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddUrl(final URI webhooksOnChannelAddUrl) { + public ServiceUpdater setWebhooksOnChannelAddUrl( + final URI webhooksOnChannelAddUrl + ) { this.webhooksOnChannelAddUrl = webhooksOnChannelAddUrl; return this; } - /** - * The webhooks.on_channel_add.url. - * - * @param webhooksOnChannelAddUrl The webhooks.on_channel_add.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddUrl(final String webhooksOnChannelAddUrl) { - return setWebhooksOnChannelAddUrl(Promoter.uriFromString(webhooksOnChannelAddUrl)); + public ServiceUpdater setWebhooksOnChannelAddUrl( + final String webhooksOnChannelAddUrl + ) { + return setWebhooksOnChannelAddUrl( + Promoter.uriFromString(webhooksOnChannelAddUrl) + ); } - /** - * The webhooks.on_channel_add.method. - * - * @param webhooksOnChannelAddMethod The webhooks.on_channel_add.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddMethod(final HttpMethod webhooksOnChannelAddMethod) { + public ServiceUpdater setWebhooksOnChannelAddMethod( + final HttpMethod webhooksOnChannelAddMethod + ) { this.webhooksOnChannelAddMethod = webhooksOnChannelAddMethod; return this; } - /** - * The webhooks.on_channel_add.format. - * - * @param webhooksOnChannelAddFormat The webhooks.on_channel_add.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddFormat(final String webhooksOnChannelAddFormat) { - this.webhooksOnChannelAddFormat = webhooksOnChannelAddFormat; - return this; - } - - /** - * The webhooks.on_channel_destroy.url. - * - * @param webhooksOnChannelDestroyUrl The webhooks.on_channel_destroy.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyUrl(final URI webhooksOnChannelDestroyUrl) { + public ServiceUpdater setWebhooksOnChannelDestroyUrl( + final URI webhooksOnChannelDestroyUrl + ) { this.webhooksOnChannelDestroyUrl = webhooksOnChannelDestroyUrl; return this; } - /** - * The webhooks.on_channel_destroy.url. - * - * @param webhooksOnChannelDestroyUrl The webhooks.on_channel_destroy.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyUrl(final String webhooksOnChannelDestroyUrl) { - return setWebhooksOnChannelDestroyUrl(Promoter.uriFromString(webhooksOnChannelDestroyUrl)); + public ServiceUpdater setWebhooksOnChannelDestroyUrl( + final String webhooksOnChannelDestroyUrl + ) { + return setWebhooksOnChannelDestroyUrl( + Promoter.uriFromString(webhooksOnChannelDestroyUrl) + ); } - /** - * The webhooks.on_channel_destroy.method. - * - * @param webhooksOnChannelDestroyMethod The webhooks.on_channel_destroy.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyMethod(final HttpMethod webhooksOnChannelDestroyMethod) { + public ServiceUpdater setWebhooksOnChannelDestroyMethod( + final HttpMethod webhooksOnChannelDestroyMethod + ) { this.webhooksOnChannelDestroyMethod = webhooksOnChannelDestroyMethod; return this; } - /** - * The webhooks.on_channel_destroy.format. - * - * @param webhooksOnChannelDestroyFormat The webhooks.on_channel_destroy.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyFormat(final String webhooksOnChannelDestroyFormat) { - this.webhooksOnChannelDestroyFormat = webhooksOnChannelDestroyFormat; - return this; - } - - /** - * The webhooks.on_channel_update.url. - * - * @param webhooksOnChannelUpdateUrl The webhooks.on_channel_update.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdateUrl(final URI webhooksOnChannelUpdateUrl) { + public ServiceUpdater setWebhooksOnChannelUpdateUrl( + final URI webhooksOnChannelUpdateUrl + ) { this.webhooksOnChannelUpdateUrl = webhooksOnChannelUpdateUrl; return this; } - /** - * The webhooks.on_channel_update.url. - * - * @param webhooksOnChannelUpdateUrl The webhooks.on_channel_update.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdateUrl(final String webhooksOnChannelUpdateUrl) { - return setWebhooksOnChannelUpdateUrl(Promoter.uriFromString(webhooksOnChannelUpdateUrl)); + public ServiceUpdater setWebhooksOnChannelUpdateUrl( + final String webhooksOnChannelUpdateUrl + ) { + return setWebhooksOnChannelUpdateUrl( + Promoter.uriFromString(webhooksOnChannelUpdateUrl) + ); } - /** - * The webhooks.on_channel_update.method. - * - * @param webhooksOnChannelUpdateMethod The webhooks.on_channel_update.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdateMethod(final HttpMethod webhooksOnChannelUpdateMethod) { + public ServiceUpdater setWebhooksOnChannelUpdateMethod( + final HttpMethod webhooksOnChannelUpdateMethod + ) { this.webhooksOnChannelUpdateMethod = webhooksOnChannelUpdateMethod; return this; } - /** - * The webhooks.on_channel_update.format. - * - * @param webhooksOnChannelUpdateFormat The webhooks.on_channel_update.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdateFormat(final String webhooksOnChannelUpdateFormat) { - this.webhooksOnChannelUpdateFormat = webhooksOnChannelUpdateFormat; - return this; - } - - /** - * The webhooks.on_member_add.url. - * - * @param webhooksOnMemberAddUrl The webhooks.on_member_add.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddUrl(final URI webhooksOnMemberAddUrl) { + public ServiceUpdater setWebhooksOnMemberAddUrl( + final URI webhooksOnMemberAddUrl + ) { this.webhooksOnMemberAddUrl = webhooksOnMemberAddUrl; return this; } - /** - * The webhooks.on_member_add.url. - * - * @param webhooksOnMemberAddUrl The webhooks.on_member_add.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddUrl(final String webhooksOnMemberAddUrl) { - return setWebhooksOnMemberAddUrl(Promoter.uriFromString(webhooksOnMemberAddUrl)); + public ServiceUpdater setWebhooksOnMemberAddUrl( + final String webhooksOnMemberAddUrl + ) { + return setWebhooksOnMemberAddUrl( + Promoter.uriFromString(webhooksOnMemberAddUrl) + ); } - /** - * The webhooks.on_member_add.method. - * - * @param webhooksOnMemberAddMethod The webhooks.on_member_add.method - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddMethod(final HttpMethod webhooksOnMemberAddMethod) { + public ServiceUpdater setWebhooksOnMemberAddMethod( + final HttpMethod webhooksOnMemberAddMethod + ) { this.webhooksOnMemberAddMethod = webhooksOnMemberAddMethod; return this; } - /** - * The webhooks.on_member_add.format. - * - * @param webhooksOnMemberAddFormat The webhooks.on_member_add.format - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddFormat(final String webhooksOnMemberAddFormat) { - this.webhooksOnMemberAddFormat = webhooksOnMemberAddFormat; - return this; - } - - /** - * The webhooks.on_member_remove.url. - * - * @param webhooksOnMemberRemoveUrl The webhooks.on_member_remove.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemoveUrl(final URI webhooksOnMemberRemoveUrl) { + public ServiceUpdater setWebhooksOnMemberRemoveUrl( + final URI webhooksOnMemberRemoveUrl + ) { this.webhooksOnMemberRemoveUrl = webhooksOnMemberRemoveUrl; return this; } - /** - * The webhooks.on_member_remove.url. - * - * @param webhooksOnMemberRemoveUrl The webhooks.on_member_remove.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemoveUrl(final String webhooksOnMemberRemoveUrl) { - return setWebhooksOnMemberRemoveUrl(Promoter.uriFromString(webhooksOnMemberRemoveUrl)); + public ServiceUpdater setWebhooksOnMemberRemoveUrl( + final String webhooksOnMemberRemoveUrl + ) { + return setWebhooksOnMemberRemoveUrl( + Promoter.uriFromString(webhooksOnMemberRemoveUrl) + ); } - /** - * The webhooks.on_member_remove.method. - * - * @param webhooksOnMemberRemoveMethod The webhooks.on_member_remove.method - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemoveMethod(final HttpMethod webhooksOnMemberRemoveMethod) { + public ServiceUpdater setWebhooksOnMemberRemoveMethod( + final HttpMethod webhooksOnMemberRemoveMethod + ) { this.webhooksOnMemberRemoveMethod = webhooksOnMemberRemoveMethod; return this; } - /** - * The webhooks.on_member_remove.format. - * - * @param webhooksOnMemberRemoveFormat The webhooks.on_member_remove.format - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemoveFormat(final String webhooksOnMemberRemoveFormat) { - this.webhooksOnMemberRemoveFormat = webhooksOnMemberRemoveFormat; - return this; - } - - /** - * The webhooks.on_message_sent.url. - * - * @param webhooksOnMessageSentUrl The webhooks.on_message_sent.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSentUrl(final URI webhooksOnMessageSentUrl) { + public ServiceUpdater setWebhooksOnMessageSentUrl( + final URI webhooksOnMessageSentUrl + ) { this.webhooksOnMessageSentUrl = webhooksOnMessageSentUrl; return this; } - /** - * The webhooks.on_message_sent.url. - * - * @param webhooksOnMessageSentUrl The webhooks.on_message_sent.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSentUrl(final String webhooksOnMessageSentUrl) { - return setWebhooksOnMessageSentUrl(Promoter.uriFromString(webhooksOnMessageSentUrl)); + public ServiceUpdater setWebhooksOnMessageSentUrl( + final String webhooksOnMessageSentUrl + ) { + return setWebhooksOnMessageSentUrl( + Promoter.uriFromString(webhooksOnMessageSentUrl) + ); } - /** - * The webhooks.on_message_sent.method. - * - * @param webhooksOnMessageSentMethod The webhooks.on_message_sent.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSentMethod(final HttpMethod webhooksOnMessageSentMethod) { + public ServiceUpdater setWebhooksOnMessageSentMethod( + final HttpMethod webhooksOnMessageSentMethod + ) { this.webhooksOnMessageSentMethod = webhooksOnMessageSentMethod; return this; } - /** - * The webhooks.on_message_sent.format. - * - * @param webhooksOnMessageSentFormat The webhooks.on_message_sent.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageSentFormat(final String webhooksOnMessageSentFormat) { - this.webhooksOnMessageSentFormat = webhooksOnMessageSentFormat; - return this; - } - - /** - * The webhooks.on_message_updated.url. - * - * @param webhooksOnMessageUpdatedUrl The webhooks.on_message_updated.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdatedUrl(final URI webhooksOnMessageUpdatedUrl) { + public ServiceUpdater setWebhooksOnMessageUpdatedUrl( + final URI webhooksOnMessageUpdatedUrl + ) { this.webhooksOnMessageUpdatedUrl = webhooksOnMessageUpdatedUrl; return this; } - /** - * The webhooks.on_message_updated.url. - * - * @param webhooksOnMessageUpdatedUrl The webhooks.on_message_updated.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdatedUrl(final String webhooksOnMessageUpdatedUrl) { - return setWebhooksOnMessageUpdatedUrl(Promoter.uriFromString(webhooksOnMessageUpdatedUrl)); + public ServiceUpdater setWebhooksOnMessageUpdatedUrl( + final String webhooksOnMessageUpdatedUrl + ) { + return setWebhooksOnMessageUpdatedUrl( + Promoter.uriFromString(webhooksOnMessageUpdatedUrl) + ); } - /** - * The webhooks.on_message_updated.method. - * - * @param webhooksOnMessageUpdatedMethod The webhooks.on_message_updated.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdatedMethod(final HttpMethod webhooksOnMessageUpdatedMethod) { + public ServiceUpdater setWebhooksOnMessageUpdatedMethod( + final HttpMethod webhooksOnMessageUpdatedMethod + ) { this.webhooksOnMessageUpdatedMethod = webhooksOnMessageUpdatedMethod; return this; } - /** - * The webhooks.on_message_updated.format. - * - * @param webhooksOnMessageUpdatedFormat The webhooks.on_message_updated.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageUpdatedFormat(final String webhooksOnMessageUpdatedFormat) { - this.webhooksOnMessageUpdatedFormat = webhooksOnMessageUpdatedFormat; - return this; - } - - /** - * The webhooks.on_message_removed.url. - * - * @param webhooksOnMessageRemovedUrl The webhooks.on_message_removed.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemovedUrl(final URI webhooksOnMessageRemovedUrl) { + public ServiceUpdater setWebhooksOnMessageRemovedUrl( + final URI webhooksOnMessageRemovedUrl + ) { this.webhooksOnMessageRemovedUrl = webhooksOnMessageRemovedUrl; return this; } - /** - * The webhooks.on_message_removed.url. - * - * @param webhooksOnMessageRemovedUrl The webhooks.on_message_removed.url - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemovedUrl(final String webhooksOnMessageRemovedUrl) { - return setWebhooksOnMessageRemovedUrl(Promoter.uriFromString(webhooksOnMessageRemovedUrl)); + public ServiceUpdater setWebhooksOnMessageRemovedUrl( + final String webhooksOnMessageRemovedUrl + ) { + return setWebhooksOnMessageRemovedUrl( + Promoter.uriFromString(webhooksOnMessageRemovedUrl) + ); } - /** - * The webhooks.on_message_removed.method. - * - * @param webhooksOnMessageRemovedMethod The webhooks.on_message_removed.method - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemovedMethod(final HttpMethod webhooksOnMessageRemovedMethod) { + public ServiceUpdater setWebhooksOnMessageRemovedMethod( + final HttpMethod webhooksOnMessageRemovedMethod + ) { this.webhooksOnMessageRemovedMethod = webhooksOnMessageRemovedMethod; return this; } - /** - * The webhooks.on_message_removed.format. - * - * @param webhooksOnMessageRemovedFormat The webhooks.on_message_removed.format - * @return this - */ - public ServiceUpdater setWebhooksOnMessageRemovedFormat(final String webhooksOnMessageRemovedFormat) { - this.webhooksOnMessageRemovedFormat = webhooksOnMessageRemovedFormat; - return this; - } - - /** - * The webhooks.on_channel_added.url. - * - * @param webhooksOnChannelAddedUrl The webhooks.on_channel_added.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddedUrl(final URI webhooksOnChannelAddedUrl) { + public ServiceUpdater setWebhooksOnChannelAddedUrl( + final URI webhooksOnChannelAddedUrl + ) { this.webhooksOnChannelAddedUrl = webhooksOnChannelAddedUrl; return this; } - /** - * The webhooks.on_channel_added.url. - * - * @param webhooksOnChannelAddedUrl The webhooks.on_channel_added.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddedUrl(final String webhooksOnChannelAddedUrl) { - return setWebhooksOnChannelAddedUrl(Promoter.uriFromString(webhooksOnChannelAddedUrl)); + public ServiceUpdater setWebhooksOnChannelAddedUrl( + final String webhooksOnChannelAddedUrl + ) { + return setWebhooksOnChannelAddedUrl( + Promoter.uriFromString(webhooksOnChannelAddedUrl) + ); } - /** - * The webhooks.on_channel_added.method. - * - * @param webhooksOnChannelAddedMethod The webhooks.on_channel_added.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddedMethod(final HttpMethod webhooksOnChannelAddedMethod) { + public ServiceUpdater setWebhooksOnChannelAddedMethod( + final HttpMethod webhooksOnChannelAddedMethod + ) { this.webhooksOnChannelAddedMethod = webhooksOnChannelAddedMethod; return this; } - /** - * The webhooks.on_channel_added.format. - * - * @param webhooksOnChannelAddedFormat The webhooks.on_channel_added.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelAddedFormat(final String webhooksOnChannelAddedFormat) { - this.webhooksOnChannelAddedFormat = webhooksOnChannelAddedFormat; - return this; - } - - /** - * The webhooks.on_channel_destroyed.url. - * - * @param webhooksOnChannelDestroyedUrl The webhooks.on_channel_destroyed.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyedUrl(final URI webhooksOnChannelDestroyedUrl) { + public ServiceUpdater setWebhooksOnChannelDestroyedUrl( + final URI webhooksOnChannelDestroyedUrl + ) { this.webhooksOnChannelDestroyedUrl = webhooksOnChannelDestroyedUrl; return this; } - /** - * The webhooks.on_channel_destroyed.url. - * - * @param webhooksOnChannelDestroyedUrl The webhooks.on_channel_destroyed.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyedUrl(final String webhooksOnChannelDestroyedUrl) { - return setWebhooksOnChannelDestroyedUrl(Promoter.uriFromString(webhooksOnChannelDestroyedUrl)); - } - - /** - * The webhooks.on_channel_destroyed.method. - * - * @param webhooksOnChannelDestroyedMethod The - * webhooks.on_channel_destroyed.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyedMethod(final HttpMethod webhooksOnChannelDestroyedMethod) { - this.webhooksOnChannelDestroyedMethod = webhooksOnChannelDestroyedMethod; - return this; + public ServiceUpdater setWebhooksOnChannelDestroyedUrl( + final String webhooksOnChannelDestroyedUrl + ) { + return setWebhooksOnChannelDestroyedUrl( + Promoter.uriFromString(webhooksOnChannelDestroyedUrl) + ); } - /** - * The webhooks.on_channel_destroyed.format. - * - * @param webhooksOnChannelDestroyedFormat The - * webhooks.on_channel_destroyed.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelDestroyedFormat(final String webhooksOnChannelDestroyedFormat) { - this.webhooksOnChannelDestroyedFormat = webhooksOnChannelDestroyedFormat; + public ServiceUpdater setWebhooksOnChannelDestroyedMethod( + final HttpMethod webhooksOnChannelDestroyedMethod + ) { + this.webhooksOnChannelDestroyedMethod = + webhooksOnChannelDestroyedMethod; return this; } - /** - * The webhooks.on_channel_updated.url. - * - * @param webhooksOnChannelUpdatedUrl The webhooks.on_channel_updated.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdatedUrl(final URI webhooksOnChannelUpdatedUrl) { + public ServiceUpdater setWebhooksOnChannelUpdatedUrl( + final URI webhooksOnChannelUpdatedUrl + ) { this.webhooksOnChannelUpdatedUrl = webhooksOnChannelUpdatedUrl; return this; } - /** - * The webhooks.on_channel_updated.url. - * - * @param webhooksOnChannelUpdatedUrl The webhooks.on_channel_updated.url - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdatedUrl(final String webhooksOnChannelUpdatedUrl) { - return setWebhooksOnChannelUpdatedUrl(Promoter.uriFromString(webhooksOnChannelUpdatedUrl)); + public ServiceUpdater setWebhooksOnChannelUpdatedUrl( + final String webhooksOnChannelUpdatedUrl + ) { + return setWebhooksOnChannelUpdatedUrl( + Promoter.uriFromString(webhooksOnChannelUpdatedUrl) + ); } - /** - * The webhooks.on_channel_updated.method. - * - * @param webhooksOnChannelUpdatedMethod The webhooks.on_channel_updated.method - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdatedMethod(final HttpMethod webhooksOnChannelUpdatedMethod) { + public ServiceUpdater setWebhooksOnChannelUpdatedMethod( + final HttpMethod webhooksOnChannelUpdatedMethod + ) { this.webhooksOnChannelUpdatedMethod = webhooksOnChannelUpdatedMethod; return this; } - /** - * The webhooks.on_channel_updated.format. - * - * @param webhooksOnChannelUpdatedFormat The webhooks.on_channel_updated.format - * @return this - */ - public ServiceUpdater setWebhooksOnChannelUpdatedFormat(final String webhooksOnChannelUpdatedFormat) { - this.webhooksOnChannelUpdatedFormat = webhooksOnChannelUpdatedFormat; - return this; - } - - /** - * The webhooks.on_member_added.url. - * - * @param webhooksOnMemberAddedUrl The webhooks.on_member_added.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddedUrl(final URI webhooksOnMemberAddedUrl) { + public ServiceUpdater setWebhooksOnMemberAddedUrl( + final URI webhooksOnMemberAddedUrl + ) { this.webhooksOnMemberAddedUrl = webhooksOnMemberAddedUrl; return this; } - /** - * The webhooks.on_member_added.url. - * - * @param webhooksOnMemberAddedUrl The webhooks.on_member_added.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddedUrl(final String webhooksOnMemberAddedUrl) { - return setWebhooksOnMemberAddedUrl(Promoter.uriFromString(webhooksOnMemberAddedUrl)); + public ServiceUpdater setWebhooksOnMemberAddedUrl( + final String webhooksOnMemberAddedUrl + ) { + return setWebhooksOnMemberAddedUrl( + Promoter.uriFromString(webhooksOnMemberAddedUrl) + ); } - /** - * The webhooks.on_member_added.method. - * - * @param webhooksOnMemberAddedMethod The webhooks.on_member_added.method - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddedMethod(final HttpMethod webhooksOnMemberAddedMethod) { + public ServiceUpdater setWebhooksOnMemberAddedMethod( + final HttpMethod webhooksOnMemberAddedMethod + ) { this.webhooksOnMemberAddedMethod = webhooksOnMemberAddedMethod; return this; } - /** - * The webhooks.on_member_added.format. - * - * @param webhooksOnMemberAddedFormat The webhooks.on_member_added.format - * @return this - */ - public ServiceUpdater setWebhooksOnMemberAddedFormat(final String webhooksOnMemberAddedFormat) { - this.webhooksOnMemberAddedFormat = webhooksOnMemberAddedFormat; - return this; - } - - /** - * The webhooks.on_member_removed.url. - * - * @param webhooksOnMemberRemovedUrl The webhooks.on_member_removed.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemovedUrl(final URI webhooksOnMemberRemovedUrl) { + public ServiceUpdater setWebhooksOnMemberRemovedUrl( + final URI webhooksOnMemberRemovedUrl + ) { this.webhooksOnMemberRemovedUrl = webhooksOnMemberRemovedUrl; return this; } - /** - * The webhooks.on_member_removed.url. - * - * @param webhooksOnMemberRemovedUrl The webhooks.on_member_removed.url - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemovedUrl(final String webhooksOnMemberRemovedUrl) { - return setWebhooksOnMemberRemovedUrl(Promoter.uriFromString(webhooksOnMemberRemovedUrl)); + public ServiceUpdater setWebhooksOnMemberRemovedUrl( + final String webhooksOnMemberRemovedUrl + ) { + return setWebhooksOnMemberRemovedUrl( + Promoter.uriFromString(webhooksOnMemberRemovedUrl) + ); } - /** - * The webhooks.on_member_removed.method. - * - * @param webhooksOnMemberRemovedMethod The webhooks.on_member_removed.method - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemovedMethod(final HttpMethod webhooksOnMemberRemovedMethod) { + public ServiceUpdater setWebhooksOnMemberRemovedMethod( + final HttpMethod webhooksOnMemberRemovedMethod + ) { this.webhooksOnMemberRemovedMethod = webhooksOnMemberRemovedMethod; return this; } - /** - * The webhooks.on_member_removed.format. - * - * @param webhooksOnMemberRemovedFormat The webhooks.on_member_removed.format - * @return this - */ - public ServiceUpdater setWebhooksOnMemberRemovedFormat(final String webhooksOnMemberRemovedFormat) { - this.webhooksOnMemberRemovedFormat = webhooksOnMemberRemovedFormat; - return this; - } - - /** - * The limits.channel_members. - * - * @param limitsChannelMembers The limits.channel_members - * @return this - */ - public ServiceUpdater setLimitsChannelMembers(final Integer limitsChannelMembers) { + public ServiceUpdater setLimitsChannelMembers( + final Integer limitsChannelMembers + ) { this.limitsChannelMembers = limitsChannelMembers; return this; } - /** - * The limits.user_channels. - * - * @param limitsUserChannels The limits.user_channels - * @return this - */ - public ServiceUpdater setLimitsUserChannels(final Integer limitsUserChannels) { + public ServiceUpdater setLimitsUserChannels( + final Integer limitsUserChannels + ) { this.limitsUserChannels = limitsUserChannels; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (defaultServiceRoleSid != null) { - request.addPostParam("DefaultServiceRoleSid", defaultServiceRoleSid); + Serializer.toString( + request, + "DefaultServiceRoleSid", + defaultServiceRoleSid, + ParameterType.URLENCODED + ); } if (defaultChannelRoleSid != null) { - request.addPostParam("DefaultChannelRoleSid", defaultChannelRoleSid); + Serializer.toString( + request, + "DefaultChannelRoleSid", + defaultChannelRoleSid, + ParameterType.URLENCODED + ); } if (defaultChannelCreatorRoleSid != null) { - request.addPostParam("DefaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid); + Serializer.toString( + request, + "DefaultChannelCreatorRoleSid", + defaultChannelCreatorRoleSid, + ParameterType.URLENCODED + ); } if (readStatusEnabled != null) { - request.addPostParam("ReadStatusEnabled", readStatusEnabled.toString()); + Serializer.toString( + request, + "ReadStatusEnabled", + readStatusEnabled, + ParameterType.URLENCODED + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); + Serializer.toString( + request, + "ReachabilityEnabled", + reachabilityEnabled, + ParameterType.URLENCODED + ); } if (typingIndicatorTimeout != null) { - request.addPostParam("TypingIndicatorTimeout", typingIndicatorTimeout.toString()); + Serializer.toString( + request, + "TypingIndicatorTimeout", + typingIndicatorTimeout, + ParameterType.URLENCODED + ); } if (consumptionReportInterval != null) { - request.addPostParam("ConsumptionReportInterval", consumptionReportInterval.toString()); + Serializer.toString( + request, + "ConsumptionReportInterval", + consumptionReportInterval, + ParameterType.URLENCODED + ); } if (notificationsNewMessageEnabled != null) { - request.addPostParam("Notifications.NewMessage.Enabled", notificationsNewMessageEnabled.toString()); + Serializer.toString( + request, + "Notifications.NewMessage.Enabled", + notificationsNewMessageEnabled, + ParameterType.URLENCODED + ); } if (notificationsNewMessageTemplate != null) { - request.addPostParam("Notifications.NewMessage.Template", notificationsNewMessageTemplate); + Serializer.toString( + request, + "Notifications.NewMessage.Template", + notificationsNewMessageTemplate, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelEnabled != null) { - request.addPostParam("Notifications.AddedToChannel.Enabled", notificationsAddedToChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.AddedToChannel.Enabled", + notificationsAddedToChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelTemplate != null) { - request.addPostParam("Notifications.AddedToChannel.Template", notificationsAddedToChannelTemplate); + Serializer.toString( + request, + "Notifications.AddedToChannel.Template", + notificationsAddedToChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelEnabled != null) { - request.addPostParam("Notifications.RemovedFromChannel.Enabled", notificationsRemovedFromChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Enabled", + notificationsRemovedFromChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelTemplate != null) { - request.addPostParam("Notifications.RemovedFromChannel.Template", notificationsRemovedFromChannelTemplate); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Template", + notificationsRemovedFromChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelEnabled != null) { - request.addPostParam("Notifications.InvitedToChannel.Enabled", notificationsInvitedToChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Enabled", + notificationsInvitedToChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelTemplate != null) { - request.addPostParam("Notifications.InvitedToChannel.Template", notificationsInvitedToChannelTemplate); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Template", + notificationsInvitedToChannelTemplate, + ParameterType.URLENCODED + ); } if (preWebhookUrl != null) { - request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); + Serializer.toString( + request, + "PreWebhookUrl", + preWebhookUrl, + ParameterType.URLENCODED + ); } if (postWebhookUrl != null) { - request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); + Serializer.toString( + request, + "PostWebhookUrl", + postWebhookUrl, + ParameterType.URLENCODED + ); } if (webhookMethod != null) { - request.addPostParam("WebhookMethod", webhookMethod.toString()); + Serializer.toString( + request, + "WebhookMethod", + webhookMethod, + ParameterType.URLENCODED + ); } if (webhookFilters != null) { - for (String prop : webhookFilters) { - request.addPostParam("WebhookFilters", prop); + for (String param : webhookFilters) { + Serializer.toString( + request, + "WebhookFilters", + param, + ParameterType.URLENCODED + ); } } if (webhooksOnMessageSendUrl != null) { - request.addPostParam("Webhooks.OnMessageSend.Url", webhooksOnMessageSendUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageSend.Url", + webhooksOnMessageSendUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageSendMethod != null) { - request.addPostParam("Webhooks.OnMessageSend.Method", webhooksOnMessageSendMethod.toString()); - } - - if (webhooksOnMessageSendFormat != null) { - request.addPostParam("Webhooks.OnMessageSend.Format", webhooksOnMessageSendFormat); + Serializer.toString( + request, + "Webhooks.OnMessageSend.Method", + webhooksOnMessageSendMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageUpdateUrl != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Url", webhooksOnMessageUpdateUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageUpdate.Url", + webhooksOnMessageUpdateUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageUpdateMethod != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Method", webhooksOnMessageUpdateMethod.toString()); - } - - if (webhooksOnMessageUpdateFormat != null) { - request.addPostParam("Webhooks.OnMessageUpdate.Format", webhooksOnMessageUpdateFormat); + Serializer.toString( + request, + "Webhooks.OnMessageUpdate.Method", + webhooksOnMessageUpdateMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageRemoveUrl != null) { - request.addPostParam("Webhooks.OnMessageRemove.Url", webhooksOnMessageRemoveUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageRemove.Url", + webhooksOnMessageRemoveUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageRemoveMethod != null) { - request.addPostParam("Webhooks.OnMessageRemove.Method", webhooksOnMessageRemoveMethod.toString()); - } - - if (webhooksOnMessageRemoveFormat != null) { - request.addPostParam("Webhooks.OnMessageRemove.Format", webhooksOnMessageRemoveFormat); + Serializer.toString( + request, + "Webhooks.OnMessageRemove.Method", + webhooksOnMessageRemoveMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelAddUrl != null) { - request.addPostParam("Webhooks.OnChannelAdd.Url", webhooksOnChannelAddUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelAdd.Url", + webhooksOnChannelAddUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelAddMethod != null) { - request.addPostParam("Webhooks.OnChannelAdd.Method", webhooksOnChannelAddMethod.toString()); - } - - if (webhooksOnChannelAddFormat != null) { - request.addPostParam("Webhooks.OnChannelAdd.Format", webhooksOnChannelAddFormat); + Serializer.toString( + request, + "Webhooks.OnChannelAdd.Method", + webhooksOnChannelAddMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelDestroyUrl != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Url", webhooksOnChannelDestroyUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelDestroy.Url", + webhooksOnChannelDestroyUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelDestroyMethod != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Method", webhooksOnChannelDestroyMethod.toString()); - } - - if (webhooksOnChannelDestroyFormat != null) { - request.addPostParam("Webhooks.OnChannelDestroy.Format", webhooksOnChannelDestroyFormat); + Serializer.toString( + request, + "Webhooks.OnChannelDestroy.Method", + webhooksOnChannelDestroyMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelUpdateUrl != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Url", webhooksOnChannelUpdateUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelUpdate.Url", + webhooksOnChannelUpdateUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelUpdateMethod != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Method", webhooksOnChannelUpdateMethod.toString()); - } - - if (webhooksOnChannelUpdateFormat != null) { - request.addPostParam("Webhooks.OnChannelUpdate.Format", webhooksOnChannelUpdateFormat); + Serializer.toString( + request, + "Webhooks.OnChannelUpdate.Method", + webhooksOnChannelUpdateMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMemberAddUrl != null) { - request.addPostParam("Webhooks.OnMemberAdd.Url", webhooksOnMemberAddUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMemberAdd.Url", + webhooksOnMemberAddUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMemberAddMethod != null) { - request.addPostParam("Webhooks.OnMemberAdd.Method", webhooksOnMemberAddMethod.toString()); - } - - if (webhooksOnMemberAddFormat != null) { - request.addPostParam("Webhooks.OnMemberAdd.Format", webhooksOnMemberAddFormat); + Serializer.toString( + request, + "Webhooks.OnMemberAdd.Method", + webhooksOnMemberAddMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMemberRemoveUrl != null) { - request.addPostParam("Webhooks.OnMemberRemove.Url", webhooksOnMemberRemoveUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMemberRemove.Url", + webhooksOnMemberRemoveUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMemberRemoveMethod != null) { - request.addPostParam("Webhooks.OnMemberRemove.Method", webhooksOnMemberRemoveMethod.toString()); - } - - if (webhooksOnMemberRemoveFormat != null) { - request.addPostParam("Webhooks.OnMemberRemove.Format", webhooksOnMemberRemoveFormat); + Serializer.toString( + request, + "Webhooks.OnMemberRemove.Method", + webhooksOnMemberRemoveMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageSentUrl != null) { - request.addPostParam("Webhooks.OnMessageSent.Url", webhooksOnMessageSentUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageSent.Url", + webhooksOnMessageSentUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageSentMethod != null) { - request.addPostParam("Webhooks.OnMessageSent.Method", webhooksOnMessageSentMethod.toString()); - } - - if (webhooksOnMessageSentFormat != null) { - request.addPostParam("Webhooks.OnMessageSent.Format", webhooksOnMessageSentFormat); + Serializer.toString( + request, + "Webhooks.OnMessageSent.Method", + webhooksOnMessageSentMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageUpdatedUrl != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Url", webhooksOnMessageUpdatedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageUpdated.Url", + webhooksOnMessageUpdatedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageUpdatedMethod != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Method", webhooksOnMessageUpdatedMethod.toString()); - } - - if (webhooksOnMessageUpdatedFormat != null) { - request.addPostParam("Webhooks.OnMessageUpdated.Format", webhooksOnMessageUpdatedFormat); + Serializer.toString( + request, + "Webhooks.OnMessageUpdated.Method", + webhooksOnMessageUpdatedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMessageRemovedUrl != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Url", webhooksOnMessageRemovedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMessageRemoved.Url", + webhooksOnMessageRemovedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMessageRemovedMethod != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Method", webhooksOnMessageRemovedMethod.toString()); - } - - if (webhooksOnMessageRemovedFormat != null) { - request.addPostParam("Webhooks.OnMessageRemoved.Format", webhooksOnMessageRemovedFormat); + Serializer.toString( + request, + "Webhooks.OnMessageRemoved.Method", + webhooksOnMessageRemovedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelAddedUrl != null) { - request.addPostParam("Webhooks.OnChannelAdded.Url", webhooksOnChannelAddedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelAdded.Url", + webhooksOnChannelAddedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelAddedMethod != null) { - request.addPostParam("Webhooks.OnChannelAdded.Method", webhooksOnChannelAddedMethod.toString()); - } - - if (webhooksOnChannelAddedFormat != null) { - request.addPostParam("Webhooks.OnChannelAdded.Format", webhooksOnChannelAddedFormat); + Serializer.toString( + request, + "Webhooks.OnChannelAdded.Method", + webhooksOnChannelAddedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelDestroyedUrl != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Url", webhooksOnChannelDestroyedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelDestroyed.Url", + webhooksOnChannelDestroyedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelDestroyedMethod != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Method", webhooksOnChannelDestroyedMethod.toString()); - } - - if (webhooksOnChannelDestroyedFormat != null) { - request.addPostParam("Webhooks.OnChannelDestroyed.Format", webhooksOnChannelDestroyedFormat); + Serializer.toString( + request, + "Webhooks.OnChannelDestroyed.Method", + webhooksOnChannelDestroyedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnChannelUpdatedUrl != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Url", webhooksOnChannelUpdatedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnChannelUpdated.Url", + webhooksOnChannelUpdatedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnChannelUpdatedMethod != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Method", webhooksOnChannelUpdatedMethod.toString()); - } - - if (webhooksOnChannelUpdatedFormat != null) { - request.addPostParam("Webhooks.OnChannelUpdated.Format", webhooksOnChannelUpdatedFormat); + Serializer.toString( + request, + "Webhooks.OnChannelUpdated.Method", + webhooksOnChannelUpdatedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMemberAddedUrl != null) { - request.addPostParam("Webhooks.OnMemberAdded.Url", webhooksOnMemberAddedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMemberAdded.Url", + webhooksOnMemberAddedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMemberAddedMethod != null) { - request.addPostParam("Webhooks.OnMemberAdded.Method", webhooksOnMemberAddedMethod.toString()); - } - - if (webhooksOnMemberAddedFormat != null) { - request.addPostParam("Webhooks.OnMemberAdded.Format", webhooksOnMemberAddedFormat); + Serializer.toString( + request, + "Webhooks.OnMemberAdded.Method", + webhooksOnMemberAddedMethod, + ParameterType.URLENCODED + ); } if (webhooksOnMemberRemovedUrl != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Url", webhooksOnMemberRemovedUrl.toString()); + Serializer.toString( + request, + "Webhooks.OnMemberRemoved.Url", + webhooksOnMemberRemovedUrl, + ParameterType.URLENCODED + ); } if (webhooksOnMemberRemovedMethod != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Method", webhooksOnMemberRemovedMethod.toString()); - } - - if (webhooksOnMemberRemovedFormat != null) { - request.addPostParam("Webhooks.OnMemberRemoved.Format", webhooksOnMemberRemovedFormat); + Serializer.toString( + request, + "Webhooks.OnMemberRemoved.Method", + webhooksOnMemberRemovedMethod, + ParameterType.URLENCODED + ); } if (limitsChannelMembers != null) { - request.addPostParam("Limits.ChannelMembers", limitsChannelMembers.toString()); + Serializer.toString( + request, + "Limits.ChannelMembers", + limitsChannelMembers, + ParameterType.URLENCODED + ); } if (limitsUserChannels != null) { - request.addPostParam("Limits.UserChannels", limitsUserChannels.toString()); + Serializer.toString( + request, + "Limits.UserChannels", + limitsUserChannels, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/Channel.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/Channel.java index f2dd673df3..707f9046a7 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/Channel.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/Channel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; @@ -10,32 +17,62 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Channel extends Resource { - private static final long serialVersionUID = 275623534063843L; + + public static ChannelCreator creator(final String pathServiceSid) { + return new ChannelCreator(pathServiceSid); + } + + public static ChannelDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelDeleter(pathServiceSid, pathSid); + } + + public static ChannelFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelFetcher(pathServiceSid, pathSid); + } + + public static ChannelReader reader(final String pathServiceSid) { + return new ChannelReader(pathServiceSid); + } + + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelUpdater(pathServiceSid, pathSid); + } public enum ChannelType { PUBLIC("public"), @@ -47,85 +84,28 @@ private ChannelType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ChannelType from a string. - * @param value string value - * @return generated ChannelType - */ @JsonCreator public static ChannelType forValue(final String value) { return Promoter.enumFromString(value, ChannelType.values()); } } - /** - * Create a ChannelFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelFetcher capable of executing the fetch - */ - public static ChannelFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new ChannelFetcher(pathServiceSid, pathSid); - } - - /** - * Create a ChannelDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelDeleter capable of executing the delete - */ - public static ChannelDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new ChannelDeleter(pathServiceSid, pathSid); - } - - /** - * Create a ChannelCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return ChannelCreator capable of executing the create - */ - public static ChannelCreator creator(final String pathServiceSid) { - return new ChannelCreator(pathServiceSid); - } - - /** - * Create a ChannelReader to execute read. - * - * @param pathServiceSid The service_sid - * @return ChannelReader capable of executing the read - */ - public static ChannelReader reader(final String pathServiceSid) { - return new ChannelReader(pathServiceSid); - } - - /** - * Create a ChannelUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelUpdater capable of executing the update - */ - public static ChannelUpdater updater(final String pathServiceSid, - final String pathSid) { - return new ChannelUpdater(pathServiceSid, pathSid); - } - /** * Converts a JSON String into a Channel object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Channel object represented by the provided JSON */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -139,12 +119,15 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Channel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Channel object represented by the provided JSON */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -155,196 +138,101 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String friendlyName; - private final String uniqueName; - private final String attributes; - private final Channel.ChannelType type; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - private final Integer membersCount; - private final Integer messagesCount; - private final URI url; - private final Map links; - - @JsonCreator - private Channel(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("type") - final Channel.ChannelType type, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy, - @JsonProperty("members_count") - final Integer membersCount, - @JsonProperty("messages_count") - final Integer messagesCount, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.friendlyName = friendlyName; - this.uniqueName = uniqueName; - this.attributes = attributes; - this.type = type; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - this.membersCount = membersCount; - this.messagesCount = messagesCount; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the [Account][/console] responsible for this - * channel.. - * - * @return The unique id of the [Account][/console] responsible for this - * channel. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String attributes; - /** - * Returns The The unique id of the [Service][service] this channel belongs to.. - * - * @return The unique id of the [Service][service] this channel belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String createdBy; - /** - * Returns The The human-readable name of this channel.. - * - * @return The human-readable name of this channel. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique, addressable name of this channel.. - * - * @return The unique, addressable name of this channel. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } + @Getter + private final String friendlyName; - /** - * Returns The The visibility of this channel - either public or private. - * - * @return The visibility of this channel - either public or private - */ - public final Channel.ChannelType getType() { - return this.type; - } + @Getter + private final Map links; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Integer membersCount; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer messagesCount; - /** - * Returns The Identity of the channel's creator.. - * - * @return Identity of the channel's creator. - */ - public final String getCreatedBy() { - return this.createdBy; - } + @Getter + private final String serviceSid; - /** - * Returns The The members_count. - * - * @return The members_count - */ - public final Integer getMembersCount() { - return this.membersCount; - } + @Getter + private final String sid; - /** - * Returns The The messages_count. - * - * @return The messages_count - */ - public final Integer getMessagesCount() { - return this.messagesCount; - } + @Getter + private final Channel.ChannelType type; - /** - * Returns The An absolute URL for this channel.. - * - * @return An absolute URL for this channel. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String uniqueName; - /** - * Returns The Absolute URLs to access the [Members][members] and - * [Messages][messages] for this channel.. - * - * @return Absolute URLs to access the [Members][members] and - * [Messages][messages] for this channel. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Channel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.membersCount = membersCount; + this.messagesCount = messagesCount; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -358,58 +246,41 @@ public boolean equals(final Object o) { } Channel other = (Channel) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(attributes, other.attributes) && - Objects.equals(type, other.type) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy) && - Objects.equals(membersCount, other.membersCount) && - Objects.equals(messagesCount, other.messagesCount) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - friendlyName, - uniqueName, - attributes, - type, - dateCreated, - dateUpdated, - createdBy, - membersCount, - messagesCount, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("friendlyName", friendlyName) - .add("uniqueName", uniqueName) - .add("attributes", attributes) - .add("type", type) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .add("membersCount", membersCount) - .add("messagesCount", messagesCount) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + attributes, + createdBy, + dateCreated, + dateUpdated, + friendlyName, + links, + membersCount, + messagesCount, + serviceSid, + sid, + type, + uniqueName, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelCreator.java index d87d45aae6..80408fddbf 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,128 +27,138 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ChannelCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; private String friendlyName; private String uniqueName; private String attributes; private Channel.ChannelType type; - /** - * Construct a new ChannelCreator. - * - * @param pathServiceSid The service_sid - */ public ChannelCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * A human-readable name for the Channel. Optional.. - * - * @param friendlyName A human-readable name for the Channel. - * @return this - */ public ChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A unique, addressable name for the Channel. Optional.. - * - * @param uniqueName A unique, addressable name for the Channel. - * @return this - */ public ChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An optional metadata field you can use to store any data you wish. No - * processing or validation is done on this field.. - * - * @param attributes An optional metadata field you can use to store any data - * you wish. - * @return this - */ public ChannelCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The visibility of the channel - `public` or `private`. Defaults to `public`.. - * - * @param type The visibility of the channel - public or private. - * @return this - */ public ChannelCreator setType(final Channel.ChannelType type) { this.type = type; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel create(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelDeleter.java index 70fc90a9be..e5ed9c9a13 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ChannelDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ChannelDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public ChannelDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelFetcher.java index 836f64797a..0c79ed6269 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ChannelFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ChannelFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public ChannelFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelReader.java index 3321d7d93b..013e7c7a90 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; @@ -10,190 +17,218 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class ChannelReader extends Reader { - private final String pathServiceSid; + + private String pathServiceSid; private List type; + private Long pageSize; - /** - * Construct a new ChannelReader. - * - * @param pathServiceSid The service_sid - */ public ChannelReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * The type. - * - * @param type The type - * @return this - */ public ChannelReader setType(final List type) { this.type = type; return this; } - /** - * The type. - * - * @param type The type - * @return this - */ public ChannelReader setType(final Channel.ChannelType type) { return setType(Promoter.listOfOne(type)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Channel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - Channel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (type != null) { - for (Channel.ChannelType prop : type) { - request.addQueryParam("Type", prop.toString()); + for (Channel.ChannelType param : type) { + Serializer.toString( + request, + "Type", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelUpdater.java index 6103da9b24..8c7f7c44e7 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/ChannelUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,116 +27,126 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ChannelUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; private String friendlyName; private String uniqueName; private String attributes; - /** - * Construct a new ChannelUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelUpdater(final String pathServiceSid, - final String pathSid) { + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * A human-readable name for the Channel. Optional.. - * - * @param friendlyName A human-readable name for the Channel. - * @return this - */ public ChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A unique, addressable name for the Channel. Optional.. - * - * @param uniqueName A unique, addressable name for the Channel. - * @return this - */ public ChannelUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An optional metadata field you can use to store any data you wish. No - * processing or validation is done on this field.. - * - * @param attributes An optional metadata field you can use to store any data - * you wish. - * @return this - */ public ChannelUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel update(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/Role.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/Role.java index b9b71df0ee..12893c81e6 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/Role.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/Role.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; @@ -10,33 +17,68 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Role extends Resource { - private static final long serialVersionUID = 78785177979928L; + + public static RoleCreator creator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + return new RoleCreator(pathServiceSid, friendlyName, type, permission); + } + + public static RoleDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new RoleDeleter(pathServiceSid, pathSid); + } + + public static RoleFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new RoleFetcher(pathServiceSid, pathSid); + } + + public static RoleReader reader(final String pathServiceSid) { + return new RoleReader(pathServiceSid); + } + + public static RoleUpdater updater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { + return new RoleUpdater(pathServiceSid, pathSid, permission); + } public enum RoleType { CHANNEL("channel"), @@ -48,93 +90,28 @@ private RoleType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a RoleType from a string. - * @param value string value - * @return generated RoleType - */ @JsonCreator public static RoleType forValue(final String value) { return Promoter.enumFromString(value, RoleType.values()); } } - /** - * Create a RoleFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return RoleFetcher capable of executing the fetch - */ - public static RoleFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new RoleFetcher(pathServiceSid, pathSid); - } - - /** - * Create a RoleDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return RoleDeleter capable of executing the delete - */ - public static RoleDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new RoleDeleter(pathServiceSid, pathSid); - } - - /** - * Create a RoleCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param friendlyName The human-readable name of this role. - * @param type What kind of role this is. - * @param permission A permission this role should have. - * @return RoleCreator capable of executing the create - */ - public static RoleCreator creator(final String pathServiceSid, - final String friendlyName, - final Role.RoleType type, - final List permission) { - return new RoleCreator(pathServiceSid, friendlyName, type, permission); - } - - /** - * Create a RoleReader to execute read. - * - * @param pathServiceSid The service_sid - * @return RoleReader capable of executing the read - */ - public static RoleReader reader(final String pathServiceSid) { - return new RoleReader(pathServiceSid); - } - - /** - * Create a RoleUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param permission A permission this role should have. - * @return RoleUpdater capable of executing the update - */ - public static RoleUpdater updater(final String pathServiceSid, - final String pathSid, - final List permission) { - return new RoleUpdater(pathServiceSid, pathSid, permission); - } - /** * Converts a JSON String into a Role object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Role object represented by the provided JSON */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -148,12 +125,15 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Role object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Role object represented by the provided JSON */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -164,125 +144,76 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String friendlyName; - private final Role.RoleType type; - private final List permissions; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private Role(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Role.RoleType type, - @JsonProperty("permissions") - final List permissions, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.friendlyName = friendlyName; - this.type = type; - this.permissions = permissions; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this role.. - * - * @return The unique id of the Account responsible for this role. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Service this role belongs to.. - * - * @return The unique id of the Service this role belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The human-readable name of this role.. - * - * @return The human-readable name of this role. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String friendlyName; - /** - * Returns The What kind of role this is.. - * - * @return What kind of role this is. - */ - public final Role.RoleType getType() { - return this.type; - } + @Getter + private final List permissions; - /** - * Returns The A JSON array of the permissions this role has.. - * - * @return A JSON array of the permissions this role has. - */ - public final List getPermissions() { - return this.permissions; - } + @Getter + private final String serviceSid; - /** - * Returns The The date that this resource was created in ISO 8601 format.. - * - * @return The date that this resource was created in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date that this resource was last updated in ISO 8601 format.. - * - * @return The date that this resource was last updated in ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Role.RoleType type; - /** - * Returns The An absolute URL for this role.. - * - * @return An absolute URL for this role. - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private Role( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("permissions") final List permissions, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.permissions = permissions; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.url = url; } @Override @@ -296,43 +227,31 @@ public boolean equals(final Object o) { } Role other = (Role) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(permissions, other.permissions) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(permissions, other.permissions) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - friendlyName, - type, - permissions, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("permissions", permissions) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + permissions, + serviceSid, + sid, + type, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleCreator.java index 57ed0db653..3c8a673f76 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleCreator.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,90 +28,138 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class RoleCreator extends Creator { - private final String pathServiceSid; - private final String friendlyName; - private final Role.RoleType type; - private final List permission; - - /** - * Construct a new RoleCreator. - * - * @param pathServiceSid The service_sid - * @param friendlyName The human-readable name of this role. - * @param type What kind of role this is. - * @param permission A permission this role should have. - */ - public RoleCreator(final String pathServiceSid, - final String friendlyName, - final Role.RoleType type, - final List permission) { + + private String pathServiceSid; + private String friendlyName; + private Role.RoleType type; + private List permission; + + public RoleCreator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role create(final TwilioRestClient client) { + public RoleCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public RoleCreator setType(final Role.RoleType type) { + this.type = type; + return this; + } + + public RoleCreator setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleCreator setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role create(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (permission != null) { - for (String prop : permission) { - request.addPostParam("Permission", prop); + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleDeleter.java index db8060959a..aade413a54 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class RoleDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new RoleDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public RoleDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public RoleDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleFetcher.java index f91cd1531d..1eb570d2e2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RoleFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new RoleFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public RoleFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public RoleFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleReader.java index ad13114ad2..e85ac6b2d1 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; @@ -10,159 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RoleReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new RoleReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public RoleReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public RoleReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Role Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "roles", - response.getContent(), - Role.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleUpdater.java index 01a7e14207..2bf34a5db6 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/RoleUpdater.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,78 +28,108 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class RoleUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; - private final List permission; - /** - * Construct a new RoleUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param permission A permission this role should have. - */ - public RoleUpdater(final String pathServiceSid, - final String pathSid, - final List permission) { + private String pathServiceSid; + private String pathSid; + private List permission; + + public RoleUpdater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.permission = permission; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role update(final TwilioRestClient client) { + public RoleUpdater setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleUpdater setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role update(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (permission != null) { - for (String prop : permission) { - request.addPostParam("Permission", prop); + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/User.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/User.java index 57c3ddd186..6e2ae1f8a6 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/User.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/User.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; @@ -11,98 +18,74 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class User extends Resource { - private static final long serialVersionUID = 15176818292650L; - /** - * Create a UserFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserFetcher capable of executing the fetch - */ - public static UserFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new UserFetcher(pathServiceSid, pathSid); + public static UserCreator creator( + final String pathServiceSid, + final String identity + ) { + return new UserCreator(pathServiceSid, identity); } - /** - * Create a UserDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserDeleter capable of executing the delete - */ - public static UserDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static UserDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new UserDeleter(pathServiceSid, pathSid); } - /** - * Create a UserCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param identity A unique string that identifies the user within this service - * - often a username or email address. - * @return UserCreator capable of executing the create - */ - public static UserCreator creator(final String pathServiceSid, - final String identity) { - return new UserCreator(pathServiceSid, identity); + public static UserFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new UserFetcher(pathServiceSid, pathSid); } - /** - * Create a UserReader to execute read. - * - * @param pathServiceSid The service_sid - * @return UserReader capable of executing the read - */ public static UserReader reader(final String pathServiceSid) { return new UserReader(pathServiceSid); } - /** - * Create a UserUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserUpdater capable of executing the update - */ - public static UserUpdater updater(final String pathServiceSid, - final String pathSid) { + public static UserUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new UserUpdater(pathServiceSid, pathSid); } /** * Converts a JSON String into a User object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return User object represented by the provided JSON */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -116,12 +99,15 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a User object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return User object represented by the provided JSON */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -132,200 +118,105 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String attributes; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final String roleSid; + + @Getter private final String identity; - private final Boolean isOnline; + + @Getter private final Boolean isNotifiable; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final Boolean isOnline; + + @Getter private final Integer joinedChannelsCount; + + @Getter private final Map links; + + @Getter + private final String roleSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private User(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("is_online") - final Boolean isOnline, - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("joined_channels_count") - final Integer joinedChannelsCount, - @JsonProperty("links") - final Map links, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private User( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity") final String identity, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty( + "joined_channels_count" + ) final Integer joinedChannelsCount, + @JsonProperty("links") final Map links, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; this.attributes = attributes; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.roleSid = roleSid; this.identity = identity; - this.isOnline = isOnline; this.isNotifiable = isNotifiable; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.isOnline = isOnline; this.joinedChannelsCount = joinedChannelsCount; this.links = links; + this.roleSid = roleSid; + this.serviceSid = serviceSid; + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account responsible for this user.. - * - * @return The unique id of the Account responsible for this user. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique id of the Service this user belongs to.. - * - * @return The unique id of the Service this user belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } - - /** - * Returns The The human-readable name of this user.. - * - * @return The human-readable name of this user. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique id of the [Role][role] assigned to this user.. - * - * @return The unique id of the [Role][role] assigned to this user. - */ - public final String getRoleSid() { - return this.roleSid; - } - - /** - * Returns The A unique string that identifies the user within this service - - * often a username or email address.. - * - * @return A unique string that identifies the user within this service - often - * a username or email address. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Indicates whether the User is actively connected to the Service - * instance and online.. - * - * @return Indicates whether the User is actively connected to the Service - * instance and online. - */ - public final Boolean getIsOnline() { - return this.isOnline; - } - - /** - * Returns The Indicates whether the User has a potentially valid Push - * Notification registration for the Service instance.. - * - * @return Indicates whether the User has a potentially valid Push Notification - * registration for the Service instance. - */ - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - - /** - * Returns The The date that this resource was created in ISO 8601 format.. - * - * @return The date that this resource was created in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated in ISO 8601 format.. - * - * @return The date that this resource was last updated in ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The joined_channels_count. - * - * @return The joined_channels_count - */ - public final Integer getJoinedChannelsCount() { - return this.joinedChannelsCount; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The An absolute URL for this user.. - * - * @return An absolute URL for this user. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -337,58 +228,41 @@ public boolean equals(final Object o) { } User other = (User) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(identity, other.identity) && - Objects.equals(isOnline, other.isOnline) && - Objects.equals(isNotifiable, other.isNotifiable) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && - Objects.equals(links, other.links) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identity, other.identity) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && + Objects.equals(links, other.links) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - attributes, - friendlyName, - roleSid, - identity, - isOnline, - isNotifiable, - dateCreated, - dateUpdated, - joinedChannelsCount, - links, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("attributes", attributes) - .add("friendlyName", friendlyName) - .add("roleSid", roleSid) - .add("identity", identity) - .add("isOnline", isOnline) - .add("isNotifiable", isNotifiable) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("joinedChannelsCount", joinedChannelsCount) - .add("links", links) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + dateCreated, + dateUpdated, + friendlyName, + identity, + isNotifiable, + isOnline, + joinedChannelsCount, + links, + roleSid, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserCreator.java index 77d8e5d705..b506c2c647 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,124 +27,139 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserCreator extends Creator { - private final String pathServiceSid; - private final String identity; + + private String pathServiceSid; + private String identity; private String roleSid; private String attributes; private String friendlyName; - /** - * Construct a new UserCreator. - * - * @param pathServiceSid The service_sid - * @param identity A unique string that identifies the user within this service - * - often a username or email address. - */ - public UserCreator(final String pathServiceSid, - final String identity) { + public UserCreator(final String pathServiceSid, final String identity) { this.pathServiceSid = pathServiceSid; this.identity = identity; } - /** - * The unique id of the - * [Role](https://www.twilio.com/docs/api/chat/rest/v1/roles) assigned to this - * user.. - * - * @param roleSid The unique id of the Role assigned to this user. - * @return this - */ + public UserCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An optional string used to contain any metadata or other information for the - * User. The string must contain structurally valid JSON if specified.. - * - * @param attributes An optional string used to contain any metadata or other - * information for the User. - * @return this - */ public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * An optional human readable string representing the user. Often used for - * display purposes.. - * - * @param friendlyName An optional human readable string representing the user. - * @return this - */ public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User create(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserDeleter.java index d7f9f9f95c..2bb43a579f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class UserDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new UserDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public UserDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserFetcher.java index c889001bc5..5e2785eb12 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new UserFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public UserFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserReader.java index 8212c21b32..0c00795f98 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; @@ -10,159 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new UserReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public UserReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of User Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "users", - response.getContent(), - User.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserUpdater.java index fdd787090f..a220f5f3f4 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/UserUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,117 +27,126 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; private String roleSid; private String attributes; private String friendlyName; - /** - * Construct a new UserUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserUpdater(final String pathServiceSid, - final String pathSid) { + public UserUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * The unique id of the [Role][role] assigned to this user.. - * - * @param roleSid The unique id of the [Role][role] assigned to this user. - * @return this - */ public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An optional string used to contain any metadata or other information for the - * User. The string must contain structurally valid JSON if specified.. - * - * @param attributes An optional string used to contain any metadata or other - * information for the User. - * @return this - */ public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * An optional human readable string representing the user. Often used for - * display purposes.. - * - * @param friendlyName An optional human readable string representing the user. - * @return this - */ public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User update(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Invite.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Invite.java index bf3071c126..088eeae3ce 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Invite.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Invite.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; @@ -11,93 +18,72 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Invite extends Resource { - private static final long serialVersionUID = 189960368613614L; - /** - * Create a InviteFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return InviteFetcher capable of executing the fetch - */ - public static InviteFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); + public static InviteCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { + return new InviteCreator(pathServiceSid, pathChannelSid, identity); } - /** - * Create a InviteCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * @return InviteCreator capable of executing the create - */ - public static InviteCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { - return new InviteCreator(pathServiceSid, pathChannelSid, identity); + public static InviteDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a InviteReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return InviteReader capable of executing the read - */ - public static InviteReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new InviteReader(pathServiceSid, pathChannelSid); + public static InviteFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a InviteDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return InviteDeleter capable of executing the delete - */ - public static InviteDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); + public static InviteReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new InviteReader(pathServiceSid, pathChannelSid); } /** * Converts a JSON String into a Invite object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Invite object represented by the provided JSON */ - public static Invite fromJson(final String json, final ObjectMapper objectMapper) { + public static Invite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -111,12 +97,15 @@ public static Invite fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Invite object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Invite object represented by the provided JSON */ - public static Invite fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Invite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -127,141 +116,83 @@ public static Invite fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String channelSid; - private final String serviceSid; + + @Getter + private final String createdBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final String roleSid; - private final String createdBy; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private Invite(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("created_by") - final String createdBy, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Invite( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.channelSid = channelSid; - this.serviceSid = serviceSid; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.roleSid = roleSid; - this.createdBy = createdBy; + this.serviceSid = serviceSid; + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account[/console] responsible for this - * member.. - * - * @return The unique id of the Account[/console] responsible for this member. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique id of the Channel for this member.. - * - * @return The unique id of the Channel for this member. - */ - public final String getChannelSid() { - return this.channelSid; - } - - /** - * Returns The The unique id of the Service this member belongs to.. - * - * @return The unique id of the Service this member belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The A unique string identifier for this User in this Service.. - * - * @return A unique string identifier for this User in this Service. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The Role assigned to this member.. - * - * @return The Role assigned to this member. - */ - public final String getRoleSid() { - return this.roleSid; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - /** - * Returns The An absolute URL for this member.. - * - * @return An absolute URL for this member. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -273,46 +204,33 @@ public boolean equals(final Object o) { } Invite other = (Invite) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(createdBy, other.createdBy) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - channelSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - roleSid, - createdBy, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("channelSid", channelSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("roleSid", roleSid) - .add("createdBy", createdBy) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + channelSid, + createdBy, + dateCreated, + dateUpdated, + identity, + roleSid, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteCreator.java index a058ee2a0b..1c6c1a4e89 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,91 +27,120 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class InviteCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String identity; + + private String pathServiceSid; + private String pathChannelSid; + private String identity; private String roleSid; - /** - * Construct a new InviteCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - */ - public InviteCreator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { + public InviteCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - /** - * The [Role](https://www.twilio.com/docs/api/chat/rest/v1/role) assigned to - * this member.. - * - * @param roleSid The Role assigned to this member. - * @return this - */ + public InviteCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public InviteCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Invite - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Invite create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Invite create(final TwilioRestClient client) { + Response response = makeRequest(client); return Invite.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Invite content = Invite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteDeleter.java index 846d978adf..515f667a93 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class InviteDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new InviteDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public InviteDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public InviteDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteFetcher.java index f118edc1a0..e35daea9ce 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class InviteFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new InviteFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public InviteFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public InviteFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Invite - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Invite fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Invite fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Invite.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Invite content = Invite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteReader.java index 8ed33bccbf..c897f8906f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/InviteReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; @@ -10,202 +17,224 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class InviteReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private List identity; + private Long pageSize; - /** - * Construct a new InviteReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public InviteReader(final String pathServiceSid, - final String pathChannelSid) { + public InviteReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/v1/user) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). See the - * [access - * tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public InviteReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/v1/user) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/v1/service). See the - * [access - * tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public InviteReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public InviteReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Invite read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Invite Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Invite read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "invites", - response.getContent(), - Invite.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Member.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Member.java index f78c77f664..08a0c4a223 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Member.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Member.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; @@ -11,107 +18,80 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Member extends Resource { - private static final long serialVersionUID = 102574959310114L; - /** - * Create a MemberFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberFetcher capable of executing the fetch - */ - public static MemberFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); + public static MemberCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { + return new MemberCreator(pathServiceSid, pathChannelSid, identity); } - /** - * Create a MemberCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * @return MemberCreator capable of executing the create - */ - public static MemberCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { - return new MemberCreator(pathServiceSid, pathChannelSid, identity); + public static MemberDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a MemberReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MemberReader capable of executing the read - */ - public static MemberReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new MemberReader(pathServiceSid, pathChannelSid); + public static MemberFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a MemberDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberDeleter capable of executing the delete - */ - public static MemberDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); + public static MemberReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MemberReader(pathServiceSid, pathChannelSid); } - /** - * Create a MemberUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberUpdater capable of executing the update - */ - public static MemberUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public static MemberUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberUpdater(pathServiceSid, pathChannelSid, pathSid); } /** * Converts a JSON String into a Member object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -125,12 +105,15 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Member object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -141,155 +124,93 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; - private final String accountSid; - private final String channelSid; - private final String serviceSid; - private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String roleSid; - private final Integer lastConsumedMessageIndex; - private final DateTime lastConsumptionTimestamp; - private final URI url; - - @JsonCreator - private Member(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - @JsonProperty("last_consumption_timestamp") - final String lastConsumptionTimestamp, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.channelSid = channelSid; - this.serviceSid = serviceSid; - this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.roleSid = roleSid; - this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.lastConsumptionTimestamp = DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this member.. - * - * @return The unique id of the Account responsible for this member. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String channelSid; - /** - * Returns The The unique id of the Channel for this member.. - * - * @return The unique id of the Channel for this member. - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Service this member belongs to.. - * - * @return The unique id of the Service this member belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A unique string identifier for this User in this Service.. - * - * @return A unique string identifier for this User in this Service. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final String identity; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Integer lastConsumedMessageIndex; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime lastConsumptionTimestamp; - /** - * Returns The The Role assigned to this member.. - * - * @return The Role assigned to this member. - */ - public final String getRoleSid() { - return this.roleSid; - } + @Getter + private final String roleSid; - /** - * Returns The An Integer representing index of the last Message this Member has - * read within this Channel. - * - * @return An Integer representing index of the last Message this Member has - * read within this Channel - */ - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } + @Getter + private final String serviceSid; - /** - * Returns The An ISO8601 based timestamp string representing the datetime of - * the last Message read event for this Member within this Channel. - * - * @return An ISO8601 based timestamp string representing the datetime of the - * last Message read event for this Member within this Channel - */ - public final DateTime getLastConsumptionTimestamp() { - return this.lastConsumptionTimestamp; - } + @Getter + private final String sid; - /** - * Returns The An absolute URL for this member.. - * - * @return An absolute URL for this member. - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private Member( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty("last_consumption_timestamp") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime lastConsumptionTimestamp, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.identity = identity; + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + this.lastConsumptionTimestamp = lastConsumptionTimestamp; + this.roleSid = roleSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -303,49 +224,41 @@ public boolean equals(final Object o) { } Member other = (Member) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && - Objects.equals(lastConsumptionTimestamp, other.lastConsumptionTimestamp) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals( + lastConsumptionTimestamp, + other.lastConsumptionTimestamp + ) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - channelSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - roleSid, - lastConsumedMessageIndex, - lastConsumptionTimestamp, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("channelSid", channelSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("roleSid", roleSid) - .add("lastConsumedMessageIndex", lastConsumedMessageIndex) - .add("lastConsumptionTimestamp", lastConsumptionTimestamp) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + channelSid, + dateCreated, + dateUpdated, + identity, + lastConsumedMessageIndex, + lastConsumptionTimestamp, + roleSid, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberCreator.java index 166284c292..cb6258611e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,91 +27,120 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String identity; + + private String pathServiceSid; + private String pathChannelSid; + private String identity; private String roleSid; - /** - * Construct a new MemberCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - */ - public MemberCreator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { + public MemberCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - /** - * The [Role](https://www.twilio.com/docs/api/chat/rest/v1/roles) assigned to - * this member.. - * - * @param roleSid The Role assigned to this member. - * @return this - */ + public MemberCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public MemberCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member create(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberDeleter.java index b31f8112b3..b98c26f67f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MemberDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MemberDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MemberDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberFetcher.java index b82ed51a86..7f4464dbe3 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MemberFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MemberFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberReader.java index f35af77be2..7aa5730d2e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; @@ -10,202 +17,224 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class MemberReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private List identity; + private Long pageSize; - /** - * Construct a new MemberReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MemberReader(final String pathServiceSid, - final String pathChannelSid) { + public MemberReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/v1/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/v1/services). See the - * [access - * tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public MemberReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/v1/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/v1/services). See the - * [access - * tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens)[/docs/api/chat/guides/create-tokens] docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public MemberReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MemberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Member Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "members", - response.getContent(), - Member.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberUpdater.java index 3bfd2c2b03..fd4635d6e2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MemberUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,108 +27,125 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; private String roleSid; private Integer lastConsumedMessageIndex; - /** - * Construct a new MemberUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public MemberUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The [Role](https://www.twilio.com/docs/api/chat/rest/v1/roles) assigned to - * this member.. - * - * @param roleSid The Role assigned to this member. - * @return this - */ public MemberUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An Integer representing index of the last - * [Message](https://www.twilio.com/docs/api/chat/rest/v1/messages) this Member - * has read within this - * [Channel](https://www.twilio.com/docs/api/chat/rest/v1/channels). - * - * @param lastConsumedMessageIndex An Integer representing index of the last - * Message this Member has read within this - * Channel - * @return this - */ - public MemberUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex) { + public MemberUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member update(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); + Serializer.toString( + request, + "LastConsumedMessageIndex", + lastConsumedMessageIndex, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Message.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Message.java index 713c0d36be..87e8f00f8b 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Message.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/Message.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; @@ -10,32 +17,71 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Message extends Resource { - private static final long serialVersionUID = 68490171213295L; + + public static MessageCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String body + ) { + return new MessageCreator(pathServiceSid, pathChannelSid, body); + } + + public static MessageDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); + } + + public static MessageFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); + } + + public static MessageReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MessageReader(pathServiceSid, pathChannelSid); + } + + public static MessageUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); + } public enum OrderType { ASC("asc"), @@ -47,97 +93,28 @@ private OrderType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a OrderType from a string. - * @param value string value - * @return generated OrderType - */ @JsonCreator public static OrderType forValue(final String value) { return Promoter.enumFromString(value, OrderType.values()); } } - /** - * Create a MessageFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageFetcher capable of executing the fetch - */ - public static MessageFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); - } - - /** - * Create a MessageCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param body The body - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String body) { - return new MessageCreator(pathServiceSid, pathChannelSid, body); - } - - /** - * Create a MessageReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MessageReader capable of executing the read - */ - public static MessageReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new MessageReader(pathServiceSid, pathChannelSid); - } - - /** - * Create a MessageDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageDeleter capable of executing the delete - */ - public static MessageDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); - } - - /** - * Create a MessageUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageUpdater capable of executing the update - */ - public static MessageUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); - } - /** * Converts a JSON String into a Message object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -151,12 +128,15 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Message object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -167,179 +147,96 @@ public static Message fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String attributes; - private final String serviceSid; - private final String to; - private final String channelSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final Boolean wasEdited; - private final String from; - private final String body; - private final Integer index; - private final URI url; - - @JsonCreator - private Message(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("to") - final String to, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("was_edited") - final Boolean wasEdited, - @JsonProperty("from") - final String from, - @JsonProperty("body") - final String body, - @JsonProperty("index") - final Integer index, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.attributes = attributes; - this.serviceSid = serviceSid; - this.to = to; - this.channelSid = channelSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.wasEdited = wasEdited; - this.from = from; - this.body = body; - this.index = index; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this message.. - * - * @return The unique id of the Account responsible for this message. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String attributes; - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } + @Getter + private final String body; - /** - * Returns The The unique id of the Service this message belongs to.. - * - * @return The unique id of the Service this message belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String channelSid; - /** - * Returns The The unique id of the Channel this message was sent to.. - * - * @return The unique id of the Channel this message was sent to. - */ - public final String getTo() { - return this.to; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The channel_sid. - * - * @return The channel_sid - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String from; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer index; - /** - * Returns The true if the message has been updated since it was created.. - * - * @return true if the message has been updated since it was created. - */ - public final Boolean getWasEdited() { - return this.wasEdited; - } + @Getter + private final String serviceSid; - /** - * Returns The The identity of the message's author.. - * - * @return The identity of the message's author. - */ - public final String getFrom() { - return this.from; - } + @Getter + private final String sid; - /** - * Returns The The contents of the message.. - * - * @return The contents of the message. - */ - public final String getBody() { - return this.body; - } + @Getter + private final String to; - /** - * Returns The The index of the message within the Channel. - * - * @return The index of the message within the Channel - */ - public final Integer getIndex() { - return this.index; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this message.. - * - * @return An absolute URL for this message. - */ - public final URI getUrl() { - return this.url; + @Getter + private final Boolean wasEdited; + + @JsonCreator + private Message( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("body") final String body, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("from") final String from, + @JsonProperty("index") final Integer index, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("to") final String to, + @JsonProperty("url") final URI url, + @JsonProperty("was_edited") final Boolean wasEdited + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.body = body; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.from = from; + this.index = index; + this.serviceSid = serviceSid; + this.sid = sid; + this.to = to; + this.url = url; + this.wasEdited = wasEdited; } @Override @@ -353,55 +250,39 @@ public boolean equals(final Object o) { } Message other = (Message) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(to, other.to) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(wasEdited, other.wasEdited) && - Objects.equals(from, other.from) && - Objects.equals(body, other.body) && - Objects.equals(index, other.index) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(body, other.body) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(from, other.from) && + Objects.equals(index, other.index) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(to, other.to) && + Objects.equals(url, other.url) && + Objects.equals(wasEdited, other.wasEdited) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - attributes, - serviceSid, - to, - channelSid, - dateCreated, - dateUpdated, - wasEdited, - from, - body, - index, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("attributes", attributes) - .add("serviceSid", serviceSid) - .add("to", to) - .add("channelSid", channelSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("wasEdited", wasEdited) - .add("from", from) - .add("body", body) - .add("index", index) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + body, + channelSid, + dateCreated, + dateUpdated, + from, + index, + serviceSid, + sid, + to, + url, + wasEdited + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageCreator.java index a7bf2973cb..0cfdf7ea5c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,106 +27,136 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String body; + + private String pathServiceSid; + private String pathChannelSid; + private String body; private String from; private String attributes; - /** - * Construct a new MessageCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param body The body - */ - public MessageCreator(final String pathServiceSid, - final String pathChannelSid, - final String body) { + public MessageCreator( + final String pathServiceSid, + final String pathChannelSid, + final String body + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.body = body; } - /** - * The from. - * - * @param from The from - * @return this - */ + public MessageCreator setBody(final String body) { + this.body = body; + return this; + } + public MessageCreator setFrom(final String from) { this.from = from; return this; } - /** - * The attributes. - * - * @param attributes The attributes - * @return this - */ public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message create(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (from != null) { - request.addPostParam("From", from); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageDeleter.java index c1fad04de0..153647ce7b 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MessageDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MessageDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MessageDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageFetcher.java index 640a0e7b23..50577bdde8 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MessageFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MessageFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageReader.java index 0484b7092e..0c787ffb8e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; @@ -10,179 +17,216 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private Message.OrderType order; + private Long pageSize; - /** - * Construct a new MessageReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MessageReader(final String pathServiceSid, - final String pathChannelSid) { + public MessageReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * The order. - * - * @param order The order - * @return this - */ public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MessageReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Message Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "messages", - response.getContent(), - Message.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); + Serializer.toString(request, "Order", order, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageUpdater.java index e9e948b237..0432b7fe5a 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/channel/MessageUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,105 +27,123 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; private String body; private String attributes; - /** - * Construct a new MessageUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public MessageUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The new message body string. You can also send structured data by serializing - * it into a string.. - * - * @param body The new message body string. - * @return this - */ public MessageUpdater setBody(final String body) { this.body = body; return this; } - /** - * The new attributes metadata field you can use to store any data you wish. - * The string value must contain structurally valid JSON if specified.. - * - * @param attributes The new attributes metadata field you can use to store any - * data you wish. - * @return this - */ public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message update(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannel.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannel.java index 8d5d825720..0db9d57545 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannel.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.user; @@ -10,29 +17,36 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class UserChannel extends Resource { - private static final long serialVersionUID = 254880238496884L; + + public static UserChannelReader reader( + final String pathServiceSid, + final String pathUserSid + ) { + return new UserChannelReader(pathServiceSid, pathUserSid); + } public enum ChannelStatus { JOINED("joined"), @@ -45,15 +59,11 @@ private ChannelStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ChannelStatus from a string. - * @param value string value - * @return generated ChannelStatus - */ @JsonCreator public static ChannelStatus forValue(final String value) { return Promoter.enumFromString(value, ChannelStatus.values()); @@ -61,26 +71,16 @@ public static ChannelStatus forValue(final String value) { } /** - * Create a UserChannelReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @return UserChannelReader capable of executing the read - */ - public static UserChannelReader reader(final String pathServiceSid, - final String pathUserSid) { - return new UserChannelReader(pathServiceSid, pathUserSid); - } - - /** - * Converts a JSON String into a UserChannel object using the provided - * ObjectMapper. - * + * Converts a JSON String into a UserChannel object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return UserChannel object represented by the provided JSON */ - public static UserChannel fromJson(final String json, final ObjectMapper objectMapper) { + public static UserChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -94,12 +94,15 @@ public static UserChannel fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a UserChannel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return UserChannel object represented by the provided JSON */ - public static UserChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static UserChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -110,112 +113,63 @@ public static UserChannel fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String channelSid; + + @Getter + private final Integer lastConsumedMessageIndex; + + @Getter + private final Map links; + + @Getter private final String memberSid; + + @Getter + private final String serviceSid; + + @Getter private final UserChannel.ChannelStatus status; - private final Integer lastConsumedMessageIndex; + + @Getter private final Integer unreadMessagesCount; - private final Map links; @JsonCreator - private UserChannel(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("member_sid") - final String memberSid, - @JsonProperty("status") - final UserChannel.ChannelStatus status, - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - @JsonProperty("links") - final Map links) { + private UserChannel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty("links") final Map links, + @JsonProperty("member_sid") final String memberSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("status") final UserChannel.ChannelStatus status, + @JsonProperty("unread_messages_count") final Integer unreadMessagesCount + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; this.channelSid = channelSid; + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + this.links = links; this.memberSid = memberSid; + this.serviceSid = serviceSid; this.status = status; - this.lastConsumedMessageIndex = lastConsumedMessageIndex; this.unreadMessagesCount = unreadMessagesCount; - this.links = links; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The channel_sid. - * - * @return The channel_sid - */ - public final String getChannelSid() { - return this.channelSid; - } - - /** - * Returns The The member_sid. - * - * @return The member_sid - */ - public final String getMemberSid() { - return this.memberSid; - } - - /** - * Returns The The status. - * - * @return The status - */ - public final UserChannel.ChannelStatus getStatus() { - return this.status; - } - - /** - * Returns The The last_consumed_message_index. - * - * @return The last_consumed_message_index - */ - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } - - /** - * Returns The The unread_messages_count. - * - * @return The unread_messages_count - */ - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -229,40 +183,32 @@ public boolean equals(final Object o) { } UserChannel other = (UserChannel) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(memberSid, other.memberSid) && - Objects.equals(status, other.status) && - Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && - Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals(links, other.links) && + Objects.equals(memberSid, other.memberSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(status, other.status) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - channelSid, - memberSid, - status, - lastConsumedMessageIndex, - unreadMessagesCount, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("channelSid", channelSid) - .add("memberSid", memberSid) - .add("status", status) - .add("lastConsumedMessageIndex", lastConsumedMessageIndex) - .add("unreadMessagesCount", unreadMessagesCount) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + channelSid, + lastConsumedMessageIndex, + links, + memberSid, + serviceSid, + status, + unreadMessagesCount + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannelReader.java b/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannelReader.java index be60cbad64..b31f5b85c3 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannelReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v1/service/user/UserChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v1.service.user; @@ -10,163 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserChannelReader extends Reader { - private final String pathServiceSid; - private final String pathUserSid; - - /** - * Construct a new UserChannelReader. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - */ - public UserChannelReader(final String pathServiceSid, - final String pathUserSid) { + + private String pathServiceSid; + private String pathUserSid; + private Long pageSize; + + public UserChannelReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Users/{UserSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UserChannel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of UserChannel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserChannel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - UserChannel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/Credential.java b/src/main/java/com/twilio/rest/ipmessaging/v2/Credential.java index 8f50117717..b9b8b0b922 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/Credential.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/Credential.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; @@ -10,32 +17,52 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Credential extends Resource { - private static final long serialVersionUID = 133884911230690L; + + public static CredentialCreator creator(final Credential.PushService type) { + return new CredentialCreator(type); + } + + public static CredentialDeleter deleter(final String pathSid) { + return new CredentialDeleter(pathSid); + } + + public static CredentialFetcher fetcher(final String pathSid) { + return new CredentialFetcher(pathSid); + } + + public static CredentialReader reader() { + return new CredentialReader(); + } + + public static CredentialUpdater updater(final String pathSid) { + return new CredentialUpdater(pathSid); + } public enum PushService { GCM("gcm"), @@ -48,15 +75,11 @@ private PushService(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a PushService from a string. - * @param value string value - * @return generated PushService - */ @JsonCreator public static PushService forValue(final String value) { return Promoter.enumFromString(value, PushService.values()); @@ -64,63 +87,16 @@ public static PushService forValue(final String value) { } /** - * Create a CredentialReader to execute read. - * - * @return CredentialReader capable of executing the read - */ - public static CredentialReader reader() { - return new CredentialReader(); - } - - /** - * Create a CredentialCreator to execute create. - * - * @param type Credential type, one of "gcm", "fcm", or "apn" - * @return CredentialCreator capable of executing the create - */ - public static CredentialCreator creator(final Credential.PushService type) { - return new CredentialCreator(type); - } - - /** - * Create a CredentialFetcher to execute fetch. - * - * @param pathSid The sid - * @return CredentialFetcher capable of executing the fetch - */ - public static CredentialFetcher fetcher(final String pathSid) { - return new CredentialFetcher(pathSid); - } - - /** - * Create a CredentialUpdater to execute update. - * - * @param pathSid The sid - * @return CredentialUpdater capable of executing the update - */ - public static CredentialUpdater updater(final String pathSid) { - return new CredentialUpdater(pathSid); - } - - /** - * Create a CredentialDeleter to execute delete. - * - * @param pathSid The sid - * @return CredentialDeleter capable of executing the delete - */ - public static CredentialDeleter deleter(final String pathSid) { - return new CredentialDeleter(pathSid); - } - - /** - * Converts a JSON String into a Credential object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -134,12 +110,15 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a Credential object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -150,118 +129,73 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final Credential.PushService type; + + @Getter private final String sandbox; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final Credential.PushService type; + + @Getter private final URI url; @JsonCreator - private Credential(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Credential.PushService type, - @JsonProperty("sandbox") - final String sandbox, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Credential( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.type = type; this.sandbox = sandbox; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.sid = sid; + this.type = type; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account responsible for this resource.. - * - * @return The unique id of the Account responsible for this resource. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The human-readable name of this resource.. - * - * @return The human-readable name of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The Indicates which push notifications service this credential is for - * - either gcm, fcm, or apn. - * - * @return Indicates which push notifications service this credential is for - - * either gcm, fcm, or apn - */ - public final Credential.PushService getType() { - return this.type; - } - - /** - * Returns The [APN only] true when this resource should use the sandbox APN - * service.. - * - * @return [APN only] true when this resource should use the sandbox APN - * service. - */ - public final String getSandbox() { - return this.sandbox; - } - - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The An absolute URL for this credential resource.. - * - * @return An absolute URL for this credential resource. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -273,40 +207,29 @@ public boolean equals(final Object o) { } Credential other = (Credential) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(sandbox, other.sandbox) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - type, - sandbox, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("sandbox", sandbox) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sandbox, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialCreator.java index 40a8cef988..a13375d4dc 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,9 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialCreator extends Creator { - private final Credential.PushService type; + + private Credential.PushService type; private String friendlyName; private String certificate; private String privateKey; @@ -26,166 +40,166 @@ public class CredentialCreator extends Creator { private String apiKey; private String secret; - /** - * Construct a new CredentialCreator. - * - * @param type Credential type, one of "gcm", "fcm", or "apn" - */ public CredentialCreator(final Credential.PushService type) { this.type = type; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ + public CredentialCreator setType(final Credential.PushService type) { + this.type = type; + return this; + } + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate, e.g. - * `-----BEGIN CERTIFICATE----- - * MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== - * -----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate, - * e. - * @return this - */ public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key, e.g. - * `-----BEGIN RSA PRIVATE KEY----- - * MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. - * -----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key, - * e. - * @return this - */ public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "API key" for project from Google Developer console - * for your GCM Service application credential. - * - * @param apiKey [GCM only] This is the "API key" for project from Google - * Developer console for your GCM Service application credential - * @return this - */ public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * [FCM only] This is the "Server key" of your project from Firebase console - * under Settings / Cloud messaging.. - * - * @param secret [FCM only] This is the "Server key" of your project from - * Firebase console under Settings / Cloud messaging. - * @return this - */ public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Credentials"; + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Credentials", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialDeleter.java index f69c060198..de23989a69 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class CredentialDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new CredentialDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialFetcher.java index 971929453d..7095bb9a87 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new CredentialFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialReader.java index 21ed83a5ce..cc7033ccc2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public CredentialReader() {} + + public CredentialReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Credentials"; + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Credentials", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Credential Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credentials", - response.getContent(), - Credential.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialUpdater.java index d761cfb1ca..1a176449e2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/CredentialUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,9 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String certificate; private String privateKey; @@ -26,162 +40,154 @@ public class CredentialUpdater extends Updater { private String apiKey; private String secret; - /** - * Construct a new CredentialUpdater. - * - * @param pathSid The sid - */ public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate, e.g. - * `-----BEGIN CERTIFICATE----- - * MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== - * -----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate, - * e. - * @return this - */ public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key, e.g. - * `-----BEGIN RSA PRIVATE KEY----- - * MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. - * -----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key, - * e. - * @return this - */ public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "API key" for project from Google Developer console - * for your GCM Service application credential. - * - * @param apiKey [GCM only] This is the "API key" for project from Google - * Developer console for your GCM Service application credential - * @return this - */ public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * [FCM only] This is the "Server key" of your project from Firebase console - * under Settings / Cloud messaging.. - * - * @param secret [FCM only] This is the "Server key" of your project from - * Firebase console under Settings / Cloud messaging. - * @return this - */ public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Credentials/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Credential update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/Service.java b/src/main/java/com/twilio/rest/ipmessaging/v2/Service.java index 5242dec4b6..6159cb8fba 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/Service.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/Service.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; @@ -11,90 +18,63 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Service extends Resource { - private static final long serialVersionUID = 81815704097903L; - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid The sid - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); + public static ServiceCreator creator(final String friendlyName) { + return new ServiceCreator(friendlyName); } - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid The sid - * @return ServiceDeleter capable of executing the delete - */ public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - /** - * Create a ServiceCreator to execute create. - * - * @param friendlyName Human-readable name for this service instance - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator(final String friendlyName) { - return new ServiceCreator(friendlyName); + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); } - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ public static ServiceReader reader() { return new ServiceReader(); } - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid The sid - * @return ServiceUpdater capable of executing the update - */ public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** * Converts a JSON String into a Service object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -108,12 +88,15 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Service object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -124,325 +107,160 @@ public static Service fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String defaultServiceRoleSid; - private final String defaultChannelRoleSid; - private final String defaultChannelCreatorRoleSid; - private final Boolean readStatusEnabled; - private final Boolean reachabilityEnabled; - private final Integer typingIndicatorTimeout; - private final Integer consumptionReportInterval; - private final Map limits; - private final String preWebhookUrl; - private final String postWebhookUrl; - private final String webhookMethod; - private final List webhookFilters; - private final Integer preWebhookRetryCount; - private final Integer postWebhookRetryCount; - private final Map notifications; - private final Map media; - private final URI url; - private final Map links; - - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("default_service_role_sid") - final String defaultServiceRoleSid, - @JsonProperty("default_channel_role_sid") - final String defaultChannelRoleSid, - @JsonProperty("default_channel_creator_role_sid") - final String defaultChannelCreatorRoleSid, - @JsonProperty("read_status_enabled") - final Boolean readStatusEnabled, - @JsonProperty("reachability_enabled") - final Boolean reachabilityEnabled, - @JsonProperty("typing_indicator_timeout") - final Integer typingIndicatorTimeout, - @JsonProperty("consumption_report_interval") - final Integer consumptionReportInterval, - @JsonProperty("limits") - final Map limits, - @JsonProperty("pre_webhook_url") - final String preWebhookUrl, - @JsonProperty("post_webhook_url") - final String postWebhookUrl, - @JsonProperty("webhook_method") - final String webhookMethod, - @JsonProperty("webhook_filters") - final List webhookFilters, - @JsonProperty("pre_webhook_retry_count") - final Integer preWebhookRetryCount, - @JsonProperty("post_webhook_retry_count") - final Integer postWebhookRetryCount, - @JsonProperty("notifications") - final Map notifications, - @JsonProperty("media") - final Map media, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.defaultServiceRoleSid = defaultServiceRoleSid; - this.defaultChannelRoleSid = defaultChannelRoleSid; - this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; - this.readStatusEnabled = readStatusEnabled; - this.reachabilityEnabled = reachabilityEnabled; - this.typingIndicatorTimeout = typingIndicatorTimeout; - this.consumptionReportInterval = consumptionReportInterval; - this.limits = limits; - this.preWebhookUrl = preWebhookUrl; - this.postWebhookUrl = postWebhookUrl; - this.webhookMethod = webhookMethod; - this.webhookFilters = webhookFilters; - this.preWebhookRetryCount = preWebhookRetryCount; - this.postWebhookRetryCount = postWebhookRetryCount; - this.notifications = notifications; - this.media = media; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this service.. - * - * @return The unique id of the Account responsible for this service. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Integer consumptionReportInterval; - /** - * Returns The The human-readable name of this service.. - * - * @return The human-readable name of this service. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String defaultChannelCreatorRoleSid; - /** - * Returns The The service role assigned to users when they are added to the - * service.. - * - * @return The service role assigned to users when they are added to the - * service. - */ - public final String getDefaultServiceRoleSid() { - return this.defaultServiceRoleSid; - } + @Getter + private final String defaultChannelRoleSid; - /** - * Returns The The channel role assigned to users when they are added to a - * channel.. - * - * @return The channel role assigned to users when they are added to a channel. - */ - public final String getDefaultChannelRoleSid() { - return this.defaultChannelRoleSid; - } + @Getter + private final String defaultServiceRoleSid; - /** - * Returns The The channel role assigned to a channel creator when joining a new - * channel.. - * - * @return The channel role assigned to a channel creator when joining a new - * channel. - */ - public final String getDefaultChannelCreatorRoleSid() { - return this.defaultChannelCreatorRoleSid; - } + @Getter + private final String friendlyName; - /** - * Returns The Enable the Message Constumption Horizon feature.. - * - * @return Enable the Message Constumption Horizon feature. - */ - public final Boolean getReadStatusEnabled() { - return this.readStatusEnabled; - } + @Getter + private final Object limits; - /** - * Returns The Indicates whether the the Reachability feature is enabled for - * this Service instance.. - * - * @return Indicates whether the the Reachability feature is enabled for this - * Service instance. - */ - public final Boolean getReachabilityEnabled() { - return this.reachabilityEnabled; - } + @Getter + private final Map links; - /** - * Returns The The amount of time in seconds after a "started typing" event when - * clients should assume that user is no longer typing, even if no "ended - * typing" message was received.. - * - * @return The amount of time in seconds after a "started typing" event when - * clients should assume that user is no longer typing, even if no - * "ended typing" message was received. - */ - public final Integer getTypingIndicatorTimeout() { - return this.typingIndicatorTimeout; - } + @Getter + private final Object media; - /** - * Returns The DEPRECATED.. - * - * @return DEPRECATED. - */ - public final Integer getConsumptionReportInterval() { - return this.consumptionReportInterval; - } + @Getter + private final Object notifications; - /** - * Returns The Configuration for service instance level limits.. - * - * @return Configuration for service instance level limits. - */ - public final Map getLimits() { - return this.limits; - } + @Getter + private final Integer postWebhookRetryCount; - /** - * Returns The The webhook URL for PRE-Event webhooks.. - * - * @return The webhook URL for PRE-Event webhooks. - */ - public final String getPreWebhookUrl() { - return this.preWebhookUrl; - } + @Getter + private final String postWebhookUrl; - /** - * Returns The The webhook URL for POST-Event webhooks.. - * - * @return The webhook URL for POST-Event webhooks. - */ - public final String getPostWebhookUrl() { - return this.postWebhookUrl; - } + @Getter + private final Integer preWebhookRetryCount; - /** - * Returns The The webhook request format to use for both PRE and POST - * webhooks.. - * - * @return The webhook request format to use for both PRE and POST webhooks. - */ - public final String getWebhookMethod() { - return this.webhookMethod; - } + @Getter + private final String preWebhookUrl; - /** - * Returns The The list of WebHook events that are enabled for this Service - * instance.. - * - * @return The list of WebHook events that are enabled for this Service - * instance. - */ - public final List getWebhookFilters() { - return this.webhookFilters; - } + @Getter + private final Boolean reachabilityEnabled; - /** - * Returns The Count of times webhook will be retried in case of timeout or - * 429/503/504 HTTP responses.. - * - * @return Count of times webhook will be retried in case of timeout or - * 429/503/504 HTTP responses. - */ - public final Integer getPreWebhookRetryCount() { - return this.preWebhookRetryCount; - } + @Getter + private final Boolean readStatusEnabled; - /** - * Returns The Count of times webhook will be retried in case of timeout or - * 429/503/504 HTTP responses.. - * - * @return Count of times webhook will be retried in case of timeout or - * 429/503/504 HTTP responses. - */ - public final Integer getPostWebhookRetryCount() { - return this.postWebhookRetryCount; - } + @Getter + private final String sid; - /** - * Returns The Notification configuration for the Service instance.. - * - * @return Notification configuration for the Service instance. - */ - public final Map getNotifications() { - return this.notifications; - } + @Getter + private final Integer typingIndicatorTimeout; - /** - * Returns The The media. - * - * @return The media - */ - public final Map getMedia() { - return this.media; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this service.. - * - * @return An absolute URL for this service. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final List webhookFilters; - /** - * Returns The URLs to access the Channels, Roles, and Users for this service.. - * - * @return URLs to access the Channels, Roles, and Users for this service. - */ - public final Map getLinks() { - return this.links; + @Getter + private final String webhookMethod; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "consumption_report_interval" + ) final Integer consumptionReportInterval, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "default_channel_creator_role_sid" + ) final String defaultChannelCreatorRoleSid, + @JsonProperty( + "default_channel_role_sid" + ) final String defaultChannelRoleSid, + @JsonProperty( + "default_service_role_sid" + ) final String defaultServiceRoleSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("limits") final Object limits, + @JsonProperty("links") final Map links, + @JsonProperty("media") final Object media, + @JsonProperty("notifications") final Object notifications, + @JsonProperty( + "post_webhook_retry_count" + ) final Integer postWebhookRetryCount, + @JsonProperty("post_webhook_url") final String postWebhookUrl, + @JsonProperty( + "pre_webhook_retry_count" + ) final Integer preWebhookRetryCount, + @JsonProperty("pre_webhook_url") final String preWebhookUrl, + @JsonProperty("reachability_enabled") final Boolean reachabilityEnabled, + @JsonProperty("read_status_enabled") final Boolean readStatusEnabled, + @JsonProperty("sid") final String sid, + @JsonProperty( + "typing_indicator_timeout" + ) final Integer typingIndicatorTimeout, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_filters") final List webhookFilters, + @JsonProperty("webhook_method") final String webhookMethod + ) { + this.accountSid = accountSid; + this.consumptionReportInterval = consumptionReportInterval; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; + this.defaultChannelRoleSid = defaultChannelRoleSid; + this.defaultServiceRoleSid = defaultServiceRoleSid; + this.friendlyName = friendlyName; + this.limits = limits; + this.links = links; + this.media = media; + this.notifications = notifications; + this.postWebhookRetryCount = postWebhookRetryCount; + this.postWebhookUrl = postWebhookUrl; + this.preWebhookRetryCount = preWebhookRetryCount; + this.preWebhookUrl = preWebhookUrl; + this.reachabilityEnabled = reachabilityEnabled; + this.readStatusEnabled = readStatusEnabled; + this.sid = sid; + this.typingIndicatorTimeout = typingIndicatorTimeout; + this.url = url; + this.webhookFilters = webhookFilters; + this.webhookMethod = webhookMethod; } @Override @@ -456,85 +274,77 @@ public boolean equals(final Object o) { } Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(defaultServiceRoleSid, other.defaultServiceRoleSid) && - Objects.equals(defaultChannelRoleSid, other.defaultChannelRoleSid) && - Objects.equals(defaultChannelCreatorRoleSid, other.defaultChannelCreatorRoleSid) && - Objects.equals(readStatusEnabled, other.readStatusEnabled) && - Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && - Objects.equals(typingIndicatorTimeout, other.typingIndicatorTimeout) && - Objects.equals(consumptionReportInterval, other.consumptionReportInterval) && - Objects.equals(limits, other.limits) && - Objects.equals(preWebhookUrl, other.preWebhookUrl) && - Objects.equals(postWebhookUrl, other.postWebhookUrl) && - Objects.equals(webhookMethod, other.webhookMethod) && - Objects.equals(webhookFilters, other.webhookFilters) && - Objects.equals(preWebhookRetryCount, other.preWebhookRetryCount) && - Objects.equals(postWebhookRetryCount, other.postWebhookRetryCount) && - Objects.equals(notifications, other.notifications) && - Objects.equals(media, other.media) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + consumptionReportInterval, + other.consumptionReportInterval + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultChannelCreatorRoleSid, + other.defaultChannelCreatorRoleSid + ) && + Objects.equals( + defaultChannelRoleSid, + other.defaultChannelRoleSid + ) && + Objects.equals( + defaultServiceRoleSid, + other.defaultServiceRoleSid + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(limits, other.limits) && + Objects.equals(links, other.links) && + Objects.equals(media, other.media) && + Objects.equals(notifications, other.notifications) && + Objects.equals( + postWebhookRetryCount, + other.postWebhookRetryCount + ) && + Objects.equals(postWebhookUrl, other.postWebhookUrl) && + Objects.equals(preWebhookRetryCount, other.preWebhookRetryCount) && + Objects.equals(preWebhookUrl, other.preWebhookUrl) && + Objects.equals(reachabilityEnabled, other.reachabilityEnabled) && + Objects.equals(readStatusEnabled, other.readStatusEnabled) && + Objects.equals(sid, other.sid) && + Objects.equals( + typingIndicatorTimeout, + other.typingIndicatorTimeout + ) && + Objects.equals(url, other.url) && + Objects.equals(webhookFilters, other.webhookFilters) && + Objects.equals(webhookMethod, other.webhookMethod) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - defaultServiceRoleSid, - defaultChannelRoleSid, - defaultChannelCreatorRoleSid, - readStatusEnabled, - reachabilityEnabled, - typingIndicatorTimeout, - consumptionReportInterval, - limits, - preWebhookUrl, - postWebhookUrl, - webhookMethod, - webhookFilters, - preWebhookRetryCount, - postWebhookRetryCount, - notifications, - media, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("defaultServiceRoleSid", defaultServiceRoleSid) - .add("defaultChannelRoleSid", defaultChannelRoleSid) - .add("defaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid) - .add("readStatusEnabled", readStatusEnabled) - .add("reachabilityEnabled", reachabilityEnabled) - .add("typingIndicatorTimeout", typingIndicatorTimeout) - .add("consumptionReportInterval", consumptionReportInterval) - .add("limits", limits) - .add("preWebhookUrl", preWebhookUrl) - .add("postWebhookUrl", postWebhookUrl) - .add("webhookMethod", webhookMethod) - .add("webhookFilters", webhookFilters) - .add("preWebhookRetryCount", preWebhookRetryCount) - .add("postWebhookRetryCount", postWebhookRetryCount) - .add("notifications", notifications) - .add("media", media) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + consumptionReportInterval, + dateCreated, + dateUpdated, + defaultChannelCreatorRoleSid, + defaultChannelRoleSid, + defaultServiceRoleSid, + friendlyName, + limits, + links, + media, + notifications, + postWebhookRetryCount, + postWebhookUrl, + preWebhookRetryCount, + preWebhookUrl, + reachabilityEnabled, + readStatusEnabled, + sid, + typingIndicatorTimeout, + url, + webhookFilters, + webhookMethod + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceCreator.java index 1900a47596..d1fc8cee97 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +27,86 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceCreator extends Creator { - private final String friendlyName; - /** - * Construct a new ServiceCreator. - * - * @param friendlyName Human-readable name for this service instance - */ + private String friendlyName; + public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services"; + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceDeleter.java index 1777f1124a..99d2e330f2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ServiceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new ServiceDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceFetcher.java index f6f1767187..a1ff80dceb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new ServiceFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceReader.java index f6dd4caa29..5d98e9cefb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services"; + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceUpdater.java index 19a57ebe74..31c2eb60a7 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/ServiceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,12 +28,14 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class ServiceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String defaultServiceRoleSid; private String defaultChannelRoleSid; @@ -55,595 +68,577 @@ public class ServiceUpdater extends Updater { private Integer postWebhookRetryCount; private Boolean notificationsLogEnabled; - /** - * Construct a new ServiceUpdater. - * - * @param pathSid The sid - */ public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Human-readable name for this service instance. - * - * @param friendlyName Human-readable name for this service instance - * @return this - */ public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The default_service_role_sid. - * - * @param defaultServiceRoleSid The default_service_role_sid - * @return this - */ - public ServiceUpdater setDefaultServiceRoleSid(final String defaultServiceRoleSid) { + public ServiceUpdater setDefaultServiceRoleSid( + final String defaultServiceRoleSid + ) { this.defaultServiceRoleSid = defaultServiceRoleSid; return this; } - /** - * Channel role assigned on channel join (see - * [Roles](https://www.twilio.com/docs/chat/api/roles) data model for the - * details). - * - * @param defaultChannelRoleSid Channel role assigned on channel join - * @return this - */ - public ServiceUpdater setDefaultChannelRoleSid(final String defaultChannelRoleSid) { + public ServiceUpdater setDefaultChannelRoleSid( + final String defaultChannelRoleSid + ) { this.defaultChannelRoleSid = defaultChannelRoleSid; return this; } - /** - * Channel role assigned to creator of channel when joining for first time. - * - * @param defaultChannelCreatorRoleSid Channel role assigned to creator of - * channel when joining for first time - * @return this - */ - public ServiceUpdater setDefaultChannelCreatorRoleSid(final String defaultChannelCreatorRoleSid) { + public ServiceUpdater setDefaultChannelCreatorRoleSid( + final String defaultChannelCreatorRoleSid + ) { this.defaultChannelCreatorRoleSid = defaultChannelCreatorRoleSid; return this; } - /** - * `true` if the member read status feature is enabled, `false` if not. - * Defaults to `true`.. - * - * @param readStatusEnabled true if the member read status feature is enabled, - * false if not. - * @return this - */ - public ServiceUpdater setReadStatusEnabled(final Boolean readStatusEnabled) { + public ServiceUpdater setReadStatusEnabled( + final Boolean readStatusEnabled + ) { this.readStatusEnabled = readStatusEnabled; return this; } - /** - * `true` if the reachability feature should be enabled. Defaults to `false`. - * - * @param reachabilityEnabled true if the reachability feature should be - * enabled. - * @return this - */ - public ServiceUpdater setReachabilityEnabled(final Boolean reachabilityEnabled) { + public ServiceUpdater setReachabilityEnabled( + final Boolean reachabilityEnabled + ) { this.reachabilityEnabled = reachabilityEnabled; return this; } - /** - * The duration in seconds indicating the timeout after "started typing" event - * when client should assume that user is not typing anymore even if no "ended - * typing" message received. - * - * @param typingIndicatorTimeout The duration in seconds indicating the timeout - * after "started typing" event when client should - * assume that user is not typing anymore even if - * no "ended typing" message received - * @return this - */ - public ServiceUpdater setTypingIndicatorTimeout(final Integer typingIndicatorTimeout) { + public ServiceUpdater setTypingIndicatorTimeout( + final Integer typingIndicatorTimeout + ) { this.typingIndicatorTimeout = typingIndicatorTimeout; return this; } - /** - * The consumption_report_interval. - * - * @param consumptionReportInterval The consumption_report_interval - * @return this - */ - public ServiceUpdater setConsumptionReportInterval(final Integer consumptionReportInterval) { + public ServiceUpdater setConsumptionReportInterval( + final Integer consumptionReportInterval + ) { this.consumptionReportInterval = consumptionReportInterval; return this; } - /** - * The notifications.new_message.enabled. - * - * @param notificationsNewMessageEnabled The notifications.new_message.enabled - * @return this - */ - public ServiceUpdater setNotificationsNewMessageEnabled(final Boolean notificationsNewMessageEnabled) { + public ServiceUpdater setNotificationsNewMessageEnabled( + final Boolean notificationsNewMessageEnabled + ) { this.notificationsNewMessageEnabled = notificationsNewMessageEnabled; return this; } - /** - * The notifications.new_message.template. - * - * @param notificationsNewMessageTemplate The notifications.new_message.template - * @return this - */ - public ServiceUpdater setNotificationsNewMessageTemplate(final String notificationsNewMessageTemplate) { + public ServiceUpdater setNotificationsNewMessageTemplate( + final String notificationsNewMessageTemplate + ) { this.notificationsNewMessageTemplate = notificationsNewMessageTemplate; return this; } - /** - * The notifications.new_message.sound. - * - * @param notificationsNewMessageSound The notifications.new_message.sound - * @return this - */ - public ServiceUpdater setNotificationsNewMessageSound(final String notificationsNewMessageSound) { + public ServiceUpdater setNotificationsNewMessageSound( + final String notificationsNewMessageSound + ) { this.notificationsNewMessageSound = notificationsNewMessageSound; return this; } - /** - * The notifications.new_message.badge_count_enabled. - * - * @param notificationsNewMessageBadgeCountEnabled The - * notifications.new_message.badge_count_enabled - * @return this - */ - public ServiceUpdater setNotificationsNewMessageBadgeCountEnabled(final Boolean notificationsNewMessageBadgeCountEnabled) { - this.notificationsNewMessageBadgeCountEnabled = notificationsNewMessageBadgeCountEnabled; + public ServiceUpdater setNotificationsNewMessageBadgeCountEnabled( + final Boolean notificationsNewMessageBadgeCountEnabled + ) { + this.notificationsNewMessageBadgeCountEnabled = + notificationsNewMessageBadgeCountEnabled; return this; } - /** - * The notifications.added_to_channel.enabled. - * - * @param notificationsAddedToChannelEnabled The - * notifications.added_to_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelEnabled(final Boolean notificationsAddedToChannelEnabled) { - this.notificationsAddedToChannelEnabled = notificationsAddedToChannelEnabled; + public ServiceUpdater setNotificationsAddedToChannelEnabled( + final Boolean notificationsAddedToChannelEnabled + ) { + this.notificationsAddedToChannelEnabled = + notificationsAddedToChannelEnabled; return this; } - /** - * The notifications.added_to_channel.template. - * - * @param notificationsAddedToChannelTemplate The - * notifications.added_to_channel.template - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelTemplate(final String notificationsAddedToChannelTemplate) { - this.notificationsAddedToChannelTemplate = notificationsAddedToChannelTemplate; + public ServiceUpdater setNotificationsAddedToChannelTemplate( + final String notificationsAddedToChannelTemplate + ) { + this.notificationsAddedToChannelTemplate = + notificationsAddedToChannelTemplate; return this; } - /** - * The notifications.added_to_channel.sound. - * - * @param notificationsAddedToChannelSound The - * notifications.added_to_channel.sound - * @return this - */ - public ServiceUpdater setNotificationsAddedToChannelSound(final String notificationsAddedToChannelSound) { - this.notificationsAddedToChannelSound = notificationsAddedToChannelSound; + public ServiceUpdater setNotificationsAddedToChannelSound( + final String notificationsAddedToChannelSound + ) { + this.notificationsAddedToChannelSound = + notificationsAddedToChannelSound; return this; } - /** - * The notifications.removed_from_channel.enabled. - * - * @param notificationsRemovedFromChannelEnabled The - * notifications.removed_from_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelEnabled(final Boolean notificationsRemovedFromChannelEnabled) { - this.notificationsRemovedFromChannelEnabled = notificationsRemovedFromChannelEnabled; + public ServiceUpdater setNotificationsRemovedFromChannelEnabled( + final Boolean notificationsRemovedFromChannelEnabled + ) { + this.notificationsRemovedFromChannelEnabled = + notificationsRemovedFromChannelEnabled; return this; } - /** - * The notifications.removed_from_channel.template. - * - * @param notificationsRemovedFromChannelTemplate The - * notifications.removed_from_channel.template - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelTemplate(final String notificationsRemovedFromChannelTemplate) { - this.notificationsRemovedFromChannelTemplate = notificationsRemovedFromChannelTemplate; + public ServiceUpdater setNotificationsRemovedFromChannelTemplate( + final String notificationsRemovedFromChannelTemplate + ) { + this.notificationsRemovedFromChannelTemplate = + notificationsRemovedFromChannelTemplate; return this; } - /** - * The notifications.removed_from_channel.sound. - * - * @param notificationsRemovedFromChannelSound The - * notifications.removed_from_channel.sound - * @return this - */ - public ServiceUpdater setNotificationsRemovedFromChannelSound(final String notificationsRemovedFromChannelSound) { - this.notificationsRemovedFromChannelSound = notificationsRemovedFromChannelSound; + public ServiceUpdater setNotificationsRemovedFromChannelSound( + final String notificationsRemovedFromChannelSound + ) { + this.notificationsRemovedFromChannelSound = + notificationsRemovedFromChannelSound; return this; } - /** - * The notifications.invited_to_channel.enabled. - * - * @param notificationsInvitedToChannelEnabled The - * notifications.invited_to_channel.enabled - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelEnabled(final Boolean notificationsInvitedToChannelEnabled) { - this.notificationsInvitedToChannelEnabled = notificationsInvitedToChannelEnabled; + public ServiceUpdater setNotificationsInvitedToChannelEnabled( + final Boolean notificationsInvitedToChannelEnabled + ) { + this.notificationsInvitedToChannelEnabled = + notificationsInvitedToChannelEnabled; return this; } - /** - * The notifications.invited_to_channel.template. - * - * @param notificationsInvitedToChannelTemplate The - * notifications.invited_to_channel.template - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelTemplate(final String notificationsInvitedToChannelTemplate) { - this.notificationsInvitedToChannelTemplate = notificationsInvitedToChannelTemplate; + public ServiceUpdater setNotificationsInvitedToChannelTemplate( + final String notificationsInvitedToChannelTemplate + ) { + this.notificationsInvitedToChannelTemplate = + notificationsInvitedToChannelTemplate; return this; } - /** - * The notifications.invited_to_channel.sound. - * - * @param notificationsInvitedToChannelSound The - * notifications.invited_to_channel.sound - * @return this - */ - public ServiceUpdater setNotificationsInvitedToChannelSound(final String notificationsInvitedToChannelSound) { - this.notificationsInvitedToChannelSound = notificationsInvitedToChannelSound; + public ServiceUpdater setNotificationsInvitedToChannelSound( + final String notificationsInvitedToChannelSound + ) { + this.notificationsInvitedToChannelSound = + notificationsInvitedToChannelSound; return this; } - /** - * The webhook URL for PRE-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param preWebhookUrl The webhook URL for PRE-Event webhooks. - * @return this - */ public ServiceUpdater setPreWebhookUrl(final URI preWebhookUrl) { this.preWebhookUrl = preWebhookUrl; return this; } - /** - * The webhook URL for PRE-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param preWebhookUrl The webhook URL for PRE-Event webhooks. - * @return this - */ public ServiceUpdater setPreWebhookUrl(final String preWebhookUrl) { return setPreWebhookUrl(Promoter.uriFromString(preWebhookUrl)); } - /** - * The webhook URL for POST-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param postWebhookUrl The webhook URL for POST-Event webhooks. - * @return this - */ public ServiceUpdater setPostWebhookUrl(final URI postWebhookUrl) { this.postWebhookUrl = postWebhookUrl; return this; } - /** - * The webhook URL for POST-Event webhooks. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param postWebhookUrl The webhook URL for POST-Event webhooks. - * @return this - */ public ServiceUpdater setPostWebhookUrl(final String postWebhookUrl) { return setPostWebhookUrl(Promoter.uriFromString(postWebhookUrl)); } - /** - * The webhook request format to use. Must be POST or GET. See [Webhook - * Events](https://www.twilio.com/docs/chat/webhook-events) for more details.. - * - * @param webhookMethod The webhook request format to use. - * @return this - */ public ServiceUpdater setWebhookMethod(final HttpMethod webhookMethod) { this.webhookMethod = webhookMethod; return this; } - /** - * The list of WebHook events that are enabled for this Service instance. See - * [Webhook Events](https://www.twilio.com/docs/chat/webhook-events) for more - * details.. - * - * @param webhookFilters The list of WebHook events that are enabled for this - * Service instance. - * @return this - */ public ServiceUpdater setWebhookFilters(final List webhookFilters) { this.webhookFilters = webhookFilters; return this; } - /** - * The list of WebHook events that are enabled for this Service instance. See - * [Webhook Events](https://www.twilio.com/docs/chat/webhook-events) for more - * details.. - * - * @param webhookFilters The list of WebHook events that are enabled for this - * Service instance. - * @return this - */ public ServiceUpdater setWebhookFilters(final String webhookFilters) { return setWebhookFilters(Promoter.listOfOne(webhookFilters)); } - /** - * The maximum number of Members that can be added to Channels within this - * Service. The maximum allowed value is 1,000. - * - * @param limitsChannelMembers The maximum number of Members that can be added - * to Channels within this Service. - * @return this - */ - public ServiceUpdater setLimitsChannelMembers(final Integer limitsChannelMembers) { + public ServiceUpdater setLimitsChannelMembers( + final Integer limitsChannelMembers + ) { this.limitsChannelMembers = limitsChannelMembers; return this; } - /** - * The maximum number of Channels Users can be a Member of within this Service. - * The maximum value allowed is 1,000. - * - * @param limitsUserChannels The maximum number of Channels Users can be a - * Member of within this Service. - * @return this - */ - public ServiceUpdater setLimitsUserChannels(final Integer limitsUserChannels) { + public ServiceUpdater setLimitsUserChannels( + final Integer limitsUserChannels + ) { this.limitsUserChannels = limitsUserChannels; return this; } - /** - * The media.compatibility_message. - * - * @param mediaCompatibilityMessage The media.compatibility_message - * @return this - */ - public ServiceUpdater setMediaCompatibilityMessage(final String mediaCompatibilityMessage) { + public ServiceUpdater setMediaCompatibilityMessage( + final String mediaCompatibilityMessage + ) { this.mediaCompatibilityMessage = mediaCompatibilityMessage; return this; } - /** - * Count of times webhook will be retried in case of timeout (5 seconds) or - * 429/503/504 HTTP responses. Default retry count is 0 times.. - * - * @param preWebhookRetryCount Count of times webhook will be retried in case - * of timeout or 429/503/504 HTTP responses. - * @return this - */ - public ServiceUpdater setPreWebhookRetryCount(final Integer preWebhookRetryCount) { + public ServiceUpdater setPreWebhookRetryCount( + final Integer preWebhookRetryCount + ) { this.preWebhookRetryCount = preWebhookRetryCount; return this; } - /** - * Count of times webhook will be retried in case of timeout (5 seconds) or - * 429/503/504 HTTP responses. Default retry count is 0 times.. - * - * @param postWebhookRetryCount Count of times webhook will be retried in case - * of timeout or 429/503/504 HTTP responses. - * @return this - */ - public ServiceUpdater setPostWebhookRetryCount(final Integer postWebhookRetryCount) { + public ServiceUpdater setPostWebhookRetryCount( + final Integer postWebhookRetryCount + ) { this.postWebhookRetryCount = postWebhookRetryCount; return this; } - /** - * The notifications.log_enabled. - * - * @param notificationsLogEnabled The notifications.log_enabled - * @return this - */ - public ServiceUpdater setNotificationsLogEnabled(final Boolean notificationsLogEnabled) { + public ServiceUpdater setNotificationsLogEnabled( + final Boolean notificationsLogEnabled + ) { this.notificationsLogEnabled = notificationsLogEnabled; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (defaultServiceRoleSid != null) { - request.addPostParam("DefaultServiceRoleSid", defaultServiceRoleSid); + Serializer.toString( + request, + "DefaultServiceRoleSid", + defaultServiceRoleSid, + ParameterType.URLENCODED + ); } if (defaultChannelRoleSid != null) { - request.addPostParam("DefaultChannelRoleSid", defaultChannelRoleSid); + Serializer.toString( + request, + "DefaultChannelRoleSid", + defaultChannelRoleSid, + ParameterType.URLENCODED + ); } if (defaultChannelCreatorRoleSid != null) { - request.addPostParam("DefaultChannelCreatorRoleSid", defaultChannelCreatorRoleSid); + Serializer.toString( + request, + "DefaultChannelCreatorRoleSid", + defaultChannelCreatorRoleSid, + ParameterType.URLENCODED + ); } if (readStatusEnabled != null) { - request.addPostParam("ReadStatusEnabled", readStatusEnabled.toString()); + Serializer.toString( + request, + "ReadStatusEnabled", + readStatusEnabled, + ParameterType.URLENCODED + ); } if (reachabilityEnabled != null) { - request.addPostParam("ReachabilityEnabled", reachabilityEnabled.toString()); + Serializer.toString( + request, + "ReachabilityEnabled", + reachabilityEnabled, + ParameterType.URLENCODED + ); } if (typingIndicatorTimeout != null) { - request.addPostParam("TypingIndicatorTimeout", typingIndicatorTimeout.toString()); + Serializer.toString( + request, + "TypingIndicatorTimeout", + typingIndicatorTimeout, + ParameterType.URLENCODED + ); } if (consumptionReportInterval != null) { - request.addPostParam("ConsumptionReportInterval", consumptionReportInterval.toString()); + Serializer.toString( + request, + "ConsumptionReportInterval", + consumptionReportInterval, + ParameterType.URLENCODED + ); } if (notificationsNewMessageEnabled != null) { - request.addPostParam("Notifications.NewMessage.Enabled", notificationsNewMessageEnabled.toString()); + Serializer.toString( + request, + "Notifications.NewMessage.Enabled", + notificationsNewMessageEnabled, + ParameterType.URLENCODED + ); } if (notificationsNewMessageTemplate != null) { - request.addPostParam("Notifications.NewMessage.Template", notificationsNewMessageTemplate); + Serializer.toString( + request, + "Notifications.NewMessage.Template", + notificationsNewMessageTemplate, + ParameterType.URLENCODED + ); } if (notificationsNewMessageSound != null) { - request.addPostParam("Notifications.NewMessage.Sound", notificationsNewMessageSound); + Serializer.toString( + request, + "Notifications.NewMessage.Sound", + notificationsNewMessageSound, + ParameterType.URLENCODED + ); } if (notificationsNewMessageBadgeCountEnabled != null) { - request.addPostParam("Notifications.NewMessage.BadgeCountEnabled", notificationsNewMessageBadgeCountEnabled.toString()); + Serializer.toString( + request, + "Notifications.NewMessage.BadgeCountEnabled", + notificationsNewMessageBadgeCountEnabled, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelEnabled != null) { - request.addPostParam("Notifications.AddedToChannel.Enabled", notificationsAddedToChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.AddedToChannel.Enabled", + notificationsAddedToChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelTemplate != null) { - request.addPostParam("Notifications.AddedToChannel.Template", notificationsAddedToChannelTemplate); + Serializer.toString( + request, + "Notifications.AddedToChannel.Template", + notificationsAddedToChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsAddedToChannelSound != null) { - request.addPostParam("Notifications.AddedToChannel.Sound", notificationsAddedToChannelSound); + Serializer.toString( + request, + "Notifications.AddedToChannel.Sound", + notificationsAddedToChannelSound, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelEnabled != null) { - request.addPostParam("Notifications.RemovedFromChannel.Enabled", notificationsRemovedFromChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Enabled", + notificationsRemovedFromChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelTemplate != null) { - request.addPostParam("Notifications.RemovedFromChannel.Template", notificationsRemovedFromChannelTemplate); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Template", + notificationsRemovedFromChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsRemovedFromChannelSound != null) { - request.addPostParam("Notifications.RemovedFromChannel.Sound", notificationsRemovedFromChannelSound); + Serializer.toString( + request, + "Notifications.RemovedFromChannel.Sound", + notificationsRemovedFromChannelSound, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelEnabled != null) { - request.addPostParam("Notifications.InvitedToChannel.Enabled", notificationsInvitedToChannelEnabled.toString()); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Enabled", + notificationsInvitedToChannelEnabled, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelTemplate != null) { - request.addPostParam("Notifications.InvitedToChannel.Template", notificationsInvitedToChannelTemplate); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Template", + notificationsInvitedToChannelTemplate, + ParameterType.URLENCODED + ); } if (notificationsInvitedToChannelSound != null) { - request.addPostParam("Notifications.InvitedToChannel.Sound", notificationsInvitedToChannelSound); + Serializer.toString( + request, + "Notifications.InvitedToChannel.Sound", + notificationsInvitedToChannelSound, + ParameterType.URLENCODED + ); } if (preWebhookUrl != null) { - request.addPostParam("PreWebhookUrl", preWebhookUrl.toString()); + Serializer.toString( + request, + "PreWebhookUrl", + preWebhookUrl, + ParameterType.URLENCODED + ); } if (postWebhookUrl != null) { - request.addPostParam("PostWebhookUrl", postWebhookUrl.toString()); + Serializer.toString( + request, + "PostWebhookUrl", + postWebhookUrl, + ParameterType.URLENCODED + ); } if (webhookMethod != null) { - request.addPostParam("WebhookMethod", webhookMethod.toString()); + Serializer.toString( + request, + "WebhookMethod", + webhookMethod, + ParameterType.URLENCODED + ); } if (webhookFilters != null) { - for (String prop : webhookFilters) { - request.addPostParam("WebhookFilters", prop); + for (String param : webhookFilters) { + Serializer.toString( + request, + "WebhookFilters", + param, + ParameterType.URLENCODED + ); } } if (limitsChannelMembers != null) { - request.addPostParam("Limits.ChannelMembers", limitsChannelMembers.toString()); + Serializer.toString( + request, + "Limits.ChannelMembers", + limitsChannelMembers, + ParameterType.URLENCODED + ); } if (limitsUserChannels != null) { - request.addPostParam("Limits.UserChannels", limitsUserChannels.toString()); + Serializer.toString( + request, + "Limits.UserChannels", + limitsUserChannels, + ParameterType.URLENCODED + ); } if (mediaCompatibilityMessage != null) { - request.addPostParam("Media.CompatibilityMessage", mediaCompatibilityMessage); + Serializer.toString( + request, + "Media.CompatibilityMessage", + mediaCompatibilityMessage, + ParameterType.URLENCODED + ); } if (preWebhookRetryCount != null) { - request.addPostParam("PreWebhookRetryCount", preWebhookRetryCount.toString()); + Serializer.toString( + request, + "PreWebhookRetryCount", + preWebhookRetryCount, + ParameterType.URLENCODED + ); } if (postWebhookRetryCount != null) { - request.addPostParam("PostWebhookRetryCount", postWebhookRetryCount.toString()); + Serializer.toString( + request, + "PostWebhookRetryCount", + postWebhookRetryCount, + ParameterType.URLENCODED + ); } if (notificationsLogEnabled != null) { - request.addPostParam("Notifications.LogEnabled", notificationsLogEnabled.toString()); + Serializer.toString( + request, + "Notifications.LogEnabled", + notificationsLogEnabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Binding.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Binding.java index c4a5dd7310..74fc9c4399 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Binding.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Binding.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; @@ -10,33 +17,52 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Binding extends Resource { - private static final long serialVersionUID = 102481637129176L; + + public static BindingDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new BindingDeleter(pathServiceSid, pathSid); + } + + public static BindingFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new BindingFetcher(pathServiceSid, pathSid); + } + + public static BindingReader reader(final String pathServiceSid) { + return new BindingReader(pathServiceSid); + } public enum BindingType { GCM("gcm"), @@ -49,63 +75,28 @@ private BindingType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a BindingType from a string. - * @param value string value - * @return generated BindingType - */ @JsonCreator public static BindingType forValue(final String value) { return Promoter.enumFromString(value, BindingType.values()); } } - /** - * Create a BindingReader to execute read. - * - * @param pathServiceSid The service_sid - * @return BindingReader capable of executing the read - */ - public static BindingReader reader(final String pathServiceSid) { - return new BindingReader(pathServiceSid); - } - - /** - * Create a BindingFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return BindingFetcher capable of executing the fetch - */ - public static BindingFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new BindingFetcher(pathServiceSid, pathSid); - } - - /** - * Create a BindingDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return BindingDeleter capable of executing the delete - */ - public static BindingDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new BindingDeleter(pathServiceSid, pathSid); - } - /** * Converts a JSON String into a Binding object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Binding object represented by the provided JSON */ - public static Binding fromJson(final String json, final ObjectMapper objectMapper) { + public static Binding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -119,12 +110,15 @@ public static Binding fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Binding object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Binding object represented by the provided JSON */ - public static Binding fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Binding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -135,166 +129,91 @@ public static Binding fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String endpoint; - private final String identity; - private final String credentialSid; - private final Binding.BindingType bindingType; - private final List messageTypes; - private final URI url; - private final Map links; - - @JsonCreator - private Binding(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("endpoint") - final String endpoint, - @JsonProperty("identity") - final String identity, - @JsonProperty("credential_sid") - final String credentialSid, - @JsonProperty("binding_type") - final Binding.BindingType bindingType, - @JsonProperty("message_types") - final List messageTypes, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.endpoint = endpoint; - this.identity = identity; - this.credentialSid = credentialSid; - this.bindingType = bindingType; - this.messageTypes = messageTypes; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this binding.. - * - * @return The unique id of the Account responsible for this binding. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Binding.BindingType bindingType; - /** - * Returns The The unique id of the Service this binding belongs to.. - * - * @return The unique id of the Service this binding belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String credentialSid; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The unique endpoint identifier for this Binding.. - * - * @return The unique endpoint identifier for this Binding. - */ - public final String getEndpoint() { - return this.endpoint; - } + @Getter + private final String endpoint; - /** - * Returns The A unique string identifier for the Binding for this User in this - * Service.. - * - * @return A unique string identifier for the Binding for this User in this - * Service. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final String identity; - /** - * Returns The The unique id of the Credential for this binding.. - * - * @return The unique id of the Credential for this binding. - */ - public final String getCredentialSid() { - return this.credentialSid; - } + @Getter + private final Map links; - /** - * Returns The The push technology to use for this binding.. - * - * @return The push technology to use for this binding. - */ - public final Binding.BindingType getBindingType() { - return this.bindingType; - } + @Getter + private final List messageTypes; - /** - * Returns The List of message types for this binding.. - * - * @return List of message types for this binding. - */ - public final List getMessageTypes() { - return this.messageTypes; - } + @Getter + private final String serviceSid; - /** - * Returns The An absolute URL for this binding.. - * - * @return An absolute URL for this binding. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String sid; - /** - * Returns The Absolute URLs to access the Users for this Binding.. - * - * @return Absolute URLs to access the Users for this Binding. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Binding( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("binding_type") final Binding.BindingType bindingType, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("links") final Map links, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.bindingType = bindingType; + this.credentialSid = credentialSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.endpoint = endpoint; + this.identity = identity; + this.links = links; + this.messageTypes = messageTypes; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -308,52 +227,37 @@ public boolean equals(final Object o) { } Binding other = (Binding) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(endpoint, other.endpoint) && - Objects.equals(identity, other.identity) && - Objects.equals(credentialSid, other.credentialSid) && - Objects.equals(bindingType, other.bindingType) && - Objects.equals(messageTypes, other.messageTypes) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(links, other.links) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - endpoint, - identity, - credentialSid, - bindingType, - messageTypes, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("endpoint", endpoint) - .add("identity", identity) - .add("credentialSid", credentialSid) - .add("bindingType", bindingType) - .add("messageTypes", messageTypes) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + bindingType, + credentialSid, + dateCreated, + dateUpdated, + endpoint, + identity, + links, + messageTypes, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingDeleter.java index d8e5e0b3c8..31b5b39c6b 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class BindingDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new BindingDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public BindingDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public BindingDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Binding delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingFetcher.java index 257e9a9d70..1225d11b62 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class BindingFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new BindingFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public BindingFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public BindingFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Binding - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Binding fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Binding fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Binding fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Binding.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Binding content = Binding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingReader.java index ed505e0d42..e8045468bf 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/BindingReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; @@ -10,222 +17,241 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class BindingReader extends Reader { - private final String pathServiceSid; + + private String pathServiceSid; private List bindingType; private List identity; + private Long pageSize; - /** - * Construct a new BindingReader. - * - * @param pathServiceSid The service_sid - */ public BindingReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * The push technology used for the returned Bindings. Supported values are - * apn, gcm and fcm. See [push notification - * configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more information.. - * - * @param bindingType The push technology used for the bindings returned. - * @return this - */ - public BindingReader setBindingType(final List bindingType) { + public BindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - /** - * The push technology used for the returned Bindings. Supported values are - * apn, gcm and fcm. See [push notification - * configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more information.. - * - * @param bindingType The push technology used for the bindings returned. - * @return this - */ public BindingReader setBindingType(final Binding.BindingType bindingType) { return setBindingType(Promoter.listOfOne(bindingType)); } - /** - * The identity. - * - * @param identity The identity - * @return this - */ public BindingReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * The identity. - * - * @param identity The identity - * @return this - */ public BindingReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public BindingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Bindings"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Bindings", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Binding read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Binding Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Binding read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "bindings", - response.getContent(), - Binding.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (bindingType != null) { - for (Binding.BindingType prop : bindingType) { - request.addQueryParam("BindingType", prop.toString()); + for (Binding.BindingType param : bindingType) { + Serializer.toString( + request, + "BindingType", + param, + ParameterType.QUERY + ); } } if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Channel.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Channel.java index 3ecf81ca50..9409a7c528 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Channel.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Channel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; @@ -10,122 +17,116 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Channel extends Resource { - private static final long serialVersionUID = 275623534063843L; - public enum ChannelType { - PUBLIC("public"), - PRIVATE("private"); + public static ChannelCreator creator(final String pathServiceSid) { + return new ChannelCreator(pathServiceSid); + } + + public static ChannelDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelDeleter(pathServiceSid, pathSid); + } + + public static ChannelFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelFetcher(pathServiceSid, pathSid); + } + + public static ChannelReader reader(final String pathServiceSid) { + return new ChannelReader(pathServiceSid); + } + + public static ChannelUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new ChannelUpdater(pathServiceSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); private final String value; - private ChannelType(final String value) { + private WebhookEnabledType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ChannelType from a string. - * @param value string value - * @return generated ChannelType - */ @JsonCreator - public static ChannelType forValue(final String value) { - return Promoter.enumFromString(value, ChannelType.values()); + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); } } - /** - * Create a ChannelFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelFetcher capable of executing the fetch - */ - public static ChannelFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new ChannelFetcher(pathServiceSid, pathSid); - } + public enum ChannelType { + PUBLIC("public"), + PRIVATE("private"); - /** - * Create a ChannelDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelDeleter capable of executing the delete - */ - public static ChannelDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new ChannelDeleter(pathServiceSid, pathSid); - } + private final String value; - /** - * Create a ChannelCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return ChannelCreator capable of executing the create - */ - public static ChannelCreator creator(final String pathServiceSid) { - return new ChannelCreator(pathServiceSid); - } + private ChannelType(final String value) { + this.value = value; + } - /** - * Create a ChannelReader to execute read. - * - * @param pathServiceSid The service_sid - * @return ChannelReader capable of executing the read - */ - public static ChannelReader reader(final String pathServiceSid) { - return new ChannelReader(pathServiceSid); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a ChannelUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ChannelUpdater capable of executing the update - */ - public static ChannelUpdater updater(final String pathServiceSid, - final String pathSid) { - return new ChannelUpdater(pathServiceSid, pathSid); + @JsonCreator + public static ChannelType forValue(final String value) { + return Promoter.enumFromString(value, ChannelType.values()); + } } /** * Converts a JSON String into a Channel object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Channel object represented by the provided JSON */ - public static Channel fromJson(final String json, final ObjectMapper objectMapper) { + public static Channel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -139,12 +140,15 @@ public static Channel fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Channel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Channel object represented by the provided JSON */ - public static Channel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Channel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Channel.class); @@ -155,194 +159,101 @@ public static Channel fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String friendlyName; - private final String uniqueName; - private final String attributes; - private final Channel.ChannelType type; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - private final Integer membersCount; - private final Integer messagesCount; - private final URI url; - private final Map links; - - @JsonCreator - private Channel(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("type") - final Channel.ChannelType type, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy, - @JsonProperty("members_count") - final Integer membersCount, - @JsonProperty("messages_count") - final Integer messagesCount, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.friendlyName = friendlyName; - this.uniqueName = uniqueName; - this.attributes = attributes; - this.type = type; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - this.membersCount = membersCount; - this.messagesCount = messagesCount; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this channel.. - * - * @return The unique id of the Account responsible for this channel. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String attributes; - /** - * Returns The The unique id of the Service this channel belongs to.. - * - * @return The unique id of the Service this channel belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String createdBy; - /** - * Returns The The human-readable name of this channel.. - * - * @return The human-readable name of this channel. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique, addressable name of this channel.. - * - * @return The unique, addressable name of this channel. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } + @Getter + private final String friendlyName; - /** - * Returns The The visibility of this channel - either public or private. - * - * @return The visibility of this channel - either public or private - */ - public final Channel.ChannelType getType() { - return this.type; - } + @Getter + private final Map links; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Integer membersCount; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer messagesCount; - /** - * Returns The Identity of the channel's creator.. - * - * @return Identity of the channel's creator. - */ - public final String getCreatedBy() { - return this.createdBy; - } + @Getter + private final String serviceSid; - /** - * Returns The The number of Members in the Channel. - * - * @return The number of Members in the Channel - */ - public final Integer getMembersCount() { - return this.membersCount; - } + @Getter + private final String sid; - /** - * Returns The The number of Messages in the Channel. - * - * @return The number of Messages in the Channel - */ - public final Integer getMessagesCount() { - return this.messagesCount; - } + @Getter + private final Channel.ChannelType type; - /** - * Returns The An absolute URL for this channel.. - * - * @return An absolute URL for this channel. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String uniqueName; - /** - * Returns The Absolute URLs to access the Members, Messages , Invites and, if - * it exists the last Message for this Channel.. - * - * @return Absolute URLs to access the Members, Messages , Invites and, if it - * exists the last Message for this Channel. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Channel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("members_count") final Integer membersCount, + @JsonProperty("messages_count") final Integer messagesCount, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Channel.ChannelType type, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.membersCount = membersCount; + this.messagesCount = messagesCount; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -356,58 +267,41 @@ public boolean equals(final Object o) { } Channel other = (Channel) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(attributes, other.attributes) && - Objects.equals(type, other.type) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy) && - Objects.equals(membersCount, other.membersCount) && - Objects.equals(messagesCount, other.messagesCount) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(membersCount, other.membersCount) && + Objects.equals(messagesCount, other.messagesCount) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - friendlyName, - uniqueName, - attributes, - type, - dateCreated, - dateUpdated, - createdBy, - membersCount, - messagesCount, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("friendlyName", friendlyName) - .add("uniqueName", uniqueName) - .add("attributes", attributes) - .add("type", type) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .add("membersCount", membersCount) - .add("messagesCount", messagesCount) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + attributes, + createdBy, + dateCreated, + dateUpdated, + friendlyName, + links, + membersCount, + messagesCount, + serviceSid, + sid, + type, + uniqueName, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelCreator.java index b945113ee5..641eb68334 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Creator; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,188 +27,204 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class ChannelCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; + private Channel.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; private String uniqueName; private String attributes; private Channel.ChannelType type; - private DateTime dateCreated; - private DateTime dateUpdated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; private String createdBy; - /** - * Construct a new ChannelCreator. - * - * @param pathServiceSid The service_sid - */ public ChannelCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * A human-readable name for the Channel. Optional.. - * - * @param friendlyName A human-readable name for the Channel. - * @return this - */ public ChannelCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A unique, addressable name for the Channel. Optional.. - * - * @param uniqueName A unique, addressable name for the Channel. - * @return this - */ public ChannelCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An optional metadata field you can use to store any data you wish. No - * processing or validation is done on this field.. - * - * @param attributes An optional metadata field you can use to store any data - * you wish. - * @return this - */ public ChannelCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The visibility of the channel - `public` or `private`. Defaults to `public`.. - * - * @param type The visibility of the channel - public or private. - * @return this - */ public ChannelCreator setType(final Channel.ChannelType type) { this.type = type; return this; } - /** - * The optional ISO8601 time specifying the datetime the Channel should be set - * as being created. Will be set to the current time by the Chat service if not - * specified. Note that this should only be used in cases where a a Channel is - * being recreated from a backup/separate source. - * - * @param dateCreated The optional ISO8601 time specifying the datetime the - * Channel should be set as being created. - * @return this - */ - public ChannelCreator setDateCreated(final DateTime dateCreated) { + public ChannelCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The optional ISO8601 time specifying the datetime the Channel should be set - * as having been last updated. Will be set to the `null` by the Chat service - * if not specified. Note that this should only be used in cases where a - * Channel is being recreated from a backup/separate source and where a Message - * was previously updated.. - * - * @param dateUpdated The optional ISO8601 time specifying the datetime the - * Channel should be set as having been last updated. - * @return this - */ - public ChannelCreator setDateUpdated(final DateTime dateUpdated) { + public ChannelCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Optional field to specify the Identity of the User that created the Channel. - * Will be set to "system" if not specified.. - * - * @param createdBy Optional field to specify the Identity of the User that - * created the Channel. - * @return this - */ public ChannelCreator setCreatedBy(final String createdBy) { this.createdBy = createdBy; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel create(final TwilioRestClient client) { + public ChannelCreator setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel create(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); } if (createdBy != null) { - request.addPostParam("CreatedBy", createdBy); + Serializer.toString( + request, + "CreatedBy", + createdBy, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelDeleter.java index 9c4c28f466..f827a75b77 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +26,101 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ChannelDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ChannelDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + private Channel.WebhookEnabledType xTwilioWebhookEnabled; + + public ChannelDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public ChannelDeleter setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelFetcher.java index 54451c0deb..c56228ff15 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ChannelFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ChannelFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public ChannelFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelReader.java index f69ebf5e03..506586b8f3 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; @@ -10,190 +17,218 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class ChannelReader extends Reader { - private final String pathServiceSid; + + private String pathServiceSid; private List type; + private Long pageSize; - /** - * Construct a new ChannelReader. - * - * @param pathServiceSid The service_sid - */ public ChannelReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * The type. - * - * @param type The type - * @return this - */ public ChannelReader setType(final List type) { this.type = type; return this; } - /** - * The type. - * - * @param type The type - * @return this - */ public ChannelReader setType(final Channel.ChannelType type) { return setType(Promoter.listOfOne(type)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Channel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Channel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + Channel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Channel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Channel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - Channel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (type != null) { - for (Channel.ChannelType prop : type) { - request.addQueryParam("Type", prop.toString()); + for (Channel.ChannelType param : type) { + Serializer.toString( + request, + "Type", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelUpdater.java index e564573d6e..51c0ab1598 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/ChannelUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.DateConverter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,170 +27,192 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class ChannelUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; + private Channel.WebhookEnabledType xTwilioWebhookEnabled; private String friendlyName; private String uniqueName; private String attributes; - private DateTime dateCreated; - private DateTime dateUpdated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; private String createdBy; - /** - * Construct a new ChannelUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ChannelUpdater(final String pathServiceSid, - final String pathSid) { + public ChannelUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * A human-readable name for the Channel. Optional.. - * - * @param friendlyName A human-readable name for the Channel. - * @return this - */ public ChannelUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A unique, addressable name for the Channel. Optional.. - * - * @param uniqueName A unique, addressable name for the Channel. - * @return this - */ public ChannelUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An optional metadata field you can use to store any data you wish. No - * processing or validation is done on this field.. - * - * @param attributes An optional metadata field you can use to store any data - * you wish. - * @return this - */ public ChannelUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The optional ISO8601 time specifying the datetime the Channel should be set - * as being created.. - * - * @param dateCreated The optional ISO8601 time specifying the datetime the - * Channel should be set as being created. - * @return this - */ - public ChannelUpdater setDateCreated(final DateTime dateCreated) { + public ChannelUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The optional ISO8601 time specifying the datetime the Channel should be set - * as having been last updated.. - * - * @param dateUpdated The optional ISO8601 time specifying the datetime the - * Channel should be set as having been last updated. - * @return this - */ - public ChannelUpdater setDateUpdated(final DateTime dateUpdated) { + public ChannelUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Optional field to specify the Identity of the User that created the Channel.. - * - * @param createdBy Optional field to specify the Identity of the User that - * created the Channel. - * @return this - */ public ChannelUpdater setCreatedBy(final String createdBy) { this.createdBy = createdBy; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Channel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Channel update(final TwilioRestClient client) { + public ChannelUpdater setXTwilioWebhookEnabled( + final Channel.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Channel update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Channel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Channel update(final TwilioRestClient client) { + Response response = makeRequest(client); return Channel.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Channel content = Channel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); } if (createdBy != null) { - request.addPostParam("CreatedBy", createdBy); + Serializer.toString( + request, + "CreatedBy", + createdBy, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Role.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Role.java index 89244165ff..c16bcfcd5f 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/Role.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/Role.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; @@ -10,33 +17,68 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Role extends Resource { - private static final long serialVersionUID = 78785177979928L; + + public static RoleCreator creator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { + return new RoleCreator(pathServiceSid, friendlyName, type, permission); + } + + public static RoleDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new RoleDeleter(pathServiceSid, pathSid); + } + + public static RoleFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new RoleFetcher(pathServiceSid, pathSid); + } + + public static RoleReader reader(final String pathServiceSid) { + return new RoleReader(pathServiceSid); + } + + public static RoleUpdater updater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { + return new RoleUpdater(pathServiceSid, pathSid, permission); + } public enum RoleType { CHANNEL("channel"), @@ -48,93 +90,28 @@ private RoleType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a RoleType from a string. - * @param value string value - * @return generated RoleType - */ @JsonCreator public static RoleType forValue(final String value) { return Promoter.enumFromString(value, RoleType.values()); } } - /** - * Create a RoleFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return RoleFetcher capable of executing the fetch - */ - public static RoleFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new RoleFetcher(pathServiceSid, pathSid); - } - - /** - * Create a RoleDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return RoleDeleter capable of executing the delete - */ - public static RoleDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new RoleDeleter(pathServiceSid, pathSid); - } - - /** - * Create a RoleCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param friendlyName The human-readable name of this role. - * @param type What kind of role this is. - * @param permission A permission this role should have. - * @return RoleCreator capable of executing the create - */ - public static RoleCreator creator(final String pathServiceSid, - final String friendlyName, - final Role.RoleType type, - final List permission) { - return new RoleCreator(pathServiceSid, friendlyName, type, permission); - } - - /** - * Create a RoleReader to execute read. - * - * @param pathServiceSid The service_sid - * @return RoleReader capable of executing the read - */ - public static RoleReader reader(final String pathServiceSid) { - return new RoleReader(pathServiceSid); - } - - /** - * Create a RoleUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param permission A permission this role should have. - * @return RoleUpdater capable of executing the update - */ - public static RoleUpdater updater(final String pathServiceSid, - final String pathSid, - final List permission) { - return new RoleUpdater(pathServiceSid, pathSid, permission); - } - /** * Converts a JSON String into a Role object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Role object represented by the provided JSON */ - public static Role fromJson(final String json, final ObjectMapper objectMapper) { + public static Role fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -148,12 +125,15 @@ public static Role fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Role object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Role object represented by the provided JSON */ - public static Role fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Role fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Role.class); @@ -164,125 +144,76 @@ public static Role fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String friendlyName; - private final Role.RoleType type; - private final List permissions; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private Role(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Role.RoleType type, - @JsonProperty("permissions") - final List permissions, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.friendlyName = friendlyName; - this.type = type; - this.permissions = permissions; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this role.. - * - * @return The unique id of the Account responsible for this role. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Service this role belongs to.. - * - * @return The unique id of the Service this role belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The human-readable name of this role.. - * - * @return The human-readable name of this role. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String friendlyName; - /** - * Returns The What kind of role this is.. - * - * @return What kind of role this is. - */ - public final Role.RoleType getType() { - return this.type; - } + @Getter + private final List permissions; - /** - * Returns The A JSON array of the permissions this role has.. - * - * @return A JSON array of the permissions this role has. - */ - public final List getPermissions() { - return this.permissions; - } + @Getter + private final String serviceSid; - /** - * Returns The The date that this resource was created in ISO 8601 format.. - * - * @return The date that this resource was created in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date that this resource was last updated in ISO 8601 format.. - * - * @return The date that this resource was last updated in ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Role.RoleType type; - /** - * Returns The An absolute URL for this role.. - * - * @return An absolute URL for this role. - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private Role( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("permissions") final List permissions, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Role.RoleType type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.permissions = permissions; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.url = url; } @Override @@ -296,43 +227,31 @@ public boolean equals(final Object o) { } Role other = (Role) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(permissions, other.permissions) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(permissions, other.permissions) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - friendlyName, - type, - permissions, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("permissions", permissions) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + permissions, + serviceSid, + sid, + type, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleCreator.java index 1d4789092f..f639f86f8d 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleCreator.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,90 +28,138 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class RoleCreator extends Creator { - private final String pathServiceSid; - private final String friendlyName; - private final Role.RoleType type; - private final List permission; - - /** - * Construct a new RoleCreator. - * - * @param pathServiceSid The service_sid - * @param friendlyName The human-readable name of this role. - * @param type What kind of role this is. - * @param permission A permission this role should have. - */ - public RoleCreator(final String pathServiceSid, - final String friendlyName, - final Role.RoleType type, - final List permission) { + + private String pathServiceSid; + private String friendlyName; + private Role.RoleType type; + private List permission; + + public RoleCreator( + final String pathServiceSid, + final String friendlyName, + final Role.RoleType type, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.friendlyName = friendlyName; this.type = type; this.permission = permission; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role create(final TwilioRestClient client) { + public RoleCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public RoleCreator setType(final Role.RoleType type) { + this.type = type; + return this; + } + + public RoleCreator setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleCreator setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role create(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (permission != null) { - for (String prop : permission) { - request.addPostParam("Permission", prop); + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleDeleter.java index 11a55fd594..22f798f89e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class RoleDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new RoleDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public RoleDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public RoleDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleFetcher.java index ee8e484344..c7113184fe 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RoleFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new RoleFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public RoleFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public RoleFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleReader.java index b5385a4b0a..cde9c4ac34 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; @@ -10,159 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class RoleReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new RoleReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public RoleReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public RoleReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Role ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Role read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "roles", + response.getContent(), + Role.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Role Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Role read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "roles", - response.getContent(), - Role.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleUpdater.java index 5f430983e0..7508243fbb 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/RoleUpdater.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,78 +28,108 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class RoleUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; - private final List permission; - /** - * Construct a new RoleUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param permission A permission this role should have. - */ - public RoleUpdater(final String pathServiceSid, - final String pathSid, - final List permission) { + private String pathServiceSid; + private String pathSid; + private List permission; + + public RoleUpdater( + final String pathServiceSid, + final String pathSid, + final List permission + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; this.permission = permission; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Role - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Role update(final TwilioRestClient client) { + public RoleUpdater setPermission(final List permission) { + this.permission = permission; + return this; + } + + public RoleUpdater setPermission(final String permission) { + return setPermission(Promoter.listOfOne(permission)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Roles/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Roles/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Role update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Role update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Role update(final TwilioRestClient client) { + Response response = makeRequest(client); return Role.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Role content = Role.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (permission != null) { - for (String prop : permission) { - request.addPostParam("Permission", prop); + for (String param : permission) { + Serializer.toString( + request, + "Permission", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/User.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/User.java index 23370b1f40..a49f952064 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/User.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/User.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; @@ -10,99 +17,98 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class User extends Resource { - private static final long serialVersionUID = 15176818292650L; - /** - * Create a UserFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserFetcher capable of executing the fetch - */ - public static UserFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new UserFetcher(pathServiceSid, pathSid); + public static UserCreator creator( + final String pathServiceSid, + final String identity + ) { + return new UserCreator(pathServiceSid, identity); } - /** - * Create a UserDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserDeleter capable of executing the delete - */ - public static UserDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static UserDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new UserDeleter(pathServiceSid, pathSid); } - /** - * Create a UserCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param identity A unique string that identifies the user within this service - * - often a username or email address. - * @return UserCreator capable of executing the create - */ - public static UserCreator creator(final String pathServiceSid, - final String identity) { - return new UserCreator(pathServiceSid, identity); + public static UserFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new UserFetcher(pathServiceSid, pathSid); } - /** - * Create a UserReader to execute read. - * - * @param pathServiceSid The service_sid - * @return UserReader capable of executing the read - */ public static UserReader reader(final String pathServiceSid) { return new UserReader(pathServiceSid); } - /** - * Create a UserUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return UserUpdater capable of executing the update - */ - public static UserUpdater updater(final String pathServiceSid, - final String pathSid) { + public static UserUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new UserUpdater(pathServiceSid, pathSid); } + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + /** * Converts a JSON String into a User object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return User object represented by the provided JSON */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -116,12 +122,15 @@ public static User fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a User object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return User object represented by the provided JSON */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, User.class); @@ -132,200 +141,105 @@ public static User fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String attributes; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final String roleSid; + + @Getter private final String identity; - private final Boolean isOnline; + + @Getter private final Boolean isNotifiable; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final Boolean isOnline; + + @Getter private final Integer joinedChannelsCount; + + @Getter private final Map links; + + @Getter + private final String roleSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private User(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("is_online") - final Boolean isOnline, - @JsonProperty("is_notifiable") - final Boolean isNotifiable, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("joined_channels_count") - final Integer joinedChannelsCount, - @JsonProperty("links") - final Map links, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private User( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identity") final String identity, + @JsonProperty("is_notifiable") final Boolean isNotifiable, + @JsonProperty("is_online") final Boolean isOnline, + @JsonProperty( + "joined_channels_count" + ) final Integer joinedChannelsCount, + @JsonProperty("links") final Map links, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; this.attributes = attributes; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.roleSid = roleSid; this.identity = identity; - this.isOnline = isOnline; this.isNotifiable = isNotifiable; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.isOnline = isOnline; this.joinedChannelsCount = joinedChannelsCount; this.links = links; + this.roleSid = roleSid; + this.serviceSid = serviceSid; + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account responsible for this user.. - * - * @return The unique id of the Account responsible for this user. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique id of the Service this user belongs to.. - * - * @return The unique id of the Service this user belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The An optional string metadata field you can use to store any data - * you wish.. - * - * @return An optional string metadata field you can use to store any data you - * wish. - */ - public final String getAttributes() { - return this.attributes; - } - - /** - * Returns The The human-readable name of this user.. - * - * @return The human-readable name of this user. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique id of the [Role][role] assigned to this user.. - * - * @return The unique id of the [Role][role] assigned to this user. - */ - public final String getRoleSid() { - return this.roleSid; - } - - /** - * Returns The A unique string that identifies the user within this service - - * often a username or email address.. - * - * @return A unique string that identifies the user within this service - often - * a username or email address. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Indicates whether the User is actively connected to the Service - * instance and online.. - * - * @return Indicates whether the User is actively connected to the Service - * instance and online. - */ - public final Boolean getIsOnline() { - return this.isOnline; - } - - /** - * Returns The Indicates whether the User has a potentially valid Push - * Notification registration for the Service instance.. - * - * @return Indicates whether the User has a potentially valid Push Notification - * registration for the Service instance. - */ - public final Boolean getIsNotifiable() { - return this.isNotifiable; - } - - /** - * Returns The The date that this resource was created in ISO 8601 format.. - * - * @return The date that this resource was created in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated in ISO 8601 format.. - * - * @return The date that this resource was last updated in ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The number of Channels this User is a Member of.. - * - * @return The number of Channels this User is a Member of. - */ - public final Integer getJoinedChannelsCount() { - return this.joinedChannelsCount; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The An absolute URL for this user.. - * - * @return An absolute URL for this user. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -337,58 +251,41 @@ public boolean equals(final Object o) { } User other = (User) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(identity, other.identity) && - Objects.equals(isOnline, other.isOnline) && - Objects.equals(isNotifiable, other.isNotifiable) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && - Objects.equals(links, other.links) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identity, other.identity) && + Objects.equals(isNotifiable, other.isNotifiable) && + Objects.equals(isOnline, other.isOnline) && + Objects.equals(joinedChannelsCount, other.joinedChannelsCount) && + Objects.equals(links, other.links) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - attributes, - friendlyName, - roleSid, - identity, - isOnline, - isNotifiable, - dateCreated, - dateUpdated, - joinedChannelsCount, - links, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("attributes", attributes) - .add("friendlyName", friendlyName) - .add("roleSid", roleSid) - .add("identity", identity) - .add("isOnline", isOnline) - .add("isNotifiable", isNotifiable) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("joinedChannelsCount", joinedChannelsCount) - .add("links", links) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + dateCreated, + dateUpdated, + friendlyName, + identity, + isNotifiable, + isOnline, + joinedChannelsCount, + links, + roleSid, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserCreator.java index 4f85553b4e..429036aed0 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,123 +27,159 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserCreator extends Creator { - private final String pathServiceSid; - private final String identity; + + private String pathServiceSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; + private String identity; private String roleSid; private String attributes; private String friendlyName; - /** - * Construct a new UserCreator. - * - * @param pathServiceSid The service_sid - * @param identity A unique string that identifies the user within this service - * - often a username or email address. - */ - public UserCreator(final String pathServiceSid, - final String identity) { + public UserCreator(final String pathServiceSid, final String identity) { this.pathServiceSid = pathServiceSid; this.identity = identity; } - /** - * The unique id of the [Role](https://www.twilio.com/docs/api/chat/rest/roles) - * assigned to this user.. - * - * @param roleSid The unique id of the Role assigned to this user. - * @return this - */ + public UserCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public UserCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An optional string used to contain any metadata or other information for the - * User. The string must contain structurally valid JSON if specified.. - * - * @param attributes An optional string used to contain any metadata or other - * information for the User. - * @return this - */ public UserCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * An optional human readable string representing the user. Often used for - * display purposes.. - * - * @param friendlyName An optional human readable string representing the user. - * @return this - */ public UserCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User create(final TwilioRestClient client) { + public UserCreator setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User create(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserDeleter.java index ca378b33de..45411b0cf2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class UserDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new UserDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public UserDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserFetcher.java index b054b90e9f..eee28f07d4 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new UserFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public UserFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserReader.java index f1e4e042e2..31641f3761 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; @@ -10,159 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new UserReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public UserReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "users", + response.getContent(), + User.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of User Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "users", - response.getContent(), - User.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserUpdater.java index de74bc2746..f9a6bf07e6 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/UserUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,117 +27,146 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; + private User.WebhookEnabledType xTwilioWebhookEnabled; private String roleSid; private String attributes; private String friendlyName; - /** - * Construct a new UserUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public UserUpdater(final String pathServiceSid, - final String pathSid) { + public UserUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * The unique id of the [Role][role] assigned to this user.. - * - * @param roleSid The unique id of the [Role][role] assigned to this user. - * @return this - */ public UserUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * An optional string used to contain any metadata or other information for the - * User. The string must contain structurally valid JSON if specified.. - * - * @param attributes An optional string used to contain any metadata or other - * information for the User. - * @return this - */ public UserUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * An optional human readable string representing the user. Often used for - * display purposes.. - * - * @param friendlyName An optional human readable string representing the user. - * @return this - */ public UserUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User update(final TwilioRestClient client) { + public UserUpdater setXTwilioWebhookEnabled( + final User.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("User update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public User update(final TwilioRestClient client) { + Response response = makeRequest(client); return User.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Invite.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Invite.java index 5f3ffb248f..97df855e93 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Invite.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Invite.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; @@ -11,93 +18,72 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Invite extends Resource { - private static final long serialVersionUID = 189960368613614L; - /** - * Create a InviteFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return InviteFetcher capable of executing the fetch - */ - public static InviteFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); + public static InviteCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { + return new InviteCreator(pathServiceSid, pathChannelSid, identity); } - /** - * Create a InviteCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * @return InviteCreator capable of executing the create - */ - public static InviteCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { - return new InviteCreator(pathServiceSid, pathChannelSid, identity); + public static InviteDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a InviteReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return InviteReader capable of executing the read - */ - public static InviteReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new InviteReader(pathServiceSid, pathChannelSid); + public static InviteFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new InviteFetcher(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a InviteDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return InviteDeleter capable of executing the delete - */ - public static InviteDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new InviteDeleter(pathServiceSid, pathChannelSid, pathSid); + public static InviteReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new InviteReader(pathServiceSid, pathChannelSid); } /** * Converts a JSON String into a Invite object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Invite object represented by the provided JSON */ - public static Invite fromJson(final String json, final ObjectMapper objectMapper) { + public static Invite fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -111,12 +97,15 @@ public static Invite fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Invite object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Invite object represented by the provided JSON */ - public static Invite fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Invite fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Invite.class); @@ -127,140 +116,83 @@ public static Invite fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String channelSid; - private final String serviceSid; + + @Getter + private final String createdBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final String roleSid; - private final String createdBy; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter private final URI url; @JsonCreator - private Invite(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("created_by") - final String createdBy, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Invite( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.channelSid = channelSid; - this.serviceSid = serviceSid; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.roleSid = roleSid; - this.createdBy = createdBy; + this.serviceSid = serviceSid; + this.sid = sid; this.url = url; } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique id of the Account responsible for this member.. - * - * @return The unique id of the Account responsible for this member. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique id of the Channel for this member.. - * - * @return The unique id of the Channel for this member. - */ - public final String getChannelSid() { - return this.channelSid; - } - - /** - * Returns The The unique id of the Service this member belongs to.. - * - * @return The unique id of the Service this member belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The A unique string identifier for this User in this Service.. - * - * @return A unique string identifier for this User in this Service. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The Role assigned to this member.. - * - * @return The Role assigned to this member. - */ - public final String getRoleSid() { - return this.roleSid; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - /** - * Returns The An absolute URL for this member.. - * - * @return An absolute URL for this member. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -272,46 +204,33 @@ public boolean equals(final Object o) { } Invite other = (Invite) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(createdBy, other.createdBy) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - channelSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - roleSid, - createdBy, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("channelSid", channelSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("roleSid", roleSid) - .add("createdBy", createdBy) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + channelSid, + createdBy, + dateCreated, + dateUpdated, + identity, + roleSid, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteCreator.java index 5fe5229712..c276c4c697 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,91 +27,120 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class InviteCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String identity; + + private String pathServiceSid; + private String pathChannelSid; + private String identity; private String roleSid; - /** - * Construct a new InviteCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - */ - public InviteCreator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { + public InviteCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - /** - * The [Role](https://www.twilio.com/docs/api/chat/rest/roles) assigned to this - * member.. - * - * @param roleSid The Role assigned to this member. - * @return this - */ + public InviteCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public InviteCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Invite - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Invite create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Invite create(final TwilioRestClient client) { + Response response = makeRequest(client); return Invite.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Invite content = Invite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteDeleter.java index 1e3d01570c..24cc94d68d 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class InviteDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new InviteDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public InviteDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public InviteDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteFetcher.java index 7a79f75fbe..d8fff5ab33 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class InviteFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new InviteFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public InviteFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public InviteFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Invite - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Invite fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Invite fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Invite fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Invite fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Invite.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Invite content = Invite.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteReader.java index c37d6ceb85..d0ba48d64c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/InviteReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; @@ -10,202 +17,224 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class InviteReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private List identity; + private Long pageSize; - /** - * Construct a new InviteReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public InviteReader(final String pathServiceSid, - final String pathChannelSid) { + public InviteReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/services). See the - * [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) - * docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public InviteReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/services). See the - * [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) - * docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * @return this - */ public InviteReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public InviteReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Invites"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Invites", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Invite ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Invite read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "invites", + response.getContent(), + Invite.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Invite Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Invite read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "invites", - response.getContent(), - Invite.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Member.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Member.java index ec4d855798..cfc7c9fa16 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Member.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Member.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; @@ -10,110 +17,104 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; +import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Member extends Resource { - private static final long serialVersionUID = 102574959310114L; - /** - * Create a MemberFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberFetcher capable of executing the fetch - */ - public static MemberFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); + public static MemberCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { + return new MemberCreator(pathServiceSid, pathChannelSid, identity); } - /** - * Create a MemberCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * See the access tokens docs for more details. (📇 PII MTL: 120 - * days) - * @return MemberCreator capable of executing the create - */ - public static MemberCreator creator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { - return new MemberCreator(pathServiceSid, pathChannelSid, identity); + public static MemberDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a MemberReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MemberReader capable of executing the read - */ - public static MemberReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new MemberReader(pathServiceSid, pathChannelSid); + public static MemberFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MemberFetcher(pathServiceSid, pathChannelSid, pathSid); } - /** - * Create a MemberDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberDeleter capable of executing the delete - */ - public static MemberDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MemberDeleter(pathServiceSid, pathChannelSid, pathSid); + public static MemberReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MemberReader(pathServiceSid, pathChannelSid); } - /** - * Create a MemberUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MemberUpdater capable of executing the update - */ - public static MemberUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public static MemberUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { return new MemberUpdater(pathServiceSid, pathChannelSid, pathSid); } + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); + + private final String value; + + private WebhookEnabledType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); + } + } + /** * Converts a JSON String into a Member object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final String json, final ObjectMapper objectMapper) { + public static Member fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -127,12 +128,15 @@ public static Member fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Member object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Member object represented by the provided JSON */ - public static Member fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Member fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Member.class); @@ -143,155 +147,98 @@ public static Member fromJson(final InputStream json, final ObjectMapper objectM } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String channelSid; - private final String serviceSid; - private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String roleSid; - private final Integer lastConsumedMessageIndex; - private final DateTime lastConsumptionTimestamp; - private final URI url; - @JsonCreator - private Member(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("role_sid") - final String roleSid, - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - @JsonProperty("last_consumption_timestamp") - final String lastConsumptionTimestamp, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.channelSid = channelSid; - this.serviceSid = serviceSid; - this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.roleSid = roleSid; - this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.lastConsumptionTimestamp = DateConverter.iso8601DateTimeFromString(lastConsumptionTimestamp); - this.url = url; - } + @Getter + private final String attributes; - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String channelSid; - /** - * Returns The The unique id of the Account responsible for this member.. - * - * @return The unique id of the Account responsible for this member. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique id of the Channel for this member.. - * - * @return The unique id of the Channel for this member. - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The unique id of the Service this member belongs to.. - * - * @return The unique id of the Service this member belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String identity; - /** - * Returns The A unique string identifier for this User in this Service.. - * - * @return A unique string identifier for this User in this Service. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final Integer lastConsumedMessageIndex; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime lastConsumptionTimestamp; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String roleSid; - /** - * Returns The The Role assigned to this member.. - * - * @return The Role assigned to this member. - */ - public final String getRoleSid() { - return this.roleSid; - } + @Getter + private final String serviceSid; - /** - * Returns The An Integer representing index of the last Message this Member has - * read within this Channel. - * - * @return An Integer representing index of the last Message this Member has - * read within this Channel - */ - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } + @Getter + private final String sid; - /** - * Returns The An ISO8601 based timestamp string representing the datetime of - * the last Message read event for this Member within this Channel. - * - * @return An ISO8601 based timestamp string representing the datetime of the - * last Message read event for this Member within this Channel - */ - public final DateTime getLastConsumptionTimestamp() { - return this.lastConsumptionTimestamp; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this member.. - * - * @return An absolute URL for this member. - */ - public final URI getUrl() { - return this.url; + @JsonCreator + private Member( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("identity") final String identity, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty("last_consumption_timestamp") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime lastConsumptionTimestamp, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.identity = identity; + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + this.lastConsumptionTimestamp = lastConsumptionTimestamp; + this.roleSid = roleSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -305,49 +252,43 @@ public boolean equals(final Object o) { } Member other = (Member) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(roleSid, other.roleSid) && - Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && - Objects.equals(lastConsumptionTimestamp, other.lastConsumptionTimestamp) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(identity, other.identity) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals( + lastConsumptionTimestamp, + other.lastConsumptionTimestamp + ) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - channelSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - roleSid, - lastConsumedMessageIndex, - lastConsumptionTimestamp, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("channelSid", channelSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("roleSid", roleSid) - .add("lastConsumedMessageIndex", lastConsumedMessageIndex) - .add("lastConsumptionTimestamp", lastConsumptionTimestamp) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + channelSid, + dateCreated, + dateUpdated, + identity, + lastConsumedMessageIndex, + lastConsumptionTimestamp, + roleSid, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberCreator.java index d1cbce2253..0d4b537cf3 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Creator; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,185 +27,220 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MemberCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final String identity; + + private String pathServiceSid; + private String pathChannelSid; + private Member.WebhookEnabledType xTwilioWebhookEnabled; + private String identity; private String roleSid; private Integer lastConsumedMessageIndex; - private DateTime lastConsumptionTimestamp; - private DateTime dateCreated; - private DateTime dateUpdated; - - /** - * Construct a new MemberCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param identity A unique string identifier for this User in this Service. - * See the access tokens docs for more details. (📇 PII MTL: 120 - * days) - */ - public MemberCreator(final String pathServiceSid, - final String pathChannelSid, - final String identity) { + private ZonedDateTime lastConsumptionTimestamp; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + + public MemberCreator( + final String pathServiceSid, + final String pathChannelSid, + final String identity + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.identity = identity; } - /** - * The role to be assigned to this member. Defaults to the roles specified on - * the [Service](https://www.twilio.com/docs/chat/api/services).. - * - * @param roleSid The role to be assigned to this member. Defaults to the roles - * specified on the Service. - * @return this - */ + public MemberCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + public MemberCreator setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Field used to specify the last consumed Message index for the Channel for - * this Member. Should only be used when recreating a Member from a - * backup/separate source.. - * - * @param lastConsumedMessageIndex Field used to specify the last consumed - * Message index for the Channel for this - * Member. Should only be used when recreating - * a Member from a backup/separate source. - * @return this - */ - public MemberCreator setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex) { + public MemberCreator setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - /** - * ISO8601 time indicating the last datetime the Member consumed a Message in - * the Channel. Should only be used when recreating a Member from a - * backup/separate source. - * - * @param lastConsumptionTimestamp ISO8601 time indicating the last datetime - * the Member consumed a Message in the Channel. - * Should only be used when recreating a Member - * from a backup/separate source - * @return this - */ - public MemberCreator setLastConsumptionTimestamp(final DateTime lastConsumptionTimestamp) { + public MemberCreator setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } - /** - * The ISO8601 time specifying the datetime the Members should be set as being - * created. Will be set to the current time by the Chat service if not - * specified. Note that this should only be used in cases where a Member is - * being recreated from a backup/separate source. - * - * @param dateCreated The ISO8601 time specifying the datetime the Members - * should be set as being created. Will be set to the - * current time by the Chat service if not specified. Note - * that this should only be used in cases where a Member is - * being recreated from a backup/separate source - * @return this - */ - public MemberCreator setDateCreated(final DateTime dateCreated) { + public MemberCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The ISO8601 time specifying the datetime the Member should be set as having - * been last updated. Will be set to the `null` by the Chat service if not - * specified. Note that this should only be used in cases where a Member is - * being recreated from a backup/separate source and where a Member was - * previously updated.. - * - * @param dateUpdated The ISO8601 time specifying the datetime the Member - * should be set as having been last updated. Will be set to - * the null by the Chat service if not specified. Note that - * this should only be used in cases where a Member is being - * recreated from a backup/separate source and where a - * Member was previously updated. - * @return this - */ - public MemberCreator setDateUpdated(final DateTime dateUpdated) { + public MemberCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member create(final TwilioRestClient client) { + public MemberCreator setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public MemberCreator setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member create(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); + Serializer.toString( + request, + "LastConsumedMessageIndex", + lastConsumedMessageIndex, + ParameterType.URLENCODED + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toString()); + Serializer.toString( + request, + "LastConsumptionTimestamp", + lastConsumptionTimestamp, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberDeleter.java index 9930c257ab..664aaeae91 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +26,113 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MemberDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MemberDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + private Member.WebhookEnabledType xTwilioWebhookEnabled; + + public MemberDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public MemberDeleter setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberFetcher.java index 4570906613..d1f7e81219 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MemberFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MemberFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MemberFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberReader.java index 223c28b430..448211778d 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; @@ -10,206 +17,224 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class MemberReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private List identity; + private Long pageSize; - /** - * Construct a new MemberReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MemberReader(final String pathServiceSid, - final String pathChannelSid) { + public MemberReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/services). See the - * [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) - * docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * See the access tokens docs for more details. (📇 PII MTL: 120 - * days) - * @return this - */ public MemberReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * A unique string identifier for this - * [User](https://www.twilio.com/docs/api/chat/rest/users) in this - * [Service](https://www.twilio.com/docs/api/chat/rest/services). See the - * [access tokens](https://www.twilio.com/docs/api/chat/guides/create-tokens) - * docs for more details.. - * - * @param identity A unique string identifier for this User in this Service. - * See the access tokens docs for more details. (📇 PII MTL: 120 - * days) - * @return this - */ public MemberReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MemberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Member ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Member read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "members", + response.getContent(), + Member.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Member Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Member read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "members", - response.getContent(), - Member.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberUpdater.java index d0d72ea715..8323dc99de 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MemberUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.DateConverter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,168 +27,208 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MemberUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + private Member.WebhookEnabledType xTwilioWebhookEnabled; private String roleSid; private Integer lastConsumedMessageIndex; - private DateTime lastConsumptionTimestamp; - private DateTime dateCreated; - private DateTime dateUpdated; - - /** - * Construct a new MemberUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MemberUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private ZonedDateTime lastConsumptionTimestamp; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; + private String attributes; + + public MemberUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The role to be assigned to this member. Defaults to the roles specified on - * the [Service](https://www.twilio.com/docs/chat/api/services).. - * - * @param roleSid The role to be assigned to this member. - * @return this - */ public MemberUpdater setRoleSid(final String roleSid) { this.roleSid = roleSid; return this; } - /** - * Field used to specify the last consumed Message index for the Channel for - * this Member. Should only be used when recreating a Member from a - * backup/separate source.. - * - * @param lastConsumedMessageIndex Field used to specify the last consumed - * Message index for the Channel for this - * Member. - * @return this - */ - public MemberUpdater setLastConsumedMessageIndex(final Integer lastConsumedMessageIndex) { + public MemberUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { this.lastConsumedMessageIndex = lastConsumedMessageIndex; return this; } - /** - * ISO8601 time indicating the last datetime the Member consumed a Message in - * the Channel. Should only be used when recreating a Member from a - * backup/separate source. - * - * @param lastConsumptionTimestamp ISO8601 time indicating the last datetime - * the Member consumed a Message in the Channel. - * @return this - */ - public MemberUpdater setLastConsumptionTimestamp(final DateTime lastConsumptionTimestamp) { + public MemberUpdater setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { this.lastConsumptionTimestamp = lastConsumptionTimestamp; return this; } - /** - * The ISO8601 time specifying the datetime the Members should be set as being - * created. Will be set to the current time by the Chat service if not - * specified. Note that this should only be used in cases where a Member is - * being recreated from a backup/separate source. - * - * @param dateCreated The ISO8601 time specifying the datetime the Members - * should be set as being created. - * @return this - */ - public MemberUpdater setDateCreated(final DateTime dateCreated) { + public MemberUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The ISO8601 time specifying the datetime the Member should be set as having - * been last updated. Will be set to the `null` by the Chat service if not - * specified. Note that this should only be used in cases where a Member is - * being recreated from a backup/separate source and where a Member was - * previously updated.. - * - * @param dateUpdated The ISO8601 time specifying the datetime the Member - * should be set as having been last updated. - * @return this - */ - public MemberUpdater setDateUpdated(final DateTime dateUpdated) { + public MemberUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Member - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Member update(final TwilioRestClient client) { + public MemberUpdater setAttributes(final String attributes) { + this.attributes = attributes; + return this; + } + + public MemberUpdater setXTwilioWebhookEnabled( + final Member.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Members/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Members/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Member update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Member update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Member update(final TwilioRestClient client) { + Response response = makeRequest(client); return Member.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Member content = Member.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (roleSid != null) { - request.addPostParam("RoleSid", roleSid); + Serializer.toString( + request, + "RoleSid", + roleSid, + ParameterType.URLENCODED + ); } if (lastConsumedMessageIndex != null) { - request.addPostParam("LastConsumedMessageIndex", lastConsumedMessageIndex.toString()); + Serializer.toString( + request, + "LastConsumedMessageIndex", + lastConsumedMessageIndex, + ParameterType.URLENCODED + ); } if (lastConsumptionTimestamp != null) { - request.addPostParam("LastConsumptionTimestamp", lastConsumptionTimestamp.toString()); + Serializer.toString( + request, + "LastConsumptionTimestamp", + lastConsumptionTimestamp, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Message.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Message.java index 617dafe743..b6c63a7cd3 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Message.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Message.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; @@ -10,133 +17,124 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Message extends Resource { - private static final long serialVersionUID = 240696203452729L; - public enum OrderType { - ASC("asc"), - DESC("desc"); + public static MessageCreator creator( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MessageCreator(pathServiceSid, pathChannelSid); + } + + public static MessageDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); + } + + public static MessageFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); + } + + public static MessageReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new MessageReader(pathServiceSid, pathChannelSid); + } + + public static MessageUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); + } + + public enum WebhookEnabledType { + TRUE("true"), + FALSE("false"); private final String value; - private OrderType(final String value) { + private WebhookEnabledType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a OrderType from a string. - * @param value string value - * @return generated OrderType - */ @JsonCreator - public static OrderType forValue(final String value) { - return Promoter.enumFromString(value, OrderType.values()); + public static WebhookEnabledType forValue(final String value) { + return Promoter.enumFromString(value, WebhookEnabledType.values()); } } - /** - * Create a MessageFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageFetcher capable of executing the fetch - */ - public static MessageFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageFetcher(pathServiceSid, pathChannelSid, pathSid); - } + public enum OrderType { + ASC("asc"), + DESC("desc"); - /** - * Create a MessageCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MessageCreator capable of executing the create - */ - public static MessageCreator creator(final String pathServiceSid, - final String pathChannelSid) { - return new MessageCreator(pathServiceSid, pathChannelSid); - } + private final String value; - /** - * Create a MessageReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return MessageReader capable of executing the read - */ - public static MessageReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new MessageReader(pathServiceSid, pathChannelSid); - } + private OrderType(final String value) { + this.value = value; + } - /** - * Create a MessageDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageDeleter capable of executing the delete - */ - public static MessageDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageDeleter(pathServiceSid, pathChannelSid, pathSid); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a MessageUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return MessageUpdater capable of executing the update - */ - public static MessageUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new MessageUpdater(pathServiceSid, pathChannelSid, pathSid); + @JsonCreator + public static OrderType forValue(final String value) { + return Promoter.enumFromString(value, OrderType.values()); + } } /** * Converts a JSON String into a Message object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final String json, final ObjectMapper objectMapper) { + public static Message fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -150,12 +148,15 @@ public static Message fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Message object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Message object represented by the provided JSON */ - public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Message fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Message.class); @@ -166,220 +167,111 @@ public static Message fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String attributes; - private final String serviceSid; - private final String to; - private final String channelSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String lastUpdatedBy; - private final Boolean wasEdited; - private final String from; - private final String body; - private final Integer index; - private final String type; - private final Map media; - private final URI url; - - @JsonCreator - private Message(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("to") - final String to, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("last_updated_by") - final String lastUpdatedBy, - @JsonProperty("was_edited") - final Boolean wasEdited, - @JsonProperty("from") - final String from, - @JsonProperty("body") - final String body, - @JsonProperty("index") - final Integer index, - @JsonProperty("type") - final String type, - @JsonProperty("media") - final Map media, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.attributes = attributes; - this.serviceSid = serviceSid; - this.to = to; - this.channelSid = channelSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.lastUpdatedBy = lastUpdatedBy; - this.wasEdited = wasEdited; - this.from = from; - this.body = body; - this.index = index; - this.type = type; - this.media = media; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this message.. - * - * @return The unique id of the Account responsible for this message. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String attributes; - /** - * Returns The A string metadata field you can use to store any data you wish.. - * - * @return A string metadata field you can use to store any data you wish. - */ - public final String getAttributes() { - return this.attributes; - } + @Getter + private final String body; - /** - * Returns The The unique id of the Service this message belongs to.. - * - * @return The unique id of the Service this message belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String channelSid; - /** - * Returns The The unique id of the Channel this message was sent to.. - * - * @return The unique id of the Channel this message was sent to. - */ - public final String getTo() { - return this.to; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The channel_sid. - * - * @return The channel_sid - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String from; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer index; - /** - * Returns The Field to specify the Identity of the User that last updated the - * Message. - * - * @return Field to specify the Identity of the User that last updated the - * Message - */ - public final String getLastUpdatedBy() { - return this.lastUpdatedBy; - } + @Getter + private final String lastUpdatedBy; - /** - * Returns The true if the message has been updated since it was created.. - * - * @return true if the message has been updated since it was created. - */ - public final Boolean getWasEdited() { - return this.wasEdited; - } + @Getter + private final Object media; - /** - * Returns The The identity of the message's author.. - * - * @return The identity of the message's author. - */ - public final String getFrom() { - return this.from; - } + @Getter + private final String serviceSid; - /** - * Returns The The contents of the message.. - * - * @return The contents of the message. - */ - public final String getBody() { - return this.body; - } + @Getter + private final String sid; - /** - * Returns The The index of the message within the Channel. - * - * @return The index of the message within the Channel - */ - public final Integer getIndex() { - return this.index; - } + @Getter + private final String to; - /** - * Returns The Message type.. - * - * @return Message type. - */ - public final String getType() { - return this.type; - } + @Getter + private final String type; - /** - * Returns The If a Media resource instance is attached to the Message, this - * will contain the Media object for the attached Media.. - * - * @return If a Media resource instance is attached to the Message, this will - * contain the Media object for the attached Media. - */ - public final Map getMedia() { - return this.media; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this message.. - * - * @return An absolute URL for this message. - */ - public final URI getUrl() { - return this.url; + @Getter + private final Boolean wasEdited; + + @JsonCreator + private Message( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("body") final String body, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("from") final String from, + @JsonProperty("index") final Integer index, + @JsonProperty("last_updated_by") final String lastUpdatedBy, + @JsonProperty("media") final Object media, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("to") final String to, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url, + @JsonProperty("was_edited") final Boolean wasEdited + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.body = body; + this.channelSid = channelSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.from = from; + this.index = index; + this.lastUpdatedBy = lastUpdatedBy; + this.media = media; + this.serviceSid = serviceSid; + this.sid = sid; + this.to = to; + this.type = type; + this.url = url; + this.wasEdited = wasEdited; } @Override @@ -393,64 +285,45 @@ public boolean equals(final Object o) { } Message other = (Message) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(to, other.to) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(lastUpdatedBy, other.lastUpdatedBy) && - Objects.equals(wasEdited, other.wasEdited) && - Objects.equals(from, other.from) && - Objects.equals(body, other.body) && - Objects.equals(index, other.index) && - Objects.equals(type, other.type) && - Objects.equals(media, other.media) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(body, other.body) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(from, other.from) && + Objects.equals(index, other.index) && + Objects.equals(lastUpdatedBy, other.lastUpdatedBy) && + Objects.equals(media, other.media) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(to, other.to) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) && + Objects.equals(wasEdited, other.wasEdited) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - attributes, - serviceSid, - to, - channelSid, - dateCreated, - dateUpdated, - lastUpdatedBy, - wasEdited, - from, - body, - index, - type, - media, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("attributes", attributes) - .add("serviceSid", serviceSid) - .add("to", to) - .add("channelSid", channelSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("lastUpdatedBy", lastUpdatedBy) - .add("wasEdited", wasEdited) - .add("from", from) - .add("body", body) - .add("index", index) - .add("type", type) - .add("media", media) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + attributes, + body, + channelSid, + dateCreated, + dateUpdated, + from, + index, + lastUpdatedBy, + media, + serviceSid, + sid, + to, + type, + url, + wasEdited + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageCreator.java index ee5e71f2fd..0e26346d68 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Creator; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,198 +27,215 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MessageCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; private String from; private String attributes; - private DateTime dateCreated; - private DateTime dateUpdated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; private String lastUpdatedBy; private String body; private String mediaSid; - /** - * Construct a new MessageCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MessageCreator(final String pathServiceSid, - final String pathChannelSid) { + public MessageCreator( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * The [identity](https://www.twilio.com/docs/api/chat/guides/identity) of the - * message's author. Defaults to `system`.. - * - * @param from The identity of the message's author. Defaults to system if not - * specified. - * @return this - */ public MessageCreator setFrom(final String from) { this.from = from; return this; } - /** - * An string metadata field you can use to store any data you wish. The string - * value must contain structurally valid JSON if specified. **Note** that this - * will always be null for resources returned via LIST GET operations, but will - * be present for single GET operations.. - * - * @param attributes The attributes metadata field you can use to store any - * data you wish. - * @return this - */ public MessageCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The ISO8601 time specifying the datetime the Message should be set as being - * created. Will be set to the current time by the Chat service if not - * specified. Note that this should only be used in cases where a Chat's - * history is being recreated from a backup/separate source.. - * - * @param dateCreated The ISO8601 time specifying the datetime the Message - * should be set as being created. - * @return this - */ - public MessageCreator setDateCreated(final DateTime dateCreated) { + public MessageCreator setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The ISO8601 time specifying the datetime the Message should be set as having - * been last updated. Will be set to the `null` by the Chat service if not - * specified. Note that this should only be used in cases where a Chat's - * history is being recreated from a backup/separate source and where a Message - * was previously updated.. - * - * @param dateUpdated The ISO8601 time specifying the datetime the Message - * should be set as having been last updated. - * @return this - */ - public MessageCreator setDateUpdated(final DateTime dateUpdated) { + public MessageCreator setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Specify the Identity of the User that last updated the Message (if relevant). - * - * @param lastUpdatedBy Specify the Identity of the User that last updated the - * Message - * @return this - */ public MessageCreator setLastUpdatedBy(final String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; return this; } - /** - * A string message to send to this channel. You can also send structured data - * by serializing it into a string. May be empty string or `null`, will be set - * as empty string as a result in this cases.. - * - * @param body The message body string. - * @return this - */ public MessageCreator setBody(final String body) { this.body = body; return this; } - /** - * The [Media](https://www.twilio.com/docs/api/chat/rest/media) Sid to be - * attached to this Message.. - * - * @param mediaSid The Media Sid to be attached to this Message. - * @return this - */ public MessageCreator setMediaSid(final String mediaSid) { this.mediaSid = mediaSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message create(final TwilioRestClient client) { + public MessageCreator setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message create(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (from != null) { - request.addPostParam("From", from); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); } if (lastUpdatedBy != null) { - request.addPostParam("LastUpdatedBy", lastUpdatedBy); + Serializer.toString( + request, + "LastUpdatedBy", + lastUpdatedBy, + ParameterType.URLENCODED + ); } if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (mediaSid != null) { - request.addPostParam("MediaSid", mediaSid); + Serializer.toString( + request, + "MediaSid", + mediaSid, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageDeleter.java index f6155208df..0bb552183c 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +26,113 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class MessageDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MessageDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; + + public MessageDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public MessageDeleter setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageFetcher.java index 32d5228905..0343de9577 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new MessageFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public MessageFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageReader.java index a34d42acc6..121e8ce759 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; @@ -10,181 +17,216 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class MessageReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; + + private String pathServiceSid; + private String pathChannelSid; private Message.OrderType order; + private Long pageSize; - /** - * Construct a new MessageReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public MessageReader(final String pathServiceSid, - final String pathChannelSid) { + public MessageReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * Specifies sorting order for messages list, possible values are: `asc` or - * `desc`. If no value is specified, then `asc` is used as the default.. - * - * @param order Specifies sorting order for messages list, possible values are: - * `asc` or `desc`. - * @return this - */ public MessageReader setOrder(final Message.OrderType order) { this.order = order; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MessageReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Message ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Message read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "messages", + response.getContent(), + Message.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Message Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Message read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "messages", - response.getContent(), - Message.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); + Serializer.toString(request, "Order", order, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageUpdater.java index 45948abf13..e311e73e59 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/MessageUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.DateConverter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,162 +27,204 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class MessageUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + private Message.WebhookEnabledType xTwilioWebhookEnabled; private String body; private String attributes; - private DateTime dateCreated; - private DateTime dateUpdated; + private ZonedDateTime dateCreated; + private ZonedDateTime dateUpdated; private String lastUpdatedBy; + private String from; - /** - * Construct a new MessageUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public MessageUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public MessageUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The message body string. You can also send structured data by serializing it - * into a string. May be updated to empty string or `null`, will be set as empty - * string as a result in this cases.. - * - * @param body The message body string. - * @return this - */ public MessageUpdater setBody(final String body) { this.body = body; return this; } - /** - * A string metadata field you can use to store any data you wish. The string - * value must contain structurally valid JSON if specified. **Note** that this - * will always be null for resources returned via LIST GET operations, but will - * be present for single GET operations.. - * - * @param attributes The attributes metadata field you can use to store any - * data you wish. - * @return this - */ public MessageUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The ISO8601 time specifying the datetime the Message should be set as being - * created.. - * - * @param dateCreated The ISO8601 time specifying the datetime the Message - * should be set as being created. - * @return this - */ - public MessageUpdater setDateCreated(final DateTime dateCreated) { + public MessageUpdater setDateCreated(final ZonedDateTime dateCreated) { this.dateCreated = dateCreated; return this; } - /** - * The ISO8601 time specifying the datetime the Message should be set as having - * been last updated.. - * - * @param dateUpdated The ISO8601 time specifying the datetime the Message - * should be set as having been last updated. - * @return this - */ - public MessageUpdater setDateUpdated(final DateTime dateUpdated) { + public MessageUpdater setDateUpdated(final ZonedDateTime dateUpdated) { this.dateUpdated = dateUpdated; return this; } - /** - * Specify the Identity of the User that last updated the Message (if relevant). - * - * @param lastUpdatedBy Specify the Identity of the User that last updated the - * Message - * @return this - */ public MessageUpdater setLastUpdatedBy(final String lastUpdatedBy) { this.lastUpdatedBy = lastUpdatedBy; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Message - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Message update(final TwilioRestClient client) { + public MessageUpdater setFrom(final String from) { + this.from = from; + return this; + } + + public MessageUpdater setXTwilioWebhookEnabled( + final Message.WebhookEnabledType xTwilioWebhookEnabled + ) { + this.xTwilioWebhookEnabled = xTwilioWebhookEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Messages/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Messages/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Message update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Message update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Message update(final TwilioRestClient client) { + Response response = makeRequest(client); return Message.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Message content = Message.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (dateCreated != null) { - request.addPostParam("DateCreated", dateCreated.toString()); + Serializer.toString( + request, + "DateCreated", + dateCreated, + ParameterType.URLENCODED + ); } if (dateUpdated != null) { - request.addPostParam("DateUpdated", dateUpdated.toString()); + Serializer.toString( + request, + "DateUpdated", + dateUpdated, + ParameterType.URLENCODED + ); } if (lastUpdatedBy != null) { - request.addPostParam("LastUpdatedBy", lastUpdatedBy); + Serializer.toString( + request, + "LastUpdatedBy", + lastUpdatedBy, + ParameterType.URLENCODED + ); + } + + if (from != null) { + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioWebhookEnabled != null) { + Serializer.toString( + request, + "X-Twilio-Webhook-Enabled", + xTwilioWebhookEnabled, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Webhook.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Webhook.java index 40fc8d2b6b..71ffb7bf42 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Webhook.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/Webhook.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; @@ -10,33 +17,71 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Webhook extends Resource { - private static final long serialVersionUID = 142993163058456L; + + public static WebhookCreator creator( + final String pathServiceSid, + final String pathChannelSid, + final Webhook.Type type + ) { + return new WebhookCreator(pathServiceSid, pathChannelSid, type); + } + + public static WebhookDeleter deleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new WebhookDeleter(pathServiceSid, pathChannelSid, pathSid); + } + + public static WebhookFetcher fetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new WebhookFetcher(pathServiceSid, pathChannelSid, pathSid); + } + + public static WebhookReader reader( + final String pathServiceSid, + final String pathChannelSid + ) { + return new WebhookReader(pathServiceSid, pathChannelSid); + } + + public static WebhookUpdater updater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { + return new WebhookUpdater(pathServiceSid, pathChannelSid, pathSid); + } public enum Type { WEBHOOK("webhook"), @@ -49,15 +94,11 @@ private Type(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Type from a string. - * @param value string value - * @return generated Type - */ @JsonCreator public static Type forValue(final String value) { return Promoter.enumFromString(value, Type.values()); @@ -74,97 +115,28 @@ private Method(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Method from a string. - * @param value string value - * @return generated Method - */ @JsonCreator public static Method forValue(final String value) { return Promoter.enumFromString(value, Method.values()); } } - /** - * Create a WebhookReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @return WebhookReader capable of executing the read - */ - public static WebhookReader reader(final String pathServiceSid, - final String pathChannelSid) { - return new WebhookReader(pathServiceSid, pathChannelSid); - } - - /** - * Create a WebhookFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return WebhookFetcher capable of executing the fetch - */ - public static WebhookFetcher fetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new WebhookFetcher(pathServiceSid, pathChannelSid, pathSid); - } - - /** - * Create a WebhookCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param type The type - * @return WebhookCreator capable of executing the create - */ - public static WebhookCreator creator(final String pathServiceSid, - final String pathChannelSid, - final Webhook.Type type) { - return new WebhookCreator(pathServiceSid, pathChannelSid, type); - } - - /** - * Create a WebhookUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return WebhookUpdater capable of executing the update - */ - public static WebhookUpdater updater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new WebhookUpdater(pathServiceSid, pathChannelSid, pathSid); - } - - /** - * Create a WebhookDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - * @return WebhookDeleter capable of executing the delete - */ - public static WebhookDeleter deleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { - return new WebhookDeleter(pathServiceSid, pathChannelSid, pathSid); - } - /** * Converts a JSON String into a Webhook object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Webhook object represented by the provided JSON */ - public static Webhook fromJson(final String json, final ObjectMapper objectMapper) { + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -178,12 +150,15 @@ public static Webhook fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Webhook object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Webhook object represented by the provided JSON */ - public static Webhook fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Webhook.class); @@ -194,125 +169,76 @@ public static Webhook fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String channelSid; - private final String type; - private final URI url; - private final Map configuration; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private Webhook(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("type") - final String type, - @JsonProperty("url") - final URI url, - @JsonProperty("configuration") - final Map configuration, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.channelSid = channelSid; - this.type = type; - this.url = url; - this.configuration = configuration; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String channelSid; - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final Object configuration; - /** - * Returns The The channel_sid. - * - * @return The channel_sid - */ - public final String getChannelSid() { - return this.channelSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The type. - * - * @return The type - */ - public final String getType() { - return this.type; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String serviceSid; - /** - * Returns The The configuration. - * - * @return The configuration - */ - public final Map getConfiguration() { - return this.configuration; - } + @Getter + private final String sid; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String type; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; + @Getter + private final URI url; + + @JsonCreator + private Webhook( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty("configuration") final Object configuration, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelSid = channelSid; + this.configuration = configuration; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.serviceSid = serviceSid; + this.sid = sid; + this.type = type; + this.url = url; } @Override @@ -326,43 +252,31 @@ public boolean equals(final Object o) { } Webhook other = (Webhook) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(type, other.type) && - Objects.equals(url, other.url) && - Objects.equals(configuration, other.configuration) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - channelSid, - type, - url, - configuration, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("channelSid", channelSid) - .add("type", type) - .add("url", url) - .add("configuration", configuration) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); + return Objects.hash( + accountSid, + channelSid, + configuration, + dateCreated, + dateUpdated, + serviceSid, + sid, + type, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookCreator.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookCreator.java index 40c3f038b3..f2e8b0ca5d 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookCreator.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,13 +28,15 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class WebhookCreator extends Creator { - private final String pathServiceSid; - private final String pathChannelSid; - private final Webhook.Type type; + + private String pathServiceSid; + private String pathChannelSid; + private Webhook.Type type; private String configurationUrl; private Webhook.Method configurationMethod; private List configurationFilters; @@ -31,182 +44,211 @@ public class WebhookCreator extends Creator { private String configurationFlowSid; private Integer configurationRetryCount; - /** - * Construct a new WebhookCreator. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param type The type - */ - public WebhookCreator(final String pathServiceSid, - final String pathChannelSid, - final Webhook.Type type) { + public WebhookCreator( + final String pathServiceSid, + final String pathChannelSid, + final Webhook.Type type + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.type = type; } - /** - * The configuration.url. - * - * @param configurationUrl The configuration.url - * @return this - */ + public WebhookCreator setType(final Webhook.Type type) { + this.type = type; + return this; + } + public WebhookCreator setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - /** - * The configuration.method. - * - * @param configurationMethod The configuration.method - * @return this - */ - public WebhookCreator setConfigurationMethod(final Webhook.Method configurationMethod) { + public WebhookCreator setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - /** - * The configuration.filters. - * - * @param configurationFilters The configuration.filters - * @return this - */ - public WebhookCreator setConfigurationFilters(final List configurationFilters) { + public WebhookCreator setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - /** - * The configuration.filters. - * - * @param configurationFilters The configuration.filters - * @return this - */ - public WebhookCreator setConfigurationFilters(final String configurationFilters) { - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + public WebhookCreator setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - /** - * The configuration.triggers. - * - * @param configurationTriggers The configuration.triggers - * @return this - */ - public WebhookCreator setConfigurationTriggers(final List configurationTriggers) { + public WebhookCreator setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - /** - * The configuration.triggers. - * - * @param configurationTriggers The configuration.triggers - * @return this - */ - public WebhookCreator setConfigurationTriggers(final String configurationTriggers) { - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + public WebhookCreator setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - /** - * The configuration.flow_sid. - * - * @param configurationFlowSid The configuration.flow_sid - * @return this - */ - public WebhookCreator setConfigurationFlowSid(final String configurationFlowSid) { + public WebhookCreator setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - /** - * The configuration.retry_count. - * - * @param configurationRetryCount The configuration.retry_count - * @return this - */ - public WebhookCreator setConfigurationRetryCount(final Integer configurationRetryCount) { + public WebhookCreator setConfigurationRetryCount( + final Integer configurationRetryCount + ) { this.configurationRetryCount = configurationRetryCount; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Webhook - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Webhook create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Webhook creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Webhook create(final TwilioRestClient client) { + Response response = makeRequest(client); return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (configurationUrl != null) { - request.addPostParam("Configuration.Url", configurationUrl); + Serializer.toString( + request, + "Configuration.Url", + configurationUrl, + ParameterType.URLENCODED + ); } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); + Serializer.toString( + request, + "Configuration.Method", + configurationMethod, + ParameterType.URLENCODED + ); } if (configurationFilters != null) { - for (String prop : configurationFilters) { - request.addPostParam("Configuration.Filters", prop); + for (String param : configurationFilters) { + Serializer.toString( + request, + "Configuration.Filters", + param, + ParameterType.URLENCODED + ); } } if (configurationTriggers != null) { - for (String prop : configurationTriggers) { - request.addPostParam("Configuration.Triggers", prop); + for (String param : configurationTriggers) { + Serializer.toString( + request, + "Configuration.Triggers", + param, + ParameterType.URLENCODED + ); } } if (configurationFlowSid != null) { - request.addPostParam("Configuration.FlowSid", configurationFlowSid); + Serializer.toString( + request, + "Configuration.FlowSid", + configurationFlowSid, + ParameterType.URLENCODED + ); } if (configurationRetryCount != null) { - request.addPostParam("Configuration.RetryCount", configurationRetryCount.toString()); + Serializer.toString( + request, + "Configuration.RetryCount", + configurationRetryCount, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookDeleter.java index 4ad80f09c2..fd11faad47 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class WebhookDeleter extends Deleter { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new WebhookDeleter. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public WebhookDeleter(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public WebhookDeleter( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Webhook delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookFetcher.java index 6c15a58d75..e5c3918d18 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WebhookFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; - /** - * Construct a new WebhookFetcher. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public WebhookFetcher(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; + + public WebhookFetcher( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Webhook - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Webhook fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Webhook fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookReader.java index 1fa5d254e9..8572808a8d 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; @@ -10,163 +17,206 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WebhookReader extends Reader { - private final String pathServiceSid; - private final String pathChannelSid; - - /** - * Construct a new WebhookReader. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - */ - public WebhookReader(final String pathServiceSid, - final String pathChannelSid) { + + private String pathServiceSid; + private String pathChannelSid; + private Long pageSize; + + public WebhookReader( + final String pathServiceSid, + final String pathChannelSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Webhook ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public WebhookReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Webhook ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Webhook ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Webhook read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "webhooks", + response.getContent(), + Webhook.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Webhook Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Webhook read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "webhooks", - response.getContent(), - Webhook.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookUpdater.java index 33aea19ce1..1ca83966ab 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookUpdater.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/channel/WebhookUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.channel; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,13 +28,15 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class WebhookUpdater extends Updater { - private final String pathServiceSid; - private final String pathChannelSid; - private final String pathSid; + + private String pathServiceSid; + private String pathChannelSid; + private String pathSid; private String configurationUrl; private Webhook.Method configurationMethod; private List configurationFilters; @@ -31,178 +44,198 @@ public class WebhookUpdater extends Updater { private String configurationFlowSid; private Integer configurationRetryCount; - /** - * Construct a new WebhookUpdater. - * - * @param pathServiceSid The service_sid - * @param pathChannelSid The channel_sid - * @param pathSid The sid - */ - public WebhookUpdater(final String pathServiceSid, - final String pathChannelSid, - final String pathSid) { + public WebhookUpdater( + final String pathServiceSid, + final String pathChannelSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathChannelSid = pathChannelSid; this.pathSid = pathSid; } - /** - * The configuration.url. - * - * @param configurationUrl The configuration.url - * @return this - */ public WebhookUpdater setConfigurationUrl(final String configurationUrl) { this.configurationUrl = configurationUrl; return this; } - /** - * The configuration.method. - * - * @param configurationMethod The configuration.method - * @return this - */ - public WebhookUpdater setConfigurationMethod(final Webhook.Method configurationMethod) { + public WebhookUpdater setConfigurationMethod( + final Webhook.Method configurationMethod + ) { this.configurationMethod = configurationMethod; return this; } - /** - * The configuration.filters. - * - * @param configurationFilters The configuration.filters - * @return this - */ - public WebhookUpdater setConfigurationFilters(final List configurationFilters) { + public WebhookUpdater setConfigurationFilters( + final List configurationFilters + ) { this.configurationFilters = configurationFilters; return this; } - /** - * The configuration.filters. - * - * @param configurationFilters The configuration.filters - * @return this - */ - public WebhookUpdater setConfigurationFilters(final String configurationFilters) { - return setConfigurationFilters(Promoter.listOfOne(configurationFilters)); + public WebhookUpdater setConfigurationFilters( + final String configurationFilters + ) { + return setConfigurationFilters( + Promoter.listOfOne(configurationFilters) + ); } - /** - * The configuration.triggers. - * - * @param configurationTriggers The configuration.triggers - * @return this - */ - public WebhookUpdater setConfigurationTriggers(final List configurationTriggers) { + public WebhookUpdater setConfigurationTriggers( + final List configurationTriggers + ) { this.configurationTriggers = configurationTriggers; return this; } - /** - * The configuration.triggers. - * - * @param configurationTriggers The configuration.triggers - * @return this - */ - public WebhookUpdater setConfigurationTriggers(final String configurationTriggers) { - return setConfigurationTriggers(Promoter.listOfOne(configurationTriggers)); + public WebhookUpdater setConfigurationTriggers( + final String configurationTriggers + ) { + return setConfigurationTriggers( + Promoter.listOfOne(configurationTriggers) + ); } - /** - * The configuration.flow_sid. - * - * @param configurationFlowSid The configuration.flow_sid - * @return this - */ - public WebhookUpdater setConfigurationFlowSid(final String configurationFlowSid) { + public WebhookUpdater setConfigurationFlowSid( + final String configurationFlowSid + ) { this.configurationFlowSid = configurationFlowSid; return this; } - /** - * The configuration.retry_count. - * - * @param configurationRetryCount The configuration.retry_count - * @return this - */ - public WebhookUpdater setConfigurationRetryCount(final Integer configurationRetryCount) { + public WebhookUpdater setConfigurationRetryCount( + final Integer configurationRetryCount + ) { this.configurationRetryCount = configurationRetryCount; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Webhook - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Webhook update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Channels/{ChannelSid}/Webhooks/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Channels/" + this.pathChannelSid + "/Webhooks/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Webhook update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Webhook update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Webhook update(final TwilioRestClient client) { + Response response = makeRequest(client); return Webhook.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (configurationUrl != null) { - request.addPostParam("Configuration.Url", configurationUrl); + Serializer.toString( + request, + "Configuration.Url", + configurationUrl, + ParameterType.URLENCODED + ); } if (configurationMethod != null) { - request.addPostParam("Configuration.Method", configurationMethod.toString()); + Serializer.toString( + request, + "Configuration.Method", + configurationMethod, + ParameterType.URLENCODED + ); } if (configurationFilters != null) { - for (String prop : configurationFilters) { - request.addPostParam("Configuration.Filters", prop); + for (String param : configurationFilters) { + Serializer.toString( + request, + "Configuration.Filters", + param, + ParameterType.URLENCODED + ); } } if (configurationTriggers != null) { - for (String prop : configurationTriggers) { - request.addPostParam("Configuration.Triggers", prop); + for (String param : configurationTriggers) { + Serializer.toString( + request, + "Configuration.Triggers", + param, + ParameterType.URLENCODED + ); } } if (configurationFlowSid != null) { - request.addPostParam("Configuration.FlowSid", configurationFlowSid); + Serializer.toString( + request, + "Configuration.FlowSid", + configurationFlowSid, + ParameterType.URLENCODED + ); } if (configurationRetryCount != null) { - request.addPostParam("Configuration.RetryCount", configurationRetryCount.toString()); + Serializer.toString( + request, + "Configuration.RetryCount", + configurationRetryCount, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBinding.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBinding.java index 087a5140be..a4f38264c1 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBinding.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBinding.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.user; @@ -10,33 +17,56 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class UserBinding extends Resource { - private static final long serialVersionUID = 241481961692245L; + + public static UserBindingDeleter deleter( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { + return new UserBindingDeleter(pathServiceSid, pathUserSid, pathSid); + } + + public static UserBindingFetcher fetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { + return new UserBindingFetcher(pathServiceSid, pathUserSid, pathSid); + } + + public static UserBindingReader reader( + final String pathServiceSid, + final String pathUserSid + ) { + return new UserBindingReader(pathServiceSid, pathUserSid); + } public enum BindingType { GCM("gcm"), @@ -49,15 +79,11 @@ private BindingType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a BindingType from a string. - * @param value string value - * @return generated BindingType - */ @JsonCreator public static BindingType forValue(final String value) { return Promoter.enumFromString(value, BindingType.values()); @@ -65,54 +91,16 @@ public static BindingType forValue(final String value) { } /** - * Create a UserBindingReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @return UserBindingReader capable of executing the read - */ - public static UserBindingReader reader(final String pathServiceSid, - final String pathUserSid) { - return new UserBindingReader(pathServiceSid, pathUserSid); - } - - /** - * Create a UserBindingFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @param pathSid The sid - * @return UserBindingFetcher capable of executing the fetch - */ - public static UserBindingFetcher fetcher(final String pathServiceSid, - final String pathUserSid, - final String pathSid) { - return new UserBindingFetcher(pathServiceSid, pathUserSid, pathSid); - } - - /** - * Create a UserBindingDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @param pathSid The sid - * @return UserBindingDeleter capable of executing the delete - */ - public static UserBindingDeleter deleter(final String pathServiceSid, - final String pathUserSid, - final String pathSid) { - return new UserBindingDeleter(pathServiceSid, pathUserSid, pathSid); - } - - /** - * Converts a JSON String into a UserBinding object using the provided - * ObjectMapper. - * + * Converts a JSON String into a UserBinding object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return UserBinding object represented by the provided JSON */ - public static UserBinding fromJson(final String json, final ObjectMapper objectMapper) { + public static UserBinding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserBinding.class); @@ -126,12 +114,15 @@ public static UserBinding fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a UserBinding object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return UserBinding object represented by the provided JSON */ - public static UserBinding fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static UserBinding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserBinding.class); @@ -142,166 +133,91 @@ public static UserBinding fromJson(final InputStream json, final ObjectMapper ob } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String endpoint; - private final String identity; - private final String userSid; - private final String credentialSid; - private final UserBinding.BindingType bindingType; - private final List messageTypes; - private final URI url; - - @JsonCreator - private UserBinding(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("endpoint") - final String endpoint, - @JsonProperty("identity") - final String identity, - @JsonProperty("user_sid") - final String userSid, - @JsonProperty("credential_sid") - final String credentialSid, - @JsonProperty("binding_type") - final UserBinding.BindingType bindingType, - @JsonProperty("message_types") - final List messageTypes, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.endpoint = endpoint; - this.identity = identity; - this.userSid = userSid; - this.credentialSid = credentialSid; - this.bindingType = bindingType; - this.messageTypes = messageTypes; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique id of the Account responsible for this binding.. - * - * @return The unique id of the Account responsible for this binding. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final UserBinding.BindingType bindingType; - /** - * Returns The The unique id of the Service this binding belongs to.. - * - * @return The unique id of the Service this binding belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String credentialSid; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The unique endpoint identifier for this Binding.. - * - * @return The unique endpoint identifier for this Binding. - */ - public final String getEndpoint() { - return this.endpoint; - } + @Getter + private final String endpoint; - /** - * Returns The A unique string identifier for the Binding for this User in this - * Service.. - * - * @return A unique string identifier for the Binding for this User in this - * Service. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final String identity; - /** - * Returns The The unique id of the User for this binding.. - * - * @return The unique id of the User for this binding. - */ - public final String getUserSid() { - return this.userSid; - } + @Getter + private final List messageTypes; - /** - * Returns The The unique id of the Credential for this binding.. - * - * @return The unique id of the Credential for this binding. - */ - public final String getCredentialSid() { - return this.credentialSid; - } + @Getter + private final String serviceSid; - /** - * Returns The The push technology to use for this binding.. - * - * @return The push technology to use for this binding. - */ - public final UserBinding.BindingType getBindingType() { - return this.bindingType; - } + @Getter + private final String sid; - /** - * Returns The List of message types for this binding.. - * - * @return List of message types for this binding. - */ - public final List getMessageTypes() { - return this.messageTypes; - } + @Getter + private final URI url; - /** - * Returns The An absolute URL for this binding.. - * - * @return An absolute URL for this binding. - */ - public final URI getUrl() { - return this.url; + @Getter + private final String userSid; + + @JsonCreator + private UserBinding( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("binding_type") final UserBinding.BindingType bindingType, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("message_types") final List messageTypes, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("user_sid") final String userSid + ) { + this.accountSid = accountSid; + this.bindingType = bindingType; + this.credentialSid = credentialSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.endpoint = endpoint; + this.identity = identity; + this.messageTypes = messageTypes; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + this.userSid = userSid; } @Override @@ -315,52 +231,37 @@ public boolean equals(final Object o) { } UserBinding other = (UserBinding) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(endpoint, other.endpoint) && - Objects.equals(identity, other.identity) && - Objects.equals(userSid, other.userSid) && - Objects.equals(credentialSid, other.credentialSid) && - Objects.equals(bindingType, other.bindingType) && - Objects.equals(messageTypes, other.messageTypes) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(messageTypes, other.messageTypes) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(userSid, other.userSid) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - endpoint, - identity, - userSid, - credentialSid, - bindingType, - messageTypes, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("endpoint", endpoint) - .add("identity", identity) - .add("userSid", userSid) - .add("credentialSid", credentialSid) - .add("bindingType", bindingType) - .add("messageTypes", messageTypes) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + bindingType, + credentialSid, + dateCreated, + dateUpdated, + endpoint, + identity, + messageTypes, + serviceSid, + sid, + url, + userSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingDeleter.java index 1e4b9881bf..d749b200b2 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingDeleter.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.user; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class UserBindingDeleter extends Deleter { - private final String pathServiceSid; - private final String pathUserSid; - private final String pathSid; - /** - * Construct a new UserBindingDeleter. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @param pathSid The sid - */ - public UserBindingDeleter(final String pathServiceSid, - final String pathUserSid, - final String pathSid) { + private String pathServiceSid; + private String pathUserSid; + private String pathSid; + + public UserBindingDeleter( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "UserBinding delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingFetcher.java index 7f622380e3..dc30f22f1e 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingFetcher.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.user; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,88 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserBindingFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathUserSid; - private final String pathSid; - /** - * Construct a new UserBindingFetcher. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - * @param pathSid The sid - */ - public UserBindingFetcher(final String pathServiceSid, - final String pathUserSid, - final String pathSid) { + private String pathServiceSid; + private String pathUserSid; + private String pathSid; + + public UserBindingFetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched UserBinding - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public UserBinding fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("UserBinding fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "UserBinding fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return UserBinding.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public UserBinding fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserBinding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserBinding content = UserBinding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingReader.java index b5b0b526cf..0244794b48 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserBindingReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.user; @@ -10,198 +17,228 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class UserBindingReader extends Reader { - private final String pathServiceSid; - private final String pathUserSid; + + private String pathServiceSid; + private String pathUserSid; private List bindingType; + private Long pageSize; - /** - * Construct a new UserBindingReader. - * - * @param pathServiceSid The service_sid - * @param pathUserSid The user_sid - */ - public UserBindingReader(final String pathServiceSid, - final String pathUserSid) { + public UserBindingReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - /** - * The push technology used for the returned Bindings. Supported values are - * apn, gcm and fcm. See [push notification - * configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more information.. - * - * @param bindingType The push technology used for the bindings returned. - * @return this - */ - public UserBindingReader setBindingType(final List bindingType) { + public UserBindingReader setBindingType( + final List bindingType + ) { this.bindingType = bindingType; return this; } - /** - * The push technology used for the returned Bindings. Supported values are - * apn, gcm and fcm. See [push notification - * configuration](https://www.twilio.com/docs/chat/push-notification-configuration) for more information.. - * - * @param bindingType The push technology used for the bindings returned. - * @return this - */ - public UserBindingReader setBindingType(final UserBinding.BindingType bindingType) { + public UserBindingReader setBindingType( + final UserBinding.BindingType bindingType + ) { return setBindingType(Promoter.listOfOne(bindingType)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserBindingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + UserBinding.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Bindings"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Bindings", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + UserBinding.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UserBinding read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "bindings", + response.getContent(), + UserBinding.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of UserBinding Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserBinding read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "bindings", - response.getContent(), - UserBinding.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (bindingType != null) { - for (UserBinding.BindingType prop : bindingType) { - request.addQueryParam("BindingType", prop.toString()); + for (UserBinding.BindingType param : bindingType) { + Serializer.toString( + request, + "BindingType", + param, + ParameterType.QUERY + ); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannel.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannel.java index da1354c7cf..00e32b948d 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannel.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.user; @@ -10,29 +17,94 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.net.URI; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class UserChannel extends Resource { - private static final long serialVersionUID = 254880238496884L; + + public static UserChannelDeleter deleter( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelDeleter( + pathServiceSid, + pathUserSid, + pathChannelSid + ); + } + + public static UserChannelFetcher fetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelFetcher( + pathServiceSid, + pathUserSid, + pathChannelSid + ); + } + + public static UserChannelReader reader( + final String pathServiceSid, + final String pathUserSid + ) { + return new UserChannelReader(pathServiceSid, pathUserSid); + } + + public static UserChannelUpdater updater( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + return new UserChannelUpdater( + pathServiceSid, + pathUserSid, + pathChannelSid + ); + } + + public enum NotificationLevel { + DEFAULT("default"), + MUTED("muted"); + + private final String value; + + private NotificationLevel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static NotificationLevel forValue(final String value) { + return Promoter.enumFromString(value, NotificationLevel.values()); + } + } public enum ChannelStatus { JOINED("joined"), @@ -45,15 +117,11 @@ private ChannelStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ChannelStatus from a string. - * @param value string value - * @return generated ChannelStatus - */ @JsonCreator public static ChannelStatus forValue(final String value) { return Promoter.enumFromString(value, ChannelStatus.values()); @@ -61,26 +129,16 @@ public static ChannelStatus forValue(final String value) { } /** - * Create a UserChannelReader to execute read. - * - * @param pathServiceSid The unique id of the Service those channels belong to. - * @param pathUserSid The unique id of a User. - * @return UserChannelReader capable of executing the read - */ - public static UserChannelReader reader(final String pathServiceSid, - final String pathUserSid) { - return new UserChannelReader(pathServiceSid, pathUserSid); - } - - /** - * Converts a JSON String into a UserChannel object using the provided - * ObjectMapper. - * + * Converts a JSON String into a UserChannel object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return UserChannel object represented by the provided JSON */ - public static UserChannel fromJson(final String json, final ObjectMapper objectMapper) { + public static UserChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -94,12 +152,15 @@ public static UserChannel fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a UserChannel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return UserChannel object represented by the provided JSON */ - public static UserChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static UserChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, UserChannel.class); @@ -110,113 +171,82 @@ public static UserChannel fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String channelSid; - private final String memberSid; - private final UserChannel.ChannelStatus status; + + @Getter private final Integer lastConsumedMessageIndex; - private final Integer unreadMessagesCount; - private final Map links; - @JsonCreator - private UserChannel(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("channel_sid") - final String channelSid, - @JsonProperty("member_sid") - final String memberSid, - @JsonProperty("status") - final UserChannel.ChannelStatus status, - @JsonProperty("last_consumed_message_index") - final Integer lastConsumedMessageIndex, - @JsonProperty("unread_messages_count") - final Integer unreadMessagesCount, - @JsonProperty("links") - final Map links) { - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.channelSid = channelSid; - this.memberSid = memberSid; - this.status = status; - this.lastConsumedMessageIndex = lastConsumedMessageIndex; - this.unreadMessagesCount = unreadMessagesCount; - this.links = links; - } + @Getter + private final Map links; - /** - * Returns The The unique id of the Account responsible for this channel.. - * - * @return The unique id of the Account responsible for this channel. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String memberSid; - /** - * Returns The The unique id of the Service this channel belongs to.. - * - * @return The unique id of the Service this channel belongs to. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final UserChannel.NotificationLevel notificationLevel; - /** - * Returns The The unique id of a Channel.. - * - * @return The unique id of a Channel. - */ - public final String getChannelSid() { - return this.channelSid; - } + @Getter + private final String serviceSid; - /** - * Returns The The unique id of this User as a Member in this Channel.. - * - * @return The unique id of this User as a Member in this Channel. - */ - public final String getMemberSid() { - return this.memberSid; - } + @Getter + private final UserChannel.ChannelStatus status; - /** - * Returns The The status of the User on this Channel.. - * - * @return The status of the User on this Channel. - */ - public final UserChannel.ChannelStatus getStatus() { - return this.status; - } + @Getter + private final Integer unreadMessagesCount; - /** - * Returns The The index of the last read Message in this Channel for this - * User.. - * - * @return The index of the last read Message in this Channel for this User. - */ - public final Integer getLastConsumedMessageIndex() { - return this.lastConsumedMessageIndex; - } + @Getter + private final URI url; - /** - * Returns The The count of unread Messages in this Channel for this User.. - * - * @return The count of unread Messages in this Channel for this User. - */ - public final Integer getUnreadMessagesCount() { - return this.unreadMessagesCount; - } + @Getter + private final String userSid; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @JsonCreator + private UserChannel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_sid") final String channelSid, + @JsonProperty( + "last_consumed_message_index" + ) final Integer lastConsumedMessageIndex, + @JsonProperty("links") final Map links, + @JsonProperty("member_sid") final String memberSid, + @JsonProperty( + "notification_level" + ) final UserChannel.NotificationLevel notificationLevel, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("status") final UserChannel.ChannelStatus status, + @JsonProperty( + "unread_messages_count" + ) final Integer unreadMessagesCount, + @JsonProperty("url") final URI url, + @JsonProperty("user_sid") final String userSid + ) { + this.accountSid = accountSid; + this.channelSid = channelSid; + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + this.links = links; + this.memberSid = memberSid; + this.notificationLevel = notificationLevel; + this.serviceSid = serviceSid; + this.status = status; + this.unreadMessagesCount = unreadMessagesCount; + this.url = url; + this.userSid = userSid; } @Override @@ -230,40 +260,38 @@ public boolean equals(final Object o) { } UserChannel other = (UserChannel) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(channelSid, other.channelSid) && - Objects.equals(memberSid, other.memberSid) && - Objects.equals(status, other.status) && - Objects.equals(lastConsumedMessageIndex, other.lastConsumedMessageIndex) && - Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelSid, other.channelSid) && + Objects.equals( + lastConsumedMessageIndex, + other.lastConsumedMessageIndex + ) && + Objects.equals(links, other.links) && + Objects.equals(memberSid, other.memberSid) && + Objects.equals(notificationLevel, other.notificationLevel) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(status, other.status) && + Objects.equals(unreadMessagesCount, other.unreadMessagesCount) && + Objects.equals(url, other.url) && + Objects.equals(userSid, other.userSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - channelSid, - memberSid, - status, - lastConsumedMessageIndex, - unreadMessagesCount, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("channelSid", channelSid) - .add("memberSid", memberSid) - .add("status", status) - .add("lastConsumedMessageIndex", lastConsumedMessageIndex) - .add("unreadMessagesCount", unreadMessagesCount) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + channelSid, + lastConsumedMessageIndex, + links, + memberSid, + notificationLevel, + serviceSid, + status, + unreadMessagesCount, + url, + userSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelDeleter.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelDeleter.java new file mode 100644 index 0000000000..872b877266 --- /dev/null +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelDeleter.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.ipmessaging.v2.service.user; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UserChannelDeleter extends Deleter { + + private String pathServiceSid; + private String pathUserSid; + private String pathChannelSid; + + public UserChannelDeleter( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathUserSid = pathUserSid; + this.pathChannelSid = pathChannelSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.IPMESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserChannel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelFetcher.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelFetcher.java new file mode 100644 index 0000000000..601810b009 --- /dev/null +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.ipmessaging.v2.service.user; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserChannelFetcher extends Fetcher { + + private String pathServiceSid; + private String pathUserSid; + private String pathChannelSid; + + public UserChannelFetcher( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathUserSid = pathUserSid; + this.pathChannelSid = pathChannelSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.IPMESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserChannel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserChannel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserChannel content = UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelReader.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelReader.java index 826e790b63..34639a4922 100644 --- a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelReader.java +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.ipmessaging.v2.service.user; @@ -10,163 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class UserChannelReader extends Reader { - private final String pathServiceSid; - private final String pathUserSid; - - /** - * Construct a new UserChannelReader. - * - * @param pathServiceSid The unique id of the Service those channels belong to. - * @param pathUserSid The unique id of a User. - */ - public UserChannelReader(final String pathServiceSid, - final String pathUserSid) { + + private String pathServiceSid; + private String pathUserSid; + private Long pageSize; + + public UserChannelReader( + final String pathServiceSid, + final String pathUserSid + ) { this.pathServiceSid = pathServiceSid; this.pathUserSid = pathUserSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public UserChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.IPMESSAGING.toString(), - "/v2/Services/" + this.pathServiceSid + "/Users/" + this.pathUserSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return UserChannel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UserChannel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + UserChannel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.IPMESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of UserChannel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserChannel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - UserChannel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelUpdater.java b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelUpdater.java new file mode 100644 index 0000000000..faf320acfb --- /dev/null +++ b/src/main/java/com/twilio/rest/ipmessaging/v2/service/user/UserChannelUpdater.java @@ -0,0 +1,174 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Ip_messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.ipmessaging.v2.service.user; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class UserChannelUpdater extends Updater { + + private String pathServiceSid; + private String pathUserSid; + private String pathChannelSid; + private UserChannel.NotificationLevel notificationLevel; + private Integer lastConsumedMessageIndex; + private ZonedDateTime lastConsumptionTimestamp; + + public UserChannelUpdater( + final String pathServiceSid, + final String pathUserSid, + final String pathChannelSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathUserSid = pathUserSid; + this.pathChannelSid = pathChannelSid; + } + + public UserChannelUpdater setNotificationLevel( + final UserChannel.NotificationLevel notificationLevel + ) { + this.notificationLevel = notificationLevel; + return this; + } + + public UserChannelUpdater setLastConsumedMessageIndex( + final Integer lastConsumedMessageIndex + ) { + this.lastConsumedMessageIndex = lastConsumedMessageIndex; + return this; + } + + public UserChannelUpdater setLastConsumptionTimestamp( + final ZonedDateTime lastConsumptionTimestamp + ) { + this.lastConsumptionTimestamp = lastConsumptionTimestamp; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Services/{ServiceSid}/Users/{UserSid}/Channels/{ChannelSid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + path = + path.replace( + "{" + "ChannelSid" + "}", + this.pathChannelSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.IPMESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UserChannel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UserChannel update(final TwilioRestClient client) { + Response response = makeRequest(client); + return UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UserChannel content = UserChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (notificationLevel != null) { + Serializer.toString( + request, + "NotificationLevel", + notificationLevel, + ParameterType.URLENCODED + ); + } + + if (lastConsumedMessageIndex != null) { + Serializer.toString( + request, + "LastConsumedMessageIndex", + lastConsumedMessageIndex, + ParameterType.URLENCODED + ); + } + + if (lastConsumptionTimestamp != null) { + Serializer.toString( + request, + "LastConsumptionTimestamp", + lastConsumptionTimestamp, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/Knowledge.java b/src/main/java/com/twilio/rest/knowledge/v1/Knowledge.java new file mode 100644 index 0000000000..0f11209abf --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/Knowledge.java @@ -0,0 +1,721 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Knowledge extends Resource { + + public static KnowledgeCreator creator( + final Knowledge.KnowledgeV1ServiceCreateKnowledgeRequest knowledgeV1ServiceCreateKnowledgeRequest + ) { + return new KnowledgeCreator(knowledgeV1ServiceCreateKnowledgeRequest); + } + + public static KnowledgeDeleter deleter(final String pathId) { + return new KnowledgeDeleter(pathId); + } + + public static KnowledgeFetcher fetcher(final String pathId) { + return new KnowledgeFetcher(pathId); + } + + public static KnowledgeReader reader() { + return new KnowledgeReader(); + } + + public static KnowledgeUpdater updater(final String pathId) { + return new KnowledgeUpdater(pathId); + } + + @JsonDeserialize( + builder = KnowledgeV1ServiceUpdateKnowledgeRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeV1ServiceUpdateKnowledgeRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge_source_details") + @Getter + private final Object knowledgeSourceDetails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + @Getter + private final KnowledgeV1ServiceCreatePolicyRequest policy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("embedding_model") + @Getter + private final String embeddingModel; + + private KnowledgeV1ServiceUpdateKnowledgeRequest(Builder builder) { + this.description = builder.description; + this.knowledgeSourceDetails = builder.knowledgeSourceDetails; + this.name = builder.name; + this.policy = builder.policy; + this.type = builder.type; + this.embeddingModel = builder.embeddingModel; + } + + public static Builder builder() { + return new Builder(); + } + + public static KnowledgeV1ServiceUpdateKnowledgeRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + KnowledgeV1ServiceUpdateKnowledgeRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("description") + private String description; + + @JsonProperty("knowledge_source_details") + private Object knowledgeSourceDetails; + + @JsonProperty("name") + private String name; + + @JsonProperty("policy") + private KnowledgeV1ServiceCreatePolicyRequest policy; + + @JsonProperty("type") + private String type; + + @JsonProperty("embedding_model") + private String embeddingModel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge_source_details") + public Builder knowledgeSourceDetails( + Object knowledgeSourceDetails + ) { + this.knowledgeSourceDetails = knowledgeSourceDetails; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + public Builder policy( + KnowledgeV1ServiceCreatePolicyRequest policy + ) { + this.policy = policy; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("embedding_model") + public Builder embeddingModel(String embeddingModel) { + this.embeddingModel = embeddingModel; + return this; + } + + public KnowledgeV1ServiceUpdateKnowledgeRequest build() { + return new KnowledgeV1ServiceUpdateKnowledgeRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeV1ServiceUpdateKnowledgeRequest other = + (KnowledgeV1ServiceUpdateKnowledgeRequest) o; + return ( + Objects.equals(description, other.description) && + Objects.equals( + knowledgeSourceDetails, + other.knowledgeSourceDetails + ) && + Objects.equals(name, other.name) && + Objects.equals(policy, other.policy) && + Objects.equals(type, other.type) && + Objects.equals(embeddingModel, other.embeddingModel) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + description, + knowledgeSourceDetails, + name, + policy, + type, + embeddingModel + ); + } + } + + @JsonDeserialize( + builder = KnowledgeV1ServiceCreateKnowledgeRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeV1ServiceCreateKnowledgeRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge_source_details") + @Getter + private final Object knowledgeSourceDetails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + @Getter + private final KnowledgeV1ServiceCreatePolicyRequest policy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("embedding_model") + @Getter + private final String embeddingModel; + + private KnowledgeV1ServiceCreateKnowledgeRequest(Builder builder) { + this.description = builder.description; + this.knowledgeSourceDetails = builder.knowledgeSourceDetails; + this.name = builder.name; + this.policy = builder.policy; + this.type = builder.type; + this.embeddingModel = builder.embeddingModel; + } + + public static Builder builder(final String name, final String type) { + return new Builder(name, type); + } + + public static KnowledgeV1ServiceCreateKnowledgeRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + KnowledgeV1ServiceCreateKnowledgeRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("description") + private String description; + + @JsonProperty("knowledge_source_details") + private Object knowledgeSourceDetails; + + @JsonProperty("name") + private String name; + + @JsonProperty("policy") + private KnowledgeV1ServiceCreatePolicyRequest policy; + + @JsonProperty("type") + private String type; + + @JsonProperty("embedding_model") + private String embeddingModel; + + @JsonCreator + public Builder( + @JsonProperty("name") final String name, + @JsonProperty("type") final String type + ) { + this.name = name; + this.type = type; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledge_source_details") + public Builder knowledgeSourceDetails( + Object knowledgeSourceDetails + ) { + this.knowledgeSourceDetails = knowledgeSourceDetails; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy") + public Builder policy( + KnowledgeV1ServiceCreatePolicyRequest policy + ) { + this.policy = policy; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("embedding_model") + public Builder embeddingModel(String embeddingModel) { + this.embeddingModel = embeddingModel; + return this; + } + + public KnowledgeV1ServiceCreateKnowledgeRequest build() { + return new KnowledgeV1ServiceCreateKnowledgeRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeV1ServiceCreateKnowledgeRequest other = + (KnowledgeV1ServiceCreateKnowledgeRequest) o; + return ( + Objects.equals(description, other.description) && + Objects.equals( + knowledgeSourceDetails, + other.knowledgeSourceDetails + ) && + Objects.equals(name, other.name) && + Objects.equals(policy, other.policy) && + Objects.equals(type, other.type) && + Objects.equals(embeddingModel, other.embeddingModel) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + description, + knowledgeSourceDetails, + name, + policy, + type, + embeddingModel + ); + } + } + + @JsonDeserialize( + builder = KnowledgeV1ServiceCreatePolicyRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeV1ServiceCreatePolicyRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("policy_details") + @Getter + private final Object policyDetails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + private KnowledgeV1ServiceCreatePolicyRequest(Builder builder) { + this.description = builder.description; + this.id = builder.id; + this.name = builder.name; + this.policyDetails = builder.policyDetails; + this.type = builder.type; + } + + public static Builder builder(final Object policyDetails) { + return new Builder(policyDetails); + } + + public static KnowledgeV1ServiceCreatePolicyRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + KnowledgeV1ServiceCreatePolicyRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("description") + private String description; + + @JsonProperty("id") + private String id; + + @JsonProperty("name") + private String name; + + @JsonProperty("policy_details") + private Object policyDetails; + + @JsonProperty("type") + private String type; + + @JsonCreator + public Builder( + @JsonProperty("policy_details") final Object policyDetails + ) { + this.policyDetails = policyDetails; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + public KnowledgeV1ServiceCreatePolicyRequest build() { + return new KnowledgeV1ServiceCreatePolicyRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeV1ServiceCreatePolicyRequest other = + (KnowledgeV1ServiceCreatePolicyRequest) o; + return ( + Objects.equals(description, other.description) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(policyDetails, other.policyDetails) && + Objects.equals(type, other.type) + ); + } + + @Override + public int hashCode() { + return Objects.hash(description, id, name, policyDetails, type); + } + } + + /** + * Converts a JSON String into a Knowledge object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Knowledge object represented by the provided JSON + */ + public static Knowledge fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Knowledge.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Knowledge object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Knowledge object represented by the provided JSON + */ + public static Knowledge fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Knowledge.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String embeddingModel; + + @Getter + private final String id; + + @Getter + private final Object knowledgeSourceDetails; + + @Getter + private final String name; + + @Getter + private final String status; + + @Getter + private final String type; + + @Getter + private final String url; + + @JsonCreator + private Knowledge( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("embedding_model") final String embeddingModel, + @JsonProperty("id") final String id, + @JsonProperty( + "knowledge_source_details" + ) final Object knowledgeSourceDetails, + @JsonProperty("name") final String name, + @JsonProperty("status") final String status, + @JsonProperty("type") final String type, + @JsonProperty("url") final String url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.embeddingModel = embeddingModel; + this.id = id; + this.knowledgeSourceDetails = knowledgeSourceDetails; + this.name = name; + this.status = status; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Knowledge other = (Knowledge) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(embeddingModel, other.embeddingModel) && + Objects.equals(id, other.id) && + Objects.equals( + knowledgeSourceDetails, + other.knowledgeSourceDetails + ) && + Objects.equals(name, other.name) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + description, + embeddingModel, + id, + knowledgeSourceDetails, + name, + status, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeCreator.java b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeCreator.java new file mode 100644 index 0000000000..954cb6107b --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeCreator extends Creator { + + private Knowledge.KnowledgeV1ServiceCreateKnowledgeRequest knowledgeV1ServiceCreateKnowledgeRequest; + + public KnowledgeCreator( + final Knowledge.KnowledgeV1ServiceCreateKnowledgeRequest knowledgeV1ServiceCreateKnowledgeRequest + ) { + this.knowledgeV1ServiceCreateKnowledgeRequest = + knowledgeV1ServiceCreateKnowledgeRequest; + } + + public KnowledgeCreator setKnowledgeV1ServiceCreateKnowledgeRequest( + final Knowledge.KnowledgeV1ServiceCreateKnowledgeRequest knowledgeV1ServiceCreateKnowledgeRequest + ) { + this.knowledgeV1ServiceCreateKnowledgeRequest = + knowledgeV1ServiceCreateKnowledgeRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Knowledge"; + + Request request = new Request( + HttpMethod.POST, + Domains.KNOWLEDGE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Knowledge create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Knowledge content = Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (knowledgeV1ServiceCreateKnowledgeRequest != null) { + request.setBody( + Knowledge.toJson( + knowledgeV1ServiceCreateKnowledgeRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeDeleter.java b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeDeleter.java new file mode 100644 index 0000000000..1a0df35c1d --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class KnowledgeDeleter extends Deleter { + + private String pathId; + + public KnowledgeDeleter(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.KNOWLEDGE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeFetcher.java b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeFetcher.java new file mode 100644 index 0000000000..ee8324abc0 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeFetcher extends Fetcher { + + private String pathId; + + public KnowledgeFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Knowledge fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Knowledge content = Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeReader.java b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeReader.java new file mode 100644 index 0000000000..729d6ca290 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeReader.java @@ -0,0 +1,212 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeReader extends Reader { + + private Integer pageSize; + private String tags; + + public KnowledgeReader() {} + + public KnowledgeReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public KnowledgeReader setTags(final String tags) { + this.tags = tags; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "knowledge", + response.getContent(), + Knowledge.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Knowledge"; + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "knowledge", + response.getContent(), + Knowledge.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Knowledge read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "knowledge", + response.getContent(), + Knowledge.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (tags != null) { + Serializer.toString(request, "Tags", tags, ParameterType.QUERY); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeUpdater.java b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeUpdater.java new file mode 100644 index 0000000000..62b5117d8e --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/KnowledgeUpdater.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeUpdater extends Updater { + + private String pathId; + private Knowledge.KnowledgeV1ServiceUpdateKnowledgeRequest knowledgeV1ServiceUpdateKnowledgeRequest; + + public KnowledgeUpdater(final String pathId) { + this.pathId = pathId; + } + + public KnowledgeUpdater setKnowledgeV1ServiceUpdateKnowledgeRequest( + final Knowledge.KnowledgeV1ServiceUpdateKnowledgeRequest knowledgeV1ServiceUpdateKnowledgeRequest + ) { + this.knowledgeV1ServiceUpdateKnowledgeRequest = + knowledgeV1ServiceUpdateKnowledgeRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.KNOWLEDGE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Knowledge update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Knowledge content = Knowledge.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (knowledgeV1ServiceUpdateKnowledgeRequest != null) { + request.setBody( + Knowledge.toJson( + knowledgeV1ServiceUpdateKnowledgeRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/knowledge/Chunk.java b/src/main/java/com/twilio/rest/knowledge/v1/knowledge/Chunk.java new file mode 100644 index 0000000000..af8d0f3c93 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/knowledge/Chunk.java @@ -0,0 +1,173 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1.knowledge; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Chunk extends Resource { + + public static ChunkReader reader(final String pathId) { + return new ChunkReader(pathId); + } + + /** + * Converts a JSON String into a Chunk object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Chunk object represented by the provided JSON + */ + public static Chunk fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Chunk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Chunk object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Chunk object represented by the provided JSON + */ + public static Chunk fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Chunk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String content; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Object metadata; + + @JsonCreator + private Chunk( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("content") final String content, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("metadata") final Object metadata + ) { + this.accountSid = accountSid; + this.content = content; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.metadata = metadata; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Chunk other = (Chunk) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(content, other.content) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(metadata, other.metadata) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + content, + dateCreated, + dateUpdated, + metadata + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/knowledge/ChunkReader.java b/src/main/java/com/twilio/rest/knowledge/v1/knowledge/ChunkReader.java new file mode 100644 index 0000000000..3a6380dc08 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/knowledge/ChunkReader.java @@ -0,0 +1,203 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1.knowledge; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChunkReader extends Reader { + + private String pathId; + private Integer pageSize; + + public ChunkReader(final String pathId) { + this.pathId = pathId; + } + + public ChunkReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "chunks", + response.getContent(), + Chunk.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}/Chunks"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "chunks", + response.getContent(), + Chunk.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Chunk read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "chunks", + response.getContent(), + Chunk.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/knowledge/KnowledgeStatus.java b/src/main/java/com/twilio/rest/knowledge/v1/knowledge/KnowledgeStatus.java new file mode 100644 index 0000000000..03d5fc7d2e --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/knowledge/KnowledgeStatus.java @@ -0,0 +1,156 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1.knowledge; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class KnowledgeStatus extends Resource { + + public static KnowledgeStatusFetcher fetcher(final String pathId) { + return new KnowledgeStatusFetcher(pathId); + } + + /** + * Converts a JSON String into a KnowledgeStatus object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return KnowledgeStatus object represented by the provided JSON + */ + public static KnowledgeStatus fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, KnowledgeStatus.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a KnowledgeStatus object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return KnowledgeStatus object represented by the provided JSON + */ + public static KnowledgeStatus fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, KnowledgeStatus.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String lastStatus; + + @Getter + private final String status; + + @JsonCreator + private KnowledgeStatus( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("last_status") final String lastStatus, + @JsonProperty("status") final String status + ) { + this.accountSid = accountSid; + this.dateUpdated = dateUpdated; + this.lastStatus = lastStatus; + this.status = status; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeStatus other = (KnowledgeStatus) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(lastStatus, other.lastStatus) && + Objects.equals(status, other.status) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, dateUpdated, lastStatus, status); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v1/knowledge/KnowledgeStatusFetcher.java b/src/main/java/com/twilio/rest/knowledge/v1/knowledge/KnowledgeStatusFetcher.java new file mode 100644 index 0000000000..3b93ca87de --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v1/knowledge/KnowledgeStatusFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Knowledge + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v1.knowledge; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeStatusFetcher extends Fetcher { + + private String pathId; + + public KnowledgeStatusFetcher(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Knowledge/{id}/Status"; + + path = path.replace("{" + "id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "KnowledgeStatus fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public KnowledgeStatus fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return KnowledgeStatus.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + KnowledgeStatus content = KnowledgeStatus.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/Chunk.java b/src/main/java/com/twilio/rest/knowledge/v2/Chunk.java new file mode 100644 index 0000000000..8226d38b5f --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/Chunk.java @@ -0,0 +1,689 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Chunk extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateChunkResponse extends Resource { + + @JsonCreator + private CreateChunkResponse() {} + + public static CreateChunkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateChunkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateChunkResponse other = (CreateChunkResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateChunkResponse extends Resource { + + @JsonCreator + private UpdateChunkResponse() {} + + public static UpdateChunkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateChunkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateChunkResponse other = (UpdateChunkResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteChunkResponse extends Resource { + + @JsonCreator + private DeleteChunkResponse() {} + + public static DeleteChunkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteChunkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteChunkResponse other = (DeleteChunkResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListChunkResponse extends Resource { + + @Getter + private final Integer chunkIndex; + + @Getter + private final String content; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final Integer documentNumber; + + @Getter + private final String documentTitle; + + @Getter + private final URI documentUrl; + + @JsonCreator + private ListChunkResponse( + @JsonProperty("chunkIndex") final Integer chunkIndex, + @JsonProperty("content") final String content, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("documentNumber") final Integer documentNumber, + @JsonProperty("documentTitle") final String documentTitle, + @JsonProperty("documentUrl") final URI documentUrl + ) { + this.chunkIndex = chunkIndex; + this.content = content; + this.createdAt = createdAt; + this.documentNumber = documentNumber; + this.documentTitle = documentTitle; + this.documentUrl = documentUrl; + } + + public static ListChunkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListChunkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListChunkResponse other = (ListChunkResponse) o; + return ( + Objects.equals(chunkIndex, other.chunkIndex) && + Objects.equals(content, other.content) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(documentNumber, other.documentNumber) && + Objects.equals(documentTitle, other.documentTitle) && + Objects.equals(documentUrl, other.documentUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + chunkIndex, + content, + createdAt, + documentNumber, + documentTitle, + documentUrl + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchChunkResponse extends Resource { + + @JsonCreator + private PatchChunkResponse() {} + + public static PatchChunkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchChunkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchChunkResponse other = (PatchChunkResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchChunkResponse extends Resource { + + @JsonCreator + private FetchChunkResponse() {} + + public static FetchChunkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchChunkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchChunkResponse other = (FetchChunkResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + public static ChunkReader reader( + final String pathKbId, + final String pathKnowledgeId + ) { + return new ChunkReader(pathKbId, pathKnowledgeId); + } + + @JsonDeserialize(builder = KnowledgeMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private KnowledgeMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static KnowledgeMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public KnowledgeMeta build() { + return new KnowledgeMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeMeta other = (KnowledgeMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = KnowledgeChunk.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeChunk { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("chunkIndex") + @Getter + private final Integer chunkIndex; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentTitle") + @Getter + private final String documentTitle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentUrl") + @Getter + private final URI documentUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentNumber") + @Getter + private final Integer documentNumber; + + private KnowledgeChunk(Builder builder) { + this.content = builder.content; + this.createdAt = builder.createdAt; + this.chunkIndex = builder.chunkIndex; + this.documentTitle = builder.documentTitle; + this.documentUrl = builder.documentUrl; + this.documentNumber = builder.documentNumber; + } + + public static Builder builder() { + return new Builder(); + } + + public static KnowledgeChunk fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeChunk.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonProperty("chunkIndex") + private Integer chunkIndex; + + @JsonProperty("documentTitle") + private String documentTitle; + + @JsonProperty("documentUrl") + private URI documentUrl; + + @JsonProperty("documentNumber") + private Integer documentNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + public Builder content(String content) { + this.content = content; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("chunkIndex") + public Builder chunkIndex(Integer chunkIndex) { + this.chunkIndex = chunkIndex; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentTitle") + public Builder documentTitle(String documentTitle) { + this.documentTitle = documentTitle; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentUrl") + public Builder documentUrl(URI documentUrl) { + this.documentUrl = documentUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentNumber") + public Builder documentNumber(Integer documentNumber) { + this.documentNumber = documentNumber; + return this; + } + + public KnowledgeChunk build() { + return new KnowledgeChunk(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeChunk other = (KnowledgeChunk) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(chunkIndex, other.chunkIndex) && + Objects.equals(documentTitle, other.documentTitle) && + Objects.equals(documentUrl, other.documentUrl) && + Objects.equals(documentNumber, other.documentNumber) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + createdAt, + chunkIndex, + documentTitle, + documentUrl, + documentNumber + ); + } + } + + /** + * Converts a JSON String into a Chunk object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Chunk object represented by the provided JSON + */ + public static Chunk fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Chunk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Chunk object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Chunk object represented by the provided JSON + */ + public static Chunk fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Chunk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Chunk() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/ChunkReader.java b/src/main/java/com/twilio/rest/knowledge/v2/ChunkReader.java new file mode 100644 index 0000000000..af48f887b9 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/ChunkReader.java @@ -0,0 +1,272 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChunkReader extends Reader { + + private String pathKbId; + private String pathKnowledgeId; + private Integer pageSize; + private String pageToken; + + public ChunkReader(final String pathKbId, final String pathKnowledgeId) { + this.pathKbId = pathKbId; + this.pathKnowledgeId = pathKnowledgeId; + } + + public ChunkReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ChunkReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "chunks", + response.getContent(), + Chunk.ListChunkResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v2/KnowledgeBases/{kbId}/Knowledge/{knowledgeId}/Chunks"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + path = + path.replace( + "{" + "knowledgeId" + "}", + this.pathKnowledgeId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "chunks", + response.getContent(), + Chunk.ListChunkResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Chunk read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "chunks", + response.getContent(), + Chunk.ListChunkResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = + "/v2/KnowledgeBases/{kbId}/Knowledge/{knowledgeId}/Chunks"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + path = + path.replace( + "{" + "knowledgeId" + "}", + this.pathKnowledgeId.toString() + ); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = + "/v2/KnowledgeBases/{kbId}/Knowledge/{knowledgeId}/Chunks"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + path = + path.replace( + "{" + "knowledgeId" + "}", + this.pathKnowledgeId.toString() + ); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/Knowledge.java b/src/main/java/com/twilio/rest/knowledge/v2/Knowledge.java new file mode 100644 index 0000000000..bd68abd9e5 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/Knowledge.java @@ -0,0 +1,1577 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Knowledge extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateKnowledgeResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final KnowledgeSourceTypes source; + + @Getter + private final Knowledge.Status status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private CreateKnowledgeResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("source") final KnowledgeSourceTypes source, + @JsonProperty("status") final Knowledge.Status status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.createdAt = createdAt; + this.description = description; + this.id = id; + this.name = name; + this.source = source; + this.status = status; + this.updatedAt = updatedAt; + } + + public static CreateKnowledgeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateKnowledgeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateKnowledgeResponse other = (CreateKnowledgeResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(source, other.source) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + description, + id, + name, + source, + status, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateKnowledgeResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final KnowledgeSourceTypes source; + + @Getter + private final Knowledge.Status status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private UpdateKnowledgeResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("source") final KnowledgeSourceTypes source, + @JsonProperty("status") final Knowledge.Status status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.createdAt = createdAt; + this.description = description; + this.id = id; + this.name = name; + this.source = source; + this.status = status; + this.updatedAt = updatedAt; + } + + public static UpdateKnowledgeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateKnowledgeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateKnowledgeResponse other = (UpdateKnowledgeResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(source, other.source) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + description, + id, + name, + source, + status, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteKnowledgeResponse extends Resource { + + @JsonCreator + private DeleteKnowledgeResponse() {} + + public static DeleteKnowledgeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteKnowledgeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteKnowledgeResponse other = (DeleteKnowledgeResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListKnowledgeResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final KnowledgeSourceTypes source; + + @Getter + private final Knowledge.Status status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListKnowledgeResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("source") final KnowledgeSourceTypes source, + @JsonProperty("status") final Knowledge.Status status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.createdAt = createdAt; + this.description = description; + this.id = id; + this.name = name; + this.source = source; + this.status = status; + this.updatedAt = updatedAt; + } + + public static ListKnowledgeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListKnowledgeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListKnowledgeResponse other = (ListKnowledgeResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(source, other.source) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + description, + id, + name, + source, + status, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchKnowledgeResponse extends Resource { + + @JsonCreator + private PatchKnowledgeResponse() {} + + public static PatchKnowledgeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchKnowledgeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchKnowledgeResponse other = (PatchKnowledgeResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchKnowledgeResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String id; + + @Getter + private final String name; + + @Getter + private final KnowledgeSourceTypes source; + + @Getter + private final Knowledge.Status status; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchKnowledgeResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("source") final KnowledgeSourceTypes source, + @JsonProperty("status") final Knowledge.Status status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.createdAt = createdAt; + this.description = description; + this.id = id; + this.name = name; + this.source = source; + this.status = status; + this.updatedAt = updatedAt; + } + + public static FetchKnowledgeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchKnowledgeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchKnowledgeResponse other = (FetchKnowledgeResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(source, other.source) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + description, + id, + name, + source, + status, + updatedAt + ); + } + } + + public static KnowledgeCreator creator( + final String pathKbId, + final Knowledge.KnowledgeCore knowledgeCore + ) { + return new KnowledgeCreator(pathKbId, knowledgeCore); + } + + public static KnowledgeDeleter deleter( + final String pathKbId, + final String pathKnowledgeId + ) { + return new KnowledgeDeleter(pathKbId, pathKnowledgeId); + } + + public static KnowledgeFetcher fetcher( + final String pathKbId, + final String pathKnowledgeId + ) { + return new KnowledgeFetcher(pathKbId, pathKnowledgeId); + } + + public static KnowledgeReader reader(final String pathKbId) { + return new KnowledgeReader(pathKbId); + } + + public static KnowledgeUpdater updater( + final String pathKbId, + final String pathKnowledgeId + ) { + return new KnowledgeUpdater(pathKbId, pathKnowledgeId); + } + + public enum Status { + SCHEDULED("SCHEDULED"), + QUEUED("QUEUED"), + PROCESSING("PROCESSING"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Type { + TEXT("Text"), + WEB("Web"), + FILE("File"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum CrawlPeriod { + WEEKLY("WEEKLY"), + BIWEEKLY("BIWEEKLY"), + MONTHLY("MONTHLY"), + NEVER("NEVER"); + + private final String value; + + private CrawlPeriod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CrawlPeriod forValue(final String value) { + return Promoter.enumFromString(value, CrawlPeriod.values()); + } + } + + @JsonDeserialize(builder = KnowledgeErrorInstance.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeErrorInstance { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + @Getter + private final Integer code; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("instance") + @Getter + private final String instance; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + @Getter + private final String detail; + + private KnowledgeErrorInstance(Builder builder) { + this.type = builder.type; + this.code = builder.code; + this.instance = builder.instance; + this.detail = builder.detail; + } + + public static Builder builder( + final String type, + final Integer code, + final String instance + ) { + return new Builder(type, code, instance); + } + + public static KnowledgeErrorInstance fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeErrorInstance.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private String type; + + @JsonProperty("code") + private Integer code; + + @JsonProperty("instance") + private String instance; + + @JsonProperty("detail") + private String detail; + + @JsonCreator + public Builder( + @JsonProperty("type") final String type, + @JsonProperty("code") final Integer code, + @JsonProperty("instance") final String instance + ) { + this.type = type; + this.code = code; + this.instance = instance; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + public Builder detail(String detail) { + this.detail = detail; + return this; + } + + public KnowledgeErrorInstance build() { + return new KnowledgeErrorInstance(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeErrorInstance other = (KnowledgeErrorInstance) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(code, other.code) && + Objects.equals(instance, other.instance) && + Objects.equals(detail, other.detail) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, code, instance, detail); + } + } + + @JsonDeserialize(builder = KnowledgeCore.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeCore { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final KnowledgeSourceTypes source; + + private KnowledgeCore(Builder builder) { + this.name = builder.name; + this.description = builder.description; + this.source = builder.source; + } + + public static Builder builder(final String name) { + return new Builder(name); + } + + public static KnowledgeCore fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeCore.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("source") + private KnowledgeSourceTypes source; + + @JsonCreator + public Builder(@JsonProperty("name") final String name) { + this.name = name; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(KnowledgeSourceTypes source) { + this.source = source; + return this; + } + + public KnowledgeCore build() { + return new KnowledgeCore(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeCore other = (KnowledgeCore) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(source, other.source) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, description, source); + } + } + + @JsonDeserialize(builder = KnowledgeMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private KnowledgeMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static KnowledgeMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public KnowledgeMeta build() { + return new KnowledgeMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeMeta other = (KnowledgeMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = KnowledgeSourceTypes.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeSourceTypes { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Knowledge.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + @Getter + private final URI url; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("crawlDepth") + @Getter + private final Integer crawlDepth; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("crawlPeriod") + @Getter + private final Knowledge.CrawlPeriod crawlPeriod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("errors") + @Getter + private final List errors; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fileName") + @Getter + private final String fileName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fileSize") + @Getter + private final Integer fileSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mimeType") + @Getter + private final SupportedFileMimeType mimeType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("importUrl") + @Getter + private final URI importUrl; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("uploadExpiration") + @Getter + private final ZonedDateTime uploadExpiration; + + private KnowledgeSourceTypes(Builder builder) { + this.type = builder.type; + this.content = builder.content; + this.url = builder.url; + this.crawlDepth = builder.crawlDepth; + this.crawlPeriod = builder.crawlPeriod; + this.errors = builder.errors; + this.fileName = builder.fileName; + this.fileSize = builder.fileSize; + this.mimeType = builder.mimeType; + this.importUrl = builder.importUrl; + this.uploadExpiration = builder.uploadExpiration; + } + + public static Builder builder() { + return new Builder(); + } + + public static KnowledgeSourceTypes fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeSourceTypes.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Knowledge.Type type; + + @JsonProperty("content") + private String content; + + @JsonProperty("url") + private URI url; + + @JsonProperty("crawlDepth") + private Integer crawlDepth; + + @JsonProperty("crawlPeriod") + private Knowledge.CrawlPeriod crawlPeriod; + + @JsonProperty("errors") + private List errors; + + @JsonProperty("fileName") + private String fileName; + + @JsonProperty("fileSize") + private Integer fileSize; + + @JsonProperty("mimeType") + private SupportedFileMimeType mimeType; + + @JsonProperty("importUrl") + private URI importUrl; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("uploadExpiration") + private ZonedDateTime uploadExpiration; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Knowledge.Type type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + public Builder content(String content) { + this.content = content; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("url") + public Builder url(URI url) { + this.url = url; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("crawlDepth") + public Builder crawlDepth(Integer crawlDepth) { + this.crawlDepth = crawlDepth; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("crawlPeriod") + public Builder crawlPeriod(Knowledge.CrawlPeriod crawlPeriod) { + this.crawlPeriod = crawlPeriod; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("errors") + public Builder errors(List errors) { + this.errors = errors; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fileName") + public Builder fileName(String fileName) { + this.fileName = fileName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fileSize") + public Builder fileSize(Integer fileSize) { + this.fileSize = fileSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mimeType") + public Builder mimeType(SupportedFileMimeType mimeType) { + this.mimeType = mimeType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("importUrl") + public Builder importUrl(URI importUrl) { + this.importUrl = importUrl; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("uploadExpiration") + public Builder uploadExpiration(ZonedDateTime uploadExpiration) { + this.uploadExpiration = uploadExpiration; + return this; + } + + public KnowledgeSourceTypes build() { + return new KnowledgeSourceTypes(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeSourceTypes other = (KnowledgeSourceTypes) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(content, other.content) && + Objects.equals(url, other.url) && + Objects.equals(crawlDepth, other.crawlDepth) && + Objects.equals(crawlPeriod, other.crawlPeriod) && + Objects.equals(errors, other.errors) && + Objects.equals(fileName, other.fileName) && + Objects.equals(fileSize, other.fileSize) && + Objects.equals(mimeType, other.mimeType) && + Objects.equals(importUrl, other.importUrl) && + Objects.equals(uploadExpiration, other.uploadExpiration) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + type, + content, + url, + crawlDepth, + crawlPeriod, + errors, + fileName, + fileSize, + mimeType, + importUrl, + uploadExpiration + ); + } + } + + @JsonDeserialize(builder = SupportedFileMimeType.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SupportedFileMimeType { + + private SupportedFileMimeType(Builder builder) {} + + public static Builder builder() { + return new Builder(); + } + + public static SupportedFileMimeType fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SupportedFileMimeType.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + public SupportedFileMimeType build() { + return new SupportedFileMimeType(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + return 0; + } + } + + @JsonDeserialize(builder = _Knowledge.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class _Knowledge { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final KnowledgeSourceTypes source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final Knowledge.Status status; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + private _Knowledge(Builder builder) { + this.name = builder.name; + this.description = builder.description; + this.source = builder.source; + this.id = builder.id; + this.status = builder.status; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + } + + public static Builder builder( + final String name, + final String id, + final Knowledge.Status status, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt + ) { + return new Builder(name, id, status, createdAt, updatedAt); + } + + public static _Knowledge fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, _Knowledge.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("description") + private String description; + + @JsonProperty("source") + private KnowledgeSourceTypes source; + + @JsonProperty("id") + private String id; + + @JsonProperty("status") + private Knowledge.Status status; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonCreator + public Builder( + @JsonProperty("name") final String name, + @JsonProperty("id") final String id, + @JsonProperty("status") final Knowledge.Status status, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.name = name; + this.id = id; + this.status = status; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(KnowledgeSourceTypes source) { + this.source = source; + return this; + } + + public _Knowledge build() { + return new _Knowledge(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + _Knowledge other = (_Knowledge) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(description, other.description) && + Objects.equals(source, other.source) && + Objects.equals(id, other.id) && + Objects.equals(status, other.status) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + name, + description, + source, + id, + status, + createdAt, + updatedAt + ); + } + } + + @JsonDeserialize(builder = KnowledgeErrorGroup.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeErrorGroup { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("instances") + @Getter + private final List instances; + + private KnowledgeErrorGroup(Builder builder) { + this.title = builder.title; + this.instances = builder.instances; + } + + public static Builder builder( + final String title, + final List instances + ) { + return new Builder(title, instances); + } + + public static KnowledgeErrorGroup fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeErrorGroup.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("title") + private String title; + + @JsonProperty("instances") + private List instances; + + @JsonCreator + public Builder( + @JsonProperty("title") final String title, + @JsonProperty("instances") final List< + KnowledgeErrorInstance + > instances + ) { + this.title = title; + this.instances = instances; + } + + public KnowledgeErrorGroup build() { + return new KnowledgeErrorGroup(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeErrorGroup other = (KnowledgeErrorGroup) o; + return ( + Objects.equals(title, other.title) && + Objects.equals(instances, other.instances) + ); + } + + @Override + public int hashCode() { + return Objects.hash(title, instances); + } + } + + /** + * Converts a JSON String into a Knowledge object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Knowledge object represented by the provided JSON + */ + public static Knowledge fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Knowledge.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Knowledge object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Knowledge object represented by the provided JSON + */ + public static Knowledge fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Knowledge.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Knowledge() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasis.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasis.java new file mode 100644 index 0000000000..d8773af716 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasis.java @@ -0,0 +1,1057 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class KnowledgeBasis extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateKnowledgeBasisResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private CreateKnowledgeBasisResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static CreateKnowledgeBasisResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateKnowledgeBasisResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateKnowledgeBasisResponse other = + (CreateKnowledgeBasisResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateKnowledgeBasisResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private UpdateKnowledgeBasisResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static UpdateKnowledgeBasisResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateKnowledgeBasisResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateKnowledgeBasisResponse other = + (UpdateKnowledgeBasisResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteKnowledgeBasisResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private DeleteKnowledgeBasisResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static DeleteKnowledgeBasisResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteKnowledgeBasisResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteKnowledgeBasisResponse other = + (DeleteKnowledgeBasisResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListKnowledgeBasisResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final KnowledgeBasis.Status status; + + @Getter + private final ZonedDateTime updatedAt; + + @Getter + private final Integer version; + + @JsonCreator + private ListKnowledgeBasisResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("status") final KnowledgeBasis.Status status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("version") final Integer version + ) { + this.createdAt = createdAt; + this.description = description; + this.displayName = displayName; + this.id = id; + this.status = status; + this.updatedAt = updatedAt; + this.version = version; + } + + public static ListKnowledgeBasisResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListKnowledgeBasisResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListKnowledgeBasisResponse other = (ListKnowledgeBasisResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + description, + displayName, + id, + status, + updatedAt, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchKnowledgeBasisResponse extends Resource { + + @JsonCreator + private PatchKnowledgeBasisResponse() {} + + public static PatchKnowledgeBasisResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchKnowledgeBasisResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchKnowledgeBasisResponse other = (PatchKnowledgeBasisResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchKnowledgeBasisResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final KnowledgeBasis.Status status; + + @Getter + private final ZonedDateTime updatedAt; + + @Getter + private final Integer version; + + @JsonCreator + private FetchKnowledgeBasisResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("status") final KnowledgeBasis.Status status, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("version") final Integer version + ) { + this.createdAt = createdAt; + this.description = description; + this.displayName = displayName; + this.id = id; + this.status = status; + this.updatedAt = updatedAt; + this.version = version; + } + + public static FetchKnowledgeBasisResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchKnowledgeBasisResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchKnowledgeBasisResponse other = (FetchKnowledgeBasisResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(status, other.status) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + description, + displayName, + id, + status, + updatedAt, + version + ); + } + } + + public static KnowledgeBasisCreator creator( + final KnowledgeBasis.KnowledgeBaseCore knowledgeBaseCore + ) { + return new KnowledgeBasisCreator(knowledgeBaseCore); + } + + public static KnowledgeBasisDeleter deleter(final String pathKbId) { + return new KnowledgeBasisDeleter(pathKbId); + } + + public static KnowledgeBasisFetcher fetcher(final String pathKbId) { + return new KnowledgeBasisFetcher(pathKbId); + } + + public static KnowledgeBasisReader reader() { + return new KnowledgeBasisReader(); + } + + public static KnowledgeBasisUpdater updater( + final String pathKbId, + final KnowledgeBasis.UpdateKnowledgeBaseRequest updateKnowledgeBaseRequest + ) { + return new KnowledgeBasisUpdater(pathKbId, updateKnowledgeBaseRequest); + } + + public enum Status { + QUEUED("QUEUED"), + PROVISIONING("PROVISIONING"), + ACTIVE("ACTIVE"), + FAILED("FAILED"), + DELETING("DELETING"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum OrderBy { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private OrderBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderBy forValue(final String value) { + return Promoter.enumFromString(value, OrderBy.values()); + } + } + + @JsonDeserialize(builder = Meta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Meta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private Meta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static Meta fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Meta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public Meta build() { + return new Meta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Meta other = (Meta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = UpdateKnowledgeBaseRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateKnowledgeBaseRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + private UpdateKnowledgeBaseRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + } + + public static Builder builder() { + return new Builder(); + } + + public static UpdateKnowledgeBaseRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateKnowledgeBaseRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public UpdateKnowledgeBaseRequest build() { + return new UpdateKnowledgeBaseRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateKnowledgeBaseRequest other = (UpdateKnowledgeBaseRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description); + } + } + + @JsonDeserialize(builder = KnowledgeBase.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeBase { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final KnowledgeBasis.Status status; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + private KnowledgeBase(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.id = builder.id; + this.status = builder.status; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.version = builder.version; + } + + public static Builder builder( + final String displayName, + final String id, + final KnowledgeBasis.Status status, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt, + final Integer version + ) { + return new Builder( + displayName, + id, + status, + createdAt, + updatedAt, + version + ); + } + + public static KnowledgeBase fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeBase.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("id") + private String id; + + @JsonProperty("status") + private KnowledgeBasis.Status status; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonProperty("version") + private Integer version; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("status") final KnowledgeBasis.Status status, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("version") final Integer version + ) { + this.displayName = displayName; + this.id = id; + this.status = status; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.version = version; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public KnowledgeBase build() { + return new KnowledgeBase(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeBase other = (KnowledgeBase) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(id, other.id) && + Objects.equals(status, other.status) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + displayName, + description, + id, + status, + createdAt, + updatedAt, + version + ); + } + } + + @JsonDeserialize(builder = KnowledgeBaseCore.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeBaseCore { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + private KnowledgeBaseCore(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + } + + public static Builder builder(final String displayName) { + return new Builder(displayName); + } + + public static KnowledgeBaseCore fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeBaseCore.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName + ) { + this.displayName = displayName; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public KnowledgeBaseCore build() { + return new KnowledgeBaseCore(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeBaseCore other = (KnowledgeBaseCore) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description); + } + } + + /** + * Converts a JSON String into a KnowledgeBasis object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return KnowledgeBasis object represented by the provided JSON + */ + public static KnowledgeBasis fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, KnowledgeBasis.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a KnowledgeBasis object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return KnowledgeBasis object represented by the provided JSON + */ + public static KnowledgeBasis fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, KnowledgeBasis.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private KnowledgeBasis() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisCreator.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisCreator.java new file mode 100644 index 0000000000..a649ee62c8 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisCreator.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeBasisCreator + extends Creator { + + private KnowledgeBasis.KnowledgeBaseCore knowledgeBaseCore; + + public KnowledgeBasisCreator( + final KnowledgeBasis.KnowledgeBaseCore knowledgeBaseCore + ) { + this.knowledgeBaseCore = knowledgeBaseCore; + } + + public KnowledgeBasisCreator setKnowledgeBaseCore( + final KnowledgeBasis.KnowledgeBaseCore knowledgeBaseCore + ) { + this.knowledgeBaseCore = knowledgeBaseCore; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/KnowledgeBases"; + + Request request = new Request( + HttpMethod.POST, + Domains.KNOWLEDGE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "KnowledgeBasis creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public KnowledgeBasis.CreateKnowledgeBasisResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return KnowledgeBasis.CreateKnowledgeBasisResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + KnowledgeBasis.CreateKnowledgeBasisResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + KnowledgeBasis.CreateKnowledgeBasisResponse content = + KnowledgeBasis.CreateKnowledgeBasisResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (knowledgeBaseCore != null) { + request.setBody( + KnowledgeBasis.toJson(knowledgeBaseCore, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisDeleter.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisDeleter.java new file mode 100644 index 0000000000..fa3cf8b6ad --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisDeleter.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class KnowledgeBasisDeleter + extends ResourceDeleter< + KnowledgeBasis, + KnowledgeBasis.DeleteKnowledgeBasisResponse + > { + + private String pathKbId; + + public KnowledgeBasisDeleter(final String pathKbId) { + this.pathKbId = pathKbId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/KnowledgeBases/{kbId}"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.KNOWLEDGE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "KnowledgeBasis delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public KnowledgeBasis.DeleteKnowledgeBasisResponse delete( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return KnowledgeBasis.DeleteKnowledgeBasisResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + KnowledgeBasis.DeleteKnowledgeBasisResponse + > deleteWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + KnowledgeBasis.DeleteKnowledgeBasisResponse content = + KnowledgeBasis.DeleteKnowledgeBasisResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisFetcher.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisFetcher.java new file mode 100644 index 0000000000..ecc7ca9273 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeBasisFetcher + extends Fetcher { + + private String pathKbId; + + public KnowledgeBasisFetcher(final String pathKbId) { + this.pathKbId = pathKbId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/KnowledgeBases/{kbId}"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "KnowledgeBasis fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public KnowledgeBasis.FetchKnowledgeBasisResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return KnowledgeBasis.FetchKnowledgeBasisResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + KnowledgeBasis.FetchKnowledgeBasisResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + KnowledgeBasis.FetchKnowledgeBasisResponse content = + KnowledgeBasis.FetchKnowledgeBasisResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisReader.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisReader.java new file mode 100644 index 0000000000..e9f6794624 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisReader.java @@ -0,0 +1,258 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeBasisReader + extends Reader { + + private Integer pageSize; + private String pageToken; + private KnowledgeBasis.OrderBy orderBy; + + public KnowledgeBasisReader() {} + + public KnowledgeBasisReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public KnowledgeBasisReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public KnowledgeBasisReader setOrderBy( + final KnowledgeBasis.OrderBy orderBy + ) { + this.orderBy = orderBy; + return this; + } + + public ResourceSetResponse< + KnowledgeBasis.ListKnowledgeBasisResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "knowledgeBases", + response.getContent(), + KnowledgeBasis.ListKnowledgeBasisResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/KnowledgeBases"; + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "knowledgeBases", + response.getContent(), + KnowledgeBasis.ListKnowledgeBasisResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "KnowledgeBasis read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "knowledgeBases", + response.getContent(), + KnowledgeBasis.ListKnowledgeBasisResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/ControlPlane/KnowledgeBases"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/ControlPlane/KnowledgeBases"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisUpdater.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisUpdater.java new file mode 100644 index 0000000000..f4f2faadb3 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeBasisUpdater.java @@ -0,0 +1,145 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeBasisUpdater + extends Updater { + + private String pathKbId; + private String ifMatch; + private KnowledgeBasis.UpdateKnowledgeBaseRequest updateKnowledgeBaseRequest; + + public KnowledgeBasisUpdater( + final String pathKbId, + final KnowledgeBasis.UpdateKnowledgeBaseRequest updateKnowledgeBaseRequest + ) { + this.pathKbId = pathKbId; + this.updateKnowledgeBaseRequest = updateKnowledgeBaseRequest; + } + + public KnowledgeBasisUpdater setUpdateKnowledgeBaseRequest( + final KnowledgeBasis.UpdateKnowledgeBaseRequest updateKnowledgeBaseRequest + ) { + this.updateKnowledgeBaseRequest = updateKnowledgeBaseRequest; + return this; + } + + public KnowledgeBasisUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/KnowledgeBases/{kbId}"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + + Request request = new Request( + HttpMethod.PATCH, + Domains.KNOWLEDGE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "KnowledgeBasis update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public KnowledgeBasis.UpdateKnowledgeBasisResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return KnowledgeBasis.UpdateKnowledgeBasisResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + KnowledgeBasis.UpdateKnowledgeBasisResponse + > updateWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + KnowledgeBasis.UpdateKnowledgeBasisResponse content = + KnowledgeBasis.UpdateKnowledgeBasisResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (updateKnowledgeBaseRequest != null) { + request.setBody( + KnowledgeBasis.toJson(updateKnowledgeBaseRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeCreator.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeCreator.java new file mode 100644 index 0000000000..daa2c76c92 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeCreator.java @@ -0,0 +1,123 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeCreator + extends Creator { + + private String pathKbId; + private Knowledge.KnowledgeCore knowledgeCore; + + public KnowledgeCreator( + final String pathKbId, + final Knowledge.KnowledgeCore knowledgeCore + ) { + this.pathKbId = pathKbId; + this.knowledgeCore = knowledgeCore; + } + + public KnowledgeCreator setKnowledgeCore( + final Knowledge.KnowledgeCore knowledgeCore + ) { + this.knowledgeCore = knowledgeCore; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/KnowledgeBases/{kbId}/Knowledge"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.KNOWLEDGE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Knowledge.CreateKnowledgeResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Knowledge.CreateKnowledgeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Knowledge.CreateKnowledgeResponse content = + Knowledge.CreateKnowledgeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (knowledgeCore != null) { + request.setBody(Knowledge.toJson(knowledgeCore, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeDeleter.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeDeleter.java new file mode 100644 index 0000000000..ce100007c2 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class KnowledgeDeleter extends Deleter { + + private String pathKbId; + private String pathKnowledgeId; + + public KnowledgeDeleter( + final String pathKbId, + final String pathKnowledgeId + ) { + this.pathKbId = pathKbId; + this.pathKnowledgeId = pathKnowledgeId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/KnowledgeBases/{kbId}/Knowledge/{knowledgeId}"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + path = + path.replace( + "{" + "knowledgeId" + "}", + this.pathKnowledgeId.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.KNOWLEDGE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeFetcher.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeFetcher.java new file mode 100644 index 0000000000..088e3e2d65 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeFetcher.java @@ -0,0 +1,110 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeFetcher + extends Fetcher { + + private String pathKbId; + private String pathKnowledgeId; + + public KnowledgeFetcher( + final String pathKbId, + final String pathKnowledgeId + ) { + this.pathKbId = pathKbId; + this.pathKnowledgeId = pathKnowledgeId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/KnowledgeBases/{kbId}/Knowledge/{knowledgeId}"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + path = + path.replace( + "{" + "knowledgeId" + "}", + this.pathKnowledgeId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Knowledge.FetchKnowledgeResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Knowledge.FetchKnowledgeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Knowledge.FetchKnowledgeResponse content = + Knowledge.FetchKnowledgeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeReader.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeReader.java new file mode 100644 index 0000000000..1482f5f401 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeReader.java @@ -0,0 +1,259 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeReader extends Reader { + + private String pathKbId; + private Integer page; + private Integer pageSize; + private String pageToken; + + public KnowledgeReader(final String pathKbId) { + this.pathKbId = pathKbId; + } + + public KnowledgeReader setPage(final Integer page) { + this.page = page; + return this; + } + + public KnowledgeReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public KnowledgeReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ResourceSetResponse< + Knowledge.ListKnowledgeResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "knowledge", + response.getContent(), + Knowledge.ListKnowledgeResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/KnowledgeBases/{kbId}/Knowledge"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "knowledge", + response.getContent(), + Knowledge.ListKnowledgeResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Knowledge read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "knowledge", + response.getContent(), + Knowledge.ListKnowledgeResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/KnowledgeBases/{kbId}/Knowledge"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v2/KnowledgeBases/{kbId}/Knowledge"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (page != null) { + Serializer.toString(request, "page", page, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeUpdater.java b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeUpdater.java new file mode 100644 index 0000000000..79573e8fab --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/KnowledgeUpdater.java @@ -0,0 +1,149 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class KnowledgeUpdater + extends Updater { + + private String pathKbId; + private String pathKnowledgeId; + private Boolean refresh; + private Knowledge.KnowledgeCore knowledgeCore; + + public KnowledgeUpdater( + final String pathKbId, + final String pathKnowledgeId + ) { + this.pathKbId = pathKbId; + this.pathKnowledgeId = pathKnowledgeId; + } + + public KnowledgeUpdater setKnowledgeCore( + final Knowledge.KnowledgeCore knowledgeCore + ) { + this.knowledgeCore = knowledgeCore; + return this; + } + + public KnowledgeUpdater setRefresh(final Boolean refresh) { + this.refresh = refresh; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/KnowledgeBases/{kbId}/Knowledge/{knowledgeId}"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + path = + path.replace( + "{" + "knowledgeId" + "}", + this.pathKnowledgeId.toString() + ); + + Request request = new Request( + HttpMethod.PATCH, + Domains.KNOWLEDGE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addQueryParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Knowledge update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Knowledge.UpdateKnowledgeResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Knowledge.UpdateKnowledgeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Knowledge.UpdateKnowledgeResponse content = + Knowledge.UpdateKnowledgeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (refresh != null) { + Serializer.toString( + request, + "refresh", + refresh, + ParameterType.QUERY + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (knowledgeCore != null) { + request.setBody(Knowledge.toJson(knowledgeCore, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/Operation.java b/src/main/java/com/twilio/rest/knowledge/v2/Operation.java new file mode 100644 index 0000000000..45d1bced39 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/Operation.java @@ -0,0 +1,678 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Operation extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateOperationResponse extends Resource { + + @JsonCreator + private CreateOperationResponse() {} + + public static CreateOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateOperationResponse other = (CreateOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateOperationResponse extends Resource { + + @JsonCreator + private UpdateOperationResponse() {} + + public static UpdateOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateOperationResponse other = (UpdateOperationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteOperationResponse extends Resource { + + @JsonCreator + private DeleteOperationResponse() {} + + public static DeleteOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteOperationResponse other = (DeleteOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListOperationResponse extends Resource { + + @JsonCreator + private ListOperationResponse() {} + + public static ListOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListOperationResponse other = (ListOperationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchOperationResponse extends Resource { + + @JsonCreator + private PatchOperationResponse() {} + + public static PatchOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchOperationResponse other = (PatchOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchOperationResponse extends Resource { + + @Getter + private final ZonedDateTime completedAt; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final OperationStatusError error; + + @Getter + private final String operationId; + + @Getter + private final OperationResultResourceId result; + + @Getter + private final URI resultUrl; + + @Getter + private final Operation.Status status; + + @Getter + private final URI statusUrl; + + @JsonCreator + private FetchOperationResponse( + @JsonProperty("completedAt") final ZonedDateTime completedAt, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("error") final OperationStatusError error, + @JsonProperty("operationId") final String operationId, + @JsonProperty("result") final OperationResultResourceId result, + @JsonProperty("resultUrl") final URI resultUrl, + @JsonProperty("status") final Operation.Status status, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.completedAt = completedAt; + this.createdAt = createdAt; + this.error = error; + this.operationId = operationId; + this.result = result; + this.resultUrl = resultUrl; + this.status = status; + this.statusUrl = statusUrl; + } + + public static FetchOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchOperationResponse other = (FetchOperationResponse) o; + return ( + Objects.equals(completedAt, other.completedAt) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(error, other.error) && + Objects.equals(operationId, other.operationId) && + Objects.equals(result, other.result) && + Objects.equals(resultUrl, other.resultUrl) && + Objects.equals(status, other.status) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + completedAt, + createdAt, + error, + operationId, + result, + resultUrl, + status, + statusUrl + ); + } + } + + public static OperationFetcher fetcher(final String pathOperationId) { + return new OperationFetcher(pathOperationId); + } + + public enum Status { + PENDING("PENDING"), + RUNNING("RUNNING"), + CANCELLED("CANCELLED"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Type { + RESOURCE_ID("RESOURCE_ID"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + @JsonDeserialize(builder = OperationResultResourceId.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperationResultResourceId { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Operation.Type type; + + private OperationResultResourceId(Builder builder) { + this.id = builder.id; + this.type = builder.type; + } + + public static Builder builder( + final String id, + final Operation.Type type + ) { + return new Builder(id, type); + } + + public static OperationResultResourceId fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + OperationResultResourceId.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("type") + private Operation.Type type; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("type") final Operation.Type type + ) { + this.id = id; + this.type = type; + } + + public OperationResultResourceId build() { + return new OperationResultResourceId(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperationResultResourceId other = (OperationResultResourceId) o; + return ( + Objects.equals(id, other.id) && Objects.equals(type, other.type) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, type); + } + } + + @JsonDeserialize(builder = OperationStatusError.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperationStatusError { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final URI type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + @Getter + private final Integer code; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + @Getter + private final String detail; + + private OperationStatusError(Builder builder) { + this.type = builder.type; + this.title = builder.title; + this.code = builder.code; + this.detail = builder.detail; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperationStatusError fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperationStatusError.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private URI type; + + @JsonProperty("title") + private String title; + + @JsonProperty("code") + private Integer code; + + @JsonProperty("detail") + private String detail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(URI type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + public Builder title(String title) { + this.title = title; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + public Builder code(Integer code) { + this.code = code; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + public Builder detail(String detail) { + this.detail = detail; + return this; + } + + public OperationStatusError build() { + return new OperationStatusError(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperationStatusError other = (OperationStatusError) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(title, other.title) && + Objects.equals(code, other.code) && + Objects.equals(detail, other.detail) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, title, code, detail); + } + } + + /** + * Converts a JSON String into a Operation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Operation object represented by the provided JSON + */ + public static Operation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Operation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Operation object represented by the provided JSON + */ + public static Operation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Operation() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/OperationFetcher.java b/src/main/java/com/twilio/rest/knowledge/v2/OperationFetcher.java new file mode 100644 index 0000000000..29412a7ac5 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/OperationFetcher.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperationFetcher + extends Fetcher { + + private String pathOperationId; + + public OperationFetcher(final String pathOperationId) { + this.pathOperationId = pathOperationId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ControlPlane/Operations/{operationId}"; + + path = + path.replace( + "{" + "operationId" + "}", + this.pathOperationId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.KNOWLEDGE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Operation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Operation.FetchOperationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Operation.FetchOperationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Operation.FetchOperationResponse content = + Operation.FetchOperationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/Search.java b/src/main/java/com/twilio/rest/knowledge/v2/Search.java new file mode 100644 index 0000000000..a24b8177ed --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/Search.java @@ -0,0 +1,662 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Search extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateSearchResponse extends Resource { + + @Getter + private final List chunks; + + @JsonCreator + private CreateSearchResponse( + @JsonProperty("chunks") final List chunks + ) { + this.chunks = chunks; + } + + public static CreateSearchResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateSearchResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateSearchResponse other = (CreateSearchResponse) o; + return Objects.equals(chunks, other.chunks); + } + + @Override + public int hashCode() { + return Objects.hash(chunks); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateSearchResponse extends Resource { + + @JsonCreator + private UpdateSearchResponse() {} + + public static UpdateSearchResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateSearchResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateSearchResponse other = (UpdateSearchResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteSearchResponse extends Resource { + + @JsonCreator + private DeleteSearchResponse() {} + + public static DeleteSearchResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteSearchResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteSearchResponse other = (DeleteSearchResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListSearchResponse extends Resource { + + @JsonCreator + private ListSearchResponse() {} + + public static ListSearchResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListSearchResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListSearchResponse other = (ListSearchResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchSearchResponse extends Resource { + + @JsonCreator + private PatchSearchResponse() {} + + public static PatchSearchResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchSearchResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchSearchResponse other = (PatchSearchResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchSearchResponse extends Resource { + + @JsonCreator + private FetchSearchResponse() {} + + public static FetchSearchResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchSearchResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchSearchResponse other = (FetchSearchResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + public static SearchCreator creator(final String pathKbId) { + return new SearchCreator(pathKbId); + } + + @JsonDeserialize(builder = KnowledgeSearch.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeSearch { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("query") + @Getter + private final String query; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("top") + @Getter + private final Integer top; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledgeIds") + @Getter + private final List knowledgeIds; + + private KnowledgeSearch(Builder builder) { + this.query = builder.query; + this.top = builder.top; + this.knowledgeIds = builder.knowledgeIds; + } + + public static Builder builder(final String query, final Integer top) { + return new Builder(query, top); + } + + public static KnowledgeSearch fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeSearch.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("query") + private String query; + + @JsonProperty("top") + private Integer top; + + @JsonProperty("knowledgeIds") + private List knowledgeIds; + + @JsonCreator + public Builder( + @JsonProperty("query") final String query, + @JsonProperty("top") final Integer top + ) { + this.query = query; + this.top = top; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledgeIds") + public Builder knowledgeIds(List knowledgeIds) { + this.knowledgeIds = knowledgeIds; + return this; + } + + public KnowledgeSearch build() { + return new KnowledgeSearch(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeSearch other = (KnowledgeSearch) o; + return ( + Objects.equals(query, other.query) && + Objects.equals(top, other.top) && + Objects.equals(knowledgeIds, other.knowledgeIds) + ); + } + + @Override + public int hashCode() { + return Objects.hash(query, top, knowledgeIds); + } + } + + @JsonDeserialize(builder = KnowledgeChunkResult.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class KnowledgeChunkResult { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("chunkIndex") + @Getter + private final Integer chunkIndex; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentTitle") + @Getter + private final String documentTitle; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentUrl") + @Getter + private final URI documentUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentNumber") + @Getter + private final Integer documentNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("score") + @Getter + private final Float score; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledgeId") + @Getter + private final String knowledgeId; + + private KnowledgeChunkResult(Builder builder) { + this.content = builder.content; + this.createdAt = builder.createdAt; + this.chunkIndex = builder.chunkIndex; + this.documentTitle = builder.documentTitle; + this.documentUrl = builder.documentUrl; + this.documentNumber = builder.documentNumber; + this.score = builder.score; + this.knowledgeId = builder.knowledgeId; + } + + public static Builder builder() { + return new Builder(); + } + + public static KnowledgeChunkResult fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, KnowledgeChunkResult.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonProperty("chunkIndex") + private Integer chunkIndex; + + @JsonProperty("documentTitle") + private String documentTitle; + + @JsonProperty("documentUrl") + private URI documentUrl; + + @JsonProperty("documentNumber") + private Integer documentNumber; + + @JsonProperty("score") + private Float score; + + @JsonProperty("knowledgeId") + private String knowledgeId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + public Builder content(String content) { + this.content = content; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("chunkIndex") + public Builder chunkIndex(Integer chunkIndex) { + this.chunkIndex = chunkIndex; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentTitle") + public Builder documentTitle(String documentTitle) { + this.documentTitle = documentTitle; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentUrl") + public Builder documentUrl(URI documentUrl) { + this.documentUrl = documentUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documentNumber") + public Builder documentNumber(Integer documentNumber) { + this.documentNumber = documentNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("score") + public Builder score(Float score) { + this.score = score; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("knowledgeId") + public Builder knowledgeId(String knowledgeId) { + this.knowledgeId = knowledgeId; + return this; + } + + public KnowledgeChunkResult build() { + return new KnowledgeChunkResult(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + KnowledgeChunkResult other = (KnowledgeChunkResult) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(chunkIndex, other.chunkIndex) && + Objects.equals(documentTitle, other.documentTitle) && + Objects.equals(documentUrl, other.documentUrl) && + Objects.equals(documentNumber, other.documentNumber) && + Objects.equals(score, other.score) && + Objects.equals(knowledgeId, other.knowledgeId) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + createdAt, + chunkIndex, + documentTitle, + documentUrl, + documentNumber, + score, + knowledgeId + ); + } + } + + /** + * Converts a JSON String into a Search object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Search object represented by the provided JSON + */ + public static Search fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Search.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Search object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Search object represented by the provided JSON + */ + public static Search fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Search.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Search() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/knowledge/v2/SearchCreator.java b/src/main/java/com/twilio/rest/knowledge/v2/SearchCreator.java new file mode 100644 index 0000000000..6b398fe2b0 --- /dev/null +++ b/src/main/java/com/twilio/rest/knowledge/v2/SearchCreator.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Knowledge API + * APIs for managing knowledge bases and knowledge content for AI-powered applications. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.knowledge.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SearchCreator extends Creator { + + private String pathKbId; + private Search.KnowledgeSearch knowledgeSearch; + + public SearchCreator(final String pathKbId) { + this.pathKbId = pathKbId; + } + + public SearchCreator setKnowledgeSearch( + final Search.KnowledgeSearch knowledgeSearch + ) { + this.knowledgeSearch = knowledgeSearch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/KnowledgeBases/{kbId}/Search"; + + path = path.replace("{" + "kbId" + "}", this.pathKbId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.KNOWLEDGE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Search creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Search.CreateSearchResponse create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Search.CreateSearchResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Search.CreateSearchResponse content = + Search.CreateSearchResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (knowledgeSearch != null) { + request.setBody(Search.toJson(knowledgeSearch, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v1/PhoneNumber.java b/src/main/java/com/twilio/rest/lookups/v1/PhoneNumber.java index 1036930927..1c588c16e9 100644 --- a/src/main/java/com/twilio/rest/lookups/v1/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/lookups/v1/PhoneNumber.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.lookups.v1; @@ -11,76 +18,42 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.Promoter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class PhoneNumber extends Resource { - private static final long serialVersionUID = 198564396301377L; - - public enum Type { - LANDLINE("landline"), - MOBILE("mobile"), - VOIP("voip"); - - private final String value; - - private Type(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - /** - * Generate a Type from a string. - * @param value string value - * @return generated Type - */ - @JsonCreator - public static Type forValue(final String value) { - return Promoter.enumFromString(value, Type.values()); - } - } - - /** - * Create a PhoneNumberFetcher to execute fetch. - * - * @param pathPhoneNumber The phone_number - * @return PhoneNumberFetcher capable of executing the fetch - */ - public static PhoneNumberFetcher fetcher(final com.twilio.type.PhoneNumber pathPhoneNumber) { + public static PhoneNumberFetcher fetcher(final String pathPhoneNumber) { return new PhoneNumberFetcher(pathPhoneNumber); } /** - * Converts a JSON String into a PhoneNumber object using the provided - * ObjectMapper. - * + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return PhoneNumber object represented by the provided JSON */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -94,12 +67,15 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a PhoneNumber object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return PhoneNumber object represented by the provided JSON */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -110,103 +86,60 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob } } - private final Map callerName; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object addOns; + + @Getter + private final Object callerName; + + @Getter + private final Object carrier; + + @Getter private final String countryCode; - private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String nationalFormat; - private final Map carrier; - private final Map addOns; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final URI url; @JsonCreator - private PhoneNumber(@JsonProperty("caller_name") - final Map callerName, - @JsonProperty("country_code") - final String countryCode, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("national_format") - final String nationalFormat, - @JsonProperty("carrier") - final Map carrier, - @JsonProperty("add_ons") - final Map addOns, - @JsonProperty("url") - final URI url) { + private PhoneNumber( + @JsonProperty("add_ons") final Object addOns, + @JsonProperty("caller_name") final Object callerName, + @JsonProperty("carrier") final Object carrier, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("national_format") final String nationalFormat, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("url") final URI url + ) { + this.addOns = addOns; this.callerName = callerName; + this.carrier = carrier; this.countryCode = countryCode; - this.phoneNumber = phoneNumber; this.nationalFormat = nationalFormat; - this.carrier = carrier; - this.addOns = addOns; + this.phoneNumber = phoneNumber; this.url = url; } - /** - * Returns The String indicating the name of the owner of the phone number.. - * - * @return String indicating the name of the owner of the phone number. - */ - public final Map getCallerName() { - return this.callerName; - } - - /** - * Returns The The ISO country code for the phone number.. - * - * @return The ISO country code for the phone number. - */ - public final String getCountryCode() { - return this.countryCode; - } - - /** - * Returns The The phone number, in E.. - * - * @return The phone number, in E. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - - /** - * Returns The The phone number, in national format.. - * - * @return The phone number, in national format. - */ - public final String getNationalFormat() { - return this.nationalFormat; - } - - /** - * Returns The The carrier. - * - * @return The carrier - */ - public final Map getCarrier() { - return this.carrier; - } - - /** - * Returns The Results of any Add-ons you have specified using the AddOn - * parameter in the request, as a JSON dictionary.. - * - * @return Results of any Add-ons you have specified using the AddOn parameter - * in the request, as a JSON dictionary. - */ - public final Map getAddOns() { - return this.addOns; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -218,37 +151,27 @@ public boolean equals(final Object o) { } PhoneNumber other = (PhoneNumber) o; - - return Objects.equals(callerName, other.callerName) && - Objects.equals(countryCode, other.countryCode) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(nationalFormat, other.nationalFormat) && - Objects.equals(carrier, other.carrier) && - Objects.equals(addOns, other.addOns) && - Objects.equals(url, other.url); + return ( + Objects.equals(addOns, other.addOns) && + Objects.equals(callerName, other.callerName) && + Objects.equals(carrier, other.carrier) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(nationalFormat, other.nationalFormat) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(callerName, - countryCode, - phoneNumber, - nationalFormat, - carrier, - addOns, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("callerName", callerName) - .add("countryCode", countryCode) - .add("phoneNumber", phoneNumber) - .add("nationalFormat", nationalFormat) - .add("carrier", carrier) - .add("addOns", addOns) - .add("url", url) - .toString(); + return Objects.hash( + addOns, + callerName, + carrier, + countryCode, + nationalFormat, + phoneNumber, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/lookups/v1/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/lookups/v1/PhoneNumberFetcher.java index c368291111..b8a1c73f98 100644 --- a/src/main/java/com/twilio/rest/lookups/v1/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/lookups/v1/PhoneNumberFetcher.java @@ -1,15 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.lookups.v1; import com.twilio.base.Fetcher; -import com.twilio.converter.PrefixedCollapsibleMap; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -18,186 +27,156 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; import java.util.Map; public class PhoneNumberFetcher extends Fetcher { - private final com.twilio.type.PhoneNumber pathPhoneNumber; + + private String pathPhoneNumber; private String countryCode; private List type; private List addOns; private Map addOnsData; - /** - * Construct a new PhoneNumberFetcher. - * - * @param pathPhoneNumber The phone_number - */ - public PhoneNumberFetcher(final com.twilio.type.PhoneNumber pathPhoneNumber) { + public PhoneNumberFetcher(final String pathPhoneNumber) { this.pathPhoneNumber = pathPhoneNumber; } - /** - * Optional [ISO country code](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) - * of the phone number. This is used to specify the country when the number is - * provided in a national format.. - * - * @param countryCode Optional ISO country code of the phone number. - * @return this - */ public PhoneNumberFetcher setCountryCode(final String countryCode) { this.countryCode = countryCode; return this; } - /** - * Indicates the type of information you would like returned with your request. - * Possible values are `carrier` or `caller-name`. If not specified, the default - * is null. Carrier information costs $0.005 per phone number looked up. - * Caller Name information costs $0.01 per phone number looked up, and is - * currently ONLY available in the US. You can retrieve both types of - * information by including two `Type` arguments or making two separate - * requests.. - * - * @param type Indicates the type of information you would like returned with - * your request. - * @return this - */ public PhoneNumberFetcher setType(final List type) { this.type = type; return this; } - /** - * Indicates the type of information you would like returned with your request. - * Possible values are `carrier` or `caller-name`. If not specified, the default - * is null. Carrier information costs $0.005 per phone number looked up. - * Caller Name information costs $0.01 per phone number looked up, and is - * currently ONLY available in the US. You can retrieve both types of - * information by including two `Type` arguments or making two separate - * requests.. - * - * @param type Indicates the type of information you would like returned with - * your request. - * @return this - */ public PhoneNumberFetcher setType(final String type) { return setType(Promoter.listOfOne(type)); } - /** - * Indicates the particular Add-on you would like to use to get more - * information. Possible values are the *Add-on Unique Names* of Add-ons - * installed on your account. You can specify multiple instances of this - * parameter to invoke different Add-ons. See [Add-ons - * documentation](https://www.twilio.com/docs/api/addons) for information on - * installing Add-ons. Add-on pricing is available in your list of Installed - * Add-ons in the Console.. - * - * @param addOns Indicates the particular Add-on you would like to use to get - * more information. - * @return this - */ public PhoneNumberFetcher setAddOns(final List addOns) { this.addOns = addOns; return this; } - /** - * Indicates the particular Add-on you would like to use to get more - * information. Possible values are the *Add-on Unique Names* of Add-ons - * installed on your account. You can specify multiple instances of this - * parameter to invoke different Add-ons. See [Add-ons - * documentation](https://www.twilio.com/docs/api/addons) for information on - * installing Add-ons. Add-on pricing is available in your list of Installed - * Add-ons in the Console.. - * - * @param addOns Indicates the particular Add-on you would like to use to get - * more information. - * @return this - */ public PhoneNumberFetcher setAddOns(final String addOns) { return setAddOns(Promoter.listOfOne(addOns)); } - /** - * The add_ons_data. - * - * @param addOnsData The add_ons_data - * @return this - */ - public PhoneNumberFetcher setAddOnsData(final Map addOnsData) { + public PhoneNumberFetcher setAddOnsData( + final Map addOnsData + ) { this.addOnsData = addOnsData; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PhoneNumbers/{PhoneNumber}"; + + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.LOOKUPS.toString(), - "/v1/PhoneNumbers/" + this.pathPhoneNumber + "", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public PhoneNumber fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (countryCode != null) { - request.addQueryParam("CountryCode", countryCode); + Serializer.toString( + request, + "CountryCode", + countryCode, + ParameterType.QUERY + ); } if (type != null) { - for (String prop : type) { - request.addQueryParam("Type", prop); + for (String param : type) { + Serializer.toString( + request, + "Type", + param, + ParameterType.QUERY + ); } } if (addOns != null) { - for (String prop : addOns) { - request.addQueryParam("AddOns", prop); + for (String param : addOns) { + Serializer.toString( + request, + "AddOns", + param, + ParameterType.QUERY + ); } } if (addOnsData != null) { - Map params = PrefixedCollapsibleMap.serialize(addOnsData, "AddOns"); - for (Map.Entry entry : params.entrySet()) { - request.addQueryParam(entry.getKey(), entry.getValue()); - } + Serializer.toString( + request, + "AddOnsData", + addOnsData, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/Bucket.java b/src/main/java/com/twilio/rest/lookups/v2/Bucket.java new file mode 100644 index 0000000000..ca59e28a64 --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/Bucket.java @@ -0,0 +1,259 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Bucket extends Resource { + + public static BucketDeleter deleter( + final String pathField, + final String pathBucket + ) { + return new BucketDeleter(pathField, pathBucket); + } + + public static BucketFetcher fetcher( + final String pathField, + final String pathBucket + ) { + return new BucketFetcher(pathField, pathBucket); + } + + public static BucketUpdater updater( + final String pathField, + final String pathBucket + ) { + return new BucketUpdater(pathField, pathBucket); + } + + @JsonDeserialize(builder = RateLimitRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class RateLimitRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("limit") + @Getter + private final Integer limit; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ttl") + @Getter + private final Integer ttl; + + private RateLimitRequest(Builder builder) { + this.limit = builder.limit; + this.ttl = builder.ttl; + } + + public static Builder builder() { + return new Builder(); + } + + public static RateLimitRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, RateLimitRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("limit") + private Integer limit; + + @JsonProperty("ttl") + private Integer ttl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("limit") + public Builder limit(Integer limit) { + this.limit = limit; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ttl") + public Builder ttl(Integer ttl) { + this.ttl = ttl; + return this; + } + + public RateLimitRequest build() { + return new RateLimitRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RateLimitRequest other = (RateLimitRequest) o; + return ( + Objects.equals(limit, other.limit) && + Objects.equals(ttl, other.ttl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(limit, ttl); + } + } + + /** + * Converts a JSON String into a Bucket object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Bucket object represented by the provided JSON + */ + public static Bucket fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Bucket.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Bucket object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Bucket object represented by the provided JSON + */ + public static Bucket fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Bucket.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String bucket; + + @Getter + private final String field; + + @Getter + private final Integer limit; + + @Getter + private final String owner; + + @Getter + private final Integer ttl; + + @JsonCreator + private Bucket( + @JsonProperty("bucket") final String bucket, + @JsonProperty("field") final String field, + @JsonProperty("limit") final Integer limit, + @JsonProperty("owner") final String owner, + @JsonProperty("ttl") final Integer ttl + ) { + this.bucket = bucket; + this.field = field; + this.limit = limit; + this.owner = owner; + this.ttl = ttl; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Bucket other = (Bucket) o; + return ( + Objects.equals(bucket, other.bucket) && + Objects.equals(field, other.field) && + Objects.equals(limit, other.limit) && + Objects.equals(owner, other.owner) && + Objects.equals(ttl, other.ttl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(bucket, field, limit, owner, ttl); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/BucketDeleter.java b/src/main/java/com/twilio/rest/lookups/v2/BucketDeleter.java new file mode 100644 index 0000000000..f08c9cfcd4 --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/BucketDeleter.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class BucketDeleter extends Deleter { + + private String pathField; + private String pathBucket; + + public BucketDeleter(final String pathField, final String pathBucket) { + this.pathField = pathField; + this.pathBucket = pathBucket; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RateLimits/Fields/{Field}/Bucket/{Bucket}"; + + path = path.replace("{" + "Field" + "}", this.pathField.toString()); + path = path.replace("{" + "Bucket" + "}", this.pathBucket.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.LOOKUPS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Bucket delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/BucketFetcher.java b/src/main/java/com/twilio/rest/lookups/v2/BucketFetcher.java new file mode 100644 index 0000000000..7a05df82f4 --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/BucketFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BucketFetcher extends Fetcher { + + private String pathField; + private String pathBucket; + + public BucketFetcher(final String pathField, final String pathBucket) { + this.pathField = pathField; + this.pathBucket = pathBucket; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RateLimits/Fields/{Field}/Bucket/{Bucket}"; + + path = path.replace("{" + "Field" + "}", this.pathField.toString()); + path = path.replace("{" + "Bucket" + "}", this.pathBucket.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.LOOKUPS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Bucket fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Bucket fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Bucket.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Bucket content = Bucket.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/BucketUpdater.java b/src/main/java/com/twilio/rest/lookups/v2/BucketUpdater.java new file mode 100644 index 0000000000..3a880e8eac --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/BucketUpdater.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BucketUpdater extends Updater { + + private String pathField; + private String pathBucket; + private Bucket.RateLimitRequest rateLimitRequest; + + public BucketUpdater(final String pathField, final String pathBucket) { + this.pathField = pathField; + this.pathBucket = pathBucket; + } + + public BucketUpdater setRateLimitRequest( + final Bucket.RateLimitRequest rateLimitRequest + ) { + this.rateLimitRequest = rateLimitRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RateLimits/Fields/{Field}/Bucket/{Bucket}"; + + path = path.replace("{" + "Field" + "}", this.pathField.toString()); + path = path.replace("{" + "Bucket" + "}", this.pathBucket.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.LOOKUPS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Bucket update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Bucket update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Bucket.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Bucket content = Bucket.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (rateLimitRequest != null) { + request.setBody(Bucket.toJson(rateLimitRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/LookupOverride.java b/src/main/java/com/twilio/rest/lookups/v2/LookupOverride.java new file mode 100644 index 0000000000..28fc201f6f --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/LookupOverride.java @@ -0,0 +1,390 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class LookupOverride extends Resource { + + public static LookupOverrideCreator creator( + final String pathField, + final String pathPhoneNumber + ) { + return new LookupOverrideCreator(pathField, pathPhoneNumber); + } + + public static LookupOverrideDeleter deleter( + final String pathField, + final String pathPhoneNumber + ) { + return new LookupOverrideDeleter(pathField, pathPhoneNumber); + } + + public static LookupOverrideFetcher fetcher( + final String pathField, + final String pathPhoneNumber + ) { + return new LookupOverrideFetcher(pathField, pathPhoneNumber); + } + + public static LookupOverrideUpdater updater( + final String pathField, + final String pathPhoneNumber + ) { + return new LookupOverrideUpdater(pathField, pathPhoneNumber); + } + + public enum OverriddenLineType { + MOBILE("mobile"), + LANDLINE("landline"), + TOLL_FREE("tollFree"), + FIXED_VOIP("fixedVoip"), + NON_FIXED_VOIP("nonFixedVoip"), + PERSONAL("personal"), + PREMIUM("premium"), + VOICEMAIL("voicemail"), + SHARED_COST("sharedCost"), + UAN("uan"), + PAGER("pager"), + UNKNOWN("unknown"); + + private final String value; + + private OverriddenLineType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OverriddenLineType forValue(final String value) { + return Promoter.enumFromString(value, OverriddenLineType.values()); + } + } + + public enum LineType { + MOBILE("mobile"), + LANDLINE("landline"), + TOLL_FREE("tollFree"), + FIXED_VOIP("fixedVoip"), + NON_FIXED_VOIP("nonFixedVoip"), + PERSONAL("personal"), + PREMIUM("premium"), + VOICEMAIL("voicemail"), + SHARED_COST("sharedCost"), + UAN("uan"), + PAGER("pager"), + UNKNOWN("unknown"); + + private final String value; + + private LineType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static LineType forValue(final String value) { + return Promoter.enumFromString(value, LineType.values()); + } + } + + public enum OriginalLineType { + MOBILE("mobile"), + LANDLINE("landline"), + TOLL_FREE("tollFree"), + FIXED_VOIP("fixedVoip"), + NON_FIXED_VOIP("nonFixedVoip"), + PERSONAL("personal"), + PREMIUM("premium"), + VOICEMAIL("voicemail"), + SHARED_COST("sharedCost"), + UAN("uan"), + PAGER("pager"), + UNKNOWN("unknown"); + + private final String value; + + private OriginalLineType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OriginalLineType forValue(final String value) { + return Promoter.enumFromString(value, OriginalLineType.values()); + } + } + + @JsonDeserialize(builder = OverridesRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OverridesRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("line_type") + @Getter + private final LookupOverride.LineType lineType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("reason") + @Getter + private final String reason; + + private OverridesRequest(Builder builder) { + this.lineType = builder.lineType; + this.reason = builder.reason; + } + + public static Builder builder() { + return new Builder(); + } + + public static OverridesRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OverridesRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("line_type") + private LookupOverride.LineType lineType; + + @JsonProperty("reason") + private String reason; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("line_type") + public Builder lineType(LookupOverride.LineType lineType) { + this.lineType = lineType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("reason") + public Builder reason(String reason) { + this.reason = reason; + return this; + } + + public OverridesRequest build() { + return new OverridesRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OverridesRequest other = (OverridesRequest) o; + return ( + Objects.equals(lineType, other.lineType) && + Objects.equals(reason, other.reason) + ); + } + + @Override + public int hashCode() { + return Objects.hash(lineType, reason); + } + } + + /** + * Converts a JSON String into a LookupOverride object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return LookupOverride object represented by the provided JSON + */ + public static LookupOverride fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, LookupOverride.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a LookupOverride object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return LookupOverride object represented by the provided JSON + */ + public static LookupOverride fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, LookupOverride.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final LookupOverride.OriginalLineType originalLineType; + + @Getter + private final String overriddenByAccountSid; + + @Getter + private final LookupOverride.OverriddenLineType overriddenLineType; + + @Getter + private final String overrideReason; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime overrideTimestamp; + + @Getter + private final String phoneNumber; + + @JsonCreator + private LookupOverride( + @JsonProperty( + "original_line_type" + ) final LookupOverride.OriginalLineType originalLineType, + @JsonProperty( + "overridden_by_account_sid" + ) final String overriddenByAccountSid, + @JsonProperty( + "overridden_line_type" + ) final LookupOverride.OverriddenLineType overriddenLineType, + @JsonProperty("override_reason") final String overrideReason, + @JsonProperty("override_timestamp") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime overrideTimestamp, + @JsonProperty("phone_number") final String phoneNumber + ) { + this.originalLineType = originalLineType; + this.overriddenByAccountSid = overriddenByAccountSid; + this.overriddenLineType = overriddenLineType; + this.overrideReason = overrideReason; + this.overrideTimestamp = overrideTimestamp; + this.phoneNumber = phoneNumber; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LookupOverride other = (LookupOverride) o; + return ( + Objects.equals(originalLineType, other.originalLineType) && + Objects.equals( + overriddenByAccountSid, + other.overriddenByAccountSid + ) && + Objects.equals(overriddenLineType, other.overriddenLineType) && + Objects.equals(overrideReason, other.overrideReason) && + Objects.equals(overrideTimestamp, other.overrideTimestamp) && + Objects.equals(phoneNumber, other.phoneNumber) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + originalLineType, + overriddenByAccountSid, + overriddenLineType, + overrideReason, + overrideTimestamp, + phoneNumber + ); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideCreator.java b/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideCreator.java new file mode 100644 index 0000000000..445ffe8d5a --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideCreator.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class LookupOverrideCreator extends Creator { + + private String pathField; + private String pathPhoneNumber; + private LookupOverride.OverridesRequest overridesRequest; + + public LookupOverrideCreator( + final String pathField, + final String pathPhoneNumber + ) { + this.pathField = pathField; + this.pathPhoneNumber = pathPhoneNumber; + } + + public LookupOverrideCreator setOverridesRequest( + final LookupOverride.OverridesRequest overridesRequest + ) { + this.overridesRequest = overridesRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/PhoneNumbers/{PhoneNumber}/Overrides/{Field}"; + + path = path.replace("{" + "Field" + "}", this.pathField.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.LOOKUPS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "LookupOverride creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public LookupOverride create(final TwilioRestClient client) { + Response response = makeRequest(client); + return LookupOverride.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + LookupOverride content = LookupOverride.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (overridesRequest != null) { + request.setBody( + LookupOverride.toJson(overridesRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideDeleter.java b/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideDeleter.java new file mode 100644 index 0000000000..2720fc518a --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class LookupOverrideDeleter extends Deleter { + + private String pathField; + private String pathPhoneNumber; + + public LookupOverrideDeleter( + final String pathField, + final String pathPhoneNumber + ) { + this.pathField = pathField; + this.pathPhoneNumber = pathPhoneNumber; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/PhoneNumbers/{PhoneNumber}/Overrides/{Field}"; + + path = path.replace("{" + "Field" + "}", this.pathField.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.LOOKUPS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "LookupOverride delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideFetcher.java b/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideFetcher.java new file mode 100644 index 0000000000..975be329db --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class LookupOverrideFetcher extends Fetcher { + + private String pathField; + private String pathPhoneNumber; + + public LookupOverrideFetcher( + final String pathField, + final String pathPhoneNumber + ) { + this.pathField = pathField; + this.pathPhoneNumber = pathPhoneNumber; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/PhoneNumbers/{PhoneNumber}/Overrides/{Field}"; + + path = path.replace("{" + "Field" + "}", this.pathField.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.LOOKUPS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "LookupOverride fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public LookupOverride fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return LookupOverride.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + LookupOverride content = LookupOverride.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideUpdater.java b/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideUpdater.java new file mode 100644 index 0000000000..3b3a61cd9e --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/LookupOverrideUpdater.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class LookupOverrideUpdater extends Updater { + + private String pathField; + private String pathPhoneNumber; + private LookupOverride.OverridesRequest overridesRequest; + + public LookupOverrideUpdater( + final String pathField, + final String pathPhoneNumber + ) { + this.pathField = pathField; + this.pathPhoneNumber = pathPhoneNumber; + } + + public LookupOverrideUpdater setOverridesRequest( + final LookupOverride.OverridesRequest overridesRequest + ) { + this.overridesRequest = overridesRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/PhoneNumbers/{PhoneNumber}/Overrides/{Field}"; + + path = path.replace("{" + "Field" + "}", this.pathField.toString()); + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.PUT, + Domains.LOOKUPS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "LookupOverride update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public LookupOverride update(final TwilioRestClient client) { + Response response = makeRequest(client); + return LookupOverride.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + LookupOverride content = LookupOverride.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (overridesRequest != null) { + request.setBody( + LookupOverride.toJson(overridesRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/PhoneNumber.java b/src/main/java/com/twilio/rest/lookups/v2/PhoneNumber.java new file mode 100644 index 0000000000..4261f929ba --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/PhoneNumber.java @@ -0,0 +1,1550 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PhoneNumber extends Resource { + + public static PhoneNumberFetcher fetcher(final String pathPhoneNumber) { + return new PhoneNumberFetcher(pathPhoneNumber); + } + + public enum PhoneNumberValidationError { + TOO_SHORT("TOO_SHORT"), + TOO_LONG("TOO_LONG"), + INVALID_BUT_POSSIBLE("INVALID_BUT_POSSIBLE"), + INVALID_COUNTRY_CODE("INVALID_COUNTRY_CODE"), + INVALID_LENGTH("INVALID_LENGTH"), + NOT_A_NUMBER("NOT_A_NUMBER"); + + private final String value; + + private PhoneNumberValidationError(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static PhoneNumberValidationError forValue(final String value) { + return Promoter.enumFromString( + value, + PhoneNumberValidationError.values() + ); + } + } + + public enum ValidationError { + TOO_SHORT("TOO_SHORT"), + TOO_LONG("TOO_LONG"), + INVALID_BUT_POSSIBLE("INVALID_BUT_POSSIBLE"), + INVALID_COUNTRY_CODE("INVALID_COUNTRY_CODE"), + INVALID_LENGTH("INVALID_LENGTH"), + NOT_A_NUMBER("NOT_A_NUMBER"); + + private final String value; + + private ValidationError(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ValidationError forValue(final String value) { + return Promoter.enumFromString(value, ValidationError.values()); + } + } + + @JsonDeserialize(builder = CallForwardingInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallForwardingInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_forwarding_enabled") + @Getter + private final Boolean callForwardingEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private CallForwardingInfo(Builder builder) { + this.callForwardingEnabled = builder.callForwardingEnabled; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallForwardingInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CallForwardingInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("call_forwarding_enabled") + private Boolean callForwardingEnabled; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_forwarding_enabled") + public Builder callForwardingEnabled( + Boolean callForwardingEnabled + ) { + this.callForwardingEnabled = callForwardingEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public CallForwardingInfo build() { + return new CallForwardingInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallForwardingInfo other = (CallForwardingInfo) o; + return ( + Objects.equals( + callForwardingEnabled, + other.callForwardingEnabled + ) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash(callForwardingEnabled, errorCode); + } + } + + @JsonDeserialize(builder = SmsPumpingRiskInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SmsPumpingRiskInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_risk_category") + @Getter + private final String carrierRiskCategory; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked") + @Getter + private final Boolean numberBlocked; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked_date") + @Getter + private final ZonedDateTime numberBlockedDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked_last_3_months") + @Getter + private final Boolean numberBlockedLast3Months; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_pumping_risk_score") + @Getter + private final Integer smsPumpingRiskScore; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private SmsPumpingRiskInfo(Builder builder) { + this.carrierRiskCategory = builder.carrierRiskCategory; + this.numberBlocked = builder.numberBlocked; + this.numberBlockedDate = builder.numberBlockedDate; + this.numberBlockedLast3Months = builder.numberBlockedLast3Months; + this.smsPumpingRiskScore = builder.smsPumpingRiskScore; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static SmsPumpingRiskInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SmsPumpingRiskInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("carrier_risk_category") + private String carrierRiskCategory; + + @JsonProperty("number_blocked") + private Boolean numberBlocked; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("number_blocked_date") + private ZonedDateTime numberBlockedDate; + + @JsonProperty("number_blocked_last_3_months") + private Boolean numberBlockedLast3Months; + + @JsonProperty("sms_pumping_risk_score") + private Integer smsPumpingRiskScore; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_risk_category") + public Builder carrierRiskCategory(String carrierRiskCategory) { + this.carrierRiskCategory = carrierRiskCategory; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked") + public Builder numberBlocked(Boolean numberBlocked) { + this.numberBlocked = numberBlocked; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked_date") + public Builder numberBlockedDate(ZonedDateTime numberBlockedDate) { + this.numberBlockedDate = numberBlockedDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked_last_3_months") + public Builder numberBlockedLast3Months( + Boolean numberBlockedLast3Months + ) { + this.numberBlockedLast3Months = numberBlockedLast3Months; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_pumping_risk_score") + public Builder smsPumpingRiskScore(Integer smsPumpingRiskScore) { + this.smsPumpingRiskScore = smsPumpingRiskScore; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public SmsPumpingRiskInfo build() { + return new SmsPumpingRiskInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SmsPumpingRiskInfo other = (SmsPumpingRiskInfo) o; + return ( + Objects.equals( + carrierRiskCategory, + other.carrierRiskCategory + ) && + Objects.equals(numberBlocked, other.numberBlocked) && + Objects.equals(numberBlockedDate, other.numberBlockedDate) && + Objects.equals( + numberBlockedLast3Months, + other.numberBlockedLast3Months + ) && + Objects.equals( + smsPumpingRiskScore, + other.smsPumpingRiskScore + ) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + carrierRiskCategory, + numberBlocked, + numberBlockedDate, + numberBlockedLast3Months, + smsPumpingRiskScore, + errorCode + ); + } + } + + @JsonDeserialize(builder = ReassignedNumberInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReassignedNumberInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_verified_date") + @Getter + private final String lastVerifiedDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("is_number_reassigned") + @Getter + private final String isNumberReassigned; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final String errorCode; + + private ReassignedNumberInfo(Builder builder) { + this.lastVerifiedDate = builder.lastVerifiedDate; + this.isNumberReassigned = builder.isNumberReassigned; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReassignedNumberInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ReassignedNumberInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("last_verified_date") + private String lastVerifiedDate; + + @JsonProperty("is_number_reassigned") + private String isNumberReassigned; + + @JsonProperty("error_code") + private String errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_verified_date") + public Builder lastVerifiedDate(String lastVerifiedDate) { + this.lastVerifiedDate = lastVerifiedDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("is_number_reassigned") + public Builder isNumberReassigned(String isNumberReassigned) { + this.isNumberReassigned = isNumberReassigned; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(String errorCode) { + this.errorCode = errorCode; + return this; + } + + public ReassignedNumberInfo build() { + return new ReassignedNumberInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReassignedNumberInfo other = (ReassignedNumberInfo) o; + return ( + Objects.equals(lastVerifiedDate, other.lastVerifiedDate) && + Objects.equals(isNumberReassigned, other.isNumberReassigned) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + lastVerifiedDate, + isNumberReassigned, + errorCode + ); + } + } + + @JsonDeserialize(builder = IdentityMatchInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IdentityMatchInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("first_name_match") + @Getter + private final String firstNameMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_name_match") + @Getter + private final String lastNameMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_lines_match") + @Getter + private final String addressLinesMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("city_match") + @Getter + private final String cityMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("state_match") + @Getter + private final String stateMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("postal_code_match") + @Getter + private final String postalCodeMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_country_match") + @Getter + private final String addressCountryMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("national_id_match") + @Getter + private final String nationalIdMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_of_birth_match") + @Getter + private final String dateOfBirthMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("summary_score") + @Getter + private final Integer summaryScore; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_message") + @Getter + private final String errorMessage; + + private IdentityMatchInfo(Builder builder) { + this.firstNameMatch = builder.firstNameMatch; + this.lastNameMatch = builder.lastNameMatch; + this.addressLinesMatch = builder.addressLinesMatch; + this.cityMatch = builder.cityMatch; + this.stateMatch = builder.stateMatch; + this.postalCodeMatch = builder.postalCodeMatch; + this.addressCountryMatch = builder.addressCountryMatch; + this.nationalIdMatch = builder.nationalIdMatch; + this.dateOfBirthMatch = builder.dateOfBirthMatch; + this.summaryScore = builder.summaryScore; + this.errorCode = builder.errorCode; + this.errorMessage = builder.errorMessage; + } + + public static Builder builder() { + return new Builder(); + } + + public static IdentityMatchInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, IdentityMatchInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("first_name_match") + private String firstNameMatch; + + @JsonProperty("last_name_match") + private String lastNameMatch; + + @JsonProperty("address_lines_match") + private String addressLinesMatch; + + @JsonProperty("city_match") + private String cityMatch; + + @JsonProperty("state_match") + private String stateMatch; + + @JsonProperty("postal_code_match") + private String postalCodeMatch; + + @JsonProperty("address_country_match") + private String addressCountryMatch; + + @JsonProperty("national_id_match") + private String nationalIdMatch; + + @JsonProperty("date_of_birth_match") + private String dateOfBirthMatch; + + @JsonProperty("summary_score") + private Integer summaryScore; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonProperty("error_message") + private String errorMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("first_name_match") + public Builder firstNameMatch(String firstNameMatch) { + this.firstNameMatch = firstNameMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_name_match") + public Builder lastNameMatch(String lastNameMatch) { + this.lastNameMatch = lastNameMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_lines_match") + public Builder addressLinesMatch(String addressLinesMatch) { + this.addressLinesMatch = addressLinesMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("city_match") + public Builder cityMatch(String cityMatch) { + this.cityMatch = cityMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("state_match") + public Builder stateMatch(String stateMatch) { + this.stateMatch = stateMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("postal_code_match") + public Builder postalCodeMatch(String postalCodeMatch) { + this.postalCodeMatch = postalCodeMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_country_match") + public Builder addressCountryMatch(String addressCountryMatch) { + this.addressCountryMatch = addressCountryMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("national_id_match") + public Builder nationalIdMatch(String nationalIdMatch) { + this.nationalIdMatch = nationalIdMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_of_birth_match") + public Builder dateOfBirthMatch(String dateOfBirthMatch) { + this.dateOfBirthMatch = dateOfBirthMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("summary_score") + public Builder summaryScore(Integer summaryScore) { + this.summaryScore = summaryScore; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_message") + public Builder errorMessage(String errorMessage) { + this.errorMessage = errorMessage; + return this; + } + + public IdentityMatchInfo build() { + return new IdentityMatchInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IdentityMatchInfo other = (IdentityMatchInfo) o; + return ( + Objects.equals(firstNameMatch, other.firstNameMatch) && + Objects.equals(lastNameMatch, other.lastNameMatch) && + Objects.equals(addressLinesMatch, other.addressLinesMatch) && + Objects.equals(cityMatch, other.cityMatch) && + Objects.equals(stateMatch, other.stateMatch) && + Objects.equals(postalCodeMatch, other.postalCodeMatch) && + Objects.equals( + addressCountryMatch, + other.addressCountryMatch + ) && + Objects.equals(nationalIdMatch, other.nationalIdMatch) && + Objects.equals(dateOfBirthMatch, other.dateOfBirthMatch) && + Objects.equals(summaryScore, other.summaryScore) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorMessage, other.errorMessage) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + firstNameMatch, + lastNameMatch, + addressLinesMatch, + cityMatch, + stateMatch, + postalCodeMatch, + addressCountryMatch, + nationalIdMatch, + dateOfBirthMatch, + summaryScore, + errorCode, + errorMessage + ); + } + } + + @JsonDeserialize(builder = LastSimSwapInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LastSimSwapInfo { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_sim_swap_date") + @Getter + private final ZonedDateTime lastSimSwapDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("swapped_period") + @Getter + private final String swappedPeriod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("swapped_in_period") + @Getter + private final Boolean swappedInPeriod; + + private LastSimSwapInfo(Builder builder) { + this.lastSimSwapDate = builder.lastSimSwapDate; + this.swappedPeriod = builder.swappedPeriod; + this.swappedInPeriod = builder.swappedInPeriod; + } + + public static Builder builder() { + return new Builder(); + } + + public static LastSimSwapInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LastSimSwapInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("last_sim_swap_date") + private ZonedDateTime lastSimSwapDate; + + @JsonProperty("swapped_period") + private String swappedPeriod; + + @JsonProperty("swapped_in_period") + private Boolean swappedInPeriod; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_sim_swap_date") + public Builder lastSimSwapDate(ZonedDateTime lastSimSwapDate) { + this.lastSimSwapDate = lastSimSwapDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("swapped_period") + public Builder swappedPeriod(String swappedPeriod) { + this.swappedPeriod = swappedPeriod; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("swapped_in_period") + public Builder swappedInPeriod(Boolean swappedInPeriod) { + this.swappedInPeriod = swappedInPeriod; + return this; + } + + public LastSimSwapInfo build() { + return new LastSimSwapInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LastSimSwapInfo other = (LastSimSwapInfo) o; + return ( + Objects.equals(lastSimSwapDate, other.lastSimSwapDate) && + Objects.equals(swappedPeriod, other.swappedPeriod) && + Objects.equals(swappedInPeriod, other.swappedInPeriod) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + lastSimSwapDate, + swappedPeriod, + swappedInPeriod + ); + } + } + + @JsonDeserialize(builder = LineTypeIntelligenceInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LineTypeIntelligenceInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_country_code") + @Getter + private final String mobileCountryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_network_code") + @Getter + private final String mobileNetworkCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_name") + @Getter + private final String carrierName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private LineTypeIntelligenceInfo(Builder builder) { + this.mobileCountryCode = builder.mobileCountryCode; + this.mobileNetworkCode = builder.mobileNetworkCode; + this.carrierName = builder.carrierName; + this.type = builder.type; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static LineTypeIntelligenceInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LineTypeIntelligenceInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("mobile_country_code") + private String mobileCountryCode; + + @JsonProperty("mobile_network_code") + private String mobileNetworkCode; + + @JsonProperty("carrier_name") + private String carrierName; + + @JsonProperty("type") + private String type; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_country_code") + public Builder mobileCountryCode(String mobileCountryCode) { + this.mobileCountryCode = mobileCountryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_network_code") + public Builder mobileNetworkCode(String mobileNetworkCode) { + this.mobileNetworkCode = mobileNetworkCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_name") + public Builder carrierName(String carrierName) { + this.carrierName = carrierName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public LineTypeIntelligenceInfo build() { + return new LineTypeIntelligenceInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LineTypeIntelligenceInfo other = (LineTypeIntelligenceInfo) o; + return ( + Objects.equals(mobileCountryCode, other.mobileCountryCode) && + Objects.equals(mobileNetworkCode, other.mobileNetworkCode) && + Objects.equals(carrierName, other.carrierName) && + Objects.equals(type, other.type) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + mobileCountryCode, + mobileNetworkCode, + carrierName, + type, + errorCode + ); + } + } + + @JsonDeserialize(builder = SimSwapInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SimSwapInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_sim_swap") + @Getter + private final LastSimSwapInfo lastSimSwap; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_name") + @Getter + private final String carrierName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_country_code") + @Getter + private final String mobileCountryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_network_code") + @Getter + private final String mobileNetworkCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private SimSwapInfo(Builder builder) { + this.lastSimSwap = builder.lastSimSwap; + this.carrierName = builder.carrierName; + this.mobileCountryCode = builder.mobileCountryCode; + this.mobileNetworkCode = builder.mobileNetworkCode; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static SimSwapInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SimSwapInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("last_sim_swap") + private LastSimSwapInfo lastSimSwap; + + @JsonProperty("carrier_name") + private String carrierName; + + @JsonProperty("mobile_country_code") + private String mobileCountryCode; + + @JsonProperty("mobile_network_code") + private String mobileNetworkCode; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_sim_swap") + public Builder lastSimSwap(LastSimSwapInfo lastSimSwap) { + this.lastSimSwap = lastSimSwap; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_name") + public Builder carrierName(String carrierName) { + this.carrierName = carrierName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_country_code") + public Builder mobileCountryCode(String mobileCountryCode) { + this.mobileCountryCode = mobileCountryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_network_code") + public Builder mobileNetworkCode(String mobileNetworkCode) { + this.mobileNetworkCode = mobileNetworkCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public SimSwapInfo build() { + return new SimSwapInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SimSwapInfo other = (SimSwapInfo) o; + return ( + Objects.equals(lastSimSwap, other.lastSimSwap) && + Objects.equals(carrierName, other.carrierName) && + Objects.equals(mobileCountryCode, other.mobileCountryCode) && + Objects.equals(mobileNetworkCode, other.mobileNetworkCode) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + lastSimSwap, + carrierName, + mobileCountryCode, + mobileNetworkCode, + errorCode + ); + } + } + + @JsonDeserialize(builder = LineStatusInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LineStatusInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final String status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private LineStatusInfo(Builder builder) { + this.status = builder.status; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static LineStatusInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LineStatusInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("status") + private String status; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + public Builder status(String status) { + this.status = status; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public LineStatusInfo build() { + return new LineStatusInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LineStatusInfo other = (LineStatusInfo) o; + return ( + Objects.equals(status, other.status) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash(status, errorCode); + } + } + + @JsonDeserialize(builder = CallerNameInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallerNameInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_name") + @Getter + private final String callerName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_type") + @Getter + private final String callerType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private CallerNameInfo(Builder builder) { + this.callerName = builder.callerName; + this.callerType = builder.callerType; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallerNameInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CallerNameInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("caller_name") + private String callerName; + + @JsonProperty("caller_type") + private String callerType; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_name") + public Builder callerName(String callerName) { + this.callerName = callerName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_type") + public Builder callerType(String callerType) { + this.callerType = callerType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public CallerNameInfo build() { + return new CallerNameInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallerNameInfo other = (CallerNameInfo) o; + return ( + Objects.equals(callerName, other.callerName) && + Objects.equals(callerType, other.callerType) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash(callerName, callerType, errorCode); + } + } + + /** + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PhoneNumber.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PhoneNumber.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final CallForwardingInfo callForwarding; + + @Getter + private final CallerNameInfo callerName; + + @Getter + private final String callingCountryCode; + + @Getter + private final String countryCode; + + @Getter + private final IdentityMatchInfo identityMatch; + + @Getter + private final LineStatusInfo lineStatus; + + @Getter + private final LineTypeIntelligenceInfo lineTypeIntelligence; + + @Getter + private final String nationalFormat; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter + private final Object phoneNumberQualityScore; + + @Getter + private final Object preFill; + + @Getter + private final ReassignedNumberInfo reassignedNumber; + + @Getter + private final SimSwapInfo simSwap; + + @Getter + private final SmsPumpingRiskInfo smsPumpingRisk; + + @Getter + private final URI url; + + @Getter + private final Boolean valid; + + @Getter + private final List validationErrors; + + @JsonCreator + private PhoneNumber( + @JsonProperty( + "call_forwarding" + ) final CallForwardingInfo callForwarding, + @JsonProperty("caller_name") final CallerNameInfo callerName, + @JsonProperty("calling_country_code") final String callingCountryCode, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("identity_match") final IdentityMatchInfo identityMatch, + @JsonProperty("line_status") final LineStatusInfo lineStatus, + @JsonProperty( + "line_type_intelligence" + ) final LineTypeIntelligenceInfo lineTypeIntelligence, + @JsonProperty("national_format") final String nationalFormat, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty( + "phone_number_quality_score" + ) final Object phoneNumberQualityScore, + @JsonProperty("pre_fill") final Object preFill, + @JsonProperty( + "reassigned_number" + ) final ReassignedNumberInfo reassignedNumber, + @JsonProperty("sim_swap") final SimSwapInfo simSwap, + @JsonProperty( + "sms_pumping_risk" + ) final SmsPumpingRiskInfo smsPumpingRisk, + @JsonProperty("url") final URI url, + @JsonProperty("valid") final Boolean valid, + @JsonProperty("validation_errors") final List< + PhoneNumber.ValidationError + > validationErrors + ) { + this.callForwarding = callForwarding; + this.callerName = callerName; + this.callingCountryCode = callingCountryCode; + this.countryCode = countryCode; + this.identityMatch = identityMatch; + this.lineStatus = lineStatus; + this.lineTypeIntelligence = lineTypeIntelligence; + this.nationalFormat = nationalFormat; + this.phoneNumber = phoneNumber; + this.phoneNumberQualityScore = phoneNumberQualityScore; + this.preFill = preFill; + this.reassignedNumber = reassignedNumber; + this.simSwap = simSwap; + this.smsPumpingRisk = smsPumpingRisk; + this.url = url; + this.valid = valid; + this.validationErrors = validationErrors; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PhoneNumber other = (PhoneNumber) o; + return ( + Objects.equals(callForwarding, other.callForwarding) && + Objects.equals(callerName, other.callerName) && + Objects.equals(callingCountryCode, other.callingCountryCode) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(identityMatch, other.identityMatch) && + Objects.equals(lineStatus, other.lineStatus) && + Objects.equals(lineTypeIntelligence, other.lineTypeIntelligence) && + Objects.equals(nationalFormat, other.nationalFormat) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals( + phoneNumberQualityScore, + other.phoneNumberQualityScore + ) && + Objects.equals(preFill, other.preFill) && + Objects.equals(reassignedNumber, other.reassignedNumber) && + Objects.equals(simSwap, other.simSwap) && + Objects.equals(smsPumpingRisk, other.smsPumpingRisk) && + Objects.equals(url, other.url) && + Objects.equals(valid, other.valid) && + Objects.equals(validationErrors, other.validationErrors) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + callForwarding, + callerName, + callingCountryCode, + countryCode, + identityMatch, + lineStatus, + lineTypeIntelligence, + nationalFormat, + phoneNumber, + phoneNumberQualityScore, + preFill, + reassignedNumber, + simSwap, + smsPumpingRisk, + url, + valid, + validationErrors + ); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/lookups/v2/PhoneNumberFetcher.java new file mode 100644 index 0000000000..8ba3807a3a --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/PhoneNumberFetcher.java @@ -0,0 +1,319 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PhoneNumberFetcher extends Fetcher { + + private String pathPhoneNumber; + private String fields; + private String countryCode; + private String firstName; + private String lastName; + private String addressLine1; + private String addressLine2; + private String city; + private String state; + private String postalCode; + private String addressCountryCode; + private String nationalId; + private String dateOfBirth; + private String lastVerifiedDate; + private String verificationSid; + private String partnerSubId; + + public PhoneNumberFetcher(final String pathPhoneNumber) { + this.pathPhoneNumber = pathPhoneNumber; + } + + public PhoneNumberFetcher setFields(final String fields) { + this.fields = fields; + return this; + } + + public PhoneNumberFetcher setCountryCode(final String countryCode) { + this.countryCode = countryCode; + return this; + } + + public PhoneNumberFetcher setFirstName(final String firstName) { + this.firstName = firstName; + return this; + } + + public PhoneNumberFetcher setLastName(final String lastName) { + this.lastName = lastName; + return this; + } + + public PhoneNumberFetcher setAddressLine1(final String addressLine1) { + this.addressLine1 = addressLine1; + return this; + } + + public PhoneNumberFetcher setAddressLine2(final String addressLine2) { + this.addressLine2 = addressLine2; + return this; + } + + public PhoneNumberFetcher setCity(final String city) { + this.city = city; + return this; + } + + public PhoneNumberFetcher setState(final String state) { + this.state = state; + return this; + } + + public PhoneNumberFetcher setPostalCode(final String postalCode) { + this.postalCode = postalCode; + return this; + } + + public PhoneNumberFetcher setAddressCountryCode( + final String addressCountryCode + ) { + this.addressCountryCode = addressCountryCode; + return this; + } + + public PhoneNumberFetcher setNationalId(final String nationalId) { + this.nationalId = nationalId; + return this; + } + + public PhoneNumberFetcher setDateOfBirth(final String dateOfBirth) { + this.dateOfBirth = dateOfBirth; + return this; + } + + public PhoneNumberFetcher setLastVerifiedDate( + final String lastVerifiedDate + ) { + this.lastVerifiedDate = lastVerifiedDate; + return this; + } + + public PhoneNumberFetcher setVerificationSid(final String verificationSid) { + this.verificationSid = verificationSid; + return this; + } + + public PhoneNumberFetcher setPartnerSubId(final String partnerSubId) { + this.partnerSubId = partnerSubId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/PhoneNumbers/{PhoneNumber}"; + + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.LOOKUPS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PhoneNumber fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (fields != null) { + Serializer.toString(request, "Fields", fields, ParameterType.QUERY); + } + + if (countryCode != null) { + Serializer.toString( + request, + "CountryCode", + countryCode, + ParameterType.QUERY + ); + } + + if (firstName != null) { + Serializer.toString( + request, + "FirstName", + firstName, + ParameterType.QUERY + ); + } + + if (lastName != null) { + Serializer.toString( + request, + "LastName", + lastName, + ParameterType.QUERY + ); + } + + if (addressLine1 != null) { + Serializer.toString( + request, + "AddressLine1", + addressLine1, + ParameterType.QUERY + ); + } + + if (addressLine2 != null) { + Serializer.toString( + request, + "AddressLine2", + addressLine2, + ParameterType.QUERY + ); + } + + if (city != null) { + Serializer.toString(request, "City", city, ParameterType.QUERY); + } + + if (state != null) { + Serializer.toString(request, "State", state, ParameterType.QUERY); + } + + if (postalCode != null) { + Serializer.toString( + request, + "PostalCode", + postalCode, + ParameterType.QUERY + ); + } + + if (addressCountryCode != null) { + Serializer.toString( + request, + "AddressCountryCode", + addressCountryCode, + ParameterType.QUERY + ); + } + + if (nationalId != null) { + Serializer.toString( + request, + "NationalId", + nationalId, + ParameterType.QUERY + ); + } + + if (dateOfBirth != null) { + Serializer.toString( + request, + "DateOfBirth", + dateOfBirth, + ParameterType.QUERY + ); + } + + if (lastVerifiedDate != null) { + Serializer.toString( + request, + "LastVerifiedDate", + lastVerifiedDate, + ParameterType.QUERY + ); + } + + if (verificationSid != null) { + Serializer.toString( + request, + "VerificationSid", + verificationSid, + ParameterType.QUERY + ); + } + + if (partnerSubId != null) { + Serializer.toString( + request, + "PartnerSubId", + partnerSubId, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/Query.java b/src/main/java/com/twilio/rest/lookups/v2/Query.java new file mode 100644 index 0000000000..b38cf6a685 --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/Query.java @@ -0,0 +1,2389 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Query extends Resource { + + public static QueryCreator creator() { + return new QueryCreator(); + } + + public enum Fields { + CALLER_NAME("caller_name"), + SIM_SWAP("sim_swap"), + CALL_FORWARDING("call_forwarding"), + LINE_TYPE_INTELLIGENCE("line_type_intelligence"), + LINE_STATUS("line_status"), + IDENTITY_MATCH("identity_match"), + REASSIGNED_NUMBER("reassigned_number"), + SMS_PUMPING_RISK("sms_pumping_risk"); + + private final String value; + + private Fields(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Fields forValue(final String value) { + return Promoter.enumFromString(value, Fields.values()); + } + } + + @JsonDeserialize(builder = LookupBatchRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LookupBatchRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("correlation_id") + @Getter + private final String correlationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + @Getter + private final String phoneNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fields") + @Getter + private final List fields; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country_code") + @Getter + private final String countryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("identity_match") + @Getter + private final IdentityMatchParameters identityMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("reassigned_number") + @Getter + private final ReassignedNumberParameters reassignedNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_pumping_risk") + @Getter + private final RiskParameters smsPumpingRisk; + + private LookupBatchRequest(Builder builder) { + this.correlationId = builder.correlationId; + this.phoneNumber = builder.phoneNumber; + this.fields = builder.fields; + this.countryCode = builder.countryCode; + this.identityMatch = builder.identityMatch; + this.reassignedNumber = builder.reassignedNumber; + this.smsPumpingRisk = builder.smsPumpingRisk; + } + + public static Builder builder(final String phoneNumber) { + return new Builder(phoneNumber); + } + + public static LookupBatchRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LookupBatchRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("correlation_id") + private String correlationId; + + @JsonProperty("phone_number") + private String phoneNumber; + + @JsonProperty("fields") + private List fields; + + @JsonProperty("country_code") + private String countryCode; + + @JsonProperty("identity_match") + private IdentityMatchParameters identityMatch; + + @JsonProperty("reassigned_number") + private ReassignedNumberParameters reassignedNumber; + + @JsonProperty("sms_pumping_risk") + private RiskParameters smsPumpingRisk; + + @JsonCreator + public Builder( + @JsonProperty("phone_number") final String phoneNumber + ) { + this.phoneNumber = phoneNumber; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("correlation_id") + public Builder correlationId(String correlationId) { + this.correlationId = correlationId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fields") + public Builder fields(List fields) { + this.fields = fields; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country_code") + public Builder countryCode(String countryCode) { + this.countryCode = countryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("identity_match") + public Builder identityMatch( + IdentityMatchParameters identityMatch + ) { + this.identityMatch = identityMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("reassigned_number") + public Builder reassignedNumber( + ReassignedNumberParameters reassignedNumber + ) { + this.reassignedNumber = reassignedNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_pumping_risk") + public Builder smsPumpingRisk(RiskParameters smsPumpingRisk) { + this.smsPumpingRisk = smsPumpingRisk; + return this; + } + + public LookupBatchRequest build() { + return new LookupBatchRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LookupBatchRequest other = (LookupBatchRequest) o; + return ( + Objects.equals(correlationId, other.correlationId) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(fields, other.fields) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(identityMatch, other.identityMatch) && + Objects.equals(reassignedNumber, other.reassignedNumber) && + Objects.equals(smsPumpingRisk, other.smsPumpingRisk) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + correlationId, + phoneNumber, + fields, + countryCode, + identityMatch, + reassignedNumber, + smsPumpingRisk + ); + } + } + + @JsonDeserialize(builder = LookupBatchResponse.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LookupBatchResponse { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("correlation_id") + @Getter + private final String correlationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio_error_code") + @Getter + private final Integer twilioErrorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("calling_country_code") + @Getter + private final String callingCountryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country_code") + @Getter + private final String countryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + @Getter + private final String phoneNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("national_format") + @Getter + private final String nationalFormat; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("valid") + @Getter + private final Boolean valid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("validation_errors") + @Getter + private final List validationErrors; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_name") + @Getter + private final CallerNameInfo callerName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sim_swap") + @Getter + private final SimSwapInfo simSwap; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_forwarding") + @Getter + private final CallForwardingInfo callForwarding; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("line_type_intelligence") + @Getter + private final LineTypeIntelligenceInfo lineTypeIntelligence; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("line_status") + @Getter + private final LineStatusInfo lineStatus; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("identity_match") + @Getter + private final IdentityMatchInfo identityMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("reassigned_number") + @Getter + private final ReassignedNumberInfo reassignedNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_pumping_risk") + @Getter + private final SmsPumpingRiskInfo smsPumpingRisk; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number_quality_score") + @Getter + private final Object phoneNumberQualityScore; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pre_fill") + @Getter + private final Object preFill; + + private LookupBatchResponse(Builder builder) { + this.correlationId = builder.correlationId; + this.twilioErrorCode = builder.twilioErrorCode; + this.callingCountryCode = builder.callingCountryCode; + this.countryCode = builder.countryCode; + this.phoneNumber = builder.phoneNumber; + this.nationalFormat = builder.nationalFormat; + this.valid = builder.valid; + this.validationErrors = builder.validationErrors; + this.callerName = builder.callerName; + this.simSwap = builder.simSwap; + this.callForwarding = builder.callForwarding; + this.lineTypeIntelligence = builder.lineTypeIntelligence; + this.lineStatus = builder.lineStatus; + this.identityMatch = builder.identityMatch; + this.reassignedNumber = builder.reassignedNumber; + this.smsPumpingRisk = builder.smsPumpingRisk; + this.phoneNumberQualityScore = builder.phoneNumberQualityScore; + this.preFill = builder.preFill; + } + + public static Builder builder() { + return new Builder(); + } + + public static LookupBatchResponse fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LookupBatchResponse.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("correlation_id") + private String correlationId; + + @JsonProperty("twilio_error_code") + private Integer twilioErrorCode; + + @JsonProperty("calling_country_code") + private String callingCountryCode; + + @JsonProperty("country_code") + private String countryCode; + + @JsonProperty("phone_number") + private String phoneNumber; + + @JsonProperty("national_format") + private String nationalFormat; + + @JsonProperty("valid") + private Boolean valid; + + @JsonProperty("validation_errors") + private List validationErrors; + + @JsonProperty("caller_name") + private CallerNameInfo callerName; + + @JsonProperty("sim_swap") + private SimSwapInfo simSwap; + + @JsonProperty("call_forwarding") + private CallForwardingInfo callForwarding; + + @JsonProperty("line_type_intelligence") + private LineTypeIntelligenceInfo lineTypeIntelligence; + + @JsonProperty("line_status") + private LineStatusInfo lineStatus; + + @JsonProperty("identity_match") + private IdentityMatchInfo identityMatch; + + @JsonProperty("reassigned_number") + private ReassignedNumberInfo reassignedNumber; + + @JsonProperty("sms_pumping_risk") + private SmsPumpingRiskInfo smsPumpingRisk; + + @JsonProperty("phone_number_quality_score") + private Object phoneNumberQualityScore; + + @JsonProperty("pre_fill") + private Object preFill; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("correlation_id") + public Builder correlationId(String correlationId) { + this.correlationId = correlationId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("twilio_error_code") + public Builder twilioErrorCode(Integer twilioErrorCode) { + this.twilioErrorCode = twilioErrorCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("calling_country_code") + public Builder callingCountryCode(String callingCountryCode) { + this.callingCountryCode = callingCountryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country_code") + public Builder countryCode(String countryCode) { + this.countryCode = countryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + public Builder phoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("national_format") + public Builder nationalFormat(String nationalFormat) { + this.nationalFormat = nationalFormat; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("valid") + public Builder valid(Boolean valid) { + this.valid = valid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("validation_errors") + public Builder validationErrors(List validationErrors) { + this.validationErrors = validationErrors; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_name") + public Builder callerName(CallerNameInfo callerName) { + this.callerName = callerName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sim_swap") + public Builder simSwap(SimSwapInfo simSwap) { + this.simSwap = simSwap; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_forwarding") + public Builder callForwarding(CallForwardingInfo callForwarding) { + this.callForwarding = callForwarding; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("line_type_intelligence") + public Builder lineTypeIntelligence( + LineTypeIntelligenceInfo lineTypeIntelligence + ) { + this.lineTypeIntelligence = lineTypeIntelligence; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("line_status") + public Builder lineStatus(LineStatusInfo lineStatus) { + this.lineStatus = lineStatus; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("identity_match") + public Builder identityMatch(IdentityMatchInfo identityMatch) { + this.identityMatch = identityMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("reassigned_number") + public Builder reassignedNumber( + ReassignedNumberInfo reassignedNumber + ) { + this.reassignedNumber = reassignedNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_pumping_risk") + public Builder smsPumpingRisk(SmsPumpingRiskInfo smsPumpingRisk) { + this.smsPumpingRisk = smsPumpingRisk; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number_quality_score") + public Builder phoneNumberQualityScore( + Object phoneNumberQualityScore + ) { + this.phoneNumberQualityScore = phoneNumberQualityScore; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pre_fill") + public Builder preFill(Object preFill) { + this.preFill = preFill; + return this; + } + + public LookupBatchResponse build() { + return new LookupBatchResponse(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LookupBatchResponse other = (LookupBatchResponse) o; + return ( + Objects.equals(correlationId, other.correlationId) && + Objects.equals(twilioErrorCode, other.twilioErrorCode) && + Objects.equals(callingCountryCode, other.callingCountryCode) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(nationalFormat, other.nationalFormat) && + Objects.equals(valid, other.valid) && + Objects.equals(validationErrors, other.validationErrors) && + Objects.equals(callerName, other.callerName) && + Objects.equals(simSwap, other.simSwap) && + Objects.equals(callForwarding, other.callForwarding) && + Objects.equals( + lineTypeIntelligence, + other.lineTypeIntelligence + ) && + Objects.equals(lineStatus, other.lineStatus) && + Objects.equals(identityMatch, other.identityMatch) && + Objects.equals(reassignedNumber, other.reassignedNumber) && + Objects.equals(smsPumpingRisk, other.smsPumpingRisk) && + Objects.equals( + phoneNumberQualityScore, + other.phoneNumberQualityScore + ) && + Objects.equals(preFill, other.preFill) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + correlationId, + twilioErrorCode, + callingCountryCode, + countryCode, + phoneNumber, + nationalFormat, + valid, + validationErrors, + callerName, + simSwap, + callForwarding, + lineTypeIntelligence, + lineStatus, + identityMatch, + reassignedNumber, + smsPumpingRisk, + phoneNumberQualityScore, + preFill + ); + } + } + + @JsonDeserialize(builder = LastSimSwapInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LastSimSwapInfo { + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_sim_swap_date") + @Getter + private final ZonedDateTime lastSimSwapDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("swapped_period") + @Getter + private final String swappedPeriod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("swapped_in_period") + @Getter + private final Boolean swappedInPeriod; + + private LastSimSwapInfo(Builder builder) { + this.lastSimSwapDate = builder.lastSimSwapDate; + this.swappedPeriod = builder.swappedPeriod; + this.swappedInPeriod = builder.swappedInPeriod; + } + + public static Builder builder() { + return new Builder(); + } + + public static LastSimSwapInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LastSimSwapInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("last_sim_swap_date") + private ZonedDateTime lastSimSwapDate; + + @JsonProperty("swapped_period") + private String swappedPeriod; + + @JsonProperty("swapped_in_period") + private Boolean swappedInPeriod; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_sim_swap_date") + public Builder lastSimSwapDate(ZonedDateTime lastSimSwapDate) { + this.lastSimSwapDate = lastSimSwapDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("swapped_period") + public Builder swappedPeriod(String swappedPeriod) { + this.swappedPeriod = swappedPeriod; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("swapped_in_period") + public Builder swappedInPeriod(Boolean swappedInPeriod) { + this.swappedInPeriod = swappedInPeriod; + return this; + } + + public LastSimSwapInfo build() { + return new LastSimSwapInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LastSimSwapInfo other = (LastSimSwapInfo) o; + return ( + Objects.equals(lastSimSwapDate, other.lastSimSwapDate) && + Objects.equals(swappedPeriod, other.swappedPeriod) && + Objects.equals(swappedInPeriod, other.swappedInPeriod) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + lastSimSwapDate, + swappedPeriod, + swappedInPeriod + ); + } + } + + @JsonDeserialize(builder = ReassignedNumberParameters.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReassignedNumberParameters { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_verified_date") + @Getter + private final String lastVerifiedDate; + + private ReassignedNumberParameters(Builder builder) { + this.lastVerifiedDate = builder.lastVerifiedDate; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReassignedNumberParameters fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ReassignedNumberParameters.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("last_verified_date") + private String lastVerifiedDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_verified_date") + public Builder lastVerifiedDate(String lastVerifiedDate) { + this.lastVerifiedDate = lastVerifiedDate; + return this; + } + + public ReassignedNumberParameters build() { + return new ReassignedNumberParameters(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReassignedNumberParameters other = (ReassignedNumberParameters) o; + return (Objects.equals(lastVerifiedDate, other.lastVerifiedDate)); + } + + @Override + public int hashCode() { + return Objects.hash(lastVerifiedDate); + } + } + + @JsonDeserialize(builder = RiskParameters.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class RiskParameters { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("partner_sub_id") + @Getter + private final String partnerSubId; + + private RiskParameters(Builder builder) { + this.partnerSubId = builder.partnerSubId; + } + + public static Builder builder() { + return new Builder(); + } + + public static RiskParameters fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, RiskParameters.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("partner_sub_id") + private String partnerSubId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("partner_sub_id") + public Builder partnerSubId(String partnerSubId) { + this.partnerSubId = partnerSubId; + return this; + } + + public RiskParameters build() { + return new RiskParameters(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RiskParameters other = (RiskParameters) o; + return (Objects.equals(partnerSubId, other.partnerSubId)); + } + + @Override + public int hashCode() { + return Objects.hash(partnerSubId); + } + } + + @JsonDeserialize(builder = LineStatusInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LineStatusInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final String status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private LineStatusInfo(Builder builder) { + this.status = builder.status; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static LineStatusInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LineStatusInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("status") + private String status; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + public Builder status(String status) { + this.status = status; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public LineStatusInfo build() { + return new LineStatusInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LineStatusInfo other = (LineStatusInfo) o; + return ( + Objects.equals(status, other.status) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash(status, errorCode); + } + } + + @JsonDeserialize(builder = LookupRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LookupRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_numbers") + @Getter + private final List phoneNumbers; + + private LookupRequest(Builder builder) { + this.phoneNumbers = builder.phoneNumbers; + } + + public static Builder builder() { + return new Builder(); + } + + public static LookupRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LookupRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("phone_numbers") + private List phoneNumbers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_numbers") + public Builder phoneNumbers(List phoneNumbers) { + this.phoneNumbers = phoneNumbers; + return this; + } + + public LookupRequest build() { + return new LookupRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LookupRequest other = (LookupRequest) o; + return (Objects.equals(phoneNumbers, other.phoneNumbers)); + } + + @Override + public int hashCode() { + return Objects.hash(phoneNumbers); + } + } + + @JsonDeserialize(builder = CallForwardingInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallForwardingInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_forwarding_enabled") + @Getter + private final Boolean callForwardingEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private CallForwardingInfo(Builder builder) { + this.callForwardingEnabled = builder.callForwardingEnabled; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallForwardingInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CallForwardingInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("call_forwarding_enabled") + private Boolean callForwardingEnabled; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_forwarding_enabled") + public Builder callForwardingEnabled( + Boolean callForwardingEnabled + ) { + this.callForwardingEnabled = callForwardingEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public CallForwardingInfo build() { + return new CallForwardingInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallForwardingInfo other = (CallForwardingInfo) o; + return ( + Objects.equals( + callForwardingEnabled, + other.callForwardingEnabled + ) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash(callForwardingEnabled, errorCode); + } + } + + @JsonDeserialize(builder = SmsPumpingRiskInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SmsPumpingRiskInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_risk_category") + @Getter + private final String carrierRiskCategory; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked") + @Getter + private final Boolean numberBlocked; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked_date") + @Getter + private final ZonedDateTime numberBlockedDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked_last_3_months") + @Getter + private final Boolean numberBlockedLast3Months; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_pumping_risk_score") + @Getter + private final Integer smsPumpingRiskScore; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private SmsPumpingRiskInfo(Builder builder) { + this.carrierRiskCategory = builder.carrierRiskCategory; + this.numberBlocked = builder.numberBlocked; + this.numberBlockedDate = builder.numberBlockedDate; + this.numberBlockedLast3Months = builder.numberBlockedLast3Months; + this.smsPumpingRiskScore = builder.smsPumpingRiskScore; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static SmsPumpingRiskInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SmsPumpingRiskInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("carrier_risk_category") + private String carrierRiskCategory; + + @JsonProperty("number_blocked") + private Boolean numberBlocked; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("number_blocked_date") + private ZonedDateTime numberBlockedDate; + + @JsonProperty("number_blocked_last_3_months") + private Boolean numberBlockedLast3Months; + + @JsonProperty("sms_pumping_risk_score") + private Integer smsPumpingRiskScore; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_risk_category") + public Builder carrierRiskCategory(String carrierRiskCategory) { + this.carrierRiskCategory = carrierRiskCategory; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked") + public Builder numberBlocked(Boolean numberBlocked) { + this.numberBlocked = numberBlocked; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked_date") + public Builder numberBlockedDate(ZonedDateTime numberBlockedDate) { + this.numberBlockedDate = numberBlockedDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_blocked_last_3_months") + public Builder numberBlockedLast3Months( + Boolean numberBlockedLast3Months + ) { + this.numberBlockedLast3Months = numberBlockedLast3Months; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_pumping_risk_score") + public Builder smsPumpingRiskScore(Integer smsPumpingRiskScore) { + this.smsPumpingRiskScore = smsPumpingRiskScore; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public SmsPumpingRiskInfo build() { + return new SmsPumpingRiskInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SmsPumpingRiskInfo other = (SmsPumpingRiskInfo) o; + return ( + Objects.equals( + carrierRiskCategory, + other.carrierRiskCategory + ) && + Objects.equals(numberBlocked, other.numberBlocked) && + Objects.equals(numberBlockedDate, other.numberBlockedDate) && + Objects.equals( + numberBlockedLast3Months, + other.numberBlockedLast3Months + ) && + Objects.equals( + smsPumpingRiskScore, + other.smsPumpingRiskScore + ) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + carrierRiskCategory, + numberBlocked, + numberBlockedDate, + numberBlockedLast3Months, + smsPumpingRiskScore, + errorCode + ); + } + } + + @JsonDeserialize(builder = ReassignedNumberInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ReassignedNumberInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_verified_date") + @Getter + private final String lastVerifiedDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("is_number_reassigned") + @Getter + private final String isNumberReassigned; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final String errorCode; + + private ReassignedNumberInfo(Builder builder) { + this.lastVerifiedDate = builder.lastVerifiedDate; + this.isNumberReassigned = builder.isNumberReassigned; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static ReassignedNumberInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ReassignedNumberInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("last_verified_date") + private String lastVerifiedDate; + + @JsonProperty("is_number_reassigned") + private String isNumberReassigned; + + @JsonProperty("error_code") + private String errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_verified_date") + public Builder lastVerifiedDate(String lastVerifiedDate) { + this.lastVerifiedDate = lastVerifiedDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("is_number_reassigned") + public Builder isNumberReassigned(String isNumberReassigned) { + this.isNumberReassigned = isNumberReassigned; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(String errorCode) { + this.errorCode = errorCode; + return this; + } + + public ReassignedNumberInfo build() { + return new ReassignedNumberInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReassignedNumberInfo other = (ReassignedNumberInfo) o; + return ( + Objects.equals(lastVerifiedDate, other.lastVerifiedDate) && + Objects.equals(isNumberReassigned, other.isNumberReassigned) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + lastVerifiedDate, + isNumberReassigned, + errorCode + ); + } + } + + @JsonDeserialize(builder = IdentityMatchParameters.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IdentityMatchParameters { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("first_name") + @Getter + private final String firstName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_name") + @Getter + private final String lastName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_line1") + @Getter + private final String addressLine1; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_line2") + @Getter + private final String addressLine2; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("city") + @Getter + private final String city; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("state") + @Getter + private final String state; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("postal_code") + @Getter + private final String postalCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_country_code") + @Getter + private final String addressCountryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("national_id") + @Getter + private final String nationalId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_of_birth") + @Getter + private final String dateOfBirth; + + private IdentityMatchParameters(Builder builder) { + this.firstName = builder.firstName; + this.lastName = builder.lastName; + this.addressLine1 = builder.addressLine1; + this.addressLine2 = builder.addressLine2; + this.city = builder.city; + this.state = builder.state; + this.postalCode = builder.postalCode; + this.addressCountryCode = builder.addressCountryCode; + this.nationalId = builder.nationalId; + this.dateOfBirth = builder.dateOfBirth; + } + + public static Builder builder() { + return new Builder(); + } + + public static IdentityMatchParameters fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, IdentityMatchParameters.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("first_name") + private String firstName; + + @JsonProperty("last_name") + private String lastName; + + @JsonProperty("address_line1") + private String addressLine1; + + @JsonProperty("address_line2") + private String addressLine2; + + @JsonProperty("city") + private String city; + + @JsonProperty("state") + private String state; + + @JsonProperty("postal_code") + private String postalCode; + + @JsonProperty("address_country_code") + private String addressCountryCode; + + @JsonProperty("national_id") + private String nationalId; + + @JsonProperty("date_of_birth") + private String dateOfBirth; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("first_name") + public Builder firstName(String firstName) { + this.firstName = firstName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_name") + public Builder lastName(String lastName) { + this.lastName = lastName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_line1") + public Builder addressLine1(String addressLine1) { + this.addressLine1 = addressLine1; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_line2") + public Builder addressLine2(String addressLine2) { + this.addressLine2 = addressLine2; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("city") + public Builder city(String city) { + this.city = city; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("state") + public Builder state(String state) { + this.state = state; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("postal_code") + public Builder postalCode(String postalCode) { + this.postalCode = postalCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_country_code") + public Builder addressCountryCode(String addressCountryCode) { + this.addressCountryCode = addressCountryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("national_id") + public Builder nationalId(String nationalId) { + this.nationalId = nationalId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_of_birth") + public Builder dateOfBirth(String dateOfBirth) { + this.dateOfBirth = dateOfBirth; + return this; + } + + public IdentityMatchParameters build() { + return new IdentityMatchParameters(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IdentityMatchParameters other = (IdentityMatchParameters) o; + return ( + Objects.equals(firstName, other.firstName) && + Objects.equals(lastName, other.lastName) && + Objects.equals(addressLine1, other.addressLine1) && + Objects.equals(addressLine2, other.addressLine2) && + Objects.equals(city, other.city) && + Objects.equals(state, other.state) && + Objects.equals(postalCode, other.postalCode) && + Objects.equals(addressCountryCode, other.addressCountryCode) && + Objects.equals(nationalId, other.nationalId) && + Objects.equals(dateOfBirth, other.dateOfBirth) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + firstName, + lastName, + addressLine1, + addressLine2, + city, + state, + postalCode, + addressCountryCode, + nationalId, + dateOfBirth + ); + } + } + + @JsonDeserialize(builder = IdentityMatchInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IdentityMatchInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("first_name_match") + @Getter + private final String firstNameMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_name_match") + @Getter + private final String lastNameMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_lines_match") + @Getter + private final String addressLinesMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("city_match") + @Getter + private final String cityMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("state_match") + @Getter + private final String stateMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("postal_code_match") + @Getter + private final String postalCodeMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_country_match") + @Getter + private final String addressCountryMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("national_id_match") + @Getter + private final String nationalIdMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_of_birth_match") + @Getter + private final String dateOfBirthMatch; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("summary_score") + @Getter + private final Integer summaryScore; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_message") + @Getter + private final String errorMessage; + + private IdentityMatchInfo(Builder builder) { + this.firstNameMatch = builder.firstNameMatch; + this.lastNameMatch = builder.lastNameMatch; + this.addressLinesMatch = builder.addressLinesMatch; + this.cityMatch = builder.cityMatch; + this.stateMatch = builder.stateMatch; + this.postalCodeMatch = builder.postalCodeMatch; + this.addressCountryMatch = builder.addressCountryMatch; + this.nationalIdMatch = builder.nationalIdMatch; + this.dateOfBirthMatch = builder.dateOfBirthMatch; + this.summaryScore = builder.summaryScore; + this.errorCode = builder.errorCode; + this.errorMessage = builder.errorMessage; + } + + public static Builder builder() { + return new Builder(); + } + + public static IdentityMatchInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, IdentityMatchInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("first_name_match") + private String firstNameMatch; + + @JsonProperty("last_name_match") + private String lastNameMatch; + + @JsonProperty("address_lines_match") + private String addressLinesMatch; + + @JsonProperty("city_match") + private String cityMatch; + + @JsonProperty("state_match") + private String stateMatch; + + @JsonProperty("postal_code_match") + private String postalCodeMatch; + + @JsonProperty("address_country_match") + private String addressCountryMatch; + + @JsonProperty("national_id_match") + private String nationalIdMatch; + + @JsonProperty("date_of_birth_match") + private String dateOfBirthMatch; + + @JsonProperty("summary_score") + private Integer summaryScore; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonProperty("error_message") + private String errorMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("first_name_match") + public Builder firstNameMatch(String firstNameMatch) { + this.firstNameMatch = firstNameMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_name_match") + public Builder lastNameMatch(String lastNameMatch) { + this.lastNameMatch = lastNameMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_lines_match") + public Builder addressLinesMatch(String addressLinesMatch) { + this.addressLinesMatch = addressLinesMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("city_match") + public Builder cityMatch(String cityMatch) { + this.cityMatch = cityMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("state_match") + public Builder stateMatch(String stateMatch) { + this.stateMatch = stateMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("postal_code_match") + public Builder postalCodeMatch(String postalCodeMatch) { + this.postalCodeMatch = postalCodeMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_country_match") + public Builder addressCountryMatch(String addressCountryMatch) { + this.addressCountryMatch = addressCountryMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("national_id_match") + public Builder nationalIdMatch(String nationalIdMatch) { + this.nationalIdMatch = nationalIdMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("date_of_birth_match") + public Builder dateOfBirthMatch(String dateOfBirthMatch) { + this.dateOfBirthMatch = dateOfBirthMatch; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("summary_score") + public Builder summaryScore(Integer summaryScore) { + this.summaryScore = summaryScore; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_message") + public Builder errorMessage(String errorMessage) { + this.errorMessage = errorMessage; + return this; + } + + public IdentityMatchInfo build() { + return new IdentityMatchInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IdentityMatchInfo other = (IdentityMatchInfo) o; + return ( + Objects.equals(firstNameMatch, other.firstNameMatch) && + Objects.equals(lastNameMatch, other.lastNameMatch) && + Objects.equals(addressLinesMatch, other.addressLinesMatch) && + Objects.equals(cityMatch, other.cityMatch) && + Objects.equals(stateMatch, other.stateMatch) && + Objects.equals(postalCodeMatch, other.postalCodeMatch) && + Objects.equals( + addressCountryMatch, + other.addressCountryMatch + ) && + Objects.equals(nationalIdMatch, other.nationalIdMatch) && + Objects.equals(dateOfBirthMatch, other.dateOfBirthMatch) && + Objects.equals(summaryScore, other.summaryScore) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorMessage, other.errorMessage) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + firstNameMatch, + lastNameMatch, + addressLinesMatch, + cityMatch, + stateMatch, + postalCodeMatch, + addressCountryMatch, + nationalIdMatch, + dateOfBirthMatch, + summaryScore, + errorCode, + errorMessage + ); + } + } + + @JsonDeserialize(builder = LineTypeIntelligenceInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class LineTypeIntelligenceInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_country_code") + @Getter + private final String mobileCountryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_network_code") + @Getter + private final String mobileNetworkCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_name") + @Getter + private final String carrierName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private LineTypeIntelligenceInfo(Builder builder) { + this.mobileCountryCode = builder.mobileCountryCode; + this.mobileNetworkCode = builder.mobileNetworkCode; + this.carrierName = builder.carrierName; + this.type = builder.type; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static LineTypeIntelligenceInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, LineTypeIntelligenceInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("mobile_country_code") + private String mobileCountryCode; + + @JsonProperty("mobile_network_code") + private String mobileNetworkCode; + + @JsonProperty("carrier_name") + private String carrierName; + + @JsonProperty("type") + private String type; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_country_code") + public Builder mobileCountryCode(String mobileCountryCode) { + this.mobileCountryCode = mobileCountryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_network_code") + public Builder mobileNetworkCode(String mobileNetworkCode) { + this.mobileNetworkCode = mobileNetworkCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_name") + public Builder carrierName(String carrierName) { + this.carrierName = carrierName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public LineTypeIntelligenceInfo build() { + return new LineTypeIntelligenceInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LineTypeIntelligenceInfo other = (LineTypeIntelligenceInfo) o; + return ( + Objects.equals(mobileCountryCode, other.mobileCountryCode) && + Objects.equals(mobileNetworkCode, other.mobileNetworkCode) && + Objects.equals(carrierName, other.carrierName) && + Objects.equals(type, other.type) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + mobileCountryCode, + mobileNetworkCode, + carrierName, + type, + errorCode + ); + } + } + + @JsonDeserialize(builder = SimSwapInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SimSwapInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_sim_swap") + @Getter + private final LastSimSwapInfo lastSimSwap; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_name") + @Getter + private final String carrierName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_country_code") + @Getter + private final String mobileCountryCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_network_code") + @Getter + private final String mobileNetworkCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private SimSwapInfo(Builder builder) { + this.lastSimSwap = builder.lastSimSwap; + this.carrierName = builder.carrierName; + this.mobileCountryCode = builder.mobileCountryCode; + this.mobileNetworkCode = builder.mobileNetworkCode; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static SimSwapInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SimSwapInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("last_sim_swap") + private LastSimSwapInfo lastSimSwap; + + @JsonProperty("carrier_name") + private String carrierName; + + @JsonProperty("mobile_country_code") + private String mobileCountryCode; + + @JsonProperty("mobile_network_code") + private String mobileNetworkCode; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("last_sim_swap") + public Builder lastSimSwap(LastSimSwapInfo lastSimSwap) { + this.lastSimSwap = lastSimSwap; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carrier_name") + public Builder carrierName(String carrierName) { + this.carrierName = carrierName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_country_code") + public Builder mobileCountryCode(String mobileCountryCode) { + this.mobileCountryCode = mobileCountryCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mobile_network_code") + public Builder mobileNetworkCode(String mobileNetworkCode) { + this.mobileNetworkCode = mobileNetworkCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public SimSwapInfo build() { + return new SimSwapInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SimSwapInfo other = (SimSwapInfo) o; + return ( + Objects.equals(lastSimSwap, other.lastSimSwap) && + Objects.equals(carrierName, other.carrierName) && + Objects.equals(mobileCountryCode, other.mobileCountryCode) && + Objects.equals(mobileNetworkCode, other.mobileNetworkCode) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + lastSimSwap, + carrierName, + mobileCountryCode, + mobileNetworkCode, + errorCode + ); + } + } + + @JsonDeserialize(builder = CallerNameInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CallerNameInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_name") + @Getter + private final String callerName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_type") + @Getter + private final String callerType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + @Getter + private final Integer errorCode; + + private CallerNameInfo(Builder builder) { + this.callerName = builder.callerName; + this.callerType = builder.callerType; + this.errorCode = builder.errorCode; + } + + public static Builder builder() { + return new Builder(); + } + + public static CallerNameInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CallerNameInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("caller_name") + private String callerName; + + @JsonProperty("caller_type") + private String callerType; + + @JsonProperty("error_code") + private Integer errorCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_name") + public Builder callerName(String callerName) { + this.callerName = callerName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("caller_type") + public Builder callerType(String callerType) { + this.callerType = callerType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("error_code") + public Builder errorCode(Integer errorCode) { + this.errorCode = errorCode; + return this; + } + + public CallerNameInfo build() { + return new CallerNameInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CallerNameInfo other = (CallerNameInfo) o; + return ( + Objects.equals(callerName, other.callerName) && + Objects.equals(callerType, other.callerType) && + Objects.equals(errorCode, other.errorCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash(callerName, callerType, errorCode); + } + } + + /** + * Converts a JSON String into a Query object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Query object represented by the provided JSON + */ + public static Query fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Query.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Query object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Query object represented by the provided JSON + */ + public static Query fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Query.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List phoneNumbers; + + @JsonCreator + private Query( + @JsonProperty("phone_numbers") final List< + LookupBatchResponse + > phoneNumbers + ) { + this.phoneNumbers = phoneNumbers; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Query other = (Query) o; + return (Objects.equals(phoneNumbers, other.phoneNumbers)); + } + + @Override + public int hashCode() { + return Objects.hash(phoneNumbers); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/QueryCreator.java b/src/main/java/com/twilio/rest/lookups/v2/QueryCreator.java new file mode 100644 index 0000000000..8097ea52e4 --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/QueryCreator.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class QueryCreator extends Creator { + + private Query.LookupRequest lookupRequest; + + public QueryCreator() {} + + public QueryCreator setLookupRequest( + final Query.LookupRequest lookupRequest + ) { + this.lookupRequest = lookupRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/batch/query"; + + Request request = new Request( + HttpMethod.POST, + Domains.LOOKUPS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Query creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Query create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Query.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Query content = Query.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (lookupRequest != null) { + request.setBody(Query.toJson(lookupRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/RateLimit.java b/src/main/java/com/twilio/rest/lookups/v2/RateLimit.java new file mode 100644 index 0000000000..58a3230af5 --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/RateLimit.java @@ -0,0 +1,268 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class RateLimit extends Resource { + + public static RateLimitFetcher fetcher() { + return new RateLimitFetcher(); + } + + @JsonDeserialize(builder = RateLimitResponse.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class RateLimitResponse { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + @Getter + private final String field; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("limit") + @Getter + private final Integer limit; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bucket") + @Getter + private final String bucket; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("owner") + @Getter + private final String owner; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ttl") + @Getter + private final Integer ttl; + + private RateLimitResponse(Builder builder) { + this.field = builder.field; + this.limit = builder.limit; + this.bucket = builder.bucket; + this.owner = builder.owner; + this.ttl = builder.ttl; + } + + public static Builder builder() { + return new Builder(); + } + + public static RateLimitResponse fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, RateLimitResponse.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("field") + private String field; + + @JsonProperty("limit") + private Integer limit; + + @JsonProperty("bucket") + private String bucket; + + @JsonProperty("owner") + private String owner; + + @JsonProperty("ttl") + private Integer ttl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("field") + public Builder field(String field) { + this.field = field; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("limit") + public Builder limit(Integer limit) { + this.limit = limit; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bucket") + public Builder bucket(String bucket) { + this.bucket = bucket; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("owner") + public Builder owner(String owner) { + this.owner = owner; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ttl") + public Builder ttl(Integer ttl) { + this.ttl = ttl; + return this; + } + + public RateLimitResponse build() { + return new RateLimitResponse(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RateLimitResponse other = (RateLimitResponse) o; + return ( + Objects.equals(field, other.field) && + Objects.equals(limit, other.limit) && + Objects.equals(bucket, other.bucket) && + Objects.equals(owner, other.owner) && + Objects.equals(ttl, other.ttl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(field, limit, bucket, owner, ttl); + } + } + + /** + * Converts a JSON String into a RateLimit object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return RateLimit object represented by the provided JSON + */ + public static RateLimit fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RateLimit.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a RateLimit object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return RateLimit object represented by the provided JSON + */ + public static RateLimit fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RateLimit.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List rateLimits; + + @JsonCreator + private RateLimit( + @JsonProperty("rate_limits") final List rateLimits + ) { + this.rateLimits = rateLimits; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RateLimit other = (RateLimit) o; + return (Objects.equals(rateLimits, other.rateLimits)); + } + + @Override + public int hashCode() { + return Objects.hash(rateLimits); + } +} diff --git a/src/main/java/com/twilio/rest/lookups/v2/RateLimitFetcher.java b/src/main/java/com/twilio/rest/lookups/v2/RateLimitFetcher.java new file mode 100644 index 0000000000..843cde458e --- /dev/null +++ b/src/main/java/com/twilio/rest/lookups/v2/RateLimitFetcher.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Lookups + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.lookups.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class RateLimitFetcher extends Fetcher { + + private List fields; + + public RateLimitFetcher() {} + + public RateLimitFetcher setFields(final List fields) { + this.fields = fields; + return this; + } + + public RateLimitFetcher setFields(final String fields) { + return setFields(Promoter.listOfOne(fields)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RateLimits"; + + Request request = new Request( + HttpMethod.GET, + Domains.LOOKUPS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "RateLimit fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public RateLimit fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return RateLimit.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + RateLimit content = RateLimit.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (fields != null) { + for (String param : fields) { + Serializer.toString( + request, + "Fields", + param, + ParameterType.QUERY + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOn.java b/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOn.java new file mode 100644 index 0000000000..cbc97aa800 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOn.java @@ -0,0 +1,180 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AvailableAddOn extends Resource { + + public static AvailableAddOnFetcher fetcher(final String pathSid) { + return new AvailableAddOnFetcher(pathSid); + } + + public static AvailableAddOnReader reader() { + return new AvailableAddOnReader(); + } + + /** + * Converts a JSON String into a AvailableAddOn object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AvailableAddOn object represented by the provided JSON + */ + public static AvailableAddOn fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AvailableAddOn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AvailableAddOn object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AvailableAddOn object represented by the provided JSON + */ + public static AvailableAddOn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AvailableAddOn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object configurationSchema; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String pricingType; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private AvailableAddOn( + @JsonProperty("configuration_schema") final Object configurationSchema, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("pricing_type") final String pricingType, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.configurationSchema = configurationSchema; + this.description = description; + this.friendlyName = friendlyName; + this.links = links; + this.pricingType = pricingType; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AvailableAddOn other = (AvailableAddOn) o; + return ( + Objects.equals(configurationSchema, other.configurationSchema) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(pricingType, other.pricingType) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + configurationSchema, + description, + friendlyName, + links, + pricingType, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOnFetcher.java b/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOnFetcher.java new file mode 100644 index 0000000000..f01d91d1c3 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOnFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AvailableAddOnFetcher extends Fetcher { + + private String pathSid; + + public AvailableAddOnFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/AvailableAddOns/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AvailableAddOn fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AvailableAddOn fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AvailableAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AvailableAddOn content = AvailableAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOnReader.java b/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOnReader.java new file mode 100644 index 0000000000..8e1ec8a588 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/AvailableAddOnReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AvailableAddOnReader extends Reader { + + private Integer pageSize; + + public AvailableAddOnReader() {} + + public AvailableAddOnReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_add_ons", + response.getContent(), + AvailableAddOn.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/AvailableAddOns"; + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_add_ons", + response.getContent(), + AvailableAddOn.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AvailableAddOn read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_add_ons", + response.getContent(), + AvailableAddOn.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOn.java b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOn.java new file mode 100644 index 0000000000..66580a6764 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOn.java @@ -0,0 +1,232 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InstalledAddOn extends Resource { + + public static InstalledAddOnCreator creator( + final String availableAddOnSid, + final Boolean acceptTermsOfService + ) { + return new InstalledAddOnCreator( + availableAddOnSid, + acceptTermsOfService + ); + } + + public static InstalledAddOnDeleter deleter(final String pathSid) { + return new InstalledAddOnDeleter(pathSid); + } + + public static InstalledAddOnFetcher fetcher(final String pathSid) { + return new InstalledAddOnFetcher(pathSid); + } + + public static InstalledAddOnReader reader() { + return new InstalledAddOnReader(); + } + + public static InstalledAddOnUpdater updater(final String pathSid) { + return new InstalledAddOnUpdater(pathSid); + } + + /** + * Converts a JSON String into a InstalledAddOn object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOn object represented by the provided JSON + */ + public static InstalledAddOn fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InstalledAddOn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InstalledAddOn object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOn object represented by the provided JSON + */ + public static InstalledAddOn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InstalledAddOn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object configuration; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private InstalledAddOn( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("configuration") final Object configuration, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.configuration = configuration; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.friendlyName = friendlyName; + this.links = links; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InstalledAddOn other = (InstalledAddOn) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + configuration, + dateCreated, + dateUpdated, + description, + friendlyName, + links, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnCreator.java b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnCreator.java new file mode 100644 index 0000000000..94543c47fb --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnCreator.java @@ -0,0 +1,168 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnCreator extends Creator { + + private String availableAddOnSid; + private Boolean acceptTermsOfService; + private Object configuration; + private String uniqueName; + + public InstalledAddOnCreator( + final String availableAddOnSid, + final Boolean acceptTermsOfService + ) { + this.availableAddOnSid = availableAddOnSid; + this.acceptTermsOfService = acceptTermsOfService; + } + + public InstalledAddOnCreator setAvailableAddOnSid( + final String availableAddOnSid + ) { + this.availableAddOnSid = availableAddOnSid; + return this; + } + + public InstalledAddOnCreator setAcceptTermsOfService( + final Boolean acceptTermsOfService + ) { + this.acceptTermsOfService = acceptTermsOfService; + return this; + } + + public InstalledAddOnCreator setConfiguration(final Object configuration) { + this.configuration = configuration; + return this; + } + + public InstalledAddOnCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/InstalledAddOns"; + + Request request = new Request( + HttpMethod.POST, + Domains.MARKETPLACE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOn creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InstalledAddOn create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOn content = InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (availableAddOnSid != null) { + Serializer.toString( + request, + "AvailableAddOnSid", + availableAddOnSid, + ParameterType.URLENCODED + ); + } + + if (acceptTermsOfService != null) { + Serializer.toString( + request, + "AcceptTermsOfService", + acceptTermsOfService, + ParameterType.URLENCODED + ); + } + + if (configuration != null) { + Serializer.toString( + request, + "Configuration", + configuration, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnDeleter.java b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnDeleter.java new file mode 100644 index 0000000000..81b17a3249 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class InstalledAddOnDeleter extends Deleter { + + private String pathSid; + + public InstalledAddOnDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/InstalledAddOns/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MARKETPLACE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOn delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnFetcher.java b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnFetcher.java new file mode 100644 index 0000000000..7ac8b5dcd6 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnFetcher extends Fetcher { + + private String pathSid; + + public InstalledAddOnFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/InstalledAddOns/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOn fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InstalledAddOn fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOn content = InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnReader.java b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnReader.java new file mode 100644 index 0000000000..967cf928db --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnReader extends Reader { + + private Integer pageSize; + + public InstalledAddOnReader() {} + + public InstalledAddOnReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "installed_add_ons", + response.getContent(), + InstalledAddOn.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/InstalledAddOns"; + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "installed_add_ons", + response.getContent(), + InstalledAddOn.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOn read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "installed_add_ons", + response.getContent(), + InstalledAddOn.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnUpdater.java b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnUpdater.java new file mode 100644 index 0000000000..3221a316f1 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/InstalledAddOnUpdater.java @@ -0,0 +1,133 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnUpdater extends Updater { + + private String pathSid; + private Object configuration; + private String uniqueName; + + public InstalledAddOnUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public InstalledAddOnUpdater setConfiguration(final Object configuration) { + this.configuration = configuration; + return this; + } + + public InstalledAddOnUpdater setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/InstalledAddOns/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MARKETPLACE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOn update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InstalledAddOn update(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOn content = InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (configuration != null) { + Serializer.toString( + request, + "Configuration", + configuration, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ModuleData.java b/src/main/java/com/twilio/rest/marketplace/v1/ModuleData.java new file mode 100644 index 0000000000..97357031e9 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/ModuleData.java @@ -0,0 +1,201 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ModuleData extends Resource { + + public static ModuleDataCreator creator() { + return new ModuleDataCreator(); + } + + public static ModuleDataFetcher fetcher() { + return new ModuleDataFetcher(); + } + + /** + * Converts a JSON String into a ModuleData object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ModuleData object represented by the provided JSON + */ + public static ModuleData fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ModuleData.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ModuleData object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ModuleData object represented by the provided JSON + */ + public static ModuleData fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ModuleData.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object configuration; + + @Getter + private final Object description; + + @Getter + private final Object documentation; + + @Getter + private final List listings; + + @Getter + private final Object moduleInfo; + + @Getter + private final Object policies; + + @Getter + private final Object pricing; + + @Getter + private final String sid; + + @Getter + private final Object support; + + @Getter + private final URI url; + + @JsonCreator + private ModuleData( + @JsonProperty("configuration") final Object configuration, + @JsonProperty("description") final Object description, + @JsonProperty("documentation") final Object documentation, + @JsonProperty("listings") final List listings, + @JsonProperty("module_info") final Object moduleInfo, + @JsonProperty("policies") final Object policies, + @JsonProperty("pricing") final Object pricing, + @JsonProperty("sid") final String sid, + @JsonProperty("support") final Object support, + @JsonProperty("url") final URI url + ) { + this.configuration = configuration; + this.description = description; + this.documentation = documentation; + this.listings = listings; + this.moduleInfo = moduleInfo; + this.policies = policies; + this.pricing = pricing; + this.sid = sid; + this.support = support; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ModuleData other = (ModuleData) o; + return ( + Objects.equals(configuration, other.configuration) && + Objects.equals(description, other.description) && + Objects.equals(documentation, other.documentation) && + Objects.equals(listings, other.listings) && + Objects.equals(moduleInfo, other.moduleInfo) && + Objects.equals(policies, other.policies) && + Objects.equals(pricing, other.pricing) && + Objects.equals(sid, other.sid) && + Objects.equals(support, other.support) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + configuration, + description, + documentation, + listings, + moduleInfo, + policies, + pricing, + sid, + support, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataCreator.java b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataCreator.java new file mode 100644 index 0000000000..ba7f57687d --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataCreator.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ModuleDataCreator extends Creator { + + private String moduleInfo; + private String configuration; + + public ModuleDataCreator() {} + + public ModuleDataCreator setModuleInfo(final String moduleInfo) { + this.moduleInfo = moduleInfo; + return this; + } + + public ModuleDataCreator setConfiguration(final String configuration) { + this.configuration = configuration; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Listings"; + + Request request = new Request( + HttpMethod.POST, + Domains.MARKETPLACE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ModuleData creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ModuleData create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ModuleData.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ModuleData content = ModuleData.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (moduleInfo != null) { + Serializer.toString( + request, + "ModuleInfo", + moduleInfo, + ParameterType.URLENCODED + ); + } + + if (configuration != null) { + Serializer.toString( + request, + "Configuration", + configuration, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataFetcher.java b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataFetcher.java new file mode 100644 index 0000000000..0f87974e06 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataFetcher.java @@ -0,0 +1,90 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ModuleDataFetcher extends Fetcher { + + public ModuleDataFetcher() {} + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Listings"; + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ModuleData fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ModuleData fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ModuleData.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ModuleData content = ModuleData.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagement.java b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagement.java new file mode 100644 index 0000000000..9a399e6160 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagement.java @@ -0,0 +1,193 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ModuleDataManagement extends Resource { + + public static ModuleDataManagementFetcher fetcher(final String pathSid) { + return new ModuleDataManagementFetcher(pathSid); + } + + public static ModuleDataManagementUpdater updater(final String pathSid) { + return new ModuleDataManagementUpdater(pathSid); + } + + /** + * Converts a JSON String into a ModuleDataManagement object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ModuleDataManagement object represented by the provided JSON + */ + public static ModuleDataManagement fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ModuleDataManagement.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ModuleDataManagement object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ModuleDataManagement object represented by the provided JSON + */ + public static ModuleDataManagement fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ModuleDataManagement.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object configuration; + + @Getter + private final Object description; + + @Getter + private final Object documentation; + + @Getter + private final Object moduleInfo; + + @Getter + private final Object policies; + + @Getter + private final Object pricing; + + @Getter + private final String sid; + + @Getter + private final Object support; + + @Getter + private final URI url; + + @JsonCreator + private ModuleDataManagement( + @JsonProperty("configuration") final Object configuration, + @JsonProperty("description") final Object description, + @JsonProperty("documentation") final Object documentation, + @JsonProperty("module_info") final Object moduleInfo, + @JsonProperty("policies") final Object policies, + @JsonProperty("pricing") final Object pricing, + @JsonProperty("sid") final String sid, + @JsonProperty("support") final Object support, + @JsonProperty("url") final URI url + ) { + this.configuration = configuration; + this.description = description; + this.documentation = documentation; + this.moduleInfo = moduleInfo; + this.policies = policies; + this.pricing = pricing; + this.sid = sid; + this.support = support; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ModuleDataManagement other = (ModuleDataManagement) o; + return ( + Objects.equals(configuration, other.configuration) && + Objects.equals(description, other.description) && + Objects.equals(documentation, other.documentation) && + Objects.equals(moduleInfo, other.moduleInfo) && + Objects.equals(policies, other.policies) && + Objects.equals(pricing, other.pricing) && + Objects.equals(sid, other.sid) && + Objects.equals(support, other.support) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + configuration, + description, + documentation, + moduleInfo, + policies, + pricing, + sid, + support, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementFetcher.java b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementFetcher.java new file mode 100644 index 0000000000..4ae2170786 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ModuleDataManagementFetcher extends Fetcher { + + private String pathSid; + + public ModuleDataManagementFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Listing/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ModuleDataManagement fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ModuleDataManagement fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ModuleDataManagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ModuleDataManagement content = ModuleDataManagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementUpdater.java b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementUpdater.java new file mode 100644 index 0000000000..01887f4954 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/ModuleDataManagementUpdater.java @@ -0,0 +1,214 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ModuleDataManagementUpdater extends Updater { + + private String pathSid; + private String moduleInfo; + private String description; + private String documentation; + private String policies; + private String support; + private String configuration; + private String pricing; + + public ModuleDataManagementUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public ModuleDataManagementUpdater setModuleInfo(final String moduleInfo) { + this.moduleInfo = moduleInfo; + return this; + } + + public ModuleDataManagementUpdater setDescription( + final String description + ) { + this.description = description; + return this; + } + + public ModuleDataManagementUpdater setDocumentation( + final String documentation + ) { + this.documentation = documentation; + return this; + } + + public ModuleDataManagementUpdater setPolicies(final String policies) { + this.policies = policies; + return this; + } + + public ModuleDataManagementUpdater setSupport(final String support) { + this.support = support; + return this; + } + + public ModuleDataManagementUpdater setConfiguration( + final String configuration + ) { + this.configuration = configuration; + return this; + } + + public ModuleDataManagementUpdater setPricing(final String pricing) { + this.pricing = pricing; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Listing/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MARKETPLACE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ModuleDataManagement update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ModuleDataManagement update(final TwilioRestClient client) { + Response response = makeRequest(client); + return ModuleDataManagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ModuleDataManagement content = ModuleDataManagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (moduleInfo != null) { + Serializer.toString( + request, + "ModuleInfo", + moduleInfo, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (documentation != null) { + Serializer.toString( + request, + "Documentation", + documentation, + ParameterType.URLENCODED + ); + } + + if (policies != null) { + Serializer.toString( + request, + "Policies", + policies, + ParameterType.URLENCODED + ); + } + + if (support != null) { + Serializer.toString( + request, + "Support", + support, + ParameterType.URLENCODED + ); + } + + if (configuration != null) { + Serializer.toString( + request, + "Configuration", + configuration, + ParameterType.URLENCODED + ); + } + + if (pricing != null) { + Serializer.toString( + request, + "Pricing", + pricing, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ReferralConversion.java b/src/main/java/com/twilio/rest/marketplace/v1/ReferralConversion.java new file mode 100644 index 0000000000..a8eb9257ec --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/ReferralConversion.java @@ -0,0 +1,205 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ReferralConversion extends Resource { + + public static ReferralConversionCreator creator( + final ReferralConversion.CreateReferralConversionRequest createReferralConversionRequest + ) { + return new ReferralConversionCreator(createReferralConversionRequest); + } + + @JsonDeserialize(builder = CreateReferralConversionRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateReferralConversionRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("referral_account_sid") + @Getter + private final String referralAccountSid; + + private CreateReferralConversionRequest(Builder builder) { + this.referralAccountSid = builder.referralAccountSid; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateReferralConversionRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateReferralConversionRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("referral_account_sid") + private String referralAccountSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("referral_account_sid") + public Builder referralAccountSid(String referralAccountSid) { + this.referralAccountSid = referralAccountSid; + return this; + } + + public CreateReferralConversionRequest build() { + return new CreateReferralConversionRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateReferralConversionRequest other = + (CreateReferralConversionRequest) o; + return ( + Objects.equals(referralAccountSid, other.referralAccountSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash(referralAccountSid); + } + } + + /** + * Converts a JSON String into a ReferralConversion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ReferralConversion object represented by the provided JSON + */ + public static ReferralConversion fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ReferralConversion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ReferralConversion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ReferralConversion object represented by the provided JSON + */ + public static ReferralConversion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ReferralConversion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String convertedAccountSid; + + @JsonCreator + private ReferralConversion( + @JsonProperty("converted_account_sid") final String convertedAccountSid + ) { + this.convertedAccountSid = convertedAccountSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReferralConversion other = (ReferralConversion) o; + return (Objects.equals(convertedAccountSid, other.convertedAccountSid)); + } + + @Override + public int hashCode() { + return Objects.hash(convertedAccountSid); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/ReferralConversionCreator.java b/src/main/java/com/twilio/rest/marketplace/v1/ReferralConversionCreator.java new file mode 100644 index 0000000000..c2e50eb2f9 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/ReferralConversionCreator.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ReferralConversionCreator extends Creator { + + private ReferralConversion.CreateReferralConversionRequest createReferralConversionRequest; + + public ReferralConversionCreator( + final ReferralConversion.CreateReferralConversionRequest createReferralConversionRequest + ) { + this.createReferralConversionRequest = createReferralConversionRequest; + } + + public ReferralConversionCreator setCreateReferralConversionRequest( + final ReferralConversion.CreateReferralConversionRequest createReferralConversionRequest + ) { + this.createReferralConversionRequest = createReferralConversionRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ReferralConversion"; + + Request request = new Request( + HttpMethod.POST, + Domains.MARKETPLACE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ReferralConversion creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ReferralConversion create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ReferralConversion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ReferralConversion content = ReferralConversion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createReferralConversionRequest != null) { + request.setBody( + ReferralConversion.toJson( + createReferralConversionRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtension.java b/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtension.java new file mode 100644 index 0000000000..627b370a5d --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtension.java @@ -0,0 +1,180 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.availableaddon; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AvailableAddOnExtension extends Resource { + + public static AvailableAddOnExtensionFetcher fetcher( + final String pathAvailableAddOnSid, + final String pathSid + ) { + return new AvailableAddOnExtensionFetcher( + pathAvailableAddOnSid, + pathSid + ); + } + + public static AvailableAddOnExtensionReader reader( + final String pathAvailableAddOnSid + ) { + return new AvailableAddOnExtensionReader(pathAvailableAddOnSid); + } + + /** + * Converts a JSON String into a AvailableAddOnExtension object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AvailableAddOnExtension object represented by the provided JSON + */ + public static AvailableAddOnExtension fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AvailableAddOnExtension.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AvailableAddOnExtension object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AvailableAddOnExtension object represented by the provided JSON + */ + public static AvailableAddOnExtension fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AvailableAddOnExtension.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String availableAddOnSid; + + @Getter + private final String friendlyName; + + @Getter + private final String productName; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private AvailableAddOnExtension( + @JsonProperty("available_add_on_sid") final String availableAddOnSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("product_name") final String productName, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.availableAddOnSid = availableAddOnSid; + this.friendlyName = friendlyName; + this.productName = productName; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AvailableAddOnExtension other = (AvailableAddOnExtension) o; + return ( + Objects.equals(availableAddOnSid, other.availableAddOnSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(productName, other.productName) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + availableAddOnSid, + friendlyName, + productName, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtensionFetcher.java b/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtensionFetcher.java new file mode 100644 index 0000000000..770a9bee38 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtensionFetcher.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.availableaddon; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AvailableAddOnExtensionFetcher + extends Fetcher { + + private String pathAvailableAddOnSid; + private String pathSid; + + public AvailableAddOnExtensionFetcher( + final String pathAvailableAddOnSid, + final String pathSid + ) { + this.pathAvailableAddOnSid = pathAvailableAddOnSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/AvailableAddOns/{AvailableAddOnSid}/Extensions/{Sid}"; + + path = + path.replace( + "{" + "AvailableAddOnSid" + "}", + this.pathAvailableAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AvailableAddOnExtension fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AvailableAddOnExtension fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AvailableAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AvailableAddOnExtension content = AvailableAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtensionReader.java b/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtensionReader.java new file mode 100644 index 0000000000..3025e40a3f --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/availableaddon/AvailableAddOnExtensionReader.java @@ -0,0 +1,216 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.availableaddon; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AvailableAddOnExtensionReader + extends Reader { + + private String pathAvailableAddOnSid; + private Integer pageSize; + + public AvailableAddOnExtensionReader(final String pathAvailableAddOnSid) { + this.pathAvailableAddOnSid = pathAvailableAddOnSid; + } + + public AvailableAddOnExtensionReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + AvailableAddOnExtension.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/AvailableAddOns/{AvailableAddOnSid}/Extensions"; + + path = + path.replace( + "{" + "AvailableAddOnSid" + "}", + this.pathAvailableAddOnSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + AvailableAddOnExtension.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AvailableAddOnExtension read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "extensions", + response.getContent(), + AvailableAddOnExtension.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtension.java b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtension.java new file mode 100644 index 0000000000..779325a4d1 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtension.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.installedaddon; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InstalledAddOnExtension extends Resource { + + public static InstalledAddOnExtensionFetcher fetcher( + final String pathInstalledAddOnSid, + final String pathSid + ) { + return new InstalledAddOnExtensionFetcher( + pathInstalledAddOnSid, + pathSid + ); + } + + public static InstalledAddOnExtensionReader reader( + final String pathInstalledAddOnSid + ) { + return new InstalledAddOnExtensionReader(pathInstalledAddOnSid); + } + + public static InstalledAddOnExtensionUpdater updater( + final String pathInstalledAddOnSid, + final String pathSid, + final Boolean enabled + ) { + return new InstalledAddOnExtensionUpdater( + pathInstalledAddOnSid, + pathSid, + enabled + ); + } + + /** + * Converts a JSON String into a InstalledAddOnExtension object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOnExtension object represented by the provided JSON + */ + public static InstalledAddOnExtension fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InstalledAddOnExtension.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InstalledAddOnExtension object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOnExtension object represented by the provided JSON + */ + public static InstalledAddOnExtension fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InstalledAddOnExtension.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean enabled; + + @Getter + private final String friendlyName; + + @Getter + private final String installedAddOnSid; + + @Getter + private final String productName; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private InstalledAddOnExtension( + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("installed_add_on_sid") final String installedAddOnSid, + @JsonProperty("product_name") final String productName, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.enabled = enabled; + this.friendlyName = friendlyName; + this.installedAddOnSid = installedAddOnSid; + this.productName = productName; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InstalledAddOnExtension other = (InstalledAddOnExtension) o; + return ( + Objects.equals(enabled, other.enabled) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(installedAddOnSid, other.installedAddOnSid) && + Objects.equals(productName, other.productName) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + enabled, + friendlyName, + installedAddOnSid, + productName, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionFetcher.java b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionFetcher.java new file mode 100644 index 0000000000..86a4e2a257 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionFetcher.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.installedaddon; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnExtensionFetcher + extends Fetcher { + + private String pathInstalledAddOnSid; + private String pathSid; + + public InstalledAddOnExtensionFetcher( + final String pathInstalledAddOnSid, + final String pathSid + ) { + this.pathInstalledAddOnSid = pathInstalledAddOnSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}"; + + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOnExtension fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InstalledAddOnExtension fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOnExtension content = InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionReader.java b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionReader.java new file mode 100644 index 0000000000..8028fb8909 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionReader.java @@ -0,0 +1,216 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.installedaddon; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnExtensionReader + extends Reader { + + private String pathInstalledAddOnSid; + private Integer pageSize; + + public InstalledAddOnExtensionReader(final String pathInstalledAddOnSid) { + this.pathInstalledAddOnSid = pathInstalledAddOnSid; + } + + public InstalledAddOnExtensionReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + InstalledAddOnExtension.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/InstalledAddOns/{InstalledAddOnSid}/Extensions"; + + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MARKETPLACE.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + InstalledAddOnExtension.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOnExtension read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "extensions", + response.getContent(), + InstalledAddOnExtension.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionUpdater.java b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionUpdater.java new file mode 100644 index 0000000000..47c7f79865 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnExtensionUpdater.java @@ -0,0 +1,132 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.installedaddon; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnExtensionUpdater + extends Updater { + + private String pathInstalledAddOnSid; + private String pathSid; + private Boolean enabled; + + public InstalledAddOnExtensionUpdater( + final String pathInstalledAddOnSid, + final String pathSid, + final Boolean enabled + ) { + this.pathInstalledAddOnSid = pathInstalledAddOnSid; + this.pathSid = pathSid; + this.enabled = enabled; + } + + public InstalledAddOnExtensionUpdater setEnabled(final Boolean enabled) { + this.enabled = enabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}"; + + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MARKETPLACE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOnExtension update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InstalledAddOnExtension update(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOnExtension content = InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (enabled != null) { + Serializer.toString( + request, + "Enabled", + enabled, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsage.java b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsage.java new file mode 100644 index 0000000000..562f1de4a4 --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsage.java @@ -0,0 +1,363 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.installedaddon; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class InstalledAddOnUsage extends Resource { + + public static InstalledAddOnUsageCreator creator( + final String pathInstalledAddOnSid, + final InstalledAddOnUsage.MarketplaceV1InstalledAddOnInstalledAddOnUsage marketplaceV1InstalledAddOnInstalledAddOnUsage + ) { + return new InstalledAddOnUsageCreator( + pathInstalledAddOnSid, + marketplaceV1InstalledAddOnInstalledAddOnUsage + ); + } + + @JsonDeserialize( + builder = MarketplaceV1InstalledAddOnInstalledAddOnUsage.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MarketplaceV1InstalledAddOnInstalledAddOnUsage { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_submitted") + @Getter + private final BigDecimal totalSubmitted; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("billable_items") + @Getter + private final List< + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems + > billableItems; + + private MarketplaceV1InstalledAddOnInstalledAddOnUsage( + Builder builder + ) { + this.totalSubmitted = builder.totalSubmitted; + this.billableItems = builder.billableItems; + } + + public static Builder builder( + final List< + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems + > billableItems + ) { + return new Builder(billableItems); + } + + public static MarketplaceV1InstalledAddOnInstalledAddOnUsage fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MarketplaceV1InstalledAddOnInstalledAddOnUsage.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("total_submitted") + private BigDecimal totalSubmitted; + + @JsonProperty("billable_items") + private List< + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems + > billableItems; + + @JsonCreator + public Builder( + @JsonProperty("billable_items") final List< + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems + > billableItems + ) { + this.billableItems = billableItems; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("total_submitted") + public Builder totalSubmitted(BigDecimal totalSubmitted) { + this.totalSubmitted = totalSubmitted; + return this; + } + + public MarketplaceV1InstalledAddOnInstalledAddOnUsage build() { + return new MarketplaceV1InstalledAddOnInstalledAddOnUsage(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MarketplaceV1InstalledAddOnInstalledAddOnUsage other = + (MarketplaceV1InstalledAddOnInstalledAddOnUsage) o; + return ( + Objects.equals(totalSubmitted, other.totalSubmitted) && + Objects.equals(billableItems, other.billableItems) + ); + } + + @Override + public int hashCode() { + return Objects.hash(totalSubmitted, billableItems); + } + } + + @JsonDeserialize( + builder = MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("quantity") + @Getter + private final BigDecimal quantity; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sid") + @Getter + private final String sid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("submitted") + @Getter + private final Boolean submitted; + + private MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems( + Builder builder + ) { + this.quantity = builder.quantity; + this.sid = builder.sid; + this.submitted = builder.submitted; + } + + public static Builder builder( + final BigDecimal quantity, + final String sid + ) { + return new Builder(quantity, sid); + } + + public static MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("quantity") + private BigDecimal quantity; + + @JsonProperty("sid") + private String sid; + + @JsonProperty("submitted") + private Boolean submitted; + + @JsonCreator + public Builder( + @JsonProperty("quantity") final BigDecimal quantity, + @JsonProperty("sid") final String sid + ) { + this.quantity = quantity; + this.sid = sid; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("submitted") + public Builder submitted(Boolean submitted) { + this.submitted = submitted; + return this; + } + + public MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems build() { + return new MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems other = + (MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems) o; + return ( + Objects.equals(quantity, other.quantity) && + Objects.equals(sid, other.sid) && + Objects.equals(submitted, other.submitted) + ); + } + + @Override + public int hashCode() { + return Objects.hash(quantity, sid, submitted); + } + } + + /** + * Converts a JSON String into a InstalledAddOnUsage object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOnUsage object represented by the provided JSON + */ + public static InstalledAddOnUsage fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InstalledAddOnUsage.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a InstalledAddOnUsage object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return InstalledAddOnUsage object represented by the provided JSON + */ + public static InstalledAddOnUsage fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, InstalledAddOnUsage.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List< + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems + > billableItems; + + @Getter + private final BigDecimal totalSubmitted; + + @JsonCreator + private InstalledAddOnUsage( + @JsonProperty("billable_items") final List< + MarketplaceV1InstalledAddOnInstalledAddOnUsageBillableItems + > billableItems, + @JsonProperty("total_submitted") final BigDecimal totalSubmitted + ) { + this.billableItems = billableItems; + this.totalSubmitted = totalSubmitted; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + InstalledAddOnUsage other = (InstalledAddOnUsage) o; + return ( + Objects.equals(billableItems, other.billableItems) && + Objects.equals(totalSubmitted, other.totalSubmitted) + ); + } + + @Override + public int hashCode() { + return Objects.hash(billableItems, totalSubmitted); + } +} diff --git a/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsageCreator.java b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsageCreator.java new file mode 100644 index 0000000000..19c47d524e --- /dev/null +++ b/src/main/java/com/twilio/rest/marketplace/v1/installedaddon/InstalledAddOnUsageCreator.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Marketplace + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.marketplace.v1.installedaddon; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnUsageCreator extends Creator { + + private String pathInstalledAddOnSid; + private InstalledAddOnUsage.MarketplaceV1InstalledAddOnInstalledAddOnUsage marketplaceV1InstalledAddOnInstalledAddOnUsage; + + public InstalledAddOnUsageCreator( + final String pathInstalledAddOnSid, + final InstalledAddOnUsage.MarketplaceV1InstalledAddOnInstalledAddOnUsage marketplaceV1InstalledAddOnInstalledAddOnUsage + ) { + this.pathInstalledAddOnSid = pathInstalledAddOnSid; + this.marketplaceV1InstalledAddOnInstalledAddOnUsage = + marketplaceV1InstalledAddOnInstalledAddOnUsage; + } + + public InstalledAddOnUsageCreator setMarketplaceV1InstalledAddOnInstalledAddOnUsage( + final InstalledAddOnUsage.MarketplaceV1InstalledAddOnInstalledAddOnUsage marketplaceV1InstalledAddOnInstalledAddOnUsage + ) { + this.marketplaceV1InstalledAddOnInstalledAddOnUsage = + marketplaceV1InstalledAddOnInstalledAddOnUsage; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/InstalledAddOns/{InstalledAddOnSid}/Usage"; + + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MARKETPLACE.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOnUsage creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public InstalledAddOnUsage create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOnUsage.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOnUsage content = InstalledAddOnUsage.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (marketplaceV1InstalledAddOnInstalledAddOnUsage != null) { + request.setBody( + InstalledAddOnUsage.toJson( + marketplaceV1InstalledAddOnInstalledAddOnUsage, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Bulk.java b/src/main/java/com/twilio/rest/memory/v1/Bulk.java new file mode 100644 index 0000000000..be8c4cd3a9 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Bulk.java @@ -0,0 +1,516 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Bulk extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateBulkResponse extends Resource { + + @JsonCreator + private CreateBulkResponse() {} + + public static CreateBulkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateBulkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateBulkResponse other = (CreateBulkResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateBulkResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String message; + + @Getter + private final String operationId; + + @Getter + private final String statusUrl; + + @JsonCreator + private UpdateBulkResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("message") final String message, + @JsonProperty("operationId") final String operationId, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.createdAt = createdAt; + this.message = message; + this.operationId = operationId; + this.statusUrl = statusUrl; + } + + public static UpdateBulkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateBulkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateBulkResponse other = (UpdateBulkResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(message, other.message) && + Objects.equals(operationId, other.operationId) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(createdAt, message, operationId, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteBulkResponse extends Resource { + + @JsonCreator + private DeleteBulkResponse() {} + + public static DeleteBulkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteBulkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteBulkResponse other = (DeleteBulkResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListBulkResponse extends Resource { + + @JsonCreator + private ListBulkResponse() {} + + public static ListBulkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListBulkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListBulkResponse other = (ListBulkResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchBulkResponse extends Resource { + + @JsonCreator + private PatchBulkResponse() {} + + public static PatchBulkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchBulkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchBulkResponse other = (PatchBulkResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchBulkResponse extends Resource { + + @JsonCreator + private FetchBulkResponse() {} + + public static FetchBulkResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchBulkResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchBulkResponse other = (FetchBulkResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + public static BulkUpdater updater( + final String pathStoreId, + final Bulk.UpdateProfilesBulkRequest updateProfilesBulkRequest + ) { + return new BulkUpdater(pathStoreId, updateProfilesBulkRequest); + } + + @JsonDeserialize(builder = UpdateProfilesBulkRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class UpdateProfilesBulkRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profiles") + @Getter + private final List profiles; + + private UpdateProfilesBulkRequest(Builder builder) { + this.profiles = builder.profiles; + } + + public static Builder builder() { + return new Builder(); + } + + public static UpdateProfilesBulkRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + UpdateProfilesBulkRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("profiles") + private List profiles; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profiles") + public Builder profiles(List profiles) { + this.profiles = profiles; + return this; + } + + public UpdateProfilesBulkRequest build() { + return new UpdateProfilesBulkRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UpdateProfilesBulkRequest other = (UpdateProfilesBulkRequest) o; + return (Objects.equals(profiles, other.profiles)); + } + + @Override + public int hashCode() { + return Objects.hash(profiles); + } + } + + @JsonDeserialize(builder = ProfileData.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ProfileData { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + @Getter + private final Map> traits; + + private ProfileData(Builder builder) { + this.traits = builder.traits; + } + + public static Builder builder() { + return new Builder(); + } + + public static ProfileData fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ProfileData.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("traits") + private Map> traits; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + public Builder traits(Map> traits) { + this.traits = traits; + return this; + } + + public ProfileData build() { + return new ProfileData(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ProfileData other = (ProfileData) o; + return (Objects.equals(traits, other.traits)); + } + + @Override + public int hashCode() { + return Objects.hash(traits); + } + } + + /** + * Converts a JSON String into a Bulk object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Bulk object represented by the provided JSON + */ + public static Bulk fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Bulk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Bulk object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Bulk object represented by the provided JSON + */ + public static Bulk fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Bulk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Bulk() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/BulkUpdater.java b/src/main/java/com/twilio/rest/memory/v1/BulkUpdater.java new file mode 100644 index 0000000000..3a1a6a4329 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/BulkUpdater.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BulkUpdater extends Updater { + + private String pathStoreId; + private Bulk.UpdateProfilesBulkRequest updateProfilesBulkRequest; + + public BulkUpdater( + final String pathStoreId, + final Bulk.UpdateProfilesBulkRequest updateProfilesBulkRequest + ) { + this.pathStoreId = pathStoreId; + this.updateProfilesBulkRequest = updateProfilesBulkRequest; + } + + public BulkUpdater setUpdateProfilesBulkRequest( + final Bulk.UpdateProfilesBulkRequest updateProfilesBulkRequest + ) { + this.updateProfilesBulkRequest = updateProfilesBulkRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/Bulk"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Bulk update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Bulk.UpdateBulkResponse update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Bulk.UpdateBulkResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Bulk.UpdateBulkResponse content = Bulk.UpdateBulkResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (updateProfilesBulkRequest != null) { + request.setBody( + Bulk.toJson(updateProfilesBulkRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ConversationSummary.java b/src/main/java/com/twilio/rest/memory/v1/ConversationSummary.java new file mode 100644 index 0000000000..b143e67682 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ConversationSummary.java @@ -0,0 +1,1195 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ConversationSummary extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateConversationSummaryResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private CreateConversationSummaryResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static CreateConversationSummaryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateConversationSummaryResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateConversationSummaryResponse other = + (CreateConversationSummaryResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateConversationSummaryResponse extends Resource { + + @JsonCreator + private UpdateConversationSummaryResponse() {} + + public static UpdateConversationSummaryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateConversationSummaryResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateConversationSummaryResponse other = + (UpdateConversationSummaryResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteConversationSummaryResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private DeleteConversationSummaryResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static DeleteConversationSummaryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteConversationSummaryResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteConversationSummaryResponse other = + (DeleteConversationSummaryResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListConversationSummaryResponse extends Resource { + + @Getter + private final String content; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final ZonedDateTime occurredAt; + + @Getter + private final String source; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListConversationSummaryResponse( + @JsonProperty("content") final String content, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("source") final String source, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.content = content; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.occurredAt = occurredAt; + this.source = source; + this.updatedAt = updatedAt; + } + + public static ListConversationSummaryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListConversationSummaryResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListConversationSummaryResponse other = + (ListConversationSummaryResponse) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + conversationId, + createdAt, + id, + occurredAt, + source, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchConversationSummaryResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private PatchConversationSummaryResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static PatchConversationSummaryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchConversationSummaryResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchConversationSummaryResponse other = + (PatchConversationSummaryResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchConversationSummaryResponse extends Resource { + + @Getter + private final String content; + + @Getter + private final String conversationId; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final ZonedDateTime occurredAt; + + @Getter + private final String source; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchConversationSummaryResponse( + @JsonProperty("content") final String content, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("source") final String source, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.content = content; + this.conversationId = conversationId; + this.createdAt = createdAt; + this.id = id; + this.occurredAt = occurredAt; + this.source = source; + this.updatedAt = updatedAt; + } + + public static FetchConversationSummaryResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchConversationSummaryResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchConversationSummaryResponse other = + (FetchConversationSummaryResponse) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + conversationId, + createdAt, + id, + occurredAt, + source, + updatedAt + ); + } + } + + public static ConversationSummaryCreator creator( + final String pathStoreId, + final String pathProfileId, + final ConversationSummary.CreateSummariesRequest createSummariesRequest + ) { + return new ConversationSummaryCreator( + pathStoreId, + pathProfileId, + createSummariesRequest + ); + } + + public static ConversationSummaryDeleter deleter( + final String pathStoreId, + final String pathProfileId, + final String pathSummaryId + ) { + return new ConversationSummaryDeleter( + pathStoreId, + pathProfileId, + pathSummaryId + ); + } + + public static ConversationSummaryFetcher fetcher( + final String pathStoreId, + final String pathProfileId, + final String pathSummaryId + ) { + return new ConversationSummaryFetcher( + pathStoreId, + pathProfileId, + pathSummaryId + ); + } + + public static ConversationSummaryReader reader( + final String pathStoreId, + final String pathProfileId + ) { + return new ConversationSummaryReader(pathStoreId, pathProfileId); + } + + public static ConversationSummaryPatcher patcher( + final String pathStoreId, + final String pathProfileId, + final String pathSummaryId, + final ConversationSummary.SummaryCorePatch summaryCorePatch + ) { + return new ConversationSummaryPatcher( + pathStoreId, + pathProfileId, + pathSummaryId, + summaryCorePatch + ); + } + + public enum ContentEncoding { + GZIP("gzip"), + DEFLATE("deflate"), + BR("br"), + COMPRESS("compress"); + + private final String value; + + private ContentEncoding(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ContentEncoding forValue(final String value) { + return Promoter.enumFromString(value, ContentEncoding.values()); + } + } + + @JsonDeserialize(builder = CreateSummariesRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateSummariesRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("summaries") + @Getter + private final List summaries; + + private CreateSummariesRequest(Builder builder) { + this.summaries = builder.summaries; + } + + public static Builder builder(final List summaries) { + return new Builder(summaries); + } + + public static CreateSummariesRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CreateSummariesRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("summaries") + private List summaries; + + @JsonCreator + public Builder( + @JsonProperty("summaries") final List summaries + ) { + this.summaries = summaries; + } + + public CreateSummariesRequest build() { + return new CreateSummariesRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateSummariesRequest other = (CreateSummariesRequest) o; + return (Objects.equals(summaries, other.summaries)); + } + + @Override + public int hashCode() { + return Objects.hash(summaries); + } + } + + @JsonDeserialize(builder = ObservationsMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ObservationsMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private ObservationsMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static ObservationsMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ObservationsMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public ObservationsMeta build() { + return new ObservationsMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ObservationsMeta other = (ObservationsMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = SummaryCorePatch.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SummaryCorePatch { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + private SummaryCorePatch(Builder builder) { + this.source = builder.source; + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.conversationId = builder.conversationId; + } + + public static Builder builder() { + return new Builder(); + } + + public static SummaryCorePatch fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SummaryCorePatch.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("source") + private String source; + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(String source) { + this.source = source; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + public Builder content(String content) { + this.content = content; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + public Builder occurredAt(ZonedDateTime occurredAt) { + this.occurredAt = occurredAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + public Builder conversationId(String conversationId) { + this.conversationId = conversationId; + return this; + } + + public SummaryCorePatch build() { + return new SummaryCorePatch(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SummaryCorePatch other = (SummaryCorePatch) o; + return ( + Objects.equals(source, other.source) && + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(conversationId, other.conversationId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(source, content, occurredAt, conversationId); + } + } + + @JsonDeserialize(builder = SummaryCore.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SummaryCore { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + private SummaryCore(Builder builder) { + this.source = builder.source; + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.conversationId = builder.conversationId; + } + + public static Builder builder( + final String content, + final ZonedDateTime occurredAt, + final String conversationId + ) { + return new Builder(content, occurredAt, conversationId); + } + + public static SummaryCore fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SummaryCore.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("source") + private String source; + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonCreator + public Builder( + @JsonProperty("content") final String content, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("conversationId") final String conversationId + ) { + this.content = content; + this.occurredAt = occurredAt; + this.conversationId = conversationId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(String source) { + this.source = source; + return this; + } + + public SummaryCore build() { + return new SummaryCore(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SummaryCore other = (SummaryCore) o; + return ( + Objects.equals(source, other.source) && + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(conversationId, other.conversationId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(source, content, occurredAt, conversationId); + } + } + + @JsonDeserialize(builder = SummaryInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class SummaryInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + private SummaryInfo(Builder builder) { + this.source = builder.source; + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.conversationId = builder.conversationId; + this.id = builder.id; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + } + + public static Builder builder( + final String content, + final ZonedDateTime occurredAt, + final String conversationId, + final String id, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt + ) { + return new Builder( + content, + occurredAt, + conversationId, + id, + createdAt, + updatedAt + ); + } + + public static SummaryInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, SummaryInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("source") + private String source; + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonProperty("id") + private String id; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonCreator + public Builder( + @JsonProperty("content") final String content, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("id") final String id, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.content = content; + this.occurredAt = occurredAt; + this.conversationId = conversationId; + this.id = id; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(String source) { + this.source = source; + return this; + } + + public SummaryInfo build() { + return new SummaryInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SummaryInfo other = (SummaryInfo) o; + return ( + Objects.equals(source, other.source) && + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(id, other.id) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + source, + content, + occurredAt, + conversationId, + id, + createdAt, + updatedAt + ); + } + } + + /** + * Converts a JSON String into a ConversationSummary object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ConversationSummary object represented by the provided JSON + */ + public static ConversationSummary fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ConversationSummary.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ConversationSummary object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ConversationSummary object represented by the provided JSON + */ + public static ConversationSummary fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ConversationSummary.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private ConversationSummary() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryCreator.java b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryCreator.java new file mode 100644 index 0000000000..65509e99d4 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryCreator.java @@ -0,0 +1,173 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationSummaryCreator + extends Creator { + + private String pathStoreId; + private String pathProfileId; + private String acceptEncoding; + private ConversationSummary.ContentEncoding contentEncoding; + private ConversationSummary.CreateSummariesRequest createSummariesRequest; + + public ConversationSummaryCreator( + final String pathStoreId, + final String pathProfileId, + final ConversationSummary.CreateSummariesRequest createSummariesRequest + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.createSummariesRequest = createSummariesRequest; + } + + public ConversationSummaryCreator setCreateSummariesRequest( + final ConversationSummary.CreateSummariesRequest createSummariesRequest + ) { + this.createSummariesRequest = createSummariesRequest; + return this; + } + + public ConversationSummaryCreator setAcceptEncoding( + final String acceptEncoding + ) { + this.acceptEncoding = acceptEncoding; + return this; + } + + public ConversationSummaryCreator setContentEncoding( + final ConversationSummary.ContentEncoding contentEncoding + ) { + this.contentEncoding = contentEncoding; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConversationSummary creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ConversationSummary.CreateConversationSummaryResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return ConversationSummary.CreateConversationSummaryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + ConversationSummary.CreateConversationSummaryResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + ConversationSummary.CreateConversationSummaryResponse content = + ConversationSummary.CreateConversationSummaryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (acceptEncoding != null) { + Serializer.toString( + request, + "Accept-Encoding", + acceptEncoding, + ParameterType.HEADER + ); + } + + if (contentEncoding != null) { + Serializer.toString( + request, + "Content-Encoding", + contentEncoding, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createSummariesRequest != null) { + request.setBody( + ConversationSummary.toJson(createSummariesRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryDeleter.java b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryDeleter.java new file mode 100644 index 0000000000..02745dbc9b --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryDeleter.java @@ -0,0 +1,125 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ConversationSummaryDeleter + extends ResourceDeleter< + ConversationSummary, + ConversationSummary.DeleteConversationSummaryResponse + > { + + private String pathStoreId; + private String pathProfileId; + private String pathSummaryId; + + public ConversationSummaryDeleter( + final String pathStoreId, + final String pathProfileId, + final String pathSummaryId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathSummaryId = pathSummaryId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "summaryId" + "}", + this.pathSummaryId.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConversationSummary delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ConversationSummary.DeleteConversationSummaryResponse delete( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return ConversationSummary.DeleteConversationSummaryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + ConversationSummary.DeleteConversationSummaryResponse + > deleteWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + ConversationSummary.DeleteConversationSummaryResponse content = + ConversationSummary.DeleteConversationSummaryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryFetcher.java b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryFetcher.java new file mode 100644 index 0000000000..ad81777639 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryFetcher.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationSummaryFetcher + extends Fetcher { + + private String pathStoreId; + private String pathProfileId; + private String pathSummaryId; + + public ConversationSummaryFetcher( + final String pathStoreId, + final String pathProfileId, + final String pathSummaryId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathSummaryId = pathSummaryId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "summaryId" + "}", + this.pathSummaryId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConversationSummary fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ConversationSummary.FetchConversationSummaryResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return ConversationSummary.FetchConversationSummaryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + ConversationSummary.FetchConversationSummaryResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + ConversationSummary.FetchConversationSummaryResponse content = + ConversationSummary.FetchConversationSummaryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryPatcher.java b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryPatcher.java new file mode 100644 index 0000000000..12757e827b --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryPatcher.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationSummaryPatcher + extends Patcher { + + private String pathStoreId; + private String pathProfileId; + private String pathSummaryId; + private ConversationSummary.SummaryCorePatch summaryCorePatch; + + public ConversationSummaryPatcher( + final String pathStoreId, + final String pathProfileId, + final String pathSummaryId, + final ConversationSummary.SummaryCorePatch summaryCorePatch + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathSummaryId = pathSummaryId; + this.summaryCorePatch = summaryCorePatch; + } + + public ConversationSummaryPatcher setSummaryCorePatch( + final ConversationSummary.SummaryCorePatch summaryCorePatch + ) { + this.summaryCorePatch = summaryCorePatch; + return this; + } + + @Override + public ConversationSummary.PatchConversationSummaryResponse patch( + final TwilioRestClient client + ) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries/{summaryId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "summaryId" + "}", + this.pathSummaryId.toString() + ); + + Request request = new Request( + HttpMethod.PATCH, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ConversationSummary patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return ConversationSummary.PatchConversationSummaryResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (summaryCorePatch != null) { + request.setBody( + ConversationSummary.toJson(summaryCorePatch, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryReader.java b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryReader.java new file mode 100644 index 0000000000..63d49e6c25 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ConversationSummaryReader.java @@ -0,0 +1,314 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ConversationSummaryReader + extends Reader { + + private String pathStoreId; + private String pathProfileId; + private Integer pageSize; + private String pageToken; + private String conversationId; + private String acceptEncoding; + + public ConversationSummaryReader( + final String pathStoreId, + final String pathProfileId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + } + + public ConversationSummaryReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ConversationSummaryReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ConversationSummaryReader setConversationId( + final String conversationId + ) { + this.conversationId = conversationId; + return this; + } + + public ConversationSummaryReader setAcceptEncoding( + final String acceptEncoding + ) { + this.acceptEncoding = acceptEncoding; + return this; + } + + public ResourceSetResponse< + ConversationSummary.ListConversationSummaryResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = + Page.fromJson( + "summaries", + response.getContent(), + ConversationSummary.ListConversationSummaryResponse.class, + client.getObjectMapper() + ); + ResourceSet< + ConversationSummary.ListConversationSummaryResponse + > resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet< + ConversationSummary.ListConversationSummaryResponse + > read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = + Page.fromJson( + "summaries", + response.getContent(), + ConversationSummary.ListConversationSummaryResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ConversationSummary read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page< + ConversationSummary.ListConversationSummaryResponse + > pageForRequest(final TwilioRestClient client, final Request request) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "summaries", + response.getContent(), + ConversationSummary.ListConversationSummaryResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page< + ConversationSummary.ListConversationSummaryResponse + > previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/ConversationSummaries"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (conversationId != null) { + Serializer.toString( + request, + "conversationId", + conversationId, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (acceptEncoding != null) { + Serializer.toString( + request, + "Accept-Encoding", + acceptEncoding, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/DataMapping.java b/src/main/java/com/twilio/rest/memory/v1/DataMapping.java new file mode 100644 index 0000000000..6afb69eb3f --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/DataMapping.java @@ -0,0 +1,1510 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DataMapping extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateDataMappingResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private CreateDataMappingResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static CreateDataMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateDataMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateDataMappingResponse other = (CreateDataMappingResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateDataMappingResponse extends Resource { + + @JsonCreator + private UpdateDataMappingResponse() {} + + public static UpdateDataMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateDataMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateDataMappingResponse other = (UpdateDataMappingResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteDataMappingResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private DeleteDataMappingResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static DeleteDataMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteDataMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteDataMappingResponse other = (DeleteDataMappingResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListDataMappingResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final Boolean isEnabled; + + @Getter + private final DataMappingFromTypes mappingFrom; + + @Getter + private final DataMappingToTraits mappingTo; + + @Getter + private final ZonedDateTime updatedAt; + + @Getter + private final Integer version; + + @JsonCreator + private ListDataMappingResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("isEnabled") final Boolean isEnabled, + @JsonProperty("mappingFrom") final DataMappingFromTypes mappingFrom, + @JsonProperty("mappingTo") final DataMappingToTraits mappingTo, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("version") final Integer version + ) { + this.createdAt = createdAt; + this.description = description; + this.displayName = displayName; + this.id = id; + this.isEnabled = isEnabled; + this.mappingFrom = mappingFrom; + this.mappingTo = mappingTo; + this.updatedAt = updatedAt; + this.version = version; + } + + public static ListDataMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListDataMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListDataMappingResponse other = (ListDataMappingResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(isEnabled, other.isEnabled) && + Objects.equals(mappingFrom, other.mappingFrom) && + Objects.equals(mappingTo, other.mappingTo) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + description, + displayName, + id, + isEnabled, + mappingFrom, + mappingTo, + updatedAt, + version + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchDataMappingResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private PatchDataMappingResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static PatchDataMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchDataMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchDataMappingResponse other = (PatchDataMappingResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchDataMappingResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final Boolean isEnabled; + + @Getter + private final DataMappingFromTypes mappingFrom; + + @Getter + private final DataMappingToTraits mappingTo; + + @Getter + private final ZonedDateTime updatedAt; + + @Getter + private final Integer version; + + @JsonCreator + private FetchDataMappingResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty("isEnabled") final Boolean isEnabled, + @JsonProperty("mappingFrom") final DataMappingFromTypes mappingFrom, + @JsonProperty("mappingTo") final DataMappingToTraits mappingTo, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("version") final Integer version + ) { + this.createdAt = createdAt; + this.description = description; + this.displayName = displayName; + this.id = id; + this.isEnabled = isEnabled; + this.mappingFrom = mappingFrom; + this.mappingTo = mappingTo; + this.updatedAt = updatedAt; + this.version = version; + } + + public static FetchDataMappingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchDataMappingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchDataMappingResponse other = (FetchDataMappingResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals(isEnabled, other.isEnabled) && + Objects.equals(mappingFrom, other.mappingFrom) && + Objects.equals(mappingTo, other.mappingTo) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + description, + displayName, + id, + isEnabled, + mappingFrom, + mappingTo, + updatedAt, + version + ); + } + } + + public static DataMappingCreator creator( + final String pathStoreId, + final DataMapping.CreateDataMappingInput createDataMappingInput + ) { + return new DataMappingCreator(pathStoreId, createDataMappingInput); + } + + public static DataMappingDeleter deleter( + final String pathStoreId, + final String pathDataMappingId + ) { + return new DataMappingDeleter(pathStoreId, pathDataMappingId); + } + + public static DataMappingFetcher fetcher( + final String pathStoreId, + final String pathDataMappingId + ) { + return new DataMappingFetcher(pathStoreId, pathDataMappingId); + } + + public static DataMappingReader reader(final String pathStoreId) { + return new DataMappingReader(pathStoreId); + } + + public static DataMappingPatcher patcher( + final String pathStoreId, + final String pathDataMappingId, + final DataMapping.DataMappingCore dataMappingCore + ) { + return new DataMappingPatcher( + pathStoreId, + pathDataMappingId, + dataMappingCore + ); + } + + public enum OrderBy { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private OrderBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderBy forValue(final String value) { + return Promoter.enumFromString(value, OrderBy.values()); + } + } + + public enum Type { + TRAITS("TRAITS"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + public enum DataMappingType { + INGRESS("INGRESS"), + DATASET_CLOUDAPP("DATASET_CLOUDAPP"), + DATASET_WAREHOUSE("DATASET_WAREHOUSE"); + + private final String value; + + private DataMappingType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static DataMappingType forValue(final String value) { + return Promoter.enumFromString(value, DataMappingType.values()); + } + } + + @JsonDeserialize(builder = Meta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Meta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private Meta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static Meta fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Meta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public Meta build() { + return new Meta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Meta other = (Meta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = DataMappingCore.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class DataMappingCore { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isEnabled") + @Getter + private final Boolean isEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mappingTo") + @Getter + private final DataMappingToTraits mappingTo; + + private DataMappingCore(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.isEnabled = builder.isEnabled; + this.mappingTo = builder.mappingTo; + } + + public static Builder builder() { + return new Builder(); + } + + public static DataMappingCore fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, DataMappingCore.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("isEnabled") + private Boolean isEnabled; + + @JsonProperty("mappingTo") + private DataMappingToTraits mappingTo; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isEnabled") + public Builder isEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mappingTo") + public Builder mappingTo(DataMappingToTraits mappingTo) { + this.mappingTo = mappingTo; + return this; + } + + public DataMappingCore build() { + return new DataMappingCore(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DataMappingCore other = (DataMappingCore) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(isEnabled, other.isEnabled) && + Objects.equals(mappingTo, other.mappingTo) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description, isEnabled, mappingTo); + } + } + + @JsonDeserialize(builder = DataMappingFromTypes.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class DataMappingFromTypes { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final DataMapping.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("columns") + @Getter + private final List columns; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("datasetId") + @Getter + private final String datasetId; + + private DataMappingFromTypes(Builder builder) { + this.type = builder.type; + this.columns = builder.columns; + this.datasetId = builder.datasetId; + } + + public static Builder builder() { + return new Builder(); + } + + public static DataMappingFromTypes fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, DataMappingFromTypes.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private DataMapping.Type type; + + @JsonProperty("columns") + private List columns; + + @JsonProperty("datasetId") + private String datasetId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(DataMapping.Type type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("columns") + public Builder columns(List columns) { + this.columns = columns; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("datasetId") + public Builder datasetId(String datasetId) { + this.datasetId = datasetId; + return this; + } + + public DataMappingFromTypes build() { + return new DataMappingFromTypes(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DataMappingFromTypes other = (DataMappingFromTypes) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(columns, other.columns) && + Objects.equals(datasetId, other.datasetId) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, columns, datasetId); + } + } + + @JsonDeserialize(builder = DataMappingToTraits.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class DataMappingToTraits { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final DataMapping.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mappings") + @Getter + private final List mappings; + + private DataMappingToTraits(Builder builder) { + this.type = builder.type; + this.mappings = builder.mappings; + } + + public static Builder builder( + final DataMapping.Type type, + final List mappings + ) { + return new Builder(type, mappings); + } + + public static DataMappingToTraits fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, DataMappingToTraits.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private DataMapping.Type type; + + @JsonProperty("mappings") + private List mappings; + + @JsonCreator + public Builder( + @JsonProperty("type") final DataMapping.Type type, + @JsonProperty("mappings") final List mappings + ) { + this.type = type; + this.mappings = mappings; + } + + public DataMappingToTraits build() { + return new DataMappingToTraits(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DataMappingToTraits other = (DataMappingToTraits) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(mappings, other.mappings) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, mappings); + } + } + + @JsonDeserialize(builder = MappingTraitItem.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MappingTraitItem { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("expression") + @Getter + private final String expression; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitGroup") + @Getter + private final String traitGroup; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitName") + @Getter + private final String traitName; + + private MappingTraitItem(Builder builder) { + this.expression = builder.expression; + this.traitGroup = builder.traitGroup; + this.traitName = builder.traitName; + } + + public static Builder builder( + final String expression, + final String traitGroup, + final String traitName + ) { + return new Builder(expression, traitGroup, traitName); + } + + public static MappingTraitItem fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, MappingTraitItem.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("expression") + private String expression; + + @JsonProperty("traitGroup") + private String traitGroup; + + @JsonProperty("traitName") + private String traitName; + + @JsonCreator + public Builder( + @JsonProperty("expression") final String expression, + @JsonProperty("traitGroup") final String traitGroup, + @JsonProperty("traitName") final String traitName + ) { + this.expression = expression; + this.traitGroup = traitGroup; + this.traitName = traitName; + } + + public MappingTraitItem build() { + return new MappingTraitItem(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MappingTraitItem other = (MappingTraitItem) o; + return ( + Objects.equals(expression, other.expression) && + Objects.equals(traitGroup, other.traitGroup) && + Objects.equals(traitName, other.traitName) + ); + } + + @Override + public int hashCode() { + return Objects.hash(expression, traitGroup, traitName); + } + } + + @JsonDeserialize(builder = CreateDataMappingInput.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateDataMappingInput { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isEnabled") + @Getter + private final Boolean isEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mappingTo") + @Getter + private final DataMappingToTraits mappingTo; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mappingFrom") + @Getter + private final DataMappingFromTypes mappingFrom; + + private CreateDataMappingInput(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.isEnabled = builder.isEnabled; + this.mappingTo = builder.mappingTo; + this.mappingFrom = builder.mappingFrom; + } + + public static Builder builder( + final String displayName, + final DataMappingToTraits mappingTo, + final DataMappingFromTypes mappingFrom + ) { + return new Builder(displayName, mappingTo, mappingFrom); + } + + public static CreateDataMappingInput fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CreateDataMappingInput.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("isEnabled") + private Boolean isEnabled; + + @JsonProperty("mappingTo") + private DataMappingToTraits mappingTo; + + @JsonProperty("mappingFrom") + private DataMappingFromTypes mappingFrom; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName, + @JsonProperty("mappingTo") final DataMappingToTraits mappingTo, + @JsonProperty( + "mappingFrom" + ) final DataMappingFromTypes mappingFrom + ) { + this.displayName = displayName; + this.mappingTo = mappingTo; + this.mappingFrom = mappingFrom; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isEnabled") + public Builder isEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + return this; + } + + public CreateDataMappingInput build() { + return new CreateDataMappingInput(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateDataMappingInput other = (CreateDataMappingInput) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(isEnabled, other.isEnabled) && + Objects.equals(mappingTo, other.mappingTo) && + Objects.equals(mappingFrom, other.mappingFrom) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + displayName, + description, + isEnabled, + mappingTo, + mappingFrom + ); + } + } + + @JsonDeserialize(builder = _DataMapping.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class _DataMapping { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isEnabled") + @Getter + private final Boolean isEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mappingTo") + @Getter + private final DataMappingToTraits mappingTo; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mappingFrom") + @Getter + private final DataMappingFromTypes mappingFrom; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + private _DataMapping(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.isEnabled = builder.isEnabled; + this.mappingTo = builder.mappingTo; + this.mappingFrom = builder.mappingFrom; + this.id = builder.id; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.version = builder.version; + } + + public static Builder builder( + final String displayName, + final DataMappingToTraits mappingTo, + final DataMappingFromTypes mappingFrom, + final String id, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt, + final Integer version + ) { + return new Builder( + displayName, + mappingTo, + mappingFrom, + id, + createdAt, + updatedAt, + version + ); + } + + public static _DataMapping fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, _DataMapping.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("isEnabled") + private Boolean isEnabled; + + @JsonProperty("mappingTo") + private DataMappingToTraits mappingTo; + + @JsonProperty("mappingFrom") + private DataMappingFromTypes mappingFrom; + + @JsonProperty("id") + private String id; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonProperty("version") + private Integer version; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName, + @JsonProperty("mappingTo") final DataMappingToTraits mappingTo, + @JsonProperty( + "mappingFrom" + ) final DataMappingFromTypes mappingFrom, + @JsonProperty("id") final String id, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt, + @JsonProperty("version") final Integer version + ) { + this.displayName = displayName; + this.mappingTo = mappingTo; + this.mappingFrom = mappingFrom; + this.id = id; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.version = version; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isEnabled") + public Builder isEnabled(Boolean isEnabled) { + this.isEnabled = isEnabled; + return this; + } + + public _DataMapping build() { + return new _DataMapping(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + _DataMapping other = (_DataMapping) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(isEnabled, other.isEnabled) && + Objects.equals(mappingTo, other.mappingTo) && + Objects.equals(mappingFrom, other.mappingFrom) && + Objects.equals(id, other.id) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + displayName, + description, + isEnabled, + mappingTo, + mappingFrom, + id, + createdAt, + updatedAt, + version + ); + } + } + + /** + * Converts a JSON String into a DataMapping object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DataMapping object represented by the provided JSON + */ + public static DataMapping fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DataMapping.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DataMapping object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DataMapping object represented by the provided JSON + */ + public static DataMapping fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DataMapping.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private DataMapping() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/DataMappingCreator.java b/src/main/java/com/twilio/rest/memory/v1/DataMappingCreator.java new file mode 100644 index 0000000000..03bda5e393 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/DataMappingCreator.java @@ -0,0 +1,125 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DataMappingCreator + extends Creator { + + private String pathStoreId; + private DataMapping.CreateDataMappingInput createDataMappingInput; + + public DataMappingCreator( + final String pathStoreId, + final DataMapping.CreateDataMappingInput createDataMappingInput + ) { + this.pathStoreId = pathStoreId; + this.createDataMappingInput = createDataMappingInput; + } + + public DataMappingCreator setCreateDataMappingInput( + final DataMapping.CreateDataMappingInput createDataMappingInput + ) { + this.createDataMappingInput = createDataMappingInput; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores/{storeId}/DataMappings"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DataMapping creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DataMapping.CreateDataMappingResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return DataMapping.CreateDataMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + DataMapping.CreateDataMappingResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + DataMapping.CreateDataMappingResponse content = + DataMapping.CreateDataMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createDataMappingInput != null) { + request.setBody( + DataMapping.toJson(createDataMappingInput, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/DataMappingDeleter.java b/src/main/java/com/twilio/rest/memory/v1/DataMappingDeleter.java new file mode 100644 index 0000000000..f3d9d5bc03 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/DataMappingDeleter.java @@ -0,0 +1,117 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class DataMappingDeleter + extends ResourceDeleter< + DataMapping, + DataMapping.DeleteDataMappingResponse + > { + + private String pathStoreId; + private String pathDataMappingId; + + public DataMappingDeleter( + final String pathStoreId, + final String pathDataMappingId + ) { + this.pathStoreId = pathStoreId; + this.pathDataMappingId = pathDataMappingId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ControlPlane/Stores/{storeId}/DataMappings/{dataMappingId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "dataMappingId" + "}", + this.pathDataMappingId.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DataMapping delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DataMapping.DeleteDataMappingResponse delete( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return DataMapping.DeleteDataMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + DataMapping.DeleteDataMappingResponse + > deleteWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + DataMapping.DeleteDataMappingResponse content = + DataMapping.DeleteDataMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/DataMappingFetcher.java b/src/main/java/com/twilio/rest/memory/v1/DataMappingFetcher.java new file mode 100644 index 0000000000..b771a3e2c5 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/DataMappingFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DataMappingFetcher + extends Fetcher { + + private String pathStoreId; + private String pathDataMappingId; + + public DataMappingFetcher( + final String pathStoreId, + final String pathDataMappingId + ) { + this.pathStoreId = pathStoreId; + this.pathDataMappingId = pathDataMappingId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ControlPlane/Stores/{storeId}/DataMappings/{dataMappingId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "dataMappingId" + "}", + this.pathDataMappingId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DataMapping fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DataMapping.FetchDataMappingResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return DataMapping.FetchDataMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + DataMapping.FetchDataMappingResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + DataMapping.FetchDataMappingResponse content = + DataMapping.FetchDataMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/DataMappingPatcher.java b/src/main/java/com/twilio/rest/memory/v1/DataMappingPatcher.java new file mode 100644 index 0000000000..c682a46a22 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/DataMappingPatcher.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DataMappingPatcher + extends Patcher { + + private String pathStoreId; + private String pathDataMappingId; + private String ifMatch; + private DataMapping.DataMappingCore dataMappingCore; + + public DataMappingPatcher( + final String pathStoreId, + final String pathDataMappingId, + final DataMapping.DataMappingCore dataMappingCore + ) { + this.pathStoreId = pathStoreId; + this.pathDataMappingId = pathDataMappingId; + this.dataMappingCore = dataMappingCore; + } + + public DataMappingPatcher setDataMappingCore( + final DataMapping.DataMappingCore dataMappingCore + ) { + this.dataMappingCore = dataMappingCore; + return this; + } + + public DataMappingPatcher setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + @Override + public DataMapping.PatchDataMappingResponse patch( + final TwilioRestClient client + ) { + String path = + "/v1/ControlPlane/Stores/{storeId}/DataMappings/{dataMappingId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "dataMappingId" + "}", + this.pathDataMappingId.toString() + ); + + Request request = new Request( + HttpMethod.PATCH, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DataMapping patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return DataMapping.PatchDataMappingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (dataMappingCore != null) { + request.setBody(DataMapping.toJson(dataMappingCore, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/DataMappingReader.java b/src/main/java/com/twilio/rest/memory/v1/DataMappingReader.java new file mode 100644 index 0000000000..c0ebdc32f6 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/DataMappingReader.java @@ -0,0 +1,275 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DataMappingReader + extends Reader { + + private String pathStoreId; + private Integer pageSize; + private String pageToken; + private DataMapping.OrderBy orderBy; + private DataMapping.DataMappingType type; + + public DataMappingReader(final String pathStoreId) { + this.pathStoreId = pathStoreId; + } + + public DataMappingReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public DataMappingReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public DataMappingReader setOrderBy(final DataMapping.OrderBy orderBy) { + this.orderBy = orderBy; + return this; + } + + public DataMappingReader setType(final DataMapping.DataMappingType type) { + this.type = type; + return this; + } + + public ResourceSetResponse< + DataMapping.ListDataMappingResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "dataMappings", + response.getContent(), + DataMapping.ListDataMappingResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores/{storeId}/DataMappings"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "dataMappings", + response.getContent(), + DataMapping.ListDataMappingResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "DataMapping read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "dataMappings", + response.getContent(), + DataMapping.ListDataMappingResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/ControlPlane/Stores/{storeId}/DataMappings"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/ControlPlane/Stores/{storeId}/DataMappings"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + + if (type != null) { + Serializer.toString(request, "type", type, ParameterType.QUERY); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Identifier.java b/src/main/java/com/twilio/rest/memory/v1/Identifier.java new file mode 100644 index 0000000000..821a264697 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Identifier.java @@ -0,0 +1,717 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Identifier extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateIdentifierResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private CreateIdentifierResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static CreateIdentifierResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateIdentifierResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateIdentifierResponse other = (CreateIdentifierResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateIdentifierResponse extends Resource { + + @JsonCreator + private UpdateIdentifierResponse() {} + + public static UpdateIdentifierResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateIdentifierResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateIdentifierResponse other = (UpdateIdentifierResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteIdentifierResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private DeleteIdentifierResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static DeleteIdentifierResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteIdentifierResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteIdentifierResponse other = (DeleteIdentifierResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListIdentifierResponse extends Resource { + + @Getter + private final String idType; + + @Getter + private final List values; + + @JsonCreator + private ListIdentifierResponse( + @JsonProperty("idType") final String idType, + @JsonProperty("values") final List values + ) { + this.idType = idType; + this.values = values; + } + + public static ListIdentifierResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListIdentifierResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListIdentifierResponse other = (ListIdentifierResponse) o; + return ( + Objects.equals(idType, other.idType) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(idType, values); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchIdentifierResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private PatchIdentifierResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static PatchIdentifierResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchIdentifierResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchIdentifierResponse other = (PatchIdentifierResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchIdentifierResponse extends Resource { + + @Getter + private final String idType; + + @Getter + private final List values; + + @JsonCreator + private FetchIdentifierResponse( + @JsonProperty("idType") final String idType, + @JsonProperty("values") final List values + ) { + this.idType = idType; + this.values = values; + } + + public static FetchIdentifierResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchIdentifierResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchIdentifierResponse other = (FetchIdentifierResponse) o; + return ( + Objects.equals(idType, other.idType) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(idType, values); + } + } + + public static IdentifierCreator creator( + final String pathStoreId, + final String pathProfileId, + final Identifier._Identifier identifier + ) { + return new IdentifierCreator(pathStoreId, pathProfileId, identifier); + } + + public static IdentifierDeleter deleter( + final String pathStoreId, + final String pathProfileId, + final String pathIdType + ) { + return new IdentifierDeleter(pathStoreId, pathProfileId, pathIdType); + } + + public static IdentifierFetcher fetcher( + final String pathStoreId, + final String pathProfileId, + final String pathIdType + ) { + return new IdentifierFetcher(pathStoreId, pathProfileId, pathIdType); + } + + public static IdentifierReader reader( + final String pathStoreId, + final String pathProfileId + ) { + return new IdentifierReader(pathStoreId, pathProfileId); + } + + public static IdentifierPatcher patcher( + final String pathStoreId, + final String pathProfileId, + final String pathIdType, + final Identifier.IdentifierUpdate identifierUpdate + ) { + return new IdentifierPatcher( + pathStoreId, + pathProfileId, + pathIdType, + identifierUpdate + ); + } + + @JsonDeserialize(builder = _Identifier.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class _Identifier { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idType") + @Getter + private final String idType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + @Getter + private final String value; + + private _Identifier(Builder builder) { + this.idType = builder.idType; + this.value = builder.value; + } + + public static Builder builder(final String idType, final String value) { + return new Builder(idType, value); + } + + public static _Identifier fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, _Identifier.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("idType") + private String idType; + + @JsonProperty("value") + private String value; + + @JsonCreator + public Builder( + @JsonProperty("idType") final String idType, + @JsonProperty("value") final String value + ) { + this.idType = idType; + this.value = value; + } + + public _Identifier build() { + return new _Identifier(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + _Identifier other = (_Identifier) o; + return ( + Objects.equals(idType, other.idType) && + Objects.equals(value, other.value) + ); + } + + @Override + public int hashCode() { + return Objects.hash(idType, value); + } + } + + @JsonDeserialize(builder = IdentifierSet.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IdentifierSet { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idType") + @Getter + private final String idType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("values") + @Getter + private final List values; + + private IdentifierSet(Builder builder) { + this.idType = builder.idType; + this.values = builder.values; + } + + public static Builder builder( + final String idType, + final List values + ) { + return new Builder(idType, values); + } + + public static IdentifierSet fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, IdentifierSet.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("idType") + private String idType; + + @JsonProperty("values") + private List values; + + @JsonCreator + public Builder( + @JsonProperty("idType") final String idType, + @JsonProperty("values") final List values + ) { + this.idType = idType; + this.values = values; + } + + public IdentifierSet build() { + return new IdentifierSet(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IdentifierSet other = (IdentifierSet) o; + return ( + Objects.equals(idType, other.idType) && + Objects.equals(values, other.values) + ); + } + + @Override + public int hashCode() { + return Objects.hash(idType, values); + } + } + + @JsonDeserialize(builder = IdentifierUpdate.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IdentifierUpdate { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idType") + @Getter + private final String idType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("oldValue") + @Getter + private final String oldValue; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("newValue") + @Getter + private final String newValue; + + private IdentifierUpdate(Builder builder) { + this.idType = builder.idType; + this.oldValue = builder.oldValue; + this.newValue = builder.newValue; + } + + public static Builder builder( + final String idType, + final String oldValue, + final String newValue + ) { + return new Builder(idType, oldValue, newValue); + } + + public static IdentifierUpdate fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, IdentifierUpdate.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("idType") + private String idType; + + @JsonProperty("oldValue") + private String oldValue; + + @JsonProperty("newValue") + private String newValue; + + @JsonCreator + public Builder( + @JsonProperty("idType") final String idType, + @JsonProperty("oldValue") final String oldValue, + @JsonProperty("newValue") final String newValue + ) { + this.idType = idType; + this.oldValue = oldValue; + this.newValue = newValue; + } + + public IdentifierUpdate build() { + return new IdentifierUpdate(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IdentifierUpdate other = (IdentifierUpdate) o; + return ( + Objects.equals(idType, other.idType) && + Objects.equals(oldValue, other.oldValue) && + Objects.equals(newValue, other.newValue) + ); + } + + @Override + public int hashCode() { + return Objects.hash(idType, oldValue, newValue); + } + } + + /** + * Converts a JSON String into a Identifier object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Identifier object represented by the provided JSON + */ + public static Identifier fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Identifier.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Identifier object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Identifier object represented by the provided JSON + */ + public static Identifier fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Identifier.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Identifier() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/IdentifierCreator.java b/src/main/java/com/twilio/rest/memory/v1/IdentifierCreator.java new file mode 100644 index 0000000000..35875cbe73 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/IdentifierCreator.java @@ -0,0 +1,131 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IdentifierCreator + extends Creator { + + private String pathStoreId; + private String pathProfileId; + private Identifier._Identifier identifier; + + public IdentifierCreator( + final String pathStoreId, + final String pathProfileId, + final Identifier._Identifier identifier + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.identifier = identifier; + } + + public IdentifierCreator setIdentifier( + final Identifier._Identifier identifier + ) { + this.identifier = identifier; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Identifiers"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Identifier creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Identifier.CreateIdentifierResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Identifier.CreateIdentifierResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Identifier.CreateIdentifierResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Identifier.CreateIdentifierResponse content = + Identifier.CreateIdentifierResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (identifier != null) { + request.setBody(Identifier.toJson(identifier, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/IdentifierDeleter.java b/src/main/java/com/twilio/rest/memory/v1/IdentifierDeleter.java new file mode 100644 index 0000000000..4464700637 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/IdentifierDeleter.java @@ -0,0 +1,138 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class IdentifierDeleter + extends ResourceDeleter { + + private String pathStoreId; + private String pathProfileId; + private String pathIdType; + private Boolean removeAll; + + public IdentifierDeleter( + final String pathStoreId, + final String pathProfileId, + final String pathIdType + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathIdType = pathIdType; + } + + public IdentifierDeleter setRemoveAll(final Boolean removeAll) { + this.removeAll = removeAll; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Identifiers/{idType}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = path.replace("{" + "idType" + "}", this.pathIdType.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Identifier delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Identifier.DeleteIdentifierResponse delete( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Identifier.DeleteIdentifierResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Identifier.DeleteIdentifierResponse + > deleteWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Identifier.DeleteIdentifierResponse content = + Identifier.DeleteIdentifierResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (removeAll != null) { + Serializer.toString( + request, + "removeAll", + removeAll, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/IdentifierFetcher.java b/src/main/java/com/twilio/rest/memory/v1/IdentifierFetcher.java new file mode 100644 index 0000000000..b833446ca0 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/IdentifierFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IdentifierFetcher + extends Fetcher { + + private String pathStoreId; + private String pathProfileId; + private String pathIdType; + + public IdentifierFetcher( + final String pathStoreId, + final String pathProfileId, + final String pathIdType + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathIdType = pathIdType; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Identifiers/{idType}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = path.replace("{" + "idType" + "}", this.pathIdType.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Identifier fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Identifier.FetchIdentifierResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Identifier.FetchIdentifierResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Identifier.FetchIdentifierResponse content = + Identifier.FetchIdentifierResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/IdentifierPatcher.java b/src/main/java/com/twilio/rest/memory/v1/IdentifierPatcher.java new file mode 100644 index 0000000000..953de09bbc --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/IdentifierPatcher.java @@ -0,0 +1,114 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IdentifierPatcher + extends Patcher { + + private String pathStoreId; + private String pathProfileId; + private String pathIdType; + private Identifier.IdentifierUpdate identifierUpdate; + + public IdentifierPatcher( + final String pathStoreId, + final String pathProfileId, + final String pathIdType, + final Identifier.IdentifierUpdate identifierUpdate + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathIdType = pathIdType; + this.identifierUpdate = identifierUpdate; + } + + public IdentifierPatcher setIdentifierUpdate( + final Identifier.IdentifierUpdate identifierUpdate + ) { + this.identifierUpdate = identifierUpdate; + return this; + } + + @Override + public Identifier.PatchIdentifierResponse patch( + final TwilioRestClient client + ) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Identifiers/{idType}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = path.replace("{" + "idType" + "}", this.pathIdType.toString()); + + Request request = new Request( + HttpMethod.PATCH, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Identifier patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Identifier.PatchIdentifierResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (identifierUpdate != null) { + request.setBody(Identifier.toJson(identifierUpdate, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/IdentifierReader.java b/src/main/java/com/twilio/rest/memory/v1/IdentifierReader.java new file mode 100644 index 0000000000..ef25b25ce9 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/IdentifierReader.java @@ -0,0 +1,237 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IdentifierReader + extends Reader { + + private String pathStoreId; + private String pathProfileId; + + public IdentifierReader( + final String pathStoreId, + final String pathProfileId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + } + + public ResourceSetResponse< + Identifier.ListIdentifierResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "identifiers", + response.getContent(), + Identifier.ListIdentifierResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Identifiers"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "identifiers", + response.getContent(), + Identifier.ListIdentifierResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Identifier read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "identifiers", + response.getContent(), + Identifier.ListIdentifierResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Identifiers"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Identifiers"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSetting.java b/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSetting.java new file mode 100644 index 0000000000..2785f7d88f --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSetting.java @@ -0,0 +1,772 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class IdentityResolutionSetting extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateIdentityResolutionSettingResponse + extends Resource { + + @JsonCreator + private CreateIdentityResolutionSettingResponse() {} + + public static CreateIdentityResolutionSettingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateIdentityResolutionSettingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateIdentityResolutionSettingResponse other = + (CreateIdentityResolutionSettingResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateIdentityResolutionSettingResponse + extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private UpdateIdentityResolutionSettingResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static UpdateIdentityResolutionSettingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateIdentityResolutionSettingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateIdentityResolutionSettingResponse other = + (UpdateIdentityResolutionSettingResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteIdentityResolutionSettingResponse + extends Resource { + + @JsonCreator + private DeleteIdentityResolutionSettingResponse() {} + + public static DeleteIdentityResolutionSettingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteIdentityResolutionSettingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteIdentityResolutionSettingResponse other = + (DeleteIdentityResolutionSettingResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListIdentityResolutionSettingResponse extends Resource { + + @JsonCreator + private ListIdentityResolutionSettingResponse() {} + + public static ListIdentityResolutionSettingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListIdentityResolutionSettingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListIdentityResolutionSettingResponse other = + (ListIdentityResolutionSettingResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchIdentityResolutionSettingResponse + extends Resource { + + @JsonCreator + private PatchIdentityResolutionSettingResponse() {} + + public static PatchIdentityResolutionSettingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchIdentityResolutionSettingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchIdentityResolutionSettingResponse other = + (PatchIdentityResolutionSettingResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchIdentityResolutionSettingResponse + extends Resource { + + @Getter + private final List identifierConfigs; + + @Getter + private final List matchingRules; + + @Getter + private final Integer version; + + @JsonCreator + private FetchIdentityResolutionSettingResponse( + @JsonProperty("identifierConfigs") final List< + IdentifierConfig + > identifierConfigs, + @JsonProperty("matchingRules") final List matchingRules, + @JsonProperty("version") final Integer version + ) { + this.identifierConfigs = identifierConfigs; + this.matchingRules = matchingRules; + this.version = version; + } + + public static FetchIdentityResolutionSettingResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchIdentityResolutionSettingResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchIdentityResolutionSettingResponse other = + (FetchIdentityResolutionSettingResponse) o; + return ( + Objects.equals(identifierConfigs, other.identifierConfigs) && + Objects.equals(matchingRules, other.matchingRules) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash(identifierConfigs, matchingRules, version); + } + } + + public static IdentityResolutionSettingFetcher fetcher( + final String pathStoreId + ) { + return new IdentityResolutionSettingFetcher(pathStoreId); + } + + public static IdentityResolutionSettingUpdater updater( + final String pathStoreId, + final IdentityResolutionSetting.IdentityResolutionSettingsCore identityResolutionSettingsCore + ) { + return new IdentityResolutionSettingUpdater( + pathStoreId, + identityResolutionSettingsCore + ); + } + + public enum LimitPolicy { + FIFO("fifo"), + LIFO("lifo"); + + private final String value; + + private LimitPolicy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static LimitPolicy forValue(final String value) { + return Promoter.enumFromString(value, LimitPolicy.values()); + } + } + + public enum Normalization { + PHONE("phone"), + EMAIL("email"), + TRIM("trim"), + NONE("none"); + + private final String value; + + private Normalization(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Normalization forValue(final String value) { + return Promoter.enumFromString(value, Normalization.values()); + } + } + + public enum MatchingAlgo { + EXACT("exact"), + FUZZY("fuzzy"); + + private final String value; + + private MatchingAlgo(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static MatchingAlgo forValue(final String value) { + return Promoter.enumFromString(value, MatchingAlgo.values()); + } + } + + @JsonDeserialize(builder = IdentifierConfig.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IdentifierConfig { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idType") + @Getter + private final String idType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("matchingAlgo") + @Getter + private final IdentityResolutionSetting.MatchingAlgo matchingAlgo; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("matchingThreshold") + @Getter + private final Integer matchingThreshold; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("limit") + @Getter + private final Integer limit; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("limitPolicy") + @Getter + private final IdentityResolutionSetting.LimitPolicy limitPolicy; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enforceUnique") + @Getter + private final Boolean enforceUnique; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("normalization") + @Getter + private final IdentityResolutionSetting.Normalization normalization; + + private IdentifierConfig(Builder builder) { + this.idType = builder.idType; + this.matchingAlgo = builder.matchingAlgo; + this.matchingThreshold = builder.matchingThreshold; + this.limit = builder.limit; + this.limitPolicy = builder.limitPolicy; + this.enforceUnique = builder.enforceUnique; + this.normalization = builder.normalization; + } + + public static Builder builder(final String idType) { + return new Builder(idType); + } + + public static IdentifierConfig fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, IdentifierConfig.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("idType") + private String idType; + + @JsonProperty("matchingAlgo") + private IdentityResolutionSetting.MatchingAlgo matchingAlgo; + + @JsonProperty("matchingThreshold") + private Integer matchingThreshold; + + @JsonProperty("limit") + private Integer limit; + + @JsonProperty("limitPolicy") + private IdentityResolutionSetting.LimitPolicy limitPolicy; + + @JsonProperty("enforceUnique") + private Boolean enforceUnique; + + @JsonProperty("normalization") + private IdentityResolutionSetting.Normalization normalization; + + @JsonCreator + public Builder(@JsonProperty("idType") final String idType) { + this.idType = idType; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("matchingAlgo") + public Builder matchingAlgo( + IdentityResolutionSetting.MatchingAlgo matchingAlgo + ) { + this.matchingAlgo = matchingAlgo; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("matchingThreshold") + public Builder matchingThreshold(Integer matchingThreshold) { + this.matchingThreshold = matchingThreshold; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("limit") + public Builder limit(Integer limit) { + this.limit = limit; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("limitPolicy") + public Builder limitPolicy( + IdentityResolutionSetting.LimitPolicy limitPolicy + ) { + this.limitPolicy = limitPolicy; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("enforceUnique") + public Builder enforceUnique(Boolean enforceUnique) { + this.enforceUnique = enforceUnique; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("normalization") + public Builder normalization( + IdentityResolutionSetting.Normalization normalization + ) { + this.normalization = normalization; + return this; + } + + public IdentifierConfig build() { + return new IdentifierConfig(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IdentifierConfig other = (IdentifierConfig) o; + return ( + Objects.equals(idType, other.idType) && + Objects.equals(matchingAlgo, other.matchingAlgo) && + Objects.equals(matchingThreshold, other.matchingThreshold) && + Objects.equals(limit, other.limit) && + Objects.equals(limitPolicy, other.limitPolicy) && + Objects.equals(enforceUnique, other.enforceUnique) && + Objects.equals(normalization, other.normalization) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + idType, + matchingAlgo, + matchingThreshold, + limit, + limitPolicy, + enforceUnique, + normalization + ); + } + } + + @JsonDeserialize(builder = IdentityResolutionSettingsCore.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IdentityResolutionSettingsCore { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("identifierConfigs") + @Getter + private final List identifierConfigs; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("matchingRules") + @Getter + private final List matchingRules; + + private IdentityResolutionSettingsCore(Builder builder) { + this.identifierConfigs = builder.identifierConfigs; + this.matchingRules = builder.matchingRules; + } + + public static Builder builder( + final List identifierConfigs, + final List matchingRules + ) { + return new Builder(identifierConfigs, matchingRules); + } + + public static IdentityResolutionSettingsCore fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + IdentityResolutionSettingsCore.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("identifierConfigs") + private List identifierConfigs; + + @JsonProperty("matchingRules") + private List matchingRules; + + @JsonCreator + public Builder( + @JsonProperty("identifierConfigs") final List< + IdentifierConfig + > identifierConfigs, + @JsonProperty("matchingRules") final List matchingRules + ) { + this.identifierConfigs = identifierConfigs; + this.matchingRules = matchingRules; + } + + public IdentityResolutionSettingsCore build() { + return new IdentityResolutionSettingsCore(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IdentityResolutionSettingsCore other = + (IdentityResolutionSettingsCore) o; + return ( + Objects.equals(identifierConfigs, other.identifierConfigs) && + Objects.equals(matchingRules, other.matchingRules) + ); + } + + @Override + public int hashCode() { + return Objects.hash(identifierConfigs, matchingRules); + } + } + + /** + * Converts a JSON String into a IdentityResolutionSetting object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IdentityResolutionSetting object represented by the provided JSON + */ + public static IdentityResolutionSetting fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + IdentityResolutionSetting.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a IdentityResolutionSetting object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IdentityResolutionSetting object represented by the provided JSON + */ + public static IdentityResolutionSetting fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + IdentityResolutionSetting.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private IdentityResolutionSetting() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSettingFetcher.java b/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSettingFetcher.java new file mode 100644 index 0000000000..7b8f04adde --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSettingFetcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IdentityResolutionSettingFetcher + extends Fetcher< + IdentityResolutionSetting.FetchIdentityResolutionSettingResponse + > { + + private String pathStoreId; + + public IdentityResolutionSettingFetcher(final String pathStoreId) { + this.pathStoreId = pathStoreId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ControlPlane/Stores/{storeId}/IdentityResolutionSettings"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "IdentityResolutionSetting fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public IdentityResolutionSetting.FetchIdentityResolutionSettingResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return IdentityResolutionSetting.FetchIdentityResolutionSettingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + IdentityResolutionSetting.FetchIdentityResolutionSettingResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + IdentityResolutionSetting.FetchIdentityResolutionSettingResponse content = + IdentityResolutionSetting.FetchIdentityResolutionSettingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSettingUpdater.java b/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSettingUpdater.java new file mode 100644 index 0000000000..b6a33b6004 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/IdentityResolutionSettingUpdater.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IdentityResolutionSettingUpdater + extends Updater< + IdentityResolutionSetting.UpdateIdentityResolutionSettingResponse + > { + + private String pathStoreId; + private String ifMatch; + private IdentityResolutionSetting.IdentityResolutionSettingsCore identityResolutionSettingsCore; + + public IdentityResolutionSettingUpdater( + final String pathStoreId, + final IdentityResolutionSetting.IdentityResolutionSettingsCore identityResolutionSettingsCore + ) { + this.pathStoreId = pathStoreId; + this.identityResolutionSettingsCore = identityResolutionSettingsCore; + } + + public IdentityResolutionSettingUpdater setIdentityResolutionSettingsCore( + final IdentityResolutionSetting.IdentityResolutionSettingsCore identityResolutionSettingsCore + ) { + this.identityResolutionSettingsCore = identityResolutionSettingsCore; + return this; + } + + public IdentityResolutionSettingUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ControlPlane/Stores/{storeId}/IdentityResolutionSettings"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "IdentityResolutionSetting update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public IdentityResolutionSetting.UpdateIdentityResolutionSettingResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return IdentityResolutionSetting.UpdateIdentityResolutionSettingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + IdentityResolutionSetting.UpdateIdentityResolutionSettingResponse + > updateWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + IdentityResolutionSetting.UpdateIdentityResolutionSettingResponse content = + IdentityResolutionSetting.UpdateIdentityResolutionSettingResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (identityResolutionSettingsCore != null) { + request.setBody( + IdentityResolutionSetting.toJson( + identityResolutionSettingsCore, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Import.java b/src/main/java/com/twilio/rest/memory/v1/Import.java new file mode 100644 index 0000000000..baaab54489 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Import.java @@ -0,0 +1,925 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Import extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateImportResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String importId; + + @Getter + private final String operationId; + + @Getter + private final String statusUrl; + + @Getter + private final String url; + + @JsonCreator + private CreateImportResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("importId") final String importId, + @JsonProperty("operationId") final String operationId, + @JsonProperty("statusUrl") final String statusUrl, + @JsonProperty("url") final String url + ) { + this.createdAt = createdAt; + this.importId = importId; + this.operationId = operationId; + this.statusUrl = statusUrl; + this.url = url; + } + + public static CreateImportResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateImportResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateImportResponse other = (CreateImportResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(importId, other.importId) && + Objects.equals(operationId, other.operationId) && + Objects.equals(statusUrl, other.statusUrl) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + createdAt, + importId, + operationId, + statusUrl, + url + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateImportResponse extends Resource { + + @JsonCreator + private UpdateImportResponse() {} + + public static UpdateImportResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateImportResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateImportResponse other = (UpdateImportResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteImportResponse extends Resource { + + @JsonCreator + private DeleteImportResponse() {} + + public static DeleteImportResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteImportResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteImportResponse other = (DeleteImportResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListImportResponse extends Resource { + + @Getter + private final List imports; + + @JsonCreator + private ListImportResponse( + @JsonProperty("imports") final List imports + ) { + this.imports = imports; + } + + public static ListImportResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListImportResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListImportResponse other = (ListImportResponse) o; + return (Objects.equals(imports, other.imports)); + } + + @Override + public int hashCode() { + return Objects.hash(imports); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchImportResponse extends Resource { + + @JsonCreator + private PatchImportResponse() {} + + public static PatchImportResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchImportResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchImportResponse other = (PatchImportResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchImportResponse extends Resource { + + @Getter + private final List columnMappings; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final Integer fileSize; + + @Getter + private final String filename; + + @Getter + private final Import.Status status; + + @Getter + private final FetchProfileImportV2200ResponseSummary summary; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchImportResponse( + @JsonProperty("columnMappings") final List< + ColumnMappingItem + > columnMappings, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("fileSize") final Integer fileSize, + @JsonProperty("filename") final String filename, + @JsonProperty("status") final Import.Status status, + @JsonProperty( + "summary" + ) final FetchProfileImportV2200ResponseSummary summary, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.columnMappings = columnMappings; + this.createdAt = createdAt; + this.fileSize = fileSize; + this.filename = filename; + this.status = status; + this.summary = summary; + this.updatedAt = updatedAt; + } + + public static FetchImportResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchImportResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchImportResponse other = (FetchImportResponse) o; + return ( + Objects.equals(columnMappings, other.columnMappings) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(fileSize, other.fileSize) && + Objects.equals(filename, other.filename) && + Objects.equals(status, other.status) && + Objects.equals(summary, other.summary) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + columnMappings, + createdAt, + fileSize, + filename, + status, + summary, + updatedAt + ); + } + } + + public static ImportCreator creator( + final String pathStoreId, + final Import.CreateProfilesImportV2Request createProfilesImportV2Request + ) { + return new ImportCreator(pathStoreId, createProfilesImportV2Request); + } + + public static ImportFetcher fetcher( + final String pathStoreId, + final String pathImportId + ) { + return new ImportFetcher(pathStoreId, pathImportId); + } + + public static ImportReader reader(final String pathStoreId) { + return new ImportReader(pathStoreId); + } + + public enum Status { + PENDING("PENDING"), + PROCESSING("PROCESSING"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum OrderBy { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private OrderBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderBy forValue(final String value) { + return Promoter.enumFromString(value, OrderBy.values()); + } + } + + @JsonDeserialize( + builder = FetchProfileImportV2200ResponseSummary.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class FetchProfileImportV2200ResponseSummary { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("errors") + @Getter + private final Integer errors; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("warnings") + @Getter + private final Integer warnings; + + private FetchProfileImportV2200ResponseSummary(Builder builder) { + this.errors = builder.errors; + this.warnings = builder.warnings; + } + + public static Builder builder() { + return new Builder(); + } + + public static FetchProfileImportV2200ResponseSummary fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + FetchProfileImportV2200ResponseSummary.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("errors") + private Integer errors; + + @JsonProperty("warnings") + private Integer warnings; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("errors") + public Builder errors(Integer errors) { + this.errors = errors; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("warnings") + public Builder warnings(Integer warnings) { + this.warnings = warnings; + return this; + } + + public FetchProfileImportV2200ResponseSummary build() { + return new FetchProfileImportV2200ResponseSummary(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FetchProfileImportV2200ResponseSummary other = + (FetchProfileImportV2200ResponseSummary) o; + return ( + Objects.equals(errors, other.errors) && + Objects.equals(warnings, other.warnings) + ); + } + + @Override + public int hashCode() { + return Objects.hash(errors, warnings); + } + } + + @JsonDeserialize(builder = CreateProfilesImportV2Request.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateProfilesImportV2Request { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("filename") + @Getter + private final String filename; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fileSize") + @Getter + private final Integer fileSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("columnMappings") + @Getter + private final List columnMappings; + + private CreateProfilesImportV2Request(Builder builder) { + this.filename = builder.filename; + this.fileSize = builder.fileSize; + this.columnMappings = builder.columnMappings; + } + + public static Builder builder( + final String filename, + final Integer fileSize, + final List columnMappings + ) { + return new Builder(filename, fileSize, columnMappings); + } + + public static CreateProfilesImportV2Request fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateProfilesImportV2Request.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("filename") + private String filename; + + @JsonProperty("fileSize") + private Integer fileSize; + + @JsonProperty("columnMappings") + private List columnMappings; + + @JsonCreator + public Builder( + @JsonProperty("filename") final String filename, + @JsonProperty("fileSize") final Integer fileSize, + @JsonProperty("columnMappings") final List< + ColumnMappingItem + > columnMappings + ) { + this.filename = filename; + this.fileSize = fileSize; + this.columnMappings = columnMappings; + } + + public CreateProfilesImportV2Request build() { + return new CreateProfilesImportV2Request(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateProfilesImportV2Request other = + (CreateProfilesImportV2Request) o; + return ( + Objects.equals(filename, other.filename) && + Objects.equals(fileSize, other.fileSize) && + Objects.equals(columnMappings, other.columnMappings) + ); + } + + @Override + public int hashCode() { + return Objects.hash(filename, fileSize, columnMappings); + } + } + + @JsonDeserialize( + builder = ListProfileImportsV2200ResponseMeta.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListProfileImportsV2200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final Object key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private ListProfileImportsV2200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static ListProfileImportsV2200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListProfileImportsV2200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private Object key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(Object key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public ListProfileImportsV2200ResponseMeta build() { + return new ListProfileImportsV2200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListProfileImportsV2200ResponseMeta other = + (ListProfileImportsV2200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = ColumnMappingItem.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ColumnMappingItem { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("columnName") + @Getter + private final String columnName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitGroup") + @Getter + private final String traitGroup; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitName") + @Getter + private final String traitName; + + private ColumnMappingItem(Builder builder) { + this.columnName = builder.columnName; + this.traitGroup = builder.traitGroup; + this.traitName = builder.traitName; + } + + public static Builder builder( + final String columnName, + final String traitGroup, + final String traitName + ) { + return new Builder(columnName, traitGroup, traitName); + } + + public static ColumnMappingItem fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ColumnMappingItem.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("columnName") + private String columnName; + + @JsonProperty("traitGroup") + private String traitGroup; + + @JsonProperty("traitName") + private String traitName; + + @JsonCreator + public Builder( + @JsonProperty("columnName") final String columnName, + @JsonProperty("traitGroup") final String traitGroup, + @JsonProperty("traitName") final String traitName + ) { + this.columnName = columnName; + this.traitGroup = traitGroup; + this.traitName = traitName; + } + + public ColumnMappingItem build() { + return new ColumnMappingItem(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ColumnMappingItem other = (ColumnMappingItem) o; + return ( + Objects.equals(columnName, other.columnName) && + Objects.equals(traitGroup, other.traitGroup) && + Objects.equals(traitName, other.traitName) + ); + } + + @Override + public int hashCode() { + return Objects.hash(columnName, traitGroup, traitName); + } + } + + /** + * Converts a JSON String into a Import object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Import object represented by the provided JSON + */ + public static Import fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Import.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Import object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Import object represented by the provided JSON + */ + public static Import fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Import.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Import() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ImportCreator.java b/src/main/java/com/twilio/rest/memory/v1/ImportCreator.java new file mode 100644 index 0000000000..f71a0a253d --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ImportCreator.java @@ -0,0 +1,122 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ImportCreator extends Creator { + + private String pathStoreId; + private Import.CreateProfilesImportV2Request createProfilesImportV2Request; + + public ImportCreator( + final String pathStoreId, + final Import.CreateProfilesImportV2Request createProfilesImportV2Request + ) { + this.pathStoreId = pathStoreId; + this.createProfilesImportV2Request = createProfilesImportV2Request; + } + + public ImportCreator setCreateProfilesImportV2Request( + final Import.CreateProfilesImportV2Request createProfilesImportV2Request + ) { + this.createProfilesImportV2Request = createProfilesImportV2Request; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/Imports"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Import creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Import.CreateImportResponse create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Import.CreateImportResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Import.CreateImportResponse content = + Import.CreateImportResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createProfilesImportV2Request != null) { + request.setBody( + Import.toJson(createProfilesImportV2Request, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ImportFetcher.java b/src/main/java/com/twilio/rest/memory/v1/ImportFetcher.java new file mode 100644 index 0000000000..c8579a5b8a --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ImportFetcher.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ImportFetcher extends Fetcher { + + private String pathStoreId; + private String pathImportId; + + public ImportFetcher(final String pathStoreId, final String pathImportId) { + this.pathStoreId = pathStoreId; + this.pathImportId = pathImportId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/Imports/{importId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace("{" + "importId" + "}", this.pathImportId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Import fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Import.FetchImportResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Import.FetchImportResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Import.FetchImportResponse content = + Import.FetchImportResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ImportReader.java b/src/main/java/com/twilio/rest/memory/v1/ImportReader.java new file mode 100644 index 0000000000..ac50a17797 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ImportReader.java @@ -0,0 +1,267 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ImportReader extends Reader { + + private String pathStoreId; + private Integer pageSize; + private String pageToken; + private Import.OrderBy orderBy; + + public ImportReader(final String pathStoreId) { + this.pathStoreId = pathStoreId; + } + + public ImportReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ImportReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ImportReader setOrderBy(final Import.OrderBy orderBy) { + this.orderBy = orderBy; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "imports", + response.getContent(), + Import.ListImportResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/Imports"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "imports", + response.getContent(), + Import.ListImportResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Import read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "imports", + response.getContent(), + Import.ListImportResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles/Imports"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles/Imports"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Lookup.java b/src/main/java/com/twilio/rest/memory/v1/Lookup.java new file mode 100644 index 0000000000..3c24e0a15e --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Lookup.java @@ -0,0 +1,448 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Lookup extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateLookupResponse extends Resource { + + @Getter + private final String normalizedValue; + + @Getter + private final List profiles; + + @JsonCreator + private CreateLookupResponse( + @JsonProperty("normalizedValue") final String normalizedValue, + @JsonProperty("profiles") final List profiles + ) { + this.normalizedValue = normalizedValue; + this.profiles = profiles; + } + + public static CreateLookupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateLookupResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateLookupResponse other = (CreateLookupResponse) o; + return ( + Objects.equals(normalizedValue, other.normalizedValue) && + Objects.equals(profiles, other.profiles) + ); + } + + @Override + public int hashCode() { + return Objects.hash(normalizedValue, profiles); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateLookupResponse extends Resource { + + @JsonCreator + private UpdateLookupResponse() {} + + public static UpdateLookupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateLookupResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateLookupResponse other = (UpdateLookupResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteLookupResponse extends Resource { + + @JsonCreator + private DeleteLookupResponse() {} + + public static DeleteLookupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteLookupResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteLookupResponse other = (DeleteLookupResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListLookupResponse extends Resource { + + @JsonCreator + private ListLookupResponse() {} + + public static ListLookupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListLookupResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListLookupResponse other = (ListLookupResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchLookupResponse extends Resource { + + @JsonCreator + private PatchLookupResponse() {} + + public static PatchLookupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchLookupResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchLookupResponse other = (PatchLookupResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchLookupResponse extends Resource { + + @JsonCreator + private FetchLookupResponse() {} + + public static FetchLookupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchLookupResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchLookupResponse other = (FetchLookupResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + public static LookupCreator creator( + final String pathStoreId, + final Lookup.Identifier identifier + ) { + return new LookupCreator(pathStoreId, identifier); + } + + @JsonDeserialize(builder = Identifier.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Identifier { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idType") + @Getter + private final String idType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + @Getter + private final String value; + + private Identifier(Builder builder) { + this.idType = builder.idType; + this.value = builder.value; + } + + public static Builder builder(final String idType, final String value) { + return new Builder(idType, value); + } + + public static Identifier fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, Identifier.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("idType") + private String idType; + + @JsonProperty("value") + private String value; + + @JsonCreator + public Builder( + @JsonProperty("idType") final String idType, + @JsonProperty("value") final String value + ) { + this.idType = idType; + this.value = value; + } + + public Identifier build() { + return new Identifier(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Identifier other = (Identifier) o; + return ( + Objects.equals(idType, other.idType) && + Objects.equals(value, other.value) + ); + } + + @Override + public int hashCode() { + return Objects.hash(idType, value); + } + } + + /** + * Converts a JSON String into a Lookup object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Lookup object represented by the provided JSON + */ + public static Lookup fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Lookup.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Lookup object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Lookup object represented by the provided JSON + */ + public static Lookup fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Lookup.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Lookup() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/LookupCreator.java b/src/main/java/com/twilio/rest/memory/v1/LookupCreator.java new file mode 100644 index 0000000000..8b6195e5fe --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/LookupCreator.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class LookupCreator extends Creator { + + private String pathStoreId; + private Lookup.Identifier identifier; + + public LookupCreator( + final String pathStoreId, + final Lookup.Identifier identifier + ) { + this.pathStoreId = pathStoreId; + this.identifier = identifier; + } + + public LookupCreator setIdentifier(final Lookup.Identifier identifier) { + this.identifier = identifier; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/Lookup"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Lookup creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Lookup.CreateLookupResponse create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Lookup.CreateLookupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Lookup.CreateLookupResponse content = + Lookup.CreateLookupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (identifier != null) { + request.setBody(Lookup.toJson(identifier, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Observation.java b/src/main/java/com/twilio/rest/memory/v1/Observation.java new file mode 100644 index 0000000000..4687b78d8f --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Observation.java @@ -0,0 +1,1226 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Observation extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateObservationResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private CreateObservationResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static CreateObservationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateObservationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateObservationResponse other = (CreateObservationResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateObservationResponse extends Resource { + + @JsonCreator + private UpdateObservationResponse() {} + + public static UpdateObservationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateObservationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateObservationResponse other = (UpdateObservationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteObservationResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private DeleteObservationResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static DeleteObservationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteObservationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteObservationResponse other = (DeleteObservationResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListObservationResponse extends Resource { + + @Getter + private final String content; + + @Getter + private final List conversationIds; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final ZonedDateTime occurredAt; + + @Getter + private final String source; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListObservationResponse( + @JsonProperty("content") final String content, + @JsonProperty("conversationIds") final List conversationIds, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("source") final String source, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.content = content; + this.conversationIds = conversationIds; + this.createdAt = createdAt; + this.id = id; + this.occurredAt = occurredAt; + this.source = source; + this.updatedAt = updatedAt; + } + + public static ListObservationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListObservationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListObservationResponse other = (ListObservationResponse) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(conversationIds, other.conversationIds) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + conversationIds, + createdAt, + id, + occurredAt, + source, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchObservationResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private PatchObservationResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static PatchObservationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchObservationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchObservationResponse other = (PatchObservationResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchObservationResponse extends Resource { + + @Getter + private final String content; + + @Getter + private final List conversationIds; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final ZonedDateTime occurredAt; + + @Getter + private final String source; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private FetchObservationResponse( + @JsonProperty("content") final String content, + @JsonProperty("conversationIds") final List conversationIds, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("source") final String source, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.content = content; + this.conversationIds = conversationIds; + this.createdAt = createdAt; + this.id = id; + this.occurredAt = occurredAt; + this.source = source; + this.updatedAt = updatedAt; + } + + public static FetchObservationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchObservationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchObservationResponse other = (FetchObservationResponse) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(conversationIds, other.conversationIds) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + conversationIds, + createdAt, + id, + occurredAt, + source, + updatedAt + ); + } + } + + public static ObservationCreator creator( + final String pathStoreId, + final String pathProfileId, + final Observation.CreateObservationsRequest createObservationsRequest + ) { + return new ObservationCreator( + pathStoreId, + pathProfileId, + createObservationsRequest + ); + } + + public static ObservationDeleter deleter( + final String pathStoreId, + final String pathProfileId, + final String pathObservationId + ) { + return new ObservationDeleter( + pathStoreId, + pathProfileId, + pathObservationId + ); + } + + public static ObservationFetcher fetcher( + final String pathStoreId, + final String pathProfileId, + final String pathObservationId + ) { + return new ObservationFetcher( + pathStoreId, + pathProfileId, + pathObservationId + ); + } + + public static ObservationReader reader( + final String pathStoreId, + final String pathProfileId + ) { + return new ObservationReader(pathStoreId, pathProfileId); + } + + public static ObservationPatcher patcher( + final String pathStoreId, + final String pathProfileId, + final String pathObservationId, + final Observation.ObservationBase observationBase + ) { + return new ObservationPatcher( + pathStoreId, + pathProfileId, + pathObservationId, + observationBase + ); + } + + public enum OrderBy { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private OrderBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderBy forValue(final String value) { + return Promoter.enumFromString(value, OrderBy.values()); + } + } + + public enum ContentEncoding { + GZIP("gzip"), + DEFLATE("deflate"), + BR("br"), + COMPRESS("compress"); + + private final String value; + + private ContentEncoding(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ContentEncoding forValue(final String value) { + return Promoter.enumFromString(value, ContentEncoding.values()); + } + } + + @JsonDeserialize(builder = ObservationBase.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ObservationBase { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + @Getter + private final List conversationIds; + + private ObservationBase(Builder builder) { + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.source = builder.source; + this.conversationIds = builder.conversationIds; + } + + public static Builder builder() { + return new Builder(); + } + + public static ObservationBase fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ObservationBase.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("source") + private String source; + + @JsonProperty("conversationIds") + private List conversationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + public Builder content(String content) { + this.content = content; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + public Builder occurredAt(ZonedDateTime occurredAt) { + this.occurredAt = occurredAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(String source) { + this.source = source; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + public Builder conversationIds(List conversationIds) { + this.conversationIds = conversationIds; + return this; + } + + public ObservationBase build() { + return new ObservationBase(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ObservationBase other = (ObservationBase) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(conversationIds, other.conversationIds) + ); + } + + @Override + public int hashCode() { + return Objects.hash(content, occurredAt, source, conversationIds); + } + } + + @JsonDeserialize(builder = ObservationCreateRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ObservationCreateRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + @Getter + private final List conversationIds; + + private ObservationCreateRequest(Builder builder) { + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.source = builder.source; + this.conversationIds = builder.conversationIds; + } + + public static Builder builder( + final String content, + final ZonedDateTime occurredAt, + final String source + ) { + return new Builder(content, occurredAt, source); + } + + public static ObservationCreateRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ObservationCreateRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("source") + private String source; + + @JsonProperty("conversationIds") + private List conversationIds; + + @JsonCreator + public Builder( + @JsonProperty("content") final String content, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("source") final String source + ) { + this.content = content; + this.occurredAt = occurredAt; + this.source = source; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + public Builder conversationIds(List conversationIds) { + this.conversationIds = conversationIds; + return this; + } + + public ObservationCreateRequest build() { + return new ObservationCreateRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ObservationCreateRequest other = (ObservationCreateRequest) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(conversationIds, other.conversationIds) + ); + } + + @Override + public int hashCode() { + return Objects.hash(content, occurredAt, source, conversationIds); + } + } + + @JsonDeserialize(builder = ObservationsMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ObservationsMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private ObservationsMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static ObservationsMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ObservationsMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public ObservationsMeta build() { + return new ObservationsMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ObservationsMeta other = (ObservationsMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = CreateObservationsRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateObservationsRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observations") + @Getter + private final List observations; + + private CreateObservationsRequest(Builder builder) { + this.observations = builder.observations; + } + + public static Builder builder( + final List observations + ) { + return new Builder(observations); + } + + public static CreateObservationsRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateObservationsRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("observations") + private List observations; + + @JsonCreator + public Builder( + @JsonProperty("observations") final List< + ObservationCreateRequest + > observations + ) { + this.observations = observations; + } + + public CreateObservationsRequest build() { + return new CreateObservationsRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateObservationsRequest other = (CreateObservationsRequest) o; + return (Objects.equals(observations, other.observations)); + } + + @Override + public int hashCode() { + return Objects.hash(observations); + } + } + + @JsonDeserialize(builder = ObservationInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ObservationInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + @Getter + private final List conversationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + private ObservationInfo(Builder builder) { + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.source = builder.source; + this.conversationIds = builder.conversationIds; + this.id = builder.id; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + } + + public static Builder builder( + final String id, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt + ) { + return new Builder(id, createdAt, updatedAt); + } + + public static ObservationInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ObservationInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("source") + private String source; + + @JsonProperty("conversationIds") + private List conversationIds; + + @JsonProperty("id") + private String id; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.id = id; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + public Builder content(String content) { + this.content = content; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + public Builder occurredAt(ZonedDateTime occurredAt) { + this.occurredAt = occurredAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(String source) { + this.source = source; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + public Builder conversationIds(List conversationIds) { + this.conversationIds = conversationIds; + return this; + } + + public ObservationInfo build() { + return new ObservationInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ObservationInfo other = (ObservationInfo) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(conversationIds, other.conversationIds) && + Objects.equals(id, other.id) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + occurredAt, + source, + conversationIds, + id, + createdAt, + updatedAt + ); + } + } + + /** + * Converts a JSON String into a Observation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Observation object represented by the provided JSON + */ + public static Observation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Observation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Observation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Observation object represented by the provided JSON + */ + public static Observation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Observation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Observation() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ObservationCreator.java b/src/main/java/com/twilio/rest/memory/v1/ObservationCreator.java new file mode 100644 index 0000000000..10b76dcffd --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ObservationCreator.java @@ -0,0 +1,170 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ObservationCreator + extends Creator { + + private String pathStoreId; + private String pathProfileId; + private String acceptEncoding; + private Observation.ContentEncoding contentEncoding; + private Observation.CreateObservationsRequest createObservationsRequest; + + public ObservationCreator( + final String pathStoreId, + final String pathProfileId, + final Observation.CreateObservationsRequest createObservationsRequest + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.createObservationsRequest = createObservationsRequest; + } + + public ObservationCreator setCreateObservationsRequest( + final Observation.CreateObservationsRequest createObservationsRequest + ) { + this.createObservationsRequest = createObservationsRequest; + return this; + } + + public ObservationCreator setAcceptEncoding(final String acceptEncoding) { + this.acceptEncoding = acceptEncoding; + return this; + } + + public ObservationCreator setContentEncoding( + final Observation.ContentEncoding contentEncoding + ) { + this.contentEncoding = contentEncoding; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Observations"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Observation creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Observation.CreateObservationResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Observation.CreateObservationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Observation.CreateObservationResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Observation.CreateObservationResponse content = + Observation.CreateObservationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (acceptEncoding != null) { + Serializer.toString( + request, + "Accept-Encoding", + acceptEncoding, + ParameterType.HEADER + ); + } + + if (contentEncoding != null) { + Serializer.toString( + request, + "Content-Encoding", + contentEncoding, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createObservationsRequest != null) { + request.setBody( + Observation.toJson(createObservationsRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ObservationDeleter.java b/src/main/java/com/twilio/rest/memory/v1/ObservationDeleter.java new file mode 100644 index 0000000000..9f3f6afc0f --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ObservationDeleter.java @@ -0,0 +1,125 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ObservationDeleter + extends ResourceDeleter< + Observation, + Observation.DeleteObservationResponse + > { + + private String pathStoreId; + private String pathProfileId; + private String pathObservationId; + + public ObservationDeleter( + final String pathStoreId, + final String pathProfileId, + final String pathObservationId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathObservationId = pathObservationId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Observations/{observationId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "observationId" + "}", + this.pathObservationId.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Observation delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Observation.DeleteObservationResponse delete( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Observation.DeleteObservationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Observation.DeleteObservationResponse + > deleteWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Observation.DeleteObservationResponse content = + Observation.DeleteObservationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ObservationFetcher.java b/src/main/java/com/twilio/rest/memory/v1/ObservationFetcher.java new file mode 100644 index 0000000000..2708a9bb7f --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ObservationFetcher.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ObservationFetcher + extends Fetcher { + + private String pathStoreId; + private String pathProfileId; + private String pathObservationId; + + public ObservationFetcher( + final String pathStoreId, + final String pathProfileId, + final String pathObservationId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathObservationId = pathObservationId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Observations/{observationId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "observationId" + "}", + this.pathObservationId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Observation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Observation.FetchObservationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Observation.FetchObservationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + Observation.FetchObservationResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + Observation.FetchObservationResponse content = + Observation.FetchObservationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ObservationPatcher.java b/src/main/java/com/twilio/rest/memory/v1/ObservationPatcher.java new file mode 100644 index 0000000000..e04a34a452 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ObservationPatcher.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ObservationPatcher + extends Patcher { + + private String pathStoreId; + private String pathProfileId; + private String pathObservationId; + private Observation.ObservationBase observationBase; + + public ObservationPatcher( + final String pathStoreId, + final String pathProfileId, + final String pathObservationId, + final Observation.ObservationBase observationBase + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathObservationId = pathObservationId; + this.observationBase = observationBase; + } + + public ObservationPatcher setObservationBase( + final Observation.ObservationBase observationBase + ) { + this.observationBase = observationBase; + return this; + } + + @Override + public Observation.PatchObservationResponse patch( + final TwilioRestClient client + ) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Observations/{observationId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "observationId" + "}", + this.pathObservationId.toString() + ); + + Request request = new Request( + HttpMethod.PATCH, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Observation patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Observation.PatchObservationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (observationBase != null) { + request.setBody(Observation.toJson(observationBase, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ObservationReader.java b/src/main/java/com/twilio/rest/memory/v1/ObservationReader.java new file mode 100644 index 0000000000..6e6c880ef7 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ObservationReader.java @@ -0,0 +1,361 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ObservationReader + extends Reader { + + private String pathStoreId; + private String pathProfileId; + private Integer pageSize; + private String pageToken; + private Observation.OrderBy orderBy; + private String source; + private ZonedDateTime createdAfter; + private ZonedDateTime createdBefore; + private String conversationId; + private String acceptEncoding; + + public ObservationReader( + final String pathStoreId, + final String pathProfileId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + } + + public ObservationReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ObservationReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ObservationReader setOrderBy(final Observation.OrderBy orderBy) { + this.orderBy = orderBy; + return this; + } + + public ObservationReader setSource(final String source) { + this.source = source; + return this; + } + + public ObservationReader setCreatedAfter(final ZonedDateTime createdAfter) { + this.createdAfter = createdAfter; + return this; + } + + public ObservationReader setCreatedBefore( + final ZonedDateTime createdBefore + ) { + this.createdBefore = createdBefore; + return this; + } + + public ObservationReader setConversationId(final String conversationId) { + this.conversationId = conversationId; + return this; + } + + public ObservationReader setAcceptEncoding(final String acceptEncoding) { + this.acceptEncoding = acceptEncoding; + return this; + } + + public ResourceSetResponse< + Observation.ListObservationResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "observations", + response.getContent(), + Observation.ListObservationResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Observations"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "observations", + response.getContent(), + Observation.ListObservationResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Observation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "observations", + response.getContent(), + Observation.ListObservationResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Observations"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Observations"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + + if (source != null) { + Serializer.toString(request, "source", source, ParameterType.QUERY); + } + + if (createdAfter != null) { + Serializer.toString( + request, + "createdAfter", + createdAfter, + ParameterType.QUERY + ); + } + + if (createdBefore != null) { + Serializer.toString( + request, + "createdBefore", + createdBefore, + ParameterType.QUERY + ); + } + + if (conversationId != null) { + Serializer.toString( + request, + "conversationId", + conversationId, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (acceptEncoding != null) { + Serializer.toString( + request, + "Accept-Encoding", + acceptEncoding, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Operation.java b/src/main/java/com/twilio/rest/memory/v1/Operation.java new file mode 100644 index 0000000000..a0c7f4e827 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Operation.java @@ -0,0 +1,678 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Operation extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateOperationResponse extends Resource { + + @JsonCreator + private CreateOperationResponse() {} + + public static CreateOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateOperationResponse other = (CreateOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateOperationResponse extends Resource { + + @JsonCreator + private UpdateOperationResponse() {} + + public static UpdateOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateOperationResponse other = (UpdateOperationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteOperationResponse extends Resource { + + @JsonCreator + private DeleteOperationResponse() {} + + public static DeleteOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteOperationResponse other = (DeleteOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListOperationResponse extends Resource { + + @JsonCreator + private ListOperationResponse() {} + + public static ListOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListOperationResponse other = (ListOperationResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchOperationResponse extends Resource { + + @JsonCreator + private PatchOperationResponse() {} + + public static PatchOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchOperationResponse other = (PatchOperationResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchOperationResponse extends Resource { + + @Getter + private final ZonedDateTime completedAt; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final OperationStatusError error; + + @Getter + private final String operationId; + + @Getter + private final OperationResultResourceId result; + + @Getter + private final URI resultUrl; + + @Getter + private final Operation.Status status; + + @Getter + private final URI statusUrl; + + @JsonCreator + private FetchOperationResponse( + @JsonProperty("completedAt") final ZonedDateTime completedAt, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("error") final OperationStatusError error, + @JsonProperty("operationId") final String operationId, + @JsonProperty("result") final OperationResultResourceId result, + @JsonProperty("resultUrl") final URI resultUrl, + @JsonProperty("status") final Operation.Status status, + @JsonProperty("statusUrl") final URI statusUrl + ) { + this.completedAt = completedAt; + this.createdAt = createdAt; + this.error = error; + this.operationId = operationId; + this.result = result; + this.resultUrl = resultUrl; + this.status = status; + this.statusUrl = statusUrl; + } + + public static FetchOperationResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchOperationResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchOperationResponse other = (FetchOperationResponse) o; + return ( + Objects.equals(completedAt, other.completedAt) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(error, other.error) && + Objects.equals(operationId, other.operationId) && + Objects.equals(result, other.result) && + Objects.equals(resultUrl, other.resultUrl) && + Objects.equals(status, other.status) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + completedAt, + createdAt, + error, + operationId, + result, + resultUrl, + status, + statusUrl + ); + } + } + + public static OperationFetcher fetcher(final String pathOperationId) { + return new OperationFetcher(pathOperationId); + } + + public enum Status { + PENDING("PENDING"), + RUNNING("RUNNING"), + CANCELLED("CANCELLED"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Type { + RESOURCE_ID("RESOURCE_ID"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + @JsonDeserialize(builder = OperationResultResourceId.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperationResultResourceId { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Operation.Type type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + private OperationResultResourceId(Builder builder) { + this.type = builder.type; + this.id = builder.id; + } + + public static Builder builder( + final Operation.Type type, + final String id + ) { + return new Builder(type, id); + } + + public static OperationResultResourceId fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + OperationResultResourceId.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private Operation.Type type; + + @JsonProperty("id") + private String id; + + @JsonCreator + public Builder( + @JsonProperty("type") final Operation.Type type, + @JsonProperty("id") final String id + ) { + this.type = type; + this.id = id; + } + + public OperationResultResourceId build() { + return new OperationResultResourceId(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperationResultResourceId other = (OperationResultResourceId) o; + return ( + Objects.equals(type, other.type) && Objects.equals(id, other.id) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, id); + } + } + + @JsonDeserialize(builder = OperationStatusError.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class OperationStatusError { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final URI type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + @Getter + private final String title; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + @Getter + private final Integer code; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + @Getter + private final String detail; + + private OperationStatusError(Builder builder) { + this.type = builder.type; + this.title = builder.title; + this.code = builder.code; + this.detail = builder.detail; + } + + public static Builder builder() { + return new Builder(); + } + + public static OperationStatusError fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, OperationStatusError.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("type") + private URI type; + + @JsonProperty("title") + private String title; + + @JsonProperty("code") + private Integer code; + + @JsonProperty("detail") + private String detail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(URI type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("title") + public Builder title(String title) { + this.title = title; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + public Builder code(Integer code) { + this.code = code; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("detail") + public Builder detail(String detail) { + this.detail = detail; + return this; + } + + public OperationStatusError build() { + return new OperationStatusError(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + OperationStatusError other = (OperationStatusError) o; + return ( + Objects.equals(type, other.type) && + Objects.equals(title, other.title) && + Objects.equals(code, other.code) && + Objects.equals(detail, other.detail) + ); + } + + @Override + public int hashCode() { + return Objects.hash(type, title, code, detail); + } + } + + /** + * Converts a JSON String into a Operation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Operation object represented by the provided JSON + */ + public static Operation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Operation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Operation object represented by the provided JSON + */ + public static Operation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Operation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Operation() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/OperationFetcher.java b/src/main/java/com/twilio/rest/memory/v1/OperationFetcher.java new file mode 100644 index 0000000000..6ceb04ab8d --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/OperationFetcher.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class OperationFetcher + extends Fetcher { + + private String pathOperationId; + + public OperationFetcher(final String pathOperationId) { + this.pathOperationId = pathOperationId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Operations/{operationId}"; + + path = + path.replace( + "{" + "operationId" + "}", + this.pathOperationId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Operation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Operation.FetchOperationResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return Operation.FetchOperationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Operation.FetchOperationResponse content = + Operation.FetchOperationResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Profile.java b/src/main/java/com/twilio/rest/memory/v1/Profile.java new file mode 100644 index 0000000000..6abd492e4b --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Profile.java @@ -0,0 +1,722 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Profile extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateProfileResponse extends Resource { + + @Getter + private final String id; + + @Getter + private final String message; + + @JsonCreator + private CreateProfileResponse( + @JsonProperty("id") final String id, + @JsonProperty("message") final String message + ) { + this.id = id; + this.message = message; + } + + public static CreateProfileResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateProfileResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateProfileResponse other = (CreateProfileResponse) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(message, other.message) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateProfileResponse extends Resource { + + @JsonCreator + private UpdateProfileResponse() {} + + public static UpdateProfileResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateProfileResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateProfileResponse other = (UpdateProfileResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteProfileResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private DeleteProfileResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static DeleteProfileResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteProfileResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteProfileResponse other = (DeleteProfileResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListProfileResponse extends Resource { + + @Getter + private final List profiles; + + @JsonCreator + private ListProfileResponse( + @JsonProperty("profiles") final List profiles + ) { + this.profiles = profiles; + } + + public static ListProfileResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListProfileResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListProfileResponse other = (ListProfileResponse) o; + return (Objects.equals(profiles, other.profiles)); + } + + @Override + public int hashCode() { + return Objects.hash(profiles); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchProfileResponse extends Resource { + + @Getter + private final String message; + + @JsonCreator + private PatchProfileResponse( + @JsonProperty("message") final String message + ) { + this.message = message; + } + + public static PatchProfileResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchProfileResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchProfileResponse other = (PatchProfileResponse) o; + return Objects.equals(message, other.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchProfileResponse extends Resource { + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final Map> traits; + + @JsonCreator + private FetchProfileResponse( + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("traits") final Map< + String, + Map + > traits + ) { + this.createdAt = createdAt; + this.id = id; + this.traits = traits; + } + + public static FetchProfileResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchProfileResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchProfileResponse other = (FetchProfileResponse) o; + return ( + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(traits, other.traits) + ); + } + + @Override + public int hashCode() { + return Objects.hash(createdAt, id, traits); + } + } + + public static ProfileCreator creator( + final String pathStoreId, + final Profile.ProfileData profileData + ) { + return new ProfileCreator(pathStoreId, profileData); + } + + public static ProfileDeleter deleter( + final String pathStoreId, + final String pathProfileId + ) { + return new ProfileDeleter(pathStoreId, pathProfileId); + } + + public static ProfileFetcher fetcher( + final String pathStoreId, + final String pathProfileId + ) { + return new ProfileFetcher(pathStoreId, pathProfileId); + } + + public static ProfileReader reader(final String pathStoreId) { + return new ProfileReader(pathStoreId); + } + + public static ProfilePatcher patcher( + final String pathStoreId, + final String pathProfileId, + final Profile.ProfilePatch profilePatch + ) { + return new ProfilePatcher(pathStoreId, pathProfileId, profilePatch); + } + + public enum OrderBy { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private OrderBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderBy forValue(final String value) { + return Promoter.enumFromString(value, OrderBy.values()); + } + } + + @JsonDeserialize(builder = IdentityProfilesMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class IdentityProfilesMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private IdentityProfilesMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static IdentityProfilesMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, IdentityProfilesMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public IdentityProfilesMeta build() { + return new IdentityProfilesMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IdentityProfilesMeta other = (IdentityProfilesMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = ProfileData.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ProfileData { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + @Getter + private final Map> traits; + + private ProfileData(Builder builder) { + this.traits = builder.traits; + } + + public static Builder builder() { + return new Builder(); + } + + public static ProfileData fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ProfileData.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("traits") + private Map> traits; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + public Builder traits(Map> traits) { + this.traits = traits; + return this; + } + + public ProfileData build() { + return new ProfileData(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ProfileData other = (ProfileData) o; + return (Objects.equals(traits, other.traits)); + } + + @Override + public int hashCode() { + return Objects.hash(traits); + } + } + + @JsonDeserialize(builder = ProfilePatch.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ProfilePatch { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + @Getter + private final Map> traits; + + private ProfilePatch(Builder builder) { + this.traits = builder.traits; + } + + public static Builder builder() { + return new Builder(); + } + + public static ProfilePatch fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ProfilePatch.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("traits") + private Map> traits; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + public Builder traits(Map> traits) { + this.traits = traits; + return this; + } + + public ProfilePatch build() { + return new ProfilePatch(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ProfilePatch other = (ProfilePatch) o; + return (Objects.equals(traits, other.traits)); + } + + @Override + public int hashCode() { + return Objects.hash(traits); + } + } + + /** + * Converts a JSON String into a Profile object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Profile object represented by the provided JSON + */ + public static Profile fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Profile.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Profile object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Profile object represented by the provided JSON + */ + public static Profile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Profile.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Profile() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ProfileCreator.java b/src/main/java/com/twilio/rest/memory/v1/ProfileCreator.java new file mode 100644 index 0000000000..7ca31e48b9 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ProfileCreator.java @@ -0,0 +1,120 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ProfileCreator extends Creator { + + private String pathStoreId; + private Profile.ProfileData profileData; + + public ProfileCreator( + final String pathStoreId, + final Profile.ProfileData profileData + ) { + this.pathStoreId = pathStoreId; + this.profileData = profileData; + } + + public ProfileCreator setProfileData( + final Profile.ProfileData profileData + ) { + this.profileData = profileData; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Profile creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Profile.CreateProfileResponse create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Profile.CreateProfileResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Profile.CreateProfileResponse content = + Profile.CreateProfileResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (profileData != null) { + request.setBody(Profile.toJson(profileData, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ProfileDeleter.java b/src/main/java/com/twilio/rest/memory/v1/ProfileDeleter.java new file mode 100644 index 0000000000..16d9ea1993 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ProfileDeleter.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ProfileDeleter + extends ResourceDeleter { + + private String pathStoreId; + private String pathProfileId; + + public ProfileDeleter( + final String pathStoreId, + final String pathProfileId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Profile delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Profile.DeleteProfileResponse delete(final TwilioRestClient client) { + Response response = makeRequest(client); + return Profile.DeleteProfileResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Profile.DeleteProfileResponse content = + Profile.DeleteProfileResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ProfileFetcher.java b/src/main/java/com/twilio/rest/memory/v1/ProfileFetcher.java new file mode 100644 index 0000000000..ddf5e7ff7a --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ProfileFetcher.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ProfileFetcher extends Fetcher { + + private String pathStoreId; + private String pathProfileId; + private String traitGroups; + + public ProfileFetcher( + final String pathStoreId, + final String pathProfileId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + } + + public ProfileFetcher setTraitGroups(final String traitGroups) { + this.traitGroups = traitGroups; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Profile fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Profile.FetchProfileResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Profile.FetchProfileResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Profile.FetchProfileResponse content = + Profile.FetchProfileResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (traitGroups != null) { + Serializer.toString( + request, + "traitGroups", + traitGroups, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ProfilePatcher.java b/src/main/java/com/twilio/rest/memory/v1/ProfilePatcher.java new file mode 100644 index 0000000000..fd50e493a4 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ProfilePatcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ProfilePatcher extends Patcher { + + private String pathStoreId; + private String pathProfileId; + private Profile.ProfilePatch profilePatch; + + public ProfilePatcher( + final String pathStoreId, + final String pathProfileId, + final Profile.ProfilePatch profilePatch + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.profilePatch = profilePatch; + } + + public ProfilePatcher setProfilePatch( + final Profile.ProfilePatch profilePatch + ) { + this.profilePatch = profilePatch; + return this; + } + + @Override + public Profile.PatchProfileResponse patch(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.PATCH, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Profile patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Profile.PatchProfileResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (profilePatch != null) { + request.setBody(Profile.toJson(profilePatch, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/ProfileReader.java b/src/main/java/com/twilio/rest/memory/v1/ProfileReader.java new file mode 100644 index 0000000000..973f2e4ff4 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/ProfileReader.java @@ -0,0 +1,264 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ProfileReader extends Reader { + + private String pathStoreId; + private Integer pageSize; + private String pageToken; + private Profile.OrderBy orderBy; + + public ProfileReader(final String pathStoreId) { + this.pathStoreId = pathStoreId; + } + + public ProfileReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ProfileReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public ProfileReader setOrderBy(final Profile.OrderBy orderBy) { + this.orderBy = orderBy; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "profiles", + response.getContent(), + Profile.ListProfileResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "profiles", + response.getContent(), + Profile.ListProfileResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Profile read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "profiles", + response.getContent(), + Profile.ListProfileResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Recall.java b/src/main/java/com/twilio/rest/memory/v1/Recall.java new file mode 100644 index 0000000000..6886c4997a --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Recall.java @@ -0,0 +1,1745 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Recall extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateRecallResponse extends Resource { + + @Getter + private final List communications; + + @Getter + private final MemoryRetrievalResponseMeta meta; + + @Getter + private final List observations; + + @Getter + private final List summaries; + + @JsonCreator + private CreateRecallResponse( + @JsonProperty("communications") final List< + Communication + > communications, + @JsonProperty("meta") final MemoryRetrievalResponseMeta meta, + @JsonProperty("observations") final List< + RecallObservationInfo + > observations, + @JsonProperty("summaries") final List summaries + ) { + this.communications = communications; + this.meta = meta; + this.observations = observations; + this.summaries = summaries; + } + + public static CreateRecallResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateRecallResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateRecallResponse other = (CreateRecallResponse) o; + return ( + Objects.equals(communications, other.communications) && + Objects.equals(meta, other.meta) && + Objects.equals(observations, other.observations) && + Objects.equals(summaries, other.summaries) + ); + } + + @Override + public int hashCode() { + return Objects.hash(communications, meta, observations, summaries); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateRecallResponse extends Resource { + + @JsonCreator + private UpdateRecallResponse() {} + + public static UpdateRecallResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateRecallResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateRecallResponse other = (UpdateRecallResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteRecallResponse extends Resource { + + @JsonCreator + private DeleteRecallResponse() {} + + public static DeleteRecallResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteRecallResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteRecallResponse other = (DeleteRecallResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListRecallResponse extends Resource { + + @JsonCreator + private ListRecallResponse() {} + + public static ListRecallResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListRecallResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListRecallResponse other = (ListRecallResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchRecallResponse extends Resource { + + @JsonCreator + private PatchRecallResponse() {} + + public static PatchRecallResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchRecallResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchRecallResponse other = (PatchRecallResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchRecallResponse extends Resource { + + @JsonCreator + private FetchRecallResponse() {} + + public static FetchRecallResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchRecallResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchRecallResponse other = (FetchRecallResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + public static RecallCreator creator( + final String pathStoreId, + final String pathProfileId, + final Recall.MemoryRetrievalRequest memoryRetrievalRequest + ) { + return new RecallCreator( + pathStoreId, + pathProfileId, + memoryRetrievalRequest + ); + } + + public enum Channel { + VOICE("VOICE"), + SMS("SMS"), + RCS("RCS"), + EMAIL("EMAIL"), + WHATSAPP("WHATSAPP"), + CHAT("CHAT"), + API("API"), + SYSTEM("SYSTEM"); + + private final String value; + + private Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Channel forValue(final String value) { + return Promoter.enumFromString(value, Channel.values()); + } + } + + public enum DeliveryStatus { + INITIATED("INITIATED"), + IN_PROGRESS("IN_PROGRESS"), + DELIVERED("DELIVERED"), + COMPLETED("COMPLETED"), + FAILED("FAILED"); + + private final String value; + + private DeliveryStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static DeliveryStatus forValue(final String value) { + return Promoter.enumFromString(value, DeliveryStatus.values()); + } + } + + public enum ParticipantType { + HUMAN_AGENT("HUMAN_AGENT"), + CUSTOMER("CUSTOMER"), + AI_AGENT("AI_AGENT"), + AGENT("AGENT"), + UNKNOWN("UNKNOWN"); + + private final String value; + + private ParticipantType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ParticipantType forValue(final String value) { + return Promoter.enumFromString(value, ParticipantType.values()); + } + } + + public enum ContentEncoding { + GZIP("gzip"), + DEFLATE("deflate"), + BR("br"), + COMPRESS("compress"); + + private final String value; + + private ContentEncoding(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ContentEncoding forValue(final String value) { + return Promoter.enumFromString(value, ContentEncoding.values()); + } + } + + @JsonDeserialize(builder = MemoryRetrievalResponseMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MemoryRetrievalResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("queryTime") + @Getter + private final Integer queryTime; + + private MemoryRetrievalResponseMeta(Builder builder) { + this.queryTime = builder.queryTime; + } + + public static Builder builder(final Integer queryTime) { + return new Builder(queryTime); + } + + public static MemoryRetrievalResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MemoryRetrievalResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("queryTime") + private Integer queryTime; + + @JsonCreator + public Builder(@JsonProperty("queryTime") final Integer queryTime) { + this.queryTime = queryTime; + } + + public MemoryRetrievalResponseMeta build() { + return new MemoryRetrievalResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MemoryRetrievalResponseMeta other = (MemoryRetrievalResponseMeta) o; + return (Objects.equals(queryTime, other.queryTime)); + } + + @Override + public int hashCode() { + return Objects.hash(queryTime); + } + } + + @JsonDeserialize(builder = Participant.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Participant { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Recall.ParticipantType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Recall.Channel channel; + + private Participant(Builder builder) { + this.id = builder.id; + this.name = builder.name; + this.type = builder.type; + this.profileId = builder.profileId; + this.address = builder.address; + this.channel = builder.channel; + } + + public static Builder builder( + final String id, + final String name, + final String address, + final Recall.Channel channel + ) { + return new Builder(id, name, address, channel); + } + + public static Participant fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, Participant.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private Recall.ParticipantType type; + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("address") + private String address; + + @JsonProperty("channel") + private Recall.Channel channel; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("address") final String address, + @JsonProperty("channel") final Recall.Channel channel + ) { + this.id = id; + this.name = name; + this.address = address; + this.channel = channel; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Recall.ParticipantType type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + public Builder profileId(String profileId) { + this.profileId = profileId; + return this; + } + + public Participant build() { + return new Participant(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Participant other = (Participant) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(type, other.type) && + Objects.equals(profileId, other.profileId) && + Objects.equals(address, other.address) && + Objects.equals(channel, other.channel) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, type, profileId, address, channel); + } + } + + @JsonDeserialize(builder = CommunicationContent.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CommunicationContent { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + @Getter + private final String text; + + private CommunicationContent(Builder builder) { + this.text = builder.text; + } + + public static Builder builder() { + return new Builder(); + } + + public static CommunicationContent fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CommunicationContent.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("text") + private String text; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("text") + public Builder text(String text) { + this.text = text; + return this; + } + + public CommunicationContent build() { + return new CommunicationContent(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CommunicationContent other = (CommunicationContent) o; + return (Objects.equals(text, other.text)); + } + + @Override + public int hashCode() { + return Objects.hash(text); + } + } + + @JsonDeserialize(builder = CommunicationRecipients.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CommunicationRecipients { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final Recall.ParticipantType type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + @Getter + private final String profileId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final Recall.Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("deliveryStatus") + @Getter + private final Recall.DeliveryStatus deliveryStatus; + + private CommunicationRecipients(Builder builder) { + this.id = builder.id; + this.name = builder.name; + this.type = builder.type; + this.profileId = builder.profileId; + this.address = builder.address; + this.channel = builder.channel; + this.deliveryStatus = builder.deliveryStatus; + } + + public static Builder builder( + final String id, + final String name, + final String address, + final Recall.Channel channel + ) { + return new Builder(id, name, address, channel); + } + + public static CommunicationRecipients fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, CommunicationRecipients.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("name") + private String name; + + @JsonProperty("type") + private Recall.ParticipantType type; + + @JsonProperty("profileId") + private String profileId; + + @JsonProperty("address") + private String address; + + @JsonProperty("channel") + private Recall.Channel channel; + + @JsonProperty("deliveryStatus") + private Recall.DeliveryStatus deliveryStatus; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("name") final String name, + @JsonProperty("address") final String address, + @JsonProperty("channel") final Recall.Channel channel + ) { + this.id = id; + this.name = name; + this.address = address; + this.channel = channel; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(Recall.ParticipantType type) { + this.type = type; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profileId") + public Builder profileId(String profileId) { + this.profileId = profileId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("deliveryStatus") + public Builder deliveryStatus( + Recall.DeliveryStatus deliveryStatus + ) { + this.deliveryStatus = deliveryStatus; + return this; + } + + public CommunicationRecipients build() { + return new CommunicationRecipients(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CommunicationRecipients other = (CommunicationRecipients) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(name, other.name) && + Objects.equals(type, other.type) && + Objects.equals(profileId, other.profileId) && + Objects.equals(address, other.address) && + Objects.equals(channel, other.channel) && + Objects.equals(deliveryStatus, other.deliveryStatus) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + name, + type, + profileId, + address, + channel, + deliveryStatus + ); + } + } + + @JsonDeserialize(builder = MemoryRetrievalRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MemoryRetrievalRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("query") + @Getter + private final String query; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("beginDate") + @Getter + private final ZonedDateTime beginDate; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("endDate") + @Getter + private final ZonedDateTime endDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("communicationsLimit") + @Getter + private final Integer communicationsLimit; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observationsLimit") + @Getter + private final Integer observationsLimit; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("summariesLimit") + @Getter + private final Integer summariesLimit; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("relevanceThreshold") + @Getter + private final Double relevanceThreshold; + + private MemoryRetrievalRequest(Builder builder) { + this.conversationId = builder.conversationId; + this.query = builder.query; + this.beginDate = builder.beginDate; + this.endDate = builder.endDate; + this.communicationsLimit = builder.communicationsLimit; + this.observationsLimit = builder.observationsLimit; + this.summariesLimit = builder.summariesLimit; + this.relevanceThreshold = builder.relevanceThreshold; + } + + public static Builder builder() { + return new Builder(); + } + + public static MemoryRetrievalRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, MemoryRetrievalRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("conversationId") + private String conversationId; + + @JsonProperty("query") + private String query; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("beginDate") + private ZonedDateTime beginDate; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("endDate") + private ZonedDateTime endDate; + + @JsonProperty("communicationsLimit") + private Integer communicationsLimit; + + @JsonProperty("observationsLimit") + private Integer observationsLimit; + + @JsonProperty("summariesLimit") + private Integer summariesLimit; + + @JsonProperty("relevanceThreshold") + private Double relevanceThreshold; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + public Builder conversationId(String conversationId) { + this.conversationId = conversationId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("query") + public Builder query(String query) { + this.query = query; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("beginDate") + public Builder beginDate(ZonedDateTime beginDate) { + this.beginDate = beginDate; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("endDate") + public Builder endDate(ZonedDateTime endDate) { + this.endDate = endDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("communicationsLimit") + public Builder communicationsLimit(Integer communicationsLimit) { + this.communicationsLimit = communicationsLimit; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("observationsLimit") + public Builder observationsLimit(Integer observationsLimit) { + this.observationsLimit = observationsLimit; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("summariesLimit") + public Builder summariesLimit(Integer summariesLimit) { + this.summariesLimit = summariesLimit; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("relevanceThreshold") + public Builder relevanceThreshold(Double relevanceThreshold) { + this.relevanceThreshold = relevanceThreshold; + return this; + } + + public MemoryRetrievalRequest build() { + return new MemoryRetrievalRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MemoryRetrievalRequest other = (MemoryRetrievalRequest) o; + return ( + Objects.equals(conversationId, other.conversationId) && + Objects.equals(query, other.query) && + Objects.equals(beginDate, other.beginDate) && + Objects.equals(endDate, other.endDate) && + Objects.equals( + communicationsLimit, + other.communicationsLimit + ) && + Objects.equals(observationsLimit, other.observationsLimit) && + Objects.equals(summariesLimit, other.summariesLimit) && + Objects.equals(relevanceThreshold, other.relevanceThreshold) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + conversationId, + query, + beginDate, + endDate, + communicationsLimit, + observationsLimit, + summariesLimit, + relevanceThreshold + ); + } + } + + @JsonDeserialize(builder = RecallObservationInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class RecallObservationInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + @Getter + private final List conversationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("score") + @Getter + private final Double score; + + private RecallObservationInfo(Builder builder) { + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.source = builder.source; + this.conversationIds = builder.conversationIds; + this.id = builder.id; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.score = builder.score; + } + + public static Builder builder( + final String content, + final ZonedDateTime occurredAt, + final String source, + final String id, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt + ) { + return new Builder( + content, + occurredAt, + source, + id, + createdAt, + updatedAt + ); + } + + public static RecallObservationInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, RecallObservationInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("source") + private String source; + + @JsonProperty("conversationIds") + private List conversationIds; + + @JsonProperty("id") + private String id; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonProperty("score") + private Double score; + + @JsonCreator + public Builder( + @JsonProperty("content") final String content, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("source") final String source, + @JsonProperty("id") final String id, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.content = content; + this.occurredAt = occurredAt; + this.source = source; + this.id = id; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + public Builder conversationIds(List conversationIds) { + this.conversationIds = conversationIds; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("score") + public Builder score(Double score) { + this.score = score; + return this; + } + + public RecallObservationInfo build() { + return new RecallObservationInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RecallObservationInfo other = (RecallObservationInfo) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(conversationIds, other.conversationIds) && + Objects.equals(id, other.id) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(score, other.score) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + occurredAt, + source, + conversationIds, + id, + createdAt, + updatedAt, + score + ); + } + } + + @JsonDeserialize(builder = RecallSummaryInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class RecallSummaryInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationId") + @Getter + private final String conversationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("score") + @Getter + private final Double score; + + private RecallSummaryInfo(Builder builder) { + this.source = builder.source; + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.conversationId = builder.conversationId; + this.id = builder.id; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.score = builder.score; + } + + public static Builder builder( + final String content, + final ZonedDateTime occurredAt, + final String conversationId, + final String id, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt + ) { + return new Builder( + content, + occurredAt, + conversationId, + id, + createdAt, + updatedAt + ); + } + + public static RecallSummaryInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, RecallSummaryInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("source") + private String source; + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("conversationId") + private String conversationId; + + @JsonProperty("id") + private String id; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonProperty("score") + private Double score; + + @JsonCreator + public Builder( + @JsonProperty("content") final String content, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("conversationId") final String conversationId, + @JsonProperty("id") final String id, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.content = content; + this.occurredAt = occurredAt; + this.conversationId = conversationId; + this.id = id; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(String source) { + this.source = source; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("score") + public Builder score(Double score) { + this.score = score; + return this; + } + + public RecallSummaryInfo build() { + return new RecallSummaryInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RecallSummaryInfo other = (RecallSummaryInfo) o; + return ( + Objects.equals(source, other.source) && + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(conversationId, other.conversationId) && + Objects.equals(id, other.id) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(score, other.score) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + source, + content, + occurredAt, + conversationId, + id, + createdAt, + updatedAt, + score + ); + } + } + + @JsonDeserialize(builder = Communication.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Communication { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + @Getter + private final String channelId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final CommunicationContent content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("author") + @Getter + private final Participant author; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("recipients") + @Getter + private final List recipients; + + private Communication(Builder builder) { + this.id = builder.id; + this.channelId = builder.channelId; + this.content = builder.content; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + this.author = builder.author; + this.recipients = builder.recipients; + } + + public static Builder builder( + final String id, + final CommunicationContent content, + final Participant author, + final List recipients + ) { + return new Builder(id, content, author, recipients); + } + + public static Communication fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, Communication.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("channelId") + private String channelId; + + @JsonProperty("content") + private CommunicationContent content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonProperty("author") + private Participant author; + + @JsonProperty("recipients") + private List recipients; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("content") final CommunicationContent content, + @JsonProperty("author") final Participant author, + @JsonProperty("recipients") final List< + CommunicationRecipients + > recipients + ) { + this.id = id; + this.content = content; + this.author = author; + this.recipients = recipients; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channelId") + public Builder channelId(String channelId) { + this.channelId = channelId; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + public Builder createdAt(ZonedDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + public Builder updatedAt(ZonedDateTime updatedAt) { + this.updatedAt = updatedAt; + return this; + } + + public Communication build() { + return new Communication(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Communication other = (Communication) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(channelId, other.channelId) && + Objects.equals(content, other.content) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) && + Objects.equals(author, other.author) && + Objects.equals(recipients, other.recipients) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + channelId, + content, + createdAt, + updatedAt, + author, + recipients + ); + } + } + + /** + * Converts a JSON String into a Recall object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Recall object represented by the provided JSON + */ + public static Recall fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Recall.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Recall object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Recall object represented by the provided JSON + */ + public static Recall fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Recall.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Recall() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/RecallCreator.java b/src/main/java/com/twilio/rest/memory/v1/RecallCreator.java new file mode 100644 index 0000000000..bc9b3fac90 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/RecallCreator.java @@ -0,0 +1,167 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RecallCreator extends Creator { + + private String pathStoreId; + private String pathProfileId; + private String acceptEncoding; + private Recall.ContentEncoding contentEncoding; + private Recall.MemoryRetrievalRequest memoryRetrievalRequest; + + public RecallCreator( + final String pathStoreId, + final String pathProfileId, + final Recall.MemoryRetrievalRequest memoryRetrievalRequest + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.memoryRetrievalRequest = memoryRetrievalRequest; + } + + public RecallCreator setMemoryRetrievalRequest( + final Recall.MemoryRetrievalRequest memoryRetrievalRequest + ) { + this.memoryRetrievalRequest = memoryRetrievalRequest; + return this; + } + + public RecallCreator setAcceptEncoding(final String acceptEncoding) { + this.acceptEncoding = acceptEncoding; + return this; + } + + public RecallCreator setContentEncoding( + final Recall.ContentEncoding contentEncoding + ) { + this.contentEncoding = contentEncoding; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Recall"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Recall creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Recall.CreateRecallResponse create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recall.CreateRecallResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recall.CreateRecallResponse content = + Recall.CreateRecallResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (acceptEncoding != null) { + Serializer.toString( + request, + "Accept-Encoding", + acceptEncoding, + ParameterType.HEADER + ); + } + + if (contentEncoding != null) { + Serializer.toString( + request, + "Content-Encoding", + contentEncoding, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (memoryRetrievalRequest != null) { + request.setBody( + Recall.toJson(memoryRetrievalRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Revision.java b/src/main/java/com/twilio/rest/memory/v1/Revision.java new file mode 100644 index 0000000000..79282bc30d --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Revision.java @@ -0,0 +1,740 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Revision extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateRevisionResponse extends Resource { + + @JsonCreator + private CreateRevisionResponse() {} + + public static CreateRevisionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateRevisionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateRevisionResponse other = (CreateRevisionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateRevisionResponse extends Resource { + + @JsonCreator + private UpdateRevisionResponse() {} + + public static UpdateRevisionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateRevisionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateRevisionResponse other = (UpdateRevisionResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteRevisionResponse extends Resource { + + @JsonCreator + private DeleteRevisionResponse() {} + + public static DeleteRevisionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteRevisionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteRevisionResponse other = (DeleteRevisionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListRevisionResponse extends Resource { + + @Getter + private final String content; + + @Getter + private final List conversationIds; + + @Getter + private final ZonedDateTime createdAt; + + @Getter + private final String id; + + @Getter + private final ZonedDateTime occurredAt; + + @Getter + private final String source; + + @Getter + private final ZonedDateTime updatedAt; + + @JsonCreator + private ListRevisionResponse( + @JsonProperty("content") final String content, + @JsonProperty("conversationIds") final List conversationIds, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("id") final String id, + @JsonProperty("occurredAt") final ZonedDateTime occurredAt, + @JsonProperty("source") final String source, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.content = content; + this.conversationIds = conversationIds; + this.createdAt = createdAt; + this.id = id; + this.occurredAt = occurredAt; + this.source = source; + this.updatedAt = updatedAt; + } + + public static ListRevisionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListRevisionResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListRevisionResponse other = (ListRevisionResponse) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(conversationIds, other.conversationIds) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(id, other.id) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + conversationIds, + createdAt, + id, + occurredAt, + source, + updatedAt + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchRevisionResponse extends Resource { + + @JsonCreator + private PatchRevisionResponse() {} + + public static PatchRevisionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchRevisionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchRevisionResponse other = (PatchRevisionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchRevisionResponse extends Resource { + + @JsonCreator + private FetchRevisionResponse() {} + + public static FetchRevisionResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchRevisionResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchRevisionResponse other = (FetchRevisionResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + public static RevisionReader reader( + final String pathStoreId, + final String pathProfileId, + final String pathObservationId + ) { + return new RevisionReader( + pathStoreId, + pathProfileId, + pathObservationId + ); + } + + @JsonDeserialize(builder = ObservationsMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ObservationsMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private ObservationsMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static ObservationsMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ObservationsMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public ObservationsMeta build() { + return new ObservationsMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ObservationsMeta other = (ObservationsMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = ObservationInfo.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ObservationInfo { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + @Getter + private final String content; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + @Getter + private final ZonedDateTime occurredAt; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + @Getter + private final List conversationIds; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("createdAt") + @Getter + private final ZonedDateTime createdAt; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("updatedAt") + @Getter + private final ZonedDateTime updatedAt; + + private ObservationInfo(Builder builder) { + this.content = builder.content; + this.occurredAt = builder.occurredAt; + this.source = builder.source; + this.conversationIds = builder.conversationIds; + this.id = builder.id; + this.createdAt = builder.createdAt; + this.updatedAt = builder.updatedAt; + } + + public static Builder builder( + final String id, + final ZonedDateTime createdAt, + final ZonedDateTime updatedAt + ) { + return new Builder(id, createdAt, updatedAt); + } + + public static ObservationInfo fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ObservationInfo.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("content") + private String content; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("occurredAt") + private ZonedDateTime occurredAt; + + @JsonProperty("source") + private String source; + + @JsonProperty("conversationIds") + private List conversationIds; + + @JsonProperty("id") + private String id; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("createdAt") + private ZonedDateTime createdAt; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("updatedAt") + private ZonedDateTime updatedAt; + + @JsonCreator + public Builder( + @JsonProperty("id") final String id, + @JsonProperty("createdAt") final ZonedDateTime createdAt, + @JsonProperty("updatedAt") final ZonedDateTime updatedAt + ) { + this.id = id; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("content") + public Builder content(String content) { + this.content = content; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("occurredAt") + public Builder occurredAt(ZonedDateTime occurredAt) { + this.occurredAt = occurredAt; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(String source) { + this.source = source; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("conversationIds") + public Builder conversationIds(List conversationIds) { + this.conversationIds = conversationIds; + return this; + } + + public ObservationInfo build() { + return new ObservationInfo(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ObservationInfo other = (ObservationInfo) o; + return ( + Objects.equals(content, other.content) && + Objects.equals(occurredAt, other.occurredAt) && + Objects.equals(source, other.source) && + Objects.equals(conversationIds, other.conversationIds) && + Objects.equals(id, other.id) && + Objects.equals(createdAt, other.createdAt) && + Objects.equals(updatedAt, other.updatedAt) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + content, + occurredAt, + source, + conversationIds, + id, + createdAt, + updatedAt + ); + } + } + + /** + * Converts a JSON String into a Revision object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Revision object represented by the provided JSON + */ + public static Revision fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Revision.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Revision object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Revision object represented by the provided JSON + */ + public static Revision fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Revision.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Revision() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/RevisionReader.java b/src/main/java/com/twilio/rest/memory/v1/RevisionReader.java new file mode 100644 index 0000000000..9c53db8212 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/RevisionReader.java @@ -0,0 +1,308 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RevisionReader extends Reader { + + private String pathStoreId; + private String pathProfileId; + private String pathObservationId; + private Integer pageSize; + private String pageToken; + private String acceptEncoding; + + public RevisionReader( + final String pathStoreId, + final String pathProfileId, + final String pathObservationId + ) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + this.pathObservationId = pathObservationId; + } + + public RevisionReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public RevisionReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public RevisionReader setAcceptEncoding(final String acceptEncoding) { + this.acceptEncoding = acceptEncoding; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "revisions", + response.getContent(), + Revision.ListRevisionResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Observations/{observationId}/Revisions"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "observationId" + "}", + this.pathObservationId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "revisions", + response.getContent(), + Revision.ListRevisionResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Revision read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "revisions", + response.getContent(), + Revision.ListRevisionResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Observations/{observationId}/Revisions"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "observationId" + "}", + this.pathObservationId.toString() + ); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = + "/v1/Stores/{storeId}/Profiles/{profileId}/Observations/{observationId}/Revisions"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + path = + path.replace( + "{" + "observationId" + "}", + this.pathObservationId.toString() + ); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (acceptEncoding != null) { + Serializer.toString( + request, + "Accept-Encoding", + acceptEncoding, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Store.java b/src/main/java/com/twilio/rest/memory/v1/Store.java new file mode 100644 index 0000000000..32e109ddfb --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Store.java @@ -0,0 +1,813 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Store extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateStoreResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private CreateStoreResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static CreateStoreResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateStoreResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateStoreResponse other = (CreateStoreResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateStoreResponse extends Resource { + + @JsonCreator + private UpdateStoreResponse() {} + + public static UpdateStoreResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateStoreResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateStoreResponse other = (UpdateStoreResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteStoreResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private DeleteStoreResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static DeleteStoreResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteStoreResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteStoreResponse other = (DeleteStoreResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListStoreResponse extends Resource { + + @Getter + private final List stores; + + @JsonCreator + private ListStoreResponse( + @JsonProperty("stores") final List stores + ) { + this.stores = stores; + } + + public static ListStoreResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListStoreResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListStoreResponse other = (ListStoreResponse) o; + return (Objects.equals(stores, other.stores)); + } + + @Override + public int hashCode() { + return Objects.hash(stores); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchStoreResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private PatchStoreResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static PatchStoreResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchStoreResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchStoreResponse other = (PatchStoreResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchStoreResponse extends Resource { + + @Getter + private final ZonedDateTime dataAsOf; + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final String id; + + @Getter + private final String intelligenceServiceId; + + @Getter + private final Store.Status status; + + @Getter + private final Integer version; + + @JsonCreator + private FetchStoreResponse( + @JsonProperty("dataAsOf") final ZonedDateTime dataAsOf, + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("id") final String id, + @JsonProperty( + "intelligenceServiceId" + ) final String intelligenceServiceId, + @JsonProperty("status") final Store.Status status, + @JsonProperty("version") final Integer version + ) { + this.dataAsOf = dataAsOf; + this.description = description; + this.displayName = displayName; + this.id = id; + this.intelligenceServiceId = intelligenceServiceId; + this.status = status; + this.version = version; + } + + public static FetchStoreResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchStoreResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchStoreResponse other = (FetchStoreResponse) o; + return ( + Objects.equals(dataAsOf, other.dataAsOf) && + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(id, other.id) && + Objects.equals( + intelligenceServiceId, + other.intelligenceServiceId + ) && + Objects.equals(status, other.status) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dataAsOf, + description, + displayName, + id, + intelligenceServiceId, + status, + version + ); + } + } + + public static StoreCreator creator( + final Store.ServiceRequest serviceRequest + ) { + return new StoreCreator(serviceRequest); + } + + public static StoreDeleter deleter(final String pathStoreId) { + return new StoreDeleter(pathStoreId); + } + + public static StoreFetcher fetcher(final String pathStoreId) { + return new StoreFetcher(pathStoreId); + } + + public static StoreReader reader() { + return new StoreReader(); + } + + public static StorePatcher patcher( + final String pathStoreId, + final Store.PatchStoreRequest patchStoreRequest + ) { + return new StorePatcher(pathStoreId, patchStoreRequest); + } + + public enum Status { + QUEUED("QUEUED"), + PROVISIONING("PROVISIONING"), + ACTIVE("ACTIVE"), + FAILED("FAILED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum OrderBy { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private OrderBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderBy forValue(final String value) { + return Promoter.enumFromString(value, OrderBy.values()); + } + } + + @JsonDeserialize(builder = Meta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Meta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private Meta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static Meta fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Meta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public Meta build() { + return new Meta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Meta other = (Meta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = PatchStoreRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PatchStoreRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + private PatchStoreRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + } + + public static Builder builder() { + return new Builder(); + } + + public static PatchStoreRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, PatchStoreRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public PatchStoreRequest build() { + return new PatchStoreRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PatchStoreRequest other = (PatchStoreRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description); + } + } + + @JsonDeserialize(builder = ServiceRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ServiceRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + private ServiceRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + } + + public static Builder builder(final String displayName) { + return new Builder(displayName); + } + + public static ServiceRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ServiceRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName + ) { + this.displayName = displayName; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + public ServiceRequest build() { + return new ServiceRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ServiceRequest other = (ServiceRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description); + } + } + + /** + * Converts a JSON String into a Store object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Store object represented by the provided JSON + */ + public static Store fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Store.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Store object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Store object represented by the provided JSON + */ + public static Store fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Store.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Store() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/StoreCreator.java b/src/main/java/com/twilio/rest/memory/v1/StoreCreator.java new file mode 100644 index 0000000000..65a2d1bd3c --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/StoreCreator.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class StoreCreator extends Creator { + + private Store.ServiceRequest serviceRequest; + + public StoreCreator(final Store.ServiceRequest serviceRequest) { + this.serviceRequest = serviceRequest; + } + + public StoreCreator setServiceRequest( + final Store.ServiceRequest serviceRequest + ) { + this.serviceRequest = serviceRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores"; + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Store creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Store.CreateStoreResponse create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Store.CreateStoreResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Store.CreateStoreResponse content = Store.CreateStoreResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (serviceRequest != null) { + request.setBody(Store.toJson(serviceRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/StoreDeleter.java b/src/main/java/com/twilio/rest/memory/v1/StoreDeleter.java new file mode 100644 index 0000000000..c0b35e58cd --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/StoreDeleter.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class StoreDeleter + extends ResourceDeleter { + + private String pathStoreId; + + public StoreDeleter(final String pathStoreId) { + this.pathStoreId = pathStoreId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores/{storeId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Store delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Store.DeleteStoreResponse delete(final TwilioRestClient client) { + Response response = makeRequest(client); + return Store.DeleteStoreResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Store.DeleteStoreResponse content = Store.DeleteStoreResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/StoreFetcher.java b/src/main/java/com/twilio/rest/memory/v1/StoreFetcher.java new file mode 100644 index 0000000000..3875c05957 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/StoreFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class StoreFetcher extends Fetcher { + + private String pathStoreId; + + public StoreFetcher(final String pathStoreId) { + this.pathStoreId = pathStoreId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores/{storeId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Store fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Store.FetchStoreResponse fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Store.FetchStoreResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Store.FetchStoreResponse content = Store.FetchStoreResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/StorePatcher.java b/src/main/java/com/twilio/rest/memory/v1/StorePatcher.java new file mode 100644 index 0000000000..65a47ab923 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/StorePatcher.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class StorePatcher extends Patcher { + + private String pathStoreId; + private String ifMatch; + private Store.PatchStoreRequest patchStoreRequest; + + public StorePatcher( + final String pathStoreId, + final Store.PatchStoreRequest patchStoreRequest + ) { + this.pathStoreId = pathStoreId; + this.patchStoreRequest = patchStoreRequest; + } + + public StorePatcher setPatchStoreRequest( + final Store.PatchStoreRequest patchStoreRequest + ) { + this.patchStoreRequest = patchStoreRequest; + return this; + } + + public StorePatcher setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + @Override + public Store.PatchStoreResponse patch(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores/{storeId}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.PATCH, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Store patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return Store.PatchStoreResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (patchStoreRequest != null) { + request.setBody(Store.toJson(patchStoreRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/StoreReader.java b/src/main/java/com/twilio/rest/memory/v1/StoreReader.java new file mode 100644 index 0000000000..6a70228171 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/StoreReader.java @@ -0,0 +1,258 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class StoreReader extends Reader { + + private Integer pageSize; + private String pageToken; + private Store.OrderBy orderBy; + + public StoreReader() {} + + public StoreReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public StoreReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public StoreReader setOrderBy(final Store.OrderBy orderBy) { + this.orderBy = orderBy; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "stores", + response.getContent(), + Store.ListStoreResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores"; + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "stores", + response.getContent(), + Store.ListStoreResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Store read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "stores", + response.getContent(), + Store.ListStoreResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/ControlPlane/Stores"; + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/ControlPlane/Stores"; + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/Trait.java b/src/main/java/com/twilio/rest/memory/v1/Trait.java new file mode 100644 index 0000000000..6f016c44b7 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/Trait.java @@ -0,0 +1,676 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Trait extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateTraitResponse extends Resource { + + @JsonCreator + private CreateTraitResponse() {} + + public static CreateTraitResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CreateTraitResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateTraitResponse other = (CreateTraitResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateTraitResponse extends Resource { + + @JsonCreator + private UpdateTraitResponse() {} + + public static UpdateTraitResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UpdateTraitResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateTraitResponse other = (UpdateTraitResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteTraitResponse extends Resource { + + @JsonCreator + private DeleteTraitResponse() {} + + public static DeleteTraitResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DeleteTraitResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteTraitResponse other = (DeleteTraitResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListTraitResponse extends Resource { + + @Getter + private final String name; + + @Getter + private final String source; + + @Getter + private final ZonedDateTime timestamp; + + @Getter + private final String traitGroup; + + @Getter + private final Object value; + + @JsonCreator + private ListTraitResponse( + @JsonProperty("name") final String name, + @JsonProperty("source") final String source, + @JsonProperty("timestamp") final ZonedDateTime timestamp, + @JsonProperty("traitGroup") final String traitGroup, + @JsonProperty("value") final Object value + ) { + this.name = name; + this.source = source; + this.timestamp = timestamp; + this.traitGroup = traitGroup; + this.value = value; + } + + public static ListTraitResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ListTraitResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListTraitResponse other = (ListTraitResponse) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(source, other.source) && + Objects.equals(timestamp, other.timestamp) && + Objects.equals(traitGroup, other.traitGroup) && + Objects.equals(value, other.value) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, source, timestamp, traitGroup, value); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchTraitResponse extends Resource { + + @JsonCreator + private PatchTraitResponse() {} + + public static PatchTraitResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PatchTraitResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchTraitResponse other = (PatchTraitResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchTraitResponse extends Resource { + + @JsonCreator + private FetchTraitResponse() {} + + public static FetchTraitResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FetchTraitResponse.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchTraitResponse other = (FetchTraitResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + public static TraitReader reader( + final String pathStoreId, + final String pathProfileId + ) { + return new TraitReader(pathStoreId, pathProfileId); + } + + public enum OrderBy { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private OrderBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderBy forValue(final String value) { + return Promoter.enumFromString(value, OrderBy.values()); + } + } + + @JsonDeserialize(builder = ListProfileTraits200ResponseMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ListProfileTraits200ResponseMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final Object key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private ListProfileTraits200ResponseMeta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static ListProfileTraits200ResponseMeta fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + ListProfileTraits200ResponseMeta.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private Object key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(Object key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public ListProfileTraits200ResponseMeta build() { + return new ListProfileTraits200ResponseMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ListProfileTraits200ResponseMeta other = + (ListProfileTraits200ResponseMeta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = FullTrait.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class FullTrait { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + @Getter + private final Object value; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traitGroup") + @Getter + private final String traitGroup; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("timestamp") + @Getter + private final ZonedDateTime timestamp; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + @Getter + private final String source; + + private FullTrait(Builder builder) { + this.name = builder.name; + this.value = builder.value; + this.traitGroup = builder.traitGroup; + this.timestamp = builder.timestamp; + this.source = builder.source; + } + + public static Builder builder( + final String name, + final String traitGroup + ) { + return new Builder(name, traitGroup); + } + + public static FullTrait fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, FullTrait.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("value") + private Object value; + + @JsonProperty("traitGroup") + private String traitGroup; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("timestamp") + private ZonedDateTime timestamp; + + @JsonProperty("source") + private String source; + + @JsonCreator + public Builder( + @JsonProperty("name") final String name, + @JsonProperty("traitGroup") final String traitGroup + ) { + this.name = name; + this.traitGroup = traitGroup; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + public Builder value(Object value) { + this.value = value; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("timestamp") + public Builder timestamp(ZonedDateTime timestamp) { + this.timestamp = timestamp; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("source") + public Builder source(String source) { + this.source = source; + return this; + } + + public FullTrait build() { + return new FullTrait(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FullTrait other = (FullTrait) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(value, other.value) && + Objects.equals(traitGroup, other.traitGroup) && + Objects.equals(timestamp, other.timestamp) && + Objects.equals(source, other.source) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, value, traitGroup, timestamp, source); + } + } + + /** + * Converts a JSON String into a Trait object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Trait object represented by the provided JSON + */ + public static Trait fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Trait.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Trait object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Trait object represented by the provided JSON + */ + public static Trait fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Trait.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private Trait() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/TraitGroup.java b/src/main/java/com/twilio/rest/memory/v1/TraitGroup.java new file mode 100644 index 0000000000..fdb7c0f9e6 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/TraitGroup.java @@ -0,0 +1,1541 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TraitGroup extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateTraitGroupResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private CreateTraitGroupResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static CreateTraitGroupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateTraitGroupResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateTraitGroupResponse other = (CreateTraitGroupResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateTraitGroupResponse extends Resource { + + @JsonCreator + private UpdateTraitGroupResponse() {} + + public static UpdateTraitGroupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateTraitGroupResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateTraitGroupResponse other = (UpdateTraitGroupResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteTraitGroupResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private DeleteTraitGroupResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static DeleteTraitGroupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteTraitGroupResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteTraitGroupResponse other = (DeleteTraitGroupResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListTraitGroupResponse extends Resource { + + @Getter + private final String description; + + @Getter + private final String displayName; + + @Getter + private final Map traits; + + @Getter + private final Integer version; + + @JsonCreator + private ListTraitGroupResponse( + @JsonProperty("description") final String description, + @JsonProperty("displayName") final String displayName, + @JsonProperty("traits") final Map< + String, + TraitGroupCoreTraits + > traits, + @JsonProperty("version") final Integer version + ) { + this.description = description; + this.displayName = displayName; + this.traits = traits; + this.version = version; + } + + public static ListTraitGroupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListTraitGroupResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListTraitGroupResponse other = (ListTraitGroupResponse) o; + return ( + Objects.equals(description, other.description) && + Objects.equals(displayName, other.displayName) && + Objects.equals(traits, other.traits) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash(description, displayName, traits, version); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchTraitGroupResponse extends Resource { + + @Getter + private final String message; + + @Getter + private final String statusUrl; + + @JsonCreator + private PatchTraitGroupResponse( + @JsonProperty("message") final String message, + @JsonProperty("statusUrl") final String statusUrl + ) { + this.message = message; + this.statusUrl = statusUrl; + } + + public static PatchTraitGroupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchTraitGroupResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchTraitGroupResponse other = (PatchTraitGroupResponse) o; + return ( + Objects.equals(message, other.message) && + Objects.equals(statusUrl, other.statusUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash(message, statusUrl); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchTraitGroupResponse extends Resource { + + @Getter + private final Meta meta; + + @Getter + private final _TraitGroup traitGroup; + + @JsonCreator + private FetchTraitGroupResponse( + @JsonProperty("meta") final Meta meta, + @JsonProperty("traitGroup") final _TraitGroup traitGroup + ) { + this.meta = meta; + this.traitGroup = traitGroup; + } + + public static FetchTraitGroupResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchTraitGroupResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchTraitGroupResponse other = (FetchTraitGroupResponse) o; + return ( + Objects.equals(meta, other.meta) && + Objects.equals(traitGroup, other.traitGroup) + ); + } + + @Override + public int hashCode() { + return Objects.hash(meta, traitGroup); + } + } + + public static TraitGroupCreator creator(final String pathStoreId) { + return new TraitGroupCreator(pathStoreId); + } + + public static TraitGroupDeleter deleter( + final String pathStoreId, + final String pathTraitGroupName + ) { + return new TraitGroupDeleter(pathStoreId, pathTraitGroupName); + } + + public static TraitGroupFetcher fetcher( + final String pathStoreId, + final String pathTraitGroupName + ) { + return new TraitGroupFetcher(pathStoreId, pathTraitGroupName); + } + + public static TraitGroupReader reader(final String pathStoreId) { + return new TraitGroupReader(pathStoreId); + } + + public static TraitGroupPatcher patcher( + final String pathStoreId, + final String pathTraitGroupName, + final TraitGroup.PatchTraitGroupRequest patchTraitGroupRequest + ) { + return new TraitGroupPatcher( + pathStoreId, + pathTraitGroupName, + patchTraitGroupRequest + ); + } + + public enum OrderBy { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private OrderBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OrderBy forValue(final String value) { + return Promoter.enumFromString(value, OrderBy.values()); + } + } + + public enum DataType { + STRING("STRING"), + NUMBER("NUMBER"), + BOOLEAN("BOOLEAN"), + ARRAY("ARRAY"), + EMPTY(""); + + private final String value; + + private DataType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static DataType forValue(final String value) { + return Promoter.enumFromString(value, DataType.values()); + } + } + + public enum RuleType { + STRING("STRING"), + NUMBER("NUMBER"), + BOOLEAN("BOOLEAN"), + ARRAY("ARRAY"); + + private final String value; + + private RuleType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RuleType forValue(final String value) { + return Promoter.enumFromString(value, RuleType.values()); + } + } + + @JsonDeserialize(builder = TraitDefinition.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TraitDefinition { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dataType") + @Getter + private final TraitGroup.DataType dataType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("validationRule") + @Getter + private final ValidationRule validationRule; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idTypePromotion") + @Getter + private final String idTypePromotion; + + private TraitDefinition(Builder builder) { + this.dataType = builder.dataType; + this.description = builder.description; + this.validationRule = builder.validationRule; + this.idTypePromotion = builder.idTypePromotion; + } + + public static Builder builder(final TraitGroup.DataType dataType) { + return new Builder(dataType); + } + + public static TraitDefinition fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TraitDefinition.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("dataType") + private TraitGroup.DataType dataType; + + @JsonProperty("description") + private String description; + + @JsonProperty("validationRule") + private ValidationRule validationRule; + + @JsonProperty("idTypePromotion") + private String idTypePromotion; + + @JsonCreator + public Builder( + @JsonProperty("dataType") final TraitGroup.DataType dataType + ) { + this.dataType = dataType; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("validationRule") + public Builder validationRule(ValidationRule validationRule) { + this.validationRule = validationRule; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idTypePromotion") + public Builder idTypePromotion(String idTypePromotion) { + this.idTypePromotion = idTypePromotion; + return this; + } + + public TraitDefinition build() { + return new TraitDefinition(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TraitDefinition other = (TraitDefinition) o; + return ( + Objects.equals(dataType, other.dataType) && + Objects.equals(description, other.description) && + Objects.equals(validationRule, other.validationRule) && + Objects.equals(idTypePromotion, other.idTypePromotion) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dataType, + description, + validationRule, + idTypePromotion + ); + } + } + + @JsonDeserialize(builder = _TraitGroup.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class _TraitGroup { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + @Getter + private final Map traits; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final Integer version; + + private _TraitGroup(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.traits = builder.traits; + this.version = builder.version; + } + + public static Builder builder( + final String displayName, + final Integer version + ) { + return new Builder(displayName, version); + } + + public static _TraitGroup fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, _TraitGroup.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("traits") + private Map traits; + + @JsonProperty("version") + private Integer version; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName, + @JsonProperty("version") final Integer version + ) { + this.displayName = displayName; + this.version = version; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + public Builder traits(Map traits) { + this.traits = traits; + return this; + } + + public _TraitGroup build() { + return new _TraitGroup(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + _TraitGroup other = (_TraitGroup) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(traits, other.traits) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description, traits, version); + } + } + + @JsonDeserialize(builder = Meta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class Meta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + @Getter + private final String key; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + @Getter + private final Integer pageSize; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + @Getter + private final String nextToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + @Getter + private final String previousToken; + + private Meta(Builder builder) { + this.key = builder.key; + this.pageSize = builder.pageSize; + this.nextToken = builder.nextToken; + this.previousToken = builder.previousToken; + } + + public static Builder builder() { + return new Builder(); + } + + public static Meta fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, Meta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("key") + private String key; + + @JsonProperty("pageSize") + private Integer pageSize; + + @JsonProperty("nextToken") + private String nextToken; + + @JsonProperty("previousToken") + private String previousToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("key") + public Builder key(String key) { + this.key = key; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pageSize") + public Builder pageSize(Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("nextToken") + public Builder nextToken(String nextToken) { + this.nextToken = nextToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("previousToken") + public Builder previousToken(String previousToken) { + this.previousToken = previousToken; + return this; + } + + public Meta build() { + return new Meta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Meta other = (Meta) o; + return ( + Objects.equals(key, other.key) && + Objects.equals(pageSize, other.pageSize) && + Objects.equals(nextToken, other.nextToken) && + Objects.equals(previousToken, other.previousToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(key, pageSize, nextToken, previousToken); + } + } + + @JsonDeserialize(builder = TraitGroupCoreTraits.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TraitGroupCoreTraits { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dataType") + @Getter + private final TraitGroup.DataType dataType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("validationRule") + @Getter + private final ValidationRule validationRule; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idTypePromotion") + @Getter + private final String idTypePromotion; + + private TraitGroupCoreTraits(Builder builder) { + this.dataType = builder.dataType; + this.description = builder.description; + this.validationRule = builder.validationRule; + this.idTypePromotion = builder.idTypePromotion; + } + + public static Builder builder(final TraitGroup.DataType dataType) { + return new Builder(dataType); + } + + public static TraitGroupCoreTraits fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TraitGroupCoreTraits.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("dataType") + private TraitGroup.DataType dataType; + + @JsonProperty("description") + private String description; + + @JsonProperty("validationRule") + private ValidationRule validationRule; + + @JsonProperty("idTypePromotion") + private String idTypePromotion; + + @JsonCreator + public Builder( + @JsonProperty("dataType") final TraitGroup.DataType dataType + ) { + this.dataType = dataType; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("validationRule") + public Builder validationRule(ValidationRule validationRule) { + this.validationRule = validationRule; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idTypePromotion") + public Builder idTypePromotion(String idTypePromotion) { + this.idTypePromotion = idTypePromotion; + return this; + } + + public TraitGroupCoreTraits build() { + return new TraitGroupCoreTraits(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TraitGroupCoreTraits other = (TraitGroupCoreTraits) o; + return ( + Objects.equals(dataType, other.dataType) && + Objects.equals(description, other.description) && + Objects.equals(validationRule, other.validationRule) && + Objects.equals(idTypePromotion, other.idTypePromotion) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dataType, + description, + validationRule, + idTypePromotion + ); + } + } + + @JsonDeserialize(builder = PatchTraitGroupRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PatchTraitGroupRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + @Getter + private final Map traits; + + private PatchTraitGroupRequest(Builder builder) { + this.description = builder.description; + this.traits = builder.traits; + } + + public static Builder builder() { + return new Builder(); + } + + public static PatchTraitGroupRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, PatchTraitGroupRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("description") + private String description; + + @JsonProperty("traits") + private Map traits; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + public Builder traits(Map traits) { + this.traits = traits; + return this; + } + + public PatchTraitGroupRequest build() { + return new PatchTraitGroupRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PatchTraitGroupRequest other = (PatchTraitGroupRequest) o; + return ( + Objects.equals(description, other.description) && + Objects.equals(traits, other.traits) + ); + } + + @Override + public int hashCode() { + return Objects.hash(description, traits); + } + } + + @JsonDeserialize(builder = TraitGroupRequestTraits.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TraitGroupRequestTraits { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("dataType") + @Getter + private final TraitGroup.DataType dataType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("validationRule") + @Getter + private final ValidationRule validationRule; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idTypePromotion") + @Getter + private final String idTypePromotion; + + private TraitGroupRequestTraits(Builder builder) { + this.dataType = builder.dataType; + this.description = builder.description; + this.validationRule = builder.validationRule; + this.idTypePromotion = builder.idTypePromotion; + } + + public static Builder builder(final TraitGroup.DataType dataType) { + return new Builder(dataType); + } + + public static TraitGroupRequestTraits fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TraitGroupRequestTraits.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("dataType") + private TraitGroup.DataType dataType; + + @JsonProperty("description") + private String description; + + @JsonProperty("validationRule") + private ValidationRule validationRule; + + @JsonProperty("idTypePromotion") + private String idTypePromotion; + + @JsonCreator + public Builder( + @JsonProperty("dataType") final TraitGroup.DataType dataType + ) { + this.dataType = dataType; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("validationRule") + public Builder validationRule(ValidationRule validationRule) { + this.validationRule = validationRule; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("idTypePromotion") + public Builder idTypePromotion(String idTypePromotion) { + this.idTypePromotion = idTypePromotion; + return this; + } + + public TraitGroupRequestTraits build() { + return new TraitGroupRequestTraits(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TraitGroupRequestTraits other = (TraitGroupRequestTraits) o; + return ( + Objects.equals(dataType, other.dataType) && + Objects.equals(description, other.description) && + Objects.equals(validationRule, other.validationRule) && + Objects.equals(idTypePromotion, other.idTypePromotion) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dataType, + description, + validationRule, + idTypePromotion + ); + } + } + + @JsonDeserialize(builder = TraitGroupRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TraitGroupRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + @Getter + private final Map traits; + + private TraitGroupRequest(Builder builder) { + this.displayName = builder.displayName; + this.description = builder.description; + this.traits = builder.traits; + } + + public static Builder builder(final String displayName) { + return new Builder(displayName); + } + + public static TraitGroupRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TraitGroupRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("description") + private String description; + + @JsonProperty("traits") + private Map traits; + + @JsonCreator + public Builder( + @JsonProperty("displayName") final String displayName + ) { + this.displayName = displayName; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traits") + public Builder traits(Map traits) { + this.traits = traits; + return this; + } + + public TraitGroupRequest build() { + return new TraitGroupRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TraitGroupRequest other = (TraitGroupRequest) o; + return ( + Objects.equals(displayName, other.displayName) && + Objects.equals(description, other.description) && + Objects.equals(traits, other.traits) + ); + } + + @Override + public int hashCode() { + return Objects.hash(displayName, description, traits); + } + } + + @JsonDeserialize(builder = ValidationRule.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ValidationRule { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pattern") + @Getter + private final String pattern; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("minLength") + @Getter + private final Integer minLength; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("maxLength") + @Getter + private final Integer maxLength; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ruleType") + @Getter + private final TraitGroup.RuleType ruleType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("min") + @Getter + private final BigDecimal min; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("max") + @Getter + private final BigDecimal max; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("minItems") + @Getter + private final Integer minItems; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("maxItems") + @Getter + private final Integer maxItems; + + private ValidationRule(Builder builder) { + this.pattern = builder.pattern; + this.minLength = builder.minLength; + this.maxLength = builder.maxLength; + this.ruleType = builder.ruleType; + this.min = builder.min; + this.max = builder.max; + this.minItems = builder.minItems; + this.maxItems = builder.maxItems; + } + + public static Builder builder() { + return new Builder(); + } + + public static ValidationRule fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ValidationRule.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("pattern") + private String pattern; + + @JsonProperty("minLength") + private Integer minLength; + + @JsonProperty("maxLength") + private Integer maxLength; + + @JsonProperty("ruleType") + private TraitGroup.RuleType ruleType; + + @JsonProperty("min") + private BigDecimal min; + + @JsonProperty("max") + private BigDecimal max; + + @JsonProperty("minItems") + private Integer minItems; + + @JsonProperty("maxItems") + private Integer maxItems; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pattern") + public Builder pattern(String pattern) { + this.pattern = pattern; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("minLength") + public Builder minLength(Integer minLength) { + this.minLength = minLength; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("maxLength") + public Builder maxLength(Integer maxLength) { + this.maxLength = maxLength; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ruleType") + public Builder ruleType(TraitGroup.RuleType ruleType) { + this.ruleType = ruleType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("min") + public Builder min(BigDecimal min) { + this.min = min; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("max") + public Builder max(BigDecimal max) { + this.max = max; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("minItems") + public Builder minItems(Integer minItems) { + this.minItems = minItems; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("maxItems") + public Builder maxItems(Integer maxItems) { + this.maxItems = maxItems; + return this; + } + + public ValidationRule build() { + return new ValidationRule(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ValidationRule other = (ValidationRule) o; + return ( + Objects.equals(pattern, other.pattern) && + Objects.equals(minLength, other.minLength) && + Objects.equals(maxLength, other.maxLength) && + Objects.equals(ruleType, other.ruleType) && + Objects.equals(min, other.min) && + Objects.equals(max, other.max) && + Objects.equals(minItems, other.minItems) && + Objects.equals(maxItems, other.maxItems) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + pattern, + minLength, + maxLength, + ruleType, + min, + max, + minItems, + maxItems + ); + } + } + + /** + * Converts a JSON String into a TraitGroup object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TraitGroup object represented by the provided JSON + */ + public static TraitGroup fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TraitGroup.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TraitGroup object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TraitGroup object represented by the provided JSON + */ + public static TraitGroup fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TraitGroup.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private TraitGroup() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/TraitGroupCreator.java b/src/main/java/com/twilio/rest/memory/v1/TraitGroupCreator.java new file mode 100644 index 0000000000..1a7055c732 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/TraitGroupCreator.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TraitGroupCreator + extends Creator { + + private String pathStoreId; + private TraitGroup.TraitGroupRequest traitGroupRequest; + + public TraitGroupCreator(final String pathStoreId) { + this.pathStoreId = pathStoreId; + } + + public TraitGroupCreator setTraitGroupRequest( + final TraitGroup.TraitGroupRequest traitGroupRequest + ) { + this.traitGroupRequest = traitGroupRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores/{storeId}/TraitGroups"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TraitGroup creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TraitGroup.CreateTraitGroupResponse create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return TraitGroup.CreateTraitGroupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + TraitGroup.CreateTraitGroupResponse + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + TraitGroup.CreateTraitGroupResponse content = + TraitGroup.CreateTraitGroupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (traitGroupRequest != null) { + request.setBody(TraitGroup.toJson(traitGroupRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/TraitGroupDeleter.java b/src/main/java/com/twilio/rest/memory/v1/TraitGroupDeleter.java new file mode 100644 index 0000000000..2a42abaa10 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/TraitGroupDeleter.java @@ -0,0 +1,114 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.ResourceDeleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class TraitGroupDeleter + extends ResourceDeleter { + + private String pathStoreId; + private String pathTraitGroupName; + + public TraitGroupDeleter( + final String pathStoreId, + final String pathTraitGroupName + ) { + this.pathStoreId = pathStoreId; + this.pathTraitGroupName = pathTraitGroupName; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ControlPlane/Stores/{storeId}/TraitGroups/{traitGroupName}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "traitGroupName" + "}", + this.pathTraitGroupName.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MEMORY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TraitGroup delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TraitGroup.DeleteTraitGroupResponse delete( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return TraitGroup.DeleteTraitGroupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + TraitGroup.DeleteTraitGroupResponse + > deleteWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + TraitGroup.DeleteTraitGroupResponse content = + TraitGroup.DeleteTraitGroupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/TraitGroupFetcher.java b/src/main/java/com/twilio/rest/memory/v1/TraitGroupFetcher.java new file mode 100644 index 0000000000..cd3bf2b5b9 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/TraitGroupFetcher.java @@ -0,0 +1,176 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TraitGroupFetcher + extends Fetcher { + + private String pathStoreId; + private String pathTraitGroupName; + private Boolean includeTraits; + private Integer pageSize; + private String pageToken; + private TraitGroup.OrderBy orderBy; + + public TraitGroupFetcher( + final String pathStoreId, + final String pathTraitGroupName + ) { + this.pathStoreId = pathStoreId; + this.pathTraitGroupName = pathTraitGroupName; + } + + public TraitGroupFetcher setIncludeTraits(final Boolean includeTraits) { + this.includeTraits = includeTraits; + return this; + } + + public TraitGroupFetcher setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public TraitGroupFetcher setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public TraitGroupFetcher setOrderBy(final TraitGroup.OrderBy orderBy) { + this.orderBy = orderBy; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ControlPlane/Stores/{storeId}/TraitGroups/{traitGroupName}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "traitGroupName" + "}", + this.pathTraitGroupName.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TraitGroup fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TraitGroup.FetchTraitGroupResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return TraitGroup.FetchTraitGroupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TraitGroup.FetchTraitGroupResponse content = + TraitGroup.FetchTraitGroupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (includeTraits != null) { + Serializer.toString( + request, + "includeTraits", + includeTraits, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/TraitGroupPatcher.java b/src/main/java/com/twilio/rest/memory/v1/TraitGroupPatcher.java new file mode 100644 index 0000000000..1610799550 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/TraitGroupPatcher.java @@ -0,0 +1,132 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TraitGroupPatcher + extends Patcher { + + private String pathStoreId; + private String pathTraitGroupName; + private String ifMatch; + private TraitGroup.PatchTraitGroupRequest patchTraitGroupRequest; + + public TraitGroupPatcher( + final String pathStoreId, + final String pathTraitGroupName, + final TraitGroup.PatchTraitGroupRequest patchTraitGroupRequest + ) { + this.pathStoreId = pathStoreId; + this.pathTraitGroupName = pathTraitGroupName; + this.patchTraitGroupRequest = patchTraitGroupRequest; + } + + public TraitGroupPatcher setPatchTraitGroupRequest( + final TraitGroup.PatchTraitGroupRequest patchTraitGroupRequest + ) { + this.patchTraitGroupRequest = patchTraitGroupRequest; + return this; + } + + public TraitGroupPatcher setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + @Override + public TraitGroup.PatchTraitGroupResponse patch( + final TwilioRestClient client + ) { + String path = + "/v1/ControlPlane/Stores/{storeId}/TraitGroups/{traitGroupName}"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "traitGroupName" + "}", + this.pathTraitGroupName.toString() + ); + + Request request = new Request( + HttpMethod.PATCH, + Domains.MEMORY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TraitGroup patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return TraitGroup.PatchTraitGroupResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (patchTraitGroupRequest != null) { + request.setBody( + TraitGroup.toJson(patchTraitGroupRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/TraitGroupReader.java b/src/main/java/com/twilio/rest/memory/v1/TraitGroupReader.java new file mode 100644 index 0000000000..3f85b3d24d --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/TraitGroupReader.java @@ -0,0 +1,280 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TraitGroupReader + extends Reader { + + private String pathStoreId; + private Boolean includeTraits; + private Integer pageSize; + private String pageToken; + private TraitGroup.OrderBy orderBy; + + public TraitGroupReader(final String pathStoreId) { + this.pathStoreId = pathStoreId; + } + + public TraitGroupReader setIncludeTraits(final Boolean includeTraits) { + this.includeTraits = includeTraits; + return this; + } + + public TraitGroupReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public TraitGroupReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public TraitGroupReader setOrderBy(final TraitGroup.OrderBy orderBy) { + this.orderBy = orderBy; + return this; + } + + public ResourceSetResponse< + TraitGroup.ListTraitGroupResponse + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "traitGroups", + response.getContent(), + TraitGroup.ListTraitGroupResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/ControlPlane/Stores/{storeId}/TraitGroups"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "traitGroups", + response.getContent(), + TraitGroup.ListTraitGroupResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TraitGroup read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "traitGroups", + response.getContent(), + TraitGroup.ListTraitGroupResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/ControlPlane/Stores/{storeId}/TraitGroups"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/ControlPlane/Stores/{storeId}/TraitGroups"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (includeTraits != null) { + Serializer.toString( + request, + "includeTraits", + includeTraits, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/memory/v1/TraitReader.java b/src/main/java/com/twilio/rest/memory/v1/TraitReader.java new file mode 100644 index 0000000000..a4980fbda4 --- /dev/null +++ b/src/main/java/com/twilio/rest/memory/v1/TraitReader.java @@ -0,0 +1,299 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio Memory API + * APIs for managing memory stores, profiles, and conversational intelligence capabilities. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.memory.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TokenPaginationPage; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.exception.RestStandardException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TraitReader extends Reader { + + private String pathStoreId; + private String pathProfileId; + private Integer pageSize; + private String pageToken; + private Trait.OrderBy orderBy; + private String traitGroups; + + public TraitReader(final String pathStoreId, final String pathProfileId) { + this.pathStoreId = pathStoreId; + this.pathProfileId = pathProfileId; + } + + public TraitReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public TraitReader setPageToken(final String pageToken) { + this.pageToken = pageToken; + return this; + } + + public TraitReader setOrderBy(final Trait.OrderBy orderBy) { + this.orderBy = orderBy; + return this; + } + + public TraitReader setTraitGroups(final String traitGroups) { + this.traitGroups = traitGroups; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "traits", + response.getContent(), + Trait.ListTraitResponse.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Traits"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "traits", + response.getContent(), + Trait.ListTraitResponse.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Trait read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestStandardException standardException = + RestStandardException.fromJson( + inputStream, + client.getObjectMapper() + ); + if ( + standardException != null && standardException.getType() != null + ) { + throw new ApiException(standardException); + } + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return TokenPaginationPage.fromJson( + "traits", + response.getContent(), + Trait.ListTraitResponse.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Traits"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + path = path + page.previousQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + String path = "/v1/Stores/{storeId}/Profiles/{profileId}/Traits"; + + path = path.replace("{" + "storeId" + "}", this.pathStoreId.toString()); + path = + path.replace( + "{" + "profileId" + "}", + this.pathProfileId.toString() + ); + + path = path + page.nextQueryString(); + Request request = new Request( + HttpMethod.GET, + Domains.MEMORY.toString(), + path + ); + + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "pageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (pageToken != null) { + Serializer.toString( + request, + "pageToken", + pageToken, + ParameterType.QUERY + ); + } + + if (orderBy != null) { + Serializer.toString( + request, + "orderBy", + orderBy, + ParameterType.QUERY + ); + } + + if (traitGroups != null) { + Serializer.toString( + request, + "traitGroups", + traitGroups, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistration.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistration.java new file mode 100644 index 0000000000..f508b05180 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistration.java @@ -0,0 +1,423 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BrandRegistration extends Resource { + + public static BrandRegistrationCreator creator( + final String customerProfileBundleSid, + final String a2PProfileBundleSid + ) { + return new BrandRegistrationCreator( + customerProfileBundleSid, + a2PProfileBundleSid + ); + } + + public static BrandRegistrationFetcher fetcher(final String pathSid) { + return new BrandRegistrationFetcher(pathSid); + } + + public static BrandRegistrationReader reader() { + return new BrandRegistrationReader(); + } + + public static BrandRegistrationUpdater updater(final String pathSid) { + return new BrandRegistrationUpdater(pathSid); + } + + public enum Status { + PENDING("PENDING"), + APPROVED("APPROVED"), + FAILED("FAILED"), + IN_REVIEW("IN_REVIEW"), + DELETION_PENDING("DELETION_PENDING"), + DELETION_FAILED("DELETION_FAILED"), + SUSPENDED("SUSPENDED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum BrandRegistrationBrandFeedback { + TAX_ID("TAX_ID"), + STOCK_SYMBOL("STOCK_SYMBOL"), + NONPROFIT("NONPROFIT"), + GOVERNMENT_ENTITY("GOVERNMENT_ENTITY"), + OTHERS("OTHERS"); + + private final String value; + + private BrandRegistrationBrandFeedback(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BrandRegistrationBrandFeedback forValue( + final String value + ) { + return Promoter.enumFromString( + value, + BrandRegistrationBrandFeedback.values() + ); + } + } + + public enum BrandFeedback { + TAX_ID("TAX_ID"), + STOCK_SYMBOL("STOCK_SYMBOL"), + NONPROFIT("NONPROFIT"), + GOVERNMENT_ENTITY("GOVERNMENT_ENTITY"), + OTHERS("OTHERS"); + + private final String value; + + private BrandFeedback(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BrandFeedback forValue(final String value) { + return Promoter.enumFromString(value, BrandFeedback.values()); + } + } + + public enum IdentityStatus { + SELF_DECLARED("SELF_DECLARED"), + UNVERIFIED("UNVERIFIED"), + VERIFIED("VERIFIED"), + VETTED_VERIFIED("VETTED_VERIFIED"); + + private final String value; + + private IdentityStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static IdentityStatus forValue(final String value) { + return Promoter.enumFromString(value, IdentityStatus.values()); + } + } + + /** + * Converts a JSON String into a BrandRegistration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BrandRegistration object represented by the provided JSON + */ + public static BrandRegistration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BrandRegistration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BrandRegistration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BrandRegistration object represented by the provided JSON + */ + public static BrandRegistration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BrandRegistration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String a2pProfileBundleSid; + + @Getter + private final String accountSid; + + @Getter + private final List brandFeedback; + + @Getter + private final Integer brandScore; + + @Getter + private final String brandType; + + @Getter + private final String customerProfileBundleSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final List errors; + + @Getter + private final String failureReason; + + @Getter + private final Boolean governmentEntity; + + @Getter + private final BrandRegistration.IdentityStatus identityStatus; + + @Getter + private final Map links; + + @Getter + private final Boolean mock; + + @Getter + private final Boolean russell3000; + + @Getter + private final String sid; + + @Getter + private final Boolean skipAutomaticSecVet; + + @Getter + private final BrandRegistration.Status status; + + @Getter + private final String taxExemptStatus; + + @Getter + private final String tcrId; + + @Getter + private final URI url; + + @JsonCreator + private BrandRegistration( + @JsonProperty( + "a2p_profile_bundle_sid" + ) final String a2pProfileBundleSid, + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("brand_feedback") final List< + BrandRegistration.BrandFeedback + > brandFeedback, + @JsonProperty("brand_score") final Integer brandScore, + @JsonProperty("brand_type") final String brandType, + @JsonProperty( + "customer_profile_bundle_sid" + ) final String customerProfileBundleSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("errors") final List errors, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("government_entity") final Boolean governmentEntity, + @JsonProperty( + "identity_status" + ) final BrandRegistration.IdentityStatus identityStatus, + @JsonProperty("links") final Map links, + @JsonProperty("mock") final Boolean mock, + @JsonProperty("russell_3000") final Boolean russell3000, + @JsonProperty("sid") final String sid, + @JsonProperty( + "skip_automatic_sec_vet" + ) final Boolean skipAutomaticSecVet, + @JsonProperty("status") final BrandRegistration.Status status, + @JsonProperty("tax_exempt_status") final String taxExemptStatus, + @JsonProperty("tcr_id") final String tcrId, + @JsonProperty("url") final URI url + ) { + this.a2pProfileBundleSid = a2pProfileBundleSid; + this.accountSid = accountSid; + this.brandFeedback = brandFeedback; + this.brandScore = brandScore; + this.brandType = brandType; + this.customerProfileBundleSid = customerProfileBundleSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.errors = errors; + this.failureReason = failureReason; + this.governmentEntity = governmentEntity; + this.identityStatus = identityStatus; + this.links = links; + this.mock = mock; + this.russell3000 = russell3000; + this.sid = sid; + this.skipAutomaticSecVet = skipAutomaticSecVet; + this.status = status; + this.taxExemptStatus = taxExemptStatus; + this.tcrId = tcrId; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BrandRegistration other = (BrandRegistration) o; + return ( + Objects.equals(a2pProfileBundleSid, other.a2pProfileBundleSid) && + Objects.equals(accountSid, other.accountSid) && + Objects.equals(brandFeedback, other.brandFeedback) && + Objects.equals(brandScore, other.brandScore) && + Objects.equals(brandType, other.brandType) && + Objects.equals( + customerProfileBundleSid, + other.customerProfileBundleSid + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errors, other.errors) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(governmentEntity, other.governmentEntity) && + Objects.equals(identityStatus, other.identityStatus) && + Objects.equals(links, other.links) && + Objects.equals(mock, other.mock) && + Objects.equals(russell3000, other.russell3000) && + Objects.equals(sid, other.sid) && + Objects.equals(skipAutomaticSecVet, other.skipAutomaticSecVet) && + Objects.equals(status, other.status) && + Objects.equals(taxExemptStatus, other.taxExemptStatus) && + Objects.equals(tcrId, other.tcrId) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + a2pProfileBundleSid, + accountSid, + brandFeedback, + brandScore, + brandType, + customerProfileBundleSid, + dateCreated, + dateUpdated, + errors, + failureReason, + governmentEntity, + identityStatus, + links, + mock, + russell3000, + sid, + skipAutomaticSecVet, + status, + taxExemptStatus, + tcrId, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationCreator.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationCreator.java new file mode 100644 index 0000000000..86971c9d59 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationCreator.java @@ -0,0 +1,185 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BrandRegistrationCreator extends Creator { + + private String customerProfileBundleSid; + private String a2PProfileBundleSid; + private String brandType; + private Boolean mock; + private Boolean skipAutomaticSecVet; + + public BrandRegistrationCreator( + final String customerProfileBundleSid, + final String a2PProfileBundleSid + ) { + this.customerProfileBundleSid = customerProfileBundleSid; + this.a2PProfileBundleSid = a2PProfileBundleSid; + } + + public BrandRegistrationCreator setCustomerProfileBundleSid( + final String customerProfileBundleSid + ) { + this.customerProfileBundleSid = customerProfileBundleSid; + return this; + } + + public BrandRegistrationCreator setA2PProfileBundleSid( + final String a2PProfileBundleSid + ) { + this.a2PProfileBundleSid = a2PProfileBundleSid; + return this; + } + + public BrandRegistrationCreator setBrandType(final String brandType) { + this.brandType = brandType; + return this; + } + + public BrandRegistrationCreator setMock(final Boolean mock) { + this.mock = mock; + return this; + } + + public BrandRegistrationCreator setSkipAutomaticSecVet( + final Boolean skipAutomaticSecVet + ) { + this.skipAutomaticSecVet = skipAutomaticSecVet; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/a2p/BrandRegistrations"; + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BrandRegistration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BrandRegistration create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BrandRegistration content = BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (customerProfileBundleSid != null) { + Serializer.toString( + request, + "CustomerProfileBundleSid", + customerProfileBundleSid, + ParameterType.URLENCODED + ); + } + + if (a2PProfileBundleSid != null) { + Serializer.toString( + request, + "A2PProfileBundleSid", + a2PProfileBundleSid, + ParameterType.URLENCODED + ); + } + + if (brandType != null) { + Serializer.toString( + request, + "BrandType", + brandType, + ParameterType.URLENCODED + ); + } + + if (mock != null) { + Serializer.toString( + request, + "Mock", + mock, + ParameterType.URLENCODED + ); + } + + if (skipAutomaticSecVet != null) { + Serializer.toString( + request, + "SkipAutomaticSecVet", + skipAutomaticSecVet, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationFetcher.java new file mode 100644 index 0000000000..a062ecf83a --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BrandRegistrationFetcher extends Fetcher { + + private String pathSid; + + public BrandRegistrationFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/a2p/BrandRegistrations/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BrandRegistration fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BrandRegistration fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BrandRegistration content = BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationReader.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationReader.java new file mode 100644 index 0000000000..83f40f2eb5 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BrandRegistrationReader extends Reader { + + private Long pageSize; + + public BrandRegistrationReader() {} + + public BrandRegistrationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "data", + response.getContent(), + BrandRegistration.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/a2p/BrandRegistrations"; + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "data", + response.getContent(), + BrandRegistration.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "BrandRegistration read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "data", + response.getContent(), + BrandRegistration.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationUpdater.java new file mode 100644 index 0000000000..433aebd0f1 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/BrandRegistrationUpdater.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BrandRegistrationUpdater extends Updater { + + private String pathSid; + + public BrandRegistrationUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/a2p/BrandRegistrations/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BrandRegistration update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BrandRegistration update(final TwilioRestClient client) { + Response response = makeRequest(client); + return BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BrandRegistration content = BrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/Deactivations.java b/src/main/java/com/twilio/rest/messaging/v1/Deactivations.java new file mode 100644 index 0000000000..20c4492ac5 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/Deactivations.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Deactivations extends Resource { + + public static DeactivationsFetcher fetcher() { + return new DeactivationsFetcher(); + } + + /** + * Converts a JSON String into a Deactivations object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Deactivations object represented by the provided JSON + */ + public static Deactivations fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Deactivations.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Deactivations object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Deactivations object represented by the provided JSON + */ + public static Deactivations fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Deactivations.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final URI redirectTo; + + @JsonCreator + private Deactivations(@JsonProperty("redirect_to") final URI redirectTo) { + this.redirectTo = redirectTo; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Deactivations other = (Deactivations) o; + return (Objects.equals(redirectTo, other.redirectTo)); + } + + @Override + public int hashCode() { + return Objects.hash(redirectTo); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DeactivationsFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DeactivationsFetcher.java new file mode 100644 index 0000000000..1ebdba7c1c --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DeactivationsFetcher.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; + +public class DeactivationsFetcher extends Fetcher { + + private LocalDate date; + + public DeactivationsFetcher() {} + + public DeactivationsFetcher setDate(final LocalDate date) { + this.date = date; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Deactivations"; + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Deactivations fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Deactivations fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Deactivations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Deactivations content = Deactivations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (date != null) { + Serializer.toString(request, "Date", date, ParameterType.QUERY); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainCerts.java b/src/main/java/com/twilio/rest/messaging/v1/DomainCerts.java new file mode 100644 index 0000000000..ed4dea2b53 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainCerts.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DomainCerts extends Resource { + + public static DomainCertsDeleter deleter(final String pathDomainSid) { + return new DomainCertsDeleter(pathDomainSid); + } + + public static DomainCertsFetcher fetcher(final String pathDomainSid) { + return new DomainCertsFetcher(pathDomainSid); + } + + public static DomainCertsUpdater updater( + final String pathDomainSid, + final String tlsCert + ) { + return new DomainCertsUpdater(pathDomainSid, tlsCert); + } + + /** + * Converts a JSON String into a DomainCerts object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DomainCerts object represented by the provided JSON + */ + public static DomainCerts fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DomainCerts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DomainCerts object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DomainCerts object represented by the provided JSON + */ + public static DomainCerts fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DomainCerts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object certInValidation; + + @Getter + private final String certificateSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final URI domainName; + + @Getter + private final String domainSid; + + @Getter + private final URI url; + + @JsonCreator + private DomainCerts( + @JsonProperty("cert_in_validation") final Object certInValidation, + @JsonProperty("certificate_sid") final String certificateSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_name") final URI domainName, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("url") final URI url + ) { + this.certInValidation = certInValidation; + this.certificateSid = certificateSid; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.domainName = domainName; + this.domainSid = domainSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DomainCerts other = (DomainCerts) o; + return ( + Objects.equals(certInValidation, other.certInValidation) && + Objects.equals(certificateSid, other.certificateSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainName, other.domainName) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + certInValidation, + certificateSid, + dateCreated, + dateExpires, + dateUpdated, + domainName, + domainSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsDeleter.java new file mode 100644 index 0000000000..722425b162 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsDeleter.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class DomainCertsDeleter extends Deleter { + + private String pathDomainSid; + + public DomainCertsDeleter(final String pathDomainSid) { + this.pathDomainSid = pathDomainSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/LinkShortening/Domains/{DomainSid}/Certificate"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DomainCerts delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsFetcher.java new file mode 100644 index 0000000000..69ec51b395 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DomainCertsFetcher extends Fetcher { + + private String pathDomainSid; + + public DomainCertsFetcher(final String pathDomainSid) { + this.pathDomainSid = pathDomainSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/LinkShortening/Domains/{DomainSid}/Certificate"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DomainCerts fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DomainCerts fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DomainCerts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DomainCerts content = DomainCerts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainCertsUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsUpdater.java new file mode 100644 index 0000000000..7b85a09f78 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainCertsUpdater.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DomainCertsUpdater extends Updater { + + private String pathDomainSid; + private String tlsCert; + + public DomainCertsUpdater( + final String pathDomainSid, + final String tlsCert + ) { + this.pathDomainSid = pathDomainSid; + this.tlsCert = tlsCert; + } + + public DomainCertsUpdater setTlsCert(final String tlsCert) { + this.tlsCert = tlsCert; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/LinkShortening/Domains/{DomainSid}/Certificate"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DomainCerts update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DomainCerts update(final TwilioRestClient client) { + Response response = makeRequest(client); + return DomainCerts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DomainCerts content = DomainCerts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (tlsCert != null) { + Serializer.toString( + request, + "TlsCert", + tlsCert, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfig.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfig.java new file mode 100644 index 0000000000..751a670c8e --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfig.java @@ -0,0 +1,206 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DomainConfig extends Resource { + + public static DomainConfigFetcher fetcher(final String pathDomainSid) { + return new DomainConfigFetcher(pathDomainSid); + } + + public static DomainConfigUpdater updater(final String pathDomainSid) { + return new DomainConfigUpdater(pathDomainSid); + } + + /** + * Converts a JSON String into a DomainConfig object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DomainConfig object represented by the provided JSON + */ + public static DomainConfig fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DomainConfig.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DomainConfig object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DomainConfig object represented by the provided JSON + */ + public static DomainConfig fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DomainConfig.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final URI callbackUrl; + + @Getter + private final String configSid; + + @Getter + private final Boolean continueOnFailure; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Boolean disableHttps; + + @Getter + private final String domainSid; + + @Getter + private final URI fallbackUrl; + + @Getter + private final URI url; + + @JsonCreator + private DomainConfig( + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("config_sid") final String configSid, + @JsonProperty("continue_on_failure") final Boolean continueOnFailure, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("disable_https") final Boolean disableHttps, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("fallback_url") final URI fallbackUrl, + @JsonProperty("url") final URI url + ) { + this.callbackUrl = callbackUrl; + this.configSid = configSid; + this.continueOnFailure = continueOnFailure; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.disableHttps = disableHttps; + this.domainSid = domainSid; + this.fallbackUrl = fallbackUrl; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DomainConfig other = (DomainConfig) o; + return ( + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(configSid, other.configSid) && + Objects.equals(continueOnFailure, other.continueOnFailure) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(disableHttps, other.disableHttps) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(fallbackUrl, other.fallbackUrl) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + callbackUrl, + configSid, + continueOnFailure, + dateCreated, + dateUpdated, + disableHttps, + domainSid, + fallbackUrl, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigFetcher.java new file mode 100644 index 0000000000..437331a219 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DomainConfigFetcher extends Fetcher { + + private String pathDomainSid; + + public DomainConfigFetcher(final String pathDomainSid) { + this.pathDomainSid = pathDomainSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/LinkShortening/Domains/{DomainSid}/Config"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DomainConfig fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DomainConfig fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DomainConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DomainConfig content = DomainConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingService.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingService.java new file mode 100644 index 0000000000..cb523e89c9 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingService.java @@ -0,0 +1,210 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DomainConfigMessagingService extends Resource { + + public static DomainConfigMessagingServiceFetcher fetcher( + final String pathMessagingServiceSid + ) { + return new DomainConfigMessagingServiceFetcher(pathMessagingServiceSid); + } + + /** + * Converts a JSON String into a DomainConfigMessagingService object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DomainConfigMessagingService object represented by the provided JSON + */ + public static DomainConfigMessagingService fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DomainConfigMessagingService.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DomainConfigMessagingService object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DomainConfigMessagingService object represented by the provided JSON + */ + public static DomainConfigMessagingService fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DomainConfigMessagingService.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final URI callbackUrl; + + @Getter + private final String configSid; + + @Getter + private final Boolean continueOnFailure; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String domainSid; + + @Getter + private final URI fallbackUrl; + + @Getter + private final String messagingServiceSid; + + @Getter + private final URI url; + + @JsonCreator + private DomainConfigMessagingService( + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("config_sid") final String configSid, + @JsonProperty("continue_on_failure") final Boolean continueOnFailure, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("fallback_url") final URI fallbackUrl, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("url") final URI url + ) { + this.callbackUrl = callbackUrl; + this.configSid = configSid; + this.continueOnFailure = continueOnFailure; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.domainSid = domainSid; + this.fallbackUrl = fallbackUrl; + this.messagingServiceSid = messagingServiceSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DomainConfigMessagingService other = (DomainConfigMessagingService) o; + return ( + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(configSid, other.configSid) && + Objects.equals(continueOnFailure, other.continueOnFailure) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(fallbackUrl, other.fallbackUrl) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + callbackUrl, + configSid, + continueOnFailure, + dateCreated, + dateUpdated, + domainSid, + fallbackUrl, + messagingServiceSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingServiceFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingServiceFetcher.java new file mode 100644 index 0000000000..7b292fb326 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigMessagingServiceFetcher.java @@ -0,0 +1,105 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DomainConfigMessagingServiceFetcher + extends Fetcher { + + private String pathMessagingServiceSid; + + public DomainConfigMessagingServiceFetcher( + final String pathMessagingServiceSid + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/LinkShortening/MessagingService/{MessagingServiceSid}/DomainConfig"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DomainConfigMessagingService fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DomainConfigMessagingService fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DomainConfigMessagingService.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DomainConfigMessagingService content = + DomainConfigMessagingService.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainConfigUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigUpdater.java new file mode 100644 index 0000000000..86afbcabf4 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainConfigUpdater.java @@ -0,0 +1,179 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class DomainConfigUpdater extends Updater { + + private String pathDomainSid; + private URI fallbackUrl; + private URI callbackUrl; + private Boolean continueOnFailure; + private Boolean disableHttps; + + public DomainConfigUpdater(final String pathDomainSid) { + this.pathDomainSid = pathDomainSid; + } + + public DomainConfigUpdater setFallbackUrl(final URI fallbackUrl) { + this.fallbackUrl = fallbackUrl; + return this; + } + + public DomainConfigUpdater setFallbackUrl(final String fallbackUrl) { + return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); + } + + public DomainConfigUpdater setCallbackUrl(final URI callbackUrl) { + this.callbackUrl = callbackUrl; + return this; + } + + public DomainConfigUpdater setCallbackUrl(final String callbackUrl) { + return setCallbackUrl(Promoter.uriFromString(callbackUrl)); + } + + public DomainConfigUpdater setContinueOnFailure( + final Boolean continueOnFailure + ) { + this.continueOnFailure = continueOnFailure; + return this; + } + + public DomainConfigUpdater setDisableHttps(final Boolean disableHttps) { + this.disableHttps = disableHttps; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/LinkShortening/Domains/{DomainSid}/Config"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DomainConfig update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DomainConfig update(final TwilioRestClient client) { + Response response = makeRequest(client); + return DomainConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DomainConfig content = DomainConfig.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (fallbackUrl != null) { + Serializer.toString( + request, + "FallbackUrl", + fallbackUrl, + ParameterType.URLENCODED + ); + } + + if (callbackUrl != null) { + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); + } + + if (continueOnFailure != null) { + Serializer.toString( + request, + "ContinueOnFailure", + continueOnFailure, + ParameterType.URLENCODED + ); + } + + if (disableHttps != null) { + Serializer.toString( + request, + "DisableHttps", + disableHttps, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainValidateDn.java b/src/main/java/com/twilio/rest/messaging/v1/DomainValidateDn.java new file mode 100644 index 0000000000..62349341f0 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainValidateDn.java @@ -0,0 +1,149 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DomainValidateDn extends Resource { + + public static DomainValidateDnFetcher fetcher(final String pathDomainSid) { + return new DomainValidateDnFetcher(pathDomainSid); + } + + /** + * Converts a JSON String into a DomainValidateDn object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DomainValidateDn object represented by the provided JSON + */ + public static DomainValidateDn fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DomainValidateDn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DomainValidateDn object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DomainValidateDn object represented by the provided JSON + */ + public static DomainValidateDn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DomainValidateDn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String domainSid; + + @Getter + private final Boolean isValid; + + @Getter + private final String reason; + + @Getter + private final URI url; + + @JsonCreator + private DomainValidateDn( + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("is_valid") final Boolean isValid, + @JsonProperty("reason") final String reason, + @JsonProperty("url") final URI url + ) { + this.domainSid = domainSid; + this.isValid = isValid; + this.reason = reason; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DomainValidateDn other = (DomainValidateDn) o; + return ( + Objects.equals(domainSid, other.domainSid) && + Objects.equals(isValid, other.isValid) && + Objects.equals(reason, other.reason) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(domainSid, isValid, reason, url); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/DomainValidateDnFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/DomainValidateDnFetcher.java new file mode 100644 index 0000000000..0b0b4982a9 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/DomainValidateDnFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DomainValidateDnFetcher extends Fetcher { + + private String pathDomainSid; + + public DomainValidateDnFetcher(final String pathDomainSid) { + this.pathDomainSid = pathDomainSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/LinkShortening/Domains/{DomainSid}/ValidateDns"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DomainValidateDn fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DomainValidateDn fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DomainValidateDn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DomainValidateDn content = DomainValidateDn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaign.java b/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaign.java new file mode 100644 index 0000000000..c12ddf49dd --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaign.java @@ -0,0 +1,171 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExternalCampaign extends Resource { + + public static ExternalCampaignCreator creator( + final String campaignId, + final String messagingServiceSid + ) { + return new ExternalCampaignCreator(campaignId, messagingServiceSid); + } + + /** + * Converts a JSON String into a ExternalCampaign object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExternalCampaign object represented by the provided JSON + */ + public static ExternalCampaign fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExternalCampaign.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExternalCampaign object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExternalCampaign object represented by the provided JSON + */ + public static ExternalCampaign fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExternalCampaign.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String campaignId; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String messagingServiceSid; + + @Getter + private final String sid; + + @JsonCreator + private ExternalCampaign( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("campaign_id") final String campaignId, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid + ) { + this.accountSid = accountSid; + this.campaignId = campaignId; + this.dateCreated = dateCreated; + this.messagingServiceSid = messagingServiceSid; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExternalCampaign other = (ExternalCampaign) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(campaignId, other.campaignId) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + campaignId, + dateCreated, + messagingServiceSid, + sid + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaignCreator.java b/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaignCreator.java new file mode 100644 index 0000000000..8e25fe659f --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/ExternalCampaignCreator.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExternalCampaignCreator extends Creator { + + private String campaignId; + private String messagingServiceSid; + private Boolean cnpMigration; + + public ExternalCampaignCreator( + final String campaignId, + final String messagingServiceSid + ) { + this.campaignId = campaignId; + this.messagingServiceSid = messagingServiceSid; + } + + public ExternalCampaignCreator setCampaignId(final String campaignId) { + this.campaignId = campaignId; + return this; + } + + public ExternalCampaignCreator setMessagingServiceSid( + final String messagingServiceSid + ) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + public ExternalCampaignCreator setCnpMigration(final Boolean cnpMigration) { + this.cnpMigration = cnpMigration; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/PreregisteredUsa2p"; + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExternalCampaign creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExternalCampaign create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExternalCampaign.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExternalCampaign content = ExternalCampaign.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (campaignId != null) { + Serializer.toString( + request, + "CampaignId", + campaignId, + ParameterType.URLENCODED + ); + } + + if (messagingServiceSid != null) { + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); + } + + if (cnpMigration != null) { + Serializer.toString( + request, + "CnpMigration", + cnpMigration, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingService.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingService.java new file mode 100644 index 0000000000..ca4364ea9c --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingService.java @@ -0,0 +1,166 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class LinkshorteningMessagingService extends Resource { + + public static LinkshorteningMessagingServiceCreator creator( + final String pathDomainSid, + final String pathMessagingServiceSid + ) { + return new LinkshorteningMessagingServiceCreator( + pathDomainSid, + pathMessagingServiceSid + ); + } + + public static LinkshorteningMessagingServiceDeleter deleter( + final String pathDomainSid, + final String pathMessagingServiceSid + ) { + return new LinkshorteningMessagingServiceDeleter( + pathDomainSid, + pathMessagingServiceSid + ); + } + + /** + * Converts a JSON String into a LinkshorteningMessagingService object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return LinkshorteningMessagingService object represented by the provided JSON + */ + public static LinkshorteningMessagingService fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + LinkshorteningMessagingService.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a LinkshorteningMessagingService object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return LinkshorteningMessagingService object represented by the provided JSON + */ + public static LinkshorteningMessagingService fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + LinkshorteningMessagingService.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String domainSid; + + @Getter + private final String messagingServiceSid; + + @Getter + private final URI url; + + @JsonCreator + private LinkshorteningMessagingService( + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("url") final URI url + ) { + this.domainSid = domainSid; + this.messagingServiceSid = messagingServiceSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LinkshorteningMessagingService other = + (LinkshorteningMessagingService) o; + return ( + Objects.equals(domainSid, other.domainSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(domainSid, messagingServiceSid, url); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceCreator.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceCreator.java new file mode 100644 index 0000000000..f4b8c34d54 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceCreator.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class LinkshorteningMessagingServiceCreator + extends Creator { + + private String pathDomainSid; + private String pathMessagingServiceSid; + + public LinkshorteningMessagingServiceCreator( + final String pathDomainSid, + final String pathMessagingServiceSid + ) { + this.pathDomainSid = pathDomainSid; + this.pathMessagingServiceSid = pathMessagingServiceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/LinkShortening/Domains/{DomainSid}/MessagingServices/{MessagingServiceSid}"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "LinkshorteningMessagingService creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public LinkshorteningMessagingService create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return LinkshorteningMessagingService.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + LinkshorteningMessagingService content = + LinkshorteningMessagingService.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDeleter.java new file mode 100644 index 0000000000..802c827287 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDeleter.java @@ -0,0 +1,113 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class LinkshorteningMessagingServiceDeleter + extends Deleter { + + private String pathDomainSid; + private String pathMessagingServiceSid; + + public LinkshorteningMessagingServiceDeleter( + final String pathDomainSid, + final String pathMessagingServiceSid + ) { + this.pathDomainSid = pathDomainSid; + this.pathMessagingServiceSid = pathMessagingServiceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/LinkShortening/Domains/{DomainSid}/MessagingServices/{MessagingServiceSid}"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "LinkshorteningMessagingService delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociation.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociation.java new file mode 100644 index 0000000000..6869fef06c --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociation.java @@ -0,0 +1,154 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class LinkshorteningMessagingServiceDomainAssociation extends Resource { + + public static LinkshorteningMessagingServiceDomainAssociationFetcher fetcher( + final String pathMessagingServiceSid + ) { + return new LinkshorteningMessagingServiceDomainAssociationFetcher( + pathMessagingServiceSid + ); + } + + /** + * Converts a JSON String into a LinkshorteningMessagingServiceDomainAssociation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return LinkshorteningMessagingServiceDomainAssociation object represented by the provided JSON + */ + public static LinkshorteningMessagingServiceDomainAssociation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + LinkshorteningMessagingServiceDomainAssociation.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a LinkshorteningMessagingServiceDomainAssociation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return LinkshorteningMessagingServiceDomainAssociation object represented by the provided JSON + */ + public static LinkshorteningMessagingServiceDomainAssociation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + LinkshorteningMessagingServiceDomainAssociation.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String domainSid; + + @Getter + private final String messagingServiceSid; + + @Getter + private final URI url; + + @JsonCreator + private LinkshorteningMessagingServiceDomainAssociation( + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("url") final URI url + ) { + this.domainSid = domainSid; + this.messagingServiceSid = messagingServiceSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + LinkshorteningMessagingServiceDomainAssociation other = + (LinkshorteningMessagingServiceDomainAssociation) o; + return ( + Objects.equals(domainSid, other.domainSid) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(domainSid, messagingServiceSid, url); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociationFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociationFetcher.java new file mode 100644 index 0000000000..c10232e1be --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/LinkshorteningMessagingServiceDomainAssociationFetcher.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class LinkshorteningMessagingServiceDomainAssociationFetcher + extends Fetcher { + + private String pathMessagingServiceSid; + + public LinkshorteningMessagingServiceDomainAssociationFetcher( + final String pathMessagingServiceSid + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/LinkShortening/MessagingServices/{MessagingServiceSid}/Domain"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "LinkshorteningMessagingServiceDomainAssociation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public LinkshorteningMessagingServiceDomainAssociation fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return LinkshorteningMessagingServiceDomainAssociation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + LinkshorteningMessagingServiceDomainAssociation + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + LinkshorteningMessagingServiceDomainAssociation content = + LinkshorteningMessagingServiceDomainAssociation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/RequestManagedCert.java b/src/main/java/com/twilio/rest/messaging/v1/RequestManagedCert.java new file mode 100644 index 0000000000..b768fbd500 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/RequestManagedCert.java @@ -0,0 +1,209 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class RequestManagedCert extends Resource { + + public static RequestManagedCertUpdater updater( + final String pathDomainSid + ) { + return new RequestManagedCertUpdater(pathDomainSid); + } + + /** + * Converts a JSON String into a RequestManagedCert object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return RequestManagedCert object represented by the provided JSON + */ + public static RequestManagedCert fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RequestManagedCert.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a RequestManagedCert object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return RequestManagedCert object represented by the provided JSON + */ + public static RequestManagedCert fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RequestManagedCert.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String certificateSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final URI domainName; + + @Getter + private final String domainSid; + + @Getter + private final Boolean managed; + + @Getter + private final Boolean requesting; + + @Getter + private final URI url; + + @JsonCreator + private RequestManagedCert( + @JsonProperty("certificate_sid") final String certificateSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_name") final URI domainName, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("managed") final Boolean managed, + @JsonProperty("requesting") final Boolean requesting, + @JsonProperty("url") final URI url + ) { + this.certificateSid = certificateSid; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.domainName = domainName; + this.domainSid = domainSid; + this.managed = managed; + this.requesting = requesting; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RequestManagedCert other = (RequestManagedCert) o; + return ( + Objects.equals(certificateSid, other.certificateSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainName, other.domainName) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(managed, other.managed) && + Objects.equals(requesting, other.requesting) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + certificateSid, + dateCreated, + dateExpires, + dateUpdated, + domainName, + domainSid, + managed, + requesting, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/RequestManagedCertUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/RequestManagedCertUpdater.java new file mode 100644 index 0000000000..08d34abd0b --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/RequestManagedCertUpdater.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RequestManagedCertUpdater extends Updater { + + private String pathDomainSid; + + public RequestManagedCertUpdater(final String pathDomainSid) { + this.pathDomainSid = pathDomainSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/LinkShortening/Domains/{DomainSid}/RequestManagedCert"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "RequestManagedCert update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public RequestManagedCert update(final TwilioRestClient client) { + Response response = makeRequest(client); + return RequestManagedCert.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + RequestManagedCert content = RequestManagedCert.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/Service.java b/src/main/java/com/twilio/rest/messaging/v1/Service.java index 5b1b63e91c..c115e5866a 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/Service.java +++ b/src/main/java/com/twilio/rest/messaging/v1/Service.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1; @@ -10,36 +17,54 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Service extends Resource { - private static final long serialVersionUID = 155674022160031L; + + public static ServiceCreator creator(final String friendlyName) { + return new ServiceCreator(friendlyName); + } + + public static ServiceDeleter deleter(final String pathSid) { + return new ServiceDeleter(pathSid); + } + + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); + } + + public static ServiceReader reader() { + return new ServiceReader(); + } + + public static ServiceUpdater updater(final String pathSid) { + return new ServiceUpdater(pathSid); + } public enum ScanMessageContent { INHERIT("inherit"), @@ -52,79 +77,28 @@ private ScanMessageContent(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ScanMessageContent from a string. - * @param value string value - * @return generated ScanMessageContent - */ @JsonCreator public static ScanMessageContent forValue(final String value) { return Promoter.enumFromString(value, ScanMessageContent.values()); } } - /** - * Create a ServiceCreator to execute create. - * - * @param friendlyName A human readable descriptive text for this resource, up - * to 64 characters. - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator(final String friendlyName) { - return new ServiceCreator(friendlyName); - } - - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid The sid - * @return ServiceUpdater capable of executing the update - */ - public static ServiceUpdater updater(final String pathSid) { - return new ServiceUpdater(pathSid); - } - - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ - public static ServiceReader reader() { - return new ServiceReader(); - } - - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid The sid - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); - } - - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid The sid - * @return ServiceDeleter capable of executing the delete - */ - public static ServiceDeleter deleter(final String pathSid) { - return new ServiceDeleter(pathSid); - } - /** * Converts a JSON String into a Service object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -138,12 +112,15 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Service object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -154,292 +131,154 @@ public static Service fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI inboundRequestUrl; - private final HttpMethod inboundMethod; - private final URI fallbackUrl; - private final HttpMethod fallbackMethod; - private final URI statusCallback; - private final Boolean stickySender; - private final Boolean mmsConverter; - private final Boolean smartEncoding; - private final Service.ScanMessageContent scanMessageContent; - private final Boolean fallbackToLongCode; + + @Getter private final Boolean areaCodeGeomatch; - private final Boolean synchronousValidation; - private final Integer validityPeriod; - private final URI url; - private final Map links; - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("inbound_request_url") - final URI inboundRequestUrl, - @JsonProperty("inbound_method") - final HttpMethod inboundMethod, - @JsonProperty("fallback_url") - final URI fallbackUrl, - @JsonProperty("fallback_method") - final HttpMethod fallbackMethod, - @JsonProperty("status_callback") - final URI statusCallback, - @JsonProperty("sticky_sender") - final Boolean stickySender, - @JsonProperty("mms_converter") - final Boolean mmsConverter, - @JsonProperty("smart_encoding") - final Boolean smartEncoding, - @JsonProperty("scan_message_content") - final Service.ScanMessageContent scanMessageContent, - @JsonProperty("fallback_to_long_code") - final Boolean fallbackToLongCode, - @JsonProperty("area_code_geomatch") - final Boolean areaCodeGeomatch, - @JsonProperty("synchronous_validation") - final Boolean synchronousValidation, - @JsonProperty("validity_period") - final Integer validityPeriod, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.inboundRequestUrl = inboundRequestUrl; - this.inboundMethod = inboundMethod; - this.fallbackUrl = fallbackUrl; - this.fallbackMethod = fallbackMethod; - this.statusCallback = statusCallback; - this.stickySender = stickySender; - this.mmsConverter = mmsConverter; - this.smartEncoding = smartEncoding; - this.scanMessageContent = scanMessageContent; - this.fallbackToLongCode = fallbackToLongCode; - this.areaCodeGeomatch = areaCodeGeomatch; - this.synchronousValidation = synchronousValidation; - this.validityPeriod = validityPeriod; - this.url = url; - this.links = links; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The Unique 34 character ID of the Service.. - * - * @return Unique 34 character ID of the Service. - */ - public final String getSid() { - return this.sid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The Unique 34 character ID of the Account that created this Service.. - * - * @return Unique 34 character ID of the Account that created this Service. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final HttpMethod fallbackMethod; - /** - * Returns The A human readable descriptive text for this resource, up to 64 - * characters.. - * - * @return A human readable descriptive text for this resource, up to 64 - * characters. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final Boolean fallbackToLongCode; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final URI fallbackUrl; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String friendlyName; - /** - * Returns The The URL Twilio will make a webhook request to when a message is - * received by any phone number or short code in your Service.. - * - * @return The URL Twilio will make a webhook request to when a message is - * received by any phone number or short code in your Service. - */ - public final URI getInboundRequestUrl() { - return this.inboundRequestUrl; - } + @Getter + private final HttpMethod inboundMethod; - /** - * Returns The The HTTP method Twilio will use when making requests to the - * Inbound Request URL.. - * - * @return The HTTP method Twilio will use when making requests to the Inbound - * Request URL. - */ - public final HttpMethod getInboundMethod() { - return this.inboundMethod; - } + @Getter + private final URI inboundRequestUrl; - /** - * Returns The The URL that Twilio will request if an error occurs when - * retrieving or executing the TwiML from your Inbound Request URL.. - * - * @return The URL that Twilio will request if an error occurs when retrieving - * or executing the TwiML from your Inbound Request URL. - */ - public final URI getFallbackUrl() { - return this.fallbackUrl; - } + @Getter + private final Map links; - /** - * Returns The The HTTP method Twilio will use when making requests to the - * Fallback URL.. - * - * @return The HTTP method Twilio will use when making requests to the Fallback - * URL. - */ - public final HttpMethod getFallbackMethod() { - return this.fallbackMethod; - } + @Getter + private final Boolean mmsConverter; - /** - * Returns The The URL Twilio will make a webhook request to when passing you - * status updates about the delivery of your messages.. - * - * @return The URL Twilio will make a webhook request to when passing you - * status updates about the delivery of your messages. - */ - public final URI getStatusCallback() { - return this.statusCallback; - } + @Getter + private final Service.ScanMessageContent scanMessageContent; - /** - * Returns The Configuration to enable or disable Sticky Sender on your Service - * instance.. - * - * @return Configuration to enable or disable Sticky Sender on your Service - * instance. - */ - public final Boolean getStickySender() { - return this.stickySender; - } + @Getter + private final String sid; - /** - * Returns The Configuration to enable or disable MMS Converter for messages - * sent through your Service instance.. - * - * @return Configuration to enable or disable MMS Converter for messages sent - * through your Service instance. - */ - public final Boolean getMmsConverter() { - return this.mmsConverter; - } + @Getter + private final Boolean smartEncoding; - /** - * Returns The Configuration to enable or disable Smart Encoding for messages - * sent through your Service instance.. - * - * @return Configuration to enable or disable Smart Encoding for messages sent - * through your Service instance. - */ - public final Boolean getSmartEncoding() { - return this.smartEncoding; - } + @Getter + private final URI statusCallback; - /** - * Returns The The scan_message_content. - * - * @return The scan_message_content - */ - public final Service.ScanMessageContent getScanMessageContent() { - return this.scanMessageContent; - } + @Getter + private final Boolean stickySender; - /** - * Returns The Configuration to enable or disable Fallback to Long Code for - * messages sent through your Service instance.. - * - * @return Configuration to enable or disable Fallback to Long Code for - * messages sent through your Service instance. - */ - public final Boolean getFallbackToLongCode() { - return this.fallbackToLongCode; - } + @Getter + private final Boolean synchronousValidation; - /** - * Returns The Configuration to enable or disable Area Code Geomatch on your - * Service Instance.. - * - * @return Configuration to enable or disable Area Code Geomatch on your - * Service Instance. - */ - public final Boolean getAreaCodeGeomatch() { - return this.areaCodeGeomatch; - } + @Getter + private final URI url; - /** - * Returns The The synchronous_validation. - * - * @return The synchronous_validation - */ - public final Boolean getSynchronousValidation() { - return this.synchronousValidation; - } + @Getter + private final Boolean usAppToPersonRegistered; - /** - * Returns The The number of seconds all messages sent from your Service are - * valid for.. - * - * @return The number of seconds all messages sent from your Service are valid - * for. - */ - public final Integer getValidityPeriod() { - return this.validityPeriod; - } + @Getter + private final Boolean useInboundWebhookOnNumber; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String usecase; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @Getter + private final Integer validityPeriod; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("area_code_geomatch") final Boolean areaCodeGeomatch, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("fallback_method") final HttpMethod fallbackMethod, + @JsonProperty("fallback_to_long_code") final Boolean fallbackToLongCode, + @JsonProperty("fallback_url") final URI fallbackUrl, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("inbound_method") final HttpMethod inboundMethod, + @JsonProperty("inbound_request_url") final URI inboundRequestUrl, + @JsonProperty("links") final Map links, + @JsonProperty("mms_converter") final Boolean mmsConverter, + @JsonProperty( + "scan_message_content" + ) final Service.ScanMessageContent scanMessageContent, + @JsonProperty("sid") final String sid, + @JsonProperty("smart_encoding") final Boolean smartEncoding, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("sticky_sender") final Boolean stickySender, + @JsonProperty( + "synchronous_validation" + ) final Boolean synchronousValidation, + @JsonProperty("url") final URI url, + @JsonProperty( + "us_app_to_person_registered" + ) final Boolean usAppToPersonRegistered, + @JsonProperty( + "use_inbound_webhook_on_number" + ) final Boolean useInboundWebhookOnNumber, + @JsonProperty("usecase") final String usecase, + @JsonProperty("validity_period") final Integer validityPeriod + ) { + this.accountSid = accountSid; + this.areaCodeGeomatch = areaCodeGeomatch; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.fallbackMethod = fallbackMethod; + this.fallbackToLongCode = fallbackToLongCode; + this.fallbackUrl = fallbackUrl; + this.friendlyName = friendlyName; + this.inboundMethod = inboundMethod; + this.inboundRequestUrl = inboundRequestUrl; + this.links = links; + this.mmsConverter = mmsConverter; + this.scanMessageContent = scanMessageContent; + this.sid = sid; + this.smartEncoding = smartEncoding; + this.statusCallback = statusCallback; + this.stickySender = stickySender; + this.synchronousValidation = synchronousValidation; + this.url = url; + this.usAppToPersonRegistered = usAppToPersonRegistered; + this.useInboundWebhookOnNumber = useInboundWebhookOnNumber; + this.usecase = usecase; + this.validityPeriod = validityPeriod; } @Override @@ -453,76 +292,68 @@ public boolean equals(final Object o) { } Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(inboundRequestUrl, other.inboundRequestUrl) && - Objects.equals(inboundMethod, other.inboundMethod) && - Objects.equals(fallbackUrl, other.fallbackUrl) && - Objects.equals(fallbackMethod, other.fallbackMethod) && - Objects.equals(statusCallback, other.statusCallback) && - Objects.equals(stickySender, other.stickySender) && - Objects.equals(mmsConverter, other.mmsConverter) && - Objects.equals(smartEncoding, other.smartEncoding) && - Objects.equals(scanMessageContent, other.scanMessageContent) && - Objects.equals(fallbackToLongCode, other.fallbackToLongCode) && - Objects.equals(areaCodeGeomatch, other.areaCodeGeomatch) && - Objects.equals(synchronousValidation, other.synchronousValidation) && - Objects.equals(validityPeriod, other.validityPeriod) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(areaCodeGeomatch, other.areaCodeGeomatch) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(fallbackMethod, other.fallbackMethod) && + Objects.equals(fallbackToLongCode, other.fallbackToLongCode) && + Objects.equals(fallbackUrl, other.fallbackUrl) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(inboundMethod, other.inboundMethod) && + Objects.equals(inboundRequestUrl, other.inboundRequestUrl) && + Objects.equals(links, other.links) && + Objects.equals(mmsConverter, other.mmsConverter) && + Objects.equals(scanMessageContent, other.scanMessageContent) && + Objects.equals(sid, other.sid) && + Objects.equals(smartEncoding, other.smartEncoding) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(stickySender, other.stickySender) && + Objects.equals( + synchronousValidation, + other.synchronousValidation + ) && + Objects.equals(url, other.url) && + Objects.equals( + usAppToPersonRegistered, + other.usAppToPersonRegistered + ) && + Objects.equals( + useInboundWebhookOnNumber, + other.useInboundWebhookOnNumber + ) && + Objects.equals(usecase, other.usecase) && + Objects.equals(validityPeriod, other.validityPeriod) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - inboundRequestUrl, - inboundMethod, - fallbackUrl, - fallbackMethod, - statusCallback, - stickySender, - mmsConverter, - smartEncoding, - scanMessageContent, - fallbackToLongCode, - areaCodeGeomatch, - synchronousValidation, - validityPeriod, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("inboundRequestUrl", inboundRequestUrl) - .add("inboundMethod", inboundMethod) - .add("fallbackUrl", fallbackUrl) - .add("fallbackMethod", fallbackMethod) - .add("statusCallback", statusCallback) - .add("stickySender", stickySender) - .add("mmsConverter", mmsConverter) - .add("smartEncoding", smartEncoding) - .add("scanMessageContent", scanMessageContent) - .add("fallbackToLongCode", fallbackToLongCode) - .add("areaCodeGeomatch", areaCodeGeomatch) - .add("synchronousValidation", synchronousValidation) - .add("validityPeriod", validityPeriod) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + areaCodeGeomatch, + dateCreated, + dateUpdated, + fallbackMethod, + fallbackToLongCode, + fallbackUrl, + friendlyName, + inboundMethod, + inboundRequestUrl, + links, + mmsConverter, + scanMessageContent, + sid, + smartEncoding, + statusCallback, + stickySender, + synchronousValidation, + url, + usAppToPersonRegistered, + useInboundWebhookOnNumber, + usecase, + validityPeriod + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceCreator.java index 1033cf291c..dd4e67f85f 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,15 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceCreator extends Creator { - private final String friendlyName; + + private String friendlyName; private URI inboundRequestUrl; private HttpMethod inboundMethod; private URI fallbackUrl; @@ -39,331 +48,312 @@ public class ServiceCreator extends Creator { private Boolean areaCodeGeomatch; private Integer validityPeriod; private Boolean synchronousValidation; + private String usecase; + private Boolean useInboundWebhookOnNumber; - /** - * Construct a new ServiceCreator. - * - * @param friendlyName A human readable descriptive text for this resource, up - * to 64 characters. - */ public ServiceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * A [webhook request](https://www.twilio.com/docs/api/twiml/sms/twilio_request) - * is made to the Inbound Request URL when a message is received by any phone - * number or shortcode associated to your Messaging Service. Set to `null` to - * disable inbound messaging.. - * - * @param inboundRequestUrl A webhook request is made to the Inbound Request - * URL when a message is received by any phone number - * or shortcode associated to your Messaging Service. - * @return this - */ + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + public ServiceCreator setInboundRequestUrl(final URI inboundRequestUrl) { this.inboundRequestUrl = inboundRequestUrl; return this; } - /** - * A [webhook request](https://www.twilio.com/docs/api/twiml/sms/twilio_request) - * is made to the Inbound Request URL when a message is received by any phone - * number or shortcode associated to your Messaging Service. Set to `null` to - * disable inbound messaging.. - * - * @param inboundRequestUrl A webhook request is made to the Inbound Request - * URL when a message is received by any phone number - * or shortcode associated to your Messaging Service. - * @return this - */ public ServiceCreator setInboundRequestUrl(final String inboundRequestUrl) { return setInboundRequestUrl(Promoter.uriFromString(inboundRequestUrl)); } - /** - * The HTTP method used when making requests to the Inbound Request URL. Either - * `GET` or `POST`. Default value is `POST`.. - * - * @param inboundMethod The HTTP method used when making requests to the - * Inbound Request URL. - * @return this - */ public ServiceCreator setInboundMethod(final HttpMethod inboundMethod) { this.inboundMethod = inboundMethod; return this; } - /** - * A request is made to the Fallback URL if an error occurs with retrieving or - * executing the TwiML from you Inbound Request URL.. - * - * @param fallbackUrl A request is made to the Fallback URL if an error occurs - * with retrieving or executing the TwiML from you Inbound - * Request URL. - * @return this - */ public ServiceCreator setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - /** - * A request is made to the Fallback URL if an error occurs with retrieving or - * executing the TwiML from you Inbound Request URL.. - * - * @param fallbackUrl A request is made to the Fallback URL if an error occurs - * with retrieving or executing the TwiML from you Inbound - * Request URL. - * @return this - */ public ServiceCreator setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - /** - * The HTTP method used when requesting the Fallback URL. Either `GET` or - * `POST`. Default value is `POST`.. - * - * @param fallbackMethod The HTTP method used when requesting the Fallback URL. - * @return this - */ public ServiceCreator setFallbackMethod(final HttpMethod fallbackMethod) { this.fallbackMethod = fallbackMethod; return this; } - /** - * A webhook request is made to the Status Callback to pass [status - * updates](https://www.twilio.com/docs/api/rest/message#sms-status-values) - * about your messages. These status updates let you know if your accepted - * message were successfully sent and delivered or if a [delivery related - * error](https://www.twilio.com/docs/api/rest/message#error-values) may have - * occurred.. - * - * @param statusCallback A webhook request is made to the Status Callback to - * pass status updates about your messages. - * @return this - */ public ServiceCreator setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * A webhook request is made to the Status Callback to pass [status - * updates](https://www.twilio.com/docs/api/rest/message#sms-status-values) - * about your messages. These status updates let you know if your accepted - * message were successfully sent and delivered or if a [delivery related - * error](https://www.twilio.com/docs/api/rest/message#error-values) may have - * occurred.. - * - * @param statusCallback A webhook request is made to the Status Callback to - * pass status updates about your messages. - * @return this - */ public ServiceCreator setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * Configuration to enable or disable Sticky Sender on your Service Instance. - * Possible values are `true` and `false`. Default value is `true`.. - * - * @param stickySender Configuration to enable or disable Sticky Sender on your - * Service Instance. - * @return this - */ public ServiceCreator setStickySender(final Boolean stickySender) { this.stickySender = stickySender; return this; } - /** - * Configuration to enable or disable MMS Converter on your Service Instance. - * Possible values are `true` and `false`. Default value is `true`.. - * - * @param mmsConverter Configuration to enable or disable MMS Converter on your - * Service Instance. - * @return this - */ public ServiceCreator setMmsConverter(final Boolean mmsConverter) { this.mmsConverter = mmsConverter; return this; } - /** - * Configuration to enable or disable [Smart - * Encoding](https://www.twilio.com/docs/api/messaging/services-and-copilot#smart-encoding). Possible values are `true` and `false`. Default value is `true`.. - * - * @param smartEncoding Configuration to enable or disable Smart Encoding. - * @return this - */ public ServiceCreator setSmartEncoding(final Boolean smartEncoding) { this.smartEncoding = smartEncoding; return this; } - /** - * The scan_message_content. - * - * @param scanMessageContent The scan_message_content - * @return this - */ - public ServiceCreator setScanMessageContent(final Service.ScanMessageContent scanMessageContent) { + public ServiceCreator setScanMessageContent( + final Service.ScanMessageContent scanMessageContent + ) { this.scanMessageContent = scanMessageContent; return this; } - /** - * Configuration to enable or disable [Fallback to Long - * Code](https://www.twilio.com/docs/api/messaging/services-and-copilot#fallback-to-long-code). Possible values are `true` and `false`. Default value is `false`.. - * - * @param fallbackToLongCode Configuration to enable or disable Fallback to - * Long Code. - * @return this - */ - public ServiceCreator setFallbackToLongCode(final Boolean fallbackToLongCode) { + public ServiceCreator setFallbackToLongCode( + final Boolean fallbackToLongCode + ) { this.fallbackToLongCode = fallbackToLongCode; return this; } - /** - * Configuration to enable or disable [Area Code - * Geomatch](https://www.twilio.com/docs/api/messaging/services-and-copilot#area-code-geomatch). Possible values are `true` and `false`. Default value is `false`.. - * - * @param areaCodeGeomatch Configuration to enable or disable Area Code - * Geomatch. - * @return this - */ public ServiceCreator setAreaCodeGeomatch(final Boolean areaCodeGeomatch) { this.areaCodeGeomatch = areaCodeGeomatch; return this; } - /** - * Configuration to set the [validity - * period](https://www.twilio.com/docs/api/messaging/services-and-copilot#validity-period) of all messages sent from your Service, in seconds. Acceptable integers range from `1` to `14,400`. Default value is `14,400`.. - * - * @param validityPeriod Configuration to set the validity period of all - * messages sent from your Service, in seconds. - * @return this - */ public ServiceCreator setValidityPeriod(final Integer validityPeriod) { this.validityPeriod = validityPeriod; return this; } - /** - * The synchronous_validation. - * - * @param synchronousValidation The synchronous_validation - * @return this - */ - public ServiceCreator setSynchronousValidation(final Boolean synchronousValidation) { + public ServiceCreator setSynchronousValidation( + final Boolean synchronousValidation + ) { this.synchronousValidation = synchronousValidation; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { + public ServiceCreator setUsecase(final String usecase) { + this.usecase = usecase; + return this; + } + + public ServiceCreator setUseInboundWebhookOnNumber( + final Boolean useInboundWebhookOnNumber + ) { + this.useInboundWebhookOnNumber = useInboundWebhookOnNumber; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), - "/v1/Services", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (inboundRequestUrl != null) { - request.addPostParam("InboundRequestUrl", inboundRequestUrl.toString()); + Serializer.toString( + request, + "InboundRequestUrl", + inboundRequestUrl, + ParameterType.URLENCODED + ); } if (inboundMethod != null) { - request.addPostParam("InboundMethod", inboundMethod.toString()); + Serializer.toString( + request, + "InboundMethod", + inboundMethod, + ParameterType.URLENCODED + ); } if (fallbackUrl != null) { - request.addPostParam("FallbackUrl", fallbackUrl.toString()); + Serializer.toString( + request, + "FallbackUrl", + fallbackUrl, + ParameterType.URLENCODED + ); } if (fallbackMethod != null) { - request.addPostParam("FallbackMethod", fallbackMethod.toString()); + Serializer.toString( + request, + "FallbackMethod", + fallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (stickySender != null) { - request.addPostParam("StickySender", stickySender.toString()); + Serializer.toString( + request, + "StickySender", + stickySender, + ParameterType.URLENCODED + ); } if (mmsConverter != null) { - request.addPostParam("MmsConverter", mmsConverter.toString()); + Serializer.toString( + request, + "MmsConverter", + mmsConverter, + ParameterType.URLENCODED + ); } if (smartEncoding != null) { - request.addPostParam("SmartEncoding", smartEncoding.toString()); + Serializer.toString( + request, + "SmartEncoding", + smartEncoding, + ParameterType.URLENCODED + ); } if (scanMessageContent != null) { - request.addPostParam("ScanMessageContent", scanMessageContent.toString()); + Serializer.toString( + request, + "ScanMessageContent", + scanMessageContent, + ParameterType.URLENCODED + ); } if (fallbackToLongCode != null) { - request.addPostParam("FallbackToLongCode", fallbackToLongCode.toString()); + Serializer.toString( + request, + "FallbackToLongCode", + fallbackToLongCode, + ParameterType.URLENCODED + ); } if (areaCodeGeomatch != null) { - request.addPostParam("AreaCodeGeomatch", areaCodeGeomatch.toString()); + Serializer.toString( + request, + "AreaCodeGeomatch", + areaCodeGeomatch, + ParameterType.URLENCODED + ); } if (validityPeriod != null) { - request.addPostParam("ValidityPeriod", validityPeriod.toString()); + Serializer.toString( + request, + "ValidityPeriod", + validityPeriod, + ParameterType.URLENCODED + ); } if (synchronousValidation != null) { - request.addPostParam("SynchronousValidation", synchronousValidation.toString()); + Serializer.toString( + request, + "SynchronousValidation", + synchronousValidation, + ParameterType.URLENCODED + ); + } + + if (usecase != null) { + Serializer.toString( + request, + "Usecase", + usecase, + ParameterType.URLENCODED + ); + } + + if (useInboundWebhookOnNumber != null) { + Serializer.toString( + request, + "UseInboundWebhookOnNumber", + useInboundWebhookOnNumber, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceDeleter.java index add6b910af..d2859e3b55 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new ServiceDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceFetcher.java index 7a4e6fe1ed..5495370c6b 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new ServiceFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceReader.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceReader.java index 4e193e1aad..8e80b4b253 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1; @@ -10,152 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), - "/v1/Services", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.MESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.MESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/ServiceUpdater.java index e3663e5bcb..0ed5dda863 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/messaging/v1/ServiceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,15 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private URI inboundRequestUrl; private HttpMethod inboundMethod; @@ -40,299 +49,314 @@ public class ServiceUpdater extends Updater { private Boolean areaCodeGeomatch; private Integer validityPeriod; private Boolean synchronousValidation; + private String usecase; + private Boolean useInboundWebhookOnNumber; - /** - * Construct a new ServiceUpdater. - * - * @param pathSid The sid - */ public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The inbound_request_url. - * - * @param inboundRequestUrl The inbound_request_url - * @return this - */ public ServiceUpdater setInboundRequestUrl(final URI inboundRequestUrl) { this.inboundRequestUrl = inboundRequestUrl; return this; } - /** - * The inbound_request_url. - * - * @param inboundRequestUrl The inbound_request_url - * @return this - */ public ServiceUpdater setInboundRequestUrl(final String inboundRequestUrl) { return setInboundRequestUrl(Promoter.uriFromString(inboundRequestUrl)); } - /** - * The inbound_method. - * - * @param inboundMethod The inbound_method - * @return this - */ public ServiceUpdater setInboundMethod(final HttpMethod inboundMethod) { this.inboundMethod = inboundMethod; return this; } - /** - * The fallback_url. - * - * @param fallbackUrl The fallback_url - * @return this - */ public ServiceUpdater setFallbackUrl(final URI fallbackUrl) { this.fallbackUrl = fallbackUrl; return this; } - /** - * The fallback_url. - * - * @param fallbackUrl The fallback_url - * @return this - */ public ServiceUpdater setFallbackUrl(final String fallbackUrl) { return setFallbackUrl(Promoter.uriFromString(fallbackUrl)); } - /** - * The fallback_method. - * - * @param fallbackMethod The fallback_method - * @return this - */ public ServiceUpdater setFallbackMethod(final HttpMethod fallbackMethod) { this.fallbackMethod = fallbackMethod; return this; } - /** - * The status_callback. - * - * @param statusCallback The status_callback - * @return this - */ public ServiceUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * The status_callback. - * - * @param statusCallback The status_callback - * @return this - */ public ServiceUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The sticky_sender. - * - * @param stickySender The sticky_sender - * @return this - */ public ServiceUpdater setStickySender(final Boolean stickySender) { this.stickySender = stickySender; return this; } - /** - * The mms_converter. - * - * @param mmsConverter The mms_converter - * @return this - */ public ServiceUpdater setMmsConverter(final Boolean mmsConverter) { this.mmsConverter = mmsConverter; return this; } - /** - * The smart_encoding. - * - * @param smartEncoding The smart_encoding - * @return this - */ public ServiceUpdater setSmartEncoding(final Boolean smartEncoding) { this.smartEncoding = smartEncoding; return this; } - /** - * The scan_message_content. - * - * @param scanMessageContent The scan_message_content - * @return this - */ - public ServiceUpdater setScanMessageContent(final Service.ScanMessageContent scanMessageContent) { + public ServiceUpdater setScanMessageContent( + final Service.ScanMessageContent scanMessageContent + ) { this.scanMessageContent = scanMessageContent; return this; } - /** - * The fallback_to_long_code. - * - * @param fallbackToLongCode The fallback_to_long_code - * @return this - */ - public ServiceUpdater setFallbackToLongCode(final Boolean fallbackToLongCode) { + public ServiceUpdater setFallbackToLongCode( + final Boolean fallbackToLongCode + ) { this.fallbackToLongCode = fallbackToLongCode; return this; } - /** - * The area_code_geomatch. - * - * @param areaCodeGeomatch The area_code_geomatch - * @return this - */ public ServiceUpdater setAreaCodeGeomatch(final Boolean areaCodeGeomatch) { this.areaCodeGeomatch = areaCodeGeomatch; return this; } - /** - * The validity_period. - * - * @param validityPeriod The validity_period - * @return this - */ public ServiceUpdater setValidityPeriod(final Integer validityPeriod) { this.validityPeriod = validityPeriod; return this; } - /** - * The synchronous_validation. - * - * @param synchronousValidation The synchronous_validation - * @return this - */ - public ServiceUpdater setSynchronousValidation(final Boolean synchronousValidation) { + public ServiceUpdater setSynchronousValidation( + final Boolean synchronousValidation + ) { this.synchronousValidation = synchronousValidation; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { + public ServiceUpdater setUsecase(final String usecase) { + this.usecase = usecase; + return this; + } + + public ServiceUpdater setUseInboundWebhookOnNumber( + final Boolean useInboundWebhookOnNumber + ) { + this.useInboundWebhookOnNumber = useInboundWebhookOnNumber; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (inboundRequestUrl != null) { - request.addPostParam("InboundRequestUrl", inboundRequestUrl.toString()); + Serializer.toString( + request, + "InboundRequestUrl", + inboundRequestUrl, + ParameterType.URLENCODED + ); } if (inboundMethod != null) { - request.addPostParam("InboundMethod", inboundMethod.toString()); + Serializer.toString( + request, + "InboundMethod", + inboundMethod, + ParameterType.URLENCODED + ); } if (fallbackUrl != null) { - request.addPostParam("FallbackUrl", fallbackUrl.toString()); + Serializer.toString( + request, + "FallbackUrl", + fallbackUrl, + ParameterType.URLENCODED + ); } if (fallbackMethod != null) { - request.addPostParam("FallbackMethod", fallbackMethod.toString()); + Serializer.toString( + request, + "FallbackMethod", + fallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (stickySender != null) { - request.addPostParam("StickySender", stickySender.toString()); + Serializer.toString( + request, + "StickySender", + stickySender, + ParameterType.URLENCODED + ); } if (mmsConverter != null) { - request.addPostParam("MmsConverter", mmsConverter.toString()); + Serializer.toString( + request, + "MmsConverter", + mmsConverter, + ParameterType.URLENCODED + ); } if (smartEncoding != null) { - request.addPostParam("SmartEncoding", smartEncoding.toString()); + Serializer.toString( + request, + "SmartEncoding", + smartEncoding, + ParameterType.URLENCODED + ); } if (scanMessageContent != null) { - request.addPostParam("ScanMessageContent", scanMessageContent.toString()); + Serializer.toString( + request, + "ScanMessageContent", + scanMessageContent, + ParameterType.URLENCODED + ); } if (fallbackToLongCode != null) { - request.addPostParam("FallbackToLongCode", fallbackToLongCode.toString()); + Serializer.toString( + request, + "FallbackToLongCode", + fallbackToLongCode, + ParameterType.URLENCODED + ); } if (areaCodeGeomatch != null) { - request.addPostParam("AreaCodeGeomatch", areaCodeGeomatch.toString()); + Serializer.toString( + request, + "AreaCodeGeomatch", + areaCodeGeomatch, + ParameterType.URLENCODED + ); } if (validityPeriod != null) { - request.addPostParam("ValidityPeriod", validityPeriod.toString()); + Serializer.toString( + request, + "ValidityPeriod", + validityPeriod, + ParameterType.URLENCODED + ); } if (synchronousValidation != null) { - request.addPostParam("SynchronousValidation", synchronousValidation.toString()); + Serializer.toString( + request, + "SynchronousValidation", + synchronousValidation, + ParameterType.URLENCODED + ); + } + + if (usecase != null) { + Serializer.toString( + request, + "Usecase", + usecase, + ParameterType.URLENCODED + ); + } + + if (useInboundWebhookOnNumber != null) { + Serializer.toString( + request, + "UseInboundWebhookOnNumber", + useInboundWebhookOnNumber, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerification.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerification.java new file mode 100644 index 0000000000..7763fd1866 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerification.java @@ -0,0 +1,815 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TollfreeVerification extends Resource { + + public static TollfreeVerificationCreator creator( + final String businessName, + final String businessWebsite, + final String notificationEmail, + final List useCaseCategories, + final String useCaseSummary, + final String productionMessageSample, + final List optInImageUrls, + final TollfreeVerification.OptInType optInType, + final String messageVolume, + final String tollfreePhoneNumberSid + ) { + return new TollfreeVerificationCreator( + businessName, + businessWebsite, + notificationEmail, + useCaseCategories, + useCaseSummary, + productionMessageSample, + optInImageUrls, + optInType, + messageVolume, + tollfreePhoneNumberSid + ); + } + + public static TollfreeVerificationDeleter deleter(final String pathSid) { + return new TollfreeVerificationDeleter(pathSid); + } + + public static TollfreeVerificationFetcher fetcher(final String pathSid) { + return new TollfreeVerificationFetcher(pathSid); + } + + public static TollfreeVerificationReader reader() { + return new TollfreeVerificationReader(); + } + + public static TollfreeVerificationUpdater updater(final String pathSid) { + return new TollfreeVerificationUpdater(pathSid); + } + + public enum Status { + PENDING_REVIEW("PENDING_REVIEW"), + IN_REVIEW("IN_REVIEW"), + TWILIO_APPROVED("TWILIO_APPROVED"), + TWILIO_REJECTED("TWILIO_REJECTED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum UseCaseCategories { + TWO_FACTOR_AUTHENTICATION("TWO_FACTOR_AUTHENTICATION"), + ACCOUNT_NOTIFICATIONS("ACCOUNT_NOTIFICATIONS"), + CUSTOMER_CARE("CUSTOMER_CARE"), + CHARITY_NONPROFIT("CHARITY_NONPROFIT"), + DELIVERY_NOTIFICATIONS("DELIVERY_NOTIFICATIONS"), + FRAUD_ALERT_MESSAGING("FRAUD_ALERT_MESSAGING"), + EVENTS("EVENTS"), + HIGHER_EDUCATION("HIGHER_EDUCATION"), + K12("K12"), + MARKETING("MARKETING"), + POLLING_AND_VOTING_NON_POLITICAL("POLLING_AND_VOTING_NON_POLITICAL"), + POLITICAL_ELECTION_CAMPAIGNS("POLITICAL_ELECTION_CAMPAIGNS"), + PUBLIC_SERVICE_ANNOUNCEMENT("PUBLIC_SERVICE_ANNOUNCEMENT"), + SECURITY_ALERT("SECURITY_ALERT"); + + private final String value; + + private UseCaseCategories(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static UseCaseCategories forValue(final String value) { + return Promoter.enumFromString(value, UseCaseCategories.values()); + } + } + + public enum VettingProvider { + CAMPAIGN_VERIFY("CAMPAIGN_VERIFY"); + + private final String value; + + private VettingProvider(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static VettingProvider forValue(final String value) { + return Promoter.enumFromString(value, VettingProvider.values()); + } + } + + public enum BusinessType { + PRIVATE_PROFIT("PRIVATE_PROFIT"), + PUBLIC_PROFIT("PUBLIC_PROFIT"), + SOLE_PROPRIETOR("SOLE_PROPRIETOR"), + NON_PROFIT("NON_PROFIT"), + GOVERNMENT("GOVERNMENT"); + + private final String value; + + private BusinessType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BusinessType forValue(final String value) { + return Promoter.enumFromString(value, BusinessType.values()); + } + } + + public enum BusinessRegistrationAuthority { + EIN("EIN"), + CBN("CBN"), + CRN("CRN"), + PROVINCIAL_NUMBER("PROVINCIAL_NUMBER"), + VAT("VAT"), + ACN("ACN"), + ABN("ABN"), + BRN("BRN"), + SIREN("SIREN"), + SIRET("SIRET"), + NZBN("NZBN"), + UST_ID_NR("USt-IdNr"), + CIF("CIF"), + NIF("NIF"), + CNPJ("CNPJ"), + UID("UID"), + NEQ("NEQ"), + OTHER("OTHER"); + + private final String value; + + private BusinessRegistrationAuthority(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BusinessRegistrationAuthority forValue( + final String value + ) { + return Promoter.enumFromString( + value, + BusinessRegistrationAuthority.values() + ); + } + } + + public enum OptInType { + VERBAL("VERBAL"), + WEB_FORM("WEB_FORM"), + PAPER_FORM("PAPER_FORM"), + VIA_TEXT("VIA_TEXT"), + MOBILE_QR_CODE("MOBILE_QR_CODE"), + IMPORT("IMPORT"), + IMPORT_PLEASE_REPLACE("IMPORT_PLEASE_REPLACE"); + + private final String value; + + private OptInType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OptInType forValue(final String value) { + return Promoter.enumFromString(value, OptInType.values()); + } + } + + /** + * Converts a JSON String into a TollfreeVerification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TollfreeVerification object represented by the provided JSON + */ + public static TollfreeVerification fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TollfreeVerification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TollfreeVerification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TollfreeVerification object represented by the provided JSON + */ + public static TollfreeVerification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TollfreeVerification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String additionalInformation; + + @Getter + private final Boolean ageGatedContent; + + @Getter + private final String businessCity; + + @Getter + private final String businessContactEmail; + + @Getter + private final String businessContactFirstName; + + @Getter + private final String businessContactLastName; + + @Getter + private final com.twilio.type.PhoneNumber businessContactPhone; + + @Getter + private final String businessCountry; + + @Getter + private final String businessName; + + @Getter + private final String businessPostalCode; + + @Getter + private final TollfreeVerification.BusinessRegistrationAuthority businessRegistrationAuthority; + + @Getter + private final String businessRegistrationCountry; + + @Getter + private final String businessRegistrationNumber; + + @Getter + private final String businessRegistrationPhoneNumber; + + @Getter + private final String businessStateProvinceRegion; + + @Getter + private final String businessStreetAddress; + + @Getter + private final String businessStreetAddress2; + + @Getter + private final TollfreeVerification.BusinessType businessType; + + @Getter + private final String businessWebsite; + + @Getter + private final String customerProfileSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String doingBusinessAs; + + @Getter + private final Boolean editAllowed; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime editExpiration; + + @Getter + private final Integer errorCode; + + @Getter + private final String externalReferenceId; + + @Getter + private final String helpMessageSample; + + @Getter + private final String messageVolume; + + @Getter + private final String notificationEmail; + + @Getter + private final String optInConfirmationMessage; + + @Getter + private final List optInImageUrls; + + @Getter + private final List optInKeywords; + + @Getter + private final TollfreeVerification.OptInType optInType; + + @Getter + private final URI privacyPolicyUrl; + + @Getter + private final String productionMessageSample; + + @Getter + private final String regulatedItemSid; + + @Getter + private final String rejectionReason; + + @Getter + private final List rejectionReasons; + + @Getter + private final Object resourceLinks; + + @Getter + private final String sid; + + @Getter + private final TollfreeVerification.Status status; + + @Getter + private final URI termsAndConditionsUrl; + + @Getter + private final com.twilio.type.PhoneNumber tollfreePhoneNumber; + + @Getter + private final String tollfreePhoneNumberSid; + + @Getter + private final String trustProductSid; + + @Getter + private final URI url; + + @Getter + private final List< + TollfreeVerification.UseCaseCategories + > useCaseCategories; + + @Getter + private final String useCaseSummary; + + @Getter + private final String vettingId; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime vettingIdExpiration; + + @Getter + private final TollfreeVerification.VettingProvider vettingProvider; + + @JsonCreator + private TollfreeVerification( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "additional_information" + ) final String additionalInformation, + @JsonProperty("age_gated_content") final Boolean ageGatedContent, + @JsonProperty("business_city") final String businessCity, + @JsonProperty( + "business_contact_email" + ) final String businessContactEmail, + @JsonProperty( + "business_contact_first_name" + ) final String businessContactFirstName, + @JsonProperty( + "business_contact_last_name" + ) final String businessContactLastName, + @JsonProperty( + "business_contact_phone" + ) final com.twilio.type.PhoneNumber businessContactPhone, + @JsonProperty("business_country") final String businessCountry, + @JsonProperty("business_name") final String businessName, + @JsonProperty("business_postal_code") final String businessPostalCode, + @JsonProperty( + "business_registration_authority" + ) final TollfreeVerification.BusinessRegistrationAuthority businessRegistrationAuthority, + @JsonProperty( + "business_registration_country" + ) final String businessRegistrationCountry, + @JsonProperty( + "business_registration_number" + ) final String businessRegistrationNumber, + @JsonProperty( + "business_registration_phone_number" + ) final String businessRegistrationPhoneNumber, + @JsonProperty( + "business_state_province_region" + ) final String businessStateProvinceRegion, + @JsonProperty( + "business_street_address" + ) final String businessStreetAddress, + @JsonProperty( + "business_street_address2" + ) final String businessStreetAddress2, + @JsonProperty( + "business_type" + ) final TollfreeVerification.BusinessType businessType, + @JsonProperty("business_website") final String businessWebsite, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("doing_business_as") final String doingBusinessAs, + @JsonProperty("edit_allowed") final Boolean editAllowed, + @JsonProperty("edit_expiration") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime editExpiration, + @JsonProperty("error_code") final Integer errorCode, + @JsonProperty("external_reference_id") final String externalReferenceId, + @JsonProperty("help_message_sample") final String helpMessageSample, + @JsonProperty("message_volume") final String messageVolume, + @JsonProperty("notification_email") final String notificationEmail, + @JsonProperty( + "opt_in_confirmation_message" + ) final String optInConfirmationMessage, + @JsonProperty("opt_in_image_urls") final List optInImageUrls, + @JsonProperty("opt_in_keywords") final List optInKeywords, + @JsonProperty( + "opt_in_type" + ) final TollfreeVerification.OptInType optInType, + @JsonProperty("privacy_policy_url") final URI privacyPolicyUrl, + @JsonProperty( + "production_message_sample" + ) final String productionMessageSample, + @JsonProperty("regulated_item_sid") final String regulatedItemSid, + @JsonProperty("rejection_reason") final String rejectionReason, + @JsonProperty("rejection_reasons") final List rejectionReasons, + @JsonProperty("resource_links") final Object resourceLinks, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final TollfreeVerification.Status status, + @JsonProperty( + "terms_and_conditions_url" + ) final URI termsAndConditionsUrl, + @JsonProperty( + "tollfree_phone_number" + ) final com.twilio.type.PhoneNumber tollfreePhoneNumber, + @JsonProperty( + "tollfree_phone_number_sid" + ) final String tollfreePhoneNumberSid, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("url") final URI url, + @JsonProperty("use_case_categories") final List< + TollfreeVerification.UseCaseCategories + > useCaseCategories, + @JsonProperty("use_case_summary") final String useCaseSummary, + @JsonProperty("vetting_id") final String vettingId, + @JsonProperty("vetting_id_expiration") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime vettingIdExpiration, + @JsonProperty( + "vetting_provider" + ) final TollfreeVerification.VettingProvider vettingProvider + ) { + this.accountSid = accountSid; + this.additionalInformation = additionalInformation; + this.ageGatedContent = ageGatedContent; + this.businessCity = businessCity; + this.businessContactEmail = businessContactEmail; + this.businessContactFirstName = businessContactFirstName; + this.businessContactLastName = businessContactLastName; + this.businessContactPhone = businessContactPhone; + this.businessCountry = businessCountry; + this.businessName = businessName; + this.businessPostalCode = businessPostalCode; + this.businessRegistrationAuthority = businessRegistrationAuthority; + this.businessRegistrationCountry = businessRegistrationCountry; + this.businessRegistrationNumber = businessRegistrationNumber; + this.businessRegistrationPhoneNumber = businessRegistrationPhoneNumber; + this.businessStateProvinceRegion = businessStateProvinceRegion; + this.businessStreetAddress = businessStreetAddress; + this.businessStreetAddress2 = businessStreetAddress2; + this.businessType = businessType; + this.businessWebsite = businessWebsite; + this.customerProfileSid = customerProfileSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.doingBusinessAs = doingBusinessAs; + this.editAllowed = editAllowed; + this.editExpiration = editExpiration; + this.errorCode = errorCode; + this.externalReferenceId = externalReferenceId; + this.helpMessageSample = helpMessageSample; + this.messageVolume = messageVolume; + this.notificationEmail = notificationEmail; + this.optInConfirmationMessage = optInConfirmationMessage; + this.optInImageUrls = optInImageUrls; + this.optInKeywords = optInKeywords; + this.optInType = optInType; + this.privacyPolicyUrl = privacyPolicyUrl; + this.productionMessageSample = productionMessageSample; + this.regulatedItemSid = regulatedItemSid; + this.rejectionReason = rejectionReason; + this.rejectionReasons = rejectionReasons; + this.resourceLinks = resourceLinks; + this.sid = sid; + this.status = status; + this.termsAndConditionsUrl = termsAndConditionsUrl; + this.tollfreePhoneNumber = tollfreePhoneNumber; + this.tollfreePhoneNumberSid = tollfreePhoneNumberSid; + this.trustProductSid = trustProductSid; + this.url = url; + this.useCaseCategories = useCaseCategories; + this.useCaseSummary = useCaseSummary; + this.vettingId = vettingId; + this.vettingIdExpiration = vettingIdExpiration; + this.vettingProvider = vettingProvider; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TollfreeVerification other = (TollfreeVerification) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + additionalInformation, + other.additionalInformation + ) && + Objects.equals(ageGatedContent, other.ageGatedContent) && + Objects.equals(businessCity, other.businessCity) && + Objects.equals(businessContactEmail, other.businessContactEmail) && + Objects.equals( + businessContactFirstName, + other.businessContactFirstName + ) && + Objects.equals( + businessContactLastName, + other.businessContactLastName + ) && + Objects.equals(businessContactPhone, other.businessContactPhone) && + Objects.equals(businessCountry, other.businessCountry) && + Objects.equals(businessName, other.businessName) && + Objects.equals(businessPostalCode, other.businessPostalCode) && + Objects.equals( + businessRegistrationAuthority, + other.businessRegistrationAuthority + ) && + Objects.equals( + businessRegistrationCountry, + other.businessRegistrationCountry + ) && + Objects.equals( + businessRegistrationNumber, + other.businessRegistrationNumber + ) && + Objects.equals( + businessRegistrationPhoneNumber, + other.businessRegistrationPhoneNumber + ) && + Objects.equals( + businessStateProvinceRegion, + other.businessStateProvinceRegion + ) && + Objects.equals( + businessStreetAddress, + other.businessStreetAddress + ) && + Objects.equals( + businessStreetAddress2, + other.businessStreetAddress2 + ) && + Objects.equals(businessType, other.businessType) && + Objects.equals(businessWebsite, other.businessWebsite) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(doingBusinessAs, other.doingBusinessAs) && + Objects.equals(editAllowed, other.editAllowed) && + Objects.equals(editExpiration, other.editExpiration) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(externalReferenceId, other.externalReferenceId) && + Objects.equals(helpMessageSample, other.helpMessageSample) && + Objects.equals(messageVolume, other.messageVolume) && + Objects.equals(notificationEmail, other.notificationEmail) && + Objects.equals( + optInConfirmationMessage, + other.optInConfirmationMessage + ) && + Objects.equals(optInImageUrls, other.optInImageUrls) && + Objects.equals(optInKeywords, other.optInKeywords) && + Objects.equals(optInType, other.optInType) && + Objects.equals(privacyPolicyUrl, other.privacyPolicyUrl) && + Objects.equals( + productionMessageSample, + other.productionMessageSample + ) && + Objects.equals(regulatedItemSid, other.regulatedItemSid) && + Objects.equals(rejectionReason, other.rejectionReason) && + Objects.equals(rejectionReasons, other.rejectionReasons) && + Objects.equals(resourceLinks, other.resourceLinks) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals( + termsAndConditionsUrl, + other.termsAndConditionsUrl + ) && + Objects.equals(tollfreePhoneNumber, other.tollfreePhoneNumber) && + Objects.equals( + tollfreePhoneNumberSid, + other.tollfreePhoneNumberSid + ) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(url, other.url) && + Objects.equals(useCaseCategories, other.useCaseCategories) && + Objects.equals(useCaseSummary, other.useCaseSummary) && + Objects.equals(vettingId, other.vettingId) && + Objects.equals(vettingIdExpiration, other.vettingIdExpiration) && + Objects.equals(vettingProvider, other.vettingProvider) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + additionalInformation, + ageGatedContent, + businessCity, + businessContactEmail, + businessContactFirstName, + businessContactLastName, + businessContactPhone, + businessCountry, + businessName, + businessPostalCode, + businessRegistrationAuthority, + businessRegistrationCountry, + businessRegistrationNumber, + businessRegistrationPhoneNumber, + businessStateProvinceRegion, + businessStreetAddress, + businessStreetAddress2, + businessType, + businessWebsite, + customerProfileSid, + dateCreated, + dateUpdated, + doingBusinessAs, + editAllowed, + editExpiration, + errorCode, + externalReferenceId, + helpMessageSample, + messageVolume, + notificationEmail, + optInConfirmationMessage, + optInImageUrls, + optInKeywords, + optInType, + privacyPolicyUrl, + productionMessageSample, + regulatedItemSid, + rejectionReason, + rejectionReasons, + resourceLinks, + sid, + status, + termsAndConditionsUrl, + tollfreePhoneNumber, + tollfreePhoneNumberSid, + trustProductSid, + url, + useCaseCategories, + useCaseSummary, + vettingId, + vettingIdExpiration, + vettingProvider + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationCreator.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationCreator.java new file mode 100644 index 0000000000..b00a4b5863 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationCreator.java @@ -0,0 +1,781 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class TollfreeVerificationCreator extends Creator { + + private String businessName; + private String businessWebsite; + private String notificationEmail; + private List useCaseCategories; + private String useCaseSummary; + private String productionMessageSample; + private List optInImageUrls; + private TollfreeVerification.OptInType optInType; + private String messageVolume; + private String tollfreePhoneNumberSid; + private String customerProfileSid; + private String businessStreetAddress; + private String businessStreetAddress2; + private String businessCity; + private String businessStateProvinceRegion; + private String businessPostalCode; + private String businessCountry; + private String additionalInformation; + private String businessContactFirstName; + private String businessContactLastName; + private String businessContactEmail; + private com.twilio.type.PhoneNumber businessContactPhone; + private String externalReferenceId; + private String businessRegistrationNumber; + private TollfreeVerification.BusinessRegistrationAuthority businessRegistrationAuthority; + private String businessRegistrationCountry; + private TollfreeVerification.BusinessType businessType; + private String businessRegistrationPhoneNumber; + private String doingBusinessAs; + private String optInConfirmationMessage; + private String helpMessageSample; + private String privacyPolicyUrl; + private String termsAndConditionsUrl; + private Boolean ageGatedContent; + private List optInKeywords; + private TollfreeVerification.VettingProvider vettingProvider; + private String vettingId; + + public TollfreeVerificationCreator( + final String businessName, + final String businessWebsite, + final String notificationEmail, + final List useCaseCategories, + final String useCaseSummary, + final String productionMessageSample, + final List optInImageUrls, + final TollfreeVerification.OptInType optInType, + final String messageVolume, + final String tollfreePhoneNumberSid + ) { + this.businessName = businessName; + this.businessWebsite = businessWebsite; + this.notificationEmail = notificationEmail; + this.useCaseCategories = useCaseCategories; + this.useCaseSummary = useCaseSummary; + this.productionMessageSample = productionMessageSample; + this.optInImageUrls = optInImageUrls; + this.optInType = optInType; + this.messageVolume = messageVolume; + this.tollfreePhoneNumberSid = tollfreePhoneNumberSid; + } + + public TollfreeVerificationCreator setBusinessName( + final String businessName + ) { + this.businessName = businessName; + return this; + } + + public TollfreeVerificationCreator setBusinessWebsite( + final String businessWebsite + ) { + this.businessWebsite = businessWebsite; + return this; + } + + public TollfreeVerificationCreator setNotificationEmail( + final String notificationEmail + ) { + this.notificationEmail = notificationEmail; + return this; + } + + public TollfreeVerificationCreator setUseCaseCategories( + final List useCaseCategories + ) { + this.useCaseCategories = useCaseCategories; + return this; + } + + public TollfreeVerificationCreator setUseCaseCategories( + final TollfreeVerification.UseCaseCategories useCaseCategories + ) { + return setUseCaseCategories(Promoter.listOfOne(useCaseCategories)); + } + + public TollfreeVerificationCreator setUseCaseSummary( + final String useCaseSummary + ) { + this.useCaseSummary = useCaseSummary; + return this; + } + + public TollfreeVerificationCreator setProductionMessageSample( + final String productionMessageSample + ) { + this.productionMessageSample = productionMessageSample; + return this; + } + + public TollfreeVerificationCreator setOptInImageUrls( + final List optInImageUrls + ) { + this.optInImageUrls = optInImageUrls; + return this; + } + + public TollfreeVerificationCreator setOptInImageUrls( + final String optInImageUrls + ) { + return setOptInImageUrls(Promoter.listOfOne(optInImageUrls)); + } + + public TollfreeVerificationCreator setOptInType( + final TollfreeVerification.OptInType optInType + ) { + this.optInType = optInType; + return this; + } + + public TollfreeVerificationCreator setMessageVolume( + final String messageVolume + ) { + this.messageVolume = messageVolume; + return this; + } + + public TollfreeVerificationCreator setTollfreePhoneNumberSid( + final String tollfreePhoneNumberSid + ) { + this.tollfreePhoneNumberSid = tollfreePhoneNumberSid; + return this; + } + + public TollfreeVerificationCreator setCustomerProfileSid( + final String customerProfileSid + ) { + this.customerProfileSid = customerProfileSid; + return this; + } + + public TollfreeVerificationCreator setBusinessStreetAddress( + final String businessStreetAddress + ) { + this.businessStreetAddress = businessStreetAddress; + return this; + } + + public TollfreeVerificationCreator setBusinessStreetAddress2( + final String businessStreetAddress2 + ) { + this.businessStreetAddress2 = businessStreetAddress2; + return this; + } + + public TollfreeVerificationCreator setBusinessCity( + final String businessCity + ) { + this.businessCity = businessCity; + return this; + } + + public TollfreeVerificationCreator setBusinessStateProvinceRegion( + final String businessStateProvinceRegion + ) { + this.businessStateProvinceRegion = businessStateProvinceRegion; + return this; + } + + public TollfreeVerificationCreator setBusinessPostalCode( + final String businessPostalCode + ) { + this.businessPostalCode = businessPostalCode; + return this; + } + + public TollfreeVerificationCreator setBusinessCountry( + final String businessCountry + ) { + this.businessCountry = businessCountry; + return this; + } + + public TollfreeVerificationCreator setAdditionalInformation( + final String additionalInformation + ) { + this.additionalInformation = additionalInformation; + return this; + } + + public TollfreeVerificationCreator setBusinessContactFirstName( + final String businessContactFirstName + ) { + this.businessContactFirstName = businessContactFirstName; + return this; + } + + public TollfreeVerificationCreator setBusinessContactLastName( + final String businessContactLastName + ) { + this.businessContactLastName = businessContactLastName; + return this; + } + + public TollfreeVerificationCreator setBusinessContactEmail( + final String businessContactEmail + ) { + this.businessContactEmail = businessContactEmail; + return this; + } + + public TollfreeVerificationCreator setBusinessContactPhone( + final com.twilio.type.PhoneNumber businessContactPhone + ) { + this.businessContactPhone = businessContactPhone; + return this; + } + + public TollfreeVerificationCreator setBusinessContactPhone( + final String businessContactPhone + ) { + return setBusinessContactPhone( + Promoter.phoneNumberFromString(businessContactPhone) + ); + } + + public TollfreeVerificationCreator setExternalReferenceId( + final String externalReferenceId + ) { + this.externalReferenceId = externalReferenceId; + return this; + } + + public TollfreeVerificationCreator setBusinessRegistrationNumber( + final String businessRegistrationNumber + ) { + this.businessRegistrationNumber = businessRegistrationNumber; + return this; + } + + public TollfreeVerificationCreator setBusinessRegistrationAuthority( + final TollfreeVerification.BusinessRegistrationAuthority businessRegistrationAuthority + ) { + this.businessRegistrationAuthority = businessRegistrationAuthority; + return this; + } + + public TollfreeVerificationCreator setBusinessRegistrationCountry( + final String businessRegistrationCountry + ) { + this.businessRegistrationCountry = businessRegistrationCountry; + return this; + } + + public TollfreeVerificationCreator setBusinessType( + final TollfreeVerification.BusinessType businessType + ) { + this.businessType = businessType; + return this; + } + + public TollfreeVerificationCreator setBusinessRegistrationPhoneNumber( + final String businessRegistrationPhoneNumber + ) { + this.businessRegistrationPhoneNumber = businessRegistrationPhoneNumber; + return this; + } + + public TollfreeVerificationCreator setDoingBusinessAs( + final String doingBusinessAs + ) { + this.doingBusinessAs = doingBusinessAs; + return this; + } + + public TollfreeVerificationCreator setOptInConfirmationMessage( + final String optInConfirmationMessage + ) { + this.optInConfirmationMessage = optInConfirmationMessage; + return this; + } + + public TollfreeVerificationCreator setHelpMessageSample( + final String helpMessageSample + ) { + this.helpMessageSample = helpMessageSample; + return this; + } + + public TollfreeVerificationCreator setPrivacyPolicyUrl( + final String privacyPolicyUrl + ) { + this.privacyPolicyUrl = privacyPolicyUrl; + return this; + } + + public TollfreeVerificationCreator setTermsAndConditionsUrl( + final String termsAndConditionsUrl + ) { + this.termsAndConditionsUrl = termsAndConditionsUrl; + return this; + } + + public TollfreeVerificationCreator setAgeGatedContent( + final Boolean ageGatedContent + ) { + this.ageGatedContent = ageGatedContent; + return this; + } + + public TollfreeVerificationCreator setOptInKeywords( + final List optInKeywords + ) { + this.optInKeywords = optInKeywords; + return this; + } + + public TollfreeVerificationCreator setOptInKeywords( + final String optInKeywords + ) { + return setOptInKeywords(Promoter.listOfOne(optInKeywords)); + } + + public TollfreeVerificationCreator setVettingProvider( + final TollfreeVerification.VettingProvider vettingProvider + ) { + this.vettingProvider = vettingProvider; + return this; + } + + public TollfreeVerificationCreator setVettingId(final String vettingId) { + this.vettingId = vettingId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications"; + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TollfreeVerification create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TollfreeVerification content = TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (businessName != null) { + Serializer.toString( + request, + "BusinessName", + businessName, + ParameterType.URLENCODED + ); + } + + if (businessWebsite != null) { + Serializer.toString( + request, + "BusinessWebsite", + businessWebsite, + ParameterType.URLENCODED + ); + } + + if (notificationEmail != null) { + Serializer.toString( + request, + "NotificationEmail", + notificationEmail, + ParameterType.URLENCODED + ); + } + + if (useCaseCategories != null) { + for (TollfreeVerification.UseCaseCategories param : useCaseCategories) { + Serializer.toString( + request, + "UseCaseCategories", + param, + ParameterType.URLENCODED + ); + } + } + + if (useCaseSummary != null) { + Serializer.toString( + request, + "UseCaseSummary", + useCaseSummary, + ParameterType.URLENCODED + ); + } + + if (productionMessageSample != null) { + Serializer.toString( + request, + "ProductionMessageSample", + productionMessageSample, + ParameterType.URLENCODED + ); + } + + if (optInImageUrls != null) { + for (String param : optInImageUrls) { + Serializer.toString( + request, + "OptInImageUrls", + param, + ParameterType.URLENCODED + ); + } + } + + if (optInType != null) { + Serializer.toString( + request, + "OptInType", + optInType, + ParameterType.URLENCODED + ); + } + + if (messageVolume != null) { + Serializer.toString( + request, + "MessageVolume", + messageVolume, + ParameterType.URLENCODED + ); + } + + if (tollfreePhoneNumberSid != null) { + Serializer.toString( + request, + "TollfreePhoneNumberSid", + tollfreePhoneNumberSid, + ParameterType.URLENCODED + ); + } + + if (customerProfileSid != null) { + Serializer.toString( + request, + "CustomerProfileSid", + customerProfileSid, + ParameterType.URLENCODED + ); + } + + if (businessStreetAddress != null) { + Serializer.toString( + request, + "BusinessStreetAddress", + businessStreetAddress, + ParameterType.URLENCODED + ); + } + + if (businessStreetAddress2 != null) { + Serializer.toString( + request, + "BusinessStreetAddress2", + businessStreetAddress2, + ParameterType.URLENCODED + ); + } + + if (businessCity != null) { + Serializer.toString( + request, + "BusinessCity", + businessCity, + ParameterType.URLENCODED + ); + } + + if (businessStateProvinceRegion != null) { + Serializer.toString( + request, + "BusinessStateProvinceRegion", + businessStateProvinceRegion, + ParameterType.URLENCODED + ); + } + + if (businessPostalCode != null) { + Serializer.toString( + request, + "BusinessPostalCode", + businessPostalCode, + ParameterType.URLENCODED + ); + } + + if (businessCountry != null) { + Serializer.toString( + request, + "BusinessCountry", + businessCountry, + ParameterType.URLENCODED + ); + } + + if (additionalInformation != null) { + Serializer.toString( + request, + "AdditionalInformation", + additionalInformation, + ParameterType.URLENCODED + ); + } + + if (businessContactFirstName != null) { + Serializer.toString( + request, + "BusinessContactFirstName", + businessContactFirstName, + ParameterType.URLENCODED + ); + } + + if (businessContactLastName != null) { + Serializer.toString( + request, + "BusinessContactLastName", + businessContactLastName, + ParameterType.URLENCODED + ); + } + + if (businessContactEmail != null) { + Serializer.toString( + request, + "BusinessContactEmail", + businessContactEmail, + ParameterType.URLENCODED + ); + } + + if (businessContactPhone != null) { + Serializer.toString( + request, + "BusinessContactPhone", + businessContactPhone, + ParameterType.URLENCODED + ); + } + + if (externalReferenceId != null) { + Serializer.toString( + request, + "ExternalReferenceId", + externalReferenceId, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationNumber != null) { + Serializer.toString( + request, + "BusinessRegistrationNumber", + businessRegistrationNumber, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationAuthority != null) { + Serializer.toString( + request, + "BusinessRegistrationAuthority", + businessRegistrationAuthority, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationCountry != null) { + Serializer.toString( + request, + "BusinessRegistrationCountry", + businessRegistrationCountry, + ParameterType.URLENCODED + ); + } + + if (businessType != null) { + Serializer.toString( + request, + "BusinessType", + businessType, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationPhoneNumber != null) { + Serializer.toString( + request, + "BusinessRegistrationPhoneNumber", + businessRegistrationPhoneNumber, + ParameterType.URLENCODED + ); + } + + if (doingBusinessAs != null) { + Serializer.toString( + request, + "DoingBusinessAs", + doingBusinessAs, + ParameterType.URLENCODED + ); + } + + if (optInConfirmationMessage != null) { + Serializer.toString( + request, + "OptInConfirmationMessage", + optInConfirmationMessage, + ParameterType.URLENCODED + ); + } + + if (helpMessageSample != null) { + Serializer.toString( + request, + "HelpMessageSample", + helpMessageSample, + ParameterType.URLENCODED + ); + } + + if (privacyPolicyUrl != null) { + Serializer.toString( + request, + "PrivacyPolicyUrl", + privacyPolicyUrl, + ParameterType.URLENCODED + ); + } + + if (termsAndConditionsUrl != null) { + Serializer.toString( + request, + "TermsAndConditionsUrl", + termsAndConditionsUrl, + ParameterType.URLENCODED + ); + } + + if (ageGatedContent != null) { + Serializer.toString( + request, + "AgeGatedContent", + ageGatedContent, + ParameterType.URLENCODED + ); + } + + if (optInKeywords != null) { + for (String param : optInKeywords) { + Serializer.toString( + request, + "OptInKeywords", + param, + ParameterType.URLENCODED + ); + } + } + + if (vettingProvider != null) { + Serializer.toString( + request, + "VettingProvider", + vettingProvider, + ParameterType.URLENCODED + ); + } + + if (vettingId != null) { + Serializer.toString( + request, + "VettingId", + vettingId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationDeleter.java new file mode 100644 index 0000000000..99cad7622d --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class TollfreeVerificationDeleter extends Deleter { + + private String pathSid; + + public TollfreeVerificationDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationFetcher.java new file mode 100644 index 0000000000..ae724505ae --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TollfreeVerificationFetcher extends Fetcher { + + private String pathSid; + + public TollfreeVerificationFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TollfreeVerification fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TollfreeVerification content = TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationReader.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationReader.java new file mode 100644 index 0000000000..caba113418 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationReader.java @@ -0,0 +1,294 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class TollfreeVerificationReader extends Reader { + + private String tollfreePhoneNumberSid; + private TollfreeVerification.Status status; + private String externalReferenceId; + private Boolean includeSubAccounts; + private Long pageSize; + private List trustProductSid; + + public TollfreeVerificationReader() {} + + public TollfreeVerificationReader setTollfreePhoneNumberSid( + final String tollfreePhoneNumberSid + ) { + this.tollfreePhoneNumberSid = tollfreePhoneNumberSid; + return this; + } + + public TollfreeVerificationReader setStatus( + final TollfreeVerification.Status status + ) { + this.status = status; + return this; + } + + public TollfreeVerificationReader setExternalReferenceId( + final String externalReferenceId + ) { + this.externalReferenceId = externalReferenceId; + return this; + } + + public TollfreeVerificationReader setIncludeSubAccounts( + final Boolean includeSubAccounts + ) { + this.includeSubAccounts = includeSubAccounts; + return this; + } + + public TollfreeVerificationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public TollfreeVerificationReader setTrustProductSid( + final List trustProductSid + ) { + this.trustProductSid = trustProductSid; + return this; + } + + public TollfreeVerificationReader setTrustProductSid( + final String trustProductSid + ) { + return setTrustProductSid(Promoter.listOfOne(trustProductSid)); + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "verifications", + response.getContent(), + TollfreeVerification.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications"; + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "verifications", + response.getContent(), + TollfreeVerification.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "verifications", + response.getContent(), + TollfreeVerification.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (tollfreePhoneNumberSid != null) { + Serializer.toString( + request, + "TollfreePhoneNumberSid", + tollfreePhoneNumberSid, + ParameterType.QUERY + ); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (externalReferenceId != null) { + Serializer.toString( + request, + "ExternalReferenceId", + externalReferenceId, + ParameterType.QUERY + ); + } + + if (includeSubAccounts != null) { + Serializer.toString( + request, + "IncludeSubAccounts", + includeSubAccounts, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (trustProductSid != null) { + for (String param : trustProductSid) { + Serializer.toString( + request, + "TrustProductSid", + param, + ParameterType.QUERY + ); + } + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationUpdater.java new file mode 100644 index 0000000000..78ecceab2e --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/TollfreeVerificationUpdater.java @@ -0,0 +1,728 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class TollfreeVerificationUpdater extends Updater { + + private String pathSid; + private String businessName; + private String businessWebsite; + private String notificationEmail; + private List useCaseCategories; + private String useCaseSummary; + private String productionMessageSample; + private List optInImageUrls; + private TollfreeVerification.OptInType optInType; + private String messageVolume; + private String businessStreetAddress; + private String businessStreetAddress2; + private String businessCity; + private String businessStateProvinceRegion; + private String businessPostalCode; + private String businessCountry; + private String additionalInformation; + private String businessContactFirstName; + private String businessContactLastName; + private String businessContactEmail; + private com.twilio.type.PhoneNumber businessContactPhone; + private String editReason; + private String businessRegistrationNumber; + private TollfreeVerification.BusinessRegistrationAuthority businessRegistrationAuthority; + private String businessRegistrationCountry; + private TollfreeVerification.BusinessType businessType; + private String businessRegistrationPhoneNumber; + private String doingBusinessAs; + private String optInConfirmationMessage; + private String helpMessageSample; + private String privacyPolicyUrl; + private String termsAndConditionsUrl; + private Boolean ageGatedContent; + private List optInKeywords; + private TollfreeVerification.VettingProvider vettingProvider; + private String vettingId; + + public TollfreeVerificationUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public TollfreeVerificationUpdater setBusinessName( + final String businessName + ) { + this.businessName = businessName; + return this; + } + + public TollfreeVerificationUpdater setBusinessWebsite( + final String businessWebsite + ) { + this.businessWebsite = businessWebsite; + return this; + } + + public TollfreeVerificationUpdater setNotificationEmail( + final String notificationEmail + ) { + this.notificationEmail = notificationEmail; + return this; + } + + public TollfreeVerificationUpdater setUseCaseCategories( + final List useCaseCategories + ) { + this.useCaseCategories = useCaseCategories; + return this; + } + + public TollfreeVerificationUpdater setUseCaseCategories( + final TollfreeVerification.UseCaseCategories useCaseCategories + ) { + return setUseCaseCategories(Promoter.listOfOne(useCaseCategories)); + } + + public TollfreeVerificationUpdater setUseCaseSummary( + final String useCaseSummary + ) { + this.useCaseSummary = useCaseSummary; + return this; + } + + public TollfreeVerificationUpdater setProductionMessageSample( + final String productionMessageSample + ) { + this.productionMessageSample = productionMessageSample; + return this; + } + + public TollfreeVerificationUpdater setOptInImageUrls( + final List optInImageUrls + ) { + this.optInImageUrls = optInImageUrls; + return this; + } + + public TollfreeVerificationUpdater setOptInImageUrls( + final String optInImageUrls + ) { + return setOptInImageUrls(Promoter.listOfOne(optInImageUrls)); + } + + public TollfreeVerificationUpdater setOptInType( + final TollfreeVerification.OptInType optInType + ) { + this.optInType = optInType; + return this; + } + + public TollfreeVerificationUpdater setMessageVolume( + final String messageVolume + ) { + this.messageVolume = messageVolume; + return this; + } + + public TollfreeVerificationUpdater setBusinessStreetAddress( + final String businessStreetAddress + ) { + this.businessStreetAddress = businessStreetAddress; + return this; + } + + public TollfreeVerificationUpdater setBusinessStreetAddress2( + final String businessStreetAddress2 + ) { + this.businessStreetAddress2 = businessStreetAddress2; + return this; + } + + public TollfreeVerificationUpdater setBusinessCity( + final String businessCity + ) { + this.businessCity = businessCity; + return this; + } + + public TollfreeVerificationUpdater setBusinessStateProvinceRegion( + final String businessStateProvinceRegion + ) { + this.businessStateProvinceRegion = businessStateProvinceRegion; + return this; + } + + public TollfreeVerificationUpdater setBusinessPostalCode( + final String businessPostalCode + ) { + this.businessPostalCode = businessPostalCode; + return this; + } + + public TollfreeVerificationUpdater setBusinessCountry( + final String businessCountry + ) { + this.businessCountry = businessCountry; + return this; + } + + public TollfreeVerificationUpdater setAdditionalInformation( + final String additionalInformation + ) { + this.additionalInformation = additionalInformation; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactFirstName( + final String businessContactFirstName + ) { + this.businessContactFirstName = businessContactFirstName; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactLastName( + final String businessContactLastName + ) { + this.businessContactLastName = businessContactLastName; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactEmail( + final String businessContactEmail + ) { + this.businessContactEmail = businessContactEmail; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactPhone( + final com.twilio.type.PhoneNumber businessContactPhone + ) { + this.businessContactPhone = businessContactPhone; + return this; + } + + public TollfreeVerificationUpdater setBusinessContactPhone( + final String businessContactPhone + ) { + return setBusinessContactPhone( + Promoter.phoneNumberFromString(businessContactPhone) + ); + } + + public TollfreeVerificationUpdater setEditReason(final String editReason) { + this.editReason = editReason; + return this; + } + + public TollfreeVerificationUpdater setBusinessRegistrationNumber( + final String businessRegistrationNumber + ) { + this.businessRegistrationNumber = businessRegistrationNumber; + return this; + } + + public TollfreeVerificationUpdater setBusinessRegistrationAuthority( + final TollfreeVerification.BusinessRegistrationAuthority businessRegistrationAuthority + ) { + this.businessRegistrationAuthority = businessRegistrationAuthority; + return this; + } + + public TollfreeVerificationUpdater setBusinessRegistrationCountry( + final String businessRegistrationCountry + ) { + this.businessRegistrationCountry = businessRegistrationCountry; + return this; + } + + public TollfreeVerificationUpdater setBusinessType( + final TollfreeVerification.BusinessType businessType + ) { + this.businessType = businessType; + return this; + } + + public TollfreeVerificationUpdater setBusinessRegistrationPhoneNumber( + final String businessRegistrationPhoneNumber + ) { + this.businessRegistrationPhoneNumber = businessRegistrationPhoneNumber; + return this; + } + + public TollfreeVerificationUpdater setDoingBusinessAs( + final String doingBusinessAs + ) { + this.doingBusinessAs = doingBusinessAs; + return this; + } + + public TollfreeVerificationUpdater setOptInConfirmationMessage( + final String optInConfirmationMessage + ) { + this.optInConfirmationMessage = optInConfirmationMessage; + return this; + } + + public TollfreeVerificationUpdater setHelpMessageSample( + final String helpMessageSample + ) { + this.helpMessageSample = helpMessageSample; + return this; + } + + public TollfreeVerificationUpdater setPrivacyPolicyUrl( + final String privacyPolicyUrl + ) { + this.privacyPolicyUrl = privacyPolicyUrl; + return this; + } + + public TollfreeVerificationUpdater setTermsAndConditionsUrl( + final String termsAndConditionsUrl + ) { + this.termsAndConditionsUrl = termsAndConditionsUrl; + return this; + } + + public TollfreeVerificationUpdater setAgeGatedContent( + final Boolean ageGatedContent + ) { + this.ageGatedContent = ageGatedContent; + return this; + } + + public TollfreeVerificationUpdater setOptInKeywords( + final List optInKeywords + ) { + this.optInKeywords = optInKeywords; + return this; + } + + public TollfreeVerificationUpdater setOptInKeywords( + final String optInKeywords + ) { + return setOptInKeywords(Promoter.listOfOne(optInKeywords)); + } + + public TollfreeVerificationUpdater setVettingProvider( + final TollfreeVerification.VettingProvider vettingProvider + ) { + this.vettingProvider = vettingProvider; + return this; + } + + public TollfreeVerificationUpdater setVettingId(final String vettingId) { + this.vettingId = vettingId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Tollfree/Verifications/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TollfreeVerification update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TollfreeVerification update(final TwilioRestClient client) { + Response response = makeRequest(client); + return TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TollfreeVerification content = TollfreeVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (businessName != null) { + Serializer.toString( + request, + "BusinessName", + businessName, + ParameterType.URLENCODED + ); + } + + if (businessWebsite != null) { + Serializer.toString( + request, + "BusinessWebsite", + businessWebsite, + ParameterType.URLENCODED + ); + } + + if (notificationEmail != null) { + Serializer.toString( + request, + "NotificationEmail", + notificationEmail, + ParameterType.URLENCODED + ); + } + + if (useCaseCategories != null) { + for (TollfreeVerification.UseCaseCategories param : useCaseCategories) { + Serializer.toString( + request, + "UseCaseCategories", + param, + ParameterType.URLENCODED + ); + } + } + + if (useCaseSummary != null) { + Serializer.toString( + request, + "UseCaseSummary", + useCaseSummary, + ParameterType.URLENCODED + ); + } + + if (productionMessageSample != null) { + Serializer.toString( + request, + "ProductionMessageSample", + productionMessageSample, + ParameterType.URLENCODED + ); + } + + if (optInImageUrls != null) { + for (String param : optInImageUrls) { + Serializer.toString( + request, + "OptInImageUrls", + param, + ParameterType.URLENCODED + ); + } + } + + if (optInType != null) { + Serializer.toString( + request, + "OptInType", + optInType, + ParameterType.URLENCODED + ); + } + + if (messageVolume != null) { + Serializer.toString( + request, + "MessageVolume", + messageVolume, + ParameterType.URLENCODED + ); + } + + if (businessStreetAddress != null) { + Serializer.toString( + request, + "BusinessStreetAddress", + businessStreetAddress, + ParameterType.URLENCODED + ); + } + + if (businessStreetAddress2 != null) { + Serializer.toString( + request, + "BusinessStreetAddress2", + businessStreetAddress2, + ParameterType.URLENCODED + ); + } + + if (businessCity != null) { + Serializer.toString( + request, + "BusinessCity", + businessCity, + ParameterType.URLENCODED + ); + } + + if (businessStateProvinceRegion != null) { + Serializer.toString( + request, + "BusinessStateProvinceRegion", + businessStateProvinceRegion, + ParameterType.URLENCODED + ); + } + + if (businessPostalCode != null) { + Serializer.toString( + request, + "BusinessPostalCode", + businessPostalCode, + ParameterType.URLENCODED + ); + } + + if (businessCountry != null) { + Serializer.toString( + request, + "BusinessCountry", + businessCountry, + ParameterType.URLENCODED + ); + } + + if (additionalInformation != null) { + Serializer.toString( + request, + "AdditionalInformation", + additionalInformation, + ParameterType.URLENCODED + ); + } + + if (businessContactFirstName != null) { + Serializer.toString( + request, + "BusinessContactFirstName", + businessContactFirstName, + ParameterType.URLENCODED + ); + } + + if (businessContactLastName != null) { + Serializer.toString( + request, + "BusinessContactLastName", + businessContactLastName, + ParameterType.URLENCODED + ); + } + + if (businessContactEmail != null) { + Serializer.toString( + request, + "BusinessContactEmail", + businessContactEmail, + ParameterType.URLENCODED + ); + } + + if (businessContactPhone != null) { + Serializer.toString( + request, + "BusinessContactPhone", + businessContactPhone, + ParameterType.URLENCODED + ); + } + + if (editReason != null) { + Serializer.toString( + request, + "EditReason", + editReason, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationNumber != null) { + Serializer.toString( + request, + "BusinessRegistrationNumber", + businessRegistrationNumber, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationAuthority != null) { + Serializer.toString( + request, + "BusinessRegistrationAuthority", + businessRegistrationAuthority, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationCountry != null) { + Serializer.toString( + request, + "BusinessRegistrationCountry", + businessRegistrationCountry, + ParameterType.URLENCODED + ); + } + + if (businessType != null) { + Serializer.toString( + request, + "BusinessType", + businessType, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationPhoneNumber != null) { + Serializer.toString( + request, + "BusinessRegistrationPhoneNumber", + businessRegistrationPhoneNumber, + ParameterType.URLENCODED + ); + } + + if (doingBusinessAs != null) { + Serializer.toString( + request, + "DoingBusinessAs", + doingBusinessAs, + ParameterType.URLENCODED + ); + } + + if (optInConfirmationMessage != null) { + Serializer.toString( + request, + "OptInConfirmationMessage", + optInConfirmationMessage, + ParameterType.URLENCODED + ); + } + + if (helpMessageSample != null) { + Serializer.toString( + request, + "HelpMessageSample", + helpMessageSample, + ParameterType.URLENCODED + ); + } + + if (privacyPolicyUrl != null) { + Serializer.toString( + request, + "PrivacyPolicyUrl", + privacyPolicyUrl, + ParameterType.URLENCODED + ); + } + + if (termsAndConditionsUrl != null) { + Serializer.toString( + request, + "TermsAndConditionsUrl", + termsAndConditionsUrl, + ParameterType.URLENCODED + ); + } + + if (ageGatedContent != null) { + Serializer.toString( + request, + "AgeGatedContent", + ageGatedContent, + ParameterType.URLENCODED + ); + } + + if (optInKeywords != null) { + for (String param : optInKeywords) { + Serializer.toString( + request, + "OptInKeywords", + param, + ParameterType.URLENCODED + ); + } + } + + if (vettingProvider != null) { + Serializer.toString( + request, + "VettingProvider", + vettingProvider, + ParameterType.URLENCODED + ); + } + + if (vettingId != null) { + Serializer.toString( + request, + "VettingId", + vettingId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/Usecase.java b/src/main/java/com/twilio/rest/messaging/v1/Usecase.java new file mode 100644 index 0000000000..d2a173be6e --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/Usecase.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Usecase extends Resource { + + public static UsecaseFetcher fetcher() { + return new UsecaseFetcher(); + } + + /** + * Converts a JSON String into a Usecase object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Usecase object represented by the provided JSON + */ + public static Usecase fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Usecase.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Usecase object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Usecase object represented by the provided JSON + */ + public static Usecase fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Usecase.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List usecases; + + @JsonCreator + private Usecase(@JsonProperty("usecases") final List usecases) { + this.usecases = usecases; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Usecase other = (Usecase) o; + return (Objects.equals(usecases, other.usecases)); + } + + @Override + public int hashCode() { + return Objects.hash(usecases); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/UsecaseFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/UsecaseFetcher.java new file mode 100644 index 0000000000..a28b3ffd6d --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/UsecaseFetcher.java @@ -0,0 +1,87 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UsecaseFetcher extends Fetcher { + + public UsecaseFetcher() {} + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/Usecases"; + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Usecase fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Usecase fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Usecase.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Usecase content = Usecase.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtp.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtp.java new file mode 100644 index 0000000000..1a7f88d825 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtp.java @@ -0,0 +1,140 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.brandregistration; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BrandRegistrationOtp extends Resource { + + public static BrandRegistrationOtpCreator creator( + final String pathBrandRegistrationSid + ) { + return new BrandRegistrationOtpCreator(pathBrandRegistrationSid); + } + + /** + * Converts a JSON String into a BrandRegistrationOtp object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BrandRegistrationOtp object represented by the provided JSON + */ + public static BrandRegistrationOtp fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BrandRegistrationOtp.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BrandRegistrationOtp object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BrandRegistrationOtp object represented by the provided JSON + */ + public static BrandRegistrationOtp fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BrandRegistrationOtp.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String brandRegistrationSid; + + @JsonCreator + private BrandRegistrationOtp( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "brand_registration_sid" + ) final String brandRegistrationSid + ) { + this.accountSid = accountSid; + this.brandRegistrationSid = brandRegistrationSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BrandRegistrationOtp other = (BrandRegistrationOtp) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(brandRegistrationSid, other.brandRegistrationSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, brandRegistrationSid); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtpCreator.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtpCreator.java new file mode 100644 index 0000000000..d8b4991359 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandRegistrationOtpCreator.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.brandregistration; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BrandRegistrationOtpCreator extends Creator { + + private String pathBrandRegistrationSid; + + public BrandRegistrationOtpCreator(final String pathBrandRegistrationSid) { + this.pathBrandRegistrationSid = pathBrandRegistrationSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/a2p/BrandRegistrations/{BrandRegistrationSid}/SmsOtp"; + + path = + path.replace( + "{" + "BrandRegistrationSid" + "}", + this.pathBrandRegistrationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BrandRegistrationOtp creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BrandRegistrationOtp create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BrandRegistrationOtp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BrandRegistrationOtp content = BrandRegistrationOtp.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVetting.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVetting.java new file mode 100644 index 0000000000..4a94147ca0 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVetting.java @@ -0,0 +1,248 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.brandregistration; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BrandVetting extends Resource { + + public static BrandVettingCreator creator( + final String pathBrandSid, + final BrandVetting.VettingProvider vettingProvider + ) { + return new BrandVettingCreator(pathBrandSid, vettingProvider); + } + + public static BrandVettingFetcher fetcher( + final String pathBrandSid, + final String pathBrandVettingSid + ) { + return new BrandVettingFetcher(pathBrandSid, pathBrandVettingSid); + } + + public static BrandVettingReader reader(final String pathBrandSid) { + return new BrandVettingReader(pathBrandSid); + } + + public enum VettingProvider { + CAMPAIGN_VERIFY("campaign-verify"), + AEGIS("aegis"); + + private final String value; + + private VettingProvider(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static VettingProvider forValue(final String value) { + return Promoter.enumFromString(value, VettingProvider.values()); + } + } + + /** + * Converts a JSON String into a BrandVetting object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BrandVetting object represented by the provided JSON + */ + public static BrandVetting fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BrandVetting.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BrandVetting object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BrandVetting object represented by the provided JSON + */ + public static BrandVetting fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BrandVetting.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String brandSid; + + @Getter + private final String brandVettingSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final URI url; + + @Getter + private final String vettingClass; + + @Getter + private final String vettingId; + + @Getter + private final BrandVetting.VettingProvider vettingProvider; + + @Getter + private final String vettingStatus; + + @JsonCreator + private BrandVetting( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("brand_sid") final String brandSid, + @JsonProperty("brand_vetting_sid") final String brandVettingSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("url") final URI url, + @JsonProperty("vetting_class") final String vettingClass, + @JsonProperty("vetting_id") final String vettingId, + @JsonProperty( + "vetting_provider" + ) final BrandVetting.VettingProvider vettingProvider, + @JsonProperty("vetting_status") final String vettingStatus + ) { + this.accountSid = accountSid; + this.brandSid = brandSid; + this.brandVettingSid = brandVettingSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.url = url; + this.vettingClass = vettingClass; + this.vettingId = vettingId; + this.vettingProvider = vettingProvider; + this.vettingStatus = vettingStatus; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BrandVetting other = (BrandVetting) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(brandSid, other.brandSid) && + Objects.equals(brandVettingSid, other.brandVettingSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(url, other.url) && + Objects.equals(vettingClass, other.vettingClass) && + Objects.equals(vettingId, other.vettingId) && + Objects.equals(vettingProvider, other.vettingProvider) && + Objects.equals(vettingStatus, other.vettingStatus) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + brandSid, + brandVettingSid, + dateCreated, + dateUpdated, + url, + vettingClass, + vettingId, + vettingProvider, + vettingStatus + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingCreator.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingCreator.java new file mode 100644 index 0000000000..b157a9a78d --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingCreator.java @@ -0,0 +1,140 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.brandregistration; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BrandVettingCreator extends Creator { + + private String pathBrandSid; + private BrandVetting.VettingProvider vettingProvider; + private String vettingId; + + public BrandVettingCreator( + final String pathBrandSid, + final BrandVetting.VettingProvider vettingProvider + ) { + this.pathBrandSid = pathBrandSid; + this.vettingProvider = vettingProvider; + } + + public BrandVettingCreator setVettingProvider( + final BrandVetting.VettingProvider vettingProvider + ) { + this.vettingProvider = vettingProvider; + return this; + } + + public BrandVettingCreator setVettingId(final String vettingId) { + this.vettingId = vettingId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings"; + + path = + path.replace("{" + "BrandSid" + "}", this.pathBrandSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BrandVetting creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BrandVetting create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BrandVetting.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BrandVetting content = BrandVetting.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (vettingProvider != null) { + Serializer.toString( + request, + "VettingProvider", + vettingProvider, + ParameterType.URLENCODED + ); + } + + if (vettingId != null) { + Serializer.toString( + request, + "VettingId", + vettingId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingFetcher.java new file mode 100644 index 0000000000..6a8ba1830b --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingFetcher.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.brandregistration; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BrandVettingFetcher extends Fetcher { + + private String pathBrandSid; + private String pathBrandVettingSid; + + public BrandVettingFetcher( + final String pathBrandSid, + final String pathBrandVettingSid + ) { + this.pathBrandSid = pathBrandSid; + this.pathBrandVettingSid = pathBrandVettingSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings/{BrandVettingSid}"; + + path = + path.replace("{" + "BrandSid" + "}", this.pathBrandSid.toString()); + path = + path.replace( + "{" + "BrandVettingSid" + "}", + this.pathBrandVettingSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BrandVetting fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BrandVetting fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return BrandVetting.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BrandVetting content = BrandVetting.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingReader.java b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingReader.java new file mode 100644 index 0000000000..6f4f0a609e --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/brandregistration/BrandVettingReader.java @@ -0,0 +1,210 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.brandregistration; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BrandVettingReader extends Reader { + + private String pathBrandSid; + private BrandVetting.VettingProvider vettingProvider; + + public BrandVettingReader(final String pathBrandSid) { + this.pathBrandSid = pathBrandSid; + } + + public BrandVettingReader setVettingProvider( + final BrandVetting.VettingProvider vettingProvider + ) { + this.vettingProvider = vettingProvider; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "data", + response.getContent(), + BrandVetting.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/a2p/BrandRegistrations/{BrandSid}/Vettings"; + + path = + path.replace("{" + "BrandSid" + "}", this.pathBrandSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "data", + response.getContent(), + BrandVetting.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "BrandVetting read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "data", + response.getContent(), + BrandVetting.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (vettingProvider != null) { + Serializer.toString( + request, + "VettingProvider", + vettingProvider, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSender.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSender.java index 3511bc839e..2d37395dbe 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSender.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSender.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; @@ -11,92 +18,67 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AlphaSender extends Resource { - private static final long serialVersionUID = 107541920381976L; - /** - * Create a AlphaSenderCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param alphaSender An Alphanumeric Sender ID string, up to 11 characters. - * @return AlphaSenderCreator capable of executing the create - */ - public static AlphaSenderCreator creator(final String pathServiceSid, - final String alphaSender) { + public static AlphaSenderCreator creator( + final String pathServiceSid, + final String alphaSender + ) { return new AlphaSenderCreator(pathServiceSid, alphaSender); } - /** - * Create a AlphaSenderReader to execute read. - * - * @param pathServiceSid The service_sid - * @return AlphaSenderReader capable of executing the read - */ - public static AlphaSenderReader reader(final String pathServiceSid) { - return new AlphaSenderReader(pathServiceSid); + public static AlphaSenderDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new AlphaSenderDeleter(pathServiceSid, pathSid); } - /** - * Create a AlphaSenderFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return AlphaSenderFetcher capable of executing the fetch - */ - public static AlphaSenderFetcher fetcher(final String pathServiceSid, - final String pathSid) { + public static AlphaSenderFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { return new AlphaSenderFetcher(pathServiceSid, pathSid); } - /** - * Create a AlphaSenderDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return AlphaSenderDeleter capable of executing the delete - */ - public static AlphaSenderDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new AlphaSenderDeleter(pathServiceSid, pathSid); + public static AlphaSenderReader reader(final String pathServiceSid) { + return new AlphaSenderReader(pathServiceSid); } /** - * Converts a JSON String into a AlphaSender object using the provided - * ObjectMapper. - * + * Converts a JSON String into a AlphaSender object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AlphaSender object represented by the provided JSON */ - public static AlphaSender fromJson(final String json, final ObjectMapper objectMapper) { + public static AlphaSender fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AlphaSender.class); @@ -110,12 +92,15 @@ public static AlphaSender fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a AlphaSender object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AlphaSender object represented by the provided JSON */ - public static AlphaSender fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AlphaSender fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AlphaSender.class); @@ -126,114 +111,71 @@ public static AlphaSender fromJson(final InputStream json, final ObjectMapper ob } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String alphaSender; - private final List> capabilities; - private final URI url; - - @JsonCreator - private AlphaSender(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("alpha_sender") - final String alphaSender, - @JsonProperty("capabilities") - final List> capabilities, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.alphaSender = alphaSender; - this.capabilities = capabilities; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The 34 character unique sid of the Alpha Sender ID.. - * - * @return The 34 character unique sid of the Alpha Sender ID. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The 34 character unique sid of the Account.. - * - * @return The 34 character unique sid of the Account. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String alphaSender; - /** - * Returns The The 34 character unique sid of the Messaging Service.. - * - * @return The 34 character unique sid of the Messaging Service. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final List capabilities; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The An Alphanumeric Sender ID string, up to 11 characters.. - * - * @return An Alphanumeric Sender ID string, up to 11 characters. - */ - public final String getAlphaSender() { - return this.alphaSender; - } + @Getter + private final String serviceSid; - /** - * Returns The An array of values that indicate whether the number can receive - * calls or messages.. - * - * @return An array of values that indicate whether the number can receive - * calls or messages. - */ - public final List> getCapabilities() { - return this.capabilities; - } + @Getter + private final String sid; - /** - * Returns The The absolute URL for this resource.. - * - * @return The absolute URL for this resource. - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private AlphaSender( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("alpha_sender") final String alphaSender, + @JsonProperty("capabilities") final List capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.alphaSender = alphaSender; + this.capabilities = capabilities; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -247,40 +189,29 @@ public boolean equals(final Object o) { } AlphaSender other = (AlphaSender) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(alphaSender, other.alphaSender) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(alphaSender, other.alphaSender) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - alphaSender, - capabilities, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("alphaSender", alphaSender) - .add("capabilities", capabilities) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + alphaSender, + capabilities, + dateCreated, + dateUpdated, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderCreator.java index 979735cc7f..720c663494 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,74 +27,100 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class AlphaSenderCreator extends Creator { - private final String pathServiceSid; - private final String alphaSender; - /** - * Construct a new AlphaSenderCreator. - * - * @param pathServiceSid The service_sid - * @param alphaSender An Alphanumeric Sender ID string, up to 11 characters. - */ - public AlphaSenderCreator(final String pathServiceSid, - final String alphaSender) { + private String pathServiceSid; + private String alphaSender; + + public AlphaSenderCreator( + final String pathServiceSid, + final String alphaSender + ) { this.pathServiceSid = pathServiceSid; this.alphaSender = alphaSender; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created AlphaSender - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AlphaSender create(final TwilioRestClient client) { + public AlphaSenderCreator setAlphaSender(final String alphaSender) { + this.alphaSender = alphaSender; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/AlphaSenders"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/AlphaSenders", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AlphaSender creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AlphaSender creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return AlphaSender.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public AlphaSender create(final TwilioRestClient client) { + Response response = makeRequest(client); + return AlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AlphaSender content = AlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (alphaSender != null) { - request.addPostParam("AlphaSender", alphaSender); + Serializer.toString( + request, + "AlphaSender", + alphaSender, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderDeleter.java index 4ce4076ed8..ccaf935116 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,84 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class AlphaSenderDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new AlphaSenderDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public AlphaSenderDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public AlphaSenderDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/AlphaSenders/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/AlphaSenders/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AlphaSender delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AlphaSender delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderFetcher.java index c469218211..e094ae439e 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class AlphaSenderFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new AlphaSenderFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public AlphaSenderFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public AlphaSenderFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AlphaSender - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AlphaSender fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/AlphaSenders/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/AlphaSenders/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AlphaSender fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AlphaSender fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public AlphaSender fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return AlphaSender.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AlphaSender content = AlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderReader.java index b674619804..09239f7f93 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/AlphaSenderReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; @@ -10,163 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class AlphaSenderReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new AlphaSenderReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public AlphaSenderReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AlphaSender ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AlphaSenderReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AlphaSender ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "alpha_senders", + response.getContent(), + AlphaSender.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/AlphaSenders"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/AlphaSenders", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AlphaSender ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "alpha_senders", + response.getContent(), + AlphaSender.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AlphaSender read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "alpha_senders", + response.getContent(), + AlphaSender.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.MESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.MESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AlphaSender Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AlphaSender read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "alpha_senders", - response.getContent(), - AlphaSender.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSender.java b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSender.java new file mode 100644 index 0000000000..6b72af8376 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSender.java @@ -0,0 +1,225 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ChannelSender extends Resource { + + public static ChannelSenderCreator creator( + final String pathMessagingServiceSid, + final String sid + ) { + return new ChannelSenderCreator(pathMessagingServiceSid, sid); + } + + public static ChannelSenderDeleter deleter( + final String pathMessagingServiceSid, + final String pathSid + ) { + return new ChannelSenderDeleter(pathMessagingServiceSid, pathSid); + } + + public static ChannelSenderFetcher fetcher( + final String pathMessagingServiceSid, + final String pathSid + ) { + return new ChannelSenderFetcher(pathMessagingServiceSid, pathSid); + } + + public static ChannelSenderReader reader( + final String pathMessagingServiceSid + ) { + return new ChannelSenderReader(pathMessagingServiceSid); + } + + /** + * Converts a JSON String into a ChannelSender object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ChannelSender object represented by the provided JSON + */ + public static ChannelSender fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ChannelSender.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ChannelSender object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ChannelSender object represented by the provided JSON + */ + public static ChannelSender fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ChannelSender.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String countryCode; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String messagingServiceSid; + + @Getter + private final String sender; + + @Getter + private final String senderType; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private ChannelSender( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sender") final String sender, + @JsonProperty("sender_type") final String senderType, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.countryCode = countryCode; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.messagingServiceSid = messagingServiceSid; + this.sender = sender; + this.senderType = senderType; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ChannelSender other = (ChannelSender) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sender, other.sender) && + Objects.equals(senderType, other.senderType) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + countryCode, + dateCreated, + dateUpdated, + messagingServiceSid, + sender, + senderType, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderCreator.java new file mode 100644 index 0000000000..922b569805 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelSenderCreator extends Creator { + + private String pathMessagingServiceSid; + private String sid; + + public ChannelSenderCreator( + final String pathMessagingServiceSid, + final String sid + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + this.sid = sid; + } + + public ChannelSenderCreator setSid(final String sid) { + this.sid = sid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{MessagingServiceSid}/ChannelSenders"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ChannelSender creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ChannelSender create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ChannelSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ChannelSender content = ChannelSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (sid != null) { + Serializer.toString(request, "Sid", sid, ParameterType.URLENCODED); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderDeleter.java new file mode 100644 index 0000000000..c93aca6fff --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ChannelSenderDeleter extends Deleter { + + private String pathMessagingServiceSid; + private String pathSid; + + public ChannelSenderDeleter( + final String pathMessagingServiceSid, + final String pathSid + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{MessagingServiceSid}/ChannelSenders/{Sid}"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ChannelSender delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderFetcher.java new file mode 100644 index 0000000000..04555bf736 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelSenderFetcher extends Fetcher { + + private String pathMessagingServiceSid; + private String pathSid; + + public ChannelSenderFetcher( + final String pathMessagingServiceSid, + final String pathSid + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{MessagingServiceSid}/ChannelSenders/{Sid}"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ChannelSender fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ChannelSender fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ChannelSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ChannelSender content = ChannelSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderReader.java new file mode 100644 index 0000000000..d0f882e923 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ChannelSenderReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelSenderReader extends Reader { + + private String pathMessagingServiceSid; + private Long pageSize; + + public ChannelSenderReader(final String pathMessagingServiceSid) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + } + + public ChannelSenderReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "senders", + response.getContent(), + ChannelSender.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{MessagingServiceSid}/ChannelSenders"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "senders", + response.getContent(), + ChannelSender.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ChannelSender read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "senders", + response.getContent(), + ChannelSender.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSender.java b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSender.java new file mode 100644 index 0000000000..922f9d7f01 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSender.java @@ -0,0 +1,226 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DestinationAlphaSender extends Resource { + + public static DestinationAlphaSenderCreator creator( + final String pathServiceSid, + final String alphaSender + ) { + return new DestinationAlphaSenderCreator(pathServiceSid, alphaSender); + } + + public static DestinationAlphaSenderDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new DestinationAlphaSenderDeleter(pathServiceSid, pathSid); + } + + public static DestinationAlphaSenderFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new DestinationAlphaSenderFetcher(pathServiceSid, pathSid); + } + + public static DestinationAlphaSenderReader reader( + final String pathServiceSid + ) { + return new DestinationAlphaSenderReader(pathServiceSid); + } + + /** + * Converts a JSON String into a DestinationAlphaSender object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DestinationAlphaSender object represented by the provided JSON + */ + public static DestinationAlphaSender fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DestinationAlphaSender.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DestinationAlphaSender object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DestinationAlphaSender object represented by the provided JSON + */ + public static DestinationAlphaSender fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DestinationAlphaSender.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String alphaSender; + + @Getter + private final List capabilities; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String isoCountryCode; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private DestinationAlphaSender( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("alpha_sender") final String alphaSender, + @JsonProperty("capabilities") final List capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("iso_country_code") final String isoCountryCode, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.alphaSender = alphaSender; + this.capabilities = capabilities; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.isoCountryCode = isoCountryCode; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DestinationAlphaSender other = (DestinationAlphaSender) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(alphaSender, other.alphaSender) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(isoCountryCode, other.isoCountryCode) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + alphaSender, + capabilities, + dateCreated, + dateUpdated, + isoCountryCode, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderCreator.java new file mode 100644 index 0000000000..a1ced44d72 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderCreator.java @@ -0,0 +1,146 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DestinationAlphaSenderCreator + extends Creator { + + private String pathServiceSid; + private String alphaSender; + private String isoCountryCode; + + public DestinationAlphaSenderCreator( + final String pathServiceSid, + final String alphaSender + ) { + this.pathServiceSid = pathServiceSid; + this.alphaSender = alphaSender; + } + + public DestinationAlphaSenderCreator setAlphaSender( + final String alphaSender + ) { + this.alphaSender = alphaSender; + return this; + } + + public DestinationAlphaSenderCreator setIsoCountryCode( + final String isoCountryCode + ) { + this.isoCountryCode = isoCountryCode; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/DestinationAlphaSenders"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DestinationAlphaSender creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DestinationAlphaSender create(final TwilioRestClient client) { + Response response = makeRequest(client); + return DestinationAlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DestinationAlphaSender content = DestinationAlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (alphaSender != null) { + Serializer.toString( + request, + "AlphaSender", + alphaSender, + ParameterType.URLENCODED + ); + } + + if (isoCountryCode != null) { + Serializer.toString( + request, + "IsoCountryCode", + isoCountryCode, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderDeleter.java new file mode 100644 index 0000000000..79295eb521 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderDeleter.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class DestinationAlphaSenderDeleter + extends Deleter { + + private String pathServiceSid; + private String pathSid; + + public DestinationAlphaSenderDeleter( + final String pathServiceSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/DestinationAlphaSenders/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DestinationAlphaSender delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderFetcher.java new file mode 100644 index 0000000000..e9d05421d8 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderFetcher.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DestinationAlphaSenderFetcher + extends Fetcher { + + private String pathServiceSid; + private String pathSid; + + public DestinationAlphaSenderFetcher( + final String pathServiceSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/DestinationAlphaSenders/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DestinationAlphaSender fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DestinationAlphaSender fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DestinationAlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DestinationAlphaSender content = DestinationAlphaSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderReader.java new file mode 100644 index 0000000000..303a2224cf --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/DestinationAlphaSenderReader.java @@ -0,0 +1,233 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DestinationAlphaSenderReader + extends Reader { + + private String pathServiceSid; + private String isoCountryCode; + private Long pageSize; + + public DestinationAlphaSenderReader(final String pathServiceSid) { + this.pathServiceSid = pathServiceSid; + } + + public DestinationAlphaSenderReader setIsoCountryCode( + final String isoCountryCode + ) { + this.isoCountryCode = isoCountryCode; + return this; + } + + public DestinationAlphaSenderReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "alpha_senders", + response.getContent(), + DestinationAlphaSender.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/DestinationAlphaSenders"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "alpha_senders", + response.getContent(), + DestinationAlphaSender.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "DestinationAlphaSender read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "alpha_senders", + response.getContent(), + DestinationAlphaSender.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (isoCountryCode != null) { + Serializer.toString( + request, + "IsoCountryCode", + isoCountryCode, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumber.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumber.java index 97ea654f6e..bb7cb24c31 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumber.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; @@ -11,92 +18,67 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class PhoneNumber extends Resource { - private static final long serialVersionUID = 177917350059297L; - /** - * Create a PhoneNumberCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param phoneNumberSid Phone Number SID for the Phone Number being added to - * the Service. - * @return PhoneNumberCreator capable of executing the create - */ - public static PhoneNumberCreator creator(final String pathServiceSid, - final String phoneNumberSid) { + public static PhoneNumberCreator creator( + final String pathServiceSid, + final String phoneNumberSid + ) { return new PhoneNumberCreator(pathServiceSid, phoneNumberSid); } - /** - * Create a PhoneNumberDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return PhoneNumberDeleter capable of executing the delete - */ - public static PhoneNumberDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static PhoneNumberDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new PhoneNumberDeleter(pathServiceSid, pathSid); } - /** - * Create a PhoneNumberReader to execute read. - * - * @param pathServiceSid The service_sid - * @return PhoneNumberReader capable of executing the read - */ - public static PhoneNumberReader reader(final String pathServiceSid) { - return new PhoneNumberReader(pathServiceSid); + public static PhoneNumberFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new PhoneNumberFetcher(pathServiceSid, pathSid); } - /** - * Create a PhoneNumberFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return PhoneNumberFetcher capable of executing the fetch - */ - public static PhoneNumberFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new PhoneNumberFetcher(pathServiceSid, pathSid); + public static PhoneNumberReader reader(final String pathServiceSid) { + return new PhoneNumberReader(pathServiceSid); } /** - * Converts a JSON String into a PhoneNumber object using the provided - * ObjectMapper. - * + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return PhoneNumber object represented by the provided JSON */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -110,12 +92,15 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a PhoneNumber object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return PhoneNumber object represented by the provided JSON */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -126,127 +111,78 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String countryCode; - private final List capabilities; - private final URI url; - - @JsonCreator - private PhoneNumber(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("country_code") - final String countryCode, - @JsonProperty("capabilities") - final List capabilities, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.phoneNumber = phoneNumber; - this.countryCode = countryCode; - this.capabilities = capabilities; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The 34 character unique sid of the Phone Number.. - * - * @return The 34 character unique sid of the Phone Number. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The 34 character unique sid of the Account.. - * - * @return The 34 character unique sid of the Account. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final List capabilities; - /** - * Returns The The 34 character unique sid of the Service.. - * - * @return The 34 character unique sid of the Service. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String countryCode; - /** - * Returns The The date that this resource was created.. - * - * @return The date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The E.. - * - * @return The E. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The 2 character ISO Country Code of the number.. - * - * @return The 2 character ISO Country Code of the number. - */ - public final String getCountryCode() { - return this.countryCode; - } + @Getter + private final String serviceSid; - /** - * Returns The Any array of values that indicate whether the number can receive - * calls or messages.. - * - * @return Any array of values that indicate whether the number can receive - * calls or messages. - */ - public final List getCapabilities() { - return this.capabilities; - } + @Getter + private final String sid; - /** - * Returns The The absolute URL for this resource.. - * - * @return The absolute URL for this resource. - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private PhoneNumber( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("capabilities") final List capabilities, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.capabilities = capabilities; + this.countryCode = countryCode; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.phoneNumber = phoneNumber; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -260,43 +196,31 @@ public boolean equals(final Object o) { } PhoneNumber other = (PhoneNumber) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(countryCode, other.countryCode) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - phoneNumber, - countryCode, - capabilities, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("phoneNumber", phoneNumber) - .add("countryCode", countryCode) - .add("capabilities", capabilities) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + capabilities, + countryCode, + dateCreated, + dateUpdated, + phoneNumber, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberCreator.java index 9faca9082e..6f00ae589e 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +27,100 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class PhoneNumberCreator extends Creator { - private final String pathServiceSid; - private final String phoneNumberSid; - /** - * Construct a new PhoneNumberCreator. - * - * @param pathServiceSid The service_sid - * @param phoneNumberSid Phone Number SID for the Phone Number being added to - * the Service. - */ - public PhoneNumberCreator(final String pathServiceSid, - final String phoneNumberSid) { + private String pathServiceSid; + private String phoneNumberSid; + + public PhoneNumberCreator( + final String pathServiceSid, + final String phoneNumberSid + ) { this.pathServiceSid = pathServiceSid; this.phoneNumberSid = phoneNumberSid; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber create(final TwilioRestClient client) { + public PhoneNumberCreator setPhoneNumberSid(final String phoneNumberSid) { + this.phoneNumberSid = phoneNumberSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/PhoneNumbers", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public PhoneNumber create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (phoneNumberSid != null) { - request.addPostParam("PhoneNumberSid", phoneNumberSid); + Serializer.toString( + request, + "PhoneNumberSid", + phoneNumberSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberDeleter.java index 0c62ec47fb..a0ccce7a4f 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,84 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class PhoneNumberDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new PhoneNumberDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public PhoneNumberDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public PhoneNumberDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/PhoneNumbers/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberFetcher.java index 7d6a5afb32..c893c069d4 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class PhoneNumberFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new PhoneNumberFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public PhoneNumberFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public PhoneNumberFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/PhoneNumbers/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public PhoneNumber fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberReader.java index 9888f5ff69..bbd03e1951 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/PhoneNumberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; @@ -10,163 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class PhoneNumberReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new PhoneNumberReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public PhoneNumberReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public PhoneNumberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/PhoneNumbers", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.MESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.MESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of PhoneNumber Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("PhoneNumber read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "phone_numbers", - response.getContent(), - PhoneNumber.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCode.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCode.java index ab267b25b8..d29d009436 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCode.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCode.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; @@ -11,93 +18,67 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class ShortCode extends Resource { - private static final long serialVersionUID = 158453184063477L; - /** - * Create a ShortCodeCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param shortCodeSid ShortCodeSid for the Shortcode being added to the - * Service. - * @return ShortCodeCreator capable of executing the create - */ - public static ShortCodeCreator creator(final String pathServiceSid, - final String shortCodeSid) { + public static ShortCodeCreator creator( + final String pathServiceSid, + final String shortCodeSid + ) { return new ShortCodeCreator(pathServiceSid, shortCodeSid); } - /** - * Create a ShortCodeDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ShortCodeDeleter capable of executing the delete - */ - public static ShortCodeDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static ShortCodeDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new ShortCodeDeleter(pathServiceSid, pathSid); } - /** - * Create a ShortCodeReader to execute read. - * - * @param pathServiceSid The service_sid - * @return ShortCodeReader capable of executing the read - */ - public static ShortCodeReader reader(final String pathServiceSid) { - return new ShortCodeReader(pathServiceSid); + public static ShortCodeFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new ShortCodeFetcher(pathServiceSid, pathSid); } - /** - * Create a ShortCodeFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return ShortCodeFetcher capable of executing the fetch - */ - public static ShortCodeFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new ShortCodeFetcher(pathServiceSid, pathSid); + public static ShortCodeReader reader(final String pathServiceSid) { + return new ShortCodeReader(pathServiceSid); } /** - * Converts a JSON String into a ShortCode object using the provided - * ObjectMapper. - * + * Converts a JSON String into a ShortCode object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return ShortCode object represented by the provided JSON */ - public static ShortCode fromJson(final String json, final ObjectMapper objectMapper) { + public static ShortCode fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -111,12 +92,15 @@ public static ShortCode fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a ShortCode object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return ShortCode object represented by the provided JSON */ - public static ShortCode fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static ShortCode fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, ShortCode.class); @@ -127,127 +111,76 @@ public static ShortCode fromJson(final InputStream json, final ObjectMapper obje } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String shortCode; - private final String countryCode; - private final List> capabilities; - private final URI url; - - @JsonCreator - private ShortCode(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("short_code") - final String shortCode, - @JsonProperty("country_code") - final String countryCode, - @JsonProperty("capabilities") - final List> capabilities, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.shortCode = shortCode; - this.countryCode = countryCode; - this.capabilities = capabilities; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The 34 character unique sid of the Short Code. - * - * @return The 34 character unique sid of the Short Code - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The 34 character unique sid of the Account.. - * - * @return The 34 character unique sid of the Account. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final List capabilities; - /** - * Returns The The 34 character unique sid of the Service.. - * - * @return The 34 character unique sid of the Service. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String countryCode; - /** - * Returns The he date that this resource was created.. - * - * @return he date that this resource was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date that this resource was last updated.. - * - * @return The date that this resource was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The E.164 format of the short code.. - * - * @return The E.164 format of the short code. - */ - public final String getShortCode() { - return this.shortCode; - } + @Getter + private final String serviceSid; - /** - * Returns The The 2 character ISO Country Code of the number.. - * - * @return The 2 character ISO Country Code of the number. - */ - public final String getCountryCode() { - return this.countryCode; - } + @Getter + private final String shortCode; - /** - * Returns The Any array of values that indicate whether the number can receive - * calls or messages.. - * - * @return Any array of values that indicate whether the number can receive - * calls or messages. - */ - public final List> getCapabilities() { - return this.capabilities; - } + @Getter + private final String sid; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private ShortCode( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("capabilities") final List capabilities, + @JsonProperty("country_code") final String countryCode, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("short_code") final String shortCode, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.capabilities = capabilities; + this.countryCode = countryCode; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.serviceSid = serviceSid; + this.shortCode = shortCode; + this.sid = sid; + this.url = url; } @Override @@ -261,43 +194,31 @@ public boolean equals(final Object o) { } ShortCode other = (ShortCode) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(shortCode, other.shortCode) && - Objects.equals(countryCode, other.countryCode) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(countryCode, other.countryCode) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(shortCode, other.shortCode) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - shortCode, - countryCode, - capabilities, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("shortCode", shortCode) - .add("countryCode", countryCode) - .add("capabilities", capabilities) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + capabilities, + countryCode, + dateCreated, + dateUpdated, + serviceSid, + shortCode, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeCreator.java index e9ba6106d2..44067d3f9d 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeCreator.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,75 +27,100 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ShortCodeCreator extends Creator { - private final String pathServiceSid; - private final String shortCodeSid; - /** - * Construct a new ShortCodeCreator. - * - * @param pathServiceSid The service_sid - * @param shortCodeSid ShortCodeSid for the Shortcode being added to the - * Service. - */ - public ShortCodeCreator(final String pathServiceSid, - final String shortCodeSid) { + private String pathServiceSid; + private String shortCodeSid; + + public ShortCodeCreator( + final String pathServiceSid, + final String shortCodeSid + ) { this.pathServiceSid = pathServiceSid; this.shortCodeSid = shortCodeSid; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created ShortCode - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ShortCode create(final TwilioRestClient client) { + public ShortCodeCreator setShortCodeSid(final String shortCodeSid) { + this.shortCodeSid = shortCodeSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/ShortCodes"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/ShortCodes", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "ShortCode creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public ShortCode create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ShortCode content = ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (shortCodeSid != null) { - request.addPostParam("ShortCodeSid", shortCodeSid); + Serializer.toString( + request, + "ShortCodeSid", + shortCodeSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeDeleter.java index 56ff849ec9..f30634f2ba 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeDeleter.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ShortCodeDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ShortCodeDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ShortCodeDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public ShortCodeDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/ShortCodes/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/ShortCodes/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "ShortCode delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeFetcher.java index 6fac6cad92..140be854de 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeFetcher.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,80 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ShortCodeFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new ShortCodeFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public ShortCodeFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public ShortCodeFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched ShortCode - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ShortCode fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/ShortCodes/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/ShortCodes/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("ShortCode fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "ShortCode fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public ShortCode fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ShortCode content = ShortCode.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeReader.java index 1123d20c0d..224f51cc16 100644 --- a/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeReader.java +++ b/src/main/java/com/twilio/rest/messaging/v1/service/ShortCodeReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.messaging.v1.service; @@ -10,163 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ShortCodeReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new ShortCodeReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public ShortCodeReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ShortCodeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "short_codes", + response.getContent(), + ShortCode.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/ShortCodes"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.MESSAGING.toString(), - "/v1/Services/" + this.pathServiceSid + "/ShortCodes", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "short_codes", + response.getContent(), + ShortCode.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ShortCode read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "short_codes", + response.getContent(), + ShortCode.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.MESSAGING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.MESSAGING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of ShortCode Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "short_codes", - response.getContent(), - ShortCode.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPerson.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPerson.java new file mode 100644 index 0000000000..6c88d8b14d --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPerson.java @@ -0,0 +1,426 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class UsAppToPerson extends Resource { + + public static UsAppToPersonCreator creator( + final String pathMessagingServiceSid, + final String brandRegistrationSid, + final String description, + final String messageFlow, + final List messageSamples, + final String usAppToPersonUsecase, + final Boolean hasEmbeddedLinks, + final Boolean hasEmbeddedPhone + ) { + return new UsAppToPersonCreator( + pathMessagingServiceSid, + brandRegistrationSid, + description, + messageFlow, + messageSamples, + usAppToPersonUsecase, + hasEmbeddedLinks, + hasEmbeddedPhone + ); + } + + public static UsAppToPersonDeleter deleter( + final String pathMessagingServiceSid, + final String pathSid + ) { + return new UsAppToPersonDeleter(pathMessagingServiceSid, pathSid); + } + + public static UsAppToPersonFetcher fetcher( + final String pathMessagingServiceSid, + final String pathSid + ) { + return new UsAppToPersonFetcher(pathMessagingServiceSid, pathSid); + } + + public static UsAppToPersonReader reader( + final String pathMessagingServiceSid + ) { + return new UsAppToPersonReader(pathMessagingServiceSid); + } + + public static UsAppToPersonUpdater updater( + final String pathMessagingServiceSid, + final String pathSid, + final Boolean hasEmbeddedLinks, + final Boolean hasEmbeddedPhone, + final List messageSamples, + final String messageFlow, + final String description, + final Boolean ageGated, + final Boolean directLending + ) { + return new UsAppToPersonUpdater( + pathMessagingServiceSid, + pathSid, + hasEmbeddedLinks, + hasEmbeddedPhone, + messageSamples, + messageFlow, + description, + ageGated, + directLending + ); + } + + /** + * Converts a JSON String into a UsAppToPerson object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UsAppToPerson object represented by the provided JSON + */ + public static UsAppToPerson fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UsAppToPerson.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a UsAppToPerson object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UsAppToPerson object represented by the provided JSON + */ + public static UsAppToPerson fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UsAppToPerson.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean ageGated; + + @Getter + private final String brandRegistrationSid; + + @Getter + private final String campaignId; + + @Getter + private final String campaignStatus; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String description; + + @Getter + private final Boolean directLending; + + @Getter + private final List errors; + + @Getter + private final Boolean hasEmbeddedLinks; + + @Getter + private final Boolean hasEmbeddedPhone; + + @Getter + private final List helpKeywords; + + @Getter + private final String helpMessage; + + @Getter + private final Boolean isExternallyRegistered; + + @Getter + private final String messageFlow; + + @Getter + private final List messageSamples; + + @Getter + private final String messagingServiceSid; + + @Getter + private final Boolean mock; + + @Getter + private final List optInKeywords; + + @Getter + private final String optInMessage; + + @Getter + private final List optOutKeywords; + + @Getter + private final String optOutMessage; + + @Getter + private final URI privacyPolicyUrl; + + @Getter + private final Object rateLimits; + + @Getter + private final String sid; + + @Getter + private final Boolean subscriberOptIn; + + @Getter + private final URI termsAndConditionsUrl; + + @Getter + private final URI url; + + @Getter + private final String usAppToPersonUsecase; + + @JsonCreator + private UsAppToPerson( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("age_gated") final Boolean ageGated, + @JsonProperty( + "brand_registration_sid" + ) final String brandRegistrationSid, + @JsonProperty("campaign_id") final String campaignId, + @JsonProperty("campaign_status") final String campaignStatus, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("direct_lending") final Boolean directLending, + @JsonProperty("errors") final List errors, + @JsonProperty("has_embedded_links") final Boolean hasEmbeddedLinks, + @JsonProperty("has_embedded_phone") final Boolean hasEmbeddedPhone, + @JsonProperty("help_keywords") final List helpKeywords, + @JsonProperty("help_message") final String helpMessage, + @JsonProperty( + "is_externally_registered" + ) final Boolean isExternallyRegistered, + @JsonProperty("message_flow") final String messageFlow, + @JsonProperty("message_samples") final List messageSamples, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("mock") final Boolean mock, + @JsonProperty("opt_in_keywords") final List optInKeywords, + @JsonProperty("opt_in_message") final String optInMessage, + @JsonProperty("opt_out_keywords") final List optOutKeywords, + @JsonProperty("opt_out_message") final String optOutMessage, + @JsonProperty("privacy_policy_url") final URI privacyPolicyUrl, + @JsonProperty("rate_limits") final Object rateLimits, + @JsonProperty("sid") final String sid, + @JsonProperty("subscriber_opt_in") final Boolean subscriberOptIn, + @JsonProperty( + "terms_and_conditions_url" + ) final URI termsAndConditionsUrl, + @JsonProperty("url") final URI url, + @JsonProperty( + "us_app_to_person_usecase" + ) final String usAppToPersonUsecase + ) { + this.accountSid = accountSid; + this.ageGated = ageGated; + this.brandRegistrationSid = brandRegistrationSid; + this.campaignId = campaignId; + this.campaignStatus = campaignStatus; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.directLending = directLending; + this.errors = errors; + this.hasEmbeddedLinks = hasEmbeddedLinks; + this.hasEmbeddedPhone = hasEmbeddedPhone; + this.helpKeywords = helpKeywords; + this.helpMessage = helpMessage; + this.isExternallyRegistered = isExternallyRegistered; + this.messageFlow = messageFlow; + this.messageSamples = messageSamples; + this.messagingServiceSid = messagingServiceSid; + this.mock = mock; + this.optInKeywords = optInKeywords; + this.optInMessage = optInMessage; + this.optOutKeywords = optOutKeywords; + this.optOutMessage = optOutMessage; + this.privacyPolicyUrl = privacyPolicyUrl; + this.rateLimits = rateLimits; + this.sid = sid; + this.subscriberOptIn = subscriberOptIn; + this.termsAndConditionsUrl = termsAndConditionsUrl; + this.url = url; + this.usAppToPersonUsecase = usAppToPersonUsecase; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UsAppToPerson other = (UsAppToPerson) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(ageGated, other.ageGated) && + Objects.equals(brandRegistrationSid, other.brandRegistrationSid) && + Objects.equals(campaignId, other.campaignId) && + Objects.equals(campaignStatus, other.campaignStatus) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(directLending, other.directLending) && + Objects.equals(errors, other.errors) && + Objects.equals(hasEmbeddedLinks, other.hasEmbeddedLinks) && + Objects.equals(hasEmbeddedPhone, other.hasEmbeddedPhone) && + Objects.equals(helpKeywords, other.helpKeywords) && + Objects.equals(helpMessage, other.helpMessage) && + Objects.equals( + isExternallyRegistered, + other.isExternallyRegistered + ) && + Objects.equals(messageFlow, other.messageFlow) && + Objects.equals(messageSamples, other.messageSamples) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(mock, other.mock) && + Objects.equals(optInKeywords, other.optInKeywords) && + Objects.equals(optInMessage, other.optInMessage) && + Objects.equals(optOutKeywords, other.optOutKeywords) && + Objects.equals(optOutMessage, other.optOutMessage) && + Objects.equals(privacyPolicyUrl, other.privacyPolicyUrl) && + Objects.equals(rateLimits, other.rateLimits) && + Objects.equals(sid, other.sid) && + Objects.equals(subscriberOptIn, other.subscriberOptIn) && + Objects.equals( + termsAndConditionsUrl, + other.termsAndConditionsUrl + ) && + Objects.equals(url, other.url) && + Objects.equals(usAppToPersonUsecase, other.usAppToPersonUsecase) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + ageGated, + brandRegistrationSid, + campaignId, + campaignStatus, + dateCreated, + dateUpdated, + description, + directLending, + errors, + hasEmbeddedLinks, + hasEmbeddedPhone, + helpKeywords, + helpMessage, + isExternallyRegistered, + messageFlow, + messageSamples, + messagingServiceSid, + mock, + optInKeywords, + optInMessage, + optOutKeywords, + optOutMessage, + privacyPolicyUrl, + rateLimits, + sid, + subscriberOptIn, + termsAndConditionsUrl, + url, + usAppToPersonUsecase + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonCreator.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonCreator.java new file mode 100644 index 0000000000..6427cc670b --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonCreator.java @@ -0,0 +1,476 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; +import java.util.List; + +public class UsAppToPersonCreator extends Creator { + + private String pathMessagingServiceSid; + private String xTwilioApiVersion; + private String brandRegistrationSid; + private String description; + private String messageFlow; + private List messageSamples; + private String usAppToPersonUsecase; + private Boolean hasEmbeddedLinks; + private Boolean hasEmbeddedPhone; + private String optInMessage; + private String optOutMessage; + private String helpMessage; + private List optInKeywords; + private List optOutKeywords; + private List helpKeywords; + private Boolean subscriberOptIn; + private Boolean ageGated; + private Boolean directLending; + private URI privacyPolicyUrl; + private URI termsAndConditionsUrl; + + public UsAppToPersonCreator( + final String pathMessagingServiceSid, + final String brandRegistrationSid, + final String description, + final String messageFlow, + final List messageSamples, + final String usAppToPersonUsecase, + final Boolean hasEmbeddedLinks, + final Boolean hasEmbeddedPhone + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + this.brandRegistrationSid = brandRegistrationSid; + this.description = description; + this.messageFlow = messageFlow; + this.messageSamples = messageSamples; + this.usAppToPersonUsecase = usAppToPersonUsecase; + this.hasEmbeddedLinks = hasEmbeddedLinks; + this.hasEmbeddedPhone = hasEmbeddedPhone; + } + + public UsAppToPersonCreator setBrandRegistrationSid( + final String brandRegistrationSid + ) { + this.brandRegistrationSid = brandRegistrationSid; + return this; + } + + public UsAppToPersonCreator setDescription(final String description) { + this.description = description; + return this; + } + + public UsAppToPersonCreator setMessageFlow(final String messageFlow) { + this.messageFlow = messageFlow; + return this; + } + + public UsAppToPersonCreator setMessageSamples( + final List messageSamples + ) { + this.messageSamples = messageSamples; + return this; + } + + public UsAppToPersonCreator setMessageSamples(final String messageSamples) { + return setMessageSamples(Promoter.listOfOne(messageSamples)); + } + + public UsAppToPersonCreator setUsAppToPersonUsecase( + final String usAppToPersonUsecase + ) { + this.usAppToPersonUsecase = usAppToPersonUsecase; + return this; + } + + public UsAppToPersonCreator setHasEmbeddedLinks( + final Boolean hasEmbeddedLinks + ) { + this.hasEmbeddedLinks = hasEmbeddedLinks; + return this; + } + + public UsAppToPersonCreator setHasEmbeddedPhone( + final Boolean hasEmbeddedPhone + ) { + this.hasEmbeddedPhone = hasEmbeddedPhone; + return this; + } + + public UsAppToPersonCreator setOptInMessage(final String optInMessage) { + this.optInMessage = optInMessage; + return this; + } + + public UsAppToPersonCreator setOptOutMessage(final String optOutMessage) { + this.optOutMessage = optOutMessage; + return this; + } + + public UsAppToPersonCreator setHelpMessage(final String helpMessage) { + this.helpMessage = helpMessage; + return this; + } + + public UsAppToPersonCreator setOptInKeywords( + final List optInKeywords + ) { + this.optInKeywords = optInKeywords; + return this; + } + + public UsAppToPersonCreator setOptInKeywords(final String optInKeywords) { + return setOptInKeywords(Promoter.listOfOne(optInKeywords)); + } + + public UsAppToPersonCreator setOptOutKeywords( + final List optOutKeywords + ) { + this.optOutKeywords = optOutKeywords; + return this; + } + + public UsAppToPersonCreator setOptOutKeywords(final String optOutKeywords) { + return setOptOutKeywords(Promoter.listOfOne(optOutKeywords)); + } + + public UsAppToPersonCreator setHelpKeywords( + final List helpKeywords + ) { + this.helpKeywords = helpKeywords; + return this; + } + + public UsAppToPersonCreator setHelpKeywords(final String helpKeywords) { + return setHelpKeywords(Promoter.listOfOne(helpKeywords)); + } + + public UsAppToPersonCreator setSubscriberOptIn( + final Boolean subscriberOptIn + ) { + this.subscriberOptIn = subscriberOptIn; + return this; + } + + public UsAppToPersonCreator setAgeGated(final Boolean ageGated) { + this.ageGated = ageGated; + return this; + } + + public UsAppToPersonCreator setDirectLending(final Boolean directLending) { + this.directLending = directLending; + return this; + } + + public UsAppToPersonCreator setPrivacyPolicyUrl( + final URI privacyPolicyUrl + ) { + this.privacyPolicyUrl = privacyPolicyUrl; + return this; + } + + public UsAppToPersonCreator setPrivacyPolicyUrl( + final String privacyPolicyUrl + ) { + return setPrivacyPolicyUrl(Promoter.uriFromString(privacyPolicyUrl)); + } + + public UsAppToPersonCreator setTermsAndConditionsUrl( + final URI termsAndConditionsUrl + ) { + this.termsAndConditionsUrl = termsAndConditionsUrl; + return this; + } + + public UsAppToPersonCreator setTermsAndConditionsUrl( + final String termsAndConditionsUrl + ) { + return setTermsAndConditionsUrl( + Promoter.uriFromString(termsAndConditionsUrl) + ); + } + + public UsAppToPersonCreator setXTwilioApiVersion( + final String xTwilioApiVersion + ) { + this.xTwilioApiVersion = xTwilioApiVersion; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UsAppToPerson creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UsAppToPerson create(final TwilioRestClient client) { + Response response = makeRequest(client); + return UsAppToPerson.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UsAppToPerson content = UsAppToPerson.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (brandRegistrationSid != null) { + Serializer.toString( + request, + "BrandRegistrationSid", + brandRegistrationSid, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (messageFlow != null) { + Serializer.toString( + request, + "MessageFlow", + messageFlow, + ParameterType.URLENCODED + ); + } + + if (messageSamples != null) { + for (String param : messageSamples) { + Serializer.toString( + request, + "MessageSamples", + param, + ParameterType.URLENCODED + ); + } + } + + if (usAppToPersonUsecase != null) { + Serializer.toString( + request, + "UsAppToPersonUsecase", + usAppToPersonUsecase, + ParameterType.URLENCODED + ); + } + + if (hasEmbeddedLinks != null) { + Serializer.toString( + request, + "HasEmbeddedLinks", + hasEmbeddedLinks, + ParameterType.URLENCODED + ); + } + + if (hasEmbeddedPhone != null) { + Serializer.toString( + request, + "HasEmbeddedPhone", + hasEmbeddedPhone, + ParameterType.URLENCODED + ); + } + + if (optInMessage != null) { + Serializer.toString( + request, + "OptInMessage", + optInMessage, + ParameterType.URLENCODED + ); + } + + if (optOutMessage != null) { + Serializer.toString( + request, + "OptOutMessage", + optOutMessage, + ParameterType.URLENCODED + ); + } + + if (helpMessage != null) { + Serializer.toString( + request, + "HelpMessage", + helpMessage, + ParameterType.URLENCODED + ); + } + + if (optInKeywords != null) { + for (String param : optInKeywords) { + Serializer.toString( + request, + "OptInKeywords", + param, + ParameterType.URLENCODED + ); + } + } + + if (optOutKeywords != null) { + for (String param : optOutKeywords) { + Serializer.toString( + request, + "OptOutKeywords", + param, + ParameterType.URLENCODED + ); + } + } + + if (helpKeywords != null) { + for (String param : helpKeywords) { + Serializer.toString( + request, + "HelpKeywords", + param, + ParameterType.URLENCODED + ); + } + } + + if (subscriberOptIn != null) { + Serializer.toString( + request, + "SubscriberOptIn", + subscriberOptIn, + ParameterType.URLENCODED + ); + } + + if (ageGated != null) { + Serializer.toString( + request, + "AgeGated", + ageGated, + ParameterType.URLENCODED + ); + } + + if (directLending != null) { + Serializer.toString( + request, + "DirectLending", + directLending, + ParameterType.URLENCODED + ); + } + + if (privacyPolicyUrl != null) { + Serializer.toString( + request, + "PrivacyPolicyUrl", + privacyPolicyUrl, + ParameterType.URLENCODED + ); + } + + if (termsAndConditionsUrl != null) { + Serializer.toString( + request, + "TermsAndConditionsUrl", + termsAndConditionsUrl, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioApiVersion != null) { + Serializer.toString( + request, + "X-Twilio-Api-Version", + xTwilioApiVersion, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonDeleter.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonDeleter.java new file mode 100644 index 0000000000..ffaa97dc44 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonDeleter.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UsAppToPersonDeleter extends Deleter { + + private String pathMessagingServiceSid; + private String pathSid; + + public UsAppToPersonDeleter( + final String pathMessagingServiceSid, + final String pathSid + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UsAppToPerson delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonFetcher.java new file mode 100644 index 0000000000..33c22ce4e3 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonFetcher.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UsAppToPersonFetcher extends Fetcher { + + private String pathMessagingServiceSid; + private String pathSid; + private String xTwilioApiVersion; + + public UsAppToPersonFetcher( + final String pathMessagingServiceSid, + final String pathSid + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + this.pathSid = pathSid; + } + + public UsAppToPersonFetcher setXTwilioApiVersion( + final String xTwilioApiVersion + ) { + this.xTwilioApiVersion = xTwilioApiVersion; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addHeaderParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UsAppToPerson fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UsAppToPerson fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return UsAppToPerson.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UsAppToPerson content = UsAppToPerson.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (xTwilioApiVersion != null) { + Serializer.toString( + request, + "X-Twilio-Api-Version", + xTwilioApiVersion, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonReader.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonReader.java new file mode 100644 index 0000000000..c6a0bbbbb6 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonReader.java @@ -0,0 +1,231 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UsAppToPersonReader extends Reader { + + private String pathMessagingServiceSid; + private Long pageSize; + private String xTwilioApiVersion; + + public UsAppToPersonReader(final String pathMessagingServiceSid) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + } + + public UsAppToPersonReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public UsAppToPersonReader setXTwilioApiVersion( + final String xTwilioApiVersion + ) { + this.xTwilioApiVersion = xTwilioApiVersion; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "compliance", + response.getContent(), + UsAppToPerson.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + addHeaderParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "compliance", + response.getContent(), + UsAppToPerson.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UsAppToPerson read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "compliance", + response.getContent(), + UsAppToPerson.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioApiVersion != null) { + Serializer.toString( + request, + "X-Twilio-Api-Version", + xTwilioApiVersion, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUpdater.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUpdater.java new file mode 100644 index 0000000000..be6114f7ca --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUpdater.java @@ -0,0 +1,316 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; +import java.util.List; + +public class UsAppToPersonUpdater extends Updater { + + private String pathMessagingServiceSid; + private String pathSid; + private String xTwilioApiVersion; + private Boolean hasEmbeddedLinks; + private Boolean hasEmbeddedPhone; + private List messageSamples; + private String messageFlow; + private String description; + private Boolean ageGated; + private Boolean directLending; + private URI privacyPolicyUrl; + private URI termsAndConditionsUrl; + + public UsAppToPersonUpdater( + final String pathMessagingServiceSid, + final String pathSid, + final Boolean hasEmbeddedLinks, + final Boolean hasEmbeddedPhone, + final List messageSamples, + final String messageFlow, + final String description, + final Boolean ageGated, + final Boolean directLending + ) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + this.pathSid = pathSid; + this.hasEmbeddedLinks = hasEmbeddedLinks; + this.hasEmbeddedPhone = hasEmbeddedPhone; + this.messageSamples = messageSamples; + this.messageFlow = messageFlow; + this.description = description; + this.ageGated = ageGated; + this.directLending = directLending; + } + + public UsAppToPersonUpdater setHasEmbeddedLinks( + final Boolean hasEmbeddedLinks + ) { + this.hasEmbeddedLinks = hasEmbeddedLinks; + return this; + } + + public UsAppToPersonUpdater setHasEmbeddedPhone( + final Boolean hasEmbeddedPhone + ) { + this.hasEmbeddedPhone = hasEmbeddedPhone; + return this; + } + + public UsAppToPersonUpdater setMessageSamples( + final List messageSamples + ) { + this.messageSamples = messageSamples; + return this; + } + + public UsAppToPersonUpdater setMessageSamples(final String messageSamples) { + return setMessageSamples(Promoter.listOfOne(messageSamples)); + } + + public UsAppToPersonUpdater setMessageFlow(final String messageFlow) { + this.messageFlow = messageFlow; + return this; + } + + public UsAppToPersonUpdater setDescription(final String description) { + this.description = description; + return this; + } + + public UsAppToPersonUpdater setAgeGated(final Boolean ageGated) { + this.ageGated = ageGated; + return this; + } + + public UsAppToPersonUpdater setDirectLending(final Boolean directLending) { + this.directLending = directLending; + return this; + } + + public UsAppToPersonUpdater setPrivacyPolicyUrl( + final URI privacyPolicyUrl + ) { + this.privacyPolicyUrl = privacyPolicyUrl; + return this; + } + + public UsAppToPersonUpdater setPrivacyPolicyUrl( + final String privacyPolicyUrl + ) { + return setPrivacyPolicyUrl(Promoter.uriFromString(privacyPolicyUrl)); + } + + public UsAppToPersonUpdater setTermsAndConditionsUrl( + final URI termsAndConditionsUrl + ) { + this.termsAndConditionsUrl = termsAndConditionsUrl; + return this; + } + + public UsAppToPersonUpdater setTermsAndConditionsUrl( + final String termsAndConditionsUrl + ) { + return setTermsAndConditionsUrl( + Promoter.uriFromString(termsAndConditionsUrl) + ); + } + + public UsAppToPersonUpdater setXTwilioApiVersion( + final String xTwilioApiVersion + ) { + this.xTwilioApiVersion = xTwilioApiVersion; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/{Sid}"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UsAppToPerson update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UsAppToPerson update(final TwilioRestClient client) { + Response response = makeRequest(client); + return UsAppToPerson.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UsAppToPerson content = UsAppToPerson.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (hasEmbeddedLinks != null) { + Serializer.toString( + request, + "HasEmbeddedLinks", + hasEmbeddedLinks, + ParameterType.URLENCODED + ); + } + + if (hasEmbeddedPhone != null) { + Serializer.toString( + request, + "HasEmbeddedPhone", + hasEmbeddedPhone, + ParameterType.URLENCODED + ); + } + + if (messageSamples != null) { + for (String param : messageSamples) { + Serializer.toString( + request, + "MessageSamples", + param, + ParameterType.URLENCODED + ); + } + } + + if (messageFlow != null) { + Serializer.toString( + request, + "MessageFlow", + messageFlow, + ParameterType.URLENCODED + ); + } + + if (description != null) { + Serializer.toString( + request, + "Description", + description, + ParameterType.URLENCODED + ); + } + + if (ageGated != null) { + Serializer.toString( + request, + "AgeGated", + ageGated, + ParameterType.URLENCODED + ); + } + + if (directLending != null) { + Serializer.toString( + request, + "DirectLending", + directLending, + ParameterType.URLENCODED + ); + } + + if (privacyPolicyUrl != null) { + Serializer.toString( + request, + "PrivacyPolicyUrl", + privacyPolicyUrl, + ParameterType.URLENCODED + ); + } + + if (termsAndConditionsUrl != null) { + Serializer.toString( + request, + "TermsAndConditionsUrl", + termsAndConditionsUrl, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (xTwilioApiVersion != null) { + Serializer.toString( + request, + "X-Twilio-Api-Version", + xTwilioApiVersion, + ParameterType.HEADER + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecase.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecase.java new file mode 100644 index 0000000000..17d7bceeb1 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecase.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class UsAppToPersonUsecase extends Resource { + + public static UsAppToPersonUsecaseFetcher fetcher( + final String pathMessagingServiceSid + ) { + return new UsAppToPersonUsecaseFetcher(pathMessagingServiceSid); + } + + /** + * Converts a JSON String into a UsAppToPersonUsecase object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UsAppToPersonUsecase object represented by the provided JSON + */ + public static UsAppToPersonUsecase fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UsAppToPersonUsecase.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a UsAppToPersonUsecase object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UsAppToPersonUsecase object represented by the provided JSON + */ + public static UsAppToPersonUsecase fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UsAppToPersonUsecase.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List usAppToPersonUsecases; + + @JsonCreator + private UsAppToPersonUsecase( + @JsonProperty("us_app_to_person_usecases") final List< + Object + > usAppToPersonUsecases + ) { + this.usAppToPersonUsecases = usAppToPersonUsecases; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UsAppToPersonUsecase other = (UsAppToPersonUsecase) o; + return ( + Objects.equals(usAppToPersonUsecases, other.usAppToPersonUsecases) + ); + } + + @Override + public int hashCode() { + return Objects.hash(usAppToPersonUsecases); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecaseFetcher.java b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecaseFetcher.java new file mode 100644 index 0000000000..6c61726a21 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v1/service/UsAppToPersonUsecaseFetcher.java @@ -0,0 +1,123 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UsAppToPersonUsecaseFetcher extends Fetcher { + + private String pathMessagingServiceSid; + private String brandRegistrationSid; + + public UsAppToPersonUsecaseFetcher(final String pathMessagingServiceSid) { + this.pathMessagingServiceSid = pathMessagingServiceSid; + } + + public UsAppToPersonUsecaseFetcher setBrandRegistrationSid( + final String brandRegistrationSid + ) { + this.brandRegistrationSid = brandRegistrationSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{MessagingServiceSid}/Compliance/Usa2p/Usecases"; + + path = + path.replace( + "{" + "MessagingServiceSid" + "}", + this.pathMessagingServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "UsAppToPersonUsecase fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public UsAppToPersonUsecase fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return UsAppToPersonUsecase.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + UsAppToPersonUsecase content = UsAppToPersonUsecase.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (brandRegistrationSid != null) { + Serializer.toString( + request, + "BrandRegistrationSid", + brandRegistrationSid, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/ChannelsSender.java b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSender.java new file mode 100644 index 0000000000..37b3095e0a --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSender.java @@ -0,0 +1,2543 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ChannelsSender extends Resource { + + public static ChannelsSenderCreator creator( + final ChannelsSender.MessagingV2ChannelsSenderRequestsCreate messagingV2ChannelsSenderRequestsCreate + ) { + return new ChannelsSenderCreator( + messagingV2ChannelsSenderRequestsCreate + ); + } + + public static ChannelsSenderDeleter deleter(final String pathSid) { + return new ChannelsSenderDeleter(pathSid); + } + + public static ChannelsSenderFetcher fetcher(final String pathSid) { + return new ChannelsSenderFetcher(pathSid); + } + + public static ChannelsSenderReader reader(final String channel) { + return new ChannelsSenderReader(channel); + } + + public static ChannelsSenderUpdater updater(final String pathSid) { + return new ChannelsSenderUpdater(pathSid); + } + + public enum Status { + CREATING("CREATING"), + ONLINE("ONLINE"), + OFFLINE("OFFLINE"), + PENDING_VERIFICATION("PENDING_VERIFICATION"), + VERIFYING("VERIFYING"), + ONLINE_UPDATING("ONLINE:UPDATING"), + TWILIO_REVIEW("TWILIO_REVIEW"), + DRAFT("DRAFT"), + STUBBED("STUBBED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum CallbackMethod { + POST("POST"), + PUT("PUT"); + + private final String value; + + private CallbackMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CallbackMethod forValue(final String value) { + return Promoter.enumFromString(value, CallbackMethod.values()); + } + } + + public enum PendingDisplayNameStatus { + PENDING_REVIEW("PENDING_REVIEW"), + APPROVED("APPROVED"), + DECLINED("DECLINED"), + PIN_MISMATCH("PIN_MISMATCH"), + REGISTRATION_FAILED("REGISTRATION_FAILED"), + EXPIRED("EXPIRED"), + COMPLETED("COMPLETED"); + + private final String value; + + private PendingDisplayNameStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static PendingDisplayNameStatus forValue(final String value) { + return Promoter.enumFromString( + value, + PendingDisplayNameStatus.values() + ); + } + } + + public enum MessagingV2RcsCarrierStatus { + UNKNOWN("UNKNOWN"), + UNLAUNCHED("UNLAUNCHED"), + CARRIER_REVIEW("CARRIER_REVIEW"), + APPROVED("APPROVED"), + REJECTED("REJECTED"), + SUSPENDED("SUSPENDED"); + + private final String value; + + private MessagingV2RcsCarrierStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static MessagingV2RcsCarrierStatus forValue(final String value) { + return Promoter.enumFromString( + value, + MessagingV2RcsCarrierStatus.values() + ); + } + } + + public enum VerificationMethod { + SMS("sms"), + VOICE("voice"); + + private final String value; + + private VerificationMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static VerificationMethod forValue(final String value) { + return Promoter.enumFromString(value, VerificationMethod.values()); + } + } + + public enum UseCase { + PROMOTIONAL("PROMOTIONAL"), + TRANSACTIONAL("TRANSACTIONAL"), + OTP("OTP"), + MULTI_USE("MULTI_USE"); + + private final String value; + + private UseCase(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static UseCase forValue(final String value) { + return Promoter.enumFromString(value, UseCase.values()); + } + } + + public enum AccountType { + ISV("ISV"), + ISV_SUB_ACCOUNT("ISVSubAccount"); + + private final String value; + + private AccountType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static AccountType forValue(final String value) { + return Promoter.enumFromString(value, AccountType.values()); + } + } + + public enum DisplayNameStatus { + UPDATING("updating"), + NO_CHANGE("no_change"), + PENDING_REVIEW("pending_review"), + ERROR("error"); + + private final String value; + + private DisplayNameStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static DisplayNameStatus forValue(final String value) { + return Promoter.enumFromString(value, DisplayNameStatus.values()); + } + } + + public enum FallbackMethod { + POST("POST"), + PUT("PUT"); + + private final String value; + + private FallbackMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static FallbackMethod forValue(final String value) { + return Promoter.enumFromString(value, FallbackMethod.values()); + } + } + + public enum MessagingV2RcsCountryStatus { + ONLINE("ONLINE"), + OFFLINE("OFFLINE"), + TWILIO_REVIEW("TWILIO_REVIEW"), + PENDING_VERIFICATION("PENDING_VERIFICATION"); + + private final String value; + + private MessagingV2RcsCountryStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static MessagingV2RcsCountryStatus forValue(final String value) { + return Promoter.enumFromString( + value, + MessagingV2RcsCountryStatus.values() + ); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderProfileGenericResponseWebsites.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderProfileGenericResponseWebsites { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("website") + @Getter + private final String website; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + @Getter + private final String label; + + private MessagingV2ChannelsSenderProfileGenericResponseWebsites( + Builder builder + ) { + this.website = builder.website; + this.label = builder.label; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderProfileGenericResponseWebsites fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderProfileGenericResponseWebsites.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("website") + private String website; + + @JsonProperty("label") + private String label; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("website") + public Builder website(String website) { + this.website = website; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + public Builder label(String label) { + this.label = label; + return this; + } + + public MessagingV2ChannelsSenderProfileGenericResponseWebsites build() { + return new MessagingV2ChannelsSenderProfileGenericResponseWebsites( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderProfileGenericResponseWebsites other = + (MessagingV2ChannelsSenderProfileGenericResponseWebsites) o; + return ( + Objects.equals(website, other.website) && + Objects.equals(label, other.label) + ); + } + + @Override + public int hashCode() { + return Objects.hash(website, label); + } + } + + @JsonDeserialize(builder = MessagingV2ChannelsSenderProfile.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderProfile { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("about") + @Getter + private final String about; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("logo_url") + @Getter + private final String logoUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("banner_url") + @Getter + private final String bannerUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("privacy_url") + @Getter + private final String privacyUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("terms_of_service_url") + @Getter + private final String termsOfServiceUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accent_color") + @Getter + private final String accentColor; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("use_case") + @Getter + private final ChannelsSender.UseCase useCase; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("vertical") + @Getter + private final String vertical; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("websites") + @Getter + private final Object websites; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("emails") + @Getter + private final Object emails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_numbers") + @Getter + private final Object phoneNumbers; + + private MessagingV2ChannelsSenderProfile(Builder builder) { + this.name = builder.name; + this.about = builder.about; + this.address = builder.address; + this.description = builder.description; + this.logoUrl = builder.logoUrl; + this.bannerUrl = builder.bannerUrl; + this.privacyUrl = builder.privacyUrl; + this.termsOfServiceUrl = builder.termsOfServiceUrl; + this.accentColor = builder.accentColor; + this.useCase = builder.useCase; + this.vertical = builder.vertical; + this.websites = builder.websites; + this.emails = builder.emails; + this.phoneNumbers = builder.phoneNumbers; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderProfile fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderProfile.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("about") + private String about; + + @JsonProperty("address") + private String address; + + @JsonProperty("description") + private String description; + + @JsonProperty("logo_url") + private String logoUrl; + + @JsonProperty("banner_url") + private String bannerUrl; + + @JsonProperty("privacy_url") + private String privacyUrl; + + @JsonProperty("terms_of_service_url") + private String termsOfServiceUrl; + + @JsonProperty("accent_color") + private String accentColor; + + @JsonProperty("use_case") + private ChannelsSender.UseCase useCase; + + @JsonProperty("vertical") + private String vertical; + + @JsonProperty("websites") + private Object websites; + + @JsonProperty("emails") + private Object emails; + + @JsonProperty("phone_numbers") + private Object phoneNumbers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("about") + public Builder about(String about) { + this.about = about; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + public Builder address(String address) { + this.address = address; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("logo_url") + public Builder logoUrl(String logoUrl) { + this.logoUrl = logoUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("banner_url") + public Builder bannerUrl(String bannerUrl) { + this.bannerUrl = bannerUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("privacy_url") + public Builder privacyUrl(String privacyUrl) { + this.privacyUrl = privacyUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("terms_of_service_url") + public Builder termsOfServiceUrl(String termsOfServiceUrl) { + this.termsOfServiceUrl = termsOfServiceUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accent_color") + public Builder accentColor(String accentColor) { + this.accentColor = accentColor; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("use_case") + public Builder useCase(ChannelsSender.UseCase useCase) { + this.useCase = useCase; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("vertical") + public Builder vertical(String vertical) { + this.vertical = vertical; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("websites") + public Builder websites(Object websites) { + this.websites = websites; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("emails") + public Builder emails(Object emails) { + this.emails = emails; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_numbers") + public Builder phoneNumbers(Object phoneNumbers) { + this.phoneNumbers = phoneNumbers; + return this; + } + + public MessagingV2ChannelsSenderProfile build() { + return new MessagingV2ChannelsSenderProfile(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderProfile other = + (MessagingV2ChannelsSenderProfile) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(about, other.about) && + Objects.equals(address, other.address) && + Objects.equals(description, other.description) && + Objects.equals(logoUrl, other.logoUrl) && + Objects.equals(bannerUrl, other.bannerUrl) && + Objects.equals(privacyUrl, other.privacyUrl) && + Objects.equals(termsOfServiceUrl, other.termsOfServiceUrl) && + Objects.equals(accentColor, other.accentColor) && + Objects.equals(useCase, other.useCase) && + Objects.equals(vertical, other.vertical) && + Objects.equals(websites, other.websites) && + Objects.equals(emails, other.emails) && + Objects.equals(phoneNumbers, other.phoneNumbers) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + name, + about, + address, + description, + logoUrl, + bannerUrl, + privacyUrl, + termsOfServiceUrl, + accentColor, + useCase, + vertical, + websites, + emails, + phoneNumbers + ); + } + } + + @JsonDeserialize(builder = MessagingV2RcsComplianceResponse.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2RcsComplianceResponse { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("registration_sid") + @Getter + private final String registrationSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("countries") + @Getter + private final List countries; + + private MessagingV2RcsComplianceResponse(Builder builder) { + this.registrationSid = builder.registrationSid; + this.countries = builder.countries; + } + + public static Builder builder(final String registrationSid) { + return new Builder(registrationSid); + } + + public static MessagingV2RcsComplianceResponse fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2RcsComplianceResponse.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("registration_sid") + private String registrationSid; + + @JsonProperty("countries") + private List countries; + + @JsonCreator + public Builder( + @JsonProperty("registration_sid") final String registrationSid + ) { + this.registrationSid = registrationSid; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("countries") + public Builder countries( + List countries + ) { + this.countries = countries; + return this; + } + + public MessagingV2RcsComplianceResponse build() { + return new MessagingV2RcsComplianceResponse(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2RcsComplianceResponse other = + (MessagingV2RcsComplianceResponse) o; + return ( + Objects.equals(registrationSid, other.registrationSid) && + Objects.equals(countries, other.countries) + ); + } + + @Override + public int hashCode() { + return Objects.hash(registrationSid, countries); + } + } + + @JsonDeserialize(builder = MessagingV2RcsCarrier.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2RcsCarrier { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final ChannelsSender.MessagingV2RcsCarrierStatus status; + + private MessagingV2RcsCarrier(Builder builder) { + this.name = builder.name; + this.status = builder.status; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2RcsCarrier fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, MessagingV2RcsCarrier.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("status") + private ChannelsSender.MessagingV2RcsCarrierStatus status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + public Builder status( + ChannelsSender.MessagingV2RcsCarrierStatus status + ) { + this.status = status; + return this; + } + + public MessagingV2RcsCarrier build() { + return new MessagingV2RcsCarrier(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2RcsCarrier other = (MessagingV2RcsCarrier) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(status, other.status) + ); + } + + @Override + public int hashCode() { + return Objects.hash(name, status); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderRequestsCreate.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderRequestsCreate { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sender_id") + @Getter + private final String senderId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + @Getter + private final MessagingV2ChannelsSenderConfiguration configuration; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("webhook") + @Getter + private final MessagingV2ChannelsSenderWebhook webhook; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profile") + @Getter + private final MessagingV2ChannelsSenderProfile profile; + + private MessagingV2ChannelsSenderRequestsCreate(Builder builder) { + this.senderId = builder.senderId; + this.friendlyName = builder.friendlyName; + this.configuration = builder.configuration; + this.webhook = builder.webhook; + this.profile = builder.profile; + } + + public static Builder builder(final String senderId) { + return new Builder(senderId); + } + + public static MessagingV2ChannelsSenderRequestsCreate fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderRequestsCreate.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("sender_id") + private String senderId; + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonProperty("configuration") + private MessagingV2ChannelsSenderConfiguration configuration; + + @JsonProperty("webhook") + private MessagingV2ChannelsSenderWebhook webhook; + + @JsonProperty("profile") + private MessagingV2ChannelsSenderProfile profile; + + @JsonCreator + public Builder(@JsonProperty("sender_id") final String senderId) { + this.senderId = senderId; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + public Builder configuration( + MessagingV2ChannelsSenderConfiguration configuration + ) { + this.configuration = configuration; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("webhook") + public Builder webhook(MessagingV2ChannelsSenderWebhook webhook) { + this.webhook = webhook; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profile") + public Builder profile(MessagingV2ChannelsSenderProfile profile) { + this.profile = profile; + return this; + } + + public MessagingV2ChannelsSenderRequestsCreate build() { + return new MessagingV2ChannelsSenderRequestsCreate(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderRequestsCreate other = + (MessagingV2ChannelsSenderRequestsCreate) o; + return ( + Objects.equals(senderId, other.senderId) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(configuration, other.configuration) && + Objects.equals(webhook, other.webhook) && + Objects.equals(profile, other.profile) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + senderId, + friendlyName, + configuration, + webhook, + profile + ); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderProfileGenericResponseEmails.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderProfileGenericResponseEmails { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("email") + @Getter + private final String email; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + @Getter + private final String label; + + private MessagingV2ChannelsSenderProfileGenericResponseEmails( + Builder builder + ) { + this.email = builder.email; + this.label = builder.label; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderProfileGenericResponseEmails fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderProfileGenericResponseEmails.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("email") + private String email; + + @JsonProperty("label") + private String label; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("email") + public Builder email(String email) { + this.email = email; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + public Builder label(String label) { + this.label = label; + return this; + } + + public MessagingV2ChannelsSenderProfileGenericResponseEmails build() { + return new MessagingV2ChannelsSenderProfileGenericResponseEmails( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderProfileGenericResponseEmails other = + (MessagingV2ChannelsSenderProfileGenericResponseEmails) o; + return ( + Objects.equals(email, other.email) && + Objects.equals(label, other.label) + ); + } + + @Override + public int hashCode() { + return Objects.hash(email, label); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderProperties.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderProperties { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("quality_rating") + @Getter + private final String qualityRating; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("messaging_limit") + @Getter + private final String messagingLimit; + + private MessagingV2ChannelsSenderProperties(Builder builder) { + this.qualityRating = builder.qualityRating; + this.messagingLimit = builder.messagingLimit; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderProperties fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderProperties.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("quality_rating") + private String qualityRating; + + @JsonProperty("messaging_limit") + private String messagingLimit; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("quality_rating") + public Builder qualityRating(String qualityRating) { + this.qualityRating = qualityRating; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("messaging_limit") + public Builder messagingLimit(String messagingLimit) { + this.messagingLimit = messagingLimit; + return this; + } + + public MessagingV2ChannelsSenderProperties build() { + return new MessagingV2ChannelsSenderProperties(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderProperties other = + (MessagingV2ChannelsSenderProperties) o; + return ( + Objects.equals(qualityRating, other.qualityRating) && + Objects.equals(messagingLimit, other.messagingLimit) + ); + } + + @Override + public int hashCode() { + return Objects.hash(qualityRating, messagingLimit); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderOfflineReasonsItems.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderOfflineReasonsItems { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + @Getter + private final String code; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("message") + @Getter + private final String message; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("more_info") + @Getter + private final URI moreInfo; + + private MessagingV2ChannelsSenderOfflineReasonsItems(Builder builder) { + this.code = builder.code; + this.message = builder.message; + this.moreInfo = builder.moreInfo; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderOfflineReasonsItems fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderOfflineReasonsItems.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("code") + private String code; + + @JsonProperty("message") + private String message; + + @JsonProperty("more_info") + private URI moreInfo; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("code") + public Builder code(String code) { + this.code = code; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("message") + public Builder message(String message) { + this.message = message; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("more_info") + public Builder moreInfo(URI moreInfo) { + this.moreInfo = moreInfo; + return this; + } + + public MessagingV2ChannelsSenderOfflineReasonsItems build() { + return new MessagingV2ChannelsSenderOfflineReasonsItems(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderOfflineReasonsItems other = + (MessagingV2ChannelsSenderOfflineReasonsItems) o; + return ( + Objects.equals(code, other.code) && + Objects.equals(message, other.message) && + Objects.equals(moreInfo, other.moreInfo) + ); + } + + @Override + public int hashCode() { + return Objects.hash(code, message, moreInfo); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderRequestsUpdate.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderRequestsUpdate { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + @Getter + private final MessagingV2ChannelsSenderConfiguration configuration; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("webhook") + @Getter + private final MessagingV2ChannelsSenderWebhook webhook; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profile") + @Getter + private final MessagingV2ChannelsSenderProfile profile; + + private MessagingV2ChannelsSenderRequestsUpdate(Builder builder) { + this.friendlyName = builder.friendlyName; + this.configuration = builder.configuration; + this.webhook = builder.webhook; + this.profile = builder.profile; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderRequestsUpdate fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderRequestsUpdate.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonProperty("configuration") + private MessagingV2ChannelsSenderConfiguration configuration; + + @JsonProperty("webhook") + private MessagingV2ChannelsSenderWebhook webhook; + + @JsonProperty("profile") + private MessagingV2ChannelsSenderProfile profile; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("configuration") + public Builder configuration( + MessagingV2ChannelsSenderConfiguration configuration + ) { + this.configuration = configuration; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("webhook") + public Builder webhook(MessagingV2ChannelsSenderWebhook webhook) { + this.webhook = webhook; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("profile") + public Builder profile(MessagingV2ChannelsSenderProfile profile) { + this.profile = profile; + return this; + } + + public MessagingV2ChannelsSenderRequestsUpdate build() { + return new MessagingV2ChannelsSenderRequestsUpdate(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderRequestsUpdate other = + (MessagingV2ChannelsSenderRequestsUpdate) o; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(configuration, other.configuration) && + Objects.equals(webhook, other.webhook) && + Objects.equals(profile, other.profile) + ); + } + + @Override + public int hashCode() { + return Objects.hash(friendlyName, configuration, webhook, profile); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + @Getter + private final String phoneNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + @Getter + private final String label; + + private MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers( + Builder builder + ) { + this.phoneNumber = builder.phoneNumber; + this.label = builder.label; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("phone_number") + private String phoneNumber; + + @JsonProperty("label") + private String label; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + public Builder phoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("label") + public Builder label(String label) { + this.label = label; + return this; + } + + public MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers build() { + return new MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers other = + (MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers) o; + return ( + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(label, other.label) + ); + } + + @Override + public int hashCode() { + return Objects.hash(phoneNumber, label); + } + } + + @JsonDeserialize( + builder = MessagingV2RcsComplianceCountryResponse.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2RcsComplianceCountryResponse { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country") + @Getter + private final String country; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("registration_sid") + @Getter + private final String registrationSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + @Getter + private final ChannelsSender.MessagingV2RcsCountryStatus status; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carriers") + @Getter + private final List carriers; + + private MessagingV2RcsComplianceCountryResponse(Builder builder) { + this.country = builder.country; + this.registrationSid = builder.registrationSid; + this.status = builder.status; + this.carriers = builder.carriers; + } + + public static Builder builder(final String country) { + return new Builder(country); + } + + public static MessagingV2RcsComplianceCountryResponse fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2RcsComplianceCountryResponse.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("country") + private String country; + + @JsonProperty("registration_sid") + private String registrationSid; + + @JsonProperty("status") + private ChannelsSender.MessagingV2RcsCountryStatus status; + + @JsonProperty("carriers") + private List carriers; + + @JsonCreator + public Builder(@JsonProperty("country") final String country) { + this.country = country; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("registration_sid") + public Builder registrationSid(String registrationSid) { + this.registrationSid = registrationSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status") + public Builder status( + ChannelsSender.MessagingV2RcsCountryStatus status + ) { + this.status = status; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("carriers") + public Builder carriers(List carriers) { + this.carriers = carriers; + return this; + } + + public MessagingV2RcsComplianceCountryResponse build() { + return new MessagingV2RcsComplianceCountryResponse(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2RcsComplianceCountryResponse other = + (MessagingV2RcsComplianceCountryResponse) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(registrationSid, other.registrationSid) && + Objects.equals(status, other.status) && + Objects.equals(carriers, other.carriers) + ); + } + + @Override + public int hashCode() { + return Objects.hash(country, registrationSid, status, carriers); + } + } + + @JsonDeserialize(builder = MessagingV2ChannelsSenderWebhook.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderWebhook { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("callback_url") + @Getter + private final String callbackUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("callback_method") + @Getter + private final ChannelsSender.CallbackMethod callbackMethod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fallback_url") + @Getter + private final String fallbackUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fallback_method") + @Getter + private final ChannelsSender.FallbackMethod fallbackMethod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_callback_url") + @Getter + private final String statusCallbackUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_callback_method") + @Getter + private final String statusCallbackMethod; + + private MessagingV2ChannelsSenderWebhook(Builder builder) { + this.callbackUrl = builder.callbackUrl; + this.callbackMethod = builder.callbackMethod; + this.fallbackUrl = builder.fallbackUrl; + this.fallbackMethod = builder.fallbackMethod; + this.statusCallbackUrl = builder.statusCallbackUrl; + this.statusCallbackMethod = builder.statusCallbackMethod; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderWebhook fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderWebhook.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("callback_url") + private String callbackUrl; + + @JsonProperty("callback_method") + private ChannelsSender.CallbackMethod callbackMethod; + + @JsonProperty("fallback_url") + private String fallbackUrl; + + @JsonProperty("fallback_method") + private ChannelsSender.FallbackMethod fallbackMethod; + + @JsonProperty("status_callback_url") + private String statusCallbackUrl; + + @JsonProperty("status_callback_method") + private String statusCallbackMethod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("callback_url") + public Builder callbackUrl(String callbackUrl) { + this.callbackUrl = callbackUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("callback_method") + public Builder callbackMethod( + ChannelsSender.CallbackMethod callbackMethod + ) { + this.callbackMethod = callbackMethod; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fallback_url") + public Builder fallbackUrl(String fallbackUrl) { + this.fallbackUrl = fallbackUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("fallback_method") + public Builder fallbackMethod( + ChannelsSender.FallbackMethod fallbackMethod + ) { + this.fallbackMethod = fallbackMethod; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_callback_url") + public Builder statusCallbackUrl(String statusCallbackUrl) { + this.statusCallbackUrl = statusCallbackUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_callback_method") + public Builder statusCallbackMethod(String statusCallbackMethod) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + public MessagingV2ChannelsSenderWebhook build() { + return new MessagingV2ChannelsSenderWebhook(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderWebhook other = + (MessagingV2ChannelsSenderWebhook) o; + return ( + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(callbackMethod, other.callbackMethod) && + Objects.equals(fallbackUrl, other.fallbackUrl) && + Objects.equals(fallbackMethod, other.fallbackMethod) && + Objects.equals(statusCallbackUrl, other.statusCallbackUrl) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + callbackUrl, + callbackMethod, + fallbackUrl, + fallbackMethod, + statusCallbackUrl, + statusCallbackMethod + ); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderProfileGenericResponse.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderProfileGenericResponse { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final String name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("about") + @Getter + private final String about; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final String address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + @Getter + private final String description; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("logo_url") + @Getter + private final String logoUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("banner_url") + @Getter + private final String bannerUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("privacy_url") + @Getter + private final String privacyUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("terms_of_service_url") + @Getter + private final String termsOfServiceUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accent_color") + @Getter + private final String accentColor; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("use_case") + @Getter + private final ChannelsSender.UseCase useCase; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("vertical") + @Getter + private final String vertical; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("websites") + @Getter + private final List< + MessagingV2ChannelsSenderProfileGenericResponseWebsites + > websites; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("emails") + @Getter + private final List< + MessagingV2ChannelsSenderProfileGenericResponseEmails + > emails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_numbers") + @Getter + private final List< + MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers + > phoneNumbers; + + private MessagingV2ChannelsSenderProfileGenericResponse( + Builder builder + ) { + this.name = builder.name; + this.about = builder.about; + this.address = builder.address; + this.description = builder.description; + this.logoUrl = builder.logoUrl; + this.bannerUrl = builder.bannerUrl; + this.privacyUrl = builder.privacyUrl; + this.termsOfServiceUrl = builder.termsOfServiceUrl; + this.accentColor = builder.accentColor; + this.useCase = builder.useCase; + this.vertical = builder.vertical; + this.websites = builder.websites; + this.emails = builder.emails; + this.phoneNumbers = builder.phoneNumbers; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderProfileGenericResponse fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderProfileGenericResponse.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("name") + private String name; + + @JsonProperty("about") + private String about; + + @JsonProperty("address") + private String address; + + @JsonProperty("description") + private String description; + + @JsonProperty("logo_url") + private String logoUrl; + + @JsonProperty("banner_url") + private String bannerUrl; + + @JsonProperty("privacy_url") + private String privacyUrl; + + @JsonProperty("terms_of_service_url") + private String termsOfServiceUrl; + + @JsonProperty("accent_color") + private String accentColor; + + @JsonProperty("use_case") + private ChannelsSender.UseCase useCase; + + @JsonProperty("vertical") + private String vertical; + + @JsonProperty("websites") + private List< + MessagingV2ChannelsSenderProfileGenericResponseWebsites + > websites; + + @JsonProperty("emails") + private List< + MessagingV2ChannelsSenderProfileGenericResponseEmails + > emails; + + @JsonProperty("phone_numbers") + private List< + MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers + > phoneNumbers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(String name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("about") + public Builder about(String about) { + this.about = about; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + public Builder address(String address) { + this.address = address; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("description") + public Builder description(String description) { + this.description = description; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("logo_url") + public Builder logoUrl(String logoUrl) { + this.logoUrl = logoUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("banner_url") + public Builder bannerUrl(String bannerUrl) { + this.bannerUrl = bannerUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("privacy_url") + public Builder privacyUrl(String privacyUrl) { + this.privacyUrl = privacyUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("terms_of_service_url") + public Builder termsOfServiceUrl(String termsOfServiceUrl) { + this.termsOfServiceUrl = termsOfServiceUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("accent_color") + public Builder accentColor(String accentColor) { + this.accentColor = accentColor; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("use_case") + public Builder useCase(ChannelsSender.UseCase useCase) { + this.useCase = useCase; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("vertical") + public Builder vertical(String vertical) { + this.vertical = vertical; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("websites") + public Builder websites( + List< + MessagingV2ChannelsSenderProfileGenericResponseWebsites + > websites + ) { + this.websites = websites; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("emails") + public Builder emails( + List< + MessagingV2ChannelsSenderProfileGenericResponseEmails + > emails + ) { + this.emails = emails; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_numbers") + public Builder phoneNumbers( + List< + MessagingV2ChannelsSenderProfileGenericResponsePhoneNumbers + > phoneNumbers + ) { + this.phoneNumbers = phoneNumbers; + return this; + } + + public MessagingV2ChannelsSenderProfileGenericResponse build() { + return new MessagingV2ChannelsSenderProfileGenericResponse( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderProfileGenericResponse other = + (MessagingV2ChannelsSenderProfileGenericResponse) o; + return ( + Objects.equals(name, other.name) && + Objects.equals(about, other.about) && + Objects.equals(address, other.address) && + Objects.equals(description, other.description) && + Objects.equals(logoUrl, other.logoUrl) && + Objects.equals(bannerUrl, other.bannerUrl) && + Objects.equals(privacyUrl, other.privacyUrl) && + Objects.equals(termsOfServiceUrl, other.termsOfServiceUrl) && + Objects.equals(accentColor, other.accentColor) && + Objects.equals(useCase, other.useCase) && + Objects.equals(vertical, other.vertical) && + Objects.equals(websites, other.websites) && + Objects.equals(emails, other.emails) && + Objects.equals(phoneNumbers, other.phoneNumbers) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + name, + about, + address, + description, + logoUrl, + bannerUrl, + privacyUrl, + termsOfServiceUrl, + accentColor, + useCase, + vertical, + websites, + emails, + phoneNumbers + ); + } + } + + @JsonDeserialize( + builder = MessagingV2ChannelsSenderConfiguration.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessagingV2ChannelsSenderConfiguration { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("waba_id") + @Getter + private final String wabaId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("verification_method") + @Getter + private final ChannelsSender.VerificationMethod verificationMethod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("verification_code") + @Getter + private final String verificationCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("voice_application_sid") + @Getter + private final String voiceApplicationSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_type") + @Getter + private final ChannelsSender.AccountType accountType; + + private MessagingV2ChannelsSenderConfiguration(Builder builder) { + this.wabaId = builder.wabaId; + this.verificationMethod = builder.verificationMethod; + this.verificationCode = builder.verificationCode; + this.voiceApplicationSid = builder.voiceApplicationSid; + this.accountType = builder.accountType; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessagingV2ChannelsSenderConfiguration fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessagingV2ChannelsSenderConfiguration.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("waba_id") + private String wabaId; + + @JsonProperty("verification_method") + private ChannelsSender.VerificationMethod verificationMethod; + + @JsonProperty("verification_code") + private String verificationCode; + + @JsonProperty("voice_application_sid") + private String voiceApplicationSid; + + @JsonProperty("account_type") + private ChannelsSender.AccountType accountType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("waba_id") + public Builder wabaId(String wabaId) { + this.wabaId = wabaId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("verification_method") + public Builder verificationMethod( + ChannelsSender.VerificationMethod verificationMethod + ) { + this.verificationMethod = verificationMethod; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("verification_code") + public Builder verificationCode(String verificationCode) { + this.verificationCode = verificationCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("voice_application_sid") + public Builder voiceApplicationSid(String voiceApplicationSid) { + this.voiceApplicationSid = voiceApplicationSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_type") + public Builder accountType(ChannelsSender.AccountType accountType) { + this.accountType = accountType; + return this; + } + + public MessagingV2ChannelsSenderConfiguration build() { + return new MessagingV2ChannelsSenderConfiguration(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessagingV2ChannelsSenderConfiguration other = + (MessagingV2ChannelsSenderConfiguration) o; + return ( + Objects.equals(wabaId, other.wabaId) && + Objects.equals(verificationMethod, other.verificationMethod) && + Objects.equals(verificationCode, other.verificationCode) && + Objects.equals( + voiceApplicationSid, + other.voiceApplicationSid + ) && + Objects.equals(accountType, other.accountType) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + wabaId, + verificationMethod, + verificationCode, + voiceApplicationSid, + accountType + ); + } + } + + /** + * Converts a JSON String into a ChannelsSender object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ChannelsSender object represented by the provided JSON + */ + public static ChannelsSender fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ChannelsSender.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ChannelsSender object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ChannelsSender object represented by the provided JSON + */ + public static ChannelsSender fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ChannelsSender.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final MessagingV2RcsComplianceResponse compliance; + + @Getter + private final MessagingV2ChannelsSenderConfiguration configuration; + + @Getter + private final ChannelsSender.DisplayNameStatus displayNameStatus; + + @Getter + private final String friendlyName; + + @Getter + private final List< + MessagingV2ChannelsSenderOfflineReasonsItems + > offlineReasons; + + @Getter + private final String pendingDisplayName; + + @Getter + private final ChannelsSender.PendingDisplayNameStatus pendingDisplayNameStatus; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime pendingDisplayNameStatusDate; + + @Getter + private final MessagingV2ChannelsSenderProfileGenericResponse profile; + + @Getter + private final MessagingV2ChannelsSenderProperties properties; + + @Getter + private final String senderId; + + @Getter + private final String sid; + + @Getter + private final ChannelsSender.Status status; + + @Getter + private final URI url; + + @Getter + private final MessagingV2ChannelsSenderWebhook webhook; + + @JsonCreator + private ChannelsSender( + @JsonProperty( + "compliance" + ) final MessagingV2RcsComplianceResponse compliance, + @JsonProperty( + "configuration" + ) final MessagingV2ChannelsSenderConfiguration configuration, + @JsonProperty( + "display_name_status" + ) final ChannelsSender.DisplayNameStatus displayNameStatus, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("offline_reasons") final List< + MessagingV2ChannelsSenderOfflineReasonsItems + > offlineReasons, + @JsonProperty("pending_display_name") final String pendingDisplayName, + @JsonProperty( + "pending_display_name_status" + ) final ChannelsSender.PendingDisplayNameStatus pendingDisplayNameStatus, + @JsonProperty("pending_display_name_status_date") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime pendingDisplayNameStatusDate, + @JsonProperty( + "profile" + ) final MessagingV2ChannelsSenderProfileGenericResponse profile, + @JsonProperty( + "properties" + ) final MessagingV2ChannelsSenderProperties properties, + @JsonProperty("sender_id") final String senderId, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final ChannelsSender.Status status, + @JsonProperty("url") final URI url, + @JsonProperty("webhook") final MessagingV2ChannelsSenderWebhook webhook + ) { + this.compliance = compliance; + this.configuration = configuration; + this.displayNameStatus = displayNameStatus; + this.friendlyName = friendlyName; + this.offlineReasons = offlineReasons; + this.pendingDisplayName = pendingDisplayName; + this.pendingDisplayNameStatus = pendingDisplayNameStatus; + this.pendingDisplayNameStatusDate = pendingDisplayNameStatusDate; + this.profile = profile; + this.properties = properties; + this.senderId = senderId; + this.sid = sid; + this.status = status; + this.url = url; + this.webhook = webhook; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ChannelsSender other = (ChannelsSender) o; + return ( + Objects.equals(compliance, other.compliance) && + Objects.equals(configuration, other.configuration) && + Objects.equals(displayNameStatus, other.displayNameStatus) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(offlineReasons, other.offlineReasons) && + Objects.equals(pendingDisplayName, other.pendingDisplayName) && + Objects.equals( + pendingDisplayNameStatus, + other.pendingDisplayNameStatus + ) && + Objects.equals( + pendingDisplayNameStatusDate, + other.pendingDisplayNameStatusDate + ) && + Objects.equals(profile, other.profile) && + Objects.equals(properties, other.properties) && + Objects.equals(senderId, other.senderId) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(webhook, other.webhook) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + compliance, + configuration, + displayNameStatus, + friendlyName, + offlineReasons, + pendingDisplayName, + pendingDisplayNameStatus, + pendingDisplayNameStatusDate, + profile, + properties, + senderId, + sid, + status, + url, + webhook + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderCreator.java b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderCreator.java new file mode 100644 index 0000000000..60b771242f --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelsSenderCreator extends Creator { + + private ChannelsSender.MessagingV2ChannelsSenderRequestsCreate messagingV2ChannelsSenderRequestsCreate; + + public ChannelsSenderCreator( + final ChannelsSender.MessagingV2ChannelsSenderRequestsCreate messagingV2ChannelsSenderRequestsCreate + ) { + this.messagingV2ChannelsSenderRequestsCreate = + messagingV2ChannelsSenderRequestsCreate; + } + + public ChannelsSenderCreator setMessagingV2ChannelsSenderRequestsCreate( + final ChannelsSender.MessagingV2ChannelsSenderRequestsCreate messagingV2ChannelsSenderRequestsCreate + ) { + this.messagingV2ChannelsSenderRequestsCreate = + messagingV2ChannelsSenderRequestsCreate; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Channels/Senders"; + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ChannelsSender creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ChannelsSender create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ChannelsSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ChannelsSender content = ChannelsSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (messagingV2ChannelsSenderRequestsCreate != null) { + request.setBody( + ChannelsSender.toJson( + messagingV2ChannelsSenderRequestsCreate, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderDeleter.java b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderDeleter.java new file mode 100644 index 0000000000..5e66814c1a --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ChannelsSenderDeleter extends Deleter { + + private String pathSid; + + public ChannelsSenderDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Channels/Senders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ChannelsSender delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderFetcher.java b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderFetcher.java new file mode 100644 index 0000000000..4b2352b55d --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelsSenderFetcher extends Fetcher { + + private String pathSid; + + public ChannelsSenderFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Channels/Senders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ChannelsSender fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ChannelsSender fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ChannelsSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ChannelsSender content = ChannelsSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderReader.java b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderReader.java new file mode 100644 index 0000000000..76d01ca894 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderReader.java @@ -0,0 +1,219 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelsSenderReader extends Reader { + + private String channel; + private Long pageSize; + + public ChannelsSenderReader(final String channel) { + this.channel = channel; + } + + public ChannelsSenderReader setChannel(final String channel) { + this.channel = channel; + return this; + } + + public ChannelsSenderReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "senders", + response.getContent(), + ChannelsSender.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Channels/Senders"; + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "senders", + response.getContent(), + ChannelsSender.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ChannelsSender read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "senders", + response.getContent(), + ChannelsSender.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (channel != null) { + Serializer.toString( + request, + "Channel", + channel, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderUpdater.java b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderUpdater.java new file mode 100644 index 0000000000..4f6ea54527 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/ChannelsSenderUpdater.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ChannelsSenderUpdater extends Updater { + + private String pathSid; + private ChannelsSender.MessagingV2ChannelsSenderRequestsUpdate messagingV2ChannelsSenderRequestsUpdate; + + public ChannelsSenderUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public ChannelsSenderUpdater setMessagingV2ChannelsSenderRequestsUpdate( + final ChannelsSender.MessagingV2ChannelsSenderRequestsUpdate messagingV2ChannelsSenderRequestsUpdate + ) { + this.messagingV2ChannelsSenderRequestsUpdate = + messagingV2ChannelsSenderRequestsUpdate; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Channels/Senders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ChannelsSender update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ChannelsSender update(final TwilioRestClient client) { + Response response = makeRequest(client); + return ChannelsSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ChannelsSender content = ChannelsSender.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (messagingV2ChannelsSenderRequestsUpdate != null) { + request.setBody( + ChannelsSender.toJson( + messagingV2ChannelsSenderRequestsUpdate, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/DomainCerts.java b/src/main/java/com/twilio/rest/messaging/v2/DomainCerts.java new file mode 100644 index 0000000000..8e43197a2d --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/DomainCerts.java @@ -0,0 +1,214 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DomainCerts extends Resource { + + public static DomainCertsFetcher fetcher(final String pathDomainSid) { + return new DomainCertsFetcher(pathDomainSid); + } + + /** + * Converts a JSON String into a DomainCerts object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DomainCerts object represented by the provided JSON + */ + public static DomainCerts fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DomainCerts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DomainCerts object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DomainCerts object represented by the provided JSON + */ + public static DomainCerts fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, DomainCerts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object certInValidation; + + @Getter + private final String certificateSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final URI domainName; + + @Getter + private final String domainSid; + + @Getter + private final Boolean managed; + + @Getter + private final Boolean requesting; + + @Getter + private final URI url; + + @JsonCreator + private DomainCerts( + @JsonProperty("cert_in_validation") final Object certInValidation, + @JsonProperty("certificate_sid") final String certificateSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_name") final URI domainName, + @JsonProperty("domain_sid") final String domainSid, + @JsonProperty("managed") final Boolean managed, + @JsonProperty("requesting") final Boolean requesting, + @JsonProperty("url") final URI url + ) { + this.certInValidation = certInValidation; + this.certificateSid = certificateSid; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.domainName = domainName; + this.domainSid = domainSid; + this.managed = managed; + this.requesting = requesting; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DomainCerts other = (DomainCerts) o; + return ( + Objects.equals(certInValidation, other.certInValidation) && + Objects.equals(certificateSid, other.certificateSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainName, other.domainName) && + Objects.equals(domainSid, other.domainSid) && + Objects.equals(managed, other.managed) && + Objects.equals(requesting, other.requesting) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + certInValidation, + certificateSid, + dateCreated, + dateExpires, + dateUpdated, + domainName, + domainSid, + managed, + requesting, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/DomainCertsFetcher.java b/src/main/java/com/twilio/rest/messaging/v2/DomainCertsFetcher.java new file mode 100644 index 0000000000..801d17bf3b --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/DomainCertsFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DomainCertsFetcher extends Fetcher { + + private String pathDomainSid; + + public DomainCertsFetcher(final String pathDomainSid) { + this.pathDomainSid = pathDomainSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/LinkShortening/Domains/{DomainSid}/Certificate"; + + path = + path.replace( + "{" + "DomainSid" + "}", + this.pathDomainSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "DomainCerts fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public DomainCerts fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DomainCerts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DomainCerts content = DomainCerts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/TypingIndicator.java b/src/main/java/com/twilio/rest/messaging/v2/TypingIndicator.java new file mode 100644 index 0000000000..95306b21b0 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/TypingIndicator.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TypingIndicator extends Resource { + + public static TypingIndicatorCreator creator( + final TypingIndicator.Channel channel, + final String messageId + ) { + return new TypingIndicatorCreator(channel, messageId); + } + + public enum Channel { + WHATSAPP("whatsapp"); + + private final String value; + + private Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Channel forValue(final String value) { + return Promoter.enumFromString(value, Channel.values()); + } + } + + /** + * Converts a JSON String into a TypingIndicator object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TypingIndicator object represented by the provided JSON + */ + public static TypingIndicator fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TypingIndicator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TypingIndicator object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TypingIndicator object represented by the provided JSON + */ + public static TypingIndicator fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TypingIndicator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean success; + + @JsonCreator + private TypingIndicator(@JsonProperty("success") final Boolean success) { + this.success = success; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TypingIndicator other = (TypingIndicator) o; + return (Objects.equals(success, other.success)); + } + + @Override + public int hashCode() { + return Objects.hash(success); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v2/TypingIndicatorCreator.java b/src/main/java/com/twilio/rest/messaging/v2/TypingIndicatorCreator.java new file mode 100644 index 0000000000..d3f1475d56 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v2/TypingIndicatorCreator.java @@ -0,0 +1,136 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TypingIndicatorCreator extends Creator { + + private TypingIndicator.Channel channel; + private String messageId; + + public TypingIndicatorCreator( + final TypingIndicator.Channel channel, + final String messageId + ) { + this.channel = channel; + this.messageId = messageId; + } + + public TypingIndicatorCreator setChannel( + final TypingIndicator.Channel channel + ) { + this.channel = channel; + return this; + } + + public TypingIndicatorCreator setMessageId(final String messageId) { + this.messageId = messageId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Indicators/Typing.json"; + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TypingIndicator creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TypingIndicator create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TypingIndicator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TypingIndicator content = TypingIndicator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (channel != null) { + Serializer.toString( + request, + "channel", + channel, + ParameterType.URLENCODED + ); + } + + if (messageId != null) { + Serializer.toString( + request, + "messageId", + messageId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v3/MessageCostEstimate.java b/src/main/java/com/twilio/rest/messaging/v3/MessageCostEstimate.java new file mode 100644 index 0000000000..bb370219e7 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v3/MessageCostEstimate.java @@ -0,0 +1,415 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class MessageCostEstimate extends Resource { + + public static MessageCostEstimateFetcher fetcher( + final String country, + final MessageCostEstimate.LookbackWindow lookbackWindow + ) { + return new MessageCostEstimateFetcher(country, lookbackWindow); + } + + public enum LookbackWindow { + L1_D("L1D"), + L7_D("L7D"), + L14_D("L14D"), + L28_D("L28D"); + + private final String value; + + private LookbackWindow(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static LookbackWindow forValue(final String value) { + return Promoter.enumFromString(value, LookbackWindow.values()); + } + } + + @JsonDeserialize(builder = MessageCostEstimateBidLevel.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessageCostEstimateBidLevel { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bidAmount") + @Getter + private final Long bidAmount; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("targetedUsers") + @Getter + private final Long targetedUsers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("estimatedDeliveries") + @Getter + private final MessageCostEstimateRange estimatedDeliveries; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("estimatedCost") + @Getter + private final MessageCostEstimateRange estimatedCost; + + private MessageCostEstimateBidLevel(Builder builder) { + this.bidAmount = builder.bidAmount; + this.targetedUsers = builder.targetedUsers; + this.estimatedDeliveries = builder.estimatedDeliveries; + this.estimatedCost = builder.estimatedCost; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessageCostEstimateBidLevel fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + MessageCostEstimateBidLevel.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("bidAmount") + private Long bidAmount; + + @JsonProperty("targetedUsers") + private Long targetedUsers; + + @JsonProperty("estimatedDeliveries") + private MessageCostEstimateRange estimatedDeliveries; + + @JsonProperty("estimatedCost") + private MessageCostEstimateRange estimatedCost; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bidAmount") + public Builder bidAmount(Long bidAmount) { + this.bidAmount = bidAmount; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("targetedUsers") + public Builder targetedUsers(Long targetedUsers) { + this.targetedUsers = targetedUsers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("estimatedDeliveries") + public Builder estimatedDeliveries( + MessageCostEstimateRange estimatedDeliveries + ) { + this.estimatedDeliveries = estimatedDeliveries; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("estimatedCost") + public Builder estimatedCost( + MessageCostEstimateRange estimatedCost + ) { + this.estimatedCost = estimatedCost; + return this; + } + + public MessageCostEstimateBidLevel build() { + return new MessageCostEstimateBidLevel(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessageCostEstimateBidLevel other = (MessageCostEstimateBidLevel) o; + return ( + Objects.equals(bidAmount, other.bidAmount) && + Objects.equals(targetedUsers, other.targetedUsers) && + Objects.equals( + estimatedDeliveries, + other.estimatedDeliveries + ) && + Objects.equals(estimatedCost, other.estimatedCost) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + bidAmount, + targetedUsers, + estimatedDeliveries, + estimatedCost + ); + } + } + + @JsonDeserialize(builder = MessageCostEstimateRange.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class MessageCostEstimateRange { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("lower") + @Getter + private final BigDecimal lower; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("upper") + @Getter + private final BigDecimal upper; + + private MessageCostEstimateRange(Builder builder) { + this.lower = builder.lower; + this.upper = builder.upper; + } + + public static Builder builder() { + return new Builder(); + } + + public static MessageCostEstimateRange fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, MessageCostEstimateRange.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("lower") + private BigDecimal lower; + + @JsonProperty("upper") + private BigDecimal upper; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("lower") + public Builder lower(BigDecimal lower) { + this.lower = lower; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("upper") + public Builder upper(BigDecimal upper) { + this.upper = upper; + return this; + } + + public MessageCostEstimateRange build() { + return new MessageCostEstimateRange(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessageCostEstimateRange other = (MessageCostEstimateRange) o; + return ( + Objects.equals(lower, other.lower) && + Objects.equals(upper, other.upper) + ); + } + + @Override + public int hashCode() { + return Objects.hash(lower, upper); + } + } + + /** + * Converts a JSON String into a MessageCostEstimate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return MessageCostEstimate object represented by the provided JSON + */ + public static MessageCostEstimate fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, MessageCostEstimate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a MessageCostEstimate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return MessageCostEstimate object represented by the provided JSON + */ + public static MessageCostEstimate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, MessageCostEstimate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String country; + + @Getter + private final String currency; + + @Getter + private final String disclaimer; + + @Getter + private final List estimates; + + @Getter + private final MessageCostEstimate.LookbackWindow lookbackWindow; + + @JsonCreator + private MessageCostEstimate( + @JsonProperty("country") final String country, + @JsonProperty("currency") final String currency, + @JsonProperty("disclaimer") final String disclaimer, + @JsonProperty("estimates") final List< + MessageCostEstimateBidLevel + > estimates, + @JsonProperty( + "lookbackWindow" + ) final MessageCostEstimate.LookbackWindow lookbackWindow + ) { + this.country = country; + this.currency = currency; + this.disclaimer = disclaimer; + this.estimates = estimates; + this.lookbackWindow = lookbackWindow; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessageCostEstimate other = (MessageCostEstimate) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(currency, other.currency) && + Objects.equals(disclaimer, other.disclaimer) && + Objects.equals(estimates, other.estimates) && + Objects.equals(lookbackWindow, other.lookbackWindow) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + country, + currency, + disclaimer, + estimates, + lookbackWindow + ); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v3/MessageCostEstimateFetcher.java b/src/main/java/com/twilio/rest/messaging/v3/MessageCostEstimateFetcher.java new file mode 100644 index 0000000000..5697669a4b --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v3/MessageCostEstimateFetcher.java @@ -0,0 +1,134 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class MessageCostEstimateFetcher extends Fetcher { + + private String country; + private MessageCostEstimate.LookbackWindow lookbackWindow; + + public MessageCostEstimateFetcher( + final String country, + final MessageCostEstimate.LookbackWindow lookbackWindow + ) { + this.country = country; + this.lookbackWindow = lookbackWindow; + } + + public MessageCostEstimateFetcher setCountry(final String country) { + this.country = country; + return this; + } + + public MessageCostEstimateFetcher setLookbackWindow( + final MessageCostEstimate.LookbackWindow lookbackWindow + ) { + this.lookbackWindow = lookbackWindow; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/MessageCostEstimate"; + + Request request = new Request( + HttpMethod.GET, + Domains.MESSAGING.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "MessageCostEstimate fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public MessageCostEstimate fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return MessageCostEstimate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + MessageCostEstimate content = MessageCostEstimate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (country != null) { + Serializer.toString( + request, + "country", + country, + ParameterType.QUERY + ); + } + + if (lookbackWindow != null) { + Serializer.toString( + request, + "lookbackWindow", + lookbackWindow, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v3/TypingIndicator.java b/src/main/java/com/twilio/rest/messaging/v3/TypingIndicator.java new file mode 100644 index 0000000000..f93a3481ef --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v3/TypingIndicator.java @@ -0,0 +1,312 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TypingIndicator extends Resource { + + public static TypingIndicatorCreator creator( + final TypingIndicator.TypingIndicatorRequest typingIndicatorRequest + ) { + return new TypingIndicatorCreator(typingIndicatorRequest); + } + + public enum Channel { + WHATSAPP("WHATSAPP"), + APPLE("APPLE"), + RCS("RCS"); + + private final String value; + + private Channel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Channel forValue(final String value) { + return Promoter.enumFromString(value, Channel.values()); + } + } + + public enum Event { + START("START"), + END("END"); + + private final String value; + + private Event(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Event forValue(final String value) { + return Promoter.enumFromString(value, Event.values()); + } + } + + @JsonDeserialize(builder = TypingIndicatorRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TypingIndicatorRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + @Getter + private final TypingIndicator.Channel channel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("messageId") + @Getter + private final String messageId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("from") + @Getter + private final String from; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + @Getter + private final String to; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("event") + @Getter + private final TypingIndicator.Event event; + + private TypingIndicatorRequest(Builder builder) { + this.channel = builder.channel; + this.messageId = builder.messageId; + this.from = builder.from; + this.to = builder.to; + this.event = builder.event; + } + + public static Builder builder() { + return new Builder(); + } + + public static TypingIndicatorRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, TypingIndicatorRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("channel") + private TypingIndicator.Channel channel; + + @JsonProperty("messageId") + private String messageId; + + @JsonProperty("from") + private String from; + + @JsonProperty("to") + private String to; + + @JsonProperty("event") + private TypingIndicator.Event event; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("channel") + public Builder channel(TypingIndicator.Channel channel) { + this.channel = channel; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("messageId") + public Builder messageId(String messageId) { + this.messageId = messageId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("from") + public Builder from(String from) { + this.from = from; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + public Builder to(String to) { + this.to = to; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("event") + public Builder event(TypingIndicator.Event event) { + this.event = event; + return this; + } + + public TypingIndicatorRequest build() { + return new TypingIndicatorRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TypingIndicatorRequest other = (TypingIndicatorRequest) o; + return ( + Objects.equals(channel, other.channel) && + Objects.equals(messageId, other.messageId) && + Objects.equals(from, other.from) && + Objects.equals(to, other.to) && + Objects.equals(event, other.event) + ); + } + + @Override + public int hashCode() { + return Objects.hash(channel, messageId, from, to, event); + } + } + + /** + * Converts a JSON String into a TypingIndicator object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TypingIndicator object represented by the provided JSON + */ + public static TypingIndicator fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TypingIndicator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TypingIndicator object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TypingIndicator object represented by the provided JSON + */ + public static TypingIndicator fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TypingIndicator.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean success; + + @JsonCreator + private TypingIndicator(@JsonProperty("success") final Boolean success) { + this.success = success; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TypingIndicator other = (TypingIndicator) o; + return (Objects.equals(success, other.success)); + } + + @Override + public int hashCode() { + return Objects.hash(success); + } +} diff --git a/src/main/java/com/twilio/rest/messaging/v3/TypingIndicatorCreator.java b/src/main/java/com/twilio/rest/messaging/v3/TypingIndicatorCreator.java new file mode 100644 index 0000000000..6ff19551f4 --- /dev/null +++ b/src/main/java/com/twilio/rest/messaging/v3/TypingIndicatorCreator.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Messaging + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.messaging.v3; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TypingIndicatorCreator extends Creator { + + private TypingIndicator.TypingIndicatorRequest typingIndicatorRequest; + + public TypingIndicatorCreator( + final TypingIndicator.TypingIndicatorRequest typingIndicatorRequest + ) { + this.typingIndicatorRequest = typingIndicatorRequest; + } + + public TypingIndicatorCreator setTypingIndicatorRequest( + final TypingIndicator.TypingIndicatorRequest typingIndicatorRequest + ) { + this.typingIndicatorRequest = typingIndicatorRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/Indicators/Typing.json"; + + Request request = new Request( + HttpMethod.POST, + Domains.MESSAGING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TypingIndicator creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TypingIndicator create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TypingIndicator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TypingIndicator content = TypingIndicator.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (typingIndicatorRequest != null) { + request.setBody( + TypingIndicator.toJson(typingIndicatorRequest, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/monitor/v1/Alert.java b/src/main/java/com/twilio/rest/monitor/v1/Alert.java index 0a008bb271..6ac8bf61e1 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/Alert.java +++ b/src/main/java/com/twilio/rest/monitor/v1/Alert.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Monitor + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.monitor.v1; @@ -11,68 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Alert extends Resource { - private static final long serialVersionUID = 84420812948753L; - /** - * Create a AlertFetcher to execute fetch. - * - * @param pathSid The sid - * @return AlertFetcher capable of executing the fetch - */ public static AlertFetcher fetcher(final String pathSid) { return new AlertFetcher(pathSid); } - /** - * Create a AlertDeleter to execute delete. - * - * @param pathSid The sid - * @return AlertDeleter capable of executing the delete - */ - public static AlertDeleter deleter(final String pathSid) { - return new AlertDeleter(pathSid); - } - - /** - * Create a AlertReader to execute read. - * - * @return AlertReader capable of executing the read - */ public static AlertReader reader() { return new AlertReader(); } /** * Converts a JSON String into a Alert object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Alert object represented by the provided JSON */ - public static Alert fromJson(final String json, final ObjectMapper objectMapper) { + public static Alert fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Alert.class); @@ -86,12 +75,15 @@ public static Alert fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Alert object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Alert object represented by the provided JSON */ - public static Alert fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Alert fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Alert.class); @@ -102,242 +94,133 @@ public static Alert fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String alertText; + + @Getter private final String apiVersion; - private final DateTime dateCreated; - private final DateTime dateGenerated; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateGenerated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String errorCode; + + @Getter private final String logLevel; + + @Getter private final String moreInfo; + + @Getter + private final String requestHeaders; + + @Getter private final HttpMethod requestMethod; + + @Getter private final String requestUrl; + + @Getter private final String requestVariables; + + @Getter private final String resourceSid; + + @Getter private final String responseBody; + + @Getter private final String responseHeaders; + + @Getter + private final String serviceSid; + + @Getter private final String sid; + + @Getter private final URI url; @JsonCreator - private Alert(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("alert_text") - final String alertText, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_generated") - final String dateGenerated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("error_code") - final String errorCode, - @JsonProperty("log_level") - final String logLevel, - @JsonProperty("more_info") - final String moreInfo, - @JsonProperty("request_method") - final HttpMethod requestMethod, - @JsonProperty("request_url") - final String requestUrl, - @JsonProperty("request_variables") - final String requestVariables, - @JsonProperty("resource_sid") - final String resourceSid, - @JsonProperty("response_body") - final String responseBody, - @JsonProperty("response_headers") - final String responseHeaders, - @JsonProperty("sid") - final String sid, - @JsonProperty("url") - final URI url) { + private Alert( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("alert_text") final String alertText, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_generated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateGenerated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("error_code") final String errorCode, + @JsonProperty("log_level") final String logLevel, + @JsonProperty("more_info") final String moreInfo, + @JsonProperty("request_headers") final String requestHeaders, + @JsonProperty("request_method") final HttpMethod requestMethod, + @JsonProperty("request_url") final String requestUrl, + @JsonProperty("request_variables") final String requestVariables, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("response_body") final String responseBody, + @JsonProperty("response_headers") final String responseHeaders, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.alertText = alertText; this.apiVersion = apiVersion; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateGenerated = DateConverter.iso8601DateTimeFromString(dateGenerated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateGenerated = dateGenerated; + this.dateUpdated = dateUpdated; this.errorCode = errorCode; this.logLevel = logLevel; this.moreInfo = moreInfo; + this.requestHeaders = requestHeaders; this.requestMethod = requestMethod; this.requestUrl = requestUrl; this.requestVariables = requestVariables; this.resourceSid = resourceSid; this.responseBody = responseBody; this.responseHeaders = responseHeaders; + this.serviceSid = serviceSid; this.sid = sid; this.url = url; } - /** - * Returns The The unique id of the Account responsible for this alert.. - * - * @return The unique id of the Account responsible for this alert. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The text of the alert.. - * - * @return The text of the alert. - */ - public final String getAlertText() { - return this.alertText; - } - - /** - * Returns The The version of the Twilio API in use when this alert was - * generated.. - * - * @return The version of the Twilio API in use when this alert was generated. - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The date that this resource was created, given in ISO 8601 - * format.. - * - * @return The date that this resource was created, given in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date the alert was actually generated, given in ISO 8601 - * format.. - * - * @return The date the alert was actually generated, given in ISO 8601 format. - */ - public final DateTime getDateGenerated() { - return this.dateGenerated; - } - - /** - * Returns The The most recent date that this resource was updated, given in ISO - * 8601 format.. - * - * @return The most recent date that this resource was updated, given in ISO - * 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A unique error code for the error condition.. - * - * @return A unique error code for the error condition. - */ - public final String getErrorCode() { - return this.errorCode; - } - - /** - * Returns The A string representing the log level.. - * - * @return A string representing the log level. - */ - public final String getLogLevel() { - return this.logLevel; - } - - /** - * Returns The A URL for more information about the error condition.. - * - * @return A URL for more information about the error condition. - */ - public final String getMoreInfo() { - return this.moreInfo; - } - - /** - * Returns The If the Alert was generated by a request Twilio made to your - * server, this will be the request method used when Twilio made the request to - * your server.. - * - * @return If the Alert was generated by a request Twilio made to your server, - * this will be the request method used when Twilio made the request to - * your server. - */ - public final HttpMethod getRequestMethod() { - return this.requestMethod; - } - - /** - * Returns The If the Alert was generated by a request Twilio made to your - * server, this will be the URL on your server that generated the alert.. - * - * @return If the Alert was generated by a request Twilio made to your server, - * this will be the URL on your server that generated the alert. - */ - public final String getRequestUrl() { - return this.requestUrl; - } - - /** - * Returns The The request_variables. - * - * @return The request_variables - */ - public final String getRequestVariables() { - return this.requestVariables; - } - - /** - * Returns The The unique ID of the resource for which the Alert was generated.. - * - * @return The unique ID of the resource for which the Alert was generated. - */ - public final String getResourceSid() { - return this.resourceSid; - } - - /** - * Returns The The response_body. - * - * @return The response_body - */ - public final String getResponseBody() { - return this.responseBody; - } - - /** - * Returns The The response_headers. - * - * @return The response_headers - */ - public final String getResponseHeaders() { - return this.responseHeaders; - } - - /** - * Returns The A 34 character string that uniquely identifies this Alert.. - * - * @return A 34 character string that uniquely identifies this Alert. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The absolute URL for this resource.. - * - * @return The absolute URL for this resource. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -349,67 +232,51 @@ public boolean equals(final Object o) { } Alert other = (Alert) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(alertText, other.alertText) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateGenerated, other.dateGenerated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(errorCode, other.errorCode) && - Objects.equals(logLevel, other.logLevel) && - Objects.equals(moreInfo, other.moreInfo) && - Objects.equals(requestMethod, other.requestMethod) && - Objects.equals(requestUrl, other.requestUrl) && - Objects.equals(requestVariables, other.requestVariables) && - Objects.equals(resourceSid, other.resourceSid) && - Objects.equals(responseBody, other.responseBody) && - Objects.equals(responseHeaders, other.responseHeaders) && - Objects.equals(sid, other.sid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(alertText, other.alertText) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateGenerated, other.dateGenerated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(logLevel, other.logLevel) && + Objects.equals(moreInfo, other.moreInfo) && + Objects.equals(requestHeaders, other.requestHeaders) && + Objects.equals(requestMethod, other.requestMethod) && + Objects.equals(requestUrl, other.requestUrl) && + Objects.equals(requestVariables, other.requestVariables) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(responseBody, other.responseBody) && + Objects.equals(responseHeaders, other.responseHeaders) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - alertText, - apiVersion, - dateCreated, - dateGenerated, - dateUpdated, - errorCode, - logLevel, - moreInfo, - requestMethod, - requestUrl, - requestVariables, - resourceSid, - responseBody, - responseHeaders, - sid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("alertText", alertText) - .add("apiVersion", apiVersion) - .add("dateCreated", dateCreated) - .add("dateGenerated", dateGenerated) - .add("dateUpdated", dateUpdated) - .add("errorCode", errorCode) - .add("logLevel", logLevel) - .add("moreInfo", moreInfo) - .add("requestMethod", requestMethod) - .add("requestUrl", requestUrl) - .add("requestVariables", requestVariables) - .add("resourceSid", resourceSid) - .add("responseBody", responseBody) - .add("responseHeaders", responseHeaders) - .add("sid", sid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + alertText, + apiVersion, + dateCreated, + dateGenerated, + dateUpdated, + errorCode, + logLevel, + moreInfo, + requestHeaders, + requestMethod, + requestUrl, + requestVariables, + resourceSid, + responseBody, + responseHeaders, + serviceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/monitor/v1/AlertDeleter.java b/src/main/java/com/twilio/rest/monitor/v1/AlertDeleter.java deleted file mode 100644 index 4f07f1e8cb..0000000000 --- a/src/main/java/com/twilio/rest/monitor/v1/AlertDeleter.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.monitor.v1; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -public class AlertDeleter extends Deleter { - private final String pathSid; - - /** - * Construct a new AlertDeleter. - * - * @param pathSid The sid - */ - public AlertDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.MONITOR.toString(), - "/v1/Alerts/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Alert delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/monitor/v1/AlertFetcher.java b/src/main/java/com/twilio/rest/monitor/v1/AlertFetcher.java index 860caddd33..06c152942e 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/AlertFetcher.java +++ b/src/main/java/com/twilio/rest/monitor/v1/AlertFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Monitor + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.monitor.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class AlertFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new AlertFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public AlertFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Alert - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Alert fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Alerts/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.MONITOR.toString(), - "/v1/Alerts/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Alert fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Alert fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Alert fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Alert.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Alert content = Alert.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/monitor/v1/AlertReader.java b/src/main/java/com/twilio/rest/monitor/v1/AlertReader.java index 330d6b0ef9..1bdf5ddf7e 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/AlertReader.java +++ b/src/main/java/com/twilio/rest/monitor/v1/AlertReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Monitor + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.monitor.v1; @@ -10,208 +17,228 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class AlertReader extends Reader { + private String logLevel; - private LocalDate startDate; - private LocalDate endDate; - - /** - * Only show alerts for this log-level. One of 'error', 'warning', 'notice', or - * 'debug'.. - * - * @param logLevel Only show alerts for this log-level. - * @return this - */ + private ZonedDateTime startDate; + private ZonedDateTime endDate; + private Long pageSize; + + public AlertReader() {} + public AlertReader setLogLevel(final String logLevel) { this.logLevel = logLevel; return this; } - /** - * Only show Alerts on or after this date. Useful in combination with `EndDate` - * to define a date-range of Alerts. Input is a [UTC ISO 8601 - * Timestamp](http://en.wikipedia.org/wiki/ISO_8601#UTC), but time of day is - * ignored by the filter. Queries for Alerts older than 30 days are not - * supported.. - * - * @param startDate Only show Alerts on or after this date. - * @return this - */ - public AlertReader setStartDate(final LocalDate startDate) { + public AlertReader setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - /** - * Only show Alerts on or before this date. Useful in combination with - * `StartDate` to define a date-range of Alerts. Input is a [UTC ISO 8601 - * Timestamp](http://en.wikipedia.org/wiki/ISO_8601#UTC), but time of day is - * ignored by the filter. Queries for Alerts older than 30 days are not - * supported.. - * - * @param endDate Only show Alerts on or before this date. - * @return this - */ - public AlertReader setEndDate(final LocalDate endDate) { + public AlertReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Alert ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AlertReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Alert ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "alerts", + response.getContent(), + Alert.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Alerts"; + Request request = new Request( HttpMethod.GET, Domains.MONITOR.toString(), - "/v1/Alerts", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Alert ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "alerts", + response.getContent(), + Alert.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Alert read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "alerts", + response.getContent(), + Alert.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.MONITOR.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.MONITOR.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Alert Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Alert read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "alerts", - response.getContent(), - Alert.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (logLevel != null) { - request.addQueryParam("LogLevel", logLevel); + Serializer.toString( + request, + "LogLevel", + logLevel, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/monitor/v1/Event.java b/src/main/java/com/twilio/rest/monitor/v1/Event.java index 5fee969527..d0dca1b3af 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/Event.java +++ b/src/main/java/com/twilio/rest/monitor/v1/Event.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Monitor + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.monitor.v1; @@ -11,59 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Event extends Resource { - private static final long serialVersionUID = 124591176455880L; - /** - * Create a EventFetcher to execute fetch. - * - * @param pathSid The sid - * @return EventFetcher capable of executing the fetch - */ public static EventFetcher fetcher(final String pathSid) { return new EventFetcher(pathSid); } - /** - * Create a EventReader to execute read. - * - * @return EventReader capable of executing the read - */ public static EventReader reader() { return new EventReader(); } /** * Converts a JSON String into a Event object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Event object represented by the provided JSON */ - public static Event fromJson(final String json, final ObjectMapper objectMapper) { + public static Event fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -77,12 +75,15 @@ public static Event fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Event object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Event object represented by the provided JSON */ - public static Event fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Event fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -93,196 +94,96 @@ public static Event fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String actorSid; + + @Getter private final String actorType; + + @Getter private final String description; - private final Map eventData; - private final DateTime eventDate; + + @Getter + private final Object eventData; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime eventDate; + + @Getter private final String eventType; + + @Getter + private final Map links; + + @Getter private final String resourceSid; + + @Getter private final String resourceType; + + @Getter private final String sid; + + @Getter private final String source; + + @Getter private final String sourceIpAddress; + + @Getter private final URI url; - private final Map links; @JsonCreator - private Event(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("actor_sid") - final String actorSid, - @JsonProperty("actor_type") - final String actorType, - @JsonProperty("description") - final String description, - @JsonProperty("event_data") - final Map eventData, - @JsonProperty("event_date") - final String eventDate, - @JsonProperty("event_type") - final String eventType, - @JsonProperty("resource_sid") - final String resourceSid, - @JsonProperty("resource_type") - final String resourceType, - @JsonProperty("sid") - final String sid, - @JsonProperty("source") - final String source, - @JsonProperty("source_ip_address") - final String sourceIpAddress, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { + private Event( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("actor_sid") final String actorSid, + @JsonProperty("actor_type") final String actorType, + @JsonProperty("description") final String description, + @JsonProperty("event_data") final Object eventData, + @JsonProperty("event_date") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime eventDate, + @JsonProperty("event_type") final String eventType, + @JsonProperty("links") final Map links, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("sid") final String sid, + @JsonProperty("source") final String source, + @JsonProperty("source_ip_address") final String sourceIpAddress, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.actorSid = actorSid; this.actorType = actorType; this.description = description; this.eventData = eventData; - this.eventDate = DateConverter.iso8601DateTimeFromString(eventDate); + this.eventDate = eventDate; this.eventType = eventType; + this.links = links; this.resourceSid = resourceSid; this.resourceType = resourceType; this.sid = sid; this.source = source; this.sourceIpAddress = sourceIpAddress; this.url = url; - this.links = links; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The actor_sid. - * - * @return The actor_sid - */ - public final String getActorSid() { - return this.actorSid; - } - - /** - * Returns The The actor_type. - * - * @return The actor_type - */ - public final String getActorType() { - return this.actorType; - } - - /** - * Returns The A human-readable description of the event. May be null.. - * - * @return A human-readable description of the event. May be null. - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The The event_data. - * - * @return The event_data - */ - public final Map getEventData() { - return this.eventData; - } - - /** - * Returns The The event_date. - * - * @return The event_date - */ - public final DateTime getEventDate() { - return this.eventDate; - } - - /** - * Returns The The event_type. - * - * @return The event_type - */ - public final String getEventType() { - return this.eventType; - } - - /** - * Returns The The resource_sid. - * - * @return The resource_sid - */ - public final String getResourceSid() { - return this.resourceSid; - } - - /** - * Returns The The resource_type. - * - * @return The resource_type - */ - public final String getResourceType() { - return this.resourceType; - } - - /** - * Returns The A 34 character string that uniquely identifies this event.. - * - * @return A 34 character string that uniquely identifies this event. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The originating system or interface that caused the event. web - * for events caused by user action in the Twilio Console. api for events - * caused through a request to the REST API. twilio for events caused by an - * automated or internal Twilio system.. - * - * @return The originating system or interface that caused the event. web for - * events caused by user action in the Twilio Console. api for events - * caused through a request to the REST API. twilio for events caused - * by an automated or internal Twilio system. - */ - public final String getSource() { - return this.source; - } - - /** - * Returns The The source_ip_address. - * - * @return The source_ip_address - */ - public final String getSourceIpAddress() { - return this.sourceIpAddress; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -296,58 +197,41 @@ public boolean equals(final Object o) { } Event other = (Event) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(actorSid, other.actorSid) && - Objects.equals(actorType, other.actorType) && - Objects.equals(description, other.description) && - Objects.equals(eventData, other.eventData) && - Objects.equals(eventDate, other.eventDate) && - Objects.equals(eventType, other.eventType) && - Objects.equals(resourceSid, other.resourceSid) && - Objects.equals(resourceType, other.resourceType) && - Objects.equals(sid, other.sid) && - Objects.equals(source, other.source) && - Objects.equals(sourceIpAddress, other.sourceIpAddress) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(actorSid, other.actorSid) && + Objects.equals(actorType, other.actorType) && + Objects.equals(description, other.description) && + Objects.equals(eventData, other.eventData) && + Objects.equals(eventDate, other.eventDate) && + Objects.equals(eventType, other.eventType) && + Objects.equals(links, other.links) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(sid, other.sid) && + Objects.equals(source, other.source) && + Objects.equals(sourceIpAddress, other.sourceIpAddress) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - actorSid, - actorType, - description, - eventData, - eventDate, - eventType, - resourceSid, - resourceType, - sid, - source, - sourceIpAddress, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("actorSid", actorSid) - .add("actorType", actorType) - .add("description", description) - .add("eventData", eventData) - .add("eventDate", eventDate) - .add("eventType", eventType) - .add("resourceSid", resourceSid) - .add("resourceType", resourceType) - .add("sid", sid) - .add("source", source) - .add("sourceIpAddress", sourceIpAddress) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + actorSid, + actorType, + description, + eventData, + eventDate, + eventType, + links, + resourceSid, + resourceType, + sid, + source, + sourceIpAddress, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/monitor/v1/EventFetcher.java b/src/main/java/com/twilio/rest/monitor/v1/EventFetcher.java index ab0123ead6..12b2115a55 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/EventFetcher.java +++ b/src/main/java/com/twilio/rest/monitor/v1/EventFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Monitor + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.monitor.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class EventFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new EventFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public EventFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Event - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Event fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Events/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.MONITOR.toString(), - "/v1/Events/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Event fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Event fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Event fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Event.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Event content = Event.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/monitor/v1/EventReader.java b/src/main/java/com/twilio/rest/monitor/v1/EventReader.java index 5439e919e2..2ca8d5f8e0 100644 --- a/src/main/java/com/twilio/rest/monitor/v1/EventReader.java +++ b/src/main/java/com/twilio/rest/monitor/v1/EventReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Monitor + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.monitor.v1; @@ -10,247 +17,273 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class EventReader extends Reader { + private String actorSid; private String eventType; private String resourceSid; private String sourceIpAddress; - private DateTime startDate; - private DateTime endDate; - - /** - * The actor_sid. - * - * @param actorSid The actor_sid - * @return this - */ + private ZonedDateTime startDate; + private ZonedDateTime endDate; + private Long pageSize; + + public EventReader() {} + public EventReader setActorSid(final String actorSid) { this.actorSid = actorSid; return this; } - /** - * The event_type. - * - * @param eventType The event_type - * @return this - */ public EventReader setEventType(final String eventType) { this.eventType = eventType; return this; } - /** - * The resource_sid. - * - * @param resourceSid The resource_sid - * @return this - */ public EventReader setResourceSid(final String resourceSid) { this.resourceSid = resourceSid; return this; } - /** - * The source_ip_address. - * - * @param sourceIpAddress The source_ip_address - * @return this - */ public EventReader setSourceIpAddress(final String sourceIpAddress) { this.sourceIpAddress = sourceIpAddress; return this; } - /** - * The start_date. - * - * @param startDate The start_date - * @return this - */ - public EventReader setStartDate(final DateTime startDate) { + public EventReader setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - /** - * The end_date. - * - * @param endDate The end_date - * @return this - */ - public EventReader setEndDate(final DateTime endDate) { + public EventReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Event ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public EventReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Event ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Events"; + Request request = new Request( HttpMethod.GET, Domains.MONITOR.toString(), - "/v1/Events", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Event ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Event read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.MONITOR.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.MONITOR.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Event Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Event read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "events", - response.getContent(), - Event.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (actorSid != null) { - request.addQueryParam("ActorSid", actorSid); + Serializer.toString( + request, + "ActorSid", + actorSid, + ParameterType.QUERY + ); } if (eventType != null) { - request.addQueryParam("EventType", eventType); + Serializer.toString( + request, + "EventType", + eventType, + ParameterType.QUERY + ); } if (resourceSid != null) { - request.addQueryParam("ResourceSid", resourceSid); + Serializer.toString( + request, + "ResourceSid", + resourceSid, + ParameterType.QUERY + ); } if (sourceIpAddress != null) { - request.addQueryParam("SourceIpAddress", sourceIpAddress); + Serializer.toString( + request, + "SourceIpAddress", + sourceIpAddress, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/Credential.java b/src/main/java/com/twilio/rest/notify/v1/Credential.java index d3d65ffafa..cdd2c6324a 100644 --- a/src/main/java/com/twilio/rest/notify/v1/Credential.java +++ b/src/main/java/com/twilio/rest/notify/v1/Credential.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; @@ -10,36 +17,52 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Credential extends Resource { - private static final long serialVersionUID = 133884911230690L; + + public static CredentialCreator creator(final Credential.PushService type) { + return new CredentialCreator(type); + } + + public static CredentialDeleter deleter(final String pathSid) { + return new CredentialDeleter(pathSid); + } + + public static CredentialFetcher fetcher(final String pathSid) { + return new CredentialFetcher(pathSid); + } + + public static CredentialReader reader() { + return new CredentialReader(); + } + + public static CredentialUpdater updater(final String pathSid) { + return new CredentialUpdater(pathSid); + } public enum PushService { GCM("gcm"), @@ -52,15 +75,11 @@ private PushService(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a PushService from a string. - * @param value string value - * @return generated PushService - */ @JsonCreator public static PushService forValue(final String value) { return Promoter.enumFromString(value, PushService.values()); @@ -68,63 +87,16 @@ public static PushService forValue(final String value) { } /** - * Create a CredentialReader to execute read. - * - * @return CredentialReader capable of executing the read - */ - public static CredentialReader reader() { - return new CredentialReader(); - } - - /** - * Create a CredentialCreator to execute create. - * - * @param type Credential type, one of "gcm", "fcm", or "apn" - * @return CredentialCreator capable of executing the create - */ - public static CredentialCreator creator(final Credential.PushService type) { - return new CredentialCreator(type); - } - - /** - * Create a CredentialFetcher to execute fetch. - * - * @param pathSid The sid - * @return CredentialFetcher capable of executing the fetch - */ - public static CredentialFetcher fetcher(final String pathSid) { - return new CredentialFetcher(pathSid); - } - - /** - * Create a CredentialUpdater to execute update. - * - * @param pathSid The sid - * @return CredentialUpdater capable of executing the update - */ - public static CredentialUpdater updater(final String pathSid) { - return new CredentialUpdater(pathSid); - } - - /** - * Create a CredentialDeleter to execute delete. - * - * @param pathSid The sid - * @return CredentialDeleter capable of executing the delete - */ - public static CredentialDeleter deleter(final String pathSid) { - return new CredentialDeleter(pathSid); - } - - /** - * Converts a JSON String into a Credential object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Credential object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final String json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -138,12 +110,15 @@ public static Credential fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a Credential object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Credential object represented by the provided JSON */ - public static Credential fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Credential fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Credential.class); @@ -154,116 +129,73 @@ public static Credential fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; - private final Credential.PushService type; + + @Getter private final String sandbox; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final Credential.PushService type; + + @Getter private final URI url; @JsonCreator - private Credential(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("type") - final Credential.PushService type, - @JsonProperty("sandbox") - final String sandbox, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private Credential( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sandbox") final String sandbox, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Credential.PushService type, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; - this.type = type; this.sandbox = sandbox; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.sid = sid; + this.type = type; this.url = url; } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Friendly name for stored credential. - * - * @return Friendly name for stored credential - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The Credential type, one of "gcm", "fcm", or "apn". - * - * @return Credential type, one of "gcm", "fcm", or "apn" - */ - public final Credential.PushService getType() { - return this.type; - } - - /** - * Returns The [APN only] use this credential for sending to production or - * sandbox APNs. - * - * @return [APN only] use this credential for sending to production or sandbox - * APNs - */ - public final String getSandbox() { - return this.sandbox; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -275,40 +207,29 @@ public boolean equals(final Object o) { } Credential other = (Credential) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(type, other.type) && - Objects.equals(sandbox, other.sandbox) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sandbox, other.sandbox) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - type, - sandbox, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("type", type) - .add("sandbox", sandbox) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sandbox, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialCreator.java b/src/main/java/com/twilio/rest/notify/v1/CredentialCreator.java index be569a9f57..5735657125 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialCreator.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,13 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class CredentialCreator extends Creator { - private final Credential.PushService type; + + private Credential.PushService type; private String friendlyName; private String certificate; private String privateKey; @@ -30,163 +40,166 @@ public class CredentialCreator extends Creator { private String apiKey; private String secret; - /** - * Construct a new CredentialCreator. - * - * @param type Credential type, one of "gcm", "fcm", or "apn" - */ public CredentialCreator(final Credential.PushService type) { this.type = type; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ + public CredentialCreator setType(final Credential.PushService type) { + this.type = type; + return this; + } + public CredentialCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate. Strip everything - * outside of the headers, e.g. `-----BEGIN - * CERTIFICATE-----MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A==-----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate. - * @return this - */ public CredentialCreator setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key. Strip everything - * outside of the headers, e.g. `-----BEGIN RSA PRIVATE - * KEY-----MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR\n.-----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key. - * @return this - */ public CredentialCreator setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialCreator setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "Server key" of your project from Firebase console - * under Settings / Cloud messaging. Yes, you can use the server key from the - * Firebase console for GCM.. - * - * @param apiKey [GCM only] This is the "Server key" of your project from - * Firebase console under Settings / Cloud messaging. - * @return this - */ public CredentialCreator setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * [FCM only] This is the "Server key" of your project from Firebase console - * under Settings / Cloud messaging.. - * - * @param secret [FCM only] This is the "Server key" of your project from - * Firebase console under Settings / Cloud messaging. - * @return this - */ public CredentialCreator setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials"; + Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), - "/v1/Credentials", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (type != null) { - request.addPostParam("Type", type.toString()); + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialDeleter.java b/src/main/java/com/twilio/rest/notify/v1/CredentialDeleter.java index 227384e522..fa33d843e8 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialDeleter.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class CredentialDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new CredentialDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.NOTIFY.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialFetcher.java b/src/main/java/com/twilio/rest/notify/v1/CredentialFetcher.java index 436fc20a64..703c2f8f09 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialFetcher.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class CredentialFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new CredentialFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public CredentialFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.NOTIFY.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialReader.java b/src/main/java/com/twilio/rest/notify/v1/CredentialReader.java index b883276832..d6f51d49de 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialReader.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; @@ -10,152 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class CredentialReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public CredentialReader() {} + + public CredentialReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Credentials"; + Request request = new Request( HttpMethod.GET, Domains.NOTIFY.toString(), - "/v1/Credentials", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Credential ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Credential read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credentials", + response.getContent(), + Credential.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Credential Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Credential read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credentials", - response.getContent(), - Credential.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/CredentialUpdater.java b/src/main/java/com/twilio/rest/notify/v1/CredentialUpdater.java index e27e036df3..678f597b26 100644 --- a/src/main/java/com/twilio/rest/notify/v1/CredentialUpdater.java +++ b/src/main/java/com/twilio/rest/notify/v1/CredentialUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,13 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class CredentialUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String certificate; private String privateKey; @@ -30,159 +40,154 @@ public class CredentialUpdater extends Updater { private String apiKey; private String secret; - /** - * Construct a new CredentialUpdater. - * - * @param pathSid The sid - */ public CredentialUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Friendly name for stored credential. - * - * @param friendlyName Friendly name for stored credential - * @return this - */ public CredentialUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * [APN only] URL encoded representation of the certificate. Strip everything - * outside of the headers, e.g. `-----BEGIN - * CERTIFICATE-----MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A==-----END CERTIFICATE-----`. - * - * @param certificate [APN only] URL encoded representation of the certificate. - * @return this - */ public CredentialUpdater setCertificate(final String certificate) { this.certificate = certificate; return this; } - /** - * [APN only] URL encoded representation of the private key. Strip everything - * outside of the headers, e.g. `-----BEGIN RSA PRIVATE - * KEY-----MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR\n.-----END RSA PRIVATE KEY-----`. - * - * @param privateKey [APN only] URL encoded representation of the private key. - * @return this - */ public CredentialUpdater setPrivateKey(final String privateKey) { this.privateKey = privateKey; return this; } - /** - * [APN only] use this credential for sending to production or sandbox APNs - * (string `true` or `false`). - * - * @param sandbox [APN only] use this credential for sending to production or - * sandbox APNs - * @return this - */ public CredentialUpdater setSandbox(final Boolean sandbox) { this.sandbox = sandbox; return this; } - /** - * [GCM only] This is the "Server key" of your project from Firebase console - * under Settings / Cloud messaging. Yes, you can use the server key from the - * Firebase console for GCM.. - * - * @param apiKey [GCM only] This is the "Server key" of your project from - * Firebase console under Settings / Cloud messaging. - * @return this - */ public CredentialUpdater setApiKey(final String apiKey) { this.apiKey = apiKey; return this; } - /** - * [FCM only] This is the "Server key" of your project from Firebase console - * under Settings / Cloud messaging.. - * - * @param secret [FCM only] This is the "Server key" of your project from - * Firebase console under Settings / Cloud messaging. - * @return this - */ public CredentialUpdater setSecret(final String secret) { this.secret = secret; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Credential - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Credential update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Credentials/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), - "/v1/Credentials/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Credential update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Credential update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Credential.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Credential update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Credential content = Credential.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (certificate != null) { - request.addPostParam("Certificate", certificate); + Serializer.toString( + request, + "Certificate", + certificate, + ParameterType.URLENCODED + ); } if (privateKey != null) { - request.addPostParam("PrivateKey", privateKey); + Serializer.toString( + request, + "PrivateKey", + privateKey, + ParameterType.URLENCODED + ); } if (sandbox != null) { - request.addPostParam("Sandbox", sandbox.toString()); + Serializer.toString( + request, + "Sandbox", + sandbox, + ParameterType.URLENCODED + ); } if (apiKey != null) { - request.addPostParam("ApiKey", apiKey); + Serializer.toString( + request, + "ApiKey", + apiKey, + ParameterType.URLENCODED + ); } if (secret != null) { - request.addPostParam("Secret", secret); + Serializer.toString( + request, + "Secret", + secret, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/Service.java b/src/main/java/com/twilio/rest/notify/v1/Service.java index e79f09cbcd..83b23c5c1a 100644 --- a/src/main/java/com/twilio/rest/notify/v1/Service.java +++ b/src/main/java/com/twilio/rest/notify/v1/Service.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; @@ -11,91 +18,62 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Service extends Resource { - private static final long serialVersionUID = 76800844046701L; - /** - * Create a ServiceCreator to execute create. - * - * @return ServiceCreator capable of executing the create - */ public static ServiceCreator creator() { return new ServiceCreator(); } - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid The sid - * @return ServiceDeleter capable of executing the delete - */ public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid The sid - * @return ServiceFetcher capable of executing the fetch - */ public static ServiceFetcher fetcher(final String pathSid) { return new ServiceFetcher(pathSid); } - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ public static ServiceReader reader() { return new ServiceReader(); } - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid The sid - * @return ServiceUpdater capable of executing the update - */ public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** * Converts a JSON String into a Service object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -109,12 +87,15 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Service object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -125,246 +106,147 @@ public static Service fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String apnCredentialSid; - private final String gcmCredentialSid; - private final String fcmCredentialSid; - private final String messagingServiceSid; - private final String facebookMessengerPageId; - private final String defaultApnNotificationProtocolVersion; - private final String defaultGcmNotificationProtocolVersion; - private final String defaultFcmNotificationProtocolVersion; - private final Boolean logEnabled; - private final URI url; - private final Map links; + + @Getter private final String alexaSkillId; - private final String defaultAlexaNotificationProtocolVersion; - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("apn_credential_sid") - final String apnCredentialSid, - @JsonProperty("gcm_credential_sid") - final String gcmCredentialSid, - @JsonProperty("fcm_credential_sid") - final String fcmCredentialSid, - @JsonProperty("messaging_service_sid") - final String messagingServiceSid, - @JsonProperty("facebook_messenger_page_id") - final String facebookMessengerPageId, - @JsonProperty("default_apn_notification_protocol_version") - final String defaultApnNotificationProtocolVersion, - @JsonProperty("default_gcm_notification_protocol_version") - final String defaultGcmNotificationProtocolVersion, - @JsonProperty("default_fcm_notification_protocol_version") - final String defaultFcmNotificationProtocolVersion, - @JsonProperty("log_enabled") - final Boolean logEnabled, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links, - @JsonProperty("alexa_skill_id") - final String alexaSkillId, - @JsonProperty("default_alexa_notification_protocol_version") - final String defaultAlexaNotificationProtocolVersion) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.apnCredentialSid = apnCredentialSid; - this.gcmCredentialSid = gcmCredentialSid; - this.fcmCredentialSid = fcmCredentialSid; - this.messagingServiceSid = messagingServiceSid; - this.facebookMessengerPageId = facebookMessengerPageId; - this.defaultApnNotificationProtocolVersion = defaultApnNotificationProtocolVersion; - this.defaultGcmNotificationProtocolVersion = defaultGcmNotificationProtocolVersion; - this.defaultFcmNotificationProtocolVersion = defaultFcmNotificationProtocolVersion; - this.logEnabled = logEnabled; - this.url = url; - this.links = links; - this.alexaSkillId = alexaSkillId; - this.defaultAlexaNotificationProtocolVersion = defaultAlexaNotificationProtocolVersion; - } + @Getter + private final String apnCredentialSid; - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The Human-readable name for this service instance. - * - * @return Human-readable name for this service instance - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String defaultAlexaNotificationProtocolVersion; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String defaultApnNotificationProtocolVersion; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String defaultFcmNotificationProtocolVersion; - /** - * Returns The The SID of the Credential to be used for APN Bindings.. - * - * @return The SID of the Credential to be used for APN Bindings. - */ - public final String getApnCredentialSid() { - return this.apnCredentialSid; - } + @Getter + private final String defaultGcmNotificationProtocolVersion; - /** - * Returns The The SID of the Credential to be used for GCM Bindings.. - * - * @return The SID of the Credential to be used for GCM Bindings. - */ - public final String getGcmCredentialSid() { - return this.gcmCredentialSid; - } + @Getter + private final Boolean deliveryCallbackEnabled; - /** - * Returns The The SID of the Credential to be used for FCM Bindings.. - * - * @return The SID of the Credential to be used for FCM Bindings. - */ - public final String getFcmCredentialSid() { - return this.fcmCredentialSid; - } + @Getter + private final String deliveryCallbackUrl; - /** - * Returns The The SID of the Messaging Service to be used for SMS Bindings.. - * - * @return The SID of the Messaging Service to be used for SMS Bindings. - */ - public final String getMessagingServiceSid() { - return this.messagingServiceSid; - } + @Getter + private final String facebookMessengerPageId; - /** - * Returns The The Page ID to be used to send for Facebook Messenger Bindings.. - * - * @return The Page ID to be used to send for Facebook Messenger Bindings. - */ - public final String getFacebookMessengerPageId() { - return this.facebookMessengerPageId; - } + @Getter + private final String fcmCredentialSid; - /** - * Returns The The version of the protocol to be used for sending APNS - * notifications.. - * - * @return The version of the protocol to be used for sending APNS - * notifications. - */ - public final String getDefaultApnNotificationProtocolVersion() { - return this.defaultApnNotificationProtocolVersion; - } + @Getter + private final String friendlyName; - /** - * Returns The The version of the protocol to be used for sending GCM - * notifications.. - * - * @return The version of the protocol to be used for sending GCM notifications. - */ - public final String getDefaultGcmNotificationProtocolVersion() { - return this.defaultGcmNotificationProtocolVersion; - } + @Getter + private final String gcmCredentialSid; - /** - * Returns The The version of the protocol to be used for sending FCM - * notifications.. - * - * @return The version of the protocol to be used for sending FCM notifications. - */ - public final String getDefaultFcmNotificationProtocolVersion() { - return this.defaultFcmNotificationProtocolVersion; - } + @Getter + private final Map links; - /** - * Returns The The log_enabled. - * - * @return The log_enabled - */ - public final Boolean getLogEnabled() { - return this.logEnabled; - } + @Getter + private final Boolean logEnabled; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String messagingServiceSid; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } + @Getter + private final String sid; - /** - * Returns The The alexa_skill_id. - * - * @return The alexa_skill_id - */ - public final String getAlexaSkillId() { - return this.alexaSkillId; - } + @Getter + private final URI url; - /** - * Returns The The default_alexa_notification_protocol_version. - * - * @return The default_alexa_notification_protocol_version - */ - public final String getDefaultAlexaNotificationProtocolVersion() { - return this.defaultAlexaNotificationProtocolVersion; + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("alexa_skill_id") final String alexaSkillId, + @JsonProperty("apn_credential_sid") final String apnCredentialSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "default_alexa_notification_protocol_version" + ) final String defaultAlexaNotificationProtocolVersion, + @JsonProperty( + "default_apn_notification_protocol_version" + ) final String defaultApnNotificationProtocolVersion, + @JsonProperty( + "default_fcm_notification_protocol_version" + ) final String defaultFcmNotificationProtocolVersion, + @JsonProperty( + "default_gcm_notification_protocol_version" + ) final String defaultGcmNotificationProtocolVersion, + @JsonProperty( + "delivery_callback_enabled" + ) final Boolean deliveryCallbackEnabled, + @JsonProperty("delivery_callback_url") final String deliveryCallbackUrl, + @JsonProperty( + "facebook_messenger_page_id" + ) final String facebookMessengerPageId, + @JsonProperty("fcm_credential_sid") final String fcmCredentialSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("gcm_credential_sid") final String gcmCredentialSid, + @JsonProperty("links") final Map links, + @JsonProperty("log_enabled") final Boolean logEnabled, + @JsonProperty("messaging_service_sid") final String messagingServiceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.alexaSkillId = alexaSkillId; + this.apnCredentialSid = apnCredentialSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.defaultAlexaNotificationProtocolVersion = + defaultAlexaNotificationProtocolVersion; + this.defaultApnNotificationProtocolVersion = + defaultApnNotificationProtocolVersion; + this.defaultFcmNotificationProtocolVersion = + defaultFcmNotificationProtocolVersion; + this.defaultGcmNotificationProtocolVersion = + defaultGcmNotificationProtocolVersion; + this.deliveryCallbackEnabled = deliveryCallbackEnabled; + this.deliveryCallbackUrl = deliveryCallbackUrl; + this.facebookMessengerPageId = facebookMessengerPageId; + this.fcmCredentialSid = fcmCredentialSid; + this.friendlyName = friendlyName; + this.gcmCredentialSid = gcmCredentialSid; + this.links = links; + this.logEnabled = logEnabled; + this.messagingServiceSid = messagingServiceSid; + this.sid = sid; + this.url = url; } @Override @@ -378,70 +260,71 @@ public boolean equals(final Object o) { } Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(apnCredentialSid, other.apnCredentialSid) && - Objects.equals(gcmCredentialSid, other.gcmCredentialSid) && - Objects.equals(fcmCredentialSid, other.fcmCredentialSid) && - Objects.equals(messagingServiceSid, other.messagingServiceSid) && - Objects.equals(facebookMessengerPageId, other.facebookMessengerPageId) && - Objects.equals(defaultApnNotificationProtocolVersion, other.defaultApnNotificationProtocolVersion) && - Objects.equals(defaultGcmNotificationProtocolVersion, other.defaultGcmNotificationProtocolVersion) && - Objects.equals(defaultFcmNotificationProtocolVersion, other.defaultFcmNotificationProtocolVersion) && - Objects.equals(logEnabled, other.logEnabled) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links) && - Objects.equals(alexaSkillId, other.alexaSkillId) && - Objects.equals(defaultAlexaNotificationProtocolVersion, other.defaultAlexaNotificationProtocolVersion); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(alexaSkillId, other.alexaSkillId) && + Objects.equals(apnCredentialSid, other.apnCredentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + defaultAlexaNotificationProtocolVersion, + other.defaultAlexaNotificationProtocolVersion + ) && + Objects.equals( + defaultApnNotificationProtocolVersion, + other.defaultApnNotificationProtocolVersion + ) && + Objects.equals( + defaultFcmNotificationProtocolVersion, + other.defaultFcmNotificationProtocolVersion + ) && + Objects.equals( + defaultGcmNotificationProtocolVersion, + other.defaultGcmNotificationProtocolVersion + ) && + Objects.equals( + deliveryCallbackEnabled, + other.deliveryCallbackEnabled + ) && + Objects.equals(deliveryCallbackUrl, other.deliveryCallbackUrl) && + Objects.equals( + facebookMessengerPageId, + other.facebookMessengerPageId + ) && + Objects.equals(fcmCredentialSid, other.fcmCredentialSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(gcmCredentialSid, other.gcmCredentialSid) && + Objects.equals(links, other.links) && + Objects.equals(logEnabled, other.logEnabled) && + Objects.equals(messagingServiceSid, other.messagingServiceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - apnCredentialSid, - gcmCredentialSid, - fcmCredentialSid, - messagingServiceSid, - facebookMessengerPageId, - defaultApnNotificationProtocolVersion, - defaultGcmNotificationProtocolVersion, - defaultFcmNotificationProtocolVersion, - logEnabled, - url, - links, - alexaSkillId, - defaultAlexaNotificationProtocolVersion); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("apnCredentialSid", apnCredentialSid) - .add("gcmCredentialSid", gcmCredentialSid) - .add("fcmCredentialSid", fcmCredentialSid) - .add("messagingServiceSid", messagingServiceSid) - .add("facebookMessengerPageId", facebookMessengerPageId) - .add("defaultApnNotificationProtocolVersion", defaultApnNotificationProtocolVersion) - .add("defaultGcmNotificationProtocolVersion", defaultGcmNotificationProtocolVersion) - .add("defaultFcmNotificationProtocolVersion", defaultFcmNotificationProtocolVersion) - .add("logEnabled", logEnabled) - .add("url", url) - .add("links", links) - .add("alexaSkillId", alexaSkillId) - .add("defaultAlexaNotificationProtocolVersion", defaultAlexaNotificationProtocolVersion) - .toString(); + return Objects.hash( + accountSid, + alexaSkillId, + apnCredentialSid, + dateCreated, + dateUpdated, + defaultAlexaNotificationProtocolVersion, + defaultApnNotificationProtocolVersion, + defaultFcmNotificationProtocolVersion, + defaultGcmNotificationProtocolVersion, + deliveryCallbackEnabled, + deliveryCallbackUrl, + facebookMessengerPageId, + fcmCredentialSid, + friendlyName, + gcmCredentialSid, + links, + logEnabled, + messagingServiceSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/notify/v1/ServiceCreator.java index 80ac9da893..8df843337f 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,12 +27,11 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceCreator extends Creator { + private String friendlyName; private String apnCredentialSid; private String gcmCredentialSid; @@ -34,257 +44,282 @@ public class ServiceCreator extends Creator { private Boolean logEnabled; private String alexaSkillId; private String defaultAlexaNotificationProtocolVersion; + private String deliveryCallbackUrl; + private Boolean deliveryCallbackEnabled; + + public ServiceCreator() {} - /** - * Human-readable name for this service instance. - * - * @param friendlyName Human-readable name for this service instance - * @return this - */ public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The SID of the - * [Credential](https://www.twilio.com/docs/notify/api/credentials) to be used - * for APN Bindings.. - * - * @param apnCredentialSid The SID of the Credential to be used for APN - * Bindings. - * @return this - */ public ServiceCreator setApnCredentialSid(final String apnCredentialSid) { this.apnCredentialSid = apnCredentialSid; return this; } - /** - * The SID of the - * [Credential](https://www.twilio.com/docs/notify/api/credentials) to be used - * for GCM Bindings.. - * - * @param gcmCredentialSid The SID of the Credential to be used for GCM - * Bindings. - * @return this - */ public ServiceCreator setGcmCredentialSid(final String gcmCredentialSid) { this.gcmCredentialSid = gcmCredentialSid; return this; } - /** - * The SID of the [Messaging - * Service](https://www.twilio.com/docs/api/rest/sending-messages#messaging-services) to be used for SMS Bindings. In order to send SMS notifications this parameter has to be set.. - * - * @param messagingServiceSid The SID of the Messaging Service to be used for - * SMS Bindings. - * @return this - */ - public ServiceCreator setMessagingServiceSid(final String messagingServiceSid) { + public ServiceCreator setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - /** - * The Page ID to be used to send for Facebook Messenger Bindings. It has to - * match the Page ID you configured when you [enabled Facebook - * Messaging](https://www.twilio.com/console/sms/settings) on your account.. - * - * @param facebookMessengerPageId The Page ID to be used to send for Facebook - * Messenger Bindings. - * @return this - */ - public ServiceCreator setFacebookMessengerPageId(final String facebookMessengerPageId) { + public ServiceCreator setFacebookMessengerPageId( + final String facebookMessengerPageId + ) { this.facebookMessengerPageId = facebookMessengerPageId; return this; } - /** - * The version of the protocol to be used for sending APNS notifications. Can be - * overriden on a Binding by Binding basis when creating a - * [Binding](https://www.twilio.com/docs/notify/api/bindings) resource.. - * - * @param defaultApnNotificationProtocolVersion The version of the protocol to - * be used for sending APNS - * notifications. - * @return this - */ - public ServiceCreator setDefaultApnNotificationProtocolVersion(final String defaultApnNotificationProtocolVersion) { - this.defaultApnNotificationProtocolVersion = defaultApnNotificationProtocolVersion; + public ServiceCreator setDefaultApnNotificationProtocolVersion( + final String defaultApnNotificationProtocolVersion + ) { + this.defaultApnNotificationProtocolVersion = + defaultApnNotificationProtocolVersion; return this; } - /** - * The version of the protocol to be used for sending GCM notifications. Can be - * overriden on a Binding by Binding basis when creating a - * [Binding](https://www.twilio.com/docs/notify/api/bindings) resource.. - * - * @param defaultGcmNotificationProtocolVersion The version of the protocol to - * be used for sending GCM - * notifications. - * @return this - */ - public ServiceCreator setDefaultGcmNotificationProtocolVersion(final String defaultGcmNotificationProtocolVersion) { - this.defaultGcmNotificationProtocolVersion = defaultGcmNotificationProtocolVersion; + public ServiceCreator setDefaultGcmNotificationProtocolVersion( + final String defaultGcmNotificationProtocolVersion + ) { + this.defaultGcmNotificationProtocolVersion = + defaultGcmNotificationProtocolVersion; return this; } - /** - * The SID of the - * [Credential](https://www.twilio.com/docs/notify/api/credentials) to be used - * for FCM Bindings.. - * - * @param fcmCredentialSid The SID of the Credential to be used for FCM - * Bindings. - * @return this - */ public ServiceCreator setFcmCredentialSid(final String fcmCredentialSid) { this.fcmCredentialSid = fcmCredentialSid; return this; } - /** - * The version of the protocol to be used for sending FCM notifications. Can be - * overriden on a Binding by Binding basis when creating a - * [Binding](https://www.twilio.com/docs/notify/api/bindings) resource.. - * - * @param defaultFcmNotificationProtocolVersion The version of the protocol to - * be used for sending FCM - * notifications. - * @return this - */ - public ServiceCreator setDefaultFcmNotificationProtocolVersion(final String defaultFcmNotificationProtocolVersion) { - this.defaultFcmNotificationProtocolVersion = defaultFcmNotificationProtocolVersion; + public ServiceCreator setDefaultFcmNotificationProtocolVersion( + final String defaultFcmNotificationProtocolVersion + ) { + this.defaultFcmNotificationProtocolVersion = + defaultFcmNotificationProtocolVersion; return this; } - /** - * The log_enabled. - * - * @param logEnabled The log_enabled - * @return this - */ public ServiceCreator setLogEnabled(final Boolean logEnabled) { this.logEnabled = logEnabled; return this; } - /** - * The alexa_skill_id. - * - * @param alexaSkillId The alexa_skill_id - * @return this - */ public ServiceCreator setAlexaSkillId(final String alexaSkillId) { this.alexaSkillId = alexaSkillId; return this; } - /** - * The default_alexa_notification_protocol_version. - * - * @param defaultAlexaNotificationProtocolVersion The - * default_alexa_notification_protocol_version - * @return this - */ - public ServiceCreator setDefaultAlexaNotificationProtocolVersion(final String defaultAlexaNotificationProtocolVersion) { - this.defaultAlexaNotificationProtocolVersion = defaultAlexaNotificationProtocolVersion; + public ServiceCreator setDefaultAlexaNotificationProtocolVersion( + final String defaultAlexaNotificationProtocolVersion + ) { + this.defaultAlexaNotificationProtocolVersion = + defaultAlexaNotificationProtocolVersion; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { + public ServiceCreator setDeliveryCallbackUrl( + final String deliveryCallbackUrl + ) { + this.deliveryCallbackUrl = deliveryCallbackUrl; + return this; + } + + public ServiceCreator setDeliveryCallbackEnabled( + final Boolean deliveryCallbackEnabled + ) { + this.deliveryCallbackEnabled = deliveryCallbackEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), - "/v1/Services", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (apnCredentialSid != null) { - request.addPostParam("ApnCredentialSid", apnCredentialSid); + Serializer.toString( + request, + "ApnCredentialSid", + apnCredentialSid, + ParameterType.URLENCODED + ); } if (gcmCredentialSid != null) { - request.addPostParam("GcmCredentialSid", gcmCredentialSid); + Serializer.toString( + request, + "GcmCredentialSid", + gcmCredentialSid, + ParameterType.URLENCODED + ); } if (messagingServiceSid != null) { - request.addPostParam("MessagingServiceSid", messagingServiceSid); + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); } if (facebookMessengerPageId != null) { - request.addPostParam("FacebookMessengerPageId", facebookMessengerPageId); + Serializer.toString( + request, + "FacebookMessengerPageId", + facebookMessengerPageId, + ParameterType.URLENCODED + ); } if (defaultApnNotificationProtocolVersion != null) { - request.addPostParam("DefaultApnNotificationProtocolVersion", defaultApnNotificationProtocolVersion); + Serializer.toString( + request, + "DefaultApnNotificationProtocolVersion", + defaultApnNotificationProtocolVersion, + ParameterType.URLENCODED + ); } if (defaultGcmNotificationProtocolVersion != null) { - request.addPostParam("DefaultGcmNotificationProtocolVersion", defaultGcmNotificationProtocolVersion); + Serializer.toString( + request, + "DefaultGcmNotificationProtocolVersion", + defaultGcmNotificationProtocolVersion, + ParameterType.URLENCODED + ); } if (fcmCredentialSid != null) { - request.addPostParam("FcmCredentialSid", fcmCredentialSid); + Serializer.toString( + request, + "FcmCredentialSid", + fcmCredentialSid, + ParameterType.URLENCODED + ); } if (defaultFcmNotificationProtocolVersion != null) { - request.addPostParam("DefaultFcmNotificationProtocolVersion", defaultFcmNotificationProtocolVersion); + Serializer.toString( + request, + "DefaultFcmNotificationProtocolVersion", + defaultFcmNotificationProtocolVersion, + ParameterType.URLENCODED + ); } if (logEnabled != null) { - request.addPostParam("LogEnabled", logEnabled.toString()); + Serializer.toString( + request, + "LogEnabled", + logEnabled, + ParameterType.URLENCODED + ); } if (alexaSkillId != null) { - request.addPostParam("AlexaSkillId", alexaSkillId); + Serializer.toString( + request, + "AlexaSkillId", + alexaSkillId, + ParameterType.URLENCODED + ); } if (defaultAlexaNotificationProtocolVersion != null) { - request.addPostParam("DefaultAlexaNotificationProtocolVersion", defaultAlexaNotificationProtocolVersion); + Serializer.toString( + request, + "DefaultAlexaNotificationProtocolVersion", + defaultAlexaNotificationProtocolVersion, + ParameterType.URLENCODED + ); + } + + if (deliveryCallbackUrl != null) { + Serializer.toString( + request, + "DeliveryCallbackUrl", + deliveryCallbackUrl, + ParameterType.URLENCODED + ); + } + + if (deliveryCallbackEnabled != null) { + Serializer.toString( + request, + "DeliveryCallbackEnabled", + deliveryCallbackEnabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/notify/v1/ServiceDeleter.java index 28c1f9e474..476fcc7f9d 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new ServiceDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/notify/v1/ServiceFetcher.java index fbc519a493..bf0e927e57 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new ServiceFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceReader.java b/src/main/java/com/twilio/rest/notify/v1/ServiceReader.java index 5abae1a5e8..00ce0349ed 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; @@ -10,169 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceReader extends Reader { + private String friendlyName; + private Long pageSize; + + public ServiceReader() {} - /** - * Filter services by FriendlyName. - * - * @param friendlyName Filter services by FriendlyName - * @return this - */ public ServiceReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.GET, Domains.NOTIFY.toString(), - "/v1/Services", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/notify/v1/ServiceUpdater.java index aa210513e3..d8faa97ec0 100644 --- a/src/main/java/com/twilio/rest/notify/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/notify/v1/ServiceUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,13 +27,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String apnCredentialSid; private String gcmCredentialSid; @@ -35,259 +45,286 @@ public class ServiceUpdater extends Updater { private Boolean logEnabled; private String alexaSkillId; private String defaultAlexaNotificationProtocolVersion; + private String deliveryCallbackUrl; + private Boolean deliveryCallbackEnabled; - /** - * Construct a new ServiceUpdater. - * - * @param pathSid The sid - */ public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Human-readable name for this service instance. - * - * @param friendlyName Human-readable name for this service instance - * @return this - */ public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The SID of the default Credential to be used for APN Bindings. - * - * @param apnCredentialSid The SID of the default Credential to be used for APN - * Bindings - * @return this - */ public ServiceUpdater setApnCredentialSid(final String apnCredentialSid) { this.apnCredentialSid = apnCredentialSid; return this; } - /** - * The SID of the default Credential to be used for GCM Bindings. - * - * @param gcmCredentialSid The SID of the default Credential to be used for GCM - * Bindings - * @return this - */ public ServiceUpdater setGcmCredentialSid(final String gcmCredentialSid) { this.gcmCredentialSid = gcmCredentialSid; return this; } - /** - * The SID of the [Messaging - * Service](https://www.twilio.com/docs/api/rest/sending-messages#messaging-services) to be used for SMS Bindings. In order to send SMS notifications this parameter has to be set.. - * - * @param messagingServiceSid The SID of the Messaging Service to be used for - * SMS Bindings. - * @return this - */ - public ServiceUpdater setMessagingServiceSid(final String messagingServiceSid) { + public ServiceUpdater setMessagingServiceSid( + final String messagingServiceSid + ) { this.messagingServiceSid = messagingServiceSid; return this; } - /** - * The Page ID to be used to send for Facebook Messenger Bindings. It has to - * match the Page ID you configured when you [enabled Facebook - * Messaging](https://www.twilio.com/console/sms/settings) on your account. - * Facebook Messenger integration is in beta. You need to be in the beta program - * to be able to enable Facebook Messaging for your account.. - * - * @param facebookMessengerPageId The Page ID to be used to send for Facebook - * Messenger Bindings. - * @return this - */ - public ServiceUpdater setFacebookMessengerPageId(final String facebookMessengerPageId) { + public ServiceUpdater setFacebookMessengerPageId( + final String facebookMessengerPageId + ) { this.facebookMessengerPageId = facebookMessengerPageId; return this; } - /** - * The version of the protocol to be used for sending APNS notifications. Can be - * overriden on a Binding by Binding basis when creating a Binding resource.. - * - * @param defaultApnNotificationProtocolVersion The version of the protocol to - * be used for sending APNS - * notifications. - * @return this - */ - public ServiceUpdater setDefaultApnNotificationProtocolVersion(final String defaultApnNotificationProtocolVersion) { - this.defaultApnNotificationProtocolVersion = defaultApnNotificationProtocolVersion; + public ServiceUpdater setDefaultApnNotificationProtocolVersion( + final String defaultApnNotificationProtocolVersion + ) { + this.defaultApnNotificationProtocolVersion = + defaultApnNotificationProtocolVersion; return this; } - /** - * The version of the protocol to be used for sending GCM notifications. Can be - * overriden on a Binding by Binding basis when creating a Binding resource.. - * - * @param defaultGcmNotificationProtocolVersion The version of the protocol to - * be used for sending GCM - * notifications. - * @return this - */ - public ServiceUpdater setDefaultGcmNotificationProtocolVersion(final String defaultGcmNotificationProtocolVersion) { - this.defaultGcmNotificationProtocolVersion = defaultGcmNotificationProtocolVersion; + public ServiceUpdater setDefaultGcmNotificationProtocolVersion( + final String defaultGcmNotificationProtocolVersion + ) { + this.defaultGcmNotificationProtocolVersion = + defaultGcmNotificationProtocolVersion; return this; } - /** - * The SID of the default Credential to be used for FCM Bindings. - * - * @param fcmCredentialSid The SID of the default Credential to be used for FCM - * Bindings - * @return this - */ public ServiceUpdater setFcmCredentialSid(final String fcmCredentialSid) { this.fcmCredentialSid = fcmCredentialSid; return this; } - /** - * The version of the protocol to be used for sending FCM notifications. Can be - * overriden on a Binding by Binding basis when creating a Binding resource.. - * - * @param defaultFcmNotificationProtocolVersion The version of the protocol to - * be used for sending FCM - * notifications. - * @return this - */ - public ServiceUpdater setDefaultFcmNotificationProtocolVersion(final String defaultFcmNotificationProtocolVersion) { - this.defaultFcmNotificationProtocolVersion = defaultFcmNotificationProtocolVersion; + public ServiceUpdater setDefaultFcmNotificationProtocolVersion( + final String defaultFcmNotificationProtocolVersion + ) { + this.defaultFcmNotificationProtocolVersion = + defaultFcmNotificationProtocolVersion; return this; } - /** - * The log_enabled. - * - * @param logEnabled The log_enabled - * @return this - */ public ServiceUpdater setLogEnabled(final Boolean logEnabled) { this.logEnabled = logEnabled; return this; } - /** - * The alexa_skill_id. - * - * @param alexaSkillId The alexa_skill_id - * @return this - */ public ServiceUpdater setAlexaSkillId(final String alexaSkillId) { this.alexaSkillId = alexaSkillId; return this; } - /** - * The default_alexa_notification_protocol_version. - * - * @param defaultAlexaNotificationProtocolVersion The - * default_alexa_notification_protocol_version - * @return this - */ - public ServiceUpdater setDefaultAlexaNotificationProtocolVersion(final String defaultAlexaNotificationProtocolVersion) { - this.defaultAlexaNotificationProtocolVersion = defaultAlexaNotificationProtocolVersion; + public ServiceUpdater setDefaultAlexaNotificationProtocolVersion( + final String defaultAlexaNotificationProtocolVersion + ) { + this.defaultAlexaNotificationProtocolVersion = + defaultAlexaNotificationProtocolVersion; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { + public ServiceUpdater setDeliveryCallbackUrl( + final String deliveryCallbackUrl + ) { + this.deliveryCallbackUrl = deliveryCallbackUrl; + return this; + } + + public ServiceUpdater setDeliveryCallbackEnabled( + final Boolean deliveryCallbackEnabled + ) { + this.deliveryCallbackEnabled = deliveryCallbackEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (apnCredentialSid != null) { - request.addPostParam("ApnCredentialSid", apnCredentialSid); + Serializer.toString( + request, + "ApnCredentialSid", + apnCredentialSid, + ParameterType.URLENCODED + ); } if (gcmCredentialSid != null) { - request.addPostParam("GcmCredentialSid", gcmCredentialSid); + Serializer.toString( + request, + "GcmCredentialSid", + gcmCredentialSid, + ParameterType.URLENCODED + ); } if (messagingServiceSid != null) { - request.addPostParam("MessagingServiceSid", messagingServiceSid); + Serializer.toString( + request, + "MessagingServiceSid", + messagingServiceSid, + ParameterType.URLENCODED + ); } if (facebookMessengerPageId != null) { - request.addPostParam("FacebookMessengerPageId", facebookMessengerPageId); + Serializer.toString( + request, + "FacebookMessengerPageId", + facebookMessengerPageId, + ParameterType.URLENCODED + ); } if (defaultApnNotificationProtocolVersion != null) { - request.addPostParam("DefaultApnNotificationProtocolVersion", defaultApnNotificationProtocolVersion); + Serializer.toString( + request, + "DefaultApnNotificationProtocolVersion", + defaultApnNotificationProtocolVersion, + ParameterType.URLENCODED + ); } if (defaultGcmNotificationProtocolVersion != null) { - request.addPostParam("DefaultGcmNotificationProtocolVersion", defaultGcmNotificationProtocolVersion); + Serializer.toString( + request, + "DefaultGcmNotificationProtocolVersion", + defaultGcmNotificationProtocolVersion, + ParameterType.URLENCODED + ); } if (fcmCredentialSid != null) { - request.addPostParam("FcmCredentialSid", fcmCredentialSid); + Serializer.toString( + request, + "FcmCredentialSid", + fcmCredentialSid, + ParameterType.URLENCODED + ); } if (defaultFcmNotificationProtocolVersion != null) { - request.addPostParam("DefaultFcmNotificationProtocolVersion", defaultFcmNotificationProtocolVersion); + Serializer.toString( + request, + "DefaultFcmNotificationProtocolVersion", + defaultFcmNotificationProtocolVersion, + ParameterType.URLENCODED + ); } if (logEnabled != null) { - request.addPostParam("LogEnabled", logEnabled.toString()); + Serializer.toString( + request, + "LogEnabled", + logEnabled, + ParameterType.URLENCODED + ); } if (alexaSkillId != null) { - request.addPostParam("AlexaSkillId", alexaSkillId); + Serializer.toString( + request, + "AlexaSkillId", + alexaSkillId, + ParameterType.URLENCODED + ); } if (defaultAlexaNotificationProtocolVersion != null) { - request.addPostParam("DefaultAlexaNotificationProtocolVersion", defaultAlexaNotificationProtocolVersion); + Serializer.toString( + request, + "DefaultAlexaNotificationProtocolVersion", + defaultAlexaNotificationProtocolVersion, + ParameterType.URLENCODED + ); + } + + if (deliveryCallbackUrl != null) { + Serializer.toString( + request, + "DeliveryCallbackUrl", + deliveryCallbackUrl, + ParameterType.URLENCODED + ); + } + + if (deliveryCallbackEnabled != null) { + Serializer.toString( + request, + "DeliveryCallbackEnabled", + deliveryCallbackEnabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/service/Binding.java b/src/main/java/com/twilio/rest/notify/v1/service/Binding.java index 7ed91640f8..0d27efca9d 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/Binding.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/Binding.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1.service; @@ -10,37 +17,66 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Binding extends Resource { - private static final long serialVersionUID = 19604548272115L; + + public static BindingCreator creator( + final String pathServiceSid, + final String identity, + final Binding.BindingType bindingType, + final String address + ) { + return new BindingCreator( + pathServiceSid, + identity, + bindingType, + address + ); + } + + public static BindingDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new BindingDeleter(pathServiceSid, pathSid); + } + + public static BindingFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new BindingFetcher(pathServiceSid, pathSid); + } + + public static BindingReader reader(final String pathServiceSid) { + return new BindingReader(pathServiceSid); + } public enum BindingType { APN("apn"), @@ -56,79 +92,28 @@ private BindingType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a BindingType from a string. - * @param value string value - * @return generated BindingType - */ @JsonCreator public static BindingType forValue(final String value) { return Promoter.enumFromString(value, BindingType.values()); } } - /** - * Create a BindingFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return BindingFetcher capable of executing the fetch - */ - public static BindingFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new BindingFetcher(pathServiceSid, pathSid); - } - - /** - * Create a BindingDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return BindingDeleter capable of executing the delete - */ - public static BindingDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new BindingDeleter(pathServiceSid, pathSid); - } - - /** - * Create a BindingCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param identity The Identity to which this Binding belongs to. - * @param bindingType The type of the Binding. - * @param address The address specific to the channel. - * @return BindingCreator capable of executing the create - */ - public static BindingCreator creator(final String pathServiceSid, - final String identity, - final Binding.BindingType bindingType, - final String address) { - return new BindingCreator(pathServiceSid, identity, bindingType, address); - } - - /** - * Create a BindingReader to execute read. - * - * @param pathServiceSid The service_sid - * @return BindingReader capable of executing the read - */ - public static BindingReader reader(final String pathServiceSid) { - return new BindingReader(pathServiceSid); - } - /** * Converts a JSON String into a Binding object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Binding object represented by the provided JSON */ - public static Binding fromJson(final String json, final ObjectMapper objectMapper) { + public static Binding fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -142,12 +127,15 @@ public static Binding fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Binding object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Binding object represented by the provided JSON */ - public static Binding fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Binding fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Binding.class); @@ -158,192 +146,103 @@ public static Binding fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String credentialSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String notificationProtocolVersion; - private final String endpoint; - private final String identity; - private final String bindingType; - private final String address; - private final List tags; - private final URI url; - private final Map links; - - @JsonCreator - private Binding(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("credential_sid") - final String credentialSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("notification_protocol_version") - final String notificationProtocolVersion, - @JsonProperty("endpoint") - final String endpoint, - @JsonProperty("identity") - final String identity, - @JsonProperty("binding_type") - final String bindingType, - @JsonProperty("address") - final String address, - @JsonProperty("tags") - final List tags, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.credentialSid = credentialSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.notificationProtocolVersion = notificationProtocolVersion; - this.endpoint = endpoint; - this.identity = identity; - this.bindingType = bindingType; - this.address = address; - this.tags = tags; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String address; - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String bindingType; - /** - * Returns The The unique identifier of the Credential resource to be used to - * send notifications to this Binding.. - * - * @return The unique identifier of the Credential resource to be used to send - * notifications to this Binding. - */ - public final String getCredentialSid() { - return this.credentialSid; - } + @Getter + private final String credentialSid; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The version of the protocol used to send the notification.. - * - * @return The version of the protocol used to send the notification. - */ - public final String getNotificationProtocolVersion() { - return this.notificationProtocolVersion; - } + @Getter + private final String endpoint; - /** - * Returns The DEPRECATED*. - * - * @return DEPRECATED* - */ - public final String getEndpoint() { - return this.endpoint; - } + @Getter + private final String identity; - /** - * Returns The The Identity to which this Binding belongs to.. - * - * @return The Identity to which this Binding belongs to. - */ - public final String getIdentity() { - return this.identity; - } + @Getter + private final Map links; - /** - * Returns The The type of the Binding.. - * - * @return The type of the Binding. - */ - public final String getBindingType() { - return this.bindingType; - } + @Getter + private final String notificationProtocolVersion; - /** - * Returns The The address specific to the channel.. - * - * @return The address specific to the channel. - */ - public final String getAddress() { - return this.address; - } + @Getter + private final String serviceSid; - /** - * Returns The The list of tags associated with this Binding.. - * - * @return The list of tags associated with this Binding. - */ - public final List getTags() { - return this.tags; - } + @Getter + private final String sid; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final List tags; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Binding( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address") final String address, + @JsonProperty("binding_type") final String bindingType, + @JsonProperty("credential_sid") final String credentialSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("endpoint") final String endpoint, + @JsonProperty("identity") final String identity, + @JsonProperty("links") final Map links, + @JsonProperty( + "notification_protocol_version" + ) final String notificationProtocolVersion, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("tags") final List tags, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.address = address; + this.bindingType = bindingType; + this.credentialSid = credentialSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.endpoint = endpoint; + this.identity = identity; + this.links = links; + this.notificationProtocolVersion = notificationProtocolVersion; + this.serviceSid = serviceSid; + this.sid = sid; + this.tags = tags; + this.url = url; } @Override @@ -357,58 +256,44 @@ public boolean equals(final Object o) { } Binding other = (Binding) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(credentialSid, other.credentialSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(notificationProtocolVersion, other.notificationProtocolVersion) && - Objects.equals(endpoint, other.endpoint) && - Objects.equals(identity, other.identity) && - Objects.equals(bindingType, other.bindingType) && - Objects.equals(address, other.address) && - Objects.equals(tags, other.tags) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(address, other.address) && + Objects.equals(bindingType, other.bindingType) && + Objects.equals(credentialSid, other.credentialSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endpoint, other.endpoint) && + Objects.equals(identity, other.identity) && + Objects.equals(links, other.links) && + Objects.equals( + notificationProtocolVersion, + other.notificationProtocolVersion + ) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(tags, other.tags) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - credentialSid, - dateCreated, - dateUpdated, - notificationProtocolVersion, - endpoint, - identity, - bindingType, - address, - tags, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("credentialSid", credentialSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("notificationProtocolVersion", notificationProtocolVersion) - .add("endpoint", endpoint) - .add("identity", identity) - .add("bindingType", bindingType) - .add("address", address) - .add("tags", tags) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + address, + bindingType, + credentialSid, + dateCreated, + dateUpdated, + endpoint, + identity, + links, + notificationProtocolVersion, + serviceSid, + sid, + tags, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/service/BindingCreator.java b/src/main/java/com/twilio/rest/notify/v1/service/BindingCreator.java index 1927c1ef5f..7b45c80213 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/BindingCreator.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/BindingCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,180 +28,202 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class BindingCreator extends Creator { - private final String pathServiceSid; - private final String identity; - private final Binding.BindingType bindingType; - private final String address; + + private String pathServiceSid; + private String identity; + private Binding.BindingType bindingType; + private String address; private List tag; private String notificationProtocolVersion; private String credentialSid; private String endpoint; - /** - * Construct a new BindingCreator. - * - * @param pathServiceSid The service_sid - * @param identity The Identity to which this Binding belongs to. - * @param bindingType The type of the Binding. - * @param address The address specific to the channel. - */ - public BindingCreator(final String pathServiceSid, - final String identity, - final Binding.BindingType bindingType, - final String address) { + public BindingCreator( + final String pathServiceSid, + final String identity, + final Binding.BindingType bindingType, + final String address + ) { this.pathServiceSid = pathServiceSid; this.identity = identity; this.bindingType = bindingType; this.address = address; } - /** - * The list of tags associated with this Binding. Tags can be used to select the - * Bindings to use when sending a notification. Maximum 20 tags are allowed.. - * - * @param tag The list of tags associated with this Binding. - * @return this - */ + public BindingCreator setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public BindingCreator setBindingType( + final Binding.BindingType bindingType + ) { + this.bindingType = bindingType; + return this; + } + + public BindingCreator setAddress(final String address) { + this.address = address; + return this; + } + public BindingCreator setTag(final List tag) { this.tag = tag; return this; } - /** - * The list of tags associated with this Binding. Tags can be used to select the - * Bindings to use when sending a notification. Maximum 20 tags are allowed.. - * - * @param tag The list of tags associated with this Binding. - * @return this - */ public BindingCreator setTag(final String tag) { return setTag(Promoter.listOfOne(tag)); } - /** - * The version of the protocol (data format) used to send the notification. This - * defaults to the value of DefaultXXXNotificationProtocolVersion in the - * [Service](https://www.twilio.com/docs/api/notify/rest/services). The current - * version is `"3"` for `apn`, `fcm`, and `gcm` type Bindings. The parameter is - * not applicable to `sms` and `facebook-messenger` type Bindings as the data - * format is fixed.. - * - * @param notificationProtocolVersion The version of the protocol used to send - * the notification. - * @return this - */ - public BindingCreator setNotificationProtocolVersion(final String notificationProtocolVersion) { + public BindingCreator setNotificationProtocolVersion( + final String notificationProtocolVersion + ) { this.notificationProtocolVersion = notificationProtocolVersion; return this; } - /** - * The unique identifier (SID) of the Credential resource to be used to send - * notifications to this Binding. If present, this overrides the Credential - * specified in the Service resource. Applicable only to `apn`, `fcm`, and `gcm` - * type Bindings.. - * - * @param credentialSid The unique identifier of the Credential resource to be - * used to send notifications to this Binding. - * @return this - */ public BindingCreator setCredentialSid(final String credentialSid) { this.credentialSid = credentialSid; return this; } - /** - * DEPRECATED*. - * - * @param endpoint DEPRECATED* - * @return this - */ public BindingCreator setEndpoint(final String endpoint) { this.endpoint = endpoint; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Binding - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Binding create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Bindings"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Bindings", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Binding creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Binding create(final TwilioRestClient client) { + Response response = makeRequest(client); return Binding.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Binding content = Binding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (identity != null) { - request.addPostParam("Identity", identity); + Serializer.toString( + request, + "Identity", + identity, + ParameterType.URLENCODED + ); } if (bindingType != null) { - request.addPostParam("BindingType", bindingType.toString()); + Serializer.toString( + request, + "BindingType", + bindingType, + ParameterType.URLENCODED + ); } if (address != null) { - request.addPostParam("Address", address); + Serializer.toString( + request, + "Address", + address, + ParameterType.URLENCODED + ); } if (tag != null) { - for (String prop : tag) { - request.addPostParam("Tag", prop); + for (String param : tag) { + Serializer.toString( + request, + "Tag", + param, + ParameterType.URLENCODED + ); } } if (notificationProtocolVersion != null) { - request.addPostParam("NotificationProtocolVersion", notificationProtocolVersion); + Serializer.toString( + request, + "NotificationProtocolVersion", + notificationProtocolVersion, + ParameterType.URLENCODED + ); } if (credentialSid != null) { - request.addPostParam("CredentialSid", credentialSid); + Serializer.toString( + request, + "CredentialSid", + credentialSid, + ParameterType.URLENCODED + ); } if (endpoint != null) { - request.addPostParam("Endpoint", endpoint); + Serializer.toString( + request, + "Endpoint", + endpoint, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/service/BindingDeleter.java b/src/main/java/com/twilio/rest/notify/v1/service/BindingDeleter.java index f87546360e..7917f09032 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/BindingDeleter.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/BindingDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class BindingDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new BindingDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public BindingDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public BindingDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Binding delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/service/BindingFetcher.java b/src/main/java/com/twilio/rest/notify/v1/service/BindingFetcher.java index 4d5f576ced..c65d5241fb 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/BindingFetcher.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/BindingFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class BindingFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new BindingFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public BindingFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public BindingFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Binding - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Binding fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Bindings/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Bindings/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Binding fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Binding fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Binding fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Binding.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Binding content = Binding.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/notify/v1/service/BindingReader.java b/src/main/java/com/twilio/rest/notify/v1/service/BindingReader.java index 6322326434..49a4bea7b4 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/BindingReader.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/BindingReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1.service; @@ -10,262 +17,265 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - +import com.twilio.type.*; +import java.io.InputStream; +import java.time.LocalDate; import java.util.List; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class BindingReader extends Reader { - private final String pathServiceSid; + + private String pathServiceSid; private LocalDate startDate; private LocalDate endDate; private List identity; private List tag; + private Long pageSize; - /** - * Construct a new BindingReader. - * - * @param pathServiceSid The service_sid - */ public BindingReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Only list Bindings created on or after the given date. Should be formatted as - * YYYY-MM-DD. All dates considered in UTC.. - * - * @param startDate Only list Bindings created on or after the given date. - * @return this - */ public BindingReader setStartDate(final LocalDate startDate) { this.startDate = startDate; return this; } - /** - * Only list Bindings created on or before the given date. Should be formatted - * as YYYY-MM-DD. All dates considered in UTC.. - * - * @param endDate Only list Bindings created on or before the given date. - * @return this - */ public BindingReader setEndDate(final LocalDate endDate) { this.endDate = endDate; return this; } - /** - * Only list Bindings that have any of the specified Identities.. - * - * @param identity Only list Bindings that have any of the specified Identities. - * @return this - */ public BindingReader setIdentity(final List identity) { this.identity = identity; return this; } - /** - * Only list Bindings that have any of the specified Identities.. - * - * @param identity Only list Bindings that have any of the specified Identities. - * @return this - */ public BindingReader setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Only list Bindings that have all of the specified Tags. The following - * implicit tags are available: all, apn, fcm, gcm, sms, facebook-messenger. - * Maximum 5 tags are allowed.. - * - * @param tag Only list Bindings that have all of the specified Tags. - * @return this - */ public BindingReader setTag(final List tag) { this.tag = tag; return this; } - /** - * Only list Bindings that have all of the specified Tags. The following - * implicit tags are available: all, apn, fcm, gcm, sms, facebook-messenger. - * Maximum 5 tags are allowed.. - * - * @param tag Only list Bindings that have all of the specified Tags. - * @return this - */ public BindingReader setTag(final String tag) { return setTag(Promoter.listOfOne(tag)); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public BindingReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Bindings"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Bindings", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Binding ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Binding read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "bindings", + response.getContent(), + Binding.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Binding Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Binding read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "bindings", - response.getContent(), - Binding.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.QUERY + ); } } if (tag != null) { - for (String prop : tag) { - request.addQueryParam("Tag", prop); + for (String param : tag) { + Serializer.toString(request, "Tag", param, ParameterType.QUERY); } } + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/service/Notification.java b/src/main/java/com/twilio/rest/notify/v1/service/Notification.java index 8f0defedca..8e379b0408 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/Notification.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/Notification.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1.service; @@ -10,37 +17,36 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Notification extends Resource { - private static final long serialVersionUID = 275926337068118L; + + public static NotificationCreator creator(final String pathServiceSid) { + return new NotificationCreator(pathServiceSid); + } public enum Priority { HIGH("high"), @@ -52,15 +58,11 @@ private Priority(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Priority from a string. - * @param value string value - * @return generated Priority - */ @JsonCreator public static Priority forValue(final String value) { return Promoter.enumFromString(value, Priority.values()); @@ -68,24 +70,16 @@ public static Priority forValue(final String value) { } /** - * Create a NotificationCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return NotificationCreator capable of executing the create - */ - public static NotificationCreator creator(final String pathServiceSid) { - return new NotificationCreator(pathServiceSid); - } - - /** - * Converts a JSON String into a Notification object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Notification object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Notification object represented by the provided JSON */ - public static Notification fromJson(final String json, final ObjectMapper objectMapper) { + public static Notification fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -99,12 +93,15 @@ public static Notification fromJson(final String json, final ObjectMapper object /** * Converts a JSON InputStream into a Notification object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Notification object represented by the provided JSON */ - public static Notification fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Notification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Notification.class); @@ -115,281 +112,126 @@ public static Notification fromJson(final InputStream json, final ObjectMapper o } } - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final List identities; - private final List tags; - private final List segments; - private final Notification.Priority priority; - private final Integer ttl; - private final String title; - private final String body; - private final String sound; - private final String action; - private final Map data; - private final Map apn; - private final Map gcm; - private final Map fcm; - private final Map sms; - private final Map facebookMessenger; - private final Map alexa; - - @JsonCreator - private Notification(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("identities") - final List identities, - @JsonProperty("tags") - final List tags, - @JsonProperty("segments") - final List segments, - @JsonProperty("priority") - final Notification.Priority priority, - @JsonProperty("ttl") - final Integer ttl, - @JsonProperty("title") - final String title, - @JsonProperty("body") - final String body, - @JsonProperty("sound") - final String sound, - @JsonProperty("action") - final String action, - @JsonProperty("data") - final Map data, - @JsonProperty("apn") - final Map apn, - @JsonProperty("gcm") - final Map gcm, - @JsonProperty("fcm") - final Map fcm, - @JsonProperty("sms") - final Map sms, - @JsonProperty("facebook_messenger") - final Map facebookMessenger, - @JsonProperty("alexa") - final Map alexa) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.identities = identities; - this.tags = tags; - this.segments = segments; - this.priority = priority; - this.ttl = ttl; - this.title = title; - this.body = body; - this.sound = sound; - this.action = action; - this.data = data; - this.apn = apn; - this.gcm = gcm; - this.fcm = fcm; - this.sms = sms; - this.facebookMessenger = facebookMessenger; - this.alexa = alexa; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String action; - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final Object alexa; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Object apn; - /** - * Returns The List of Identities.. - * - * @return List of Identities. - */ - public final List getIdentities() { - return this.identities; - } + @Getter + private final String body; - /** - * Returns The List of Tags. - * - * @return List of Tags - */ - public final List getTags() { - return this.tags; - } + @Getter + private final Object data; - /** - * Returns The The segments. - * - * @return The segments - */ - public final List getSegments() { - return this.segments; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The Two priorities defined: low and high.. - * - * @return Two priorities defined: low and high. - */ - public final Notification.Priority getPriority() { - return this.priority; - } + @Getter + private final Object facebookMessenger; - /** - * Returns The This parameter specifies how long the notification is valid.. - * - * @return This parameter specifies how long the notification is valid. - */ - public final Integer getTtl() { - return this.ttl; - } + @Getter + private final Object fcm; - /** - * Returns The Indicates the notification title.. - * - * @return Indicates the notification title. - */ - public final String getTitle() { - return this.title; - } + @Getter + private final Object gcm; - /** - * Returns The Indicates the notification body text.. - * - * @return Indicates the notification body text. - */ - public final String getBody() { - return this.body; - } + @Getter + private final List identities; - /** - * Returns The Indicates a sound to be played.. - * - * @return Indicates a sound to be played. - */ - public final String getSound() { - return this.sound; - } + @Getter + private final Notification.Priority priority; - /** - * Returns The Specifies the actions to be displayed for the notification.. - * - * @return Specifies the actions to be displayed for the notification. - */ - public final String getAction() { - return this.action; - } + @Getter + private final List segments; - /** - * Returns The This parameter specifies the custom key-value pairs of the - * notification’s payload.. - * - * @return This parameter specifies the custom key-value pairs of the - * notification’s payload. - */ - public final Map getData() { - return this.data; - } + @Getter + private final String serviceSid; - /** - * Returns The APNS specific payload that overrides corresponding attributes in - * a generic payload for Bindings with the apn BindingType.. - * - * @return APNS specific payload that overrides corresponding attributes in a - * generic payload for Bindings with the apn BindingType. - */ - public final Map getApn() { - return this.apn; - } + @Getter + private final String sid; - /** - * Returns The GCM specific payload that overrides corresponding attributes in - * generic payload for Bindings with gcm BindingType.. - * - * @return GCM specific payload that overrides corresponding attributes in - * generic payload for Bindings with gcm BindingType. - */ - public final Map getGcm() { - return this.gcm; - } + @Getter + private final Object sms; - /** - * Returns The FCM specific payload that overrides corresponding attributes in - * generic payload for Bindings with fcm BindingType.. - * - * @return FCM specific payload that overrides corresponding attributes in - * generic payload for Bindings with fcm BindingType. - */ - public final Map getFcm() { - return this.fcm; - } + @Getter + private final String sound; - /** - * Returns The SMS specific payload that overrides corresponding attributes in - * generic payload for Bindings with sms BindingType.. - * - * @return SMS specific payload that overrides corresponding attributes in - * generic payload for Bindings with sms BindingType. - */ - public final Map getSms() { - return this.sms; - } + @Getter + private final List tags; - /** - * Returns The Messenger specific payload that overrides corresponding - * attributes in generic payload for Bindings with facebook-messenger - * BindingType.. - * - * @return Messenger specific payload that overrides corresponding attributes - * in generic payload for Bindings with facebook-messenger BindingType. - */ - public final Map getFacebookMessenger() { - return this.facebookMessenger; - } + @Getter + private final String title; - /** - * Returns The The alexa. - * - * @return The alexa - */ - public final Map getAlexa() { - return this.alexa; + @Getter + private final Integer ttl; + + @JsonCreator + private Notification( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("action") final String action, + @JsonProperty("alexa") final Object alexa, + @JsonProperty("apn") final Object apn, + @JsonProperty("body") final String body, + @JsonProperty("data") final Object data, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("facebook_messenger") final Object facebookMessenger, + @JsonProperty("fcm") final Object fcm, + @JsonProperty("gcm") final Object gcm, + @JsonProperty("identities") final List identities, + @JsonProperty("priority") final Notification.Priority priority, + @JsonProperty("segments") final List segments, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("sms") final Object sms, + @JsonProperty("sound") final String sound, + @JsonProperty("tags") final List tags, + @JsonProperty("title") final String title, + @JsonProperty("ttl") final Integer ttl + ) { + this.accountSid = accountSid; + this.action = action; + this.alexa = alexa; + this.apn = apn; + this.body = body; + this.data = data; + this.dateCreated = dateCreated; + this.facebookMessenger = facebookMessenger; + this.fcm = fcm; + this.gcm = gcm; + this.identities = identities; + this.priority = priority; + this.segments = segments; + this.serviceSid = serviceSid; + this.sid = sid; + this.sms = sms; + this.sound = sound; + this.tags = tags; + this.title = title; + this.ttl = ttl; } @Override @@ -403,76 +245,53 @@ public boolean equals(final Object o) { } Notification other = (Notification) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(identities, other.identities) && - Objects.equals(tags, other.tags) && - Objects.equals(segments, other.segments) && - Objects.equals(priority, other.priority) && - Objects.equals(ttl, other.ttl) && - Objects.equals(title, other.title) && - Objects.equals(body, other.body) && - Objects.equals(sound, other.sound) && - Objects.equals(action, other.action) && - Objects.equals(data, other.data) && - Objects.equals(apn, other.apn) && - Objects.equals(gcm, other.gcm) && - Objects.equals(fcm, other.fcm) && - Objects.equals(sms, other.sms) && - Objects.equals(facebookMessenger, other.facebookMessenger) && - Objects.equals(alexa, other.alexa); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(action, other.action) && + Objects.equals(alexa, other.alexa) && + Objects.equals(apn, other.apn) && + Objects.equals(body, other.body) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(facebookMessenger, other.facebookMessenger) && + Objects.equals(fcm, other.fcm) && + Objects.equals(gcm, other.gcm) && + Objects.equals(identities, other.identities) && + Objects.equals(priority, other.priority) && + Objects.equals(segments, other.segments) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(sms, other.sms) && + Objects.equals(sound, other.sound) && + Objects.equals(tags, other.tags) && + Objects.equals(title, other.title) && + Objects.equals(ttl, other.ttl) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - identities, - tags, - segments, - priority, - ttl, - title, - body, - sound, - action, - data, - apn, - gcm, - fcm, - sms, - facebookMessenger, - alexa); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("identities", identities) - .add("tags", tags) - .add("segments", segments) - .add("priority", priority) - .add("ttl", ttl) - .add("title", title) - .add("body", body) - .add("sound", sound) - .add("action", action) - .add("data", data) - .add("apn", apn) - .add("gcm", gcm) - .add("fcm", fcm) - .add("sms", sms) - .add("facebookMessenger", facebookMessenger) - .add("alexa", alexa) - .toString(); + return Objects.hash( + accountSid, + action, + alexa, + apn, + body, + data, + dateCreated, + facebookMessenger, + fcm, + gcm, + identities, + priority, + segments, + serviceSid, + sid, + sms, + sound, + tags, + title, + ttl + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/service/NotificationCreator.java b/src/main/java/com/twilio/rest/notify/v1/service/NotificationCreator.java index d08088d1a7..cd7be87661 100644 --- a/src/main/java/com/twilio/rest/notify/v1/service/NotificationCreator.java +++ b/src/main/java/com/twilio/rest/notify/v1/service/NotificationCreator.java @@ -1,15 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Notify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.notify.v1.service; import com.twilio.base.Creator; -import com.twilio.converter.Converter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -18,481 +28,357 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; -import java.util.Map; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class NotificationCreator extends Creator { - private final String pathServiceSid; - private List identity; - private List tag; + + private String pathServiceSid; private String body; private Notification.Priority priority; private Integer ttl; private String title; private String sound; private String action; - private Map data; - private Map apn; - private Map gcm; - private Map sms; - private Map facebookMessenger; - private Map fcm; + private Object data; + private Object apn; + private Object gcm; + private Object sms; + private Object facebookMessenger; + private Object fcm; private List segment; - private Map alexa; + private Object alexa; private List toBinding; + private String deliveryCallbackUrl; + private List identity; + private List tag; - /** - * Construct a new NotificationCreator. - * - * @param pathServiceSid The service_sid - */ public NotificationCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * (optional for all except Alexa) Indicates the notification body text. - * Translates to `data.twi_body` for FCM and GCM, `aps.alert.body` for APNS, - * `Body` for SMS and Facebook Messenger and `request.message.data` for Alexa. - * For SMS either this, `body`, or the `media_url` attribute of the `Sms` - * parameter is required. For Facebook Messenger either this parameter or the - * body attribute in the `FacebookMessenger` parameter is required.. - * - * @param body Indicates the notification body text. - * @return this - */ public NotificationCreator setBody(final String body) { this.body = body; return this; } - /** - * Two priorities defined: `low` and `high` (default). `low` optimizes the - * client app's battery consumption, and notifications may be delivered with - * unspecified delay. This is the same as Normal priority for FCM and GCM or - * priority 5 for APNS. `high` sends the notification immediately, and can wake - * up a sleeping device. This is the same as High priority for FCM and GCM or - * priority 10 for APNS. This feature is not supported by SMS and Facebook - * Messenger and will be ignored for deliveries via those channels.. - * - * @param priority Two priorities defined: low and high. - * @return this - */ - public NotificationCreator setPriority(final Notification.Priority priority) { + public NotificationCreator setPriority( + final Notification.Priority priority + ) { this.priority = priority; return this; } - /** - * This parameter specifies how long (in seconds) the notification is valid. - * Delivery should be attempted if the device is offline. The maximum time to - * live supported is 4 weeks. The value zero means that the notification - * delivery is attempted immediately once but not stored for future delivery. - * The default value is 4 weeks. This feature is not supported by SMS and - * Facebook Messenger and will be ignored for deliveries via those channels.. - * - * @param ttl This parameter specifies how long the notification is valid. - * @return this - */ public NotificationCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * (optional for all except Alexa) Indicates the notification title. This field - * is not visible on iOS phones and tablets but it is on Apple Watch and Android - * devices. Translates to `data.twi_title` for FCM and GCM, `aps.alert.title` - * for APNS and `displayInfo.content[0].title`, - * `displayInfo.content[].toast.primaryText` of `request.message` for Alexa. It - * is not supported for SMS and Facebook Messenger and will be omitted from - * deliveries via those channels.. - * - * @param title Indicates the notification title. - * @return this - */ public NotificationCreator setTitle(final String title) { this.title = title; return this; } - /** - * Indicates a sound to be played. Translates to `data.twi_sound` for FCM and - * GCM and `aps.sound` for APNS. This parameter is not supported by SMS and - * Facebook Messenger and is omitted from deliveries via those channels.. - * - * @param sound Indicates a sound to be played. - * @return this - */ public NotificationCreator setSound(final String sound) { this.sound = sound; return this; } - /** - * Specifies the actions to be displayed for the notification. Translates to - * `data.twi_action` for GCM and `aps.category` for APNS. This parameter is not - * supported by SMS and Facebook Messenger and is omitted from deliveries via - * those channels.. - * - * @param action Specifies the actions to be displayed for the notification. - * @return this - */ public NotificationCreator setAction(final String action) { this.action = action; return this; } - /** - * This parameter specifies the custom key-value pairs of the notification’s - * payload. Translates to `data` dictionary in FCM and GCM payload. FCM and GCM - * [reserves certain - * keys](https://firebase.google.com/docs/cloud-messaging/http-server-ref) that - * cannot be used for those channels. For APNS, attributes of `Data` will be - * inserted into the APNS payload as custom properties outside of the `aps` - * dictionary. For Alexa they are added to `request.message.data`. For all - * channels, the `twi_` prefix is reserved for Twilio for future use. Requests - * including custom data with keys starting with `twi_` will be rejected as 400 - * Bad request and no delivery will be attempted. This parameter is not - * supported by SMS and Facebook Messenger and is omitted from deliveries via - * those channels.. - * - * @param data This parameter specifies the custom key-value pairs of the - * notification’s payload. - * @return this - */ - public NotificationCreator setData(final Map data) { + public NotificationCreator setData(final Object data) { this.data = data; return this; } - /** - * APNS specific payload that overrides corresponding attributes in a generic - * payload for Bindings with the apn BindingType. This value is mapped to the - * Payload item, therefore the `aps` key has to be used to change standard - * attributes. Adds custom key-value pairs to the root of the dictionary. Refer - * to [APNS - * documentation](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html) for more details. The `twi_` key prefix for custom key-value pairs is reserved for Twilio for future use. Custom data with keys starting with `twi_` is not allowed.. - * - * @param apn APNS specific payload that overrides corresponding attributes in - * a generic payload for Bindings with the apn BindingType. - * @return this - */ - public NotificationCreator setApn(final Map apn) { + public NotificationCreator setApn(final Object apn) { this.apn = apn; return this; } - /** - * GCM specific payload that overrides corresponding attributes in generic - * payload for Bindings with gcm BindingType. This value is mapped to the root - * json dictionary. Refer to [GCM - * documentation](https://developers.google.com/cloud-messaging/http-server-ref) - * for more details. Target parameters `to`, `registration_ids`, and - * `notification_key` are not allowed. The `twi_` key prefix for custom - * key-value pairs is reserved for Twilio for future use. Custom data with keys - * starting with `twi_` is not allowed. FCM and GCM [reserves certain - * keys](https://firebase.google.com/docs/cloud-messaging/http-server-ref) that - * cannot be used for those channels.. - * - * @param gcm GCM specific payload that overrides corresponding attributes in - * generic payload for Bindings with gcm BindingType. - * @return this - */ - public NotificationCreator setGcm(final Map gcm) { + public NotificationCreator setGcm(final Object gcm) { this.gcm = gcm; return this; } - /** - * SMS specific payload that overrides corresponding attributes in generic - * payload for Bindings with sms BindingType. Each attribute in this JSON - * object is mapped to the corresponding form parameter of the Twilio - * [Message](https://www.twilio.com/docs/api/rest/sending-messages) resource. - * The following parameters of the Message resource are supported in snake case - * format: `body`, `media_urls`, `status_callback`, and `max_price`. The - * `status_callback` parameter overrides the corresponding parameter in the - * messaging service if configured. The `media_urls` expects a JSON array.. - * - * @param sms SMS specific payload that overrides corresponding attributes in - * generic payload for Bindings with sms BindingType. - * @return this - */ - public NotificationCreator setSms(final Map sms) { + public NotificationCreator setSms(final Object sms) { this.sms = sms; return this; } - /** - * Messenger specific payload that overrides corresponding attributes in generic - * payload for Bindings with facebook-messenger BindingType. This value is - * mapped to the root json dictionary of Facebook's [Send API - * request](https://developers.facebook.com/docs/messenger-platform/send-api-reference). Overriding the `recipient` parameter is not allowed.. - * - * @param facebookMessenger Messenger specific payload that overrides - * corresponding attributes in generic payload for - * Bindings with facebook-messenger BindingType. - * @return this - */ - public NotificationCreator setFacebookMessenger(final Map facebookMessenger) { + public NotificationCreator setFacebookMessenger( + final Object facebookMessenger + ) { this.facebookMessenger = facebookMessenger; return this; } - /** - * FCM specific payload that overrides corresponding attributes in generic - * payload for Bindings with fcm BindingType. This value is mapped to the root - * json dictionary. Refer to [FCM - * documentation](https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream) for more details. Target parameters `to`, `registration_ids`, `condition`, and `notification_key` are not allowed. The `twi_` key prefix for custom key-value pairs is reserved for Twilio for future use. Custom data with keys starting with `twi_` is not allowed. Custom data with keys starting with `twi_` is not allowed. FCM and GCM [reserves certain keys](https://firebase.google.com/docs/cloud-messaging/http-server-ref) that cannot be used for those channels.. - * - * @param fcm FCM specific payload that overrides corresponding attributes in - * generic payload for Bindings with fcm BindingType. - * @return this - */ - public NotificationCreator setFcm(final Map fcm) { + public NotificationCreator setFcm(final Object fcm) { this.fcm = fcm; return this; } - /** - * The segment. - * - * @param segment The segment - * @return this - */ public NotificationCreator setSegment(final List segment) { this.segment = segment; return this; } - /** - * The segment. - * - * @param segment The segment - * @return this - */ public NotificationCreator setSegment(final String segment) { return setSegment(Promoter.listOfOne(segment)); } - /** - * The alexa. - * - * @param alexa The alexa - * @return this - */ - public NotificationCreator setAlexa(final Map alexa) { + public NotificationCreator setAlexa(final Object alexa) { this.alexa = alexa; return this; } - /** - * The destination address in a JSON object (see attributes below). Multiple - * ToBinding parameters can be included but the total size of the request entity - * should not exceed 1MB. This is typically sufficient for 10,000 phone numbers. - * . - * - * @param toBinding The destination address in a JSON object. - * @return this - */ public NotificationCreator setToBinding(final List toBinding) { this.toBinding = toBinding; return this; } - /** - * The destination address in a JSON object (see attributes below). Multiple - * ToBinding parameters can be included but the total size of the request entity - * should not exceed 1MB. This is typically sufficient for 10,000 phone numbers. - * . - * - * @param toBinding The destination address in a JSON object. - * @return this - */ public NotificationCreator setToBinding(final String toBinding) { return setToBinding(Promoter.listOfOne(toBinding)); } - /** - * Delivery will be attempted only to Bindings with an Identity in this list. - * Maximum 20 items allowed in this list.. - * - * @param identity Delivery will be attempted only to Bindings with an Identity - * in this list. - * @return this - */ + public NotificationCreator setDeliveryCallbackUrl( + final String deliveryCallbackUrl + ) { + this.deliveryCallbackUrl = deliveryCallbackUrl; + return this; + } + public NotificationCreator setIdentity(final List identity) { this.identity = identity; return this; } - /** - * Delivery will be attempted only to Bindings with an Identity in this list. - * Maximum 20 items allowed in this list.. - * - * @param identity Delivery will be attempted only to Bindings with an Identity - * in this list. - * @return this - */ public NotificationCreator setIdentity(final String identity) { return setIdentity(Promoter.listOfOne(identity)); } - /** - * Delivery will be attempted only to Bindings that have all of the Tags in this - * list. Maximum 5 items allowed in this list. The implicit tag "all" is - * available to notify all Bindings in a Service instance. Similarly the - * implicit tags "apn", "fcm", "gcm", "sms" and "facebook-messenger" are - * available to notify all Bindings of the given type.. - * - * @param tag Delivery will be attempted only to Bindings that have all of the - * Tags in this list. - * @return this - */ public NotificationCreator setTag(final List tag) { this.tag = tag; return this; } - /** - * Delivery will be attempted only to Bindings that have all of the Tags in this - * list. Maximum 5 items allowed in this list. The implicit tag "all" is - * available to notify all Bindings in a Service instance. Similarly the - * implicit tags "apn", "fcm", "gcm", "sms" and "facebook-messenger" are - * available to notify all Bindings of the given type.. - * - * @param tag Delivery will be attempted only to Bindings that have all of the - * Tags in this list. - * @return this - */ public NotificationCreator setTag(final String tag) { return setTag(Promoter.listOfOne(tag)); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Notification - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Notification create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Notifications"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Notifications", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Notification creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Notification creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } - - return Notification.fromJson(response.getStream(), client.getObjectMapper()); + return response; } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (identity != null) { - for (String prop : identity) { - request.addPostParam("Identity", prop); - } - } + @Override + public Notification create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - if (tag != null) { - for (String prop : tag) { - request.addPostParam("Tag", prop); - } - } + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Notification content = Notification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (priority != null) { - request.addPostParam("Priority", priority.toString()); + Serializer.toString( + request, + "Priority", + priority, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); } if (title != null) { - request.addPostParam("Title", title); + Serializer.toString( + request, + "Title", + title, + ParameterType.URLENCODED + ); } if (sound != null) { - request.addPostParam("Sound", sound); + Serializer.toString( + request, + "Sound", + sound, + ParameterType.URLENCODED + ); } if (action != null) { - request.addPostParam("Action", action); + Serializer.toString( + request, + "Action", + action, + ParameterType.URLENCODED + ); } if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); + Serializer.toString( + request, + "Data", + data, + ParameterType.URLENCODED + ); } if (apn != null) { - request.addPostParam("Apn", Converter.mapToJson(apn)); + Serializer.toString(request, "Apn", apn, ParameterType.URLENCODED); } if (gcm != null) { - request.addPostParam("Gcm", Converter.mapToJson(gcm)); + Serializer.toString(request, "Gcm", gcm, ParameterType.URLENCODED); } if (sms != null) { - request.addPostParam("Sms", Converter.mapToJson(sms)); + Serializer.toString(request, "Sms", sms, ParameterType.URLENCODED); } if (facebookMessenger != null) { - request.addPostParam("FacebookMessenger", Converter.mapToJson(facebookMessenger)); + Serializer.toString( + request, + "FacebookMessenger", + facebookMessenger, + ParameterType.URLENCODED + ); } if (fcm != null) { - request.addPostParam("Fcm", Converter.mapToJson(fcm)); + Serializer.toString(request, "Fcm", fcm, ParameterType.URLENCODED); } if (segment != null) { - for (String prop : segment) { - request.addPostParam("Segment", prop); + for (String param : segment) { + Serializer.toString( + request, + "Segment", + param, + ParameterType.URLENCODED + ); } } if (alexa != null) { - request.addPostParam("Alexa", Converter.mapToJson(alexa)); + Serializer.toString( + request, + "Alexa", + alexa, + ParameterType.URLENCODED + ); } if (toBinding != null) { - for (String prop : toBinding) { - request.addPostParam("ToBinding", prop); + for (String param : toBinding) { + Serializer.toString( + request, + "ToBinding", + param, + ParameterType.URLENCODED + ); + } + } + + if (deliveryCallbackUrl != null) { + Serializer.toString( + request, + "DeliveryCallbackUrl", + deliveryCallbackUrl, + ParameterType.URLENCODED + ); + } + + if (identity != null) { + for (String param : identity) { + Serializer.toString( + request, + "Identity", + param, + ParameterType.URLENCODED + ); + } + } + + if (tag != null) { + for (String param : tag) { + Serializer.toString( + request, + "Tag", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/notify/v1/service/Segment.java b/src/main/java/com/twilio/rest/notify/v1/service/Segment.java deleted file mode 100644 index 9c25b1f806..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/Segment.java +++ /dev/null @@ -1,212 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Segment extends Resource { - private static final long serialVersionUID = 34647527565964L; - - /** - * Create a SegmentReader to execute read. - * - * @param pathServiceSid The service_sid - * @return SegmentReader capable of executing the read - */ - public static SegmentReader reader(final String pathServiceSid) { - return new SegmentReader(pathServiceSid); - } - - /** - * Converts a JSON String into a Segment object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Segment object represented by the provided JSON - */ - public static Segment fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Segment.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Segment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Segment object represented by the provided JSON - */ - public static Segment fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Segment.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String uniqueName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private Segment(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.uniqueName = uniqueName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The unique_name. - * - * @return The unique_name - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Segment other = (Segment) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - uniqueName, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("uniqueName", uniqueName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/SegmentReader.java b/src/main/java/com/twilio/rest/notify/v1/service/SegmentReader.java deleted file mode 100644 index bf09248171..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/SegmentReader.java +++ /dev/null @@ -1,172 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class SegmentReader extends Reader { - private final String pathServiceSid; - - /** - * Construct a new SegmentReader. - * - * @param pathServiceSid The service_sid - */ - public SegmentReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Segment ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Segment ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Segments", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Segment ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Segment Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Segment read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "segments", - response.getContent(), - Segment.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/User.java b/src/main/java/com/twilio/rest/notify/v1/service/User.java deleted file mode 100644 index fa40957dfa..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/User.java +++ /dev/null @@ -1,298 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class User extends Resource { - private static final long serialVersionUID = 128922065257528L; - - /** - * Create a UserCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param identity The identifier of the User, defined by your application. - * @return UserCreator capable of executing the create - */ - public static UserCreator creator(final String pathServiceSid, - final String identity) { - return new UserCreator(pathServiceSid, identity); - } - - /** - * Create a UserDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @return UserDeleter capable of executing the delete - */ - public static UserDeleter deleter(final String pathServiceSid, - final String pathIdentity) { - return new UserDeleter(pathServiceSid, pathIdentity); - } - - /** - * Create a UserFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @return UserFetcher capable of executing the fetch - */ - public static UserFetcher fetcher(final String pathServiceSid, - final String pathIdentity) { - return new UserFetcher(pathServiceSid, pathIdentity); - } - - /** - * Create a UserReader to execute read. - * - * @param pathServiceSid The service_sid - * @return UserReader capable of executing the read - */ - public static UserReader reader(final String pathServiceSid) { - return new UserReader(pathServiceSid); - } - - /** - * Converts a JSON String into a User object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, User.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a User object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return User object represented by the provided JSON - */ - public static User fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, User.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String identity; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final List segments; - private final URI url; - private final Map links; - - @JsonCreator - private User(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("segments") - final List segments, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.identity = identity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.segments = segments; - this.url = url; - this.links = links; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The identifier of the User, defined by your application.. - * - * @return The identifier of the User, defined by your application. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The segments. - * - * @return The segments - */ - public final List getSegments() { - return this.segments; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - User other = (User) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(segments, other.segments) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - identity, - dateCreated, - dateUpdated, - segments, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("segments", segments) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/UserCreator.java b/src/main/java/com/twilio/rest/notify/v1/service/UserCreator.java deleted file mode 100644 index 0d5887ccbb..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/UserCreator.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.List; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class UserCreator extends Creator { - private final String pathServiceSid; - private final String identity; - private List segment; - - /** - * Construct a new UserCreator. - * - * @param pathServiceSid The service_sid - * @param identity The identifier of the User, defined by your application. - */ - public UserCreator(final String pathServiceSid, - final String identity) { - this.pathServiceSid = pathServiceSid; - this.identity = identity; - } - - /** - * The list of segments this User belongs to. Segments can be used to select - * recipients of a notification. Maximum 20 Segments per User allowed.. - * - * @param segment The list of segments this User belongs to. Segments can be - * used to select recipients of a notification. Maximum 20 - * Segments per User allowed. - * @return this - */ - public UserCreator setSegment(final List segment) { - this.segment = segment; - return this; - } - - /** - * The list of segments this User belongs to. Segments can be used to select - * recipients of a notification. Maximum 20 Segments per User allowed.. - * - * @param segment The list of segments this User belongs to. Segments can be - * used to select recipients of a notification. Maximum 20 - * Segments per User allowed. - * @return this - */ - public UserCreator setSegment(final String segment) { - return setSegment(Promoter.listOfOne(segment)); - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("User creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return User.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (identity != null) { - request.addPostParam("Identity", identity); - } - - if (segment != null) { - for (String prop : segment) { - request.addPostParam("Segment", prop); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/UserDeleter.java b/src/main/java/com/twilio/rest/notify/v1/service/UserDeleter.java deleted file mode 100644 index e30a9f6a1a..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/UserDeleter.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class UserDeleter extends Deleter { - private final String pathServiceSid; - private final String pathIdentity; - - /** - * Construct a new UserDeleter. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - */ - public UserDeleter(final String pathServiceSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("User delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/UserFetcher.java b/src/main/java/com/twilio/rest/notify/v1/service/UserFetcher.java deleted file mode 100644 index 92d4e56cda..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/UserFetcher.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class UserFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathIdentity; - - /** - * Construct a new UserFetcher. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - */ - public UserFetcher(final String pathServiceSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched User - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public User fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("User fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return User.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/UserReader.java b/src/main/java/com/twilio/rest/notify/v1/service/UserReader.java deleted file mode 100644 index 1059fec639..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/UserReader.java +++ /dev/null @@ -1,222 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.List; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class UserReader extends Reader { - private final String pathServiceSid; - private List identity; - private String segment; - - /** - * Construct a new UserReader. - * - * @param pathServiceSid The service_sid - */ - public UserReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * The identifier of the User, defined by your application.. - * - * @param identity The identifier of the User, defined by your application. - * @return this - */ - public UserReader setIdentity(final List identity) { - this.identity = identity; - return this; - } - - /** - * The identifier of the User, defined by your application.. - * - * @param identity The identifier of the User, defined by your application. - * @return this - */ - public UserReader setIdentity(final String identity) { - return setIdentity(Promoter.listOfOne(identity)); - } - - /** - * The list of segments this User belongs to. Segments can be used to select - * recipients of a notification. Maximum 20 Segments per User allowed.. - * - * @param segment The list of segments this User belongs to. Segments can be - * used to select recipients of a notification. Maximum 20 - * Segments per User allowed. - * @return this - */ - public UserReader setSegment(final String segment) { - this.segment = segment; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return User ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of User Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("User read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "users", - response.getContent(), - User.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (identity != null) { - for (String prop : identity) { - request.addQueryParam("Identity", prop); - } - } - - if (segment != null) { - request.addQueryParam("Segment", segment); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembership.java b/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembership.java deleted file mode 100644 index 564e86b75f..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembership.java +++ /dev/null @@ -1,228 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class SegmentMembership extends Resource { - private static final long serialVersionUID = 241012819747560L; - - /** - * Create a SegmentMembershipCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param segment The segment - * @return SegmentMembershipCreator capable of executing the create - */ - public static SegmentMembershipCreator creator(final String pathServiceSid, - final String pathIdentity, - final String segment) { - return new SegmentMembershipCreator(pathServiceSid, pathIdentity, segment); - } - - /** - * Create a SegmentMembershipDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param pathSegment The segment - * @return SegmentMembershipDeleter capable of executing the delete - */ - public static SegmentMembershipDeleter deleter(final String pathServiceSid, - final String pathIdentity, - final String pathSegment) { - return new SegmentMembershipDeleter(pathServiceSid, pathIdentity, pathSegment); - } - - /** - * Create a SegmentMembershipFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param pathSegment The segment - * @return SegmentMembershipFetcher capable of executing the fetch - */ - public static SegmentMembershipFetcher fetcher(final String pathServiceSid, - final String pathIdentity, - final String pathSegment) { - return new SegmentMembershipFetcher(pathServiceSid, pathIdentity, pathSegment); - } - - /** - * Converts a JSON String into a SegmentMembership object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SegmentMembership object represented by the provided JSON - */ - public static SegmentMembership fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SegmentMembership.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a SegmentMembership object using the - * provided ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SegmentMembership object represented by the provided JSON - */ - public static SegmentMembership fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SegmentMembership.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final String serviceSid; - private final String identity; - private final String segment; - private final URI url; - - @JsonCreator - private SegmentMembership(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("segment") - final String segment, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.identity = identity; - this.segment = segment; - this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The identity. - * - * @return The identity - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The The segment. - * - * @return The segment - */ - public final String getSegment() { - return this.segment; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - SegmentMembership other = (SegmentMembership) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(identity, other.identity) && - Objects.equals(segment, other.segment) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - identity, - segment, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("identity", identity) - .add("segment", segment) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipCreator.java b/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipCreator.java deleted file mode 100644 index fca92de1ff..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipCreator.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class SegmentMembershipCreator extends Creator { - private final String pathServiceSid; - private final String pathIdentity; - private final String segment; - - /** - * Construct a new SegmentMembershipCreator. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param segment The segment - */ - public SegmentMembershipCreator(final String pathServiceSid, - final String pathIdentity, - final String segment) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - this.segment = segment; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SegmentMembership - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SegmentMembership create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "/SegmentMemberships", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SegmentMembership creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SegmentMembership.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (segment != null) { - request.addPostParam("Segment", segment); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipDeleter.java b/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipDeleter.java deleted file mode 100644 index 8c7f6b810e..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipDeleter.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class SegmentMembershipDeleter extends Deleter { - private final String pathServiceSid; - private final String pathIdentity; - private final String pathSegment; - - /** - * Construct a new SegmentMembershipDeleter. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param pathSegment The segment - */ - public SegmentMembershipDeleter(final String pathServiceSid, - final String pathIdentity, - final String pathSegment) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - this.pathSegment = pathSegment; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "/SegmentMemberships/" + this.pathSegment + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SegmentMembership delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipFetcher.java b/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipFetcher.java deleted file mode 100644 index 3d669b8f81..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/SegmentMembershipFetcher.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class SegmentMembershipFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathIdentity; - private final String pathSegment; - - /** - * Construct a new SegmentMembershipFetcher. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param pathSegment The segment - */ - public SegmentMembershipFetcher(final String pathServiceSid, - final String pathIdentity, - final String pathSegment) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - this.pathSegment = pathSegment; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SegmentMembership - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SegmentMembership fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "/SegmentMemberships/" + this.pathSegment + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SegmentMembership fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SegmentMembership.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBinding.java b/src/main/java/com/twilio/rest/notify/v1/service/user/UserBinding.java deleted file mode 100644 index 2b877cafde..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBinding.java +++ /dev/null @@ -1,419 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class UserBinding extends Resource { - private static final long serialVersionUID = 19604548272115L; - - public enum BindingType { - APN("apn"), - GCM("gcm"), - SMS("sms"), - FCM("fcm"), - FACEBOOK_MESSENGER("facebook-messenger"), - ALEXA("alexa"); - - private final String value; - - private BindingType(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a BindingType from a string. - * @param value string value - * @return generated BindingType - */ - @JsonCreator - public static BindingType forValue(final String value) { - return Promoter.enumFromString(value, BindingType.values()); - } - } - - /** - * Create a UserBindingFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param pathSid The sid - * @return UserBindingFetcher capable of executing the fetch - */ - public static UserBindingFetcher fetcher(final String pathServiceSid, - final String pathIdentity, - final String pathSid) { - return new UserBindingFetcher(pathServiceSid, pathIdentity, pathSid); - } - - /** - * Create a UserBindingDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param pathSid The sid - * @return UserBindingDeleter capable of executing the delete - */ - public static UserBindingDeleter deleter(final String pathServiceSid, - final String pathIdentity, - final String pathSid) { - return new UserBindingDeleter(pathServiceSid, pathIdentity, pathSid); - } - - /** - * Create a UserBindingCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param bindingType The binding_type - * @param address The address - * @return UserBindingCreator capable of executing the create - */ - public static UserBindingCreator creator(final String pathServiceSid, - final String pathIdentity, - final UserBinding.BindingType bindingType, - final String address) { - return new UserBindingCreator(pathServiceSid, pathIdentity, bindingType, address); - } - - /** - * Create a UserBindingReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @return UserBindingReader capable of executing the read - */ - public static UserBindingReader reader(final String pathServiceSid, - final String pathIdentity) { - return new UserBindingReader(pathServiceSid, pathIdentity); - } - - /** - * Converts a JSON String into a UserBinding object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return UserBinding object represented by the provided JSON - */ - public static UserBinding fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, UserBinding.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a UserBinding object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return UserBinding object represented by the provided JSON - */ - public static UserBinding fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, UserBinding.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String serviceSid; - private final String credentialSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String notificationProtocolVersion; - private final String endpoint; - private final String identity; - private final String bindingType; - private final String address; - private final List tags; - private final URI url; - private final Map links; - - @JsonCreator - private UserBinding(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("credential_sid") - final String credentialSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("notification_protocol_version") - final String notificationProtocolVersion, - @JsonProperty("endpoint") - final String endpoint, - @JsonProperty("identity") - final String identity, - @JsonProperty("binding_type") - final String bindingType, - @JsonProperty("address") - final String address, - @JsonProperty("tags") - final List tags, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.credentialSid = credentialSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.notificationProtocolVersion = notificationProtocolVersion; - this.endpoint = endpoint; - this.identity = identity; - this.bindingType = bindingType; - this.address = address; - this.tags = tags; - this.url = url; - this.links = links; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The credential_sid. - * - * @return The credential_sid - */ - public final String getCredentialSid() { - return this.credentialSid; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The notification_protocol_version. - * - * @return The notification_protocol_version - */ - public final String getNotificationProtocolVersion() { - return this.notificationProtocolVersion; - } - - /** - * Returns The The endpoint. - * - * @return The endpoint - */ - public final String getEndpoint() { - return this.endpoint; - } - - /** - * Returns The The identity. - * - * @return The identity - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The The binding_type. - * - * @return The binding_type - */ - public final String getBindingType() { - return this.bindingType; - } - - /** - * Returns The The address. - * - * @return The address - */ - public final String getAddress() { - return this.address; - } - - /** - * Returns The The tags. - * - * @return The tags - */ - public final List getTags() { - return this.tags; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - UserBinding other = (UserBinding) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(credentialSid, other.credentialSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(notificationProtocolVersion, other.notificationProtocolVersion) && - Objects.equals(endpoint, other.endpoint) && - Objects.equals(identity, other.identity) && - Objects.equals(bindingType, other.bindingType) && - Objects.equals(address, other.address) && - Objects.equals(tags, other.tags) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - credentialSid, - dateCreated, - dateUpdated, - notificationProtocolVersion, - endpoint, - identity, - bindingType, - address, - tags, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("credentialSid", credentialSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("notificationProtocolVersion", notificationProtocolVersion) - .add("endpoint", endpoint) - .add("identity", identity) - .add("bindingType", bindingType) - .add("address", address) - .add("tags", tags) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingCreator.java b/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingCreator.java deleted file mode 100644 index 0d86ef3c8d..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingCreator.java +++ /dev/null @@ -1,180 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.List; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class UserBindingCreator extends Creator { - private final String pathServiceSid; - private final String pathIdentity; - private final UserBinding.BindingType bindingType; - private final String address; - private List tag; - private String notificationProtocolVersion; - private String credentialSid; - private String endpoint; - - /** - * Construct a new UserBindingCreator. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param bindingType The binding_type - * @param address The address - */ - public UserBindingCreator(final String pathServiceSid, - final String pathIdentity, - final UserBinding.BindingType bindingType, - final String address) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - this.bindingType = bindingType; - this.address = address; - } - - /** - * The tag. - * - * @param tag The tag - * @return this - */ - public UserBindingCreator setTag(final List tag) { - this.tag = tag; - return this; - } - - /** - * The tag. - * - * @param tag The tag - * @return this - */ - public UserBindingCreator setTag(final String tag) { - return setTag(Promoter.listOfOne(tag)); - } - - /** - * The notification_protocol_version. - * - * @param notificationProtocolVersion The notification_protocol_version - * @return this - */ - public UserBindingCreator setNotificationProtocolVersion(final String notificationProtocolVersion) { - this.notificationProtocolVersion = notificationProtocolVersion; - return this; - } - - /** - * The credential_sid. - * - * @param credentialSid The credential_sid - * @return this - */ - public UserBindingCreator setCredentialSid(final String credentialSid) { - this.credentialSid = credentialSid; - return this; - } - - /** - * The endpoint. - * - * @param endpoint The endpoint - * @return this - */ - public UserBindingCreator setEndpoint(final String endpoint) { - this.endpoint = endpoint; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created UserBinding - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public UserBinding create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "/Bindings", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserBinding creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return UserBinding.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (bindingType != null) { - request.addPostParam("BindingType", bindingType.toString()); - } - - if (address != null) { - request.addPostParam("Address", address); - } - - if (tag != null) { - for (String prop : tag) { - request.addPostParam("Tag", prop); - } - } - - if (notificationProtocolVersion != null) { - request.addPostParam("NotificationProtocolVersion", notificationProtocolVersion); - } - - if (credentialSid != null) { - request.addPostParam("CredentialSid", credentialSid); - } - - if (endpoint != null) { - request.addPostParam("Endpoint", endpoint); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingDeleter.java b/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingDeleter.java deleted file mode 100644 index daef11b619..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingDeleter.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class UserBindingDeleter extends Deleter { - private final String pathServiceSid; - private final String pathIdentity; - private final String pathSid; - - /** - * Construct a new UserBindingDeleter. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param pathSid The sid - */ - public UserBindingDeleter(final String pathServiceSid, - final String pathIdentity, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "/Bindings/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserBinding delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingFetcher.java b/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingFetcher.java deleted file mode 100644 index 1289cd87b6..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingFetcher.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class UserBindingFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathIdentity; - private final String pathSid; - - /** - * Construct a new UserBindingFetcher. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - * @param pathSid The sid - */ - public UserBindingFetcher(final String pathServiceSid, - final String pathIdentity, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched UserBinding - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public UserBinding fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "/Bindings/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserBinding fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return UserBinding.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingReader.java b/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingReader.java deleted file mode 100644 index ce8b5438b1..0000000000 --- a/src/main/java/com/twilio/rest/notify/v1/service/user/UserBindingReader.java +++ /dev/null @@ -1,241 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.notify.v1.service.user; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.LocalDate; - -import java.util.List; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class UserBindingReader extends Reader { - private final String pathServiceSid; - private final String pathIdentity; - private LocalDate startDate; - private LocalDate endDate; - private List tag; - - /** - * Construct a new UserBindingReader. - * - * @param pathServiceSid The service_sid - * @param pathIdentity The identity - */ - public UserBindingReader(final String pathServiceSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathIdentity = pathIdentity; - } - - /** - * The start_date. - * - * @param startDate The start_date - * @return this - */ - public UserBindingReader setStartDate(final LocalDate startDate) { - this.startDate = startDate; - return this; - } - - /** - * The end_date. - * - * @param endDate The end_date - * @return this - */ - public UserBindingReader setEndDate(final LocalDate endDate) { - this.endDate = endDate; - return this; - } - - /** - * The tag. - * - * @param tag The tag - * @return this - */ - public UserBindingReader setTag(final List tag) { - this.tag = tag; - return this; - } - - /** - * The tag. - * - * @param tag The tag - * @return this - */ - public UserBindingReader setTag(final String tag) { - return setTag(Promoter.listOfOne(tag)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.NOTIFY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Users/" + this.pathIdentity + "/Bindings", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return UserBinding ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.NOTIFY.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of UserBinding Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("UserBinding read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "bindings", - response.getContent(), - UserBinding.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (startDate != null) { - request.addQueryParam("StartDate", DateConverter.dateStringFromLocalDate(startDate)); - } - - if (endDate != null) { - request.addQueryParam("EndDate", DateConverter.dateStringFromLocalDate(endDate)); - } - - if (tag != null) { - for (String prop : tag) { - request.addQueryParam("Tag", prop); - } - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/numbers/v1/BulkEligibility.java b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibility.java new file mode 100644 index 0000000000..8951d9d2df --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibility.java @@ -0,0 +1,193 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BulkEligibility extends Resource { + + public static BulkEligibilityCreator creator() { + return new BulkEligibilityCreator(); + } + + public static BulkEligibilityFetcher fetcher(final String pathRequestId) { + return new BulkEligibilityFetcher(pathRequestId); + } + + /** + * Converts a JSON String into a BulkEligibility object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BulkEligibility object represented by the provided JSON + */ + public static BulkEligibility fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkEligibility.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BulkEligibility object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BulkEligibility object represented by the provided JSON + */ + public static BulkEligibility fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkEligibility.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCompleted; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String friendlyName; + + @Getter + private final String requestId; + + @Getter + private final List results; + + @Getter + private final String status; + + @Getter + private final URI url; + + @JsonCreator + private BulkEligibility( + @JsonProperty("date_completed") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCompleted, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("request_id") final String requestId, + @JsonProperty("results") final List results, + @JsonProperty("status") final String status, + @JsonProperty("url") final URI url + ) { + this.dateCompleted = dateCompleted; + this.dateCreated = dateCreated; + this.friendlyName = friendlyName; + this.requestId = requestId; + this.results = results; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BulkEligibility other = (BulkEligibility) o; + return ( + Objects.equals(dateCompleted, other.dateCompleted) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(requestId, other.requestId) && + Objects.equals(results, other.results) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dateCompleted, + dateCreated, + friendlyName, + requestId, + results, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityCreator.java b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityCreator.java new file mode 100644 index 0000000000..bb34e66e3c --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityCreator.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BulkEligibilityCreator extends Creator { + + private Object body; + + public BulkEligibilityCreator() {} + + public BulkEligibilityCreator setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/HostedNumber/Eligibility/Bulk"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BulkEligibility creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BulkEligibility create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BulkEligibility.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BulkEligibility content = BulkEligibility.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody(BulkEligibility.toJson(body, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityFetcher.java new file mode 100644 index 0000000000..1ee649bb6a --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/BulkEligibilityFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BulkEligibilityFetcher extends Fetcher { + + private String pathRequestId; + + public BulkEligibilityFetcher(final String pathRequestId) { + this.pathRequestId = pathRequestId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/HostedNumber/Eligibility/Bulk/{RequestId}"; + + path = + path.replace( + "{" + "RequestId" + "}", + this.pathRequestId.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BulkEligibility fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BulkEligibility fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return BulkEligibility.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BulkEligibility content = BulkEligibility.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/Eligibility.java b/src/main/java/com/twilio/rest/numbers/v1/Eligibility.java new file mode 100644 index 0000000000..906f3a0785 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/Eligibility.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Eligibility extends Resource { + + public static EligibilityCreator creator() { + return new EligibilityCreator(); + } + + /** + * Converts a JSON String into a Eligibility object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Eligibility object represented by the provided JSON + */ + public static Eligibility fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Eligibility.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Eligibility object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Eligibility object represented by the provided JSON + */ + public static Eligibility fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Eligibility.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List results; + + @JsonCreator + private Eligibility(@JsonProperty("results") final List results) { + this.results = results; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Eligibility other = (Eligibility) o; + return (Objects.equals(results, other.results)); + } + + @Override + public int hashCode() { + return Objects.hash(results); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/EligibilityCreator.java b/src/main/java/com/twilio/rest/numbers/v1/EligibilityCreator.java new file mode 100644 index 0000000000..897921b710 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/EligibilityCreator.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EligibilityCreator extends Creator { + + private Object body; + + public EligibilityCreator() {} + + public EligibilityCreator setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/HostedNumber/Eligibility"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Eligibility creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Eligibility create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Eligibility.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Eligibility content = Eligibility.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody(Eligibility.toJson(body, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/EmbeddedSession.java b/src/main/java/com/twilio/rest/numbers/v1/EmbeddedSession.java new file mode 100644 index 0000000000..92c5ead34f --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/EmbeddedSession.java @@ -0,0 +1,223 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EmbeddedSession extends Resource { + + public static EmbeddedSessionCreator creator( + final String pathBundleSid, + final EmbeddedSession.NumbersV1CreateEmbeddedSessionRequest numbersV1CreateEmbeddedSessionRequest + ) { + return new EmbeddedSessionCreator( + pathBundleSid, + numbersV1CreateEmbeddedSessionRequest + ); + } + + @JsonDeserialize( + builder = NumbersV1CreateEmbeddedSessionRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1CreateEmbeddedSessionRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("themeSetId") + @Getter + private final String themeSetId; + + private NumbersV1CreateEmbeddedSessionRequest(Builder builder) { + this.themeSetId = builder.themeSetId; + } + + public static Builder builder() { + return new Builder(); + } + + public static NumbersV1CreateEmbeddedSessionRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1CreateEmbeddedSessionRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("themeSetId") + private String themeSetId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("themeSetId") + public Builder themeSetId(String themeSetId) { + this.themeSetId = themeSetId; + return this; + } + + public NumbersV1CreateEmbeddedSessionRequest build() { + return new NumbersV1CreateEmbeddedSessionRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1CreateEmbeddedSessionRequest other = + (NumbersV1CreateEmbeddedSessionRequest) o; + return (Objects.equals(themeSetId, other.themeSetId)); + } + + @Override + public int hashCode() { + return Objects.hash(themeSetId); + } + } + + /** + * Converts a JSON String into a EmbeddedSession object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EmbeddedSession object represented by the provided JSON + */ + public static EmbeddedSession fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EmbeddedSession.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EmbeddedSession object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EmbeddedSession object represented by the provided JSON + */ + public static EmbeddedSession fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EmbeddedSession.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String id; + + @Getter + private final String sessionId; + + @Getter + private final String sessionToken; + + @JsonCreator + private EmbeddedSession( + @JsonProperty("id") final String id, + @JsonProperty("sessionId") final String sessionId, + @JsonProperty("sessionToken") final String sessionToken + ) { + this.id = id; + this.sessionId = sessionId; + this.sessionToken = sessionToken; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EmbeddedSession other = (EmbeddedSession) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(sessionToken, other.sessionToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, sessionId, sessionToken); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/EmbeddedSessionCreator.java b/src/main/java/com/twilio/rest/numbers/v1/EmbeddedSessionCreator.java new file mode 100644 index 0000000000..4b10e109d8 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/EmbeddedSessionCreator.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EmbeddedSessionCreator extends Creator { + + private String pathBundleSid; + private EmbeddedSession.NumbersV1CreateEmbeddedSessionRequest numbersV1CreateEmbeddedSessionRequest; + + public EmbeddedSessionCreator( + final String pathBundleSid, + final EmbeddedSession.NumbersV1CreateEmbeddedSessionRequest numbersV1CreateEmbeddedSessionRequest + ) { + this.pathBundleSid = pathBundleSid; + this.numbersV1CreateEmbeddedSessionRequest = + numbersV1CreateEmbeddedSessionRequest; + } + + public EmbeddedSessionCreator setNumbersV1CreateEmbeddedSessionRequest( + final EmbeddedSession.NumbersV1CreateEmbeddedSessionRequest numbersV1CreateEmbeddedSessionRequest + ) { + this.numbersV1CreateEmbeddedSessionRequest = + numbersV1CreateEmbeddedSessionRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SenderIdRegistrations/{BundleSid}/EmbeddedSessions"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EmbeddedSession creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EmbeddedSession create(final TwilioRestClient client) { + Response response = makeRequest(client); + return EmbeddedSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EmbeddedSession content = EmbeddedSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (numbersV1CreateEmbeddedSessionRequest != null) { + request.setBody( + EmbeddedSession.toJson( + numbersV1CreateEmbeddedSessionRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingAllPortIn.java b/src/main/java/com/twilio/rest/numbers/v1/PortingAllPortIn.java new file mode 100644 index 0000000000..91fb5b9b7a --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingAllPortIn.java @@ -0,0 +1,179 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PortingAllPortIn extends Resource { + + public static PortingAllPortInReader reader() { + return new PortingAllPortInReader(); + } + + /** + * Converts a JSON String into a PortingAllPortIn object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PortingAllPortIn object represented by the provided JSON + */ + public static PortingAllPortIn fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PortingAllPortIn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PortingAllPortIn object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PortingAllPortIn object represented by the provided JSON + */ + public static PortingAllPortIn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PortingAllPortIn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Integer phoneNumbersPorted; + + @Getter + private final Integer phoneNumbersRequested; + + @Getter + private final String portInRequestSid; + + @Getter + private final String portInRequestStatus; + + @Getter + private final String statusLastUpdatedTimestamp; + + @Getter + private final String suggestedAction; + + @JsonCreator + private PortingAllPortIn( + @JsonProperty("phone_numbers_ported") final Integer phoneNumbersPorted, + @JsonProperty( + "phone_numbers_requested" + ) final Integer phoneNumbersRequested, + @JsonProperty("port_in_request_sid") final String portInRequestSid, + @JsonProperty( + "port_in_request_status" + ) final String portInRequestStatus, + @JsonProperty( + "status_last_updated_timestamp" + ) final String statusLastUpdatedTimestamp, + @JsonProperty("suggested_action") final String suggestedAction + ) { + this.phoneNumbersPorted = phoneNumbersPorted; + this.phoneNumbersRequested = phoneNumbersRequested; + this.portInRequestSid = portInRequestSid; + this.portInRequestStatus = portInRequestStatus; + this.statusLastUpdatedTimestamp = statusLastUpdatedTimestamp; + this.suggestedAction = suggestedAction; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PortingAllPortIn other = (PortingAllPortIn) o; + return ( + Objects.equals(phoneNumbersPorted, other.phoneNumbersPorted) && + Objects.equals( + phoneNumbersRequested, + other.phoneNumbersRequested + ) && + Objects.equals(portInRequestSid, other.portInRequestSid) && + Objects.equals(portInRequestStatus, other.portInRequestStatus) && + Objects.equals( + statusLastUpdatedTimestamp, + other.statusLastUpdatedTimestamp + ) && + Objects.equals(suggestedAction, other.suggestedAction) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + phoneNumbersPorted, + phoneNumbersRequested, + portInRequestSid, + portInRequestStatus, + statusLastUpdatedTimestamp, + suggestedAction + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingAllPortInReader.java b/src/main/java/com/twilio/rest/numbers/v1/PortingAllPortInReader.java new file mode 100644 index 0000000000..77295a1828 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingAllPortInReader.java @@ -0,0 +1,271 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PortingAllPortInReader extends Reader { + + private String token; + private Integer size; + private String portInRequestSid; + private String portInRequestStatus; + private String createdBefore; + private String createdAfter; + + public PortingAllPortInReader() {} + + public PortingAllPortInReader setToken(final String token) { + this.token = token; + return this; + } + + public PortingAllPortInReader setSize(final Integer size) { + this.size = size; + return this; + } + + public PortingAllPortInReader setPortInRequestSid( + final String portInRequestSid + ) { + this.portInRequestSid = portInRequestSid; + return this; + } + + public PortingAllPortInReader setPortInRequestStatus( + final String portInRequestStatus + ) { + this.portInRequestStatus = portInRequestStatus; + return this; + } + + public PortingAllPortInReader setCreatedBefore(final String createdBefore) { + this.createdBefore = createdBefore; + return this; + } + + public PortingAllPortInReader setCreatedAfter(final String createdAfter) { + this.createdAfter = createdAfter; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "port_in_requests", + response.getContent(), + PortingAllPortIn.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Porting/PortIn/PortInRequests"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "port_in_requests", + response.getContent(), + PortingAllPortIn.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PortingAllPortIn read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "port_in_requests", + response.getContent(), + PortingAllPortIn.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (token != null) { + Serializer.toString(request, "Token", token, ParameterType.QUERY); + } + + if (size != null) { + Serializer.toString(request, "Size", size, ParameterType.QUERY); + } + + if (portInRequestSid != null) { + Serializer.toString( + request, + "PortInRequestSid", + portInRequestSid, + ParameterType.QUERY + ); + } + + if (portInRequestStatus != null) { + Serializer.toString( + request, + "PortInRequestStatus", + portInRequestStatus, + ParameterType.QUERY + ); + } + + if (createdBefore != null) { + Serializer.toString( + request, + "CreatedBefore", + createdBefore, + ParameterType.QUERY + ); + } + + if (createdAfter != null) { + Serializer.toString( + request, + "CreatedAfter", + createdAfter, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortIn.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortIn.java new file mode 100644 index 0000000000..3a23e4ac6a --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortIn.java @@ -0,0 +1,1467 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.LocalDate; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PortingPortIn extends Resource { + + public static PortingPortInCreator creator( + final PortingPortIn.NumbersV1PortingPortInCreate numbersV1PortingPortInCreate + ) { + return new PortingPortInCreator(numbersV1PortingPortInCreate); + } + + public static PortingPortInDeleter deleter( + final String pathPortInRequestSid + ) { + return new PortingPortInDeleter(pathPortInRequestSid); + } + + public static PortingPortInFetcher fetcher( + final String pathPortInRequestSid + ) { + return new PortingPortInFetcher(pathPortInRequestSid); + } + + public enum CustomerType { + BUSINESS("Business"), + INDIVIDUAL("Individual"); + + private final String value; + + private CustomerType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CustomerType forValue(final String value) { + return Promoter.enumFromString(value, CustomerType.values()); + } + } + + @JsonDeserialize(builder = NumbersV1PortingAddress.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1PortingAddress { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("street") + @Getter + private final String street; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("street_2") + @Getter + private final String street2; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("city") + @Getter + private final String city; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("state") + @Getter + private final String state; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("zip") + @Getter + private final String zip; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("country") + @Getter + private final String country; + + private NumbersV1PortingAddress(Builder builder) { + this.street = builder.street; + this.street2 = builder.street2; + this.city = builder.city; + this.state = builder.state; + this.zip = builder.zip; + this.country = builder.country; + } + + public static Builder builder( + final String street, + final String city, + final String state, + final String zip, + final String country + ) { + return new Builder(street, city, state, zip, country); + } + + public static NumbersV1PortingAddress fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, NumbersV1PortingAddress.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("street") + private String street; + + @JsonProperty("street_2") + private String street2; + + @JsonProperty("city") + private String city; + + @JsonProperty("state") + private String state; + + @JsonProperty("zip") + private String zip; + + @JsonProperty("country") + private String country; + + @JsonCreator + public Builder( + @JsonProperty("street") final String street, + @JsonProperty("city") final String city, + @JsonProperty("state") final String state, + @JsonProperty("zip") final String zip, + @JsonProperty("country") final String country + ) { + this.street = street; + this.city = city; + this.state = state; + this.zip = zip; + this.country = country; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("street_2") + public Builder street2(String street2) { + this.street2 = street2; + return this; + } + + public NumbersV1PortingAddress build() { + return new NumbersV1PortingAddress(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1PortingAddress other = (NumbersV1PortingAddress) o; + return ( + Objects.equals(street, other.street) && + Objects.equals(street2, other.street2) && + Objects.equals(city, other.city) && + Objects.equals(state, other.state) && + Objects.equals(zip, other.zip) && + Objects.equals(country, other.country) + ); + } + + @Override + public int hashCode() { + return Objects.hash(street, street2, city, state, zip, country); + } + } + + @JsonDeserialize( + builder = NumbersV1PortingPortInCreatePhoneNumbers.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1PortingPortInCreatePhoneNumbers { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + @Getter + private final String phoneNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pin") + @Getter + private final String pin; + + private NumbersV1PortingPortInCreatePhoneNumbers(Builder builder) { + this.phoneNumber = builder.phoneNumber; + this.pin = builder.pin; + } + + public static Builder builder(final String phoneNumber) { + return new Builder(phoneNumber); + } + + public static NumbersV1PortingPortInCreatePhoneNumbers fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1PortingPortInCreatePhoneNumbers.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("phone_number") + private String phoneNumber; + + @JsonProperty("pin") + private String pin; + + @JsonCreator + public Builder( + @JsonProperty("phone_number") final String phoneNumber + ) { + this.phoneNumber = phoneNumber; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("pin") + public Builder pin(String pin) { + this.pin = pin; + return this; + } + + public NumbersV1PortingPortInCreatePhoneNumbers build() { + return new NumbersV1PortingPortInCreatePhoneNumbers(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1PortingPortInCreatePhoneNumbers other = + (NumbersV1PortingPortInCreatePhoneNumbers) o; + return ( + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(pin, other.pin) + ); + } + + @Override + public int hashCode() { + return Objects.hash(phoneNumber, pin); + } + } + + @JsonDeserialize( + builder = NumbersV1PortingPortInPhoneNumberResult.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1PortingPortInPhoneNumberResult { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("not_portability_reason") + @Getter + private final String notPortabilityReason; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("not_portability_reason_code") + @Getter + private final Integer notPortabilityReasonCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_type") + @Getter + private final String numberType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + @Getter + private final String phoneNumber; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("port_date") + @Getter + private final ZonedDateTime portDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("port_in_phone_number_sid") + @Getter + private final String portInPhoneNumberSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("port_in_phone_number_status") + @Getter + private final String portInPhoneNumberStatus; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("portable") + @Getter + private final Boolean portable; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rejection_reason") + @Getter + private final String rejectionReason; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rejection_reason_code") + @Getter + private final String rejectionReasonCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_last_time_updated_timestamp") + @Getter + private final String statusLastTimeUpdatedTimestamp; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("external_porting_vendor_phone_number_id") + @Getter + private final String externalPortingVendorPhoneNumberId; + + private NumbersV1PortingPortInPhoneNumberResult(Builder builder) { + this.notPortabilityReason = builder.notPortabilityReason; + this.notPortabilityReasonCode = builder.notPortabilityReasonCode; + this.numberType = builder.numberType; + this.phoneNumber = builder.phoneNumber; + this.portDate = builder.portDate; + this.portInPhoneNumberSid = builder.portInPhoneNumberSid; + this.portInPhoneNumberStatus = builder.portInPhoneNumberStatus; + this.portable = builder.portable; + this.rejectionReason = builder.rejectionReason; + this.rejectionReasonCode = builder.rejectionReasonCode; + this.statusLastTimeUpdatedTimestamp = + builder.statusLastTimeUpdatedTimestamp; + this.externalPortingVendorPhoneNumberId = + builder.externalPortingVendorPhoneNumberId; + } + + public static Builder builder() { + return new Builder(); + } + + public static NumbersV1PortingPortInPhoneNumberResult fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1PortingPortInPhoneNumberResult.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("not_portability_reason") + private String notPortabilityReason; + + @JsonProperty("not_portability_reason_code") + private Integer notPortabilityReasonCode; + + @JsonProperty("number_type") + private String numberType; + + @JsonProperty("phone_number") + private String phoneNumber; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("port_date") + private ZonedDateTime portDate; + + @JsonProperty("port_in_phone_number_sid") + private String portInPhoneNumberSid; + + @JsonProperty("port_in_phone_number_status") + private String portInPhoneNumberStatus; + + @JsonProperty("portable") + private Boolean portable; + + @JsonProperty("rejection_reason") + private String rejectionReason; + + @JsonProperty("rejection_reason_code") + private String rejectionReasonCode; + + @JsonProperty("status_last_time_updated_timestamp") + private String statusLastTimeUpdatedTimestamp; + + @JsonProperty("external_porting_vendor_phone_number_id") + private String externalPortingVendorPhoneNumberId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("not_portability_reason") + public Builder notPortabilityReason(String notPortabilityReason) { + this.notPortabilityReason = notPortabilityReason; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("not_portability_reason_code") + public Builder notPortabilityReasonCode( + Integer notPortabilityReasonCode + ) { + this.notPortabilityReasonCode = notPortabilityReasonCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("number_type") + public Builder numberType(String numberType) { + this.numberType = numberType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + public Builder phoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("port_date") + public Builder portDate(ZonedDateTime portDate) { + this.portDate = portDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("port_in_phone_number_sid") + public Builder portInPhoneNumberSid(String portInPhoneNumberSid) { + this.portInPhoneNumberSid = portInPhoneNumberSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("port_in_phone_number_status") + public Builder portInPhoneNumberStatus( + String portInPhoneNumberStatus + ) { + this.portInPhoneNumberStatus = portInPhoneNumberStatus; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("portable") + public Builder portable(Boolean portable) { + this.portable = portable; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rejection_reason") + public Builder rejectionReason(String rejectionReason) { + this.rejectionReason = rejectionReason; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("rejection_reason_code") + public Builder rejectionReasonCode(String rejectionReasonCode) { + this.rejectionReasonCode = rejectionReasonCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_last_time_updated_timestamp") + public Builder statusLastTimeUpdatedTimestamp( + String statusLastTimeUpdatedTimestamp + ) { + this.statusLastTimeUpdatedTimestamp = + statusLastTimeUpdatedTimestamp; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("external_porting_vendor_phone_number_id") + public Builder externalPortingVendorPhoneNumberId( + String externalPortingVendorPhoneNumberId + ) { + this.externalPortingVendorPhoneNumberId = + externalPortingVendorPhoneNumberId; + return this; + } + + public NumbersV1PortingPortInPhoneNumberResult build() { + return new NumbersV1PortingPortInPhoneNumberResult(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1PortingPortInPhoneNumberResult other = + (NumbersV1PortingPortInPhoneNumberResult) o; + return ( + Objects.equals( + notPortabilityReason, + other.notPortabilityReason + ) && + Objects.equals( + notPortabilityReasonCode, + other.notPortabilityReasonCode + ) && + Objects.equals(numberType, other.numberType) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(portDate, other.portDate) && + Objects.equals( + portInPhoneNumberSid, + other.portInPhoneNumberSid + ) && + Objects.equals( + portInPhoneNumberStatus, + other.portInPhoneNumberStatus + ) && + Objects.equals(portable, other.portable) && + Objects.equals(rejectionReason, other.rejectionReason) && + Objects.equals( + rejectionReasonCode, + other.rejectionReasonCode + ) && + Objects.equals( + statusLastTimeUpdatedTimestamp, + other.statusLastTimeUpdatedTimestamp + ) && + Objects.equals( + externalPortingVendorPhoneNumberId, + other.externalPortingVendorPhoneNumberId + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + notPortabilityReason, + notPortabilityReasonCode, + numberType, + phoneNumber, + portDate, + portInPhoneNumberSid, + portInPhoneNumberStatus, + portable, + rejectionReason, + rejectionReasonCode, + statusLastTimeUpdatedTimestamp, + externalPortingVendorPhoneNumberId + ); + } + } + + @JsonDeserialize(builder = NumbersV1PortingPortInCreate.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1PortingPortInCreate { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_sid") + @Getter + private final String accountSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("documents") + @Getter + private final List documents; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_numbers") + @Getter + private final List< + NumbersV1PortingPortInCreatePhoneNumbers + > phoneNumbers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("losing_carrier_information") + @Getter + private final NumbersV1PortingLosingCarrierInformation losingCarrierInformation; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("notification_emails") + @Getter + private final List notificationEmails; + + @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("target_port_in_date") + @Getter + private final LocalDate targetPortInDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("target_port_in_time_range_start") + @Getter + private final String targetPortInTimeRangeStart; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("target_port_in_time_range_end") + @Getter + private final String targetPortInTimeRangeEnd; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bundle_sid") + @Getter + private final String bundleSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("portability_advance_carrier") + @Getter + private final String portabilityAdvanceCarrier; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("auto_cancel_approval_numbers") + @Getter + private final String autoCancelApprovalNumbers; + + private NumbersV1PortingPortInCreate(Builder builder) { + this.accountSid = builder.accountSid; + this.documents = builder.documents; + this.phoneNumbers = builder.phoneNumbers; + this.losingCarrierInformation = builder.losingCarrierInformation; + this.notificationEmails = builder.notificationEmails; + this.targetPortInDate = builder.targetPortInDate; + this.targetPortInTimeRangeStart = + builder.targetPortInTimeRangeStart; + this.targetPortInTimeRangeEnd = builder.targetPortInTimeRangeEnd; + this.bundleSid = builder.bundleSid; + this.portabilityAdvanceCarrier = builder.portabilityAdvanceCarrier; + this.autoCancelApprovalNumbers = builder.autoCancelApprovalNumbers; + } + + public static Builder builder( + final String accountSid, + final List documents, + final NumbersV1PortingLosingCarrierInformation losingCarrierInformation + ) { + return new Builder(accountSid, documents, losingCarrierInformation); + } + + public static NumbersV1PortingPortInCreate fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1PortingPortInCreate.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("account_sid") + private String accountSid; + + @JsonProperty("documents") + private List documents; + + @JsonProperty("phone_numbers") + private List phoneNumbers; + + @JsonProperty("losing_carrier_information") + private NumbersV1PortingLosingCarrierInformation losingCarrierInformation; + + @JsonProperty("notification_emails") + private List notificationEmails; + + @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) + @JsonProperty("target_port_in_date") + private LocalDate targetPortInDate; + + @JsonProperty("target_port_in_time_range_start") + private String targetPortInTimeRangeStart; + + @JsonProperty("target_port_in_time_range_end") + private String targetPortInTimeRangeEnd; + + @JsonProperty("bundle_sid") + private String bundleSid; + + @JsonProperty("portability_advance_carrier") + private String portabilityAdvanceCarrier; + + @JsonProperty("auto_cancel_approval_numbers") + private String autoCancelApprovalNumbers; + + @JsonCreator + public Builder( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("documents") final List documents, + @JsonProperty( + "losing_carrier_information" + ) final NumbersV1PortingLosingCarrierInformation losingCarrierInformation + ) { + this.accountSid = accountSid; + this.documents = documents; + this.losingCarrierInformation = losingCarrierInformation; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_numbers") + public Builder phoneNumbers( + List phoneNumbers + ) { + this.phoneNumbers = phoneNumbers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("notification_emails") + public Builder notificationEmails(List notificationEmails) { + this.notificationEmails = notificationEmails; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("target_port_in_date") + public Builder targetPortInDate(LocalDate targetPortInDate) { + this.targetPortInDate = targetPortInDate; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("target_port_in_time_range_start") + public Builder targetPortInTimeRangeStart( + String targetPortInTimeRangeStart + ) { + this.targetPortInTimeRangeStart = targetPortInTimeRangeStart; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("target_port_in_time_range_end") + public Builder targetPortInTimeRangeEnd( + String targetPortInTimeRangeEnd + ) { + this.targetPortInTimeRangeEnd = targetPortInTimeRangeEnd; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("bundle_sid") + public Builder bundleSid(String bundleSid) { + this.bundleSid = bundleSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("portability_advance_carrier") + public Builder portabilityAdvanceCarrier( + String portabilityAdvanceCarrier + ) { + this.portabilityAdvanceCarrier = portabilityAdvanceCarrier; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("auto_cancel_approval_numbers") + public Builder autoCancelApprovalNumbers( + String autoCancelApprovalNumbers + ) { + this.autoCancelApprovalNumbers = autoCancelApprovalNumbers; + return this; + } + + public NumbersV1PortingPortInCreate build() { + return new NumbersV1PortingPortInCreate(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1PortingPortInCreate other = + (NumbersV1PortingPortInCreate) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(documents, other.documents) && + Objects.equals(phoneNumbers, other.phoneNumbers) && + Objects.equals( + losingCarrierInformation, + other.losingCarrierInformation + ) && + Objects.equals(notificationEmails, other.notificationEmails) && + Objects.equals(targetPortInDate, other.targetPortInDate) && + Objects.equals( + targetPortInTimeRangeStart, + other.targetPortInTimeRangeStart + ) && + Objects.equals( + targetPortInTimeRangeEnd, + other.targetPortInTimeRangeEnd + ) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals( + portabilityAdvanceCarrier, + other.portabilityAdvanceCarrier + ) && + Objects.equals( + autoCancelApprovalNumbers, + other.autoCancelApprovalNumbers + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + documents, + phoneNumbers, + losingCarrierInformation, + notificationEmails, + targetPortInDate, + targetPortInTimeRangeStart, + targetPortInTimeRangeEnd, + bundleSid, + portabilityAdvanceCarrier, + autoCancelApprovalNumbers + ); + } + } + + @JsonDeserialize( + builder = NumbersV1PortingLosingCarrierInformation.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1PortingLosingCarrierInformation { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_name") + @Getter + private final String customerName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_number") + @Getter + private final String accountNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_telephone_number") + @Getter + private final String accountTelephoneNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_sid") + @Getter + private final String addressSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + @Getter + private final NumbersV1PortingAddress address; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("authorized_representative") + @Getter + private final String authorizedRepresentative; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("authorized_representative_email") + @Getter + private final String authorizedRepresentativeEmail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_type") + @Getter + private final PortingPortIn.CustomerType customerType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("authorized_representative_katakana") + @Getter + private final String authorizedRepresentativeKatakana; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sub_municipality") + @Getter + private final String subMunicipality; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("building") + @Getter + private final String building; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("katakana_name") + @Getter + private final String katakanaName; + + private NumbersV1PortingLosingCarrierInformation(Builder builder) { + this.customerName = builder.customerName; + this.accountNumber = builder.accountNumber; + this.accountTelephoneNumber = builder.accountTelephoneNumber; + this.addressSid = builder.addressSid; + this.address = builder.address; + this.authorizedRepresentative = builder.authorizedRepresentative; + this.authorizedRepresentativeEmail = + builder.authorizedRepresentativeEmail; + this.customerType = builder.customerType; + this.authorizedRepresentativeKatakana = + builder.authorizedRepresentativeKatakana; + this.subMunicipality = builder.subMunicipality; + this.building = builder.building; + this.katakanaName = builder.katakanaName; + } + + public static Builder builder( + final String customerName, + final String authorizedRepresentative, + final String authorizedRepresentativeEmail + ) { + return new Builder( + customerName, + authorizedRepresentative, + authorizedRepresentativeEmail + ); + } + + public static NumbersV1PortingLosingCarrierInformation fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1PortingLosingCarrierInformation.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("customer_name") + private String customerName; + + @JsonProperty("account_number") + private String accountNumber; + + @JsonProperty("account_telephone_number") + private String accountTelephoneNumber; + + @JsonProperty("address_sid") + private String addressSid; + + @JsonProperty("address") + private NumbersV1PortingAddress address; + + @JsonProperty("authorized_representative") + private String authorizedRepresentative; + + @JsonProperty("authorized_representative_email") + private String authorizedRepresentativeEmail; + + @JsonProperty("customer_type") + private PortingPortIn.CustomerType customerType; + + @JsonProperty("authorized_representative_katakana") + private String authorizedRepresentativeKatakana; + + @JsonProperty("sub_municipality") + private String subMunicipality; + + @JsonProperty("building") + private String building; + + @JsonProperty("katakana_name") + private String katakanaName; + + @JsonCreator + public Builder( + @JsonProperty("customer_name") final String customerName, + @JsonProperty( + "authorized_representative" + ) final String authorizedRepresentative, + @JsonProperty( + "authorized_representative_email" + ) final String authorizedRepresentativeEmail + ) { + this.customerName = customerName; + this.authorizedRepresentative = authorizedRepresentative; + this.authorizedRepresentativeEmail = + authorizedRepresentativeEmail; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_number") + public Builder accountNumber(String accountNumber) { + this.accountNumber = accountNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("account_telephone_number") + public Builder accountTelephoneNumber( + String accountTelephoneNumber + ) { + this.accountTelephoneNumber = accountTelephoneNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address_sid") + public Builder addressSid(String addressSid) { + this.addressSid = addressSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("address") + public Builder address(NumbersV1PortingAddress address) { + this.address = address; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_type") + public Builder customerType( + PortingPortIn.CustomerType customerType + ) { + this.customerType = customerType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("authorized_representative_katakana") + public Builder authorizedRepresentativeKatakana( + String authorizedRepresentativeKatakana + ) { + this.authorizedRepresentativeKatakana = + authorizedRepresentativeKatakana; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sub_municipality") + public Builder subMunicipality(String subMunicipality) { + this.subMunicipality = subMunicipality; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("building") + public Builder building(String building) { + this.building = building; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("katakana_name") + public Builder katakanaName(String katakanaName) { + this.katakanaName = katakanaName; + return this; + } + + public NumbersV1PortingLosingCarrierInformation build() { + return new NumbersV1PortingLosingCarrierInformation(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1PortingLosingCarrierInformation other = + (NumbersV1PortingLosingCarrierInformation) o; + return ( + Objects.equals(customerName, other.customerName) && + Objects.equals(accountNumber, other.accountNumber) && + Objects.equals( + accountTelephoneNumber, + other.accountTelephoneNumber + ) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(address, other.address) && + Objects.equals( + authorizedRepresentative, + other.authorizedRepresentative + ) && + Objects.equals( + authorizedRepresentativeEmail, + other.authorizedRepresentativeEmail + ) && + Objects.equals(customerType, other.customerType) && + Objects.equals( + authorizedRepresentativeKatakana, + other.authorizedRepresentativeKatakana + ) && + Objects.equals(subMunicipality, other.subMunicipality) && + Objects.equals(building, other.building) && + Objects.equals(katakanaName, other.katakanaName) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + customerName, + accountNumber, + accountTelephoneNumber, + addressSid, + address, + authorizedRepresentative, + authorizedRepresentativeEmail, + customerType, + authorizedRepresentativeKatakana, + subMunicipality, + building, + katakanaName + ); + } + } + + /** + * Converts a JSON String into a PortingPortIn object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PortingPortIn object represented by the provided JSON + */ + public static PortingPortIn fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PortingPortIn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PortingPortIn object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PortingPortIn object represented by the provided JSON + */ + public static PortingPortIn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PortingPortIn.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String autoCancelApprovalNumbers; + + @Getter + private final String bundleSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final List documents; + + @Getter + private final NumbersV1PortingLosingCarrierInformation losingCarrierInformation; + + @Getter + private final List notificationEmails; + + @Getter + private final String orderCancellationReason; + + @Getter + private final List phoneNumbers; + + @Getter + private final String portInRequestSid; + + @Getter + private final String portInRequestStatus; + + @Getter + private final String portabilityAdvanceCarrier; + + @Getter + private final URI signatureRequestUrl; + + @Getter + private final Integer supportTicketId; + + @Getter + private final LocalDate targetPortInDate; + + @Getter + private final String targetPortInTimeRangeEnd; + + @Getter + private final String targetPortInTimeRangeStart; + + @Getter + private final URI url; + + @JsonCreator + private PortingPortIn( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "auto_cancel_approval_numbers" + ) final String autoCancelApprovalNumbers, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("documents") final List documents, + @JsonProperty( + "losing_carrier_information" + ) final NumbersV1PortingLosingCarrierInformation losingCarrierInformation, + @JsonProperty("notification_emails") final List< + String + > notificationEmails, + @JsonProperty( + "order_cancellation_reason" + ) final String orderCancellationReason, + @JsonProperty("phone_numbers") final List< + NumbersV1PortingPortInPhoneNumberResult + > phoneNumbers, + @JsonProperty("port_in_request_sid") final String portInRequestSid, + @JsonProperty( + "port_in_request_status" + ) final String portInRequestStatus, + @JsonProperty( + "portability_advance_carrier" + ) final String portabilityAdvanceCarrier, + @JsonProperty("signature_request_url") final URI signatureRequestUrl, + @JsonProperty("support_ticket_id") final Integer supportTicketId, + @JsonProperty("target_port_in_date") @JsonDeserialize( + using = com.twilio.converter.LocalDateDeserializer.class + ) final LocalDate targetPortInDate, + @JsonProperty( + "target_port_in_time_range_end" + ) final String targetPortInTimeRangeEnd, + @JsonProperty( + "target_port_in_time_range_start" + ) final String targetPortInTimeRangeStart, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.autoCancelApprovalNumbers = autoCancelApprovalNumbers; + this.bundleSid = bundleSid; + this.dateCreated = dateCreated; + this.documents = documents; + this.losingCarrierInformation = losingCarrierInformation; + this.notificationEmails = notificationEmails; + this.orderCancellationReason = orderCancellationReason; + this.phoneNumbers = phoneNumbers; + this.portInRequestSid = portInRequestSid; + this.portInRequestStatus = portInRequestStatus; + this.portabilityAdvanceCarrier = portabilityAdvanceCarrier; + this.signatureRequestUrl = signatureRequestUrl; + this.supportTicketId = supportTicketId; + this.targetPortInDate = targetPortInDate; + this.targetPortInTimeRangeEnd = targetPortInTimeRangeEnd; + this.targetPortInTimeRangeStart = targetPortInTimeRangeStart; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PortingPortIn other = (PortingPortIn) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + autoCancelApprovalNumbers, + other.autoCancelApprovalNumbers + ) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(documents, other.documents) && + Objects.equals( + losingCarrierInformation, + other.losingCarrierInformation + ) && + Objects.equals(notificationEmails, other.notificationEmails) && + Objects.equals( + orderCancellationReason, + other.orderCancellationReason + ) && + Objects.equals(phoneNumbers, other.phoneNumbers) && + Objects.equals(portInRequestSid, other.portInRequestSid) && + Objects.equals(portInRequestStatus, other.portInRequestStatus) && + Objects.equals( + portabilityAdvanceCarrier, + other.portabilityAdvanceCarrier + ) && + Objects.equals(signatureRequestUrl, other.signatureRequestUrl) && + Objects.equals(supportTicketId, other.supportTicketId) && + Objects.equals(targetPortInDate, other.targetPortInDate) && + Objects.equals( + targetPortInTimeRangeEnd, + other.targetPortInTimeRangeEnd + ) && + Objects.equals( + targetPortInTimeRangeStart, + other.targetPortInTimeRangeStart + ) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + autoCancelApprovalNumbers, + bundleSid, + dateCreated, + documents, + losingCarrierInformation, + notificationEmails, + orderCancellationReason, + phoneNumbers, + portInRequestSid, + portInRequestStatus, + portabilityAdvanceCarrier, + signatureRequestUrl, + supportTicketId, + targetPortInDate, + targetPortInTimeRangeEnd, + targetPortInTimeRangeStart, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortInCreator.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInCreator.java new file mode 100644 index 0000000000..90a97d91c7 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInCreator.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PortingPortInCreator extends Creator { + + private PortingPortIn.NumbersV1PortingPortInCreate numbersV1PortingPortInCreate; + + public PortingPortInCreator( + final PortingPortIn.NumbersV1PortingPortInCreate numbersV1PortingPortInCreate + ) { + this.numbersV1PortingPortInCreate = numbersV1PortingPortInCreate; + } + + public PortingPortInCreator setNumbersV1PortingPortInCreate( + final PortingPortIn.NumbersV1PortingPortInCreate numbersV1PortingPortInCreate + ) { + this.numbersV1PortingPortInCreate = numbersV1PortingPortInCreate; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Porting/PortIn"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PortingPortIn creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PortingPortIn create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PortingPortIn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PortingPortIn content = PortingPortIn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (numbersV1PortingPortInCreate != null) { + request.setBody( + PortingPortIn.toJson(numbersV1PortingPortInCreate, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortInDeleter.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInDeleter.java new file mode 100644 index 0000000000..860be7e6f4 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInDeleter.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class PortingPortInDeleter extends Deleter { + + private String pathPortInRequestSid; + + public PortingPortInDeleter(final String pathPortInRequestSid) { + this.pathPortInRequestSid = pathPortInRequestSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Porting/PortIn/{PortInRequestSid}"; + + path = + path.replace( + "{" + "PortInRequestSid" + "}", + this.pathPortInRequestSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PortingPortIn delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortInFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInFetcher.java new file mode 100644 index 0000000000..40896e3da1 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PortingPortInFetcher extends Fetcher { + + private String pathPortInRequestSid; + + public PortingPortInFetcher(final String pathPortInRequestSid) { + this.pathPortInRequestSid = pathPortInRequestSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Porting/PortIn/{PortInRequestSid}"; + + path = + path.replace( + "{" + "PortInRequestSid" + "}", + this.pathPortInRequestSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PortingPortIn fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PortingPortIn fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PortingPortIn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PortingPortIn content = PortingPortIn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumber.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumber.java new file mode 100644 index 0000000000..1ca51f6937 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumber.java @@ -0,0 +1,307 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PortingPortInPhoneNumber extends Resource { + + public static PortingPortInPhoneNumberDeleter deleter( + final String pathPortInRequestSid, + final String pathPhoneNumberSid + ) { + return new PortingPortInPhoneNumberDeleter( + pathPortInRequestSid, + pathPhoneNumberSid + ); + } + + public static PortingPortInPhoneNumberFetcher fetcher( + final String pathPortInRequestSid, + final String pathPhoneNumberSid + ) { + return new PortingPortInPhoneNumberFetcher( + pathPortInRequestSid, + pathPhoneNumberSid + ); + } + + /** + * Converts a JSON String into a PortingPortInPhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PortingPortInPhoneNumber object represented by the provided JSON + */ + public static PortingPortInPhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PortingPortInPhoneNumber.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PortingPortInPhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PortingPortInPhoneNumber object represented by the provided JSON + */ + public static PortingPortInPhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PortingPortInPhoneNumber.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String country; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime lastUpdated; + + @Getter + private final Boolean missingRequiredFields; + + @Getter + private final String notPortabilityReason; + + @Getter + private final Integer notPortabilityReasonCode; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter + private final String phoneNumberSid; + + @Getter + private final String phoneNumberType; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime portDate; + + @Getter + private final String portInPhoneNumberStatus; + + @Getter + private final String portInRequestSid; + + @Getter + private final Integer portOutPin; + + @Getter + private final Boolean portable; + + @Getter + private final String rejectionReason; + + @Getter + private final Integer rejectionReasonCode; + + @Getter + private final URI url; + + @JsonCreator + private PortingPortInPhoneNumber( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("country") final String country, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("last_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime lastUpdated, + @JsonProperty( + "missing_required_fields" + ) final Boolean missingRequiredFields, + @JsonProperty( + "not_portability_reason" + ) final String notPortabilityReason, + @JsonProperty( + "not_portability_reason_code" + ) final Integer notPortabilityReasonCode, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("phone_number_sid") final String phoneNumberSid, + @JsonProperty("phone_number_type") final String phoneNumberType, + @JsonProperty("port_date") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime portDate, + @JsonProperty( + "port_in_phone_number_status" + ) final String portInPhoneNumberStatus, + @JsonProperty("port_in_request_sid") final String portInRequestSid, + @JsonProperty("port_out_pin") final Integer portOutPin, + @JsonProperty("portable") final Boolean portable, + @JsonProperty("rejection_reason") final String rejectionReason, + @JsonProperty( + "rejection_reason_code" + ) final Integer rejectionReasonCode, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.country = country; + this.dateCreated = dateCreated; + this.lastUpdated = lastUpdated; + this.missingRequiredFields = missingRequiredFields; + this.notPortabilityReason = notPortabilityReason; + this.notPortabilityReasonCode = notPortabilityReasonCode; + this.phoneNumber = phoneNumber; + this.phoneNumberSid = phoneNumberSid; + this.phoneNumberType = phoneNumberType; + this.portDate = portDate; + this.portInPhoneNumberStatus = portInPhoneNumberStatus; + this.portInRequestSid = portInRequestSid; + this.portOutPin = portOutPin; + this.portable = portable; + this.rejectionReason = rejectionReason; + this.rejectionReasonCode = rejectionReasonCode; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PortingPortInPhoneNumber other = (PortingPortInPhoneNumber) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(country, other.country) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(lastUpdated, other.lastUpdated) && + Objects.equals( + missingRequiredFields, + other.missingRequiredFields + ) && + Objects.equals(notPortabilityReason, other.notPortabilityReason) && + Objects.equals( + notPortabilityReasonCode, + other.notPortabilityReasonCode + ) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(phoneNumberSid, other.phoneNumberSid) && + Objects.equals(phoneNumberType, other.phoneNumberType) && + Objects.equals(portDate, other.portDate) && + Objects.equals( + portInPhoneNumberStatus, + other.portInPhoneNumberStatus + ) && + Objects.equals(portInRequestSid, other.portInRequestSid) && + Objects.equals(portOutPin, other.portOutPin) && + Objects.equals(portable, other.portable) && + Objects.equals(rejectionReason, other.rejectionReason) && + Objects.equals(rejectionReasonCode, other.rejectionReasonCode) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + country, + dateCreated, + lastUpdated, + missingRequiredFields, + notPortabilityReason, + notPortabilityReasonCode, + phoneNumber, + phoneNumberSid, + phoneNumberType, + portDate, + portInPhoneNumberStatus, + portInRequestSid, + portOutPin, + portable, + rejectionReason, + rejectionReasonCode, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumberDeleter.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumberDeleter.java new file mode 100644 index 0000000000..8906c223d6 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumberDeleter.java @@ -0,0 +1,113 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class PortingPortInPhoneNumberDeleter + extends Deleter { + + private String pathPortInRequestSid; + private String pathPhoneNumberSid; + + public PortingPortInPhoneNumberDeleter( + final String pathPortInRequestSid, + final String pathPhoneNumberSid + ) { + this.pathPortInRequestSid = pathPortInRequestSid; + this.pathPhoneNumberSid = pathPhoneNumberSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Porting/PortIn/{PortInRequestSid}/PhoneNumber/{PhoneNumberSid}"; + + path = + path.replace( + "{" + "PortInRequestSid" + "}", + this.pathPortInRequestSid.toString() + ); + path = + path.replace( + "{" + "PhoneNumberSid" + "}", + this.pathPhoneNumberSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PortingPortInPhoneNumber delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumberFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumberFetcher.java new file mode 100644 index 0000000000..7a0e16b987 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortInPhoneNumberFetcher.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PortingPortInPhoneNumberFetcher + extends Fetcher { + + private String pathPortInRequestSid; + private String pathPhoneNumberSid; + + public PortingPortInPhoneNumberFetcher( + final String pathPortInRequestSid, + final String pathPhoneNumberSid + ) { + this.pathPortInRequestSid = pathPortInRequestSid; + this.pathPhoneNumberSid = pathPhoneNumberSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Porting/PortIn/{PortInRequestSid}/PhoneNumber/{PhoneNumberSid}"; + + path = + path.replace( + "{" + "PortInRequestSid" + "}", + this.pathPortInRequestSid.toString() + ); + path = + path.replace( + "{" + "PhoneNumberSid" + "}", + this.pathPhoneNumberSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PortingPortInPhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PortingPortInPhoneNumber fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PortingPortInPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PortingPortInPhoneNumber content = PortingPortInPhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortability.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortability.java new file mode 100644 index 0000000000..7fa75bc9d7 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortability.java @@ -0,0 +1,230 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PortingPortability extends Resource { + + public static PortingPortabilityFetcher fetcher( + final com.twilio.type.PhoneNumber pathPhoneNumber + ) { + return new PortingPortabilityFetcher(pathPhoneNumber); + } + + public enum NumberType { + LOCAL("LOCAL"), + UNKNOWN("UNKNOWN"), + MOBILE("MOBILE"), + TOLL_FREE("TOLL-FREE"); + + private final String value; + + private NumberType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static NumberType forValue(final String value) { + return Promoter.enumFromString(value, NumberType.values()); + } + } + + /** + * Converts a JSON String into a PortingPortability object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PortingPortability object represented by the provided JSON + */ + public static PortingPortability fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PortingPortability.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PortingPortability object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PortingPortability object represented by the provided JSON + */ + public static PortingPortability fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PortingPortability.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String country; + + @Getter + private final String notPortableReason; + + @Getter + private final Integer notPortableReasonCode; + + @Getter + private final PortingPortability.NumberType numberType; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter + private final Boolean pinAndAccountNumberRequired; + + @Getter + private final Boolean portable; + + @Getter + private final URI url; + + @JsonCreator + private PortingPortability( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("country") final String country, + @JsonProperty("not_portable_reason") final String notPortableReason, + @JsonProperty( + "not_portable_reason_code" + ) final Integer notPortableReasonCode, + @JsonProperty( + "number_type" + ) final PortingPortability.NumberType numberType, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty( + "pin_and_account_number_required" + ) final Boolean pinAndAccountNumberRequired, + @JsonProperty("portable") final Boolean portable, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.country = country; + this.notPortableReason = notPortableReason; + this.notPortableReasonCode = notPortableReasonCode; + this.numberType = numberType; + this.phoneNumber = phoneNumber; + this.pinAndAccountNumberRequired = pinAndAccountNumberRequired; + this.portable = portable; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PortingPortability other = (PortingPortability) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(country, other.country) && + Objects.equals(notPortableReason, other.notPortableReason) && + Objects.equals( + notPortableReasonCode, + other.notPortableReasonCode + ) && + Objects.equals(numberType, other.numberType) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals( + pinAndAccountNumberRequired, + other.pinAndAccountNumberRequired + ) && + Objects.equals(portable, other.portable) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + country, + notPortableReason, + notPortableReasonCode, + numberType, + phoneNumber, + pinAndAccountNumberRequired, + portable, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingPortabilityFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/PortingPortabilityFetcher.java new file mode 100644 index 0000000000..16a22dcf63 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingPortabilityFetcher.java @@ -0,0 +1,139 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PortingPortabilityFetcher extends Fetcher { + + private com.twilio.type.PhoneNumber pathPhoneNumber; + private String targetAccountSid; + private String addressSid; + + public PortingPortabilityFetcher( + final com.twilio.type.PhoneNumber pathPhoneNumber + ) { + this.pathPhoneNumber = pathPhoneNumber; + } + + public PortingPortabilityFetcher setTargetAccountSid( + final String targetAccountSid + ) { + this.targetAccountSid = targetAccountSid; + return this; + } + + public PortingPortabilityFetcher setAddressSid(final String addressSid) { + this.addressSid = addressSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Porting/Portability/PhoneNumber/{PhoneNumber}"; + + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PortingPortability fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PortingPortability fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PortingPortability.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PortingPortability content = PortingPortability.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (targetAccountSid != null) { + Serializer.toString( + request, + "TargetAccountSid", + targetAccountSid, + ParameterType.QUERY + ); + } + + if (addressSid != null) { + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfiguration.java b/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfiguration.java new file mode 100644 index 0000000000..af3e79341d --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfiguration.java @@ -0,0 +1,161 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PortingWebhookConfiguration extends Resource { + + public static PortingWebhookConfigurationCreator creator() { + return new PortingWebhookConfigurationCreator(); + } + + /** + * Converts a JSON String into a PortingWebhookConfiguration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PortingWebhookConfiguration object represented by the provided JSON + */ + public static PortingWebhookConfiguration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PortingWebhookConfiguration.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PortingWebhookConfiguration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PortingWebhookConfiguration object represented by the provided JSON + */ + public static PortingWebhookConfiguration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PortingWebhookConfiguration.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List notificationsOf; + + @Getter + private final URI portInTargetUrl; + + @Getter + private final URI portOutTargetUrl; + + @Getter + private final URI url; + + @JsonCreator + private PortingWebhookConfiguration( + @JsonProperty("notifications_of") final List notificationsOf, + @JsonProperty("port_in_target_url") final URI portInTargetUrl, + @JsonProperty("port_out_target_url") final URI portOutTargetUrl, + @JsonProperty("url") final URI url + ) { + this.notificationsOf = notificationsOf; + this.portInTargetUrl = portInTargetUrl; + this.portOutTargetUrl = portOutTargetUrl; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PortingWebhookConfiguration other = (PortingWebhookConfiguration) o; + return ( + Objects.equals(notificationsOf, other.notificationsOf) && + Objects.equals(portInTargetUrl, other.portInTargetUrl) && + Objects.equals(portOutTargetUrl, other.portOutTargetUrl) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + notificationsOf, + portInTargetUrl, + portOutTargetUrl, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationCreator.java b/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationCreator.java new file mode 100644 index 0000000000..058ab19bdf --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationCreator.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PortingWebhookConfigurationCreator + extends Creator { + + private Object body; + + public PortingWebhookConfigurationCreator() {} + + public PortingWebhookConfigurationCreator setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Porting/Configuration/Webhook"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PortingWebhookConfiguration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PortingWebhookConfiguration create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PortingWebhookConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PortingWebhookConfiguration content = + PortingWebhookConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody( + PortingWebhookConfiguration.toJson(body, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationDelete.java b/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationDelete.java new file mode 100644 index 0000000000..1eded8b15f --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationDelete.java @@ -0,0 +1,140 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PortingWebhookConfigurationDelete extends Resource { + + public static PortingWebhookConfigurationDeleteDeleter deleter( + final PortingWebhookConfigurationDelete.WebhookType pathWebhookType + ) { + return new PortingWebhookConfigurationDeleteDeleter(pathWebhookType); + } + + public enum WebhookType { + PORT_IN("PORT_IN"), + PORT_OUT("PORT_OUT"); + + private final String value; + + private WebhookType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static WebhookType forValue(final String value) { + return Promoter.enumFromString(value, WebhookType.values()); + } + } + + /** + * Converts a JSON String into a PortingWebhookConfigurationDelete object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PortingWebhookConfigurationDelete object represented by the provided JSON + */ + public static PortingWebhookConfigurationDelete fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PortingWebhookConfigurationDelete.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PortingWebhookConfigurationDelete object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PortingWebhookConfigurationDelete object represented by the provided JSON + */ + public static PortingWebhookConfigurationDelete fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PortingWebhookConfigurationDelete.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private PortingWebhookConfigurationDelete() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationDeleteDeleter.java b/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationDeleteDeleter.java new file mode 100644 index 0000000000..87cdee2036 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/PortingWebhookConfigurationDeleteDeleter.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class PortingWebhookConfigurationDeleteDeleter + extends Deleter { + + private PortingWebhookConfigurationDelete.WebhookType pathWebhookType; + + public PortingWebhookConfigurationDeleteDeleter( + final PortingWebhookConfigurationDelete.WebhookType pathWebhookType + ) { + this.pathWebhookType = pathWebhookType; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Porting/Configuration/Webhook/{WebhookType}"; + + path = + path.replace( + "{" + "WebhookType" + "}", + this.pathWebhookType.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PortingWebhookConfigurationDelete delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SenderIdRegistration.java b/src/main/java/com/twilio/rest/numbers/v1/SenderIdRegistration.java new file mode 100644 index 0000000000..ef06f9cac5 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SenderIdRegistration.java @@ -0,0 +1,523 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SenderIdRegistration extends Resource { + + public static SenderIdRegistrationCreator creator( + final SenderIdRegistration.NumbersV1CreateEmbeddedRegistrationRequest numbersV1CreateEmbeddedRegistrationRequest + ) { + return new SenderIdRegistrationCreator( + numbersV1CreateEmbeddedRegistrationRequest + ); + } + + @JsonDeserialize(builder = NumbersV1EmbeddedSession.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1EmbeddedSession { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sessionId") + @Getter + private final String sessionId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sessionToken") + @Getter + private final String sessionToken; + + private NumbersV1EmbeddedSession(Builder builder) { + this.sessionId = builder.sessionId; + this.sessionToken = builder.sessionToken; + } + + public static Builder builder( + final String sessionId, + final String sessionToken + ) { + return new Builder(sessionId, sessionToken); + } + + public static NumbersV1EmbeddedSession fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, NumbersV1EmbeddedSession.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("sessionId") + private String sessionId; + + @JsonProperty("sessionToken") + private String sessionToken; + + @JsonCreator + public Builder( + @JsonProperty("sessionId") final String sessionId, + @JsonProperty("sessionToken") final String sessionToken + ) { + this.sessionId = sessionId; + this.sessionToken = sessionToken; + } + + public NumbersV1EmbeddedSession build() { + return new NumbersV1EmbeddedSession(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1EmbeddedSession other = (NumbersV1EmbeddedSession) o; + return ( + Objects.equals(sessionId, other.sessionId) && + Objects.equals(sessionToken, other.sessionToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(sessionId, sessionToken); + } + } + + @JsonDeserialize( + builder = NumbersV1CreateEmbeddedRegistrationRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1CreateEmbeddedRegistrationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("regulationId") + @Getter + private final String regulationId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("regulationVersion") + @Getter + private final Integer regulationVersion; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendlyName") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusNotificationEmail") + @Getter + private final String statusNotificationEmail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbackUrl") + @Getter + private final URI statusCallbackUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("comments") + @Getter + private final String comments; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("themeSetId") + @Getter + private final String themeSetId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("data") + @Getter + private final Map data; + + private NumbersV1CreateEmbeddedRegistrationRequest(Builder builder) { + this.regulationId = builder.regulationId; + this.regulationVersion = builder.regulationVersion; + this.friendlyName = builder.friendlyName; + this.statusNotificationEmail = builder.statusNotificationEmail; + this.statusCallbackUrl = builder.statusCallbackUrl; + this.comments = builder.comments; + this.themeSetId = builder.themeSetId; + this.data = builder.data; + } + + public static Builder builder( + final String regulationId, + final Integer regulationVersion, + final String friendlyName, + final Map data + ) { + return new Builder( + regulationId, + regulationVersion, + friendlyName, + data + ); + } + + public static NumbersV1CreateEmbeddedRegistrationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1CreateEmbeddedRegistrationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("regulationId") + private String regulationId; + + @JsonProperty("regulationVersion") + private Integer regulationVersion; + + @JsonProperty("friendlyName") + private String friendlyName; + + @JsonProperty("statusNotificationEmail") + private String statusNotificationEmail; + + @JsonProperty("statusCallbackUrl") + private URI statusCallbackUrl; + + @JsonProperty("comments") + private String comments; + + @JsonProperty("themeSetId") + private String themeSetId; + + @JsonProperty("data") + private Map data; + + @JsonCreator + public Builder( + @JsonProperty("regulationId") final String regulationId, + @JsonProperty( + "regulationVersion" + ) final Integer regulationVersion, + @JsonProperty("friendlyName") final String friendlyName, + @JsonProperty("data") final Map data + ) { + this.regulationId = regulationId; + this.regulationVersion = regulationVersion; + this.friendlyName = friendlyName; + this.data = data; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusNotificationEmail") + public Builder statusNotificationEmail( + String statusNotificationEmail + ) { + this.statusNotificationEmail = statusNotificationEmail; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("statusCallbackUrl") + public Builder statusCallbackUrl(URI statusCallbackUrl) { + this.statusCallbackUrl = statusCallbackUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("comments") + public Builder comments(String comments) { + this.comments = comments; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("themeSetId") + public Builder themeSetId(String themeSetId) { + this.themeSetId = themeSetId; + return this; + } + + public NumbersV1CreateEmbeddedRegistrationRequest build() { + return new NumbersV1CreateEmbeddedRegistrationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1CreateEmbeddedRegistrationRequest other = + (NumbersV1CreateEmbeddedRegistrationRequest) o; + return ( + Objects.equals(regulationId, other.regulationId) && + Objects.equals(regulationVersion, other.regulationVersion) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + statusNotificationEmail, + other.statusNotificationEmail + ) && + Objects.equals(statusCallbackUrl, other.statusCallbackUrl) && + Objects.equals(comments, other.comments) && + Objects.equals(themeSetId, other.themeSetId) && + Objects.equals(data, other.data) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + regulationId, + regulationVersion, + friendlyName, + statusNotificationEmail, + statusCallbackUrl, + comments, + themeSetId, + data + ); + } + } + + /** + * Converts a JSON String into a SenderIdRegistration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SenderIdRegistration object represented by the provided JSON + */ + public static SenderIdRegistration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SenderIdRegistration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SenderIdRegistration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SenderIdRegistration object represented by the provided JSON + */ + public static SenderIdRegistration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SenderIdRegistration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String comments; + + @Getter + private final Map data; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final NumbersV1EmbeddedSession embeddedSession; + + @Getter + private final String friendlyName; + + @Getter + private final String id; + + @Getter + private final String regulationId; + + @Getter + private final Integer regulationVersion; + + @Getter + private final String status; + + @Getter + private final String statusCallbackUrl; + + @Getter + private final String statusNotificationEmail; + + @JsonCreator + private SenderIdRegistration( + @JsonProperty("comments") final String comments, + @JsonProperty("data") final Map data, + @JsonProperty("dateCreated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "embeddedSession" + ) final NumbersV1EmbeddedSession embeddedSession, + @JsonProperty("friendlyName") final String friendlyName, + @JsonProperty("id") final String id, + @JsonProperty("regulationId") final String regulationId, + @JsonProperty("regulationVersion") final Integer regulationVersion, + @JsonProperty("status") final String status, + @JsonProperty("statusCallbackUrl") final String statusCallbackUrl, + @JsonProperty( + "statusNotificationEmail" + ) final String statusNotificationEmail + ) { + this.comments = comments; + this.data = data; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.embeddedSession = embeddedSession; + this.friendlyName = friendlyName; + this.id = id; + this.regulationId = regulationId; + this.regulationVersion = regulationVersion; + this.status = status; + this.statusCallbackUrl = statusCallbackUrl; + this.statusNotificationEmail = statusNotificationEmail; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SenderIdRegistration other = (SenderIdRegistration) o; + return ( + Objects.equals(comments, other.comments) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(embeddedSession, other.embeddedSession) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(id, other.id) && + Objects.equals(regulationId, other.regulationId) && + Objects.equals(regulationVersion, other.regulationVersion) && + Objects.equals(status, other.status) && + Objects.equals(statusCallbackUrl, other.statusCallbackUrl) && + Objects.equals( + statusNotificationEmail, + other.statusNotificationEmail + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + comments, + data, + dateCreated, + dateUpdated, + embeddedSession, + friendlyName, + id, + regulationId, + regulationVersion, + status, + statusCallbackUrl, + statusNotificationEmail + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SenderIdRegistrationCreator.java b/src/main/java/com/twilio/rest/numbers/v1/SenderIdRegistrationCreator.java new file mode 100644 index 0000000000..789b9b876e --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SenderIdRegistrationCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SenderIdRegistrationCreator extends Creator { + + private SenderIdRegistration.NumbersV1CreateEmbeddedRegistrationRequest numbersV1CreateEmbeddedRegistrationRequest; + + public SenderIdRegistrationCreator( + final SenderIdRegistration.NumbersV1CreateEmbeddedRegistrationRequest numbersV1CreateEmbeddedRegistrationRequest + ) { + this.numbersV1CreateEmbeddedRegistrationRequest = + numbersV1CreateEmbeddedRegistrationRequest; + } + + public SenderIdRegistrationCreator setNumbersV1CreateEmbeddedRegistrationRequest( + final SenderIdRegistration.NumbersV1CreateEmbeddedRegistrationRequest numbersV1CreateEmbeddedRegistrationRequest + ) { + this.numbersV1CreateEmbeddedRegistrationRequest = + numbersV1CreateEmbeddedRegistrationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SenderIdRegistrations"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SenderIdRegistration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SenderIdRegistration create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SenderIdRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SenderIdRegistration content = SenderIdRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (numbersV1CreateEmbeddedRegistrationRequest != null) { + request.setBody( + SenderIdRegistration.toJson( + numbersV1CreateEmbeddedRegistrationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfiguration.java b/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfiguration.java new file mode 100644 index 0000000000..1bd4624d7a --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfiguration.java @@ -0,0 +1,192 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SigningRequestConfiguration extends Resource { + + public static SigningRequestConfigurationCreator creator() { + return new SigningRequestConfigurationCreator(); + } + + public static SigningRequestConfigurationReader reader() { + return new SigningRequestConfigurationReader(); + } + + /** + * Converts a JSON String into a SigningRequestConfiguration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SigningRequestConfiguration object represented by the provided JSON + */ + public static SigningRequestConfiguration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + SigningRequestConfiguration.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SigningRequestConfiguration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SigningRequestConfiguration object represented by the provided JSON + */ + public static SigningRequestConfiguration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + SigningRequestConfiguration.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String country; + + @Getter + private final String emailMessage; + + @Getter + private final String emailSubject; + + @Getter + private final String friendlyName; + + @Getter + private final String logoSid; + + @Getter + private final String product; + + @Getter + private final URI url; + + @Getter + private final String urlRedirection; + + @JsonCreator + private SigningRequestConfiguration( + @JsonProperty("country") final String country, + @JsonProperty("email_message") final String emailMessage, + @JsonProperty("email_subject") final String emailSubject, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("logo_sid") final String logoSid, + @JsonProperty("product") final String product, + @JsonProperty("url") final URI url, + @JsonProperty("url_redirection") final String urlRedirection + ) { + this.country = country; + this.emailMessage = emailMessage; + this.emailSubject = emailSubject; + this.friendlyName = friendlyName; + this.logoSid = logoSid; + this.product = product; + this.url = url; + this.urlRedirection = urlRedirection; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SigningRequestConfiguration other = (SigningRequestConfiguration) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(emailMessage, other.emailMessage) && + Objects.equals(emailSubject, other.emailSubject) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(logoSid, other.logoSid) && + Objects.equals(product, other.product) && + Objects.equals(url, other.url) && + Objects.equals(urlRedirection, other.urlRedirection) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + country, + emailMessage, + emailSubject, + friendlyName, + logoSid, + product, + url, + urlRedirection + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfigurationCreator.java b/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfigurationCreator.java new file mode 100644 index 0000000000..0c48f025ee --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfigurationCreator.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SigningRequestConfigurationCreator + extends Creator { + + private Object body; + + public SigningRequestConfigurationCreator() {} + + public SigningRequestConfigurationCreator setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SigningRequest/Configuration"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SigningRequestConfiguration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SigningRequestConfiguration create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SigningRequestConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SigningRequestConfiguration content = + SigningRequestConfiguration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody( + SigningRequestConfiguration.toJson(body, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfigurationReader.java b/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfigurationReader.java new file mode 100644 index 0000000000..c0aecc693c --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SigningRequestConfigurationReader.java @@ -0,0 +1,234 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SigningRequestConfigurationReader + extends Reader { + + private String country; + private String product; + private Long pageSize; + + public SigningRequestConfigurationReader() {} + + public SigningRequestConfigurationReader setCountry(final String country) { + this.country = country; + return this; + } + + public SigningRequestConfigurationReader setProduct(final String product) { + this.product = product; + return this; + } + + public SigningRequestConfigurationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "configurations", + response.getContent(), + SigningRequestConfiguration.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/SigningRequest/Configuration"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "configurations", + response.getContent(), + SigningRequestConfiguration.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SigningRequestConfiguration read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "configurations", + response.getContent(), + SigningRequestConfiguration.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (country != null) { + Serializer.toString( + request, + "Country", + country, + ParameterType.QUERY + ); + } + + if (product != null) { + Serializer.toString( + request, + "Product", + product, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SmsVerification.java b/src/main/java/com/twilio/rest/numbers/v1/SmsVerification.java new file mode 100644 index 0000000000..c2e7db26fd --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SmsVerification.java @@ -0,0 +1,346 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SmsVerification extends Resource { + + public static SmsVerificationCreator creator( + final SmsVerification.NumbersV1SmsVerificationRequest numbersV1SmsVerificationRequest + ) { + return new SmsVerificationCreator(numbersV1SmsVerificationRequest); + } + + @JsonDeserialize(builder = NumbersV1SmsVerificationRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1SmsVerificationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + @Getter + private final String to; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("locale") + @Getter + private final String locale; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + private NumbersV1SmsVerificationRequest(Builder builder) { + this.to = builder.to; + this.locale = builder.locale; + this.friendlyName = builder.friendlyName; + } + + public static Builder builder(final String to) { + return new Builder(to); + } + + public static NumbersV1SmsVerificationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1SmsVerificationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("to") + private String to; + + @JsonProperty("locale") + private String locale; + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonCreator + public Builder(@JsonProperty("to") final String to) { + this.to = to; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("locale") + public Builder locale(String locale) { + this.locale = locale; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public NumbersV1SmsVerificationRequest build() { + return new NumbersV1SmsVerificationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1SmsVerificationRequest other = + (NumbersV1SmsVerificationRequest) o; + return ( + Objects.equals(to, other.to) && + Objects.equals(locale, other.locale) && + Objects.equals(friendlyName, other.friendlyName) + ); + } + + @Override + public int hashCode() { + return Objects.hash(to, locale, friendlyName); + } + } + + @JsonDeserialize( + builder = NumbersV1SmsVerificationSendCodeAttempts.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1SmsVerificationSendCodeAttempts { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("attemptSid") + @Getter + private final String attemptSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time") + @Getter + private final String time; + + private NumbersV1SmsVerificationSendCodeAttempts(Builder builder) { + this.attemptSid = builder.attemptSid; + this.time = builder.time; + } + + public static Builder builder() { + return new Builder(); + } + + public static NumbersV1SmsVerificationSendCodeAttempts fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1SmsVerificationSendCodeAttempts.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("attemptSid") + private String attemptSid; + + @JsonProperty("time") + private String time; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("attemptSid") + public Builder attemptSid(String attemptSid) { + this.attemptSid = attemptSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("time") + public Builder time(String time) { + this.time = time; + return this; + } + + public NumbersV1SmsVerificationSendCodeAttempts build() { + return new NumbersV1SmsVerificationSendCodeAttempts(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1SmsVerificationSendCodeAttempts other = + (NumbersV1SmsVerificationSendCodeAttempts) o; + return ( + Objects.equals(attemptSid, other.attemptSid) && + Objects.equals(time, other.time) + ); + } + + @Override + public int hashCode() { + return Objects.hash(attemptSid, time); + } + } + + /** + * Converts a JSON String into a SmsVerification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SmsVerification object represented by the provided JSON + */ + public static SmsVerification fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SmsVerification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SmsVerification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SmsVerification object represented by the provided JSON + */ + public static SmsVerification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SmsVerification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List< + NumbersV1SmsVerificationSendCodeAttempts + > sendCodeAttempts; + + @Getter + private final String to; + + @Getter + private final String verificationSid; + + @JsonCreator + private SmsVerification( + @JsonProperty("sendCodeAttempts") final List< + NumbersV1SmsVerificationSendCodeAttempts + > sendCodeAttempts, + @JsonProperty("to") final String to, + @JsonProperty("verificationSid") final String verificationSid + ) { + this.sendCodeAttempts = sendCodeAttempts; + this.to = to; + this.verificationSid = verificationSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SmsVerification other = (SmsVerification) o; + return ( + Objects.equals(sendCodeAttempts, other.sendCodeAttempts) && + Objects.equals(to, other.to) && + Objects.equals(verificationSid, other.verificationSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash(sendCodeAttempts, to, verificationSid); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCheck.java b/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCheck.java new file mode 100644 index 0000000000..c975c3313b --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCheck.java @@ -0,0 +1,261 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SmsVerificationCheck extends Resource { + + public static SmsVerificationCheckCreator creator( + final SmsVerificationCheck.NumbersV1SmsVerificationCheckRequest numbersV1SmsVerificationCheckRequest + ) { + return new SmsVerificationCheckCreator( + numbersV1SmsVerificationCheckRequest + ); + } + + @JsonDeserialize( + builder = NumbersV1SmsVerificationCheckRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1SmsVerificationCheckRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("to") + @Getter + private final String to; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("verification_code") + @Getter + private final String verificationCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + private NumbersV1SmsVerificationCheckRequest(Builder builder) { + this.to = builder.to; + this.verificationCode = builder.verificationCode; + this.friendlyName = builder.friendlyName; + } + + public static Builder builder( + final String to, + final String verificationCode + ) { + return new Builder(to, verificationCode); + } + + public static NumbersV1SmsVerificationCheckRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1SmsVerificationCheckRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("to") + private String to; + + @JsonProperty("verification_code") + private String verificationCode; + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonCreator + public Builder( + @JsonProperty("to") final String to, + @JsonProperty("verification_code") final String verificationCode + ) { + this.to = to; + this.verificationCode = verificationCode; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public NumbersV1SmsVerificationCheckRequest build() { + return new NumbersV1SmsVerificationCheckRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1SmsVerificationCheckRequest other = + (NumbersV1SmsVerificationCheckRequest) o; + return ( + Objects.equals(to, other.to) && + Objects.equals(verificationCode, other.verificationCode) && + Objects.equals(friendlyName, other.friendlyName) + ); + } + + @Override + public int hashCode() { + return Objects.hash(to, verificationCode, friendlyName); + } + } + + /** + * Converts a JSON String into a SmsVerificationCheck object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SmsVerificationCheck object represented by the provided JSON + */ + public static SmsVerificationCheck fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SmsVerificationCheck.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SmsVerificationCheck object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SmsVerificationCheck object represented by the provided JSON + */ + public static SmsVerificationCheck fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SmsVerificationCheck.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String callerIdSid; + + @Getter + private final String status; + + @Getter + private final String to; + + @Getter + private final String verificationSid; + + @JsonCreator + private SmsVerificationCheck( + @JsonProperty("callerIdSid") final String callerIdSid, + @JsonProperty("status") final String status, + @JsonProperty("to") final String to, + @JsonProperty("verificationSid") final String verificationSid + ) { + this.callerIdSid = callerIdSid; + this.status = status; + this.to = to; + this.verificationSid = verificationSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SmsVerificationCheck other = (SmsVerificationCheck) o; + return ( + Objects.equals(callerIdSid, other.callerIdSid) && + Objects.equals(status, other.status) && + Objects.equals(to, other.to) && + Objects.equals(verificationSid, other.verificationSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash(callerIdSid, status, to, verificationSid); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCheckCreator.java b/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCheckCreator.java new file mode 100644 index 0000000000..474f227a2f --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCheckCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SmsVerificationCheckCreator extends Creator { + + private SmsVerificationCheck.NumbersV1SmsVerificationCheckRequest numbersV1SmsVerificationCheckRequest; + + public SmsVerificationCheckCreator( + final SmsVerificationCheck.NumbersV1SmsVerificationCheckRequest numbersV1SmsVerificationCheckRequest + ) { + this.numbersV1SmsVerificationCheckRequest = + numbersV1SmsVerificationCheckRequest; + } + + public SmsVerificationCheckCreator setNumbersV1SmsVerificationCheckRequest( + final SmsVerificationCheck.NumbersV1SmsVerificationCheckRequest numbersV1SmsVerificationCheckRequest + ) { + this.numbersV1SmsVerificationCheckRequest = + numbersV1SmsVerificationCheckRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/CallerIds/SmsVerificationChecks"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SmsVerificationCheck creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SmsVerificationCheck create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SmsVerificationCheck.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SmsVerificationCheck content = SmsVerificationCheck.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (numbersV1SmsVerificationCheckRequest != null) { + request.setBody( + SmsVerificationCheck.toJson( + numbersV1SmsVerificationCheckRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCreator.java b/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCreator.java new file mode 100644 index 0000000000..24731d3fa8 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/SmsVerificationCreator.java @@ -0,0 +1,119 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SmsVerificationCreator extends Creator { + + private SmsVerification.NumbersV1SmsVerificationRequest numbersV1SmsVerificationRequest; + + public SmsVerificationCreator( + final SmsVerification.NumbersV1SmsVerificationRequest numbersV1SmsVerificationRequest + ) { + this.numbersV1SmsVerificationRequest = numbersV1SmsVerificationRequest; + } + + public SmsVerificationCreator setNumbersV1SmsVerificationRequest( + final SmsVerification.NumbersV1SmsVerificationRequest numbersV1SmsVerificationRequest + ) { + this.numbersV1SmsVerificationRequest = numbersV1SmsVerificationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/CallerIds/SmsVerifications"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SmsVerification creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SmsVerification create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SmsVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SmsVerification content = SmsVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (numbersV1SmsVerificationRequest != null) { + request.setBody( + SmsVerification.toJson( + numbersV1SmsVerificationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/VoiceVerification.java b/src/main/java/com/twilio/rest/numbers/v1/VoiceVerification.java new file mode 100644 index 0000000000..36ccaf544e --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/VoiceVerification.java @@ -0,0 +1,401 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class VoiceVerification extends Resource { + + public static VoiceVerificationCreator creator( + final VoiceVerification.NumbersV1VoiceVerificationRequest numbersV1VoiceVerificationRequest + ) { + return new VoiceVerificationCreator(numbersV1VoiceVerificationRequest); + } + + public enum StatusCallbackMethod { + HEAD("HEAD"), + GET("GET"), + POST("POST"), + PATCH("PATCH"), + PUT("PUT"), + DELETE("DELETE"); + + private final String value; + + private StatusCallbackMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static StatusCallbackMethod forValue(final String value) { + return Promoter.enumFromString( + value, + StatusCallbackMethod.values() + ); + } + } + + @JsonDeserialize(builder = NumbersV1VoiceVerificationRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class NumbersV1VoiceVerificationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("phone_number") + @Getter + private final String phoneNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("custom_code") + @Getter + private final String customCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_delay") + @Getter + private final String callDelay; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_callback") + @Getter + private final URI statusCallback; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_callback_method") + @Getter + private final VoiceVerification.StatusCallbackMethod statusCallbackMethod; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("extension") + @Getter + private final String extension; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("custom_success_message") + @Getter + private final String customSuccessMessage; + + private NumbersV1VoiceVerificationRequest(Builder builder) { + this.phoneNumber = builder.phoneNumber; + this.friendlyName = builder.friendlyName; + this.customCode = builder.customCode; + this.callDelay = builder.callDelay; + this.statusCallback = builder.statusCallback; + this.statusCallbackMethod = builder.statusCallbackMethod; + this.extension = builder.extension; + this.customSuccessMessage = builder.customSuccessMessage; + } + + public static Builder builder(final String phoneNumber) { + return new Builder(phoneNumber); + } + + public static NumbersV1VoiceVerificationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + NumbersV1VoiceVerificationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("phone_number") + private String phoneNumber; + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonProperty("custom_code") + private String customCode; + + @JsonProperty("call_delay") + private String callDelay; + + @JsonProperty("status_callback") + private URI statusCallback; + + @JsonProperty("status_callback_method") + private VoiceVerification.StatusCallbackMethod statusCallbackMethod; + + @JsonProperty("extension") + private String extension; + + @JsonProperty("custom_success_message") + private String customSuccessMessage; + + @JsonCreator + public Builder( + @JsonProperty("phone_number") final String phoneNumber + ) { + this.phoneNumber = phoneNumber; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("custom_code") + public Builder customCode(String customCode) { + this.customCode = customCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("call_delay") + public Builder callDelay(String callDelay) { + this.callDelay = callDelay; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_callback") + public Builder statusCallback(URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("status_callback_method") + public Builder statusCallbackMethod( + VoiceVerification.StatusCallbackMethod statusCallbackMethod + ) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("extension") + public Builder extension(String extension) { + this.extension = extension; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("custom_success_message") + public Builder customSuccessMessage(String customSuccessMessage) { + this.customSuccessMessage = customSuccessMessage; + return this; + } + + public NumbersV1VoiceVerificationRequest build() { + return new NumbersV1VoiceVerificationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NumbersV1VoiceVerificationRequest other = + (NumbersV1VoiceVerificationRequest) o; + return ( + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(customCode, other.customCode) && + Objects.equals(callDelay, other.callDelay) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals( + statusCallbackMethod, + other.statusCallbackMethod + ) && + Objects.equals(extension, other.extension) && + Objects.equals(customSuccessMessage, other.customSuccessMessage) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + phoneNumber, + friendlyName, + customCode, + callDelay, + statusCallback, + statusCallbackMethod, + extension, + customSuccessMessage + ); + } + } + + /** + * Converts a JSON String into a VoiceVerification object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return VoiceVerification object represented by the provided JSON + */ + public static VoiceVerification fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, VoiceVerification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a VoiceVerification object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return VoiceVerification object represented by the provided JSON + */ + public static VoiceVerification fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, VoiceVerification.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String callSid; + + @Getter + private final String friendlyName; + + @Getter + private final String phoneNumber; + + @Getter + private final String validationCode; + + @JsonCreator + private VoiceVerification( + @JsonProperty("accountSid") final String accountSid, + @JsonProperty("callSid") final String callSid, + @JsonProperty("friendlyName") final String friendlyName, + @JsonProperty("phoneNumber") final String phoneNumber, + @JsonProperty("validationCode") final String validationCode + ) { + this.accountSid = accountSid; + this.callSid = callSid; + this.friendlyName = friendlyName; + this.phoneNumber = phoneNumber; + this.validationCode = validationCode; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + VoiceVerification other = (VoiceVerification) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callSid, other.callSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(validationCode, other.validationCode) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + callSid, + friendlyName, + phoneNumber, + validationCode + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/VoiceVerificationCreator.java b/src/main/java/com/twilio/rest/numbers/v1/VoiceVerificationCreator.java new file mode 100644 index 0000000000..00f15b4832 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/VoiceVerificationCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class VoiceVerificationCreator extends Creator { + + private VoiceVerification.NumbersV1VoiceVerificationRequest numbersV1VoiceVerificationRequest; + + public VoiceVerificationCreator( + final VoiceVerification.NumbersV1VoiceVerificationRequest numbersV1VoiceVerificationRequest + ) { + this.numbersV1VoiceVerificationRequest = + numbersV1VoiceVerificationRequest; + } + + public VoiceVerificationCreator setNumbersV1VoiceVerificationRequest( + final VoiceVerification.NumbersV1VoiceVerificationRequest numbersV1VoiceVerificationRequest + ) { + this.numbersV1VoiceVerificationRequest = + numbersV1VoiceVerificationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/CallerIds/VoiceVerifications"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "VoiceVerification creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public VoiceVerification create(final TwilioRestClient client) { + Response response = makeRequest(client); + return VoiceVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + VoiceVerification content = VoiceVerification.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (numbersV1VoiceVerificationRequest != null) { + request.setBody( + VoiceVerification.toJson( + numbersV1VoiceVerificationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/Webhook.java b/src/main/java/com/twilio/rest/numbers/v1/Webhook.java new file mode 100644 index 0000000000..e3507e825d --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/Webhook.java @@ -0,0 +1,188 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Webhook extends Resource { + + public static WebhookFetcher fetcher() { + return new WebhookFetcher(); + } + + /** + * Converts a JSON String into a Webhook object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Webhook object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Webhook object represented by the provided JSON + */ + public static Webhook fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Webhook.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List notificationsOf; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime portInTargetDateCreated; + + @Getter + private final URI portInTargetUrl; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime portOutTargetDateCreated; + + @Getter + private final URI portOutTargetUrl; + + @Getter + private final URI url; + + @JsonCreator + private Webhook( + @JsonProperty("notifications_of") final List notificationsOf, + @JsonProperty("port_in_target_date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime portInTargetDateCreated, + @JsonProperty("port_in_target_url") final URI portInTargetUrl, + @JsonProperty("port_out_target_date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime portOutTargetDateCreated, + @JsonProperty("port_out_target_url") final URI portOutTargetUrl, + @JsonProperty("url") final URI url + ) { + this.notificationsOf = notificationsOf; + this.portInTargetDateCreated = portInTargetDateCreated; + this.portInTargetUrl = portInTargetUrl; + this.portOutTargetDateCreated = portOutTargetDateCreated; + this.portOutTargetUrl = portOutTargetUrl; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Webhook other = (Webhook) o; + return ( + Objects.equals(notificationsOf, other.notificationsOf) && + Objects.equals( + portInTargetDateCreated, + other.portInTargetDateCreated + ) && + Objects.equals(portInTargetUrl, other.portInTargetUrl) && + Objects.equals( + portOutTargetDateCreated, + other.portOutTargetDateCreated + ) && + Objects.equals(portOutTargetUrl, other.portOutTargetUrl) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + notificationsOf, + portInTargetDateCreated, + portInTargetUrl, + portOutTargetDateCreated, + portOutTargetUrl, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v1/WebhookFetcher.java b/src/main/java/com/twilio/rest/numbers/v1/WebhookFetcher.java new file mode 100644 index 0000000000..ed085acb47 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v1/WebhookFetcher.java @@ -0,0 +1,87 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class WebhookFetcher extends Fetcher { + + public WebhookFetcher() {} + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Porting/Configuration/Webhook"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Webhook fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Webhook fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Webhook.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Webhook content = Webhook.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/Application.java b/src/main/java/com/twilio/rest/numbers/v2/Application.java new file mode 100644 index 0000000000..160c15af49 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/Application.java @@ -0,0 +1,2168 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Application extends Resource { + + public static ApplicationCreator creator( + final Application.CreateShortCodeApplicationRequest createShortCodeApplicationRequest + ) { + return new ApplicationCreator(createShortCodeApplicationRequest); + } + + public static ApplicationFetcher fetcher(final String pathSid) { + return new ApplicationFetcher(pathSid); + } + + public static ApplicationReader reader() { + return new ApplicationReader(); + } + + public enum SignUpOptions { + ONLINE_WEB_FORM("ONLINE_WEB_FORM"), + IVR("IVR"), + VERBALLY("VERBALLY"), + MOBILE_APP_OR_DIGITAL_KIOSK("MOBILE_APP_OR_DIGITAL_KIOSK"), + PAPER_FORM("PAPER_FORM"), + SHORTCODE_KEYWORD("SHORTCODE_KEYWORD"), + OTHER_FORM("OTHER_FORM"); + + private final String value; + + private SignUpOptions(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static SignUpOptions forValue(final String value) { + return Promoter.enumFromString(value, SignUpOptions.values()); + } + } + + public enum CampaignFrequency { + ONE_MESSAGE_PER_SIGNUP("ONE_MESSAGE_PER_SIGNUP"), + LIMITED_NUMBER_OF_MESSAGES_PER_SIGNUP( + "LIMITED_NUMBER_OF_MESSAGES_PER_SIGNUP" + ), + LIMITED_NUMBER_OF_MESSAGES_AT_RECURRING_INTERVALS( + "LIMITED_NUMBER_OF_MESSAGES_AT_RECURRING_INTERVALS" + ), + VARIABLE_NUMBER_OF_MESSAGES_AT_UNPREDICTABLE_INTERVALS( + "VARIABLE_NUMBER_OF_MESSAGES_AT_UNPREDICTABLE_INTERVALS" + ), + LIMITED_NUMBER_OF_MESSAGES_IN_RESPONSE_TO_KEYWORDS( + "LIMITED_NUMBER_OF_MESSAGES_IN_RESPONSE_TO_KEYWORDS" + ); + + private final String value; + + private CampaignFrequency(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CampaignFrequency forValue(final String value) { + return Promoter.enumFromString(value, CampaignFrequency.values()); + } + } + + public enum State { + DRAFT("DRAFT"), + TWILIO_REVIEW("TWILIO_REVIEW"), + PENDING_PAYMENT("PENDING_PAYMENT"), + PAYMENT_FAILED("PAYMENT_FAILED"), + IN_PROVISIONING("IN_PROVISIONING"), + PENDING_CARRIER("PENDING_CARRIER"), + APPROVED("APPROVED"), + CORRECTIONS_NEEDED("CORRECTIONS_NEEDED"), + CANCELED("CANCELED"), + ARCHIVED("ARCHIVED"); + + private final String value; + + private State(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static State forValue(final String value) { + return Promoter.enumFromString(value, State.values()); + } + } + + public enum PaymentFrequency { + QUARTERLY("QUARTERLY"), + YEARLY("YEARLY"); + + private final String value; + + private PaymentFrequency(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static PaymentFrequency forValue(final String value) { + return Promoter.enumFromString(value, PaymentFrequency.values()); + } + } + + public enum CustomerCareChannel { + TOLL_FREE_NUMBER("TOLL_FREE_NUMBER"), + EMAIL("EMAIL"); + + private final String value; + + private CustomerCareChannel(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CustomerCareChannel forValue(final String value) { + return Promoter.enumFromString(value, CustomerCareChannel.values()); + } + } + + public enum ScUseCaseCategories { + TWO_FACTOR_AUTHENTICATION("TWO_FACTOR_AUTHENTICATION"), + ACCOUNT_NOTIFICATIONS("ACCOUNT_NOTIFICATIONS"), + CUSTOMER_CARE("CUSTOMER_CARE"), + CHARITY_NONPROFIT("CHARITY_NONPROFIT"), + DELIVERY_NOTIFICATIONS("DELIVERY_NOTIFICATIONS"), + FRAUD_ALERT_MESSAGING("FRAUD_ALERT_MESSAGING"), + EVENTS("EVENTS"), + HIGHER_EDUCATION("HIGHER_EDUCATION"), + K12("K12"), + MARKETING("MARKETING"), + POLLING_AND_VOTING_NON_POLITICAL("POLLING_AND_VOTING_NON_POLITICAL"), + POLITICAL_ELECTION_CAMPAIGNS("POLITICAL_ELECTION_CAMPAIGNS"), + PUBLIC_SERVICE_ANNOUNCEMENT("PUBLIC_SERVICE_ANNOUNCEMENT"), + SECURITY_ALERT("SECURITY_ALERT"); + + private final String value; + + private ScUseCaseCategories(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static ScUseCaseCategories forValue(final String value) { + return Promoter.enumFromString(value, ScUseCaseCategories.values()); + } + } + + public enum LeaseType { + RANDOM("RANDOM"), + VANITY("VANITY"), + SELF_LEASED("SELF_LEASED"); + + private final String value; + + private LeaseType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static LeaseType forValue(final String value) { + return Promoter.enumFromString(value, LeaseType.values()); + } + } + + public enum RequestType { + NEW("NEW"), + MIGRATION("MIGRATION"), + LEASE("LEASE"); + + private final String value; + + private RequestType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RequestType forValue(final String value) { + return Promoter.enumFromString(value, RequestType.values()); + } + } + + public enum TrafficType { + TRANSACTIONAL("TRANSACTIONAL"), + PROMOTIONAL("PROMOTIONAL"), + BOTH("BOTH"); + + private final String value; + + private TrafficType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static TrafficType forValue(final String value) { + return Promoter.enumFromString(value, TrafficType.values()); + } + } + + @JsonDeserialize( + builder = CreateShortCodeApplicationResponseUserSignUp.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationResponseUserSignUp { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sign_up_options") + @Getter + private final List signUpOptions; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("double_opt_in_process") + @Getter + private final Boolean doubleOptInProcess; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("double_opt_in_message") + @Getter + private final String doubleOptInMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sign_up_confirmation_message") + @Getter + private final String signUpConfirmationMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("double_opt_in_response_message") + @Getter + private final String doubleOptInResponseMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("online_web_form_message") + @Getter + private final String onlineWebFormMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("keyword_message") + @Getter + private final String keywordMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ivr_message") + @Getter + private final String ivrMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("other_form_message") + @Getter + private final String otherFormMessage; + + private CreateShortCodeApplicationResponseUserSignUp(Builder builder) { + this.signUpOptions = builder.signUpOptions; + this.doubleOptInProcess = builder.doubleOptInProcess; + this.doubleOptInMessage = builder.doubleOptInMessage; + this.signUpConfirmationMessage = builder.signUpConfirmationMessage; + this.doubleOptInResponseMessage = + builder.doubleOptInResponseMessage; + this.onlineWebFormMessage = builder.onlineWebFormMessage; + this.keywordMessage = builder.keywordMessage; + this.ivrMessage = builder.ivrMessage; + this.otherFormMessage = builder.otherFormMessage; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateShortCodeApplicationResponseUserSignUp fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationResponseUserSignUp.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("sign_up_options") + private List signUpOptions; + + @JsonProperty("double_opt_in_process") + private Boolean doubleOptInProcess; + + @JsonProperty("double_opt_in_message") + private String doubleOptInMessage; + + @JsonProperty("sign_up_confirmation_message") + private String signUpConfirmationMessage; + + @JsonProperty("double_opt_in_response_message") + private String doubleOptInResponseMessage; + + @JsonProperty("online_web_form_message") + private String onlineWebFormMessage; + + @JsonProperty("keyword_message") + private String keywordMessage; + + @JsonProperty("ivr_message") + private String ivrMessage; + + @JsonProperty("other_form_message") + private String otherFormMessage; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sign_up_options") + public Builder signUpOptions( + List signUpOptions + ) { + this.signUpOptions = signUpOptions; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("double_opt_in_process") + public Builder doubleOptInProcess(Boolean doubleOptInProcess) { + this.doubleOptInProcess = doubleOptInProcess; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("double_opt_in_message") + public Builder doubleOptInMessage(String doubleOptInMessage) { + this.doubleOptInMessage = doubleOptInMessage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sign_up_confirmation_message") + public Builder signUpConfirmationMessage( + String signUpConfirmationMessage + ) { + this.signUpConfirmationMessage = signUpConfirmationMessage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("double_opt_in_response_message") + public Builder doubleOptInResponseMessage( + String doubleOptInResponseMessage + ) { + this.doubleOptInResponseMessage = doubleOptInResponseMessage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("online_web_form_message") + public Builder onlineWebFormMessage(String onlineWebFormMessage) { + this.onlineWebFormMessage = onlineWebFormMessage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("keyword_message") + public Builder keywordMessage(String keywordMessage) { + this.keywordMessage = keywordMessage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ivr_message") + public Builder ivrMessage(String ivrMessage) { + this.ivrMessage = ivrMessage; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("other_form_message") + public Builder otherFormMessage(String otherFormMessage) { + this.otherFormMessage = otherFormMessage; + return this; + } + + public CreateShortCodeApplicationResponseUserSignUp build() { + return new CreateShortCodeApplicationResponseUserSignUp(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationResponseUserSignUp other = + (CreateShortCodeApplicationResponseUserSignUp) o; + return ( + Objects.equals(signUpOptions, other.signUpOptions) && + Objects.equals(doubleOptInProcess, other.doubleOptInProcess) && + Objects.equals(doubleOptInMessage, other.doubleOptInMessage) && + Objects.equals( + signUpConfirmationMessage, + other.signUpConfirmationMessage + ) && + Objects.equals( + doubleOptInResponseMessage, + other.doubleOptInResponseMessage + ) && + Objects.equals( + onlineWebFormMessage, + other.onlineWebFormMessage + ) && + Objects.equals(keywordMessage, other.keywordMessage) && + Objects.equals(ivrMessage, other.ivrMessage) && + Objects.equals(otherFormMessage, other.otherFormMessage) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + signUpOptions, + doubleOptInProcess, + doubleOptInMessage, + signUpConfirmationMessage, + doubleOptInResponseMessage, + onlineWebFormMessage, + keywordMessage, + ivrMessage, + otherFormMessage + ); + } + } + + @JsonDeserialize(builder = CreateShortCodeApplicationRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendly_name") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("iso_country") + @Getter + private final String isoCountry; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("business_information") + @Getter + private final CreateShortCodeApplicationRequestBusinessInformation businessInformation; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("setup") + @Getter + private final CreateShortCodeApplicationRequestSetup setup; + + private CreateShortCodeApplicationRequest(Builder builder) { + this.friendlyName = builder.friendlyName; + this.isoCountry = builder.isoCountry; + this.businessInformation = builder.businessInformation; + this.setup = builder.setup; + } + + public static Builder builder( + final String friendlyName, + final String isoCountry, + final CreateShortCodeApplicationRequestBusinessInformation businessInformation, + final CreateShortCodeApplicationRequestSetup setup + ) { + return new Builder( + friendlyName, + isoCountry, + businessInformation, + setup + ); + } + + public static CreateShortCodeApplicationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("friendly_name") + private String friendlyName; + + @JsonProperty("iso_country") + private String isoCountry; + + @JsonProperty("business_information") + private CreateShortCodeApplicationRequestBusinessInformation businessInformation; + + @JsonProperty("setup") + private CreateShortCodeApplicationRequestSetup setup; + + @JsonCreator + public Builder( + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "business_information" + ) final CreateShortCodeApplicationRequestBusinessInformation businessInformation, + @JsonProperty( + "setup" + ) final CreateShortCodeApplicationRequestSetup setup + ) { + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.businessInformation = businessInformation; + this.setup = setup; + } + + public CreateShortCodeApplicationRequest build() { + return new CreateShortCodeApplicationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationRequest other = + (CreateShortCodeApplicationRequest) o; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals( + businessInformation, + other.businessInformation + ) && + Objects.equals(setup, other.setup) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + friendlyName, + isoCountry, + businessInformation, + setup + ); + } + } + + @JsonDeserialize( + builder = CreateShortCodeApplicationResponseSetup.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationResponseSetup { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("request_type") + @Getter + private final Application.RequestType requestType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traffic_type") + @Getter + private final Application.TrafficType trafficType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("lease_type") + @Getter + private final Application.LeaseType leaseType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("payment_frequency") + @Getter + private final Application.PaymentFrequency paymentFrequency; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("short_code_preference") + @Getter + private final String shortCodePreference; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mms_enabled") + @Getter + private final Boolean mmsEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("free_to_end_user") + @Getter + private final Boolean freeToEndUser; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("charges_apply") + @Getter + private final Boolean chargesApply; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("current_provider") + @Getter + private final String currentProvider; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("migrated_mms_enabled") + @Getter + private final Boolean migratedMmsEnabled; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("migrated_live_traffic") + @Getter + private final Boolean migratedLiveTraffic; + + private CreateShortCodeApplicationResponseSetup(Builder builder) { + this.requestType = builder.requestType; + this.trafficType = builder.trafficType; + this.leaseType = builder.leaseType; + this.paymentFrequency = builder.paymentFrequency; + this.shortCodePreference = builder.shortCodePreference; + this.mmsEnabled = builder.mmsEnabled; + this.freeToEndUser = builder.freeToEndUser; + this.chargesApply = builder.chargesApply; + this.currentProvider = builder.currentProvider; + this.migratedMmsEnabled = builder.migratedMmsEnabled; + this.migratedLiveTraffic = builder.migratedLiveTraffic; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateShortCodeApplicationResponseSetup fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationResponseSetup.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("request_type") + private Application.RequestType requestType; + + @JsonProperty("traffic_type") + private Application.TrafficType trafficType; + + @JsonProperty("lease_type") + private Application.LeaseType leaseType; + + @JsonProperty("payment_frequency") + private Application.PaymentFrequency paymentFrequency; + + @JsonProperty("short_code_preference") + private String shortCodePreference; + + @JsonProperty("mms_enabled") + private Boolean mmsEnabled; + + @JsonProperty("free_to_end_user") + private Boolean freeToEndUser; + + @JsonProperty("charges_apply") + private Boolean chargesApply; + + @JsonProperty("current_provider") + private String currentProvider; + + @JsonProperty("migrated_mms_enabled") + private Boolean migratedMmsEnabled; + + @JsonProperty("migrated_live_traffic") + private Boolean migratedLiveTraffic; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("request_type") + public Builder requestType(Application.RequestType requestType) { + this.requestType = requestType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("traffic_type") + public Builder trafficType(Application.TrafficType trafficType) { + this.trafficType = trafficType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("lease_type") + public Builder leaseType(Application.LeaseType leaseType) { + this.leaseType = leaseType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("payment_frequency") + public Builder paymentFrequency( + Application.PaymentFrequency paymentFrequency + ) { + this.paymentFrequency = paymentFrequency; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("short_code_preference") + public Builder shortCodePreference(String shortCodePreference) { + this.shortCodePreference = shortCodePreference; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("mms_enabled") + public Builder mmsEnabled(Boolean mmsEnabled) { + this.mmsEnabled = mmsEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("free_to_end_user") + public Builder freeToEndUser(Boolean freeToEndUser) { + this.freeToEndUser = freeToEndUser; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("charges_apply") + public Builder chargesApply(Boolean chargesApply) { + this.chargesApply = chargesApply; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("current_provider") + public Builder currentProvider(String currentProvider) { + this.currentProvider = currentProvider; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("migrated_mms_enabled") + public Builder migratedMmsEnabled(Boolean migratedMmsEnabled) { + this.migratedMmsEnabled = migratedMmsEnabled; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("migrated_live_traffic") + public Builder migratedLiveTraffic(Boolean migratedLiveTraffic) { + this.migratedLiveTraffic = migratedLiveTraffic; + return this; + } + + public CreateShortCodeApplicationResponseSetup build() { + return new CreateShortCodeApplicationResponseSetup(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationResponseSetup other = + (CreateShortCodeApplicationResponseSetup) o; + return ( + Objects.equals(requestType, other.requestType) && + Objects.equals(trafficType, other.trafficType) && + Objects.equals(leaseType, other.leaseType) && + Objects.equals(paymentFrequency, other.paymentFrequency) && + Objects.equals( + shortCodePreference, + other.shortCodePreference + ) && + Objects.equals(mmsEnabled, other.mmsEnabled) && + Objects.equals(freeToEndUser, other.freeToEndUser) && + Objects.equals(chargesApply, other.chargesApply) && + Objects.equals(currentProvider, other.currentProvider) && + Objects.equals(migratedMmsEnabled, other.migratedMmsEnabled) && + Objects.equals(migratedLiveTraffic, other.migratedLiveTraffic) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + requestType, + trafficType, + leaseType, + paymentFrequency, + shortCodePreference, + mmsEnabled, + freeToEndUser, + chargesApply, + currentProvider, + migratedMmsEnabled, + migratedLiveTraffic + ); + } + } + + @JsonDeserialize( + builder = CreateShortCodeApplicationRequestSetup.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationRequestSetup { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("charges_apply") + @Getter + private final Boolean chargesApply; + + private CreateShortCodeApplicationRequestSetup(Builder builder) { + this.chargesApply = builder.chargesApply; + } + + public static Builder builder(final Boolean chargesApply) { + return new Builder(chargesApply); + } + + public static CreateShortCodeApplicationRequestSetup fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationRequestSetup.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("charges_apply") + private Boolean chargesApply; + + @JsonCreator + public Builder( + @JsonProperty("charges_apply") final Boolean chargesApply + ) { + this.chargesApply = chargesApply; + } + + public CreateShortCodeApplicationRequestSetup build() { + return new CreateShortCodeApplicationRequestSetup(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationRequestSetup other = + (CreateShortCodeApplicationRequestSetup) o; + return (Objects.equals(chargesApply, other.chargesApply)); + } + + @Override + public int hashCode() { + return Objects.hash(chargesApply); + } + } + + @JsonDeserialize( + builder = CreateShortCodeApplicationResponseComplianceKeywords.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationResponseComplianceKeywords { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("help") + @Getter + private final String help; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stop") + @Getter + private final String stop; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("info") + @Getter + private final String info; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("aide") + @Getter + private final String aide; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("arret") + @Getter + private final String arret; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("opt_out_filtering") + @Getter + private final Boolean optOutFiltering; + + private CreateShortCodeApplicationResponseComplianceKeywords( + Builder builder + ) { + this.help = builder.help; + this.stop = builder.stop; + this.info = builder.info; + this.aide = builder.aide; + this.arret = builder.arret; + this.optOutFiltering = builder.optOutFiltering; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateShortCodeApplicationResponseComplianceKeywords fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationResponseComplianceKeywords.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("help") + private String help; + + @JsonProperty("stop") + private String stop; + + @JsonProperty("info") + private String info; + + @JsonProperty("aide") + private String aide; + + @JsonProperty("arret") + private String arret; + + @JsonProperty("opt_out_filtering") + private Boolean optOutFiltering; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("help") + public Builder help(String help) { + this.help = help; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("stop") + public Builder stop(String stop) { + this.stop = stop; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("info") + public Builder info(String info) { + this.info = info; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("aide") + public Builder aide(String aide) { + this.aide = aide; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("arret") + public Builder arret(String arret) { + this.arret = arret; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("opt_out_filtering") + public Builder optOutFiltering(Boolean optOutFiltering) { + this.optOutFiltering = optOutFiltering; + return this; + } + + public CreateShortCodeApplicationResponseComplianceKeywords build() { + return new CreateShortCodeApplicationResponseComplianceKeywords( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationResponseComplianceKeywords other = + (CreateShortCodeApplicationResponseComplianceKeywords) o; + return ( + Objects.equals(help, other.help) && + Objects.equals(stop, other.stop) && + Objects.equals(info, other.info) && + Objects.equals(aide, other.aide) && + Objects.equals(arret, other.arret) && + Objects.equals(optOutFiltering, other.optOutFiltering) + ); + } + + @Override + public int hashCode() { + return Objects.hash(help, stop, info, aide, arret, optOutFiltering); + } + } + + @JsonDeserialize( + builder = CreateShortCodeApplicationResponseBusinessInformation.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationResponseBusinessInformation { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("managing_company_profile") + @Getter + private final String managingCompanyProfile; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_facing_profile") + @Getter + private final String customerFacingProfile; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("business_website") + @Getter + private final String businessWebsite; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ein_managing_company_profile") + @Getter + private final String einManagingCompanyProfile; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ein_customer_facing_profile") + @Getter + private final String einCustomerFacingProfile; + + private CreateShortCodeApplicationResponseBusinessInformation( + Builder builder + ) { + this.managingCompanyProfile = builder.managingCompanyProfile; + this.customerFacingProfile = builder.customerFacingProfile; + this.businessWebsite = builder.businessWebsite; + this.einManagingCompanyProfile = builder.einManagingCompanyProfile; + this.einCustomerFacingProfile = builder.einCustomerFacingProfile; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateShortCodeApplicationResponseBusinessInformation fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationResponseBusinessInformation.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("managing_company_profile") + private String managingCompanyProfile; + + @JsonProperty("customer_facing_profile") + private String customerFacingProfile; + + @JsonProperty("business_website") + private String businessWebsite; + + @JsonProperty("ein_managing_company_profile") + private String einManagingCompanyProfile; + + @JsonProperty("ein_customer_facing_profile") + private String einCustomerFacingProfile; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("managing_company_profile") + public Builder managingCompanyProfile( + String managingCompanyProfile + ) { + this.managingCompanyProfile = managingCompanyProfile; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_facing_profile") + public Builder customerFacingProfile(String customerFacingProfile) { + this.customerFacingProfile = customerFacingProfile; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("business_website") + public Builder businessWebsite(String businessWebsite) { + this.businessWebsite = businessWebsite; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ein_managing_company_profile") + public Builder einManagingCompanyProfile( + String einManagingCompanyProfile + ) { + this.einManagingCompanyProfile = einManagingCompanyProfile; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ein_customer_facing_profile") + public Builder einCustomerFacingProfile( + String einCustomerFacingProfile + ) { + this.einCustomerFacingProfile = einCustomerFacingProfile; + return this; + } + + public CreateShortCodeApplicationResponseBusinessInformation build() { + return new CreateShortCodeApplicationResponseBusinessInformation( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationResponseBusinessInformation other = + (CreateShortCodeApplicationResponseBusinessInformation) o; + return ( + Objects.equals( + managingCompanyProfile, + other.managingCompanyProfile + ) && + Objects.equals( + customerFacingProfile, + other.customerFacingProfile + ) && + Objects.equals(businessWebsite, other.businessWebsite) && + Objects.equals( + einManagingCompanyProfile, + other.einManagingCompanyProfile + ) && + Objects.equals( + einCustomerFacingProfile, + other.einCustomerFacingProfile + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + managingCompanyProfile, + customerFacingProfile, + businessWebsite, + einManagingCompanyProfile, + einCustomerFacingProfile + ); + } + } + + @JsonDeserialize( + builder = CreateShortCodeApplicationResponseContentExamples.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationResponseContentExamples { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("examples") + @Getter + private final List examples; + + private CreateShortCodeApplicationResponseContentExamples( + Builder builder + ) { + this.examples = builder.examples; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateShortCodeApplicationResponseContentExamples fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationResponseContentExamples.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("examples") + private List examples; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("examples") + public Builder examples(List examples) { + this.examples = examples; + return this; + } + + public CreateShortCodeApplicationResponseContentExamples build() { + return new CreateShortCodeApplicationResponseContentExamples( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationResponseContentExamples other = + (CreateShortCodeApplicationResponseContentExamples) o; + return (Objects.equals(examples, other.examples)); + } + + @Override + public int hashCode() { + return Objects.hash(examples); + } + } + + @JsonDeserialize( + builder = CreateShortCodeApplicationResponseSmsCampaignDetails.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationResponseSmsCampaignDetails { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("campaign_name") + @Getter + private final String campaignName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("campaign_brand_website") + @Getter + private final String campaignBrandWebsite; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_care_channel") + @Getter + private final Application.CustomerCareChannel customerCareChannel; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_care_value") + @Getter + private final String customerCareValue; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("campaign_frequency") + @Getter + private final List campaignFrequency; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sc_use_case_categories") + @Getter + private final List scUseCaseCategories; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_terms_of_service_url") + @Getter + private final String smsTermsOfServiceUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_privacy_policy_url") + @Getter + private final String smsPrivacyPolicyUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("monthly_outbound_volume_expected") + @Getter + private final String monthlyOutboundVolumeExpected; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("monthly_inbound_volume_expected") + @Getter + private final String monthlyInboundVolumeExpected; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("avg_monthly_messages_sent_to_each_subscriber") + @Getter + private final String avgMonthlyMessagesSentToEachSubscriber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("avg_monthly_messages_received_from_subscribers") + @Getter + private final String avgMonthlyMessagesReceivedFromSubscribers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("estimated_total_subscribers") + @Getter + private final String estimatedTotalSubscribers; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("duration_of_the_campaign") + @Getter + private final String durationOfTheCampaign; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("planned_traffic_spikes") + @Getter + private final String plannedTrafficSpikes; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("spike_details") + @Getter + private final String spikeDetails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("expected_traffic_start_date") + @Getter + private final String expectedTrafficStartDate; + + private CreateShortCodeApplicationResponseSmsCampaignDetails( + Builder builder + ) { + this.campaignName = builder.campaignName; + this.campaignBrandWebsite = builder.campaignBrandWebsite; + this.customerCareChannel = builder.customerCareChannel; + this.customerCareValue = builder.customerCareValue; + this.campaignFrequency = builder.campaignFrequency; + this.scUseCaseCategories = builder.scUseCaseCategories; + this.smsTermsOfServiceUrl = builder.smsTermsOfServiceUrl; + this.smsPrivacyPolicyUrl = builder.smsPrivacyPolicyUrl; + this.monthlyOutboundVolumeExpected = + builder.monthlyOutboundVolumeExpected; + this.monthlyInboundVolumeExpected = + builder.monthlyInboundVolumeExpected; + this.avgMonthlyMessagesSentToEachSubscriber = + builder.avgMonthlyMessagesSentToEachSubscriber; + this.avgMonthlyMessagesReceivedFromSubscribers = + builder.avgMonthlyMessagesReceivedFromSubscribers; + this.estimatedTotalSubscribers = builder.estimatedTotalSubscribers; + this.durationOfTheCampaign = builder.durationOfTheCampaign; + this.plannedTrafficSpikes = builder.plannedTrafficSpikes; + this.spikeDetails = builder.spikeDetails; + this.expectedTrafficStartDate = builder.expectedTrafficStartDate; + } + + public static Builder builder() { + return new Builder(); + } + + public static CreateShortCodeApplicationResponseSmsCampaignDetails fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationResponseSmsCampaignDetails.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("campaign_name") + private String campaignName; + + @JsonProperty("campaign_brand_website") + private String campaignBrandWebsite; + + @JsonProperty("customer_care_channel") + private Application.CustomerCareChannel customerCareChannel; + + @JsonProperty("customer_care_value") + private String customerCareValue; + + @JsonProperty("campaign_frequency") + private List campaignFrequency; + + @JsonProperty("sc_use_case_categories") + private List scUseCaseCategories; + + @JsonProperty("sms_terms_of_service_url") + private String smsTermsOfServiceUrl; + + @JsonProperty("sms_privacy_policy_url") + private String smsPrivacyPolicyUrl; + + @JsonProperty("monthly_outbound_volume_expected") + private String monthlyOutboundVolumeExpected; + + @JsonProperty("monthly_inbound_volume_expected") + private String monthlyInboundVolumeExpected; + + @JsonProperty("avg_monthly_messages_sent_to_each_subscriber") + private String avgMonthlyMessagesSentToEachSubscriber; + + @JsonProperty("avg_monthly_messages_received_from_subscribers") + private String avgMonthlyMessagesReceivedFromSubscribers; + + @JsonProperty("estimated_total_subscribers") + private String estimatedTotalSubscribers; + + @JsonProperty("duration_of_the_campaign") + private String durationOfTheCampaign; + + @JsonProperty("planned_traffic_spikes") + private String plannedTrafficSpikes; + + @JsonProperty("spike_details") + private String spikeDetails; + + @JsonProperty("expected_traffic_start_date") + private String expectedTrafficStartDate; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("campaign_name") + public Builder campaignName(String campaignName) { + this.campaignName = campaignName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("campaign_brand_website") + public Builder campaignBrandWebsite(String campaignBrandWebsite) { + this.campaignBrandWebsite = campaignBrandWebsite; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_care_channel") + public Builder customerCareChannel( + Application.CustomerCareChannel customerCareChannel + ) { + this.customerCareChannel = customerCareChannel; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_care_value") + public Builder customerCareValue(String customerCareValue) { + this.customerCareValue = customerCareValue; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("campaign_frequency") + public Builder campaignFrequency( + List campaignFrequency + ) { + this.campaignFrequency = campaignFrequency; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sc_use_case_categories") + public Builder scUseCaseCategories( + List scUseCaseCategories + ) { + this.scUseCaseCategories = scUseCaseCategories; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_terms_of_service_url") + public Builder smsTermsOfServiceUrl(String smsTermsOfServiceUrl) { + this.smsTermsOfServiceUrl = smsTermsOfServiceUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("sms_privacy_policy_url") + public Builder smsPrivacyPolicyUrl(String smsPrivacyPolicyUrl) { + this.smsPrivacyPolicyUrl = smsPrivacyPolicyUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("monthly_outbound_volume_expected") + public Builder monthlyOutboundVolumeExpected( + String monthlyOutboundVolumeExpected + ) { + this.monthlyOutboundVolumeExpected = + monthlyOutboundVolumeExpected; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("monthly_inbound_volume_expected") + public Builder monthlyInboundVolumeExpected( + String monthlyInboundVolumeExpected + ) { + this.monthlyInboundVolumeExpected = + monthlyInboundVolumeExpected; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("avg_monthly_messages_sent_to_each_subscriber") + public Builder avgMonthlyMessagesSentToEachSubscriber( + String avgMonthlyMessagesSentToEachSubscriber + ) { + this.avgMonthlyMessagesSentToEachSubscriber = + avgMonthlyMessagesSentToEachSubscriber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("avg_monthly_messages_received_from_subscribers") + public Builder avgMonthlyMessagesReceivedFromSubscribers( + String avgMonthlyMessagesReceivedFromSubscribers + ) { + this.avgMonthlyMessagesReceivedFromSubscribers = + avgMonthlyMessagesReceivedFromSubscribers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("estimated_total_subscribers") + public Builder estimatedTotalSubscribers( + String estimatedTotalSubscribers + ) { + this.estimatedTotalSubscribers = estimatedTotalSubscribers; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("duration_of_the_campaign") + public Builder durationOfTheCampaign(String durationOfTheCampaign) { + this.durationOfTheCampaign = durationOfTheCampaign; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("planned_traffic_spikes") + public Builder plannedTrafficSpikes(String plannedTrafficSpikes) { + this.plannedTrafficSpikes = plannedTrafficSpikes; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("spike_details") + public Builder spikeDetails(String spikeDetails) { + this.spikeDetails = spikeDetails; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("expected_traffic_start_date") + public Builder expectedTrafficStartDate( + String expectedTrafficStartDate + ) { + this.expectedTrafficStartDate = expectedTrafficStartDate; + return this; + } + + public CreateShortCodeApplicationResponseSmsCampaignDetails build() { + return new CreateShortCodeApplicationResponseSmsCampaignDetails( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationResponseSmsCampaignDetails other = + (CreateShortCodeApplicationResponseSmsCampaignDetails) o; + return ( + Objects.equals(campaignName, other.campaignName) && + Objects.equals( + campaignBrandWebsite, + other.campaignBrandWebsite + ) && + Objects.equals( + customerCareChannel, + other.customerCareChannel + ) && + Objects.equals(customerCareValue, other.customerCareValue) && + Objects.equals(campaignFrequency, other.campaignFrequency) && + Objects.equals( + scUseCaseCategories, + other.scUseCaseCategories + ) && + Objects.equals( + smsTermsOfServiceUrl, + other.smsTermsOfServiceUrl + ) && + Objects.equals( + smsPrivacyPolicyUrl, + other.smsPrivacyPolicyUrl + ) && + Objects.equals( + monthlyOutboundVolumeExpected, + other.monthlyOutboundVolumeExpected + ) && + Objects.equals( + monthlyInboundVolumeExpected, + other.monthlyInboundVolumeExpected + ) && + Objects.equals( + avgMonthlyMessagesSentToEachSubscriber, + other.avgMonthlyMessagesSentToEachSubscriber + ) && + Objects.equals( + avgMonthlyMessagesReceivedFromSubscribers, + other.avgMonthlyMessagesReceivedFromSubscribers + ) && + Objects.equals( + estimatedTotalSubscribers, + other.estimatedTotalSubscribers + ) && + Objects.equals( + durationOfTheCampaign, + other.durationOfTheCampaign + ) && + Objects.equals( + plannedTrafficSpikes, + other.plannedTrafficSpikes + ) && + Objects.equals(spikeDetails, other.spikeDetails) && + Objects.equals( + expectedTrafficStartDate, + other.expectedTrafficStartDate + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + campaignName, + campaignBrandWebsite, + customerCareChannel, + customerCareValue, + campaignFrequency, + scUseCaseCategories, + smsTermsOfServiceUrl, + smsPrivacyPolicyUrl, + monthlyOutboundVolumeExpected, + monthlyInboundVolumeExpected, + avgMonthlyMessagesSentToEachSubscriber, + avgMonthlyMessagesReceivedFromSubscribers, + estimatedTotalSubscribers, + durationOfTheCampaign, + plannedTrafficSpikes, + spikeDetails, + expectedTrafficStartDate + ); + } + } + + @JsonDeserialize( + builder = CreateShortCodeApplicationRequestBusinessInformation.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class CreateShortCodeApplicationRequestBusinessInformation { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("customer_facing_profile") + @Getter + private final String customerFacingProfile; + + private CreateShortCodeApplicationRequestBusinessInformation( + Builder builder + ) { + this.customerFacingProfile = builder.customerFacingProfile; + } + + public static Builder builder(final String customerFacingProfile) { + return new Builder(customerFacingProfile); + } + + public static CreateShortCodeApplicationRequestBusinessInformation fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + CreateShortCodeApplicationRequestBusinessInformation.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("customer_facing_profile") + private String customerFacingProfile; + + @JsonCreator + public Builder( + @JsonProperty( + "customer_facing_profile" + ) final String customerFacingProfile + ) { + this.customerFacingProfile = customerFacingProfile; + } + + public CreateShortCodeApplicationRequestBusinessInformation build() { + return new CreateShortCodeApplicationRequestBusinessInformation( + this + ); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CreateShortCodeApplicationRequestBusinessInformation other = + (CreateShortCodeApplicationRequestBusinessInformation) o; + return ( + Objects.equals( + customerFacingProfile, + other.customerFacingProfile + ) + ); + } + + @Override + public int hashCode() { + return Objects.hash(customerFacingProfile); + } + } + + /** + * Converts a JSON String into a Application object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Application object represented by the provided JSON + */ + public static Application fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Application.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Application object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Application object represented by the provided JSON + */ + public static Application fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Application.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String applicationRequirementsSid; + + @Getter + private final Integer applicationRequirementsVersion; + + @Getter + private final String bundleSid; + + @Getter + private final CreateShortCodeApplicationResponseBusinessInformation businessInformation; + + @Getter + private final CreateShortCodeApplicationResponseComplianceKeywords complianceKeywords; + + @Getter + private final CreateShortCodeApplicationResponseContentExamples contentExamples; + + @Getter + private final String createdBy; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String isoCountry; + + @Getter + private final List notificationEmails; + + @Getter + private final String reviewer; + + @Getter + private final CreateShortCodeApplicationResponseSetup setup; + + @Getter + private final String sid; + + @Getter + private final CreateShortCodeApplicationResponseSmsCampaignDetails smsCampaignDetails; + + @Getter + private final Application.State state; + + @Getter + private final String updatedBy; + + @Getter + private final CreateShortCodeApplicationResponseUserSignUp userSignUp; + + @Getter + private final String zendeskTicketId; + + @JsonCreator + private Application( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "application_requirements_sid" + ) final String applicationRequirementsSid, + @JsonProperty( + "application_requirements_version" + ) final Integer applicationRequirementsVersion, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty( + "business_information" + ) final CreateShortCodeApplicationResponseBusinessInformation businessInformation, + @JsonProperty( + "compliance_keywords" + ) final CreateShortCodeApplicationResponseComplianceKeywords complianceKeywords, + @JsonProperty( + "content_examples" + ) final CreateShortCodeApplicationResponseContentExamples contentExamples, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("notification_emails") final List< + String + > notificationEmails, + @JsonProperty("reviewer") final String reviewer, + @JsonProperty( + "setup" + ) final CreateShortCodeApplicationResponseSetup setup, + @JsonProperty("sid") final String sid, + @JsonProperty( + "sms_campaign_details" + ) final CreateShortCodeApplicationResponseSmsCampaignDetails smsCampaignDetails, + @JsonProperty("state") final Application.State state, + @JsonProperty("updated_by") final String updatedBy, + @JsonProperty( + "user_sign_up" + ) final CreateShortCodeApplicationResponseUserSignUp userSignUp, + @JsonProperty("zendesk_ticket_id") final String zendeskTicketId + ) { + this.accountSid = accountSid; + this.applicationRequirementsSid = applicationRequirementsSid; + this.applicationRequirementsVersion = applicationRequirementsVersion; + this.bundleSid = bundleSid; + this.businessInformation = businessInformation; + this.complianceKeywords = complianceKeywords; + this.contentExamples = contentExamples; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.notificationEmails = notificationEmails; + this.reviewer = reviewer; + this.setup = setup; + this.sid = sid; + this.smsCampaignDetails = smsCampaignDetails; + this.state = state; + this.updatedBy = updatedBy; + this.userSignUp = userSignUp; + this.zendeskTicketId = zendeskTicketId; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Application other = (Application) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + applicationRequirementsSid, + other.applicationRequirementsSid + ) && + Objects.equals( + applicationRequirementsVersion, + other.applicationRequirementsVersion + ) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(businessInformation, other.businessInformation) && + Objects.equals(complianceKeywords, other.complianceKeywords) && + Objects.equals(contentExamples, other.contentExamples) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(notificationEmails, other.notificationEmails) && + Objects.equals(reviewer, other.reviewer) && + Objects.equals(setup, other.setup) && + Objects.equals(sid, other.sid) && + Objects.equals(smsCampaignDetails, other.smsCampaignDetails) && + Objects.equals(state, other.state) && + Objects.equals(updatedBy, other.updatedBy) && + Objects.equals(userSignUp, other.userSignUp) && + Objects.equals(zendeskTicketId, other.zendeskTicketId) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + applicationRequirementsSid, + applicationRequirementsVersion, + bundleSid, + businessInformation, + complianceKeywords, + contentExamples, + createdBy, + dateCreated, + dateUpdated, + friendlyName, + isoCountry, + notificationEmails, + reviewer, + setup, + sid, + smsCampaignDetails, + state, + updatedBy, + userSignUp, + zendeskTicketId + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/ApplicationCreator.java b/src/main/java/com/twilio/rest/numbers/v2/ApplicationCreator.java new file mode 100644 index 0000000000..8507045f44 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/ApplicationCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ApplicationCreator extends Creator { + + private Application.CreateShortCodeApplicationRequest createShortCodeApplicationRequest; + + public ApplicationCreator( + final Application.CreateShortCodeApplicationRequest createShortCodeApplicationRequest + ) { + this.createShortCodeApplicationRequest = + createShortCodeApplicationRequest; + } + + public ApplicationCreator setCreateShortCodeApplicationRequest( + final Application.CreateShortCodeApplicationRequest createShortCodeApplicationRequest + ) { + this.createShortCodeApplicationRequest = + createShortCodeApplicationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ShortCodes/Applications"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Application creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Application create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Application content = Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (createShortCodeApplicationRequest != null) { + request.setBody( + Application.toJson( + createShortCodeApplicationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/ApplicationFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/ApplicationFetcher.java new file mode 100644 index 0000000000..66bbeeabee --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/ApplicationFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ApplicationFetcher extends Fetcher { + + private String pathSid; + + public ApplicationFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/ShortCodes/Applications/{sid}"; + + path = path.replace("{" + "sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Application fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Application fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Application content = Application.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/ApplicationReader.java b/src/main/java/com/twilio/rest/numbers/v2/ApplicationReader.java new file mode 100644 index 0000000000..886a98a9b0 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/ApplicationReader.java @@ -0,0 +1,267 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ApplicationReader extends Reader { + + private String accountSid; + private String isoCountry; + private String status; + private String friendlyName; + private String sid; + private Integer pageSize; + + public ApplicationReader() {} + + public ApplicationReader setAccountSid(final String accountSid) { + this.accountSid = accountSid; + return this; + } + + public ApplicationReader setIsoCountry(final String isoCountry) { + this.isoCountry = isoCountry; + return this; + } + + public ApplicationReader setStatus(final String status) { + this.status = status; + return this; + } + + public ApplicationReader setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ApplicationReader setSid(final String sid) { + this.sid = sid; + return this; + } + + public ApplicationReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Application.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/ShortCodes/Applications"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Application.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Application read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + Application.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (accountSid != null) { + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.QUERY + ); + } + + if (isoCountry != null) { + Serializer.toString( + request, + "IsoCountry", + isoCountry, + ParameterType.QUERY + ); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (sid != null) { + Serializer.toString(request, "Sid", sid, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocument.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocument.java new file mode 100644 index 0000000000..b3ee7c9ee1 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocument.java @@ -0,0 +1,252 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AuthorizationDocument extends Resource { + + public static AuthorizationDocumentCreator creator( + final String addressSid, + final String email, + final com.twilio.type.PhoneNumber contactPhoneNumber, + final List hostedNumberOrderSids + ) { + return new AuthorizationDocumentCreator( + addressSid, + email, + contactPhoneNumber, + hostedNumberOrderSids + ); + } + + public static AuthorizationDocumentDeleter deleter(final String pathSid) { + return new AuthorizationDocumentDeleter(pathSid); + } + + public static AuthorizationDocumentFetcher fetcher(final String pathSid) { + return new AuthorizationDocumentFetcher(pathSid); + } + + public static AuthorizationDocumentReader reader() { + return new AuthorizationDocumentReader(); + } + + public enum Status { + OPENED("opened"), + SIGNING("signing"), + SIGNED("signed"), + CANCELED("canceled"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a AuthorizationDocument object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AuthorizationDocument object represented by the provided JSON + */ + public static AuthorizationDocument fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AuthorizationDocument.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AuthorizationDocument object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AuthorizationDocument object represented by the provided JSON + */ + public static AuthorizationDocument fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AuthorizationDocument.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String addressSid; + + @Getter + private final List ccEmails; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final AuthorizationDocument.Status status; + + @Getter + private final URI url; + + @JsonCreator + private AuthorizationDocument( + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final AuthorizationDocument.Status status, + @JsonProperty("url") final URI url + ) { + this.addressSid = addressSid; + this.ccEmails = ccEmails; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.links = links; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AuthorizationDocument other = (AuthorizationDocument) o; + return ( + Objects.equals(addressSid, other.addressSid) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + addressSid, + ccEmails, + dateCreated, + dateUpdated, + email, + links, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentCreator.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentCreator.java new file mode 100644 index 0000000000..a29265b270 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentCreator.java @@ -0,0 +1,233 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class AuthorizationDocumentCreator + extends Creator { + + private String addressSid; + private String email; + private com.twilio.type.PhoneNumber contactPhoneNumber; + private List hostedNumberOrderSids; + private String contactTitle; + private List ccEmails; + + public AuthorizationDocumentCreator( + final String addressSid, + final String email, + final com.twilio.type.PhoneNumber contactPhoneNumber, + final List hostedNumberOrderSids + ) { + this.addressSid = addressSid; + this.email = email; + this.contactPhoneNumber = contactPhoneNumber; + this.hostedNumberOrderSids = hostedNumberOrderSids; + } + + public AuthorizationDocumentCreator setAddressSid(final String addressSid) { + this.addressSid = addressSid; + return this; + } + + public AuthorizationDocumentCreator setEmail(final String email) { + this.email = email; + return this; + } + + public AuthorizationDocumentCreator setContactPhoneNumber( + final com.twilio.type.PhoneNumber contactPhoneNumber + ) { + this.contactPhoneNumber = contactPhoneNumber; + return this; + } + + public AuthorizationDocumentCreator setContactPhoneNumber( + final String contactPhoneNumber + ) { + return setContactPhoneNumber( + Promoter.phoneNumberFromString(contactPhoneNumber) + ); + } + + public AuthorizationDocumentCreator setHostedNumberOrderSids( + final List hostedNumberOrderSids + ) { + this.hostedNumberOrderSids = hostedNumberOrderSids; + return this; + } + + public AuthorizationDocumentCreator setHostedNumberOrderSids( + final String hostedNumberOrderSids + ) { + return setHostedNumberOrderSids( + Promoter.listOfOne(hostedNumberOrderSids) + ); + } + + public AuthorizationDocumentCreator setContactTitle( + final String contactTitle + ) { + this.contactTitle = contactTitle; + return this; + } + + public AuthorizationDocumentCreator setCcEmails( + final List ccEmails + ) { + this.ccEmails = ccEmails; + return this; + } + + public AuthorizationDocumentCreator setCcEmails(final String ccEmails) { + return setCcEmails(Promoter.listOfOne(ccEmails)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/AuthorizationDocuments"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthorizationDocument creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthorizationDocument create(final TwilioRestClient client) { + Response response = makeRequest(client); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthorizationDocument content = AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (addressSid != null) { + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + + if (contactPhoneNumber != null) { + Serializer.toString( + request, + "ContactPhoneNumber", + contactPhoneNumber, + ParameterType.URLENCODED + ); + } + + if (hostedNumberOrderSids != null) { + for (String param : hostedNumberOrderSids) { + Serializer.toString( + request, + "HostedNumberOrderSids", + param, + ParameterType.URLENCODED + ); + } + } + + if (contactTitle != null) { + Serializer.toString( + request, + "ContactTitle", + contactTitle, + ParameterType.URLENCODED + ); + } + + if (ccEmails != null) { + for (String param : ccEmails) { + Serializer.toString( + request, + "CcEmails", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentDeleter.java new file mode 100644 index 0000000000..e9f217067e --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentDeleter.java @@ -0,0 +1,98 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class AuthorizationDocumentDeleter + extends Deleter { + + private String pathSid; + + public AuthorizationDocumentDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/AuthorizationDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthorizationDocument delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentFetcher.java new file mode 100644 index 0000000000..34e5e5a0c8 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthorizationDocumentFetcher + extends Fetcher { + + private String pathSid; + + public AuthorizationDocumentFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/AuthorizationDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthorizationDocument fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AuthorizationDocument fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthorizationDocument content = AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentReader.java b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentReader.java new file mode 100644 index 0000000000..1c2eba90d7 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/AuthorizationDocumentReader.java @@ -0,0 +1,228 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthorizationDocumentReader extends Reader { + + private String email; + private AuthorizationDocument.Status status; + private Long pageSize; + + public AuthorizationDocumentReader() {} + + public AuthorizationDocumentReader setEmail(final String email) { + this.email = email; + return this; + } + + public AuthorizationDocumentReader setStatus( + final AuthorizationDocument.Status status + ) { + this.status = status; + return this; + } + + public AuthorizationDocumentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + AuthorizationDocument.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/AuthorizationDocuments"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + AuthorizationDocument.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AuthorizationDocument read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "items", + response.getContent(), + AuthorizationDocument.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (email != null) { + Serializer.toString(request, "Email", email, ParameterType.QUERY); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrder.java b/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrder.java new file mode 100644 index 0000000000..524bb1deaa --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrder.java @@ -0,0 +1,235 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BulkHostedNumberOrder extends Resource { + + public static BulkHostedNumberOrderCreator creator() { + return new BulkHostedNumberOrderCreator(); + } + + public static BulkHostedNumberOrderFetcher fetcher( + final String pathBulkHostingSid + ) { + return new BulkHostedNumberOrderFetcher(pathBulkHostingSid); + } + + public enum RequestStatus { + QUEUED("QUEUED"), + IN_PROGRESS("IN_PROGRESS"), + PROCESSED("PROCESSED"); + + private final String value; + + private RequestStatus(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RequestStatus forValue(final String value) { + return Promoter.enumFromString(value, RequestStatus.values()); + } + } + + /** + * Converts a JSON String into a BulkHostedNumberOrder object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BulkHostedNumberOrder object represented by the provided JSON + */ + public static BulkHostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkHostedNumberOrder.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BulkHostedNumberOrder object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BulkHostedNumberOrder object represented by the provided JSON + */ + public static BulkHostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BulkHostedNumberOrder.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String bulkHostingSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCompleted; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String friendlyName; + + @Getter + private final String notificationEmail; + + @Getter + private final BulkHostedNumberOrder.RequestStatus requestStatus; + + @Getter + private final List results; + + @Getter + private final Integer totalCount; + + @Getter + private final URI url; + + @JsonCreator + private BulkHostedNumberOrder( + @JsonProperty("bulk_hosting_sid") final String bulkHostingSid, + @JsonProperty("date_completed") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCompleted, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("notification_email") final String notificationEmail, + @JsonProperty( + "request_status" + ) final BulkHostedNumberOrder.RequestStatus requestStatus, + @JsonProperty("results") final List results, + @JsonProperty("total_count") final Integer totalCount, + @JsonProperty("url") final URI url + ) { + this.bulkHostingSid = bulkHostingSid; + this.dateCompleted = dateCompleted; + this.dateCreated = dateCreated; + this.friendlyName = friendlyName; + this.notificationEmail = notificationEmail; + this.requestStatus = requestStatus; + this.results = results; + this.totalCount = totalCount; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BulkHostedNumberOrder other = (BulkHostedNumberOrder) o; + return ( + Objects.equals(bulkHostingSid, other.bulkHostingSid) && + Objects.equals(dateCompleted, other.dateCompleted) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(notificationEmail, other.notificationEmail) && + Objects.equals(requestStatus, other.requestStatus) && + Objects.equals(results, other.results) && + Objects.equals(totalCount, other.totalCount) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + bulkHostingSid, + dateCompleted, + dateCreated, + friendlyName, + notificationEmail, + requestStatus, + results, + totalCount, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrderCreator.java b/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrderCreator.java new file mode 100644 index 0000000000..0fa375aac8 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrderCreator.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BulkHostedNumberOrderCreator + extends Creator { + + private Object body; + + public BulkHostedNumberOrderCreator() {} + + public BulkHostedNumberOrderCreator setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/Orders/Bulk"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BulkHostedNumberOrder creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BulkHostedNumberOrder create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BulkHostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BulkHostedNumberOrder content = BulkHostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody(BulkHostedNumberOrder.toJson(body, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrderFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrderFetcher.java new file mode 100644 index 0000000000..7a7cfe4ab2 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/BulkHostedNumberOrderFetcher.java @@ -0,0 +1,123 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BulkHostedNumberOrderFetcher + extends Fetcher { + + private String pathBulkHostingSid; + private String orderStatus; + + public BulkHostedNumberOrderFetcher(final String pathBulkHostingSid) { + this.pathBulkHostingSid = pathBulkHostingSid; + } + + public BulkHostedNumberOrderFetcher setOrderStatus( + final String orderStatus + ) { + this.orderStatus = orderStatus; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/Orders/Bulk/{BulkHostingSid}"; + + path = + path.replace( + "{" + "BulkHostingSid" + "}", + this.pathBulkHostingSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BulkHostedNumberOrder fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BulkHostedNumberOrder fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return BulkHostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BulkHostedNumberOrder content = BulkHostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (orderStatus != null) { + Serializer.toString( + request, + "OrderStatus", + orderStatus, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/BundleClone.java b/src/main/java/com/twilio/rest/numbers/v2/BundleClone.java new file mode 100644 index 0000000000..a84e0327b7 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/BundleClone.java @@ -0,0 +1,251 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BundleClone extends Resource { + + public static BundleCloneCreator creator( + final String pathBundleSid, + final String targetAccountSid + ) { + return new BundleCloneCreator(pathBundleSid, targetAccountSid); + } + + public enum Status { + DRAFT("draft"), + PENDING_REVIEW("pending-review"), + IN_REVIEW("in-review"), + TWILIO_REJECTED("twilio-rejected"), + TWILIO_APPROVED("twilio-approved"), + PROVISIONALLY_APPROVED("provisionally-approved"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a BundleClone object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BundleClone object represented by the provided JSON + */ + public static BundleClone fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BundleClone.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BundleClone object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BundleClone object represented by the provided JSON + */ + public static BundleClone fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BundleClone.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String bundleSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final String friendlyName; + + @Getter + private final String regulationSid; + + @Getter + private final BundleClone.Status status; + + @Getter + private final URI statusCallback; + + @Getter + private final URI url; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime validUntil; + + @JsonCreator + private BundleClone( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("status") final BundleClone.Status status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("url") final URI url, + @JsonProperty("valid_until") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime validUntil + ) { + this.accountSid = accountSid; + this.bundleSid = bundleSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.friendlyName = friendlyName; + this.regulationSid = regulationSid; + this.status = status; + this.statusCallback = statusCallback; + this.url = url; + this.validUntil = validUntil; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BundleClone other = (BundleClone) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(url, other.url) && + Objects.equals(validUntil, other.validUntil) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + bundleSid, + dateCreated, + dateUpdated, + email, + friendlyName, + regulationSid, + status, + statusCallback, + url, + validUntil + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/BundleCloneCreator.java b/src/main/java/com/twilio/rest/numbers/v2/BundleCloneCreator.java new file mode 100644 index 0000000000..2fe027ab6f --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/BundleCloneCreator.java @@ -0,0 +1,158 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BundleCloneCreator extends Creator { + + private String pathBundleSid; + private String targetAccountSid; + private Boolean moveToDraft; + private String friendlyName; + + public BundleCloneCreator( + final String pathBundleSid, + final String targetAccountSid + ) { + this.pathBundleSid = pathBundleSid; + this.targetAccountSid = targetAccountSid; + } + + public BundleCloneCreator setTargetAccountSid( + final String targetAccountSid + ) { + this.targetAccountSid = targetAccountSid; + return this; + } + + public BundleCloneCreator setMoveToDraft(final Boolean moveToDraft) { + this.moveToDraft = moveToDraft; + return this; + } + + public BundleCloneCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Clones"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BundleClone creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BundleClone create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BundleClone.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BundleClone content = BundleClone.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (targetAccountSid != null) { + Serializer.toString( + request, + "TargetAccountSid", + targetAccountSid, + ParameterType.URLENCODED + ); + } + + if (moveToDraft != null) { + Serializer.toString( + request, + "MoveToDraft", + moveToDraft, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrder.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrder.java new file mode 100644 index 0000000000..b7aa8ab24e --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrder.java @@ -0,0 +1,428 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import com.twilio.type.PhoneNumberCapabilities; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class HostedNumberOrder extends Resource { + + public static HostedNumberOrderCreator creator( + final com.twilio.type.PhoneNumber phoneNumber, + final com.twilio.type.PhoneNumber contactPhoneNumber, + final String addressSid, + final String email + ) { + return new HostedNumberOrderCreator( + phoneNumber, + contactPhoneNumber, + addressSid, + email + ); + } + + public static HostedNumberOrderDeleter deleter(final String pathSid) { + return new HostedNumberOrderDeleter(pathSid); + } + + public static HostedNumberOrderFetcher fetcher(final String pathSid) { + return new HostedNumberOrderFetcher(pathSid); + } + + public static HostedNumberOrderReader reader() { + return new HostedNumberOrderReader(); + } + + public static HostedNumberOrderUpdater updater( + final String pathSid, + final HostedNumberOrder.Status status + ) { + return new HostedNumberOrderUpdater(pathSid, status); + } + + public enum Status { + TWILIO_PROCESSING("twilio-processing"), + RECEIVED("received"), + PENDING_VERIFICATION("pending-verification"), + VERIFIED("verified"), + PENDING_LOA("pending-loa"), + CARRIER_PROCESSING("carrier-processing"), + TESTING("testing"), + COMPLETED("completed"), + FAILED("failed"), + ACTION_REQUIRED("action-required"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum VerificationType { + PHONE_CALL("phone-call"); + + private final String value; + + private VerificationType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static VerificationType forValue(final String value) { + return Promoter.enumFromString(value, VerificationType.values()); + } + } + + /** + * Converts a JSON String into a HostedNumberOrder object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return HostedNumberOrder object represented by the provided JSON + */ + public static HostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, HostedNumberOrder.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a HostedNumberOrder object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return HostedNumberOrder object represented by the provided JSON + */ + public static HostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, HostedNumberOrder.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String addressSid; + + @Getter + private final String bulkHostingRequestSid; + + @Getter + private final PhoneNumberCapabilities capabilities; + + @Getter + private final List ccEmails; + + @Getter + private final com.twilio.type.PhoneNumber contactPhoneNumber; + + @Getter + private final String contactTitle; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final String failureReason; + + @Getter + private final String friendlyName; + + @Getter + private final String incomingPhoneNumberSid; + + @Getter + private final String nextStep; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter + private final String sid; + + @Getter + private final String signingDocumentSid; + + @Getter + private final HostedNumberOrder.Status status; + + @Getter + private final URI url; + + @Getter + private final Integer verificationAttempts; + + @Getter + private final Integer verificationCallDelay; + + @Getter + private final String verificationCallExtension; + + @Getter + private final List verificationCallSids; + + @Getter + private final String verificationCode; + + @Getter + private final HostedNumberOrder.VerificationType verificationType; + + @JsonCreator + private HostedNumberOrder( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty( + "bulk_hosting_request_sid" + ) final String bulkHostingRequestSid, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty( + "contact_phone_number" + ) final com.twilio.type.PhoneNumber contactPhoneNumber, + @JsonProperty("contact_title") final String contactTitle, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "incoming_phone_number_sid" + ) final String incomingPhoneNumberSid, + @JsonProperty("next_step") final String nextStep, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("signing_document_sid") final String signingDocumentSid, + @JsonProperty("status") final HostedNumberOrder.Status status, + @JsonProperty("url") final URI url, + @JsonProperty( + "verification_attempts" + ) final Integer verificationAttempts, + @JsonProperty( + "verification_call_delay" + ) final Integer verificationCallDelay, + @JsonProperty( + "verification_call_extension" + ) final String verificationCallExtension, + @JsonProperty("verification_call_sids") final List< + String + > verificationCallSids, + @JsonProperty("verification_code") final String verificationCode, + @JsonProperty( + "verification_type" + ) final HostedNumberOrder.VerificationType verificationType + ) { + this.accountSid = accountSid; + this.addressSid = addressSid; + this.bulkHostingRequestSid = bulkHostingRequestSid; + this.capabilities = capabilities; + this.ccEmails = ccEmails; + this.contactPhoneNumber = contactPhoneNumber; + this.contactTitle = contactTitle; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.failureReason = failureReason; + this.friendlyName = friendlyName; + this.incomingPhoneNumberSid = incomingPhoneNumberSid; + this.nextStep = nextStep; + this.phoneNumber = phoneNumber; + this.sid = sid; + this.signingDocumentSid = signingDocumentSid; + this.status = status; + this.url = url; + this.verificationAttempts = verificationAttempts; + this.verificationCallDelay = verificationCallDelay; + this.verificationCallExtension = verificationCallExtension; + this.verificationCallSids = verificationCallSids; + this.verificationCode = verificationCode; + this.verificationType = verificationType; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + HostedNumberOrder other = (HostedNumberOrder) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals( + bulkHostingRequestSid, + other.bulkHostingRequestSid + ) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(contactPhoneNumber, other.contactPhoneNumber) && + Objects.equals(contactTitle, other.contactTitle) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + incomingPhoneNumberSid, + other.incomingPhoneNumberSid + ) && + Objects.equals(nextStep, other.nextStep) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(signingDocumentSid, other.signingDocumentSid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(verificationAttempts, other.verificationAttempts) && + Objects.equals( + verificationCallDelay, + other.verificationCallDelay + ) && + Objects.equals( + verificationCallExtension, + other.verificationCallExtension + ) && + Objects.equals(verificationCallSids, other.verificationCallSids) && + Objects.equals(verificationCode, other.verificationCode) && + Objects.equals(verificationType, other.verificationType) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + addressSid, + bulkHostingRequestSid, + capabilities, + ccEmails, + contactPhoneNumber, + contactTitle, + dateCreated, + dateUpdated, + email, + failureReason, + friendlyName, + incomingPhoneNumberSid, + nextStep, + phoneNumber, + sid, + signingDocumentSid, + status, + url, + verificationAttempts, + verificationCallDelay, + verificationCallExtension, + verificationCallSids, + verificationCode, + verificationType + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderCreator.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderCreator.java new file mode 100644 index 0000000000..1d59816763 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderCreator.java @@ -0,0 +1,401 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; +import java.util.List; + +public class HostedNumberOrderCreator extends Creator { + + private com.twilio.type.PhoneNumber phoneNumber; + private com.twilio.type.PhoneNumber contactPhoneNumber; + private String addressSid; + private String email; + private String accountSid; + private String friendlyName; + private List ccEmails; + private URI smsUrl; + private HttpMethod smsMethod; + private URI smsFallbackUrl; + private Boolean smsCapability; + private HttpMethod smsFallbackMethod; + private URI statusCallbackUrl; + private HttpMethod statusCallbackMethod; + private String smsApplicationSid; + private String contactTitle; + + public HostedNumberOrderCreator( + final com.twilio.type.PhoneNumber phoneNumber, + final com.twilio.type.PhoneNumber contactPhoneNumber, + final String addressSid, + final String email + ) { + this.phoneNumber = phoneNumber; + this.contactPhoneNumber = contactPhoneNumber; + this.addressSid = addressSid; + this.email = email; + } + + public HostedNumberOrderCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { + this.phoneNumber = phoneNumber; + return this; + } + + public HostedNumberOrderCreator setPhoneNumber(final String phoneNumber) { + return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); + } + + public HostedNumberOrderCreator setContactPhoneNumber( + final com.twilio.type.PhoneNumber contactPhoneNumber + ) { + this.contactPhoneNumber = contactPhoneNumber; + return this; + } + + public HostedNumberOrderCreator setContactPhoneNumber( + final String contactPhoneNumber + ) { + return setContactPhoneNumber( + Promoter.phoneNumberFromString(contactPhoneNumber) + ); + } + + public HostedNumberOrderCreator setAddressSid(final String addressSid) { + this.addressSid = addressSid; + return this; + } + + public HostedNumberOrderCreator setEmail(final String email) { + this.email = email; + return this; + } + + public HostedNumberOrderCreator setAccountSid(final String accountSid) { + this.accountSid = accountSid; + return this; + } + + public HostedNumberOrderCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public HostedNumberOrderCreator setCcEmails(final List ccEmails) { + this.ccEmails = ccEmails; + return this; + } + + public HostedNumberOrderCreator setCcEmails(final String ccEmails) { + return setCcEmails(Promoter.listOfOne(ccEmails)); + } + + public HostedNumberOrderCreator setSmsUrl(final URI smsUrl) { + this.smsUrl = smsUrl; + return this; + } + + public HostedNumberOrderCreator setSmsUrl(final String smsUrl) { + return setSmsUrl(Promoter.uriFromString(smsUrl)); + } + + public HostedNumberOrderCreator setSmsMethod(final HttpMethod smsMethod) { + this.smsMethod = smsMethod; + return this; + } + + public HostedNumberOrderCreator setSmsFallbackUrl( + final URI smsFallbackUrl + ) { + this.smsFallbackUrl = smsFallbackUrl; + return this; + } + + public HostedNumberOrderCreator setSmsFallbackUrl( + final String smsFallbackUrl + ) { + return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); + } + + public HostedNumberOrderCreator setSmsCapability( + final Boolean smsCapability + ) { + this.smsCapability = smsCapability; + return this; + } + + public HostedNumberOrderCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { + this.smsFallbackMethod = smsFallbackMethod; + return this; + } + + public HostedNumberOrderCreator setStatusCallbackUrl( + final URI statusCallbackUrl + ) { + this.statusCallbackUrl = statusCallbackUrl; + return this; + } + + public HostedNumberOrderCreator setStatusCallbackUrl( + final String statusCallbackUrl + ) { + return setStatusCallbackUrl(Promoter.uriFromString(statusCallbackUrl)); + } + + public HostedNumberOrderCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { + this.statusCallbackMethod = statusCallbackMethod; + return this; + } + + public HostedNumberOrderCreator setSmsApplicationSid( + final String smsApplicationSid + ) { + this.smsApplicationSid = smsApplicationSid; + return this; + } + + public HostedNumberOrderCreator setContactTitle(final String contactTitle) { + this.contactTitle = contactTitle; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/Orders"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "HostedNumberOrder creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public HostedNumberOrder create(final TwilioRestClient client) { + Response response = makeRequest(client); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + HostedNumberOrder content = HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (phoneNumber != null) { + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); + } + + if (contactPhoneNumber != null) { + Serializer.toString( + request, + "ContactPhoneNumber", + contactPhoneNumber, + ParameterType.URLENCODED + ); + } + + if (addressSid != null) { + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + + if (accountSid != null) { + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (ccEmails != null) { + for (String param : ccEmails) { + Serializer.toString( + request, + "CcEmails", + param, + ParameterType.URLENCODED + ); + } + } + + if (smsUrl != null) { + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); + } + + if (smsMethod != null) { + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); + } + + if (smsFallbackUrl != null) { + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); + } + + if (smsCapability != null) { + Serializer.toString( + request, + "SmsCapability", + smsCapability, + ParameterType.URLENCODED + ); + } + + if (smsFallbackMethod != null) { + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); + } + + if (statusCallbackUrl != null) { + Serializer.toString( + request, + "StatusCallbackUrl", + statusCallbackUrl, + ParameterType.URLENCODED + ); + } + + if (statusCallbackMethod != null) { + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); + } + + if (smsApplicationSid != null) { + Serializer.toString( + request, + "SmsApplicationSid", + smsApplicationSid, + ParameterType.URLENCODED + ); + } + + if (contactTitle != null) { + Serializer.toString( + request, + "ContactTitle", + contactTitle, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderDeleter.java new file mode 100644 index 0000000000..4a711fd433 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class HostedNumberOrderDeleter extends Deleter { + + private String pathSid; + + public HostedNumberOrderDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/Orders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "HostedNumberOrder delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderFetcher.java new file mode 100644 index 0000000000..f5b2ee53e9 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class HostedNumberOrderFetcher extends Fetcher { + + private String pathSid; + + public HostedNumberOrderFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/Orders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "HostedNumberOrder fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public HostedNumberOrder fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + HostedNumberOrder content = HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderReader.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderReader.java new file mode 100644 index 0000000000..30db91d446 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderReader.java @@ -0,0 +1,285 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class HostedNumberOrderReader extends Reader { + + private HostedNumberOrder.Status status; + private Boolean smsCapability; + private com.twilio.type.PhoneNumber phoneNumber; + private String incomingPhoneNumberSid; + private String friendlyName; + private Long pageSize; + + public HostedNumberOrderReader() {} + + public HostedNumberOrderReader setStatus( + final HostedNumberOrder.Status status + ) { + this.status = status; + return this; + } + + public HostedNumberOrderReader setSmsCapability( + final Boolean smsCapability + ) { + this.smsCapability = smsCapability; + return this; + } + + public HostedNumberOrderReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { + this.phoneNumber = phoneNumber; + return this; + } + + public HostedNumberOrderReader setPhoneNumber(final String phoneNumber) { + return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); + } + + public HostedNumberOrderReader setIncomingPhoneNumberSid( + final String incomingPhoneNumberSid + ) { + this.incomingPhoneNumberSid = incomingPhoneNumberSid; + return this; + } + + public HostedNumberOrderReader setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public HostedNumberOrderReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + HostedNumberOrder.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/Orders"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + HostedNumberOrder.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "HostedNumberOrder read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "items", + response.getContent(), + HostedNumberOrder.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (smsCapability != null) { + Serializer.toString( + request, + "SmsCapability", + smsCapability, + ParameterType.QUERY + ); + } + + if (phoneNumber != null) { + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); + } + + if (incomingPhoneNumberSid != null) { + Serializer.toString( + request, + "IncomingPhoneNumberSid", + incomingPhoneNumberSid, + ParameterType.QUERY + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderUpdater.java b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderUpdater.java new file mode 100644 index 0000000000..71c9bfe984 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/HostedNumberOrderUpdater.java @@ -0,0 +1,158 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class HostedNumberOrderUpdater extends Updater { + + private String pathSid; + private HostedNumberOrder.Status status; + private Integer verificationCallDelay; + private String verificationCallExtension; + + public HostedNumberOrderUpdater( + final String pathSid, + final HostedNumberOrder.Status status + ) { + this.pathSid = pathSid; + this.status = status; + } + + public HostedNumberOrderUpdater setStatus( + final HostedNumberOrder.Status status + ) { + this.status = status; + return this; + } + + public HostedNumberOrderUpdater setVerificationCallDelay( + final Integer verificationCallDelay + ) { + this.verificationCallDelay = verificationCallDelay; + return this; + } + + public HostedNumberOrderUpdater setVerificationCallExtension( + final String verificationCallExtension + ) { + this.verificationCallExtension = verificationCallExtension; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/HostedNumber/Orders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "HostedNumberOrder update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public HostedNumberOrder update(final TwilioRestClient client) { + Response response = makeRequest(client); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + HostedNumberOrder content = HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (verificationCallDelay != null) { + Serializer.toString( + request, + "VerificationCallDelay", + verificationCallDelay, + ParameterType.URLENCODED + ); + } + + if (verificationCallExtension != null) { + Serializer.toString( + request, + "VerificationCallExtension", + verificationCallExtension, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrder.java b/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrder.java new file mode 100644 index 0000000000..2f3cc72f2d --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrder.java @@ -0,0 +1,318 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.authorizationdocument; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import com.twilio.type.PhoneNumberCapabilities; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class DependentHostedNumberOrder extends Resource { + + public static DependentHostedNumberOrderReader reader( + final String pathSigningDocumentSid + ) { + return new DependentHostedNumberOrderReader(pathSigningDocumentSid); + } + + public enum Status { + RECEIVED("received"), + VERIFIED("verified"), + PENDING_LOA("pending-loa"), + CARRIER_PROCESSING("carrier-processing"), + COMPLETED("completed"), + FAILED("failed"), + ACTION_REQUIRED("action-required"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a DependentHostedNumberOrder object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return DependentHostedNumberOrder object represented by the provided JSON + */ + public static DependentHostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DependentHostedNumberOrder.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a DependentHostedNumberOrder object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return DependentHostedNumberOrder object represented by the provided JSON + */ + public static DependentHostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DependentHostedNumberOrder.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String addressSid; + + @Getter + private final String bulkHostingRequestSid; + + @Getter + private final PhoneNumberCapabilities capabilities; + + @Getter + private final List ccEmails; + + @Getter + private final com.twilio.type.PhoneNumber contactPhoneNumber; + + @Getter + private final String contactTitle; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final String failureReason; + + @Getter + private final String friendlyName; + + @Getter + private final String incomingPhoneNumberSid; + + @Getter + private final String nextStep; + + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter + private final String sid; + + @Getter + private final String signingDocumentSid; + + @Getter + private final DependentHostedNumberOrder.Status status; + + @JsonCreator + private DependentHostedNumberOrder( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty( + "bulk_hosting_request_sid" + ) final String bulkHostingRequestSid, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty( + "contact_phone_number" + ) final com.twilio.type.PhoneNumber contactPhoneNumber, + @JsonProperty("contact_title") final String contactTitle, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "incoming_phone_number_sid" + ) final String incomingPhoneNumberSid, + @JsonProperty("next_step") final String nextStep, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("signing_document_sid") final String signingDocumentSid, + @JsonProperty("status") final DependentHostedNumberOrder.Status status + ) { + this.accountSid = accountSid; + this.addressSid = addressSid; + this.bulkHostingRequestSid = bulkHostingRequestSid; + this.capabilities = capabilities; + this.ccEmails = ccEmails; + this.contactPhoneNumber = contactPhoneNumber; + this.contactTitle = contactTitle; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.failureReason = failureReason; + this.friendlyName = friendlyName; + this.incomingPhoneNumberSid = incomingPhoneNumberSid; + this.nextStep = nextStep; + this.phoneNumber = phoneNumber; + this.sid = sid; + this.signingDocumentSid = signingDocumentSid; + this.status = status; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + DependentHostedNumberOrder other = (DependentHostedNumberOrder) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals( + bulkHostingRequestSid, + other.bulkHostingRequestSid + ) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(contactPhoneNumber, other.contactPhoneNumber) && + Objects.equals(contactTitle, other.contactTitle) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + incomingPhoneNumberSid, + other.incomingPhoneNumberSid + ) && + Objects.equals(nextStep, other.nextStep) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(signingDocumentSid, other.signingDocumentSid) && + Objects.equals(status, other.status) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + addressSid, + bulkHostingRequestSid, + capabilities, + ccEmails, + contactPhoneNumber, + contactTitle, + dateCreated, + dateUpdated, + email, + failureReason, + friendlyName, + incomingPhoneNumberSid, + nextStep, + phoneNumber, + sid, + signingDocumentSid, + status + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrderReader.java b/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrderReader.java new file mode 100644 index 0000000000..61898ef7af --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/authorizationdocument/DependentHostedNumberOrderReader.java @@ -0,0 +1,289 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.authorizationdocument; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DependentHostedNumberOrderReader + extends Reader { + + private String pathSigningDocumentSid; + private DependentHostedNumberOrder.Status status; + private com.twilio.type.PhoneNumber phoneNumber; + private String incomingPhoneNumberSid; + private String friendlyName; + private Long pageSize; + + public DependentHostedNumberOrderReader( + final String pathSigningDocumentSid + ) { + this.pathSigningDocumentSid = pathSigningDocumentSid; + } + + public DependentHostedNumberOrderReader setStatus( + final DependentHostedNumberOrder.Status status + ) { + this.status = status; + return this; + } + + public DependentHostedNumberOrderReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { + this.phoneNumber = phoneNumber; + return this; + } + + public DependentHostedNumberOrderReader setPhoneNumber( + final String phoneNumber + ) { + return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); + } + + public DependentHostedNumberOrderReader setIncomingPhoneNumberSid( + final String incomingPhoneNumberSid + ) { + this.incomingPhoneNumberSid = incomingPhoneNumberSid; + return this; + } + + public DependentHostedNumberOrderReader setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public DependentHostedNumberOrderReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + DependentHostedNumberOrder.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v2/HostedNumber/AuthorizationDocuments/{SigningDocumentSid}/DependentHostedNumberOrders"; + + path = + path.replace( + "{" + "SigningDocumentSid" + "}", + this.pathSigningDocumentSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + DependentHostedNumberOrder.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "DependentHostedNumberOrder read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "items", + response.getContent(), + DependentHostedNumberOrder.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (phoneNumber != null) { + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); + } + + if (incomingPhoneNumberSid != null) { + Serializer.toString( + request, + "IncomingPhoneNumberSid", + incomingPhoneNumberSid, + ParameterType.QUERY + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Bundle.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Bundle.java new file mode 100644 index 0000000000..c5625ceffa --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Bundle.java @@ -0,0 +1,338 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Bundle extends Resource { + + public static BundleCreator creator( + final String friendlyName, + final String email + ) { + return new BundleCreator(friendlyName, email); + } + + public static BundleDeleter deleter(final String pathSid) { + return new BundleDeleter(pathSid); + } + + public static BundleFetcher fetcher(final String pathSid) { + return new BundleFetcher(pathSid); + } + + public static BundleReader reader() { + return new BundleReader(); + } + + public static BundleUpdater updater(final String pathSid) { + return new BundleUpdater(pathSid); + } + + public enum Status { + DRAFT("draft"), + PENDING_REVIEW("pending-review"), + IN_REVIEW("in-review"), + TWILIO_REJECTED("twilio-rejected"), + TWILIO_APPROVED("twilio-approved"), + PROVISIONALLY_APPROVED("provisionally-approved"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum SortDirection { + ASC("ASC"), + DESC("DESC"); + + private final String value; + + private SortDirection(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static SortDirection forValue(final String value) { + return Promoter.enumFromString(value, SortDirection.values()); + } + } + + public enum EndUserType { + INDIVIDUAL("individual"), + BUSINESS("business"); + + private final String value; + + private EndUserType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EndUserType forValue(final String value) { + return Promoter.enumFromString(value, EndUserType.values()); + } + } + + public enum SortBy { + VALID_UNTIL("valid-until"), + DATE_UPDATED("date-updated"); + + private final String value; + + private SortBy(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static SortBy forValue(final String value) { + return Promoter.enumFromString(value, SortBy.values()); + } + } + + /** + * Converts a JSON String into a Bundle object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Bundle object represented by the provided JSON + */ + public static Bundle fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Bundle.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Bundle object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Bundle object represented by the provided JSON + */ + public static Bundle fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Bundle.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String regulationSid; + + @Getter + private final String sid; + + @Getter + private final Bundle.Status status; + + @Getter + private final URI statusCallback; + + @Getter + private final URI url; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime validUntil; + + @JsonCreator + private Bundle( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Bundle.Status status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("url") final URI url, + @JsonProperty("valid_until") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime validUntil + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.friendlyName = friendlyName; + this.links = links; + this.regulationSid = regulationSid; + this.sid = sid; + this.status = status; + this.statusCallback = statusCallback; + this.url = url; + this.validUntil = validUntil; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Bundle other = (Bundle) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(url, other.url) && + Objects.equals(validUntil, other.validUntil) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + email, + friendlyName, + links, + regulationSid, + sid, + status, + statusCallback, + url, + validUntil + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleCreator.java new file mode 100644 index 0000000000..2667610d71 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleCreator.java @@ -0,0 +1,224 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class BundleCreator extends Creator { + + private String friendlyName; + private String email; + private URI statusCallback; + private String regulationSid; + private String isoCountry; + private Bundle.EndUserType endUserType; + private String numberType; + private Boolean isTest; + + public BundleCreator(final String friendlyName, final String email) { + this.friendlyName = friendlyName; + this.email = email; + } + + public BundleCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public BundleCreator setEmail(final String email) { + this.email = email; + return this; + } + + public BundleCreator setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public BundleCreator setStatusCallback(final String statusCallback) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + public BundleCreator setRegulationSid(final String regulationSid) { + this.regulationSid = regulationSid; + return this; + } + + public BundleCreator setIsoCountry(final String isoCountry) { + this.isoCountry = isoCountry; + return this; + } + + public BundleCreator setEndUserType(final Bundle.EndUserType endUserType) { + this.endUserType = endUserType; + return this; + } + + public BundleCreator setNumberType(final String numberType) { + this.numberType = numberType; + return this; + } + + public BundleCreator setIsTest(final Boolean isTest) { + this.isTest = isTest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Bundles"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Bundle creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Bundle create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Bundle.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Bundle content = Bundle.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + + if (regulationSid != null) { + Serializer.toString( + request, + "RegulationSid", + regulationSid, + ParameterType.URLENCODED + ); + } + + if (isoCountry != null) { + Serializer.toString( + request, + "IsoCountry", + isoCountry, + ParameterType.URLENCODED + ); + } + + if (endUserType != null) { + Serializer.toString( + request, + "EndUserType", + endUserType, + ParameterType.URLENCODED + ); + } + + if (numberType != null) { + Serializer.toString( + request, + "NumberType", + numberType, + ParameterType.URLENCODED + ); + } + + if (isTest != null) { + Serializer.toString( + request, + "IsTest", + isTest, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleDeleter.java new file mode 100644 index 0000000000..c8b15e74a2 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class BundleDeleter extends Deleter { + + private String pathSid; + + public BundleDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Bundles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Bundle delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleFetcher.java new file mode 100644 index 0000000000..cec0234e76 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BundleFetcher extends Fetcher { + + private String pathSid; + + public BundleFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Bundles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Bundle fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Bundle fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Bundle.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Bundle content = Bundle.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleReader.java new file mode 100644 index 0000000000..633ecb84be --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleReader.java @@ -0,0 +1,371 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class BundleReader extends Reader { + + private Bundle.Status status; + private String bundleSids; + private String friendlyName; + private String regulationSid; + private String isoCountry; + private String numberType; + private Bundle.EndUserType endUserType; + private Boolean hasValidUntilDate; + private Bundle.SortBy sortBy; + private Bundle.SortDirection sortDirection; + private ZonedDateTime validUntilDate; + private ZonedDateTime validUntilDateBefore; + private ZonedDateTime validUntilDateAfter; + private Long pageSize; + + public BundleReader() {} + + public BundleReader setStatus(final Bundle.Status status) { + this.status = status; + return this; + } + + public BundleReader setBundleSids(final String bundleSids) { + this.bundleSids = bundleSids; + return this; + } + + public BundleReader setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public BundleReader setRegulationSid(final String regulationSid) { + this.regulationSid = regulationSid; + return this; + } + + public BundleReader setIsoCountry(final String isoCountry) { + this.isoCountry = isoCountry; + return this; + } + + public BundleReader setNumberType(final String numberType) { + this.numberType = numberType; + return this; + } + + public BundleReader setEndUserType(final Bundle.EndUserType endUserType) { + this.endUserType = endUserType; + return this; + } + + public BundleReader setHasValidUntilDate(final Boolean hasValidUntilDate) { + this.hasValidUntilDate = hasValidUntilDate; + return this; + } + + public BundleReader setSortBy(final Bundle.SortBy sortBy) { + this.sortBy = sortBy; + return this; + } + + public BundleReader setSortDirection( + final Bundle.SortDirection sortDirection + ) { + this.sortDirection = sortDirection; + return this; + } + + public BundleReader setValidUntilDate(final ZonedDateTime validUntilDate) { + this.validUntilDate = validUntilDate; + return this; + } + + public BundleReader setValidUntilDateBefore( + final ZonedDateTime validUntilDateBefore + ) { + this.validUntilDateBefore = validUntilDateBefore; + return this; + } + + public BundleReader setValidUntilDateAfter( + final ZonedDateTime validUntilDateAfter + ) { + this.validUntilDateAfter = validUntilDateAfter; + return this; + } + + public BundleReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Bundle.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Bundles"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Bundle.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Bundle read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + Bundle.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (bundleSids != null) { + Serializer.toString( + request, + "BundleSids", + bundleSids, + ParameterType.QUERY + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (regulationSid != null) { + Serializer.toString( + request, + "RegulationSid", + regulationSid, + ParameterType.QUERY + ); + } + + if (isoCountry != null) { + Serializer.toString( + request, + "IsoCountry", + isoCountry, + ParameterType.QUERY + ); + } + + if (numberType != null) { + Serializer.toString( + request, + "NumberType", + numberType, + ParameterType.QUERY + ); + } + + if (endUserType != null) { + Serializer.toString( + request, + "EndUserType", + endUserType, + ParameterType.QUERY + ); + } + + if (hasValidUntilDate != null) { + Serializer.toString( + request, + "HasValidUntilDate", + hasValidUntilDate, + ParameterType.QUERY + ); + } + + if (sortBy != null) { + Serializer.toString(request, "SortBy", sortBy, ParameterType.QUERY); + } + + if (sortDirection != null) { + Serializer.toString( + request, + "SortDirection", + sortDirection, + ParameterType.QUERY + ); + } + + Serializer.toString( + request, + "ValidUntilDate", + validUntilDate, + validUntilDateBefore, + validUntilDateAfter + ); + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleUpdater.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleUpdater.java new file mode 100644 index 0000000000..a8abeb3505 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/BundleUpdater.java @@ -0,0 +1,166 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class BundleUpdater extends Updater { + + private String pathSid; + private Bundle.Status status; + private URI statusCallback; + private String friendlyName; + private String email; + + public BundleUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public BundleUpdater setStatus(final Bundle.Status status) { + this.status = status; + return this; + } + + public BundleUpdater setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public BundleUpdater setStatusCallback(final String statusCallback) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + public BundleUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public BundleUpdater setEmail(final String email) { + this.email = email; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Bundles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Bundle update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Bundle update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Bundle.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Bundle content = Bundle.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUser.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUser.java new file mode 100644 index 0000000000..5bf3d5a518 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUser.java @@ -0,0 +1,237 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EndUser extends Resource { + + public static EndUserCreator creator( + final String friendlyName, + final EndUser.Type type + ) { + return new EndUserCreator(friendlyName, type); + } + + public static EndUserDeleter deleter(final String pathSid) { + return new EndUserDeleter(pathSid); + } + + public static EndUserFetcher fetcher(final String pathSid) { + return new EndUserFetcher(pathSid); + } + + public static EndUserReader reader() { + return new EndUserReader(); + } + + public static EndUserUpdater updater(final String pathSid) { + return new EndUserUpdater(pathSid); + } + + public enum Type { + INDIVIDUAL("individual"), + BUSINESS("business"); + + private final String value; + + private Type(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Type forValue(final String value) { + return Promoter.enumFromString(value, Type.values()); + } + } + + /** + * Converts a JSON String into a EndUser object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EndUser object represented by the provided JSON + */ + public static EndUser fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EndUser.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EndUser object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EndUser object represented by the provided JSON + */ + public static EndUser fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EndUser.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object attributes; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @Getter + private final EndUser.Type type; + + @Getter + private final URI url; + + @JsonCreator + private EndUser( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final Object attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final EndUser.Type type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EndUser other = (EndUser) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + dateCreated, + dateUpdated, + friendlyName, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserCreator.java new file mode 100644 index 0000000000..e68cdac50a --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserCreator.java @@ -0,0 +1,143 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserCreator extends Creator { + + private String friendlyName; + private EndUser.Type type; + private Object attributes; + + public EndUserCreator(final String friendlyName, final EndUser.Type type) { + this.friendlyName = friendlyName; + this.type = type; + } + + public EndUserCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public EndUserCreator setType(final EndUser.Type type) { + this.type = type; + return this; + } + + public EndUserCreator setAttributes(final Object attributes) { + this.attributes = attributes; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/EndUsers"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUser creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EndUser create(final TwilioRestClient client) { + Response response = makeRequest(client); + return EndUser.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EndUser content = EndUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserDeleter.java new file mode 100644 index 0000000000..fc6a347271 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class EndUserDeleter extends Deleter { + + private String pathSid; + + public EndUserDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/EndUsers/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUser delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserFetcher.java new file mode 100644 index 0000000000..a10461647d --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserFetcher extends Fetcher { + + private String pathSid; + + public EndUserFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/EndUsers/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUser fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EndUser fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EndUser.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EndUser content = EndUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserReader.java new file mode 100644 index 0000000000..bb6391df32 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserReader extends Reader { + + private Long pageSize; + + public EndUserReader() {} + + public EndUserReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + EndUser.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/EndUsers"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + EndUser.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "EndUser read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + EndUser.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserType.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserType.java new file mode 100644 index 0000000000..7deae5e4f8 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserType.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EndUserType extends Resource { + + public static EndUserTypeFetcher fetcher(final String pathSid) { + return new EndUserTypeFetcher(pathSid); + } + + public static EndUserTypeReader reader() { + return new EndUserTypeReader(); + } + + /** + * Converts a JSON String into a EndUserType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EndUserType object represented by the provided JSON + */ + public static EndUserType fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EndUserType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EndUserType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EndUserType object represented by the provided JSON + */ + public static EndUserType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EndUserType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List fields; + + @Getter + private final String friendlyName; + + @Getter + private final String machineName; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private EndUserType( + @JsonProperty("fields") final List fields, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("machine_name") final String machineName, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.fields = fields; + this.friendlyName = friendlyName; + this.machineName = machineName; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EndUserType other = (EndUserType) o; + return ( + Objects.equals(fields, other.fields) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(machineName, other.machineName) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(fields, friendlyName, machineName, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeFetcher.java new file mode 100644 index 0000000000..f26938d3f0 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserTypeFetcher extends Fetcher { + + private String pathSid; + + public EndUserTypeFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/EndUserTypes/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUserType fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EndUserType fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EndUserType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EndUserType content = EndUserType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeReader.java new file mode 100644 index 0000000000..0ac672686c --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserTypeReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserTypeReader extends Reader { + + private Long pageSize; + + public EndUserTypeReader() {} + + public EndUserTypeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "end_user_types", + response.getContent(), + EndUserType.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/EndUserTypes"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "end_user_types", + response.getContent(), + EndUserType.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "EndUserType read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "end_user_types", + response.getContent(), + EndUserType.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserUpdater.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserUpdater.java new file mode 100644 index 0000000000..c3c380ae4a --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/EndUserUpdater.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private Object attributes; + + public EndUserUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public EndUserUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public EndUserUpdater setAttributes(final Object attributes) { + this.attributes = attributes; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/EndUsers/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUser update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EndUser update(final TwilioRestClient client) { + Response response = makeRequest(client); + return EndUser.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EndUser content = EndUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Regulation.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Regulation.java new file mode 100644 index 0000000000..1cd0032cc3 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/Regulation.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Regulation extends Resource { + + public static RegulationFetcher fetcher(final String pathSid) { + return new RegulationFetcher(pathSid); + } + + public static RegulationReader reader() { + return new RegulationReader(); + } + + public enum EndUserType { + INDIVIDUAL("individual"), + BUSINESS("business"); + + private final String value; + + private EndUserType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EndUserType forValue(final String value) { + return Promoter.enumFromString(value, EndUserType.values()); + } + } + + /** + * Converts a JSON String into a Regulation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Regulation object represented by the provided JSON + */ + public static Regulation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Regulation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Regulation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Regulation object represented by the provided JSON + */ + public static Regulation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Regulation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Regulation.EndUserType endUserType; + + @Getter + private final String friendlyName; + + @Getter + private final String isoCountry; + + @Getter + private final String numberType; + + @Getter + private final Object requirements; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Regulation( + @JsonProperty("end_user_type") final Regulation.EndUserType endUserType, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("number_type") final String numberType, + @JsonProperty("requirements") final Object requirements, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.endUserType = endUserType; + this.friendlyName = friendlyName; + this.isoCountry = isoCountry; + this.numberType = numberType; + this.requirements = requirements; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Regulation other = (Regulation) o; + return ( + Objects.equals(endUserType, other.endUserType) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(numberType, other.numberType) && + Objects.equals(requirements, other.requirements) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + endUserType, + friendlyName, + isoCountry, + numberType, + requirements, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationFetcher.java new file mode 100644 index 0000000000..f52aea8931 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationFetcher.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RegulationFetcher extends Fetcher { + + private String pathSid; + private Boolean includeConstraints; + + public RegulationFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + public RegulationFetcher setIncludeConstraints( + final Boolean includeConstraints + ) { + this.includeConstraints = includeConstraints; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Regulations/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Regulation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Regulation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Regulation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Regulation content = Regulation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (includeConstraints != null) { + Serializer.toString( + request, + "IncludeConstraints", + includeConstraints, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationReader.java new file mode 100644 index 0000000000..55e3ff5132 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/RegulationReader.java @@ -0,0 +1,266 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RegulationReader extends Reader { + + private Regulation.EndUserType endUserType; + private String isoCountry; + private String numberType; + private Boolean includeConstraints; + private Long pageSize; + + public RegulationReader() {} + + public RegulationReader setEndUserType( + final Regulation.EndUserType endUserType + ) { + this.endUserType = endUserType; + return this; + } + + public RegulationReader setIsoCountry(final String isoCountry) { + this.isoCountry = isoCountry; + return this; + } + + public RegulationReader setNumberType(final String numberType) { + this.numberType = numberType; + return this; + } + + public RegulationReader setIncludeConstraints( + final Boolean includeConstraints + ) { + this.includeConstraints = includeConstraints; + return this; + } + + public RegulationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Regulation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Regulations"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Regulation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Regulation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + Regulation.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (endUserType != null) { + Serializer.toString( + request, + "EndUserType", + endUserType, + ParameterType.QUERY + ); + } + + if (isoCountry != null) { + Serializer.toString( + request, + "IsoCountry", + isoCountry, + ParameterType.QUERY + ); + } + + if (numberType != null) { + Serializer.toString( + request, + "NumberType", + numberType, + ParameterType.QUERY + ); + } + + if (includeConstraints != null) { + Serializer.toString( + request, + "IncludeConstraints", + includeConstraints, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocument.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocument.java new file mode 100644 index 0000000000..29f6cdea48 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocument.java @@ -0,0 +1,270 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SupportingDocument extends Resource { + + public static SupportingDocumentCreator creator( + final String friendlyName, + final String type + ) { + return new SupportingDocumentCreator(friendlyName, type); + } + + public static SupportingDocumentDeleter deleter(final String pathSid) { + return new SupportingDocumentDeleter(pathSid); + } + + public static SupportingDocumentFetcher fetcher(final String pathSid) { + return new SupportingDocumentFetcher(pathSid); + } + + public static SupportingDocumentReader reader() { + return new SupportingDocumentReader(); + } + + public static SupportingDocumentUpdater updater(final String pathSid) { + return new SupportingDocumentUpdater(pathSid); + } + + public enum Status { + DRAFT("draft"), + PENDING_REVIEW("pending-review"), + REJECTED("rejected"), + APPROVED("approved"), + EXPIRED("expired"), + PROVISIONALLY_APPROVED("provisionally-approved"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a SupportingDocument object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocument object represented by the provided JSON + */ + public static SupportingDocument fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SupportingDocument.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SupportingDocument object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocument object represented by the provided JSON + */ + public static SupportingDocument fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SupportingDocument.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object attributes; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final List errors; + + @Getter + private final String failureReason; + + @Getter + private final String friendlyName; + + @Getter + private final String mimeType; + + @Getter + private final String sid; + + @Getter + private final SupportingDocument.Status status; + + @Getter + private final String type; + + @Getter + private final URI url; + + @JsonCreator + private SupportingDocument( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final Object attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("errors") final List errors, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("mime_type") final String mimeType, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final SupportingDocument.Status status, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.errors = errors; + this.failureReason = failureReason; + this.friendlyName = friendlyName; + this.mimeType = mimeType; + this.sid = sid; + this.status = status; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SupportingDocument other = (SupportingDocument) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(errors, other.errors) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(mimeType, other.mimeType) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + dateCreated, + dateUpdated, + errors, + failureReason, + friendlyName, + mimeType, + sid, + status, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentCreator.java new file mode 100644 index 0000000000..f2e7e7e342 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentCreator.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentCreator extends Creator { + + private String friendlyName; + private String type; + private Object attributes; + + public SupportingDocumentCreator( + final String friendlyName, + final String type + ) { + this.friendlyName = friendlyName; + this.type = type; + } + + public SupportingDocumentCreator setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public SupportingDocumentCreator setType(final String type) { + this.type = type; + return this; + } + + public SupportingDocumentCreator setAttributes(final Object attributes) { + this.attributes = attributes; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/SupportingDocuments"; + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SupportingDocument create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SupportingDocument content = SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentDeleter.java new file mode 100644 index 0000000000..9b0496e50e --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class SupportingDocumentDeleter extends Deleter { + + private String pathSid; + + public SupportingDocumentDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentFetcher.java new file mode 100644 index 0000000000..a65764140e --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentFetcher extends Fetcher { + + private String pathSid; + + public SupportingDocumentFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SupportingDocument fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SupportingDocument content = SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentReader.java new file mode 100644 index 0000000000..5a38b9d120 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentReader extends Reader { + + private Long pageSize; + + public SupportingDocumentReader() {} + + public SupportingDocumentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + SupportingDocument.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/SupportingDocuments"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + SupportingDocument.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + SupportingDocument.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentType.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentType.java new file mode 100644 index 0000000000..455a807fb8 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentType.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SupportingDocumentType extends Resource { + + public static SupportingDocumentTypeFetcher fetcher(final String pathSid) { + return new SupportingDocumentTypeFetcher(pathSid); + } + + public static SupportingDocumentTypeReader reader() { + return new SupportingDocumentTypeReader(); + } + + /** + * Converts a JSON String into a SupportingDocumentType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocumentType object represented by the provided JSON + */ + public static SupportingDocumentType fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SupportingDocumentType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SupportingDocumentType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocumentType object represented by the provided JSON + */ + public static SupportingDocumentType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SupportingDocumentType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List fields; + + @Getter + private final String friendlyName; + + @Getter + private final String machineName; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private SupportingDocumentType( + @JsonProperty("fields") final List fields, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("machine_name") final String machineName, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.fields = fields; + this.friendlyName = friendlyName; + this.machineName = machineName; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SupportingDocumentType other = (SupportingDocumentType) o; + return ( + Objects.equals(fields, other.fields) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(machineName, other.machineName) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(fields, friendlyName, machineName, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeFetcher.java new file mode 100644 index 0000000000..dfedfdffc4 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentTypeFetcher + extends Fetcher { + + private String pathSid; + + public SupportingDocumentTypeFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/SupportingDocumentTypes/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocumentType fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SupportingDocumentType fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SupportingDocumentType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SupportingDocumentType content = SupportingDocumentType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeReader.java new file mode 100644 index 0000000000..259b4ef52a --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentTypeReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentTypeReader + extends Reader { + + private Long pageSize; + + public SupportingDocumentTypeReader() {} + + public SupportingDocumentTypeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "supporting_document_types", + response.getContent(), + SupportingDocumentType.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/SupportingDocumentTypes"; + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "supporting_document_types", + response.getContent(), + SupportingDocumentType.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SupportingDocumentType read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "supporting_document_types", + response.getContent(), + SupportingDocumentType.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentUpdater.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentUpdater.java new file mode 100644 index 0000000000..d36a4323fa --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/SupportingDocumentUpdater.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private Object attributes; + + public SupportingDocumentUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public SupportingDocumentUpdater setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public SupportingDocumentUpdater setAttributes(final Object attributes) { + this.attributes = attributes; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/SupportingDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SupportingDocument update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SupportingDocument content = SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopy.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopy.java new file mode 100644 index 0000000000..407019db5e --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopy.java @@ -0,0 +1,245 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BundleCopy extends Resource { + + public static BundleCopyCreator creator(final String pathBundleSid) { + return new BundleCopyCreator(pathBundleSid); + } + + public static BundleCopyReader reader(final String pathBundleSid) { + return new BundleCopyReader(pathBundleSid); + } + + public enum Status { + DRAFT("draft"), + PENDING_REVIEW("pending-review"), + IN_REVIEW("in-review"), + TWILIO_REJECTED("twilio-rejected"), + TWILIO_APPROVED("twilio-approved"), + PROVISIONALLY_APPROVED("provisionally-approved"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a BundleCopy object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BundleCopy object represented by the provided JSON + */ + public static BundleCopy fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BundleCopy.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BundleCopy object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BundleCopy object represented by the provided JSON + */ + public static BundleCopy fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BundleCopy.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final String friendlyName; + + @Getter + private final String regulationSid; + + @Getter + private final String sid; + + @Getter + private final BundleCopy.Status status; + + @Getter + private final URI statusCallback; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime validUntil; + + @JsonCreator + private BundleCopy( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final BundleCopy.Status status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("valid_until") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime validUntil + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.friendlyName = friendlyName; + this.regulationSid = regulationSid; + this.sid = sid; + this.status = status; + this.statusCallback = statusCallback; + this.validUntil = validUntil; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BundleCopy other = (BundleCopy) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(validUntil, other.validUntil) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + email, + friendlyName, + regulationSid, + sid, + status, + statusCallback, + validUntil + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyCreator.java new file mode 100644 index 0000000000..d66bc79656 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyCreator.java @@ -0,0 +1,122 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BundleCopyCreator extends Creator { + + private String pathBundleSid; + private String friendlyName; + + public BundleCopyCreator(final String pathBundleSid) { + this.pathBundleSid = pathBundleSid; + } + + public BundleCopyCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Copies"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BundleCopy creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BundleCopy create(final TwilioRestClient client) { + Response response = makeRequest(client); + return BundleCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BundleCopy content = BundleCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyReader.java new file mode 100644 index 0000000000..59c9f85257 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/BundleCopyReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BundleCopyReader extends Reader { + + private String pathBundleSid; + private Long pageSize; + + public BundleCopyReader(final String pathBundleSid) { + this.pathBundleSid = pathBundleSid; + } + + public BundleCopyReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + BundleCopy.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Copies"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + BundleCopy.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "BundleCopy read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + BundleCopy.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/Evaluation.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/Evaluation.java new file mode 100644 index 0000000000..c5e0f4957c --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/Evaluation.java @@ -0,0 +1,225 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Evaluation extends Resource { + + public static EvaluationCreator creator(final String pathBundleSid) { + return new EvaluationCreator(pathBundleSid); + } + + public static EvaluationFetcher fetcher( + final String pathBundleSid, + final String pathSid + ) { + return new EvaluationFetcher(pathBundleSid, pathSid); + } + + public static EvaluationReader reader(final String pathBundleSid) { + return new EvaluationReader(pathBundleSid); + } + + public enum Status { + COMPLIANT("compliant"), + NONCOMPLIANT("noncompliant"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a Evaluation object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Evaluation object represented by the provided JSON + */ + public static Evaluation fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Evaluation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Evaluation object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Evaluation object represented by the provided JSON + */ + public static Evaluation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Evaluation.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String bundleSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String regulationSid; + + @Getter + private final List results; + + @Getter + private final String sid; + + @Getter + private final Evaluation.Status status; + + @Getter + private final URI url; + + @JsonCreator + private Evaluation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("results") final List results, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Evaluation.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.bundleSid = bundleSid; + this.dateCreated = dateCreated; + this.regulationSid = regulationSid; + this.results = results; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Evaluation other = (Evaluation) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(results, other.results) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + bundleSid, + dateCreated, + regulationSid, + results, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationCreator.java new file mode 100644 index 0000000000..82c07f08c1 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationCreator.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EvaluationCreator extends Creator { + + private String pathBundleSid; + + public EvaluationCreator(final String pathBundleSid) { + this.pathBundleSid = pathBundleSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Evaluation creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Evaluation create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Evaluation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Evaluation content = Evaluation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationFetcher.java new file mode 100644 index 0000000000..3dded49828 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationFetcher.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EvaluationFetcher extends Fetcher { + + private String pathBundleSid; + private String pathSid; + + public EvaluationFetcher(final String pathBundleSid, final String pathSid) { + this.pathBundleSid = pathBundleSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations/{Sid}"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Evaluation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Evaluation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Evaluation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Evaluation content = Evaluation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationReader.java new file mode 100644 index 0000000000..2567ba5cd9 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/EvaluationReader.java @@ -0,0 +1,212 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EvaluationReader extends Reader { + + private String pathBundleSid; + private Long pageSize; + + public EvaluationReader(final String pathBundleSid) { + this.pathBundleSid = pathBundleSid; + } + + public EvaluationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Evaluation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/Evaluations"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Evaluation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Evaluation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + Evaluation.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignment.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignment.java new file mode 100644 index 0000000000..b63bde6c1d --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignment.java @@ -0,0 +1,197 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ItemAssignment extends Resource { + + public static ItemAssignmentCreator creator( + final String pathBundleSid, + final String objectSid + ) { + return new ItemAssignmentCreator(pathBundleSid, objectSid); + } + + public static ItemAssignmentDeleter deleter( + final String pathBundleSid, + final String pathSid + ) { + return new ItemAssignmentDeleter(pathBundleSid, pathSid); + } + + public static ItemAssignmentFetcher fetcher( + final String pathBundleSid, + final String pathSid + ) { + return new ItemAssignmentFetcher(pathBundleSid, pathSid); + } + + public static ItemAssignmentReader reader(final String pathBundleSid) { + return new ItemAssignmentReader(pathBundleSid); + } + + /** + * Converts a JSON String into a ItemAssignment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ItemAssignment object represented by the provided JSON + */ + public static ItemAssignment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ItemAssignment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ItemAssignment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ItemAssignment object represented by the provided JSON + */ + public static ItemAssignment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ItemAssignment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String bundleSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String objectSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private ItemAssignment( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("bundle_sid") final String bundleSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("object_sid") final String objectSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.bundleSid = bundleSid; + this.dateCreated = dateCreated; + this.objectSid = objectSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ItemAssignment other = (ItemAssignment) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(bundleSid, other.bundleSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(objectSid, other.objectSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + bundleSid, + dateCreated, + objectSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentCreator.java new file mode 100644 index 0000000000..f4a07ebbb7 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentCreator.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ItemAssignmentCreator extends Creator { + + private String pathBundleSid; + private String objectSid; + + public ItemAssignmentCreator( + final String pathBundleSid, + final String objectSid + ) { + this.pathBundleSid = pathBundleSid; + this.objectSid = objectSid; + } + + public ItemAssignmentCreator setObjectSid(final String objectSid) { + this.objectSid = objectSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ItemAssignment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ItemAssignment create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ItemAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ItemAssignment content = ItemAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (objectSid != null) { + Serializer.toString( + request, + "ObjectSid", + objectSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentDeleter.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentDeleter.java new file mode 100644 index 0000000000..e20c3e4bce --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentDeleter.java @@ -0,0 +1,108 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ItemAssignmentDeleter extends Deleter { + + private String pathBundleSid; + private String pathSid; + + public ItemAssignmentDeleter( + final String pathBundleSid, + final String pathSid + ) { + this.pathBundleSid = pathBundleSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments/{Sid}"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ItemAssignment delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentFetcher.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentFetcher.java new file mode 100644 index 0000000000..46ae94625f --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentFetcher.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ItemAssignmentFetcher extends Fetcher { + + private String pathBundleSid; + private String pathSid; + + public ItemAssignmentFetcher( + final String pathBundleSid, + final String pathSid + ) { + this.pathBundleSid = pathBundleSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments/{Sid}"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ItemAssignment fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ItemAssignment fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ItemAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ItemAssignment content = ItemAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentReader.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentReader.java new file mode 100644 index 0000000000..123eb6d4d4 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ItemAssignmentReader.java @@ -0,0 +1,212 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ItemAssignmentReader extends Reader { + + private String pathBundleSid; + private Long pageSize; + + public ItemAssignmentReader(final String pathBundleSid) { + this.pathBundleSid = pathBundleSid; + } + + public ItemAssignmentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + ItemAssignment.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ItemAssignments"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.NUMBERS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + ItemAssignment.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ItemAssignment read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + ItemAssignment.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItems.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItems.java new file mode 100644 index 0000000000..3c53e50477 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItems.java @@ -0,0 +1,244 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ReplaceItems extends Resource { + + public static ReplaceItemsCreator creator( + final String pathBundleSid, + final String fromBundleSid + ) { + return new ReplaceItemsCreator(pathBundleSid, fromBundleSid); + } + + public enum Status { + DRAFT("draft"), + PENDING_REVIEW("pending-review"), + IN_REVIEW("in-review"), + TWILIO_REJECTED("twilio-rejected"), + TWILIO_APPROVED("twilio-approved"), + PROVISIONALLY_APPROVED("provisionally-approved"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a ReplaceItems object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ReplaceItems object represented by the provided JSON + */ + public static ReplaceItems fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ReplaceItems.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ReplaceItems object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ReplaceItems object represented by the provided JSON + */ + public static ReplaceItems fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ReplaceItems.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final String friendlyName; + + @Getter + private final String regulationSid; + + @Getter + private final String sid; + + @Getter + private final ReplaceItems.Status status; + + @Getter + private final URI statusCallback; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime validUntil; + + @JsonCreator + private ReplaceItems( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("regulation_sid") final String regulationSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final ReplaceItems.Status status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("valid_until") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime validUntil + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.friendlyName = friendlyName; + this.regulationSid = regulationSid; + this.sid = sid; + this.status = status; + this.statusCallback = statusCallback; + this.validUntil = validUntil; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ReplaceItems other = (ReplaceItems) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(regulationSid, other.regulationSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(validUntil, other.validUntil) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + email, + friendlyName, + regulationSid, + sid, + status, + statusCallback, + validUntil + ); + } +} diff --git a/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItemsCreator.java b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItemsCreator.java new file mode 100644 index 0000000000..c4c5753e57 --- /dev/null +++ b/src/main/java/com/twilio/rest/numbers/v2/regulatorycompliance/bundle/ReplaceItemsCreator.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Numbers + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.numbers.v2.regulatorycompliance.bundle; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ReplaceItemsCreator extends Creator { + + private String pathBundleSid; + private String fromBundleSid; + + public ReplaceItemsCreator( + final String pathBundleSid, + final String fromBundleSid + ) { + this.pathBundleSid = pathBundleSid; + this.fromBundleSid = fromBundleSid; + } + + public ReplaceItemsCreator setFromBundleSid(final String fromBundleSid) { + this.fromBundleSid = fromBundleSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/RegulatoryCompliance/Bundles/{BundleSid}/ReplaceItems"; + + path = + path.replace( + "{" + "BundleSid" + "}", + this.pathBundleSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.NUMBERS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ReplaceItems creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ReplaceItems create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ReplaceItems.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ReplaceItems content = ReplaceItems.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (fromBundleSid != null) { + Serializer.toString( + request, + "FromBundleSid", + fromBundleSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/oauth/v1/Authorize.java b/src/main/java/com/twilio/rest/oauth/v1/Authorize.java new file mode 100644 index 0000000000..14415cfbf5 --- /dev/null +++ b/src/main/java/com/twilio/rest/oauth/v1/Authorize.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Oauth + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.oauth.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Authorize extends Resource { + + public static AuthorizeFetcher fetcher() { + return new AuthorizeFetcher(); + } + + /** + * Converts a JSON String into a Authorize object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Authorize object represented by the provided JSON + */ + public static Authorize fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Authorize.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Authorize object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Authorize object represented by the provided JSON + */ + public static Authorize fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Authorize.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final URI redirectTo; + + @JsonCreator + private Authorize(@JsonProperty("redirect_to") final URI redirectTo) { + this.redirectTo = redirectTo; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Authorize other = (Authorize) o; + return (Objects.equals(redirectTo, other.redirectTo)); + } + + @Override + public int hashCode() { + return Objects.hash(redirectTo); + } +} diff --git a/src/main/java/com/twilio/rest/oauth/v1/AuthorizeFetcher.java b/src/main/java/com/twilio/rest/oauth/v1/AuthorizeFetcher.java new file mode 100644 index 0000000000..4db39619ec --- /dev/null +++ b/src/main/java/com/twilio/rest/oauth/v1/AuthorizeFetcher.java @@ -0,0 +1,163 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Oauth + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.oauth.v1; + +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthorizeFetcher extends Fetcher { + + private String responseType; + private String clientId; + private String redirectUri; + private String scope; + private String state; + + public AuthorizeFetcher() {} + + public AuthorizeFetcher setResponseType(final String responseType) { + this.responseType = responseType; + return this; + } + + public AuthorizeFetcher setClientId(final String clientId) { + this.clientId = clientId; + return this; + } + + public AuthorizeFetcher setRedirectUri(final String redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + public AuthorizeFetcher setScope(final String scope) { + this.scope = scope; + return this; + } + + public AuthorizeFetcher setState(final String state) { + this.state = state; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/authorize"; + + Request request = new Request( + HttpMethod.GET, + Domains.OAUTH.toString(), + path + ); + request.setAuth(NoAuthStrategy.getInstance()); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Authorize fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Authorize fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Authorize.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Authorize content = Authorize.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (responseType != null) { + Serializer.toString( + request, + "ResponseType", + responseType, + ParameterType.QUERY + ); + } + + if (clientId != null) { + Serializer.toString( + request, + "ClientId", + clientId, + ParameterType.QUERY + ); + } + + if (redirectUri != null) { + Serializer.toString( + request, + "RedirectUri", + redirectUri, + ParameterType.QUERY + ); + } + + if (scope != null) { + Serializer.toString(request, "Scope", scope, ParameterType.QUERY); + } + + if (state != null) { + Serializer.toString(request, "State", state, ParameterType.QUERY); + } + } +} diff --git a/src/main/java/com/twilio/rest/oauth/v1/Token.java b/src/main/java/com/twilio/rest/oauth/v1/Token.java new file mode 100644 index 0000000000..2fa6a848d3 --- /dev/null +++ b/src/main/java/com/twilio/rest/oauth/v1/Token.java @@ -0,0 +1,163 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Oauth + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.oauth.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Token extends Resource { + + public static TokenCreator creator( + final String grantType, + final String clientId + ) { + return new TokenCreator(grantType, clientId); + } + + /** + * Converts a JSON String into a Token object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Token.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Token object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Token.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accessToken; + + @Getter + private final Long expiresIn; + + @Getter + private final String idToken; + + @Getter + private final String refreshToken; + + @Getter + private final String tokenType; + + @JsonCreator + private Token( + @JsonProperty("access_token") final String accessToken, + @JsonProperty("expires_in") final Long expiresIn, + @JsonProperty("id_token") final String idToken, + @JsonProperty("refresh_token") final String refreshToken, + @JsonProperty("token_type") final String tokenType + ) { + this.accessToken = accessToken; + this.expiresIn = expiresIn; + this.idToken = idToken; + this.refreshToken = refreshToken; + this.tokenType = tokenType; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Token other = (Token) o; + return ( + Objects.equals(accessToken, other.accessToken) && + Objects.equals(expiresIn, other.expiresIn) && + Objects.equals(idToken, other.idToken) && + Objects.equals(refreshToken, other.refreshToken) && + Objects.equals(tokenType, other.tokenType) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accessToken, + expiresIn, + idToken, + refreshToken, + tokenType + ); + } +} diff --git a/src/main/java/com/twilio/rest/oauth/v1/TokenCreator.java b/src/main/java/com/twilio/rest/oauth/v1/TokenCreator.java new file mode 100644 index 0000000000..a40f8acec8 --- /dev/null +++ b/src/main/java/com/twilio/rest/oauth/v1/TokenCreator.java @@ -0,0 +1,220 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Oauth + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.oauth.v1; + +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TokenCreator extends Creator { + + private String grantType; + private String clientId; + private String clientSecret; + private String code; + private String redirectUri; + private String audience; + private String refreshToken; + private String scope; + + public TokenCreator(final String grantType, final String clientId) { + this.grantType = grantType; + this.clientId = clientId; + } + + public TokenCreator setGrantType(final String grantType) { + this.grantType = grantType; + return this; + } + + public TokenCreator setClientId(final String clientId) { + this.clientId = clientId; + return this; + } + + public TokenCreator setClientSecret(final String clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + public TokenCreator setCode(final String code) { + this.code = code; + return this; + } + + public TokenCreator setRedirectUri(final String redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + public TokenCreator setAudience(final String audience) { + this.audience = audience; + return this; + } + + public TokenCreator setRefreshToken(final String refreshToken) { + this.refreshToken = refreshToken; + return this; + } + + public TokenCreator setScope(final String scope) { + this.scope = scope; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/token"; + + Request request = new Request( + HttpMethod.POST, + Domains.OAUTH.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + request.setAuth(NoAuthStrategy.getInstance()); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Token creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Token create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Token.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Token content = Token.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (grantType != null) { + Serializer.toString( + request, + "GrantType", + grantType, + ParameterType.URLENCODED + ); + } + + if (clientId != null) { + Serializer.toString( + request, + "ClientId", + clientId, + ParameterType.URLENCODED + ); + } + + if (clientSecret != null) { + Serializer.toString( + request, + "ClientSecret", + clientSecret, + ParameterType.URLENCODED + ); + } + + if (code != null) { + Serializer.toString( + request, + "Code", + code, + ParameterType.URLENCODED + ); + } + + if (redirectUri != null) { + Serializer.toString( + request, + "RedirectUri", + redirectUri, + ParameterType.URLENCODED + ); + } + + if (audience != null) { + Serializer.toString( + request, + "Audience", + audience, + ParameterType.URLENCODED + ); + } + + if (refreshToken != null) { + Serializer.toString( + request, + "RefreshToken", + refreshToken, + ParameterType.URLENCODED + ); + } + + if (scope != null) { + Serializer.toString( + request, + "Scope", + scope, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/oauth/v2/Authorize.java b/src/main/java/com/twilio/rest/oauth/v2/Authorize.java new file mode 100644 index 0000000000..7803859a8c --- /dev/null +++ b/src/main/java/com/twilio/rest/oauth/v2/Authorize.java @@ -0,0 +1,149 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * User OAuth API + * User OAuth API + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.oauth.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Authorize extends Resource { + + public static AuthorizeFetcher fetcher() { + return new AuthorizeFetcher(); + } + + public enum CodeChallengeMethod { + S256("S256"); + + private final String value; + + private CodeChallengeMethod(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static CodeChallengeMethod forValue(final String value) { + return Promoter.enumFromString(value, CodeChallengeMethod.values()); + } + } + + /** + * Converts a JSON String into a Authorize object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Authorize object represented by the provided JSON + */ + public static Authorize fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Authorize.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Authorize object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Authorize object represented by the provided JSON + */ + public static Authorize fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Authorize.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final URI redirectTo; + + @JsonCreator + private Authorize(@JsonProperty("redirect_to") final URI redirectTo) { + this.redirectTo = redirectTo; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Authorize other = (Authorize) o; + return (Objects.equals(redirectTo, other.redirectTo)); + } + + @Override + public int hashCode() { + return Objects.hash(redirectTo); + } +} diff --git a/src/main/java/com/twilio/rest/oauth/v2/AuthorizeFetcher.java b/src/main/java/com/twilio/rest/oauth/v2/AuthorizeFetcher.java new file mode 100644 index 0000000000..c2a3703664 --- /dev/null +++ b/src/main/java/com/twilio/rest/oauth/v2/AuthorizeFetcher.java @@ -0,0 +1,195 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * User OAuth API + * User OAuth API + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.oauth.v2; + +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthorizeFetcher extends Fetcher { + + private String responseType; + private String clientId; + private String redirectUri; + private String scope; + private String state; + private String codeChallenge; + private Authorize.CodeChallengeMethod codeChallengeMethod; + + public AuthorizeFetcher() {} + + public AuthorizeFetcher setResponseType(final String responseType) { + this.responseType = responseType; + return this; + } + + public AuthorizeFetcher setClientId(final String clientId) { + this.clientId = clientId; + return this; + } + + public AuthorizeFetcher setRedirectUri(final String redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + public AuthorizeFetcher setScope(final String scope) { + this.scope = scope; + return this; + } + + public AuthorizeFetcher setState(final String state) { + this.state = state; + return this; + } + + public AuthorizeFetcher setCodeChallenge(final String codeChallenge) { + this.codeChallenge = codeChallenge; + return this; + } + + public AuthorizeFetcher setCodeChallengeMethod( + final Authorize.CodeChallengeMethod codeChallengeMethod + ) { + this.codeChallengeMethod = codeChallengeMethod; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/authorize"; + + Request request = new Request( + HttpMethod.GET, + Domains.OAUTH.toString(), + path + ); + request.setAuth(NoAuthStrategy.getInstance()); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Authorize fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Authorize fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Authorize.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Authorize content = Authorize.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (responseType != null) { + Serializer.toString( + request, + "response_type", + responseType, + ParameterType.QUERY + ); + } + + if (clientId != null) { + Serializer.toString( + request, + "client_id", + clientId, + ParameterType.QUERY + ); + } + + if (redirectUri != null) { + Serializer.toString( + request, + "redirect_uri", + redirectUri, + ParameterType.QUERY + ); + } + + if (scope != null) { + Serializer.toString(request, "scope", scope, ParameterType.QUERY); + } + + if (state != null) { + Serializer.toString(request, "state", state, ParameterType.QUERY); + } + + if (codeChallenge != null) { + Serializer.toString( + request, + "code_challenge", + codeChallenge, + ParameterType.QUERY + ); + } + + if (codeChallengeMethod != null) { + Serializer.toString( + request, + "code_challenge_method", + codeChallengeMethod, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/oauth/v2/Token.java b/src/main/java/com/twilio/rest/oauth/v2/Token.java new file mode 100644 index 0000000000..e3e8530a44 --- /dev/null +++ b/src/main/java/com/twilio/rest/oauth/v2/Token.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * User OAuth API + * User OAuth API + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.oauth.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Token extends Resource { + + public static TokenCreator creator(final String grantType) { + return new TokenCreator(grantType); + } + + /** + * Converts a JSON String into a Token object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Token.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Token object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Token.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accessToken; + + @Getter + private final Long expiresIn; + + @Getter + private final String idToken; + + @Getter + private final String refreshToken; + + @Getter + private final String tokenType; + + @JsonCreator + private Token( + @JsonProperty("access_token") final String accessToken, + @JsonProperty("expires_in") final Long expiresIn, + @JsonProperty("id_token") final String idToken, + @JsonProperty("refresh_token") final String refreshToken, + @JsonProperty("token_type") final String tokenType + ) { + this.accessToken = accessToken; + this.expiresIn = expiresIn; + this.idToken = idToken; + this.refreshToken = refreshToken; + this.tokenType = tokenType; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Token other = (Token) o; + return ( + Objects.equals(accessToken, other.accessToken) && + Objects.equals(expiresIn, other.expiresIn) && + Objects.equals(idToken, other.idToken) && + Objects.equals(refreshToken, other.refreshToken) && + Objects.equals(tokenType, other.tokenType) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accessToken, + expiresIn, + idToken, + refreshToken, + tokenType + ); + } +} diff --git a/src/main/java/com/twilio/rest/oauth/v2/TokenCreator.java b/src/main/java/com/twilio/rest/oauth/v2/TokenCreator.java new file mode 100644 index 0000000000..50d241dfb8 --- /dev/null +++ b/src/main/java/com/twilio/rest/oauth/v2/TokenCreator.java @@ -0,0 +1,252 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * User OAuth API + * User OAuth API + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.oauth.v2; + +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TokenCreator extends Creator { + + private String accountSid; + private String grantType; + private String clientId; + private String clientSecret; + private String code; + private String redirectUri; + private String audience; + private String refreshToken; + private String scope; + private String codeVerifier; + + public TokenCreator(final String grantType) { + this.grantType = grantType; + } + + public TokenCreator setGrantType(final String grantType) { + this.grantType = grantType; + return this; + } + + public TokenCreator setClientId(final String clientId) { + this.clientId = clientId; + return this; + } + + public TokenCreator setClientSecret(final String clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + public TokenCreator setCode(final String code) { + this.code = code; + return this; + } + + public TokenCreator setRedirectUri(final String redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + public TokenCreator setAudience(final String audience) { + this.audience = audience; + return this; + } + + public TokenCreator setRefreshToken(final String refreshToken) { + this.refreshToken = refreshToken; + return this; + } + + public TokenCreator setScope(final String scope) { + this.scope = scope; + return this; + } + + public TokenCreator setCodeVerifier(final String codeVerifier) { + this.codeVerifier = codeVerifier; + return this; + } + + public TokenCreator setAccountSid(final String accountSid) { + this.accountSid = accountSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/token"; + + Request request = new Request( + HttpMethod.POST, + Domains.OAUTH.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + request.setAuth(NoAuthStrategy.getInstance()); + addQueryParams(request); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Token creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Token create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Token.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Token content = Token.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (accountSid != null) { + Serializer.toString( + request, + "account_sid", + accountSid, + ParameterType.QUERY + ); + } + } + + private void addPostParams(final Request request) { + if (grantType != null) { + Serializer.toString( + request, + "grant_type", + grantType, + ParameterType.URLENCODED + ); + } + + if (clientId != null) { + Serializer.toString( + request, + "client_id", + clientId, + ParameterType.URLENCODED + ); + } + + if (clientSecret != null) { + Serializer.toString( + request, + "client_secret", + clientSecret, + ParameterType.URLENCODED + ); + } + + if (code != null) { + Serializer.toString( + request, + "code", + code, + ParameterType.URLENCODED + ); + } + + if (redirectUri != null) { + Serializer.toString( + request, + "redirect_uri", + redirectUri, + ParameterType.URLENCODED + ); + } + + if (audience != null) { + Serializer.toString( + request, + "audience", + audience, + ParameterType.URLENCODED + ); + } + + if (refreshToken != null) { + Serializer.toString( + request, + "refresh_token", + refreshToken, + ParameterType.URLENCODED + ); + } + + if (scope != null) { + Serializer.toString( + request, + "scope", + scope, + ParameterType.URLENCODED + ); + } + + if (codeVerifier != null) { + Serializer.toString( + request, + "code_verifier", + codeVerifier, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/Service.java b/src/main/java/com/twilio/rest/preview/accSecurity/Service.java deleted file mode 100644 index bd41c80ca7..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/Service.java +++ /dev/null @@ -1,275 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Service extends Resource { - private static final long serialVersionUID = 156367691162880L; - - /** - * Create a ServiceCreator to execute create. - * - * @param name Friendly name of the service - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator(final String name) { - return new ServiceCreator(name); - } - - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid Verification Service Instance SID. - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); - } - - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ - public static ServiceReader reader() { - return new ServiceReader(); - } - - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid Service Sid. - * @return ServiceUpdater capable of executing the update - */ - public static ServiceUpdater updater(final String pathSid) { - return new ServiceUpdater(pathSid); - } - - /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Service.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Service.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String name; - private final Integer codeLength; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("name") - final String name, - @JsonProperty("code_length") - final Integer codeLength, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.name = name; - this.codeLength = codeLength; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; - } - - /** - * Returns The A string that uniquely identifies this Service.. - * - * @return A string that uniquely identifies this Service. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Friendly name of the service. - * - * @return Friendly name of the service - */ - public final String getName() { - return this.name; - } - - /** - * Returns The Length of verification code. Valid values are 4-10. - * - * @return Length of verification code. Valid values are 4-10 - */ - public final Integer getCodeLength() { - return this.codeLength; - } - - /** - * Returns The The date this Service was created. - * - * @return The date this Service was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Service was updated. - * - * @return The date this Service was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(name, other.name) && - Objects.equals(codeLength, other.codeLength) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - name, - codeLength, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("name", name) - .add("codeLength", codeLength) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/ServiceCreator.java b/src/main/java/com/twilio/rest/preview/accSecurity/ServiceCreator.java deleted file mode 100644 index fb3ef6528a..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/ServiceCreator.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceCreator extends Creator { - private final String name; - private Integer codeLength; - - /** - * Construct a new ServiceCreator. - * - * @param name Friendly name of the service - */ - public ServiceCreator(final String name) { - this.name = name; - } - - /** - * The length of the verification code to be generated. Must be an integer value - * between 4-10. - * - * @param codeLength Length of verification code. Valid values are 4-10 - * @return this - */ - public ServiceCreator setCodeLength(final Integer codeLength) { - this.codeLength = codeLength; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Verification/Services", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (name != null) { - request.addPostParam("Name", name); - } - - if (codeLength != null) { - request.addPostParam("CodeLength", codeLength.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/ServiceFetcher.java b/src/main/java/com/twilio/rest/preview/accSecurity/ServiceFetcher.java deleted file mode 100644 index 579ef51279..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/ServiceFetcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceFetcher extends Fetcher { - private final String pathSid; - - /** - * Construct a new ServiceFetcher. - * - * @param pathSid Verification Service Instance SID. - */ - public ServiceFetcher(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Verification/Services/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/ServiceReader.java b/src/main/java/com/twilio/rest/preview/accSecurity/ServiceReader.java deleted file mode 100644 index e5ed5134b4..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/ServiceReader.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Verification/Services", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/ServiceUpdater.java b/src/main/java/com/twilio/rest/preview/accSecurity/ServiceUpdater.java deleted file mode 100644 index 9738d9adfc..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/ServiceUpdater.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceUpdater extends Updater { - private final String pathSid; - private String name; - private Integer codeLength; - - /** - * Construct a new ServiceUpdater. - * - * @param pathSid Service Sid. - */ - public ServiceUpdater(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * A 1-64 character string with friendly name of service. - * - * @param name Friendly name of the service - * @return this - */ - public ServiceUpdater setName(final String name) { - this.name = name; - return this; - } - - /** - * The length of the verification code to be generated. Must be an integer value - * between 4-10. - * - * @param codeLength Length of verification code. Valid values are 4-10 - * @return this - */ - public ServiceUpdater setCodeLength(final Integer codeLength) { - this.codeLength = codeLength; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Verification/Services/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (name != null) { - request.addPostParam("Name", name); - } - - if (codeLength != null) { - request.addPostParam("CodeLength", codeLength.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/service/Verification.java b/src/main/java/com/twilio/rest/preview/accSecurity/service/Verification.java deleted file mode 100644 index c8c85d7985..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/service/Verification.java +++ /dev/null @@ -1,292 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Verification extends Resource { - private static final long serialVersionUID = 209968229129653L; - - public enum Channel { - SMS("sms"), - CALL("call"); - - private final String value; - - private Channel(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Channel from a string. - * @param value string value - * @return generated Channel - */ - @JsonCreator - public static Channel forValue(final String value) { - return Promoter.enumFromString(value, Channel.values()); - } - } - - /** - * Create a VerificationCreator to execute create. - * - * @param pathServiceSid Service Sid. - * @param to To phonenumber - * @param channel sms or call - * @return VerificationCreator capable of executing the create - */ - public static VerificationCreator creator(final String pathServiceSid, - final String to, - final String channel) { - return new VerificationCreator(pathServiceSid, to, channel); - } - - /** - * Converts a JSON String into a Verification object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Verification object represented by the provided JSON - */ - public static Verification fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Verification.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Verification object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Verification object represented by the provided JSON - */ - public static Verification fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Verification.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String serviceSid; - private final String accountSid; - private final com.twilio.type.PhoneNumber to; - private final Verification.Channel channel; - private final String status; - private final Boolean valid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private Verification(@JsonProperty("sid") - final String sid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("to") - final com.twilio.type.PhoneNumber to, - @JsonProperty("channel") - final Verification.Channel channel, - @JsonProperty("status") - final String status, - @JsonProperty("valid") - final Boolean valid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.serviceSid = serviceSid; - this.accountSid = accountSid; - this.to = to; - this.channel = channel; - this.status = status; - this.valid = valid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - } - - /** - * Returns The A string that uniquely identifies this Verification.. - * - * @return A string that uniquely identifies this Verification. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The To phonenumber. - * - * @return To phonenumber - */ - public final com.twilio.type.PhoneNumber getTo() { - return this.to; - } - - /** - * Returns The sms or call. - * - * @return sms or call - */ - public final Verification.Channel getChannel() { - return this.channel; - } - - /** - * Returns The pending, approved, denied or expired. - * - * @return pending, approved, denied or expired - */ - public final String getStatus() { - return this.status; - } - - /** - * Returns The successful verification. - * - * @return successful verification - */ - public final Boolean getValid() { - return this.valid; - } - - /** - * Returns The The date this Verification was created. - * - * @return The date this Verification was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Verification was updated. - * - * @return The date this Verification was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Verification other = (Verification) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(to, other.to) && - Objects.equals(channel, other.channel) && - Objects.equals(status, other.status) && - Objects.equals(valid, other.valid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - serviceSid, - accountSid, - to, - channel, - status, - valid, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("to", to) - .add("channel", channel) - .add("status", status) - .add("valid", valid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCheck.java b/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCheck.java deleted file mode 100644 index 2bcd9387ac..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCheck.java +++ /dev/null @@ -1,290 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class VerificationCheck extends Resource { - private static final long serialVersionUID = 135291297208530L; - - public enum Channel { - SMS("sms"), - CALL("call"); - - private final String value; - - private Channel(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Channel from a string. - * @param value string value - * @return generated Channel - */ - @JsonCreator - public static Channel forValue(final String value) { - return Promoter.enumFromString(value, Channel.values()); - } - } - - /** - * Create a VerificationCheckCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param code The verification string - * @return VerificationCheckCreator capable of executing the create - */ - public static VerificationCheckCreator creator(final String pathServiceSid, - final String code) { - return new VerificationCheckCreator(pathServiceSid, code); - } - - /** - * Converts a JSON String into a VerificationCheck object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return VerificationCheck object represented by the provided JSON - */ - public static VerificationCheck fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, VerificationCheck.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a VerificationCheck object using the - * provided ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return VerificationCheck object represented by the provided JSON - */ - public static VerificationCheck fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, VerificationCheck.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String serviceSid; - private final String accountSid; - private final String to; - private final VerificationCheck.Channel channel; - private final String status; - private final Boolean valid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private VerificationCheck(@JsonProperty("sid") - final String sid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("to") - final String to, - @JsonProperty("channel") - final VerificationCheck.Channel channel, - @JsonProperty("status") - final String status, - @JsonProperty("valid") - final Boolean valid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.serviceSid = serviceSid; - this.accountSid = accountSid; - this.to = to; - this.channel = channel; - this.status = status; - this.valid = valid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - } - - /** - * Returns The A string that uniquely identifies this Verification Check.. - * - * @return A string that uniquely identifies this Verification Check. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The To phonenumber. - * - * @return To phonenumber - */ - public final String getTo() { - return this.to; - } - - /** - * Returns The sms or call. - * - * @return sms or call - */ - public final VerificationCheck.Channel getChannel() { - return this.channel; - } - - /** - * Returns The pending, approved, denied or expired. - * - * @return pending, approved, denied or expired - */ - public final String getStatus() { - return this.status; - } - - /** - * Returns The successful verification. - * - * @return successful verification - */ - public final Boolean getValid() { - return this.valid; - } - - /** - * Returns The The date this Verification Check was created. - * - * @return The date this Verification Check was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Verification Check was updated. - * - * @return The date this Verification Check was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - VerificationCheck other = (VerificationCheck) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(to, other.to) && - Objects.equals(channel, other.channel) && - Objects.equals(status, other.status) && - Objects.equals(valid, other.valid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - serviceSid, - accountSid, - to, - channel, - status, - valid, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("to", to) - .add("channel", channel) - .add("status", status) - .add("valid", valid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCheckCreator.java b/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCheckCreator.java deleted file mode 100644 index 3bfe1c49ca..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCheckCreator.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity.service; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class VerificationCheckCreator extends Creator { - private final String pathServiceSid; - private final String code; - private String to; - - /** - * Construct a new VerificationCheckCreator. - * - * @param pathServiceSid The service_sid - * @param code The verification string - */ - public VerificationCheckCreator(final String pathServiceSid, - final String code) { - this.pathServiceSid = pathServiceSid; - this.code = code; - } - - /** - * The To phonenumber of the phone being verified. - * - * @param to To phonenumber - * @return this - */ - public VerificationCheckCreator setTo(final String to) { - this.to = to; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created VerificationCheck - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public VerificationCheck create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Verification/Services/" + this.pathServiceSid + "/VerificationCheck", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("VerificationCheck creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return VerificationCheck.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (code != null) { - request.addPostParam("Code", code); - } - - if (to != null) { - request.addPostParam("To", to); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCreator.java b/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCreator.java deleted file mode 100644 index e598815b85..0000000000 --- a/src/main/java/com/twilio/rest/preview/accSecurity/service/VerificationCreator.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.accSecurity.service; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class VerificationCreator extends Creator { - private final String pathServiceSid; - private final String to; - private final String channel; - private String customMessage; - - /** - * Construct a new VerificationCreator. - * - * @param pathServiceSid Service Sid. - * @param to To phonenumber - * @param channel sms or call - */ - public VerificationCreator(final String pathServiceSid, - final String to, - final String channel) { - this.pathServiceSid = pathServiceSid; - this.to = to; - this.channel = channel; - } - - /** - * A character string containing a custom message for this verification. - * - * @param customMessage A custom message for this verification - * @return this - */ - public VerificationCreator setCustomMessage(final String customMessage) { - this.customMessage = customMessage; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Verification - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Verification create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Verification/Services/" + this.pathServiceSid + "/Verifications", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Verification creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Verification.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (to != null) { - request.addPostParam("To", to); - } - - if (channel != null) { - request.addPostParam("Channel", channel); - } - - if (customMessage != null) { - request.addPostParam("CustomMessage", customMessage); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/bulkExports/Export.java b/src/main/java/com/twilio/rest/preview/bulkExports/Export.java deleted file mode 100644 index 20ec7a2aee..0000000000 --- a/src/main/java/com/twilio/rest/preview/bulkExports/Export.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.bulkExports; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Export extends Resource { - private static final long serialVersionUID = 249832685506996L; - - /** - * Create a ExportFetcher to execute fetch. - * - * @param pathResourceType The resource_type - * @return ExportFetcher capable of executing the fetch - */ - public static ExportFetcher fetcher(final String pathResourceType) { - return new ExportFetcher(pathResourceType); - } - - /** - * Converts a JSON String into a Export object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Export object represented by the provided JSON - */ - public static Export fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Export.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Export object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Export object represented by the provided JSON - */ - public static Export fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Export.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String resourceType; - private final URI url; - private final Map links; - - @JsonCreator - private Export(@JsonProperty("resource_type") - final String resourceType, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.resourceType = resourceType; - this.url = url; - this.links = links; - } - - /** - * Returns The The resource_type. - * - * @return The resource_type - */ - public final String getResourceType() { - return this.resourceType; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Export other = (Export) o; - - return Objects.equals(resourceType, other.resourceType) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(resourceType, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("resourceType", resourceType) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfiguration.java b/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfiguration.java deleted file mode 100644 index b2d111735f..0000000000 --- a/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfiguration.java +++ /dev/null @@ -1,207 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.bulkExports; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class ExportConfiguration extends Resource { - private static final long serialVersionUID = 121290827357040L; - - /** - * Create a ExportConfigurationFetcher to execute fetch. - * - * @param pathResourceType The resource_type - * @return ExportConfigurationFetcher capable of executing the fetch - */ - public static ExportConfigurationFetcher fetcher(final String pathResourceType) { - return new ExportConfigurationFetcher(pathResourceType); - } - - /** - * Create a ExportConfigurationUpdater to execute update. - * - * @param pathResourceType The resource_type - * @return ExportConfigurationUpdater capable of executing the update - */ - public static ExportConfigurationUpdater updater(final String pathResourceType) { - return new ExportConfigurationUpdater(pathResourceType); - } - - /** - * Converts a JSON String into a ExportConfiguration object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ExportConfiguration object represented by the provided JSON - */ - public static ExportConfiguration fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, ExportConfiguration.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a ExportConfiguration object using the - * provided ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ExportConfiguration object represented by the provided JSON - */ - public static ExportConfiguration fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, ExportConfiguration.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final Boolean enabled; - private final URI webhookUrl; - private final String webhookMethod; - private final String resourceType; - private final URI url; - - @JsonCreator - private ExportConfiguration(@JsonProperty("enabled") - final Boolean enabled, - @JsonProperty("webhook_url") - final URI webhookUrl, - @JsonProperty("webhook_method") - final String webhookMethod, - @JsonProperty("resource_type") - final String resourceType, - @JsonProperty("url") - final URI url) { - this.enabled = enabled; - this.webhookUrl = webhookUrl; - this.webhookMethod = webhookMethod; - this.resourceType = resourceType; - this.url = url; - } - - /** - * Returns The The enabled. - * - * @return The enabled - */ - public final Boolean getEnabled() { - return this.enabled; - } - - /** - * Returns The The webhook_url. - * - * @return The webhook_url - */ - public final URI getWebhookUrl() { - return this.webhookUrl; - } - - /** - * Returns The The webhook_method. - * - * @return The webhook_method - */ - public final String getWebhookMethod() { - return this.webhookMethod; - } - - /** - * Returns The The resource_type. - * - * @return The resource_type - */ - public final String getResourceType() { - return this.resourceType; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - ExportConfiguration other = (ExportConfiguration) o; - - return Objects.equals(enabled, other.enabled) && - Objects.equals(webhookUrl, other.webhookUrl) && - Objects.equals(webhookMethod, other.webhookMethod) && - Objects.equals(resourceType, other.resourceType) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(enabled, - webhookUrl, - webhookMethod, - resourceType, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("enabled", enabled) - .add("webhookUrl", webhookUrl) - .add("webhookMethod", webhookMethod) - .add("resourceType", resourceType) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfigurationFetcher.java b/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfigurationFetcher.java deleted file mode 100644 index 061cdcb217..0000000000 --- a/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfigurationFetcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.bulkExports; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ExportConfigurationFetcher extends Fetcher { - private final String pathResourceType; - - /** - * Construct a new ExportConfigurationFetcher. - * - * @param pathResourceType The resource_type - */ - public ExportConfigurationFetcher(final String pathResourceType) { - this.pathResourceType = pathResourceType; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched ExportConfiguration - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ExportConfiguration fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/BulkExports/Exports/" + this.pathResourceType + "/Configuration", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ExportConfiguration fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ExportConfiguration.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfigurationUpdater.java b/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfigurationUpdater.java deleted file mode 100644 index e584b55040..0000000000 --- a/src/main/java/com/twilio/rest/preview/bulkExports/ExportConfigurationUpdater.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.bulkExports; - -import com.twilio.base.Updater; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ExportConfigurationUpdater extends Updater { - private final String pathResourceType; - private Boolean enabled; - private URI webhookUrl; - private String webhookMethod; - - /** - * Construct a new ExportConfigurationUpdater. - * - * @param pathResourceType The resource_type - */ - public ExportConfigurationUpdater(final String pathResourceType) { - this.pathResourceType = pathResourceType; - } - - /** - * The enabled. - * - * @param enabled The enabled - * @return this - */ - public ExportConfigurationUpdater setEnabled(final Boolean enabled) { - this.enabled = enabled; - return this; - } - - /** - * The webhook_url. - * - * @param webhookUrl The webhook_url - * @return this - */ - public ExportConfigurationUpdater setWebhookUrl(final URI webhookUrl) { - this.webhookUrl = webhookUrl; - return this; - } - - /** - * The webhook_url. - * - * @param webhookUrl The webhook_url - * @return this - */ - public ExportConfigurationUpdater setWebhookUrl(final String webhookUrl) { - return setWebhookUrl(Promoter.uriFromString(webhookUrl)); - } - - /** - * The webhook_method. - * - * @param webhookMethod The webhook_method - * @return this - */ - public ExportConfigurationUpdater setWebhookMethod(final String webhookMethod) { - this.webhookMethod = webhookMethod; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated ExportConfiguration - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ExportConfiguration update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/BulkExports/Exports/" + this.pathResourceType + "/Configuration", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ExportConfiguration update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ExportConfiguration.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (enabled != null) { - request.addPostParam("Enabled", enabled.toString()); - } - - if (webhookUrl != null) { - request.addPostParam("WebhookUrl", webhookUrl.toString()); - } - - if (webhookMethod != null) { - request.addPostParam("WebhookMethod", webhookMethod); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/bulkExports/ExportFetcher.java b/src/main/java/com/twilio/rest/preview/bulkExports/ExportFetcher.java deleted file mode 100644 index b0574ad854..0000000000 --- a/src/main/java/com/twilio/rest/preview/bulkExports/ExportFetcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.bulkExports; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ExportFetcher extends Fetcher { - private final String pathResourceType; - - /** - * Construct a new ExportFetcher. - * - * @param pathResourceType The resource_type - */ - public ExportFetcher(final String pathResourceType) { - this.pathResourceType = pathResourceType; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Export - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Export fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/BulkExports/Exports/" + this.pathResourceType + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Export fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Export.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/bulkExports/export/Day.java b/src/main/java/com/twilio/rest/preview/bulkExports/export/Day.java deleted file mode 100644 index ecbb94f3e4..0000000000 --- a/src/main/java/com/twilio/rest/preview/bulkExports/export/Day.java +++ /dev/null @@ -1,180 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.bulkExports.export; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Day extends Resource { - private static final long serialVersionUID = 270981105820838L; - - /** - * Create a DayReader to execute read. - * - * @param pathResourceType The resource_type - * @return DayReader capable of executing the read - */ - public static DayReader reader(final String pathResourceType) { - return new DayReader(pathResourceType); - } - - /** - * Converts a JSON String into a Day object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Day object represented by the provided JSON - */ - public static Day fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Day.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Day object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Day object represented by the provided JSON - */ - public static Day fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Day.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final URI redirectTo; - private final String day; - private final Integer size; - private final String resourceType; - - @JsonCreator - private Day(@JsonProperty("redirect_to") - final URI redirectTo, - @JsonProperty("day") - final String day, - @JsonProperty("size") - final Integer size, - @JsonProperty("resource_type") - final String resourceType) { - this.redirectTo = redirectTo; - this.day = day; - this.size = size; - this.resourceType = resourceType; - } - - /** - * Returns The The redirect_to. - * - * @return The redirect_to - */ - public final URI getRedirectTo() { - return this.redirectTo; - } - - /** - * Returns The The day. - * - * @return The day - */ - public final String getDay() { - return this.day; - } - - /** - * Returns The The size. - * - * @return The size - */ - public final Integer getSize() { - return this.size; - } - - /** - * Returns The The resource_type. - * - * @return The resource_type - */ - public final String getResourceType() { - return this.resourceType; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Day other = (Day) o; - - return Objects.equals(redirectTo, other.redirectTo) && - Objects.equals(day, other.day) && - Objects.equals(size, other.size) && - Objects.equals(resourceType, other.resourceType); - } - - @Override - public int hashCode() { - return Objects.hash(redirectTo, - day, - size, - resourceType); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("redirectTo", redirectTo) - .add("day", day) - .add("size", size) - .add("resourceType", resourceType) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/bulkExports/export/DayReader.java b/src/main/java/com/twilio/rest/preview/bulkExports/export/DayReader.java deleted file mode 100644 index ddbc512851..0000000000 --- a/src/main/java/com/twilio/rest/preview/bulkExports/export/DayReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.bulkExports.export; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DayReader extends Reader { - private final String pathResourceType; - - /** - * Construct a new DayReader. - * - * @param pathResourceType The resource_type - */ - public DayReader(final String pathResourceType) { - this.pathResourceType = pathResourceType; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Day ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Day ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/BulkExports/Exports/" + this.pathResourceType + "/Days", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Day ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Day Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Day read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "days", - response.getContent(), - Day.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/Fleet.java b/src/main/java/com/twilio/rest/preview/deployedDevices/Fleet.java deleted file mode 100644 index 9eade351c5..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/Fleet.java +++ /dev/null @@ -1,300 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Fleet extends Resource { - private static final long serialVersionUID = 61125886588992L; - - /** - * Create a FleetFetcher to execute fetch. - * - * @param pathSid A string that uniquely identifies the Fleet. - * @return FleetFetcher capable of executing the fetch - */ - public static FleetFetcher fetcher(final String pathSid) { - return new FleetFetcher(pathSid); - } - - /** - * Create a FleetDeleter to execute delete. - * - * @param pathSid A string that uniquely identifies the Fleet. - * @return FleetDeleter capable of executing the delete - */ - public static FleetDeleter deleter(final String pathSid) { - return new FleetDeleter(pathSid); - } - - /** - * Create a FleetCreator to execute create. - * - * @return FleetCreator capable of executing the create - */ - public static FleetCreator creator() { - return new FleetCreator(); - } - - /** - * Create a FleetReader to execute read. - * - * @return FleetReader capable of executing the read - */ - public static FleetReader reader() { - return new FleetReader(); - } - - /** - * Create a FleetUpdater to execute update. - * - * @param pathSid A string that uniquely identifies the Fleet. - * @return FleetUpdater capable of executing the update - */ - public static FleetUpdater updater(final String pathSid) { - return new FleetUpdater(pathSid); - } - - /** - * Converts a JSON String into a Fleet object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Fleet object represented by the provided JSON - */ - public static Fleet fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Fleet.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Fleet object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Fleet object represented by the provided JSON - */ - public static Fleet fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Fleet.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final URI url; - private final String uniqueName; - private final String friendlyName; - private final String accountSid; - private final String defaultDeploymentSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final Map links; - - @JsonCreator - private Fleet(@JsonProperty("sid") - final String sid, - @JsonProperty("url") - final URI url, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("default_deployment_sid") - final String defaultDeploymentSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.url = url; - this.uniqueName = uniqueName; - this.friendlyName = friendlyName; - this.accountSid = accountSid; - this.defaultDeploymentSid = defaultDeploymentSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.links = links; - } - - /** - * Returns The A string that uniquely identifies this Fleet.. - * - * @return A string that uniquely identifies this Fleet. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The URL of this Fleet.. - * - * @return URL of this Fleet. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The A unique, addressable name of this Fleet.. - * - * @return A unique, addressable name of this Fleet. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The A human readable description for this Fleet.. - * - * @return A human readable description for this Fleet. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique SID that identifies this Account.. - * - * @return The unique SID that identifies this Account. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique SID that identifies this Fleet's default Deployment.. - * - * @return The unique SID that identifies this Fleet's default Deployment. - */ - public final String getDefaultDeploymentSid() { - return this.defaultDeploymentSid; - } - - /** - * Returns The The date this Fleet was created.. - * - * @return The date this Fleet was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Fleet was updated.. - * - * @return The date this Fleet was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Fleet other = (Fleet) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(url, other.url) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(defaultDeploymentSid, other.defaultDeploymentSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - url, - uniqueName, - friendlyName, - accountSid, - defaultDeploymentSid, - dateCreated, - dateUpdated, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("url", url) - .add("uniqueName", uniqueName) - .add("friendlyName", friendlyName) - .add("accountSid", accountSid) - .add("defaultDeploymentSid", defaultDeploymentSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetCreator.java deleted file mode 100644 index a24aec3686..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetCreator.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FleetCreator extends Creator { - private String friendlyName; - - /** - * Provides a human readable descriptive text for this Fleet, up to 256 - * characters long.. - * - * @param friendlyName A human readable description for this Fleet. - * @return this - */ - public FleetCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Fleet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Fleet create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fleet creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Fleet.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetDeleter.java deleted file mode 100644 index 666b52b957..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetDeleter.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FleetDeleter extends Deleter { - private final String pathSid; - - /** - * Construct a new FleetDeleter. - * - * @param pathSid A string that uniquely identifies the Fleet. - */ - public FleetDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fleet delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetFetcher.java deleted file mode 100644 index 41c71ad8ef..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetFetcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FleetFetcher extends Fetcher { - private final String pathSid; - - /** - * Construct a new FleetFetcher. - * - * @param pathSid A string that uniquely identifies the Fleet. - */ - public FleetFetcher(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Fleet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Fleet fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fleet fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Fleet.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetReader.java deleted file mode 100644 index 34101eb560..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetReader.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FleetReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Fleet ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Fleet ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Fleet ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Fleet Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fleet read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "fleets", - response.getContent(), - Fleet.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/FleetUpdater.java deleted file mode 100644 index 09caf04bd5..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/FleetUpdater.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FleetUpdater extends Updater { - private final String pathSid; - private String friendlyName; - private String defaultDeploymentSid; - - /** - * Construct a new FleetUpdater. - * - * @param pathSid A string that uniquely identifies the Fleet. - */ - public FleetUpdater(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Provides a human readable descriptive text for this Fleet, up to 256 - * characters long.. - * - * @param friendlyName A human readable description for this Fleet. - * @return this - */ - public FleetUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides a string identifier of a Deployment that is going to be used as a - * default one for this Fleet.. - * - * @param defaultDeploymentSid A default Deployment SID. - * @return this - */ - public FleetUpdater setDefaultDeploymentSid(final String defaultDeploymentSid) { - this.defaultDeploymentSid = defaultDeploymentSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Fleet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Fleet update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Fleet update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Fleet.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (defaultDeploymentSid != null) { - request.addPostParam("DefaultDeploymentSid", defaultDeploymentSid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Certificate.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Certificate.java deleted file mode 100644 index 46688ecbb0..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Certificate.java +++ /dev/null @@ -1,311 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Certificate extends Resource { - private static final long serialVersionUID = 78866906209311L; - - /** - * Create a CertificateFetcher to execute fetch. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Certificate. - * @return CertificateFetcher capable of executing the fetch - */ - public static CertificateFetcher fetcher(final String pathFleetSid, - final String pathSid) { - return new CertificateFetcher(pathFleetSid, pathSid); - } - - /** - * Create a CertificateDeleter to execute delete. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Certificate. - * @return CertificateDeleter capable of executing the delete - */ - public static CertificateDeleter deleter(final String pathFleetSid, - final String pathSid) { - return new CertificateDeleter(pathFleetSid, pathSid); - } - - /** - * Create a CertificateCreator to execute create. - * - * @param pathFleetSid The fleet_sid - * @param certificateData The public certificate data. - * @return CertificateCreator capable of executing the create - */ - public static CertificateCreator creator(final String pathFleetSid, - final String certificateData) { - return new CertificateCreator(pathFleetSid, certificateData); - } - - /** - * Create a CertificateReader to execute read. - * - * @param pathFleetSid The fleet_sid - * @return CertificateReader capable of executing the read - */ - public static CertificateReader reader(final String pathFleetSid) { - return new CertificateReader(pathFleetSid); - } - - /** - * Create a CertificateUpdater to execute update. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Certificate. - * @return CertificateUpdater capable of executing the update - */ - public static CertificateUpdater updater(final String pathFleetSid, - final String pathSid) { - return new CertificateUpdater(pathFleetSid, pathSid); - } - - /** - * Converts a JSON String into a Certificate object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Certificate object represented by the provided JSON - */ - public static Certificate fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Certificate.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Certificate object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Certificate object represented by the provided JSON - */ - public static Certificate fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Certificate.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final URI url; - private final String friendlyName; - private final String fleetSid; - private final String accountSid; - private final String deviceSid; - private final String thumbprint; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private Certificate(@JsonProperty("sid") - final String sid, - @JsonProperty("url") - final URI url, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("fleet_sid") - final String fleetSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("device_sid") - final String deviceSid, - @JsonProperty("thumbprint") - final String thumbprint, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.url = url; - this.friendlyName = friendlyName; - this.fleetSid = fleetSid; - this.accountSid = accountSid; - this.deviceSid = deviceSid; - this.thumbprint = thumbprint; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - } - - /** - * Returns The A string that uniquely identifies this Certificate.. - * - * @return A string that uniquely identifies this Certificate. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The URL of this Certificate.. - * - * @return URL of this Certificate. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The A human readable description for this Certificate.. - * - * @return A human readable description for this Certificate. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique identifier of the Fleet.. - * - * @return The unique identifier of the Fleet. - */ - public final String getFleetSid() { - return this.fleetSid; - } - - /** - * Returns The The unique SID that identifies this Account.. - * - * @return The unique SID that identifies this Account. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique identifier of a mapped Device.. - * - * @return The unique identifier of a mapped Device. - */ - public final String getDeviceSid() { - return this.deviceSid; - } - - /** - * Returns The A Certificate unique payload hash.. - * - * @return A Certificate unique payload hash. - */ - public final String getThumbprint() { - return this.thumbprint; - } - - /** - * Returns The The date this Certificate was created.. - * - * @return The date this Certificate was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Certificate was updated.. - * - * @return The date this Certificate was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Certificate other = (Certificate) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(url, other.url) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(fleetSid, other.fleetSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(deviceSid, other.deviceSid) && - Objects.equals(thumbprint, other.thumbprint) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - url, - friendlyName, - fleetSid, - accountSid, - deviceSid, - thumbprint, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("url", url) - .add("friendlyName", friendlyName) - .add("fleetSid", fleetSid) - .add("accountSid", accountSid) - .add("deviceSid", deviceSid) - .add("thumbprint", thumbprint) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateCreator.java deleted file mode 100644 index 9dc1c95f0f..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateCreator.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class CertificateCreator extends Creator { - private final String pathFleetSid; - private final String certificateData; - private String friendlyName; - private String deviceSid; - - /** - * Construct a new CertificateCreator. - * - * @param pathFleetSid The fleet_sid - * @param certificateData The public certificate data. - */ - public CertificateCreator(final String pathFleetSid, - final String certificateData) { - this.pathFleetSid = pathFleetSid; - this.certificateData = certificateData; - } - - /** - * Provides a human readable descriptive text for this Certificate credential, - * up to 256 characters long.. - * - * @param friendlyName The human readable description for this Certificate. - * @return this - */ - public CertificateCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides the unique string identifier of an existing Device to become - * authenticated with this Certificate credential.. - * - * @param deviceSid The unique identifier of a Device to be authenticated. - * @return this - */ - public CertificateCreator setDeviceSid(final String deviceSid) { - this.deviceSid = deviceSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Certificate - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Certificate create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Certificates", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Certificate creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Certificate.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (certificateData != null) { - request.addPostParam("CertificateData", certificateData); - } - - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (deviceSid != null) { - request.addPostParam("DeviceSid", deviceSid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateDeleter.java deleted file mode 100644 index 4875077a52..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class CertificateDeleter extends Deleter { - private final String pathFleetSid; - private final String pathSid; - - /** - * Construct a new CertificateDeleter. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Certificate. - */ - public CertificateDeleter(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Certificates/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Certificate delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateFetcher.java deleted file mode 100644 index 864c23286c..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class CertificateFetcher extends Fetcher { - private final String pathFleetSid; - private final String pathSid; - - /** - * Construct a new CertificateFetcher. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Certificate. - */ - public CertificateFetcher(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Certificate - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Certificate fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Certificates/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Certificate fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Certificate.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateReader.java deleted file mode 100644 index 4574942e24..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateReader.java +++ /dev/null @@ -1,190 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class CertificateReader extends Reader { - private final String pathFleetSid; - private String deviceSid; - - /** - * Construct a new CertificateReader. - * - * @param pathFleetSid The fleet_sid - */ - public CertificateReader(final String pathFleetSid) { - this.pathFleetSid = pathFleetSid; - } - - /** - * Filters the resulting list of Certificates by a unique string identifier of - * an authenticated Device.. - * - * @param deviceSid Find all Certificates authenticating specified Device. - * @return this - */ - public CertificateReader setDeviceSid(final String deviceSid) { - this.deviceSid = deviceSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Certificate ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Certificate ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Certificates", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Certificate ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Certificate Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Certificate read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "certificates", - response.getContent(), - Certificate.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (deviceSid != null) { - request.addQueryParam("DeviceSid", deviceSid); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateUpdater.java deleted file mode 100644 index 453ba32c99..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/CertificateUpdater.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class CertificateUpdater extends Updater { - private final String pathFleetSid; - private final String pathSid; - private String friendlyName; - private String deviceSid; - - /** - * Construct a new CertificateUpdater. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Certificate. - */ - public CertificateUpdater(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Provides a human readable descriptive text for this Certificate credential, - * up to 256 characters long.. - * - * @param friendlyName The human readable description for this Certificate. - * @return this - */ - public CertificateUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides the unique string identifier of an existing Device to become - * authenticated with this Certificate credential.. - * - * @param deviceSid The unique identifier of a Device to be authenticated. - * @return this - */ - public CertificateUpdater setDeviceSid(final String deviceSid) { - this.deviceSid = deviceSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Certificate - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Certificate update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Certificates/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Certificate update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Certificate.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (deviceSid != null) { - request.addPostParam("DeviceSid", deviceSid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Deployment.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Deployment.java deleted file mode 100644 index e61ad8da85..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Deployment.java +++ /dev/null @@ -1,293 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Deployment extends Resource { - private static final long serialVersionUID = 277943167449675L; - - /** - * Create a DeploymentFetcher to execute fetch. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Deployment. - * @return DeploymentFetcher capable of executing the fetch - */ - public static DeploymentFetcher fetcher(final String pathFleetSid, - final String pathSid) { - return new DeploymentFetcher(pathFleetSid, pathSid); - } - - /** - * Create a DeploymentDeleter to execute delete. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Deployment. - * @return DeploymentDeleter capable of executing the delete - */ - public static DeploymentDeleter deleter(final String pathFleetSid, - final String pathSid) { - return new DeploymentDeleter(pathFleetSid, pathSid); - } - - /** - * Create a DeploymentCreator to execute create. - * - * @param pathFleetSid The fleet_sid - * @return DeploymentCreator capable of executing the create - */ - public static DeploymentCreator creator(final String pathFleetSid) { - return new DeploymentCreator(pathFleetSid); - } - - /** - * Create a DeploymentReader to execute read. - * - * @param pathFleetSid The fleet_sid - * @return DeploymentReader capable of executing the read - */ - public static DeploymentReader reader(final String pathFleetSid) { - return new DeploymentReader(pathFleetSid); - } - - /** - * Create a DeploymentUpdater to execute update. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Deployment. - * @return DeploymentUpdater capable of executing the update - */ - public static DeploymentUpdater updater(final String pathFleetSid, - final String pathSid) { - return new DeploymentUpdater(pathFleetSid, pathSid); - } - - /** - * Converts a JSON String into a Deployment object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Deployment object represented by the provided JSON - */ - public static Deployment fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Deployment.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Deployment object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Deployment object represented by the provided JSON - */ - public static Deployment fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Deployment.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final URI url; - private final String friendlyName; - private final String fleetSid; - private final String accountSid; - private final String syncServiceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private Deployment(@JsonProperty("sid") - final String sid, - @JsonProperty("url") - final URI url, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("fleet_sid") - final String fleetSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("sync_service_sid") - final String syncServiceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.url = url; - this.friendlyName = friendlyName; - this.fleetSid = fleetSid; - this.accountSid = accountSid; - this.syncServiceSid = syncServiceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - } - - /** - * Returns The A string that uniquely identifies this Deployment.. - * - * @return A string that uniquely identifies this Deployment. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The URL of this Deployment.. - * - * @return URL of this Deployment. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The A human readable description for this Deployment. - * - * @return A human readable description for this Deployment - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique identifier of the Fleet.. - * - * @return The unique identifier of the Fleet. - */ - public final String getFleetSid() { - return this.fleetSid; - } - - /** - * Returns The The unique SID that identifies this Account.. - * - * @return The unique SID that identifies this Account. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique identifier of the Sync service instance.. - * - * @return The unique identifier of the Sync service instance. - */ - public final String getSyncServiceSid() { - return this.syncServiceSid; - } - - /** - * Returns The The date this Deployment was created.. - * - * @return The date this Deployment was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Deployment was updated.. - * - * @return The date this Deployment was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Deployment other = (Deployment) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(url, other.url) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(fleetSid, other.fleetSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(syncServiceSid, other.syncServiceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - url, - friendlyName, - fleetSid, - accountSid, - syncServiceSid, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("url", url) - .add("friendlyName", friendlyName) - .add("fleetSid", fleetSid) - .add("accountSid", accountSid) - .add("syncServiceSid", syncServiceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentCreator.java deleted file mode 100644 index b5802005fb..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentCreator.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeploymentCreator extends Creator { - private final String pathFleetSid; - private String friendlyName; - private String syncServiceSid; - - /** - * Construct a new DeploymentCreator. - * - * @param pathFleetSid The fleet_sid - */ - public DeploymentCreator(final String pathFleetSid) { - this.pathFleetSid = pathFleetSid; - } - - /** - * Provides a human readable descriptive text for this Deployment, up to 256 - * characters long.. - * - * @param friendlyName A human readable description for this Deployment. - * @return this - */ - public DeploymentCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides the unique string identifier of the Twilio Sync service instance - * that will be linked to and accessible by this Deployment.. - * - * @param syncServiceSid The unique identifier of the Sync service instance. - * @return this - */ - public DeploymentCreator setSyncServiceSid(final String syncServiceSid) { - this.syncServiceSid = syncServiceSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Deployment - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Deployment create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Deployments", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Deployment creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Deployment.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (syncServiceSid != null) { - request.addPostParam("SyncServiceSid", syncServiceSid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentDeleter.java deleted file mode 100644 index 7f0c94bb63..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeploymentDeleter extends Deleter { - private final String pathFleetSid; - private final String pathSid; - - /** - * Construct a new DeploymentDeleter. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Deployment. - */ - public DeploymentDeleter(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Deployments/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Deployment delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentFetcher.java deleted file mode 100644 index 133eb5fdea..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeploymentFetcher extends Fetcher { - private final String pathFleetSid; - private final String pathSid; - - /** - * Construct a new DeploymentFetcher. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Deployment. - */ - public DeploymentFetcher(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Deployment - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Deployment fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Deployments/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Deployment fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Deployment.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentReader.java deleted file mode 100644 index a817ef7a65..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeploymentReader extends Reader { - private final String pathFleetSid; - - /** - * Construct a new DeploymentReader. - * - * @param pathFleetSid The fleet_sid - */ - public DeploymentReader(final String pathFleetSid) { - this.pathFleetSid = pathFleetSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Deployment ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Deployment ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Deployments", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Deployment ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Deployment Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Deployment read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "deployments", - response.getContent(), - Deployment.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentUpdater.java deleted file mode 100644 index 31d8653004..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeploymentUpdater.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeploymentUpdater extends Updater { - private final String pathFleetSid; - private final String pathSid; - private String friendlyName; - private String syncServiceSid; - - /** - * Construct a new DeploymentUpdater. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Deployment. - */ - public DeploymentUpdater(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Provides a human readable descriptive text for this Deployment, up to 64 - * characters long. - * - * @param friendlyName A human readable description for this Deployment. - * @return this - */ - public DeploymentUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides the unique string identifier of the Twilio Sync service instance - * that will be linked to and accessible by this Deployment.. - * - * @param syncServiceSid The unique identifier of the Sync service instance. - * @return this - */ - public DeploymentUpdater setSyncServiceSid(final String syncServiceSid) { - this.syncServiceSid = syncServiceSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Deployment - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Deployment update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Deployments/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Deployment update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Deployment.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (syncServiceSid != null) { - request.addPostParam("SyncServiceSid", syncServiceSid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Device.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Device.java deleted file mode 100644 index 6ad7f6b7c6..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Device.java +++ /dev/null @@ -1,356 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Device extends Resource { - private static final long serialVersionUID = 144542670393653L; - - /** - * Create a DeviceFetcher to execute fetch. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Device. - * @return DeviceFetcher capable of executing the fetch - */ - public static DeviceFetcher fetcher(final String pathFleetSid, - final String pathSid) { - return new DeviceFetcher(pathFleetSid, pathSid); - } - - /** - * Create a DeviceDeleter to execute delete. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Device. - * @return DeviceDeleter capable of executing the delete - */ - public static DeviceDeleter deleter(final String pathFleetSid, - final String pathSid) { - return new DeviceDeleter(pathFleetSid, pathSid); - } - - /** - * Create a DeviceCreator to execute create. - * - * @param pathFleetSid The fleet_sid - * @return DeviceCreator capable of executing the create - */ - public static DeviceCreator creator(final String pathFleetSid) { - return new DeviceCreator(pathFleetSid); - } - - /** - * Create a DeviceReader to execute read. - * - * @param pathFleetSid The fleet_sid - * @return DeviceReader capable of executing the read - */ - public static DeviceReader reader(final String pathFleetSid) { - return new DeviceReader(pathFleetSid); - } - - /** - * Create a DeviceUpdater to execute update. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Device. - * @return DeviceUpdater capable of executing the update - */ - public static DeviceUpdater updater(final String pathFleetSid, - final String pathSid) { - return new DeviceUpdater(pathFleetSid, pathSid); - } - - /** - * Converts a JSON String into a Device object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Device object represented by the provided JSON - */ - public static Device fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Device.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Device object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Device object represented by the provided JSON - */ - public static Device fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Device.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final URI url; - private final String uniqueName; - private final String friendlyName; - private final String fleetSid; - private final Boolean enabled; - private final String accountSid; - private final String identity; - private final String deploymentSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final DateTime dateAuthenticated; - - @JsonCreator - private Device(@JsonProperty("sid") - final String sid, - @JsonProperty("url") - final URI url, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("fleet_sid") - final String fleetSid, - @JsonProperty("enabled") - final Boolean enabled, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("deployment_sid") - final String deploymentSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("date_authenticated") - final String dateAuthenticated) { - this.sid = sid; - this.url = url; - this.uniqueName = uniqueName; - this.friendlyName = friendlyName; - this.fleetSid = fleetSid; - this.enabled = enabled; - this.accountSid = accountSid; - this.identity = identity; - this.deploymentSid = deploymentSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.dateAuthenticated = DateConverter.iso8601DateTimeFromString(dateAuthenticated); - } - - /** - * Returns The A string that uniquely identifies this Device.. - * - * @return A string that uniquely identifies this Device. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The URL of this Device.. - * - * @return URL of this Device. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The A unique, addressable name of this Device.. - * - * @return A unique, addressable name of this Device. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The A human readable description for this Device. - * - * @return A human readable description for this Device - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique identifier of the Fleet.. - * - * @return The unique identifier of the Fleet. - */ - public final String getFleetSid() { - return this.fleetSid; - } - - /** - * Returns The Device enabled flag.. - * - * @return Device enabled flag. - */ - public final Boolean getEnabled() { - return this.enabled; - } - - /** - * Returns The The unique SID that identifies this Account.. - * - * @return The unique SID that identifies this Account. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The An identifier of the Device user.. - * - * @return An identifier of the Device user. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The The unique SID of the Deployment group.. - * - * @return The unique SID of the Deployment group. - */ - public final String getDeploymentSid() { - return this.deploymentSid; - } - - /** - * Returns The The date this Device was created.. - * - * @return The date this Device was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Device was updated.. - * - * @return The date this Device was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The date this Device was authenticated.. - * - * @return The date this Device was authenticated. - */ - public final DateTime getDateAuthenticated() { - return this.dateAuthenticated; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Device other = (Device) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(url, other.url) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(fleetSid, other.fleetSid) && - Objects.equals(enabled, other.enabled) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(identity, other.identity) && - Objects.equals(deploymentSid, other.deploymentSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(dateAuthenticated, other.dateAuthenticated); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - url, - uniqueName, - friendlyName, - fleetSid, - enabled, - accountSid, - identity, - deploymentSid, - dateCreated, - dateUpdated, - dateAuthenticated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("url", url) - .add("uniqueName", uniqueName) - .add("friendlyName", friendlyName) - .add("fleetSid", fleetSid) - .add("enabled", enabled) - .add("accountSid", accountSid) - .add("identity", identity) - .add("deploymentSid", deploymentSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("dateAuthenticated", dateAuthenticated) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceCreator.java deleted file mode 100644 index 54f211b204..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceCreator.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeviceCreator extends Creator { - private final String pathFleetSid; - private String uniqueName; - private String friendlyName; - private String identity; - private String deploymentSid; - private Boolean enabled; - - /** - * Construct a new DeviceCreator. - * - * @param pathFleetSid The fleet_sid - */ - public DeviceCreator(final String pathFleetSid) { - this.pathFleetSid = pathFleetSid; - } - - /** - * Provides a unique and addressable name to be assigned to this Device, to be - * used in addition to SID, up to 128 characters long.. - * - * @param uniqueName A unique, addressable name of this Device. - * @return this - */ - public DeviceCreator setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * Provides a human readable descriptive text to be assigned to this Device, up - * to 256 characters long.. - * - * @param friendlyName A human readable description for this Device. - * @return this - */ - public DeviceCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides an arbitrary string identifier representing a human user to be - * associated with this Device, up to 256 characters long.. - * - * @param identity An identifier of the Device user. - * @return this - */ - public DeviceCreator setIdentity(final String identity) { - this.identity = identity; - return this; - } - - /** - * Specifies the unique string identifier of the Deployment group that this - * Device is going to be associated with.. - * - * @param deploymentSid The unique SID of the Deployment group. - * @return this - */ - public DeviceCreator setDeploymentSid(final String deploymentSid) { - this.deploymentSid = deploymentSid; - return this; - } - - /** - * The enabled. - * - * @param enabled The enabled - * @return this - */ - public DeviceCreator setEnabled(final Boolean enabled) { - this.enabled = enabled; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Device - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Device create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Devices", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Device creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Device.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (identity != null) { - request.addPostParam("Identity", identity); - } - - if (deploymentSid != null) { - request.addPostParam("DeploymentSid", deploymentSid); - } - - if (enabled != null) { - request.addPostParam("Enabled", enabled.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceDeleter.java deleted file mode 100644 index 36510b98ce..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeviceDeleter extends Deleter { - private final String pathFleetSid; - private final String pathSid; - - /** - * Construct a new DeviceDeleter. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Device. - */ - public DeviceDeleter(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Devices/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Device delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceFetcher.java deleted file mode 100644 index bbbc94eaf9..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeviceFetcher extends Fetcher { - private final String pathFleetSid; - private final String pathSid; - - /** - * Construct a new DeviceFetcher. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Device. - */ - public DeviceFetcher(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Device - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Device fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Devices/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Device fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Device.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceReader.java deleted file mode 100644 index 8b743a7e86..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceReader.java +++ /dev/null @@ -1,190 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeviceReader extends Reader { - private final String pathFleetSid; - private String deploymentSid; - - /** - * Construct a new DeviceReader. - * - * @param pathFleetSid The fleet_sid - */ - public DeviceReader(final String pathFleetSid) { - this.pathFleetSid = pathFleetSid; - } - - /** - * Filters the resulting list of Devices by a unique string identifier of the - * Deployment they are associated with.. - * - * @param deploymentSid Find all Devices grouped under the specified Deployment. - * @return this - */ - public DeviceReader setDeploymentSid(final String deploymentSid) { - this.deploymentSid = deploymentSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Device ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Device ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Devices", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Device ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Device Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Device read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "devices", - response.getContent(), - Device.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (deploymentSid != null) { - request.addQueryParam("DeploymentSid", deploymentSid); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceUpdater.java deleted file mode 100644 index 9a4afa6705..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/DeviceUpdater.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DeviceUpdater extends Updater { - private final String pathFleetSid; - private final String pathSid; - private String friendlyName; - private String identity; - private String deploymentSid; - private Boolean enabled; - - /** - * Construct a new DeviceUpdater. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Device. - */ - public DeviceUpdater(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Provides a human readable descriptive text to be assigned to this Device, up - * to 256 characters long.. - * - * @param friendlyName A human readable description for this Device. - * @return this - */ - public DeviceUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides an arbitrary string identifier representing a human user to be - * associated with this Device, up to 256 characters long.. - * - * @param identity An identifier of the Device user. - * @return this - */ - public DeviceUpdater setIdentity(final String identity) { - this.identity = identity; - return this; - } - - /** - * Specifies the unique string identifier of the Deployment group that this - * Device is going to be associated with.. - * - * @param deploymentSid The unique SID of the Deployment group. - * @return this - */ - public DeviceUpdater setDeploymentSid(final String deploymentSid) { - this.deploymentSid = deploymentSid; - return this; - } - - /** - * The enabled. - * - * @param enabled The enabled - * @return this - */ - public DeviceUpdater setEnabled(final Boolean enabled) { - this.enabled = enabled; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Device - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Device update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Devices/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Device update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Device.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (identity != null) { - request.addPostParam("Identity", identity); - } - - if (deploymentSid != null) { - request.addPostParam("DeploymentSid", deploymentSid); - } - - if (enabled != null) { - request.addPostParam("Enabled", enabled.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Key.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Key.java deleted file mode 100644 index 3031bb80ad..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/Key.java +++ /dev/null @@ -1,308 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Key extends Resource { - private static final long serialVersionUID = 62747134946875L; - - /** - * Create a KeyFetcher to execute fetch. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Key. - * @return KeyFetcher capable of executing the fetch - */ - public static KeyFetcher fetcher(final String pathFleetSid, - final String pathSid) { - return new KeyFetcher(pathFleetSid, pathSid); - } - - /** - * Create a KeyDeleter to execute delete. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Key. - * @return KeyDeleter capable of executing the delete - */ - public static KeyDeleter deleter(final String pathFleetSid, - final String pathSid) { - return new KeyDeleter(pathFleetSid, pathSid); - } - - /** - * Create a KeyCreator to execute create. - * - * @param pathFleetSid The fleet_sid - * @return KeyCreator capable of executing the create - */ - public static KeyCreator creator(final String pathFleetSid) { - return new KeyCreator(pathFleetSid); - } - - /** - * Create a KeyReader to execute read. - * - * @param pathFleetSid The fleet_sid - * @return KeyReader capable of executing the read - */ - public static KeyReader reader(final String pathFleetSid) { - return new KeyReader(pathFleetSid); - } - - /** - * Create a KeyUpdater to execute update. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Key. - * @return KeyUpdater capable of executing the update - */ - public static KeyUpdater updater(final String pathFleetSid, - final String pathSid) { - return new KeyUpdater(pathFleetSid, pathSid); - } - - /** - * Converts a JSON String into a Key object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Key object represented by the provided JSON - */ - public static Key fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Key.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Key object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Key object represented by the provided JSON - */ - public static Key fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Key.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final URI url; - private final String friendlyName; - private final String fleetSid; - private final String accountSid; - private final String deviceSid; - private final String secret; - private final DateTime dateCreated; - private final DateTime dateUpdated; - - @JsonCreator - private Key(@JsonProperty("sid") - final String sid, - @JsonProperty("url") - final URI url, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("fleet_sid") - final String fleetSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("device_sid") - final String deviceSid, - @JsonProperty("secret") - final String secret, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated) { - this.sid = sid; - this.url = url; - this.friendlyName = friendlyName; - this.fleetSid = fleetSid; - this.accountSid = accountSid; - this.deviceSid = deviceSid; - this.secret = secret; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - } - - /** - * Returns The A string that uniquely identifies this Key.. - * - * @return A string that uniquely identifies this Key. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The URL of this Key.. - * - * @return URL of this Key. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The A human readable description for this Key.. - * - * @return A human readable description for this Key. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique identifier of the Fleet.. - * - * @return The unique identifier of the Fleet. - */ - public final String getFleetSid() { - return this.fleetSid; - } - - /** - * Returns The The unique SID that identifies this Account.. - * - * @return The unique SID that identifies this Account. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The unique identifier of a mapped Device.. - * - * @return The unique identifier of a mapped Device. - */ - public final String getDeviceSid() { - return this.deviceSid; - } - - /** - * Returns The The key secret.. - * - * @return The key secret. - */ - public final String getSecret() { - return this.secret; - } - - /** - * Returns The The date this Key credential was created.. - * - * @return The date this Key credential was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Key credential was updated.. - * - * @return The date this Key credential was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Key other = (Key) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(url, other.url) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(fleetSid, other.fleetSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(deviceSid, other.deviceSid) && - Objects.equals(secret, other.secret) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - url, - friendlyName, - fleetSid, - accountSid, - deviceSid, - secret, - dateCreated, - dateUpdated); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("url", url) - .add("friendlyName", friendlyName) - .add("fleetSid", fleetSid) - .add("accountSid", accountSid) - .add("deviceSid", deviceSid) - .add("secret", secret) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyCreator.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyCreator.java deleted file mode 100644 index fb0b167940..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyCreator.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class KeyCreator extends Creator { - private final String pathFleetSid; - private String friendlyName; - private String deviceSid; - - /** - * Construct a new KeyCreator. - * - * @param pathFleetSid The fleet_sid - */ - public KeyCreator(final String pathFleetSid) { - this.pathFleetSid = pathFleetSid; - } - - /** - * Provides a human readable descriptive text for this Key credential, up to 256 - * characters long.. - * - * @param friendlyName The human readable description for this Key. - * @return this - */ - public KeyCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides the unique string identifier of an existing Device to become - * authenticated with this Key credential.. - * - * @param deviceSid The unique identifier of a Key to be authenticated. - * @return this - */ - public KeyCreator setDeviceSid(final String deviceSid) { - this.deviceSid = deviceSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Key - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Key create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Keys", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Key creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Key.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (deviceSid != null) { - request.addPostParam("DeviceSid", deviceSid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyDeleter.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyDeleter.java deleted file mode 100644 index 62c3724e2d..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class KeyDeleter extends Deleter { - private final String pathFleetSid; - private final String pathSid; - - /** - * Construct a new KeyDeleter. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Key. - */ - public KeyDeleter(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Keys/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Key delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyFetcher.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyFetcher.java deleted file mode 100644 index fef3be811e..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class KeyFetcher extends Fetcher { - private final String pathFleetSid; - private final String pathSid; - - /** - * Construct a new KeyFetcher. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Key. - */ - public KeyFetcher(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Key - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Key fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Keys/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Key fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Key.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyReader.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyReader.java deleted file mode 100644 index 126fe564fa..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyReader.java +++ /dev/null @@ -1,190 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class KeyReader extends Reader { - private final String pathFleetSid; - private String deviceSid; - - /** - * Construct a new KeyReader. - * - * @param pathFleetSid The fleet_sid - */ - public KeyReader(final String pathFleetSid) { - this.pathFleetSid = pathFleetSid; - } - - /** - * Filters the resulting list of Keys by a unique string identifier of an - * authenticated Device.. - * - * @param deviceSid Find all Keys authenticating specified Device. - * @return this - */ - public KeyReader setDeviceSid(final String deviceSid) { - this.deviceSid = deviceSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Key ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Key ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Keys", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Key ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Key Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Key read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "keys", - response.getContent(), - Key.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (deviceSid != null) { - request.addQueryParam("DeviceSid", deviceSid); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyUpdater.java b/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyUpdater.java deleted file mode 100644 index 3d77735c15..0000000000 --- a/src/main/java/com/twilio/rest/preview/deployedDevices/fleet/KeyUpdater.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.deployedDevices.fleet; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class KeyUpdater extends Updater { - private final String pathFleetSid; - private final String pathSid; - private String friendlyName; - private String deviceSid; - - /** - * Construct a new KeyUpdater. - * - * @param pathFleetSid The fleet_sid - * @param pathSid A string that uniquely identifies the Key. - */ - public KeyUpdater(final String pathFleetSid, - final String pathSid) { - this.pathFleetSid = pathFleetSid; - this.pathSid = pathSid; - } - - /** - * Provides a human readable descriptive text for this Key credential, up to 256 - * characters long.. - * - * @param friendlyName The human readable description for this Key. - * @return this - */ - public KeyUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Provides the unique string identifier of an existing Device to become - * authenticated with this Key credential.. - * - * @param deviceSid The unique identifier of a Key to be authenticated. - * @return this - */ - public KeyUpdater setDeviceSid(final String deviceSid) { - this.deviceSid = deviceSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Key - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Key update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/DeployedDevices/Fleets/" + this.pathFleetSid + "/Keys/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Key update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Key.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (deviceSid != null) { - request.addPostParam("DeviceSid", deviceSid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocument.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocument.java index 228330d27f..1a8f6419c0 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocument.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocument.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; @@ -10,38 +17,66 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AuthorizationDocument extends Resource { - private static final long serialVersionUID = 156014201571905L; + + public static AuthorizationDocumentCreator creator( + final List hostedNumberOrderSids, + final String addressSid, + final String email, + final String contactTitle, + final String contactPhoneNumber + ) { + return new AuthorizationDocumentCreator( + hostedNumberOrderSids, + addressSid, + email, + contactTitle, + contactPhoneNumber + ); + } + + public static AuthorizationDocumentDeleter deleter(final String pathSid) { + return new AuthorizationDocumentDeleter(pathSid); + } + + public static AuthorizationDocumentFetcher fetcher(final String pathSid) { + return new AuthorizationDocumentFetcher(pathSid); + } + + public static AuthorizationDocumentReader reader() { + return new AuthorizationDocumentReader(); + } + + public static AuthorizationDocumentUpdater updater(final String pathSid) { + return new AuthorizationDocumentUpdater(pathSid); + } public enum Status { OPENED("opened"), @@ -56,15 +91,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -72,57 +103,16 @@ public static Status forValue(final String value) { } /** - * Create a AuthorizationDocumentFetcher to execute fetch. - * - * @param pathSid AuthorizationDocument sid. - * @return AuthorizationDocumentFetcher capable of executing the fetch - */ - public static AuthorizationDocumentFetcher fetcher(final String pathSid) { - return new AuthorizationDocumentFetcher(pathSid); - } - - /** - * Create a AuthorizationDocumentUpdater to execute update. - * - * @param pathSid The sid - * @return AuthorizationDocumentUpdater capable of executing the update - */ - public static AuthorizationDocumentUpdater updater(final String pathSid) { - return new AuthorizationDocumentUpdater(pathSid); - } - - /** - * Create a AuthorizationDocumentReader to execute read. - * - * @return AuthorizationDocumentReader capable of executing the read - */ - public static AuthorizationDocumentReader reader() { - return new AuthorizationDocumentReader(); - } - - /** - * Create a AuthorizationDocumentCreator to execute create. - * - * @param hostedNumberOrderSids A list of HostedNumberOrder sids. - * @param addressSid Address sid. - * @param email Email. - * @return AuthorizationDocumentCreator capable of executing the create - */ - public static AuthorizationDocumentCreator creator(final List hostedNumberOrderSids, - final String addressSid, - final String email) { - return new AuthorizationDocumentCreator(hostedNumberOrderSids, addressSid, email); - } - - /** - * Converts a JSON String into a AuthorizationDocument object using the provided - * ObjectMapper. - * + * Converts a JSON String into a AuthorizationDocument object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AuthorizationDocument object represented by the provided JSON */ - public static AuthorizationDocument fromJson(final String json, final ObjectMapper objectMapper) { + public static AuthorizationDocument fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizationDocument.class); @@ -134,14 +124,17 @@ public static AuthorizationDocument fromJson(final String json, final ObjectMapp } /** - * Converts a JSON InputStream into a AuthorizationDocument object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a AuthorizationDocument object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AuthorizationDocument object represented by the provided JSON */ - public static AuthorizationDocument fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AuthorizationDocument fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AuthorizationDocument.class); @@ -152,125 +145,76 @@ public static AuthorizationDocument fromJson(final InputStream json, final Objec } } - private final String sid; - private final String addressSid; - private final AuthorizationDocument.Status status; - private final String email; - private final List ccEmails; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private AuthorizationDocument(@JsonProperty("sid") - final String sid, - @JsonProperty("address_sid") - final String addressSid, - @JsonProperty("status") - final AuthorizationDocument.Status status, - @JsonProperty("email") - final String email, - @JsonProperty("cc_emails") - final List ccEmails, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.addressSid = addressSid; - this.status = status; - this.email = email; - this.ccEmails = ccEmails; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The AuthorizationDocument sid.. - * - * @return AuthorizationDocument sid. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String addressSid; - /** - * Returns The Address sid.. - * - * @return Address sid. - */ - public final String getAddressSid() { - return this.addressSid; - } + @Getter + private final List ccEmails; - /** - * Returns The The Status of this AuthorizationDocument.. - * - * @return The Status of this AuthorizationDocument. - */ - public final AuthorizationDocument.Status getStatus() { - return this.status; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The Email.. - * - * @return Email. - */ - public final String getEmail() { - return this.email; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A list of emails.. - * - * @return A list of emails. - */ - public final List getCcEmails() { - return this.ccEmails; - } + @Getter + private final String email; - /** - * Returns The The date this AuthorizationDocument was created.. - * - * @return The date this AuthorizationDocument was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Map links; - /** - * Returns The The date this AuthorizationDocument was updated.. - * - * @return The date this AuthorizationDocument was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String sid; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final AuthorizationDocument.Status status; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private AuthorizationDocument( + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final AuthorizationDocument.Status status, + @JsonProperty("url") final URI url + ) { + this.addressSid = addressSid; + this.ccEmails = ccEmails; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.links = links; + this.sid = sid; + this.status = status; + this.url = url; } @Override @@ -284,43 +228,31 @@ public boolean equals(final Object o) { } AuthorizationDocument other = (AuthorizationDocument) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(addressSid, other.addressSid) && - Objects.equals(status, other.status) && - Objects.equals(email, other.email) && - Objects.equals(ccEmails, other.ccEmails) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(addressSid, other.addressSid) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - addressSid, - status, - email, - ccEmails, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("addressSid", addressSid) - .add("status", status) - .add("email", email) - .add("ccEmails", ccEmails) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + addressSid, + ccEmails, + dateCreated, + dateUpdated, + email, + links, + sid, + status, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentCreator.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentCreator.java index c1472657d9..f2a01fe089 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentCreator.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,121 +28,200 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AuthorizationDocumentCreator extends Creator { - private final List hostedNumberOrderSids; - private final String addressSid; - private final String email; +public class AuthorizationDocumentCreator + extends Creator { + + private List hostedNumberOrderSids; + private String addressSid; + private String email; + private String contactTitle; + private String contactPhoneNumber; private List ccEmails; - /** - * Construct a new AuthorizationDocumentCreator. - * - * @param hostedNumberOrderSids A list of HostedNumberOrder sids. - * @param addressSid Address sid. - * @param email Email. - */ - public AuthorizationDocumentCreator(final List hostedNumberOrderSids, - final String addressSid, - final String email) { + public AuthorizationDocumentCreator( + final List hostedNumberOrderSids, + final String addressSid, + final String email, + final String contactTitle, + final String contactPhoneNumber + ) { this.hostedNumberOrderSids = hostedNumberOrderSids; this.addressSid = addressSid; this.email = email; + this.contactTitle = contactTitle; + this.contactPhoneNumber = contactPhoneNumber; + } + + public AuthorizationDocumentCreator setHostedNumberOrderSids( + final List hostedNumberOrderSids + ) { + this.hostedNumberOrderSids = hostedNumberOrderSids; + return this; } - /** - * Email recipients who will be informed when an Authorization Document has been - * sent and signed.. - * - * @param ccEmails A list of emails. - * @return this - */ - public AuthorizationDocumentCreator setCcEmails(final List ccEmails) { + public AuthorizationDocumentCreator setHostedNumberOrderSids( + final String hostedNumberOrderSids + ) { + return setHostedNumberOrderSids( + Promoter.listOfOne(hostedNumberOrderSids) + ); + } + + public AuthorizationDocumentCreator setAddressSid(final String addressSid) { + this.addressSid = addressSid; + return this; + } + + public AuthorizationDocumentCreator setEmail(final String email) { + this.email = email; + return this; + } + + public AuthorizationDocumentCreator setContactTitle( + final String contactTitle + ) { + this.contactTitle = contactTitle; + return this; + } + + public AuthorizationDocumentCreator setContactPhoneNumber( + final String contactPhoneNumber + ) { + this.contactPhoneNumber = contactPhoneNumber; + return this; + } + + public AuthorizationDocumentCreator setCcEmails( + final List ccEmails + ) { this.ccEmails = ccEmails; return this; } - /** - * Email recipients who will be informed when an Authorization Document has been - * sent and signed.. - * - * @param ccEmails A list of emails. - * @return this - */ public AuthorizationDocumentCreator setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created AuthorizationDocument - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AuthorizationDocument create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/AuthorizationDocuments"; + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/HostedNumbers/AuthorizationDocuments", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AuthorizationDocument creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return AuthorizationDocument.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public AuthorizationDocument create(final TwilioRestClient client) { + Response response = makeRequest(client); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthorizationDocument content = AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (hostedNumberOrderSids != null) { - for (String prop : hostedNumberOrderSids) { - request.addPostParam("HostedNumberOrderSids", prop); + for (String param : hostedNumberOrderSids) { + Serializer.toString( + request, + "HostedNumberOrderSids", + param, + ParameterType.URLENCODED + ); } } if (addressSid != null) { - request.addPostParam("AddressSid", addressSid); + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); } if (email != null) { - request.addPostParam("Email", email); + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + + if (contactTitle != null) { + Serializer.toString( + request, + "ContactTitle", + contactTitle, + ParameterType.URLENCODED + ); + } + + if (contactPhoneNumber != null) { + Serializer.toString( + request, + "ContactPhoneNumber", + contactPhoneNumber, + ParameterType.URLENCODED + ); } if (ccEmails != null) { - for (String prop : ccEmails) { - request.addPostParam("CcEmails", prop); + for (String param : ccEmails) { + Serializer.toString( + request, + "CcEmails", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentDeleter.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentDeleter.java new file mode 100644 index 0000000000..5971d49814 --- /dev/null +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentDeleter.java @@ -0,0 +1,98 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.preview.hostedNumbers; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class AuthorizationDocumentDeleter + extends Deleter { + + private String pathSid; + + public AuthorizationDocumentDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/AuthorizationDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.PREVIEW.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AuthorizationDocument delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentFetcher.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentFetcher.java index 279b39daa0..4008666361 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentFetcher.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,59 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AuthorizationDocumentFetcher extends Fetcher { - private final String pathSid; +public class AuthorizationDocumentFetcher + extends Fetcher { + + private String pathSid; - /** - * Construct a new AuthorizationDocumentFetcher. - * - * @param pathSid AuthorizationDocument sid. - */ public AuthorizationDocumentFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AuthorizationDocument - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AuthorizationDocument fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/AuthorizationDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/HostedNumbers/AuthorizationDocuments/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AuthorizationDocument fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return AuthorizationDocument.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public AuthorizationDocument fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthorizationDocument content = AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentReader.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentReader.java index 062e985bc5..308c6bd29d 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentReader.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; @@ -10,189 +17,212 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class AuthorizationDocumentReader extends Reader { + private String email; private AuthorizationDocument.Status status; + private Long pageSize; + + public AuthorizationDocumentReader() {} - /** - * Email that this AuthorizationDocument will be sent to for signing.. - * - * @param email Email. - * @return this - */ public AuthorizationDocumentReader setEmail(final String email) { this.email = email; return this; } - /** - * Status of an instance resource. It can hold one of the values: 1. opened 2. - * signing, 3. signed LOA, 4. canceled, 5. failed. See the section entitled - * [Status - * Values](https://www.twilio.com/docs/api/phone-numbers/hosted-number-authorization-documents#status-values) for more information on each of these statuses.. - * - * @param status The Status of this AuthorizationDocument. - * @return this - */ - public AuthorizationDocumentReader setStatus(final AuthorizationDocument.Status status) { + public AuthorizationDocumentReader setStatus( + final AuthorizationDocument.Status status + ) { this.status = status; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AuthorizationDocument ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AuthorizationDocumentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AuthorizationDocument ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + AuthorizationDocument.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/AuthorizationDocuments"; + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/HostedNumbers/AuthorizationDocuments", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AuthorizationDocument ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + AuthorizationDocument.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AuthorizationDocument read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "items", + response.getContent(), + AuthorizationDocument.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AuthorizationDocument Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AuthorizationDocument read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "items", - response.getContent(), - AuthorizationDocument.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (email != null) { - request.addQueryParam("Email", email); + Serializer.toString(request, "Email", email, ParameterType.QUERY); } if (status != null) { - request.addQueryParam("Status", status.toString()); + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentUpdater.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentUpdater.java index 84c7197ec2..ba75ac005f 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentUpdater.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/AuthorizationDocumentUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,181 +28,210 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AuthorizationDocumentUpdater extends Updater { - private final String pathSid; +public class AuthorizationDocumentUpdater + extends Updater { + + private String pathSid; private List hostedNumberOrderSids; private String addressSid; private String email; private List ccEmails; private AuthorizationDocument.Status status; + private String contactTitle; + private String contactPhoneNumber; - /** - * Construct a new AuthorizationDocumentUpdater. - * - * @param pathSid The sid - */ public AuthorizationDocumentUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * A list of HostedNumberOrder sids that this AuthorizationDocument will - * authorize for hosting phone number capabilities on Twilio's platform.. - * - * @param hostedNumberOrderSids A list of HostedNumberOrder sids. - * @return this - */ - public AuthorizationDocumentUpdater setHostedNumberOrderSids(final List hostedNumberOrderSids) { + public AuthorizationDocumentUpdater setHostedNumberOrderSids( + final List hostedNumberOrderSids + ) { this.hostedNumberOrderSids = hostedNumberOrderSids; return this; } - /** - * A list of HostedNumberOrder sids that this AuthorizationDocument will - * authorize for hosting phone number capabilities on Twilio's platform.. - * - * @param hostedNumberOrderSids A list of HostedNumberOrder sids. - * @return this - */ - public AuthorizationDocumentUpdater setHostedNumberOrderSids(final String hostedNumberOrderSids) { - return setHostedNumberOrderSids(Promoter.listOfOne(hostedNumberOrderSids)); + public AuthorizationDocumentUpdater setHostedNumberOrderSids( + final String hostedNumberOrderSids + ) { + return setHostedNumberOrderSids( + Promoter.listOfOne(hostedNumberOrderSids) + ); } - /** - * A 34 character string that uniquely identifies the Address resource that is - * associated with this AuthorizationDocument.. - * - * @param addressSid Address sid. - * @return this - */ public AuthorizationDocumentUpdater setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - /** - * Email that this AuthorizationDocument will be sent to for signing.. - * - * @param email Email. - * @return this - */ public AuthorizationDocumentUpdater setEmail(final String email) { this.email = email; return this; } - /** - * Email recipients who will be informed when an Authorization Document has been - * sent and signed. - * - * @param ccEmails A list of emails. - * @return this - */ - public AuthorizationDocumentUpdater setCcEmails(final List ccEmails) { + public AuthorizationDocumentUpdater setCcEmails( + final List ccEmails + ) { this.ccEmails = ccEmails; return this; } - /** - * Email recipients who will be informed when an Authorization Document has been - * sent and signed. - * - * @param ccEmails A list of emails. - * @return this - */ public AuthorizationDocumentUpdater setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } - /** - * Status of an instance resource. It can hold one of the values: 1. opened 2. - * signing, 3. signed LOA, 4. canceled, 5. failed. See the section entitled - * [Status - * Values](https://www.twilio.com/docs/api/phone-numbers/hosted-number-authorization-documents#status-values) for more information on each of these statuses.. - * - * @param status The Status of this AuthorizationDocument. - * @return this - */ - public AuthorizationDocumentUpdater setStatus(final AuthorizationDocument.Status status) { + public AuthorizationDocumentUpdater setStatus( + final AuthorizationDocument.Status status + ) { this.status = status; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated AuthorizationDocument - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AuthorizationDocument update(final TwilioRestClient client) { + public AuthorizationDocumentUpdater setContactTitle( + final String contactTitle + ) { + this.contactTitle = contactTitle; + return this; + } + + public AuthorizationDocumentUpdater setContactPhoneNumber( + final String contactPhoneNumber + ) { + this.contactPhoneNumber = contactPhoneNumber; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/AuthorizationDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/HostedNumbers/AuthorizationDocuments/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AuthorizationDocument update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AuthorizationDocument update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public AuthorizationDocument update(final TwilioRestClient client) { + Response response = makeRequest(client); + return AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return AuthorizationDocument.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AuthorizationDocument content = AuthorizationDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (hostedNumberOrderSids != null) { - for (String prop : hostedNumberOrderSids) { - request.addPostParam("HostedNumberOrderSids", prop); + for (String param : hostedNumberOrderSids) { + Serializer.toString( + request, + "HostedNumberOrderSids", + param, + ParameterType.URLENCODED + ); } } if (addressSid != null) { - request.addPostParam("AddressSid", addressSid); + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); } if (email != null) { - request.addPostParam("Email", email); + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); } if (ccEmails != null) { - for (String prop : ccEmails) { - request.addPostParam("CcEmails", prop); + for (String param : ccEmails) { + Serializer.toString( + request, + "CcEmails", + param, + ParameterType.URLENCODED + ); } } if (status != null) { - request.addPostParam("Status", status.toString()); + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (contactTitle != null) { + Serializer.toString( + request, + "ContactTitle", + contactTitle, + ParameterType.URLENCODED + ); + } + + if (contactPhoneNumber != null) { + Serializer.toString( + request, + "ContactPhoneNumber", + contactPhoneNumber, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrder.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrder.java index f32b6303a9..9294391559 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrder.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrder.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; @@ -10,41 +17,60 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class HostedNumberOrder extends Resource { - private static final long serialVersionUID = 200143237925863L; + + public static HostedNumberOrderCreator creator( + final com.twilio.type.PhoneNumber phoneNumber, + final Boolean smsCapability + ) { + return new HostedNumberOrderCreator(phoneNumber, smsCapability); + } + + public static HostedNumberOrderDeleter deleter(final String pathSid) { + return new HostedNumberOrderDeleter(pathSid); + } + + public static HostedNumberOrderFetcher fetcher(final String pathSid) { + return new HostedNumberOrderFetcher(pathSid); + } + + public static HostedNumberOrderReader reader() { + return new HostedNumberOrderReader(); + } + + public static HostedNumberOrderUpdater updater(final String pathSid) { + return new HostedNumberOrderUpdater(pathSid); + } public enum Status { + TWILIO_PROCESSING("twilio-processing"), RECEIVED("received"), PENDING_VERIFICATION("pending-verification"), VERIFIED("verified"), @@ -61,15 +87,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -86,15 +108,11 @@ private VerificationType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a VerificationType from a string. - * @param value string value - * @return generated VerificationType - */ @JsonCreator public static VerificationType forValue(final String value) { return Promoter.enumFromString(value, VerificationType.values()); @@ -102,65 +120,16 @@ public static VerificationType forValue(final String value) { } /** - * Create a HostedNumberOrderFetcher to execute fetch. - * - * @param pathSid HostedNumberOrder sid. - * @return HostedNumberOrderFetcher capable of executing the fetch - */ - public static HostedNumberOrderFetcher fetcher(final String pathSid) { - return new HostedNumberOrderFetcher(pathSid); - } - - /** - * Create a HostedNumberOrderDeleter to execute delete. - * - * @param pathSid HostedNumberOrder sid. - * @return HostedNumberOrderDeleter capable of executing the delete - */ - public static HostedNumberOrderDeleter deleter(final String pathSid) { - return new HostedNumberOrderDeleter(pathSid); - } - - /** - * Create a HostedNumberOrderUpdater to execute update. - * - * @param pathSid The sid - * @return HostedNumberOrderUpdater capable of executing the update - */ - public static HostedNumberOrderUpdater updater(final String pathSid) { - return new HostedNumberOrderUpdater(pathSid); - } - - /** - * Create a HostedNumberOrderReader to execute read. - * - * @return HostedNumberOrderReader capable of executing the read - */ - public static HostedNumberOrderReader reader() { - return new HostedNumberOrderReader(); - } - - /** - * Create a HostedNumberOrderCreator to execute create. - * - * @param phoneNumber An E164 formatted phone number. - * @param smsCapability Specify SMS capability to host. - * @return HostedNumberOrderCreator capable of executing the create - */ - public static HostedNumberOrderCreator creator(final com.twilio.type.PhoneNumber phoneNumber, - final Boolean smsCapability) { - return new HostedNumberOrderCreator(phoneNumber, smsCapability); - } - - /** - * Converts a JSON String into a HostedNumberOrder object using the provided - * ObjectMapper. - * + * Converts a JSON String into a HostedNumberOrder object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return HostedNumberOrder object represented by the provided JSON */ - public static HostedNumberOrder fromJson(final String json, final ObjectMapper objectMapper) { + public static HostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, HostedNumberOrder.class); @@ -172,14 +141,17 @@ public static HostedNumberOrder fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a HostedNumberOrder object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a HostedNumberOrder object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return HostedNumberOrder object represented by the provided JSON */ - public static HostedNumberOrder fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static HostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, HostedNumberOrder.class); @@ -190,309 +162,160 @@ public static HostedNumberOrder fromJson(final InputStream json, final ObjectMap } } - private final String sid; - private final String accountSid; - private final String incomingPhoneNumberSid; - private final String addressSid; - private final String signingDocumentSid; - private final com.twilio.type.PhoneNumber phoneNumber; - private final PhoneNumberCapabilities capabilities; - private final String friendlyName; - private final String uniqueName; - private final HostedNumberOrder.Status status; - private final String failureReason; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final Integer verificationAttempts; - private final String email; - private final List ccEmails; - private final URI url; - private final HostedNumberOrder.VerificationType verificationType; - private final String verificationDocumentSid; - private final String extension; - private final Integer callDelay; - private final String verificationCode; - private final List verificationCallSids; - - @JsonCreator - private HostedNumberOrder(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("incoming_phone_number_sid") - final String incomingPhoneNumberSid, - @JsonProperty("address_sid") - final String addressSid, - @JsonProperty("signing_document_sid") - final String signingDocumentSid, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("status") - final HostedNumberOrder.Status status, - @JsonProperty("failure_reason") - final String failureReason, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("verification_attempts") - final Integer verificationAttempts, - @JsonProperty("email") - final String email, - @JsonProperty("cc_emails") - final List ccEmails, - @JsonProperty("url") - final URI url, - @JsonProperty("verification_type") - final HostedNumberOrder.VerificationType verificationType, - @JsonProperty("verification_document_sid") - final String verificationDocumentSid, - @JsonProperty("extension") - final String extension, - @JsonProperty("call_delay") - final Integer callDelay, - @JsonProperty("verification_code") - final String verificationCode, - @JsonProperty("verification_call_sids") - final List verificationCallSids) { - this.sid = sid; - this.accountSid = accountSid; - this.incomingPhoneNumberSid = incomingPhoneNumberSid; - this.addressSid = addressSid; - this.signingDocumentSid = signingDocumentSid; - this.phoneNumber = phoneNumber; - this.capabilities = capabilities; - this.friendlyName = friendlyName; - this.uniqueName = uniqueName; - this.status = status; - this.failureReason = failureReason; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.verificationAttempts = verificationAttempts; - this.email = email; - this.ccEmails = ccEmails; - this.url = url; - this.verificationType = verificationType; - this.verificationDocumentSid = verificationDocumentSid; - this.extension = extension; - this.callDelay = callDelay; - this.verificationCode = verificationCode; - this.verificationCallSids = verificationCallSids; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The HostedNumberOrder sid.. - * - * @return HostedNumberOrder sid. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String addressSid; - /** - * Returns The IncomingPhoneNumber sid.. - * - * @return IncomingPhoneNumber sid. - */ - public final String getIncomingPhoneNumberSid() { - return this.incomingPhoneNumberSid; - } + @Getter + private final Integer callDelay; - /** - * Returns The Address sid.. - * - * @return Address sid. - */ - public final String getAddressSid() { - return this.addressSid; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The LOA document sid.. - * - * @return LOA document sid. - */ - public final String getSigningDocumentSid() { - return this.signingDocumentSid; - } + @Getter + private final List ccEmails; - /** - * Returns The An E164 formatted phone number.. - * - * @return An E164 formatted phone number. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The A mapping of phone number capabilities.. - * - * @return A mapping of phone number capabilities. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A human readable description of this resource.. - * - * @return A human readable description of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String email; - /** - * Returns The A unique, developer assigned name of this HostedNumberOrder.. - * - * @return A unique, developer assigned name of this HostedNumberOrder. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String extension; - /** - * Returns The The Status of this HostedNumberOrder.. - * - * @return The Status of this HostedNumberOrder. - */ - public final HostedNumberOrder.Status getStatus() { - return this.status; - } + @Getter + private final String failureReason; - /** - * Returns The Why a hosted_number_order reached status "action-required". - * - * @return Why a hosted_number_order reached status "action-required" - */ - public final String getFailureReason() { - return this.failureReason; - } + @Getter + private final String friendlyName; - /** - * Returns The The date this HostedNumberOrder was created.. - * - * @return The date this HostedNumberOrder was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String incomingPhoneNumberSid; - /** - * Returns The The date this HostedNumberOrder was updated.. - * - * @return The date this HostedNumberOrder was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The number of attempts made to verify ownership of the phone - * number.. - * - * @return The number of attempts made to verify ownership of the phone number. - */ - public final Integer getVerificationAttempts() { - return this.verificationAttempts; - } + @Getter + private final String sid; - /** - * Returns The Email.. - * - * @return Email. - */ - public final String getEmail() { - return this.email; - } + @Getter + private final String signingDocumentSid; - /** - * Returns The A list of emails.. - * - * @return A list of emails. - */ - public final List getCcEmails() { - return this.ccEmails; - } + @Getter + private final HostedNumberOrder.Status status; - /** - * Returns The The URL of this HostedNumberOrder.. - * - * @return The URL of this HostedNumberOrder. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String uniqueName; - /** - * Returns The The method used for verifying ownership of the number to be - * hosted.. - * - * @return The method used for verifying ownership of the number to be hosted. - */ - public final HostedNumberOrder.VerificationType getVerificationType() { - return this.verificationType; - } + @Getter + private final URI url; - /** - * Returns The Verification Document Sid.. - * - * @return Verification Document Sid. - */ - public final String getVerificationDocumentSid() { - return this.verificationDocumentSid; - } + @Getter + private final Integer verificationAttempts; - /** - * Returns The Phone extension to use for ownership verification call.. - * - * @return Phone extension to use for ownership verification call. - */ - public final String getExtension() { - return this.extension; - } + @Getter + private final List verificationCallSids; - /** - * Returns The Seconds (0-30) to delay ownership verification call by.. - * - * @return Seconds (0-30) to delay ownership verification call by. - */ - public final Integer getCallDelay() { - return this.callDelay; - } + @Getter + private final String verificationCode; - /** - * Returns The The digits passed during the ownership verification call.. - * - * @return The digits passed during the ownership verification call. - */ - public final String getVerificationCode() { - return this.verificationCode; - } + @Getter + private final String verificationDocumentSid; - /** - * Returns The List of IDs for ownership verification calls.. - * - * @return List of IDs for ownership verification calls. - */ - public final List getVerificationCallSids() { - return this.verificationCallSids; + @Getter + private final HostedNumberOrder.VerificationType verificationType; + + @JsonCreator + private HostedNumberOrder( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("call_delay") final Integer callDelay, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("extension") final String extension, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "incoming_phone_number_sid" + ) final String incomingPhoneNumberSid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("signing_document_sid") final String signingDocumentSid, + @JsonProperty("status") final HostedNumberOrder.Status status, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty( + "verification_attempts" + ) final Integer verificationAttempts, + @JsonProperty("verification_call_sids") final List< + String + > verificationCallSids, + @JsonProperty("verification_code") final String verificationCode, + @JsonProperty( + "verification_document_sid" + ) final String verificationDocumentSid, + @JsonProperty( + "verification_type" + ) final HostedNumberOrder.VerificationType verificationType + ) { + this.accountSid = accountSid; + this.addressSid = addressSid; + this.callDelay = callDelay; + this.capabilities = capabilities; + this.ccEmails = ccEmails; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.extension = extension; + this.failureReason = failureReason; + this.friendlyName = friendlyName; + this.incomingPhoneNumberSid = incomingPhoneNumberSid; + this.phoneNumber = phoneNumber; + this.sid = sid; + this.signingDocumentSid = signingDocumentSid; + this.status = status; + this.uniqueName = uniqueName; + this.url = url; + this.verificationAttempts = verificationAttempts; + this.verificationCallSids = verificationCallSids; + this.verificationCode = verificationCode; + this.verificationDocumentSid = verificationDocumentSid; + this.verificationType = verificationType; } @Override @@ -506,85 +329,65 @@ public boolean equals(final Object o) { } HostedNumberOrder other = (HostedNumberOrder) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(incomingPhoneNumberSid, other.incomingPhoneNumberSid) && - Objects.equals(addressSid, other.addressSid) && - Objects.equals(signingDocumentSid, other.signingDocumentSid) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(status, other.status) && - Objects.equals(failureReason, other.failureReason) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(verificationAttempts, other.verificationAttempts) && - Objects.equals(email, other.email) && - Objects.equals(ccEmails, other.ccEmails) && - Objects.equals(url, other.url) && - Objects.equals(verificationType, other.verificationType) && - Objects.equals(verificationDocumentSid, other.verificationDocumentSid) && - Objects.equals(extension, other.extension) && - Objects.equals(callDelay, other.callDelay) && - Objects.equals(verificationCode, other.verificationCode) && - Objects.equals(verificationCallSids, other.verificationCallSids); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(callDelay, other.callDelay) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(extension, other.extension) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + incomingPhoneNumberSid, + other.incomingPhoneNumberSid + ) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(signingDocumentSid, other.signingDocumentSid) && + Objects.equals(status, other.status) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(verificationAttempts, other.verificationAttempts) && + Objects.equals(verificationCallSids, other.verificationCallSids) && + Objects.equals(verificationCode, other.verificationCode) && + Objects.equals( + verificationDocumentSid, + other.verificationDocumentSid + ) && + Objects.equals(verificationType, other.verificationType) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - incomingPhoneNumberSid, - addressSid, - signingDocumentSid, - phoneNumber, - capabilities, - friendlyName, - uniqueName, - status, - failureReason, - dateCreated, - dateUpdated, - verificationAttempts, - email, - ccEmails, - url, - verificationType, - verificationDocumentSid, - extension, - callDelay, - verificationCode, - verificationCallSids); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("incomingPhoneNumberSid", incomingPhoneNumberSid) - .add("addressSid", addressSid) - .add("signingDocumentSid", signingDocumentSid) - .add("phoneNumber", phoneNumber) - .add("capabilities", capabilities) - .add("friendlyName", friendlyName) - .add("uniqueName", uniqueName) - .add("status", status) - .add("failureReason", failureReason) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("verificationAttempts", verificationAttempts) - .add("email", email) - .add("ccEmails", ccEmails) - .add("url", url) - .add("verificationType", verificationType) - .add("verificationDocumentSid", verificationDocumentSid) - .add("extension", extension) - .add("callDelay", callDelay) - .add("verificationCode", verificationCode) - .add("verificationCallSids", verificationCallSids) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + addressSid, + callDelay, + capabilities, + ccEmails, + dateCreated, + dateUpdated, + email, + extension, + failureReason, + friendlyName, + incomingPhoneNumberSid, + phoneNumber, + sid, + signingDocumentSid, + status, + uniqueName, + url, + verificationAttempts, + verificationCallSids, + verificationCode, + verificationDocumentSid, + verificationType + ); + } +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderCreator.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderCreator.java index cb04d360ba..39d2241d99 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderCreator.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,18 +28,15 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class HostedNumberOrderCreator extends Creator { - private final com.twilio.type.PhoneNumber phoneNumber; - private final Boolean smsCapability; + + private com.twilio.type.PhoneNumber phoneNumber; + private Boolean smsCapability; private String accountSid; private String friendlyName; private String uniqueName; @@ -45,361 +53,354 @@ public class HostedNumberOrderCreator extends Creator { private HostedNumberOrder.VerificationType verificationType; private String verificationDocumentSid; - /** - * Construct a new HostedNumberOrderCreator. - * - * @param phoneNumber An E164 formatted phone number. - * @param smsCapability Specify SMS capability to host. - */ - public HostedNumberOrderCreator(final com.twilio.type.PhoneNumber phoneNumber, - final Boolean smsCapability) { + public HostedNumberOrderCreator( + final com.twilio.type.PhoneNumber phoneNumber, + final Boolean smsCapability + ) { + this.phoneNumber = phoneNumber; + this.smsCapability = smsCapability; + } + + public HostedNumberOrderCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; + return this; + } + + public HostedNumberOrderCreator setPhoneNumber(final String phoneNumber) { + return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); + } + + public HostedNumberOrderCreator setSmsCapability( + final Boolean smsCapability + ) { this.smsCapability = smsCapability; + return this; } - /** - * This defaults to the AccountSid of the authorization the user is using. This - * can be provided to specify a subaccount to add the HostedNumberOrder to.. - * - * @param accountSid Account Sid. - * @return this - */ public HostedNumberOrderCreator setAccountSid(final String accountSid) { this.accountSid = accountSid; return this; } - /** - * A 64 character string that is a human readable text that describes this - * resource.. - * - * @param friendlyName A human readable description of this resource. - * @return this - */ public HostedNumberOrderCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Optional. Provides a unique and addressable name to be assigned to this - * HostedNumberOrder, assigned by the developer, to be optionally used in - * addition to SID.. - * - * @param uniqueName A unique, developer assigned name of this - * HostedNumberOrder. - * @return this - */ public HostedNumberOrderCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * Optional. A list of emails that the LOA document for this HostedNumberOrder - * will be carbon copied to.. - * - * @param ccEmails A list of emails. - * @return this - */ public HostedNumberOrderCreator setCcEmails(final List ccEmails) { this.ccEmails = ccEmails; return this; } - /** - * Optional. A list of emails that the LOA document for this HostedNumberOrder - * will be carbon copied to.. - * - * @param ccEmails A list of emails. - * @return this - */ public HostedNumberOrderCreator setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } - /** - * The URL that Twilio should request when somebody sends an SMS to the phone - * number. This will be copied onto the IncomingPhoneNumber resource.. - * - * @param smsUrl SMS URL. - * @return this - */ public HostedNumberOrderCreator setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The URL that Twilio should request when somebody sends an SMS to the phone - * number. This will be copied onto the IncomingPhoneNumber resource.. - * - * @param smsUrl SMS URL. - * @return this - */ public HostedNumberOrderCreator setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The HTTP method that should be used to request the SmsUrl. Must be either - * `GET` or `POST`. This will be copied onto the IncomingPhoneNumber resource.. - * - * @param smsMethod SMS Method. - * @return this - */ public HostedNumberOrderCreator setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by SmsUrl. This will be copied onto the IncomingPhoneNumber - * resource.. - * - * @param smsFallbackUrl SMS Fallback URL. - * @return this - */ - public HostedNumberOrderCreator setSmsFallbackUrl(final URI smsFallbackUrl) { + public HostedNumberOrderCreator setSmsFallbackUrl( + final URI smsFallbackUrl + ) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * A URL that Twilio will request if an error occurs requesting or executing the - * TwiML defined by SmsUrl. This will be copied onto the IncomingPhoneNumber - * resource.. - * - * @param smsFallbackUrl SMS Fallback URL. - * @return this - */ - public HostedNumberOrderCreator setSmsFallbackUrl(final String smsFallbackUrl) { + public HostedNumberOrderCreator setSmsFallbackUrl( + final String smsFallbackUrl + ) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The HTTP method that should be used to request the SmsFallbackUrl. Must be - * either `GET` or `POST`. This will be copied onto the IncomingPhoneNumber - * resource.. - * - * @param smsFallbackMethod SMS Fallback Method. - * @return this - */ - public HostedNumberOrderCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { + public HostedNumberOrderCreator setSmsFallbackMethod( + final HttpMethod smsFallbackMethod + ) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * Optional. The Status Callback URL attached to the IncomingPhoneNumber - * resource.. - * - * @param statusCallbackUrl Status Callback URL. - * @return this - */ - public HostedNumberOrderCreator setStatusCallbackUrl(final URI statusCallbackUrl) { + public HostedNumberOrderCreator setStatusCallbackUrl( + final URI statusCallbackUrl + ) { this.statusCallbackUrl = statusCallbackUrl; return this; } - /** - * Optional. The Status Callback URL attached to the IncomingPhoneNumber - * resource.. - * - * @param statusCallbackUrl Status Callback URL. - * @return this - */ - public HostedNumberOrderCreator setStatusCallbackUrl(final String statusCallbackUrl) { + public HostedNumberOrderCreator setStatusCallbackUrl( + final String statusCallbackUrl + ) { return setStatusCallbackUrl(Promoter.uriFromString(statusCallbackUrl)); } - /** - * Optional. The Status Callback Method attached to the IncomingPhoneNumber - * resource.. - * - * @param statusCallbackMethod Status Callback Method. - * @return this - */ - public HostedNumberOrderCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public HostedNumberOrderCreator setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * Optional. The 34 character sid of the application Twilio should use to handle - * SMS messages sent to this number. If a `SmsApplicationSid` is present, Twilio - * will ignore all of the SMS urls above and use those set on the application.. - * - * @param smsApplicationSid SMS Application Sid. - * @return this - */ - public HostedNumberOrderCreator setSmsApplicationSid(final String smsApplicationSid) { + public HostedNumberOrderCreator setSmsApplicationSid( + final String smsApplicationSid + ) { this.smsApplicationSid = smsApplicationSid; return this; } - /** - * Optional. A 34 character string that uniquely identifies the Address resource - * that represents the address of the owner of this phone number.. - * - * @param addressSid Address sid. - * @return this - */ public HostedNumberOrderCreator setAddressSid(final String addressSid) { this.addressSid = addressSid; return this; } - /** - * Optional. Email of the owner of this phone number that is being hosted.. - * - * @param email Email. - * @return this - */ public HostedNumberOrderCreator setEmail(final String email) { this.email = email; return this; } - /** - * Optional. The method used for verifying ownership of the number to be hosted. - * One of phone-call (default) or phone-bill.. - * - * @param verificationType Verification Type. - * @return this - */ - public HostedNumberOrderCreator setVerificationType(final HostedNumberOrder.VerificationType verificationType) { + public HostedNumberOrderCreator setVerificationType( + final HostedNumberOrder.VerificationType verificationType + ) { this.verificationType = verificationType; return this; } - /** - * Optional. The unique sid identifier of the Identity Document that represents - * the document for verifying ownership of the number to be hosted. Required - * when VerificationType is phone-bill.. - * - * @param verificationDocumentSid Verification Document Sid - * @return this - */ - public HostedNumberOrderCreator setVerificationDocumentSid(final String verificationDocumentSid) { + public HostedNumberOrderCreator setVerificationDocumentSid( + final String verificationDocumentSid + ) { this.verificationDocumentSid = verificationDocumentSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created HostedNumberOrder - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public HostedNumberOrder create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/HostedNumberOrders"; + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/HostedNumbers/HostedNumberOrders", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "HostedNumberOrder creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return HostedNumberOrder.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public HostedNumberOrder create(final TwilioRestClient client) { + Response response = makeRequest(client); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + HostedNumberOrder content = HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (phoneNumber != null) { - request.addPostParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); } if (smsCapability != null) { - request.addPostParam("SmsCapability", smsCapability.toString()); + Serializer.toString( + request, + "SmsCapability", + smsCapability, + ParameterType.URLENCODED + ); } if (accountSid != null) { - request.addPostParam("AccountSid", accountSid); + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (ccEmails != null) { - for (String prop : ccEmails) { - request.addPostParam("CcEmails", prop); + for (String param : ccEmails) { + Serializer.toString( + request, + "CcEmails", + param, + ParameterType.URLENCODED + ); } } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallbackUrl != null) { - request.addPostParam("StatusCallbackUrl", statusCallbackUrl.toString()); + Serializer.toString( + request, + "StatusCallbackUrl", + statusCallbackUrl, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (smsApplicationSid != null) { - request.addPostParam("SmsApplicationSid", smsApplicationSid); + Serializer.toString( + request, + "SmsApplicationSid", + smsApplicationSid, + ParameterType.URLENCODED + ); } if (addressSid != null) { - request.addPostParam("AddressSid", addressSid); + Serializer.toString( + request, + "AddressSid", + addressSid, + ParameterType.URLENCODED + ); } if (email != null) { - request.addPostParam("Email", email); + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); } if (verificationType != null) { - request.addPostParam("VerificationType", verificationType.toString()); + Serializer.toString( + request, + "VerificationType", + verificationType, + ParameterType.URLENCODED + ); } if (verificationDocumentSid != null) { - request.addPostParam("VerificationDocumentSid", verificationDocumentSid); + Serializer.toString( + request, + "VerificationDocumentSid", + verificationDocumentSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderDeleter.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderDeleter.java index 76ff604d6d..cf46539fe6 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderDeleter.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class HostedNumberOrderDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new HostedNumberOrderDeleter. - * - * @param pathSid HostedNumberOrder sid. - */ + private String pathSid; + public HostedNumberOrderDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/HostedNumberOrders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.PREVIEW.toString(), - "/HostedNumbers/HostedNumberOrders/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "HostedNumberOrder delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderFetcher.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderFetcher.java index 043c2e9256..b450dcfc09 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderFetcher.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,59 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class HostedNumberOrderFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new HostedNumberOrderFetcher. - * - * @param pathSid HostedNumberOrder sid. - */ + private String pathSid; + public HostedNumberOrderFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched HostedNumberOrder - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public HostedNumberOrder fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/HostedNumberOrders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/HostedNumbers/HostedNumberOrders/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "HostedNumberOrder fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return HostedNumberOrder.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public HostedNumberOrder fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + HostedNumberOrder content = HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderReader.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderReader.java index a19b954db0..42d14751fc 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderReader.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; @@ -10,251 +17,267 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class HostedNumberOrderReader extends Reader { + private HostedNumberOrder.Status status; private com.twilio.type.PhoneNumber phoneNumber; private String incomingPhoneNumberSid; private String friendlyName; private String uniqueName; + private Long pageSize; + + public HostedNumberOrderReader() {} - /** - * The Status of this HostedNumberOrder. One of `received`, - * `pending-verification`, `verified`, `pending-loa`, `carrier-processing`, - * `testing`, `completed`, `failed`, or `action-required`.. - * - * @param status The Status of this HostedNumberOrder. - * @return this - */ - public HostedNumberOrderReader setStatus(final HostedNumberOrder.Status status) { + public HostedNumberOrderReader setStatus( + final HostedNumberOrder.Status status + ) { this.status = status; return this; } - /** - * An E164 formatted phone number hosted by this HostedNumberOrder.. - * - * @param phoneNumber An E164 formatted phone number. - * @return this - */ - public HostedNumberOrderReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public HostedNumberOrderReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * An E164 formatted phone number hosted by this HostedNumberOrder.. - * - * @param phoneNumber An E164 formatted phone number. - * @return this - */ public HostedNumberOrderReader setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * A 34 character string that uniquely identifies the IncomingPhoneNumber - * resource created by this HostedNumberOrder.. - * - * @param incomingPhoneNumberSid IncomingPhoneNumber sid. - * @return this - */ - public HostedNumberOrderReader setIncomingPhoneNumberSid(final String incomingPhoneNumberSid) { + public HostedNumberOrderReader setIncomingPhoneNumberSid( + final String incomingPhoneNumberSid + ) { this.incomingPhoneNumberSid = incomingPhoneNumberSid; return this; } - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param friendlyName A human readable description of this resource. - * @return this - */ public HostedNumberOrderReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Provides a unique and addressable name to be assigned to this - * HostedNumberOrder, assigned by the developer, to be optionally used in - * addition to SID.. - * - * @param uniqueName A unique, developer assigned name of this - * HostedNumberOrder. - * @return this - */ public HostedNumberOrderReader setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return HostedNumberOrder ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public HostedNumberOrderReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return HostedNumberOrder ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + HostedNumberOrder.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/HostedNumberOrders"; + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/HostedNumbers/HostedNumberOrders", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return HostedNumberOrder ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + HostedNumberOrder.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "HostedNumberOrder read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "items", + response.getContent(), + HostedNumberOrder.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of HostedNumberOrder Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("HostedNumberOrder read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "items", - response.getContent(), - HostedNumberOrder.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); + Serializer.toString(request, "Status", status, ParameterType.QUERY); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); } if (incomingPhoneNumberSid != null) { - request.addQueryParam("IncomingPhoneNumberSid", incomingPhoneNumberSid); + Serializer.toString( + request, + "IncomingPhoneNumberSid", + incomingPhoneNumberSid, + ParameterType.QUERY + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (uniqueName != null) { - request.addQueryParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderUpdater.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderUpdater.java index 207891313d..6d52f9318b 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderUpdater.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/HostedNumberOrderUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,16 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class HostedNumberOrderUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String uniqueName; private String email; @@ -38,234 +46,224 @@ public class HostedNumberOrderUpdater extends Updater { private String extension; private Integer callDelay; - /** - * Construct a new HostedNumberOrderUpdater. - * - * @param pathSid The sid - */ public HostedNumberOrderUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * A 64 character string that is a human readable text that describes this - * resource.. - * - * @param friendlyName A human readable description of this resource. - * @return this - */ public HostedNumberOrderUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Provides a unique and addressable name to be assigned to this - * HostedNumberOrder, assigned by the developer, to be optionally used in - * addition to SID.. - * - * @param uniqueName A unique, developer assigned name of this - * HostedNumberOrder. - * @return this - */ public HostedNumberOrderUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * Email of the owner of this phone number that is being hosted.. - * - * @param email Email. - * @return this - */ public HostedNumberOrderUpdater setEmail(final String email) { this.email = email; return this; } - /** - * Optional. A list of emails that LOA document for this HostedNumberOrder will - * be carbon copied to.. - * - * @param ccEmails A list of emails. - * @return this - */ public HostedNumberOrderUpdater setCcEmails(final List ccEmails) { this.ccEmails = ccEmails; return this; } - /** - * Optional. A list of emails that LOA document for this HostedNumberOrder will - * be carbon copied to.. - * - * @param ccEmails A list of emails. - * @return this - */ public HostedNumberOrderUpdater setCcEmails(final String ccEmails) { return setCcEmails(Promoter.listOfOne(ccEmails)); } - /** - * User can only post to `pending-verification` status to transition the - * HostedNumberOrder to initiate a verification call or verification of - * ownership with a copy of a phone bill.. - * - * @param status The Status of this HostedNumberOrder. - * @return this - */ - public HostedNumberOrderUpdater setStatus(final HostedNumberOrder.Status status) { + public HostedNumberOrderUpdater setStatus( + final HostedNumberOrder.Status status + ) { this.status = status; return this; } - /** - * A verification code that is given to the user via a phone call to the phone - * number that is being hosted.. - * - * @param verificationCode A verification code. - * @return this - */ - public HostedNumberOrderUpdater setVerificationCode(final String verificationCode) { + public HostedNumberOrderUpdater setVerificationCode( + final String verificationCode + ) { this.verificationCode = verificationCode; return this; } - /** - * Optional. The method used for verifying ownership of the number to be hosted. - * One of phone-call (default) or phone-bill.. - * - * @param verificationType Verification Type. - * @return this - */ - public HostedNumberOrderUpdater setVerificationType(final HostedNumberOrder.VerificationType verificationType) { + public HostedNumberOrderUpdater setVerificationType( + final HostedNumberOrder.VerificationType verificationType + ) { this.verificationType = verificationType; return this; } - /** - * Optional. The unique sid identifier of the Identity Document that represents - * the document for verifying ownership of the number to be hosted. Required - * when VerificationType is phone-bill.. - * - * @param verificationDocumentSid Verification Document Sid - * @return this - */ - public HostedNumberOrderUpdater setVerificationDocumentSid(final String verificationDocumentSid) { + public HostedNumberOrderUpdater setVerificationDocumentSid( + final String verificationDocumentSid + ) { this.verificationDocumentSid = verificationDocumentSid; return this; } - /** - * Digits to dial after connecting the verification call.. - * - * @param extension Digits to dial after connecting the verification call. - * @return this - */ public HostedNumberOrderUpdater setExtension(final String extension) { this.extension = extension; return this; } - /** - * The number of seconds, between 0 and 60, to delay before initiating the - * verification call. Defaults to 0.. - * - * @param callDelay The number of seconds, between 0 and 60, to delay before - * initiating the verification call. - * @return this - */ public HostedNumberOrderUpdater setCallDelay(final Integer callDelay) { this.callDelay = callDelay; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated HostedNumberOrder - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public HostedNumberOrder update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/HostedNumbers/HostedNumberOrders/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/HostedNumbers/HostedNumberOrders/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("HostedNumberOrder update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "HostedNumberOrder update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return HostedNumberOrder.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public HostedNumberOrder update(final TwilioRestClient client) { + Response response = makeRequest(client); + return HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + HostedNumberOrder content = HostedNumberOrder.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (email != null) { - request.addPostParam("Email", email); + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); } if (ccEmails != null) { - for (String prop : ccEmails) { - request.addPostParam("CcEmails", prop); + for (String param : ccEmails) { + Serializer.toString( + request, + "CcEmails", + param, + ParameterType.URLENCODED + ); } } if (status != null) { - request.addPostParam("Status", status.toString()); + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); } if (verificationCode != null) { - request.addPostParam("VerificationCode", verificationCode); + Serializer.toString( + request, + "VerificationCode", + verificationCode, + ParameterType.URLENCODED + ); } if (verificationType != null) { - request.addPostParam("VerificationType", verificationType.toString()); + Serializer.toString( + request, + "VerificationType", + verificationType, + ParameterType.URLENCODED + ); } if (verificationDocumentSid != null) { - request.addPostParam("VerificationDocumentSid", verificationDocumentSid); + Serializer.toString( + request, + "VerificationDocumentSid", + verificationDocumentSid, + ParameterType.URLENCODED + ); } if (extension != null) { - request.addPostParam("Extension", extension); + Serializer.toString( + request, + "Extension", + extension, + ParameterType.URLENCODED + ); } if (callDelay != null) { - request.addPostParam("CallDelay", callDelay.toString()); + Serializer.toString( + request, + "CallDelay", + callDelay, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrder.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrder.java index a17462bad4..a1dd854319 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrder.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrder.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers.authorizationdocument; @@ -10,40 +17,42 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class DependentHostedNumberOrder extends Resource { - private static final long serialVersionUID = 20864169614063L; + + public static DependentHostedNumberOrderReader reader( + final String pathSigningDocumentSid + ) { + return new DependentHostedNumberOrderReader(pathSigningDocumentSid); + } public enum Status { + TWILIO_PROCESSING("twilio-processing"), RECEIVED("received"), PENDING_VERIFICATION("pending-verification"), VERIFIED("verified"), @@ -60,15 +69,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -85,15 +90,11 @@ private VerificationType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a VerificationType from a string. - * @param value string value - * @return generated VerificationType - */ @JsonCreator public static VerificationType forValue(final String value) { return Promoter.enumFromString(value, VerificationType.values()); @@ -101,27 +102,22 @@ public static VerificationType forValue(final String value) { } /** - * Create a DependentHostedNumberOrderReader to execute read. - * - * @param pathSigningDocumentSid The signing_document_sid - * @return DependentHostedNumberOrderReader capable of executing the read - */ - public static DependentHostedNumberOrderReader reader(final String pathSigningDocumentSid) { - return new DependentHostedNumberOrderReader(pathSigningDocumentSid); - } - - /** - * Converts a JSON String into a DependentHostedNumberOrder object using the - * provided ObjectMapper. - * + * Converts a JSON String into a DependentHostedNumberOrder object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return DependentHostedNumberOrder object represented by the provided JSON */ - public static DependentHostedNumberOrder fromJson(final String json, final ObjectMapper objectMapper) { + public static DependentHostedNumberOrder fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, DependentHostedNumberOrder.class); + return objectMapper.readValue( + json, + DependentHostedNumberOrder.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -130,17 +126,23 @@ public static DependentHostedNumberOrder fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a DependentHostedNumberOrder object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a DependentHostedNumberOrder object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return DependentHostedNumberOrder object represented by the provided JSON */ - public static DependentHostedNumberOrder fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static DependentHostedNumberOrder fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, DependentHostedNumberOrder.class); + return objectMapper.readValue( + json, + DependentHostedNumberOrder.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -148,296 +150,155 @@ public static DependentHostedNumberOrder fromJson(final InputStream json, final } } - private final String sid; - private final String accountSid; - private final String incomingPhoneNumberSid; - private final String addressSid; - private final String signingDocumentSid; - private final com.twilio.type.PhoneNumber phoneNumber; - private final PhoneNumberCapabilities capabilities; - private final String friendlyName; - private final String uniqueName; - private final DependentHostedNumberOrder.Status status; - private final String failureReason; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final Integer verificationAttempts; - private final String email; - private final List ccEmails; - private final DependentHostedNumberOrder.VerificationType verificationType; - private final String verificationDocumentSid; - private final String extension; - private final Integer callDelay; - private final String verificationCode; - private final List verificationCallSids; - - @JsonCreator - private DependentHostedNumberOrder(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("incoming_phone_number_sid") - final String incomingPhoneNumberSid, - @JsonProperty("address_sid") - final String addressSid, - @JsonProperty("signing_document_sid") - final String signingDocumentSid, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("status") - final DependentHostedNumberOrder.Status status, - @JsonProperty("failure_reason") - final String failureReason, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("verification_attempts") - final Integer verificationAttempts, - @JsonProperty("email") - final String email, - @JsonProperty("cc_emails") - final List ccEmails, - @JsonProperty("verification_type") - final DependentHostedNumberOrder.VerificationType verificationType, - @JsonProperty("verification_document_sid") - final String verificationDocumentSid, - @JsonProperty("extension") - final String extension, - @JsonProperty("call_delay") - final Integer callDelay, - @JsonProperty("verification_code") - final String verificationCode, - @JsonProperty("verification_call_sids") - final List verificationCallSids) { - this.sid = sid; - this.accountSid = accountSid; - this.incomingPhoneNumberSid = incomingPhoneNumberSid; - this.addressSid = addressSid; - this.signingDocumentSid = signingDocumentSid; - this.phoneNumber = phoneNumber; - this.capabilities = capabilities; - this.friendlyName = friendlyName; - this.uniqueName = uniqueName; - this.status = status; - this.failureReason = failureReason; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.verificationAttempts = verificationAttempts; - this.email = email; - this.ccEmails = ccEmails; - this.verificationType = verificationType; - this.verificationDocumentSid = verificationDocumentSid; - this.extension = extension; - this.callDelay = callDelay; - this.verificationCode = verificationCode; - this.verificationCallSids = verificationCallSids; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The HostedNumberOrder sid.. - * - * @return HostedNumberOrder sid. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The Account sid.. - * - * @return Account sid. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String addressSid; - /** - * Returns The IncomingPhoneNumber sid.. - * - * @return IncomingPhoneNumber sid. - */ - public final String getIncomingPhoneNumberSid() { - return this.incomingPhoneNumberSid; - } + @Getter + private final Integer callDelay; - /** - * Returns The Address sid.. - * - * @return Address sid. - */ - public final String getAddressSid() { - return this.addressSid; - } + @Getter + private final PhoneNumberCapabilities capabilities; - /** - * Returns The LOA document sid.. - * - * @return LOA document sid. - */ - public final String getSigningDocumentSid() { - return this.signingDocumentSid; - } + @Getter + private final List ccEmails; - /** - * Returns The An E164 formatted phone number.. - * - * @return An E164 formatted phone number. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The A mapping of phone number capabilities.. - * - * @return A mapping of phone number capabilities. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A human readable description of this resource.. - * - * @return A human readable description of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String email; - /** - * Returns The A unique, developer assigned name of this HostedNumberOrder.. - * - * @return A unique, developer assigned name of this HostedNumberOrder. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String extension; - /** - * Returns The The Status of this HostedNumberOrder.. - * - * @return The Status of this HostedNumberOrder. - */ - public final DependentHostedNumberOrder.Status getStatus() { - return this.status; - } + @Getter + private final String failureReason; - /** - * Returns The Why a hosted_number_order reached status "action-required". - * - * @return Why a hosted_number_order reached status "action-required" - */ - public final String getFailureReason() { - return this.failureReason; - } + @Getter + private final String friendlyName; - /** - * Returns The The date this HostedNumberOrder was created.. - * - * @return The date this HostedNumberOrder was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String incomingPhoneNumberSid; - /** - * Returns The The date this HostedNumberOrder was updated.. - * - * @return The date this HostedNumberOrder was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The The number of attempts made to verify ownership of the phone - * number.. - * - * @return The number of attempts made to verify ownership of the phone number. - */ - public final Integer getVerificationAttempts() { - return this.verificationAttempts; - } + @Getter + private final String sid; - /** - * Returns The Email.. - * - * @return Email. - */ - public final String getEmail() { - return this.email; - } + @Getter + private final String signingDocumentSid; - /** - * Returns The A list of emails.. - * - * @return A list of emails. - */ - public final List getCcEmails() { - return this.ccEmails; - } + @Getter + private final DependentHostedNumberOrder.Status status; - /** - * Returns The The method used for verifying ownership of the number to be - * hosted.. - * - * @return The method used for verifying ownership of the number to be hosted. - */ - public final DependentHostedNumberOrder.VerificationType getVerificationType() { - return this.verificationType; - } + @Getter + private final String uniqueName; - /** - * Returns The Verification Document Sid.. - * - * @return Verification Document Sid. - */ - public final String getVerificationDocumentSid() { - return this.verificationDocumentSid; - } + @Getter + private final Integer verificationAttempts; - /** - * Returns The Phone extension to use for ownership verification call.. - * - * @return Phone extension to use for ownership verification call. - */ - public final String getExtension() { - return this.extension; - } + @Getter + private final List verificationCallSids; - /** - * Returns The Seconds (0-30) to delay ownership verification call by.. - * - * @return Seconds (0-30) to delay ownership verification call by. - */ - public final Integer getCallDelay() { - return this.callDelay; - } + @Getter + private final String verificationCode; - /** - * Returns The The digits passed during the ownership verification call.. - * - * @return The digits passed during the ownership verification call. - */ - public final String getVerificationCode() { - return this.verificationCode; - } + @Getter + private final String verificationDocumentSid; - /** - * Returns The List of IDs for ownership verification calls.. - * - * @return List of IDs for ownership verification calls. - */ - public final List getVerificationCallSids() { - return this.verificationCallSids; + @Getter + private final DependentHostedNumberOrder.VerificationType verificationType; + + @JsonCreator + private DependentHostedNumberOrder( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("address_sid") final String addressSid, + @JsonProperty("call_delay") final Integer callDelay, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("cc_emails") final List ccEmails, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("extension") final String extension, + @JsonProperty("failure_reason") final String failureReason, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty( + "incoming_phone_number_sid" + ) final String incomingPhoneNumberSid, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("signing_document_sid") final String signingDocumentSid, + @JsonProperty("status") final DependentHostedNumberOrder.Status status, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty( + "verification_attempts" + ) final Integer verificationAttempts, + @JsonProperty("verification_call_sids") final List< + String + > verificationCallSids, + @JsonProperty("verification_code") final String verificationCode, + @JsonProperty( + "verification_document_sid" + ) final String verificationDocumentSid, + @JsonProperty( + "verification_type" + ) final DependentHostedNumberOrder.VerificationType verificationType + ) { + this.accountSid = accountSid; + this.addressSid = addressSid; + this.callDelay = callDelay; + this.capabilities = capabilities; + this.ccEmails = ccEmails; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.extension = extension; + this.failureReason = failureReason; + this.friendlyName = friendlyName; + this.incomingPhoneNumberSid = incomingPhoneNumberSid; + this.phoneNumber = phoneNumber; + this.sid = sid; + this.signingDocumentSid = signingDocumentSid; + this.status = status; + this.uniqueName = uniqueName; + this.verificationAttempts = verificationAttempts; + this.verificationCallSids = verificationCallSids; + this.verificationCode = verificationCode; + this.verificationDocumentSid = verificationDocumentSid; + this.verificationType = verificationType; } @Override @@ -451,82 +312,63 @@ public boolean equals(final Object o) { } DependentHostedNumberOrder other = (DependentHostedNumberOrder) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(incomingPhoneNumberSid, other.incomingPhoneNumberSid) && - Objects.equals(addressSid, other.addressSid) && - Objects.equals(signingDocumentSid, other.signingDocumentSid) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(status, other.status) && - Objects.equals(failureReason, other.failureReason) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(verificationAttempts, other.verificationAttempts) && - Objects.equals(email, other.email) && - Objects.equals(ccEmails, other.ccEmails) && - Objects.equals(verificationType, other.verificationType) && - Objects.equals(verificationDocumentSid, other.verificationDocumentSid) && - Objects.equals(extension, other.extension) && - Objects.equals(callDelay, other.callDelay) && - Objects.equals(verificationCode, other.verificationCode) && - Objects.equals(verificationCallSids, other.verificationCallSids); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressSid, other.addressSid) && + Objects.equals(callDelay, other.callDelay) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(ccEmails, other.ccEmails) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(extension, other.extension) && + Objects.equals(failureReason, other.failureReason) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals( + incomingPhoneNumberSid, + other.incomingPhoneNumberSid + ) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(signingDocumentSid, other.signingDocumentSid) && + Objects.equals(status, other.status) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(verificationAttempts, other.verificationAttempts) && + Objects.equals(verificationCallSids, other.verificationCallSids) && + Objects.equals(verificationCode, other.verificationCode) && + Objects.equals( + verificationDocumentSid, + other.verificationDocumentSid + ) && + Objects.equals(verificationType, other.verificationType) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - incomingPhoneNumberSid, - addressSid, - signingDocumentSid, - phoneNumber, - capabilities, - friendlyName, - uniqueName, - status, - failureReason, - dateCreated, - dateUpdated, - verificationAttempts, - email, - ccEmails, - verificationType, - verificationDocumentSid, - extension, - callDelay, - verificationCode, - verificationCallSids); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("incomingPhoneNumberSid", incomingPhoneNumberSid) - .add("addressSid", addressSid) - .add("signingDocumentSid", signingDocumentSid) - .add("phoneNumber", phoneNumber) - .add("capabilities", capabilities) - .add("friendlyName", friendlyName) - .add("uniqueName", uniqueName) - .add("status", status) - .add("failureReason", failureReason) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("verificationAttempts", verificationAttempts) - .add("email", email) - .add("ccEmails", ccEmails) - .add("verificationType", verificationType) - .add("verificationDocumentSid", verificationDocumentSid) - .add("extension", extension) - .add("callDelay", callDelay) - .add("verificationCode", verificationCode) - .add("verificationCallSids", verificationCallSids) - .toString(); + return Objects.hash( + accountSid, + addressSid, + callDelay, + capabilities, + ccEmails, + dateCreated, + dateUpdated, + email, + extension, + failureReason, + friendlyName, + incomingPhoneNumberSid, + phoneNumber, + sid, + signingDocumentSid, + status, + uniqueName, + verificationAttempts, + verificationCallSids, + verificationCode, + verificationDocumentSid, + verificationType + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrderReader.java b/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrderReader.java index 20bf89ecba..b532c622cb 100644 --- a/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrderReader.java +++ b/src/main/java/com/twilio/rest/preview/hostedNumbers/authorizationdocument/DependentHostedNumberOrderReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.hostedNumbers.authorizationdocument; @@ -10,262 +17,290 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DependentHostedNumberOrderReader extends Reader { - private final String pathSigningDocumentSid; +public class DependentHostedNumberOrderReader + extends Reader { + + private String pathSigningDocumentSid; private DependentHostedNumberOrder.Status status; private com.twilio.type.PhoneNumber phoneNumber; private String incomingPhoneNumberSid; private String friendlyName; private String uniqueName; + private Long pageSize; - /** - * Construct a new DependentHostedNumberOrderReader. - * - * @param pathSigningDocumentSid The signing_document_sid - */ - public DependentHostedNumberOrderReader(final String pathSigningDocumentSid) { + public DependentHostedNumberOrderReader( + final String pathSigningDocumentSid + ) { this.pathSigningDocumentSid = pathSigningDocumentSid; } - /** - * Status of an instance resource. It can hold one of the values: 1. opened 2. - * signing, 3. signed LOA, 4. canceled, 5. failed. See the section entitled - * [Status - * Values](https://www.twilio.com/docs/api/phone-numbers/hosted-number-authorization-documents#status-values) for more information on each of these statuses.. - * - * @param status The Status of this HostedNumberOrder. - * @return this - */ - public DependentHostedNumberOrderReader setStatus(final DependentHostedNumberOrder.Status status) { + public DependentHostedNumberOrderReader setStatus( + final DependentHostedNumberOrder.Status status + ) { this.status = status; return this; } - /** - * An E164 formatted phone number hosted by this HostedNumberOrder.. - * - * @param phoneNumber An E164 formatted phone number. - * @return this - */ - public DependentHostedNumberOrderReader setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public DependentHostedNumberOrderReader setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * An E164 formatted phone number hosted by this HostedNumberOrder.. - * - * @param phoneNumber An E164 formatted phone number. - * @return this - */ - public DependentHostedNumberOrderReader setPhoneNumber(final String phoneNumber) { + public DependentHostedNumberOrderReader setPhoneNumber( + final String phoneNumber + ) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * A 34 character string that uniquely identifies the IncomingPhoneNumber - * resource created by this HostedNumberOrder.. - * - * @param incomingPhoneNumberSid IncomingPhoneNumber sid. - * @return this - */ - public DependentHostedNumberOrderReader setIncomingPhoneNumberSid(final String incomingPhoneNumberSid) { + public DependentHostedNumberOrderReader setIncomingPhoneNumberSid( + final String incomingPhoneNumberSid + ) { this.incomingPhoneNumberSid = incomingPhoneNumberSid; return this; } - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param friendlyName A human readable description of this resource. - * @return this - */ - public DependentHostedNumberOrderReader setFriendlyName(final String friendlyName) { + public DependentHostedNumberOrderReader setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - /** - * Provides a unique and addressable name to be assigned to this - * HostedNumberOrder, assigned by the developer, to be optionally used in - * addition to SID.. - * - * @param uniqueName A unique, developer assigned name of this - * HostedNumberOrder. - * @return this - */ - public DependentHostedNumberOrderReader setUniqueName(final String uniqueName) { + public DependentHostedNumberOrderReader setUniqueName( + final String uniqueName + ) { this.uniqueName = uniqueName; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return DependentHostedNumberOrder ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public DependentHostedNumberOrderReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return DependentHostedNumberOrder ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + DependentHostedNumberOrder.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/HostedNumbers/AuthorizationDocuments/{SigningDocumentSid}/DependentHostedNumberOrders"; + + path = + path.replace( + "{" + "SigningDocumentSid" + "}", + this.pathSigningDocumentSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/HostedNumbers/AuthorizationDocuments/" + this.pathSigningDocumentSid + "/DependentHostedNumberOrders", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return DependentHostedNumberOrder ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + DependentHostedNumberOrder.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "DependentHostedNumberOrder read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "items", + response.getContent(), + DependentHostedNumberOrder.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of DependentHostedNumberOrder Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("DependentHostedNumberOrder read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "items", - response.getContent(), - DependentHostedNumberOrder.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status.toString()); + Serializer.toString(request, "Status", status, ParameterType.QUERY); } if (phoneNumber != null) { - request.addQueryParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.QUERY + ); } if (incomingPhoneNumberSid != null) { - request.addQueryParam("IncomingPhoneNumberSid", incomingPhoneNumberSid); + Serializer.toString( + request, + "IncomingPhoneNumberSid", + incomingPhoneNumberSid, + ParameterType.QUERY + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (uniqueName != null) { - request.addQueryParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOn.java b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOn.java index c56c730a1a..0c00be20a7 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOn.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOn.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; @@ -11,63 +18,47 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AvailableAddOn extends Resource { - private static final long serialVersionUID = 22306216855466L; - /** - * Create a AvailableAddOnFetcher to execute fetch. - * - * @param pathSid The unique Available Add-on Sid - * @return AvailableAddOnFetcher capable of executing the fetch - */ public static AvailableAddOnFetcher fetcher(final String pathSid) { return new AvailableAddOnFetcher(pathSid); } - /** - * Create a AvailableAddOnReader to execute read. - * - * @return AvailableAddOnReader capable of executing the read - */ public static AvailableAddOnReader reader() { return new AvailableAddOnReader(); } /** - * Converts a JSON String into a AvailableAddOn object using the provided - * ObjectMapper. - * + * Converts a JSON String into a AvailableAddOn object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AvailableAddOn object represented by the provided JSON */ - public static AvailableAddOn fromJson(final String json, final ObjectMapper objectMapper) { + public static AvailableAddOn fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AvailableAddOn.class); @@ -81,12 +72,15 @@ public static AvailableAddOn fromJson(final String json, final ObjectMapper obje /** * Converts a JSON InputStream into a AvailableAddOn object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AvailableAddOn object represented by the provided JSON */ - public static AvailableAddOn fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AvailableAddOn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AvailableAddOn.class); @@ -97,99 +91,56 @@ public static AvailableAddOn fromJson(final InputStream json, final ObjectMapper } } - private final String sid; - private final String friendlyName; - private final String description; - private final String pricingType; - private final Map configurationSchema; - private final URI url; - private final Map links; - - @JsonCreator - private AvailableAddOn(@JsonProperty("sid") - final String sid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("description") - final String description, - @JsonProperty("pricing_type") - final String pricingType, - @JsonProperty("configuration_schema") - final Map configurationSchema, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.friendlyName = friendlyName; - this.description = description; - this.pricingType = pricingType; - this.configurationSchema = configurationSchema; - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A string that uniquely identifies this Add-on. - * - * @return A string that uniquely identifies this Add-on - */ - public final String getSid() { - return this.sid; - } + @Getter + private final Object configurationSchema; - /** - * Returns The A description of this Add-on. - * - * @return A description of this Add-on - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String description; - /** - * Returns The A short description of the Add-on functionality. - * - * @return A short description of the Add-on functionality - */ - public final String getDescription() { - return this.description; - } + @Getter + private final String friendlyName; - /** - * Returns The The way customers are charged for using this Add-on. - * - * @return The way customers are charged for using this Add-on - */ - public final String getPricingType() { - return this.pricingType; - } + @Getter + private final Map links; - /** - * Returns The The JSON Schema describing the Add-on's configuration. - * - * @return The JSON Schema describing the Add-on's configuration - */ - public final Map getConfigurationSchema() { - return this.configurationSchema; - } + @Getter + private final String pricingType; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String sid; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private AvailableAddOn( + @JsonProperty("configuration_schema") final Object configurationSchema, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("pricing_type") final String pricingType, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.configurationSchema = configurationSchema; + this.description = description; + this.friendlyName = friendlyName; + this.links = links; + this.pricingType = pricingType; + this.sid = sid; + this.url = url; } @Override @@ -203,37 +154,27 @@ public boolean equals(final Object o) { } AvailableAddOn other = (AvailableAddOn) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(description, other.description) && - Objects.equals(pricingType, other.pricingType) && - Objects.equals(configurationSchema, other.configurationSchema) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(configurationSchema, other.configurationSchema) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(pricingType, other.pricingType) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - friendlyName, - description, - pricingType, - configurationSchema, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("friendlyName", friendlyName) - .add("description", description) - .add("pricingType", pricingType) - .add("configurationSchema", configurationSchema) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + configurationSchema, + description, + friendlyName, + links, + pricingType, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnFetcher.java b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnFetcher.java index df1e7e79e8..2ba5c6bbe7 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnFetcher.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,59 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class AvailableAddOnFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new AvailableAddOnFetcher. - * - * @param pathSid The unique Available Add-on Sid - */ + private String pathSid; + public AvailableAddOnFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AvailableAddOn - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AvailableAddOn fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/marketplace/AvailableAddOns/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/marketplace/AvailableAddOns/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailableAddOn fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AvailableAddOn fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return AvailableAddOn.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public AvailableAddOn fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AvailableAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AvailableAddOn content = AvailableAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnReader.java b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnReader.java index 6a0fef0f8f..cb98caf9d3 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnReader.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/AvailableAddOnReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; @@ -10,153 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class AvailableAddOnReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AvailableAddOn ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public AvailableAddOnReader() {} + + public AvailableAddOnReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AvailableAddOn ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_add_ons", + response.getContent(), + AvailableAddOn.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/marketplace/AvailableAddOns"; + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/marketplace/AvailableAddOns", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AvailableAddOn ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "available_add_ons", + response.getContent(), + AvailableAddOn.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AvailableAddOn read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "available_add_ons", + response.getContent(), + AvailableAddOn.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AvailableAddOn Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AvailableAddOn read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "available_add_ons", - response.getContent(), - AvailableAddOn.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOn.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOn.java index ceb13b4cc6..dddf69be73 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOn.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOn.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; @@ -11,99 +18,68 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class InstalledAddOn extends Resource { - private static final long serialVersionUID = 59619174394820L; - /** - * Create a InstalledAddOnCreator to execute create. - * - * @param availableAddOnSid A string that uniquely identifies the Add-on to - * install - * @param acceptTermsOfService A boolean reflecting your acceptance of the - * Terms of Service - * @return InstalledAddOnCreator capable of executing the create - */ - public static InstalledAddOnCreator creator(final String availableAddOnSid, - final Boolean acceptTermsOfService) { - return new InstalledAddOnCreator(availableAddOnSid, acceptTermsOfService); + public static InstalledAddOnCreator creator( + final String availableAddOnSid, + final Boolean acceptTermsOfService + ) { + return new InstalledAddOnCreator( + availableAddOnSid, + acceptTermsOfService + ); } - /** - * Create a InstalledAddOnDeleter to execute delete. - * - * @param pathSid The Installed Add-on Sid to delete - * @return InstalledAddOnDeleter capable of executing the delete - */ public static InstalledAddOnDeleter deleter(final String pathSid) { return new InstalledAddOnDeleter(pathSid); } - /** - * Create a InstalledAddOnFetcher to execute fetch. - * - * @param pathSid The unique Installed Add-on Sid - * @return InstalledAddOnFetcher capable of executing the fetch - */ public static InstalledAddOnFetcher fetcher(final String pathSid) { return new InstalledAddOnFetcher(pathSid); } - /** - * Create a InstalledAddOnUpdater to execute update. - * - * @param pathSid The sid - * @return InstalledAddOnUpdater capable of executing the update - */ - public static InstalledAddOnUpdater updater(final String pathSid) { - return new InstalledAddOnUpdater(pathSid); - } - - /** - * Create a InstalledAddOnReader to execute read. - * - * @return InstalledAddOnReader capable of executing the read - */ public static InstalledAddOnReader reader() { return new InstalledAddOnReader(); } + public static InstalledAddOnUpdater updater(final String pathSid) { + return new InstalledAddOnUpdater(pathSid); + } + /** - * Converts a JSON String into a InstalledAddOn object using the provided - * ObjectMapper. - * + * Converts a JSON String into a InstalledAddOn object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return InstalledAddOn object represented by the provided JSON */ - public static InstalledAddOn fromJson(final String json, final ObjectMapper objectMapper) { + public static InstalledAddOn fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InstalledAddOn.class); @@ -117,12 +93,15 @@ public static InstalledAddOn fromJson(final String json, final ObjectMapper obje /** * Converts a JSON InputStream into a InstalledAddOn object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return InstalledAddOn object represented by the provided JSON */ - public static InstalledAddOn fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static InstalledAddOn fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InstalledAddOn.class); @@ -133,138 +112,81 @@ public static InstalledAddOn fromJson(final InputStream json, final ObjectMapper } } - private final String sid; - private final String accountSid; - private final String friendlyName; - private final String description; - private final Map configuration; - private final String uniqueName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private InstalledAddOn(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("description") - final String description, - @JsonProperty("configuration") - final Map configuration, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.description = description; - this.configuration = configuration; - this.uniqueName = uniqueName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A string that uniquely identifies this Add-on installation. - * - * @return A string that uniquely identifies this Add-on installation - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The Account id that has installed this Add-on. - * - * @return The Account id that has installed this Add-on - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Object configuration; - /** - * Returns The A description of this Add-on installation. - * - * @return A description of this Add-on installation - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The A short description of the Add-on functionality. - * - * @return A short description of the Add-on functionality - */ - public final String getDescription() { - return this.description; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The JSON object representing the current configuration. - * - * @return The JSON object representing the current configuration - */ - public final Map getConfiguration() { - return this.configuration; - } + @Getter + private final String description; - /** - * Returns The The string that uniquely identifies this Add-on installation. - * - * @return The string that uniquely identifies this Add-on installation - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String friendlyName; - /** - * Returns The The date this Add-on installation was created. - * - * @return The date this Add-on installation was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Map links; - /** - * Returns The The date this Add-on installation was last updated. - * - * @return The date this Add-on installation was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String sid; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String uniqueName; - /** - * Returns The A dictionary of URLs for related resource.. - * - * @return A dictionary of URLs for related resource. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private InstalledAddOn( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("configuration") final Object configuration, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("description") final String description, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.configuration = configuration; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.description = description; + this.friendlyName = friendlyName; + this.links = links; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -278,46 +200,33 @@ public boolean equals(final Object o) { } InstalledAddOn other = (InstalledAddOn) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(description, other.description) && - Objects.equals(configuration, other.configuration) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(description, other.description) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - description, - configuration, - uniqueName, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("description", description) - .add("configuration", configuration) - .add("uniqueName", uniqueName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + configuration, + dateCreated, + dateUpdated, + description, + friendlyName, + links, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnCreator.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnCreator.java index 5cc30f4765..c289b3d901 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnCreator.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; import com.twilio.base.Creator; -import com.twilio.converter.Converter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,118 +27,142 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class InstalledAddOnCreator extends Creator { - private final String availableAddOnSid; - private final Boolean acceptTermsOfService; - private Map configuration; + + private String availableAddOnSid; + private Boolean acceptTermsOfService; + private Object configuration; private String uniqueName; - /** - * Construct a new InstalledAddOnCreator. - * - * @param availableAddOnSid A string that uniquely identifies the Add-on to - * install - * @param acceptTermsOfService A boolean reflecting your acceptance of the - * Terms of Service - */ - public InstalledAddOnCreator(final String availableAddOnSid, - final Boolean acceptTermsOfService) { + public InstalledAddOnCreator( + final String availableAddOnSid, + final Boolean acceptTermsOfService + ) { this.availableAddOnSid = availableAddOnSid; this.acceptTermsOfService = acceptTermsOfService; } - /** - * The JSON object representing the configuration of the new Add-on - * installation.. - * - * @param configuration The JSON object representing the configuration - * @return this - */ - public InstalledAddOnCreator setConfiguration(final Map configuration) { + public InstalledAddOnCreator setAvailableAddOnSid( + final String availableAddOnSid + ) { + this.availableAddOnSid = availableAddOnSid; + return this; + } + + public InstalledAddOnCreator setAcceptTermsOfService( + final Boolean acceptTermsOfService + ) { + this.acceptTermsOfService = acceptTermsOfService; + return this; + } + + public InstalledAddOnCreator setConfiguration(final Object configuration) { this.configuration = configuration; return this; } - /** - * The human-readable string that uniquely identifies this Add-on installation - * for an Account.. - * - * @param uniqueName The string that uniquely identifies this Add-on - * installation - * @return this - */ public InstalledAddOnCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created InstalledAddOn - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public InstalledAddOn create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/marketplace/InstalledAddOns"; + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/marketplace/InstalledAddOns", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "InstalledAddOn creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public InstalledAddOn create(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return InstalledAddOn.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOn content = InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (availableAddOnSid != null) { - request.addPostParam("AvailableAddOnSid", availableAddOnSid); + Serializer.toString( + request, + "AvailableAddOnSid", + availableAddOnSid, + ParameterType.URLENCODED + ); } if (acceptTermsOfService != null) { - request.addPostParam("AcceptTermsOfService", acceptTermsOfService.toString()); + Serializer.toString( + request, + "AcceptTermsOfService", + acceptTermsOfService, + ParameterType.URLENCODED + ); } if (configuration != null) { - request.addPostParam("Configuration", Converter.mapToJson(configuration)); + Serializer.toString( + request, + "Configuration", + configuration, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnDeleter.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnDeleter.java index 28587f6c68..8bf8917324 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnDeleter.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class InstalledAddOnDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new InstalledAddOnDeleter. - * - * @param pathSid The Installed Add-on Sid to delete - */ + private String pathSid; + public InstalledAddOnDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/marketplace/InstalledAddOns/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.PREVIEW.toString(), - "/marketplace/InstalledAddOns/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "InstalledAddOn delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnFetcher.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnFetcher.java index 2c284aee0e..b2b196f9d2 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnFetcher.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,59 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class InstalledAddOnFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new InstalledAddOnFetcher. - * - * @param pathSid The unique Installed Add-on Sid - */ + private String pathSid; + public InstalledAddOnFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched InstalledAddOn - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public InstalledAddOn fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/marketplace/InstalledAddOns/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/marketplace/InstalledAddOns/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "InstalledAddOn fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return InstalledAddOn.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public InstalledAddOn fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOn content = InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnReader.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnReader.java index a71173671c..47669fe404 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnReader.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; @@ -10,153 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class InstalledAddOnReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return InstalledAddOn ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public InstalledAddOnReader() {} + + public InstalledAddOnReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return InstalledAddOn ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "installed_add_ons", + response.getContent(), + InstalledAddOn.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/marketplace/InstalledAddOns"; + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/marketplace/InstalledAddOns", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return InstalledAddOn ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "installed_add_ons", + response.getContent(), + InstalledAddOn.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOn read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "installed_add_ons", + response.getContent(), + InstalledAddOn.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of InstalledAddOn Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("InstalledAddOn read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "installed_add_ons", - response.getContent(), - InstalledAddOn.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnUpdater.java b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnUpdater.java index 9b8270aac4..77fad4fdaf 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnUpdater.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/InstalledAddOnUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.Converter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,105 +27,107 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class InstalledAddOnUpdater extends Updater { - private final String pathSid; - private Map configuration; + + private String pathSid; + private Object configuration; private String uniqueName; - /** - * Construct a new InstalledAddOnUpdater. - * - * @param pathSid The sid - */ public InstalledAddOnUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * Valid JSON object that conform to the configuration schema exposed by the - * associated Available Add-on resource. This is only required by Add-ons that - * need to be configured. - * - * @param configuration The JSON object representing the configuration - * @return this - */ - public InstalledAddOnUpdater setConfiguration(final Map configuration) { + public InstalledAddOnUpdater setConfiguration(final Object configuration) { this.configuration = configuration; return this; } - /** - * The human-readable string that uniquely identifies this Add-on installation - * for an Account.. - * - * @param uniqueName The string that uniquely identifies this Add-on - * installation - * @return this - */ public InstalledAddOnUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated InstalledAddOn - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public InstalledAddOn update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/marketplace/InstalledAddOns/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/marketplace/InstalledAddOns/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOn update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "InstalledAddOn update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public InstalledAddOn update(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return InstalledAddOn.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOn content = InstalledAddOn.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (configuration != null) { - request.addPostParam("Configuration", Converter.mapToJson(configuration)); + Serializer.toString( + request, + "Configuration", + configuration, + ParameterType.URLENCODED + ); } if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtension.java b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtension.java index 7f2e15cdbf..d196d6a149 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtension.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtension.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace.availableaddon; @@ -11,65 +18,54 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class AvailableAddOnExtension extends Resource { - private static final long serialVersionUID = 88592059649526L; - /** - * Create a AvailableAddOnExtensionFetcher to execute fetch. - * - * @param pathAvailableAddOnSid The available_add_on_sid - * @param pathSid The unique Extension Sid - * @return AvailableAddOnExtensionFetcher capable of executing the fetch - */ - public static AvailableAddOnExtensionFetcher fetcher(final String pathAvailableAddOnSid, - final String pathSid) { - return new AvailableAddOnExtensionFetcher(pathAvailableAddOnSid, pathSid); + public static AvailableAddOnExtensionFetcher fetcher( + final String pathAvailableAddOnSid, + final String pathSid + ) { + return new AvailableAddOnExtensionFetcher( + pathAvailableAddOnSid, + pathSid + ); } - /** - * Create a AvailableAddOnExtensionReader to execute read. - * - * @param pathAvailableAddOnSid The available_add_on_sid - * @return AvailableAddOnExtensionReader capable of executing the read - */ - public static AvailableAddOnExtensionReader reader(final String pathAvailableAddOnSid) { + public static AvailableAddOnExtensionReader reader( + final String pathAvailableAddOnSid + ) { return new AvailableAddOnExtensionReader(pathAvailableAddOnSid); } /** - * Converts a JSON String into a AvailableAddOnExtension object using the - * provided ObjectMapper. - * + * Converts a JSON String into a AvailableAddOnExtension object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return AvailableAddOnExtension object represented by the provided JSON */ - public static AvailableAddOnExtension fromJson(final String json, final ObjectMapper objectMapper) { + public static AvailableAddOnExtension fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AvailableAddOnExtension.class); @@ -81,14 +77,17 @@ public static AvailableAddOnExtension fromJson(final String json, final ObjectMa } /** - * Converts a JSON InputStream into a AvailableAddOnExtension object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a AvailableAddOnExtension object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return AvailableAddOnExtension object represented by the provided JSON */ - public static AvailableAddOnExtension fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static AvailableAddOnExtension fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, AvailableAddOnExtension.class); @@ -99,88 +98,53 @@ public static AvailableAddOnExtension fromJson(final InputStream json, final Obj } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String availableAddOnSid; + + @Getter private final String friendlyName; + + @Getter private final String productName; + + @Getter + private final String sid; + + @Getter private final String uniqueName; + + @Getter private final URI url; @JsonCreator - private AvailableAddOnExtension(@JsonProperty("sid") - final String sid, - @JsonProperty("available_add_on_sid") - final String availableAddOnSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("product_name") - final String productName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("url") - final URI url) { - this.sid = sid; + private AvailableAddOnExtension( + @JsonProperty("available_add_on_sid") final String availableAddOnSid, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("product_name") final String productName, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { this.availableAddOnSid = availableAddOnSid; this.friendlyName = friendlyName; this.productName = productName; + this.sid = sid; this.uniqueName = uniqueName; this.url = url; } - /** - * Returns The A string that uniquely identifies this Extension. - * - * @return A string that uniquely identifies this Extension - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The available_add_on_sid. - * - * @return The available_add_on_sid - */ - public final String getAvailableAddOnSid() { - return this.availableAddOnSid; - } - - /** - * Returns The A human-readable description of this Extension. - * - * @return A human-readable description of this Extension - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The A human-readable description of the Extension's Product. - * - * @return A human-readable description of the Extension's Product - */ - public final String getProductName() { - return this.productName; - } - - /** - * Returns The The string that uniquely identifies this Extension. - * - * @return The string that uniquely identifies this Extension - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -192,34 +156,25 @@ public boolean equals(final Object o) { } AvailableAddOnExtension other = (AvailableAddOnExtension) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(availableAddOnSid, other.availableAddOnSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(productName, other.productName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(url, other.url); + return ( + Objects.equals(availableAddOnSid, other.availableAddOnSid) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(productName, other.productName) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - availableAddOnSid, - friendlyName, - productName, - uniqueName, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("availableAddOnSid", availableAddOnSid) - .add("friendlyName", friendlyName) - .add("productName", productName) - .add("uniqueName", uniqueName) - .add("url", url) - .toString(); + return Objects.hash( + availableAddOnSid, + friendlyName, + productName, + sid, + uniqueName, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionFetcher.java b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionFetcher.java index d36828e75c..84c4748a55 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionFetcher.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace.availableaddon; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,63 +24,85 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AvailableAddOnExtensionFetcher extends Fetcher { - private final String pathAvailableAddOnSid; - private final String pathSid; +public class AvailableAddOnExtensionFetcher + extends Fetcher { + + private String pathAvailableAddOnSid; + private String pathSid; - /** - * Construct a new AvailableAddOnExtensionFetcher. - * - * @param pathAvailableAddOnSid The available_add_on_sid - * @param pathSid The unique Extension Sid - */ - public AvailableAddOnExtensionFetcher(final String pathAvailableAddOnSid, - final String pathSid) { + public AvailableAddOnExtensionFetcher( + final String pathAvailableAddOnSid, + final String pathSid + ) { this.pathAvailableAddOnSid = pathAvailableAddOnSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched AvailableAddOnExtension - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public AvailableAddOnExtension fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/marketplace/AvailableAddOns/{AvailableAddOnSid}/Extensions/{Sid}"; + + path = + path.replace( + "{" + "AvailableAddOnSid" + "}", + this.pathAvailableAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/marketplace/AvailableAddOns/" + this.pathAvailableAddOnSid + "/Extensions/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("AvailableAddOnExtension fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "AvailableAddOnExtension fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public AvailableAddOnExtension fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AvailableAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return AvailableAddOnExtension.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AvailableAddOnExtension content = AvailableAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionReader.java b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionReader.java index 52b82cecd8..389298da1b 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionReader.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/availableaddon/AvailableAddOnExtensionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace.availableaddon; @@ -10,164 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AvailableAddOnExtensionReader + extends Reader { + + private String pathAvailableAddOnSid; + private Long pageSize; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AvailableAddOnExtensionReader extends Reader { - private final String pathAvailableAddOnSid; - - /** - * Construct a new AvailableAddOnExtensionReader. - * - * @param pathAvailableAddOnSid The available_add_on_sid - */ public AvailableAddOnExtensionReader(final String pathAvailableAddOnSid) { this.pathAvailableAddOnSid = pathAvailableAddOnSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AvailableAddOnExtension ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public AvailableAddOnExtensionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return AvailableAddOnExtension ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + AvailableAddOnExtension.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/marketplace/AvailableAddOns/{AvailableAddOnSid}/Extensions"; + + path = + path.replace( + "{" + "AvailableAddOnSid" + "}", + this.pathAvailableAddOnSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/marketplace/AvailableAddOns/" + this.pathAvailableAddOnSid + "/Extensions", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return AvailableAddOnExtension ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + AvailableAddOnExtension.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AvailableAddOnExtension read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "extensions", + response.getContent(), + AvailableAddOnExtension.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of AvailableAddOnExtension Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("AvailableAddOnExtension read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "extensions", - response.getContent(), - AvailableAddOnExtension.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtension.java b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtension.java index eb3e862c0f..182484feee 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtension.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtension.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace.installedaddon; @@ -11,79 +18,66 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class InstalledAddOnExtension extends Resource { - private static final long serialVersionUID = 70024747231532L; - /** - * Create a InstalledAddOnExtensionFetcher to execute fetch. - * - * @param pathInstalledAddOnSid The installed_add_on_sid - * @param pathSid The unique Extension Sid - * @return InstalledAddOnExtensionFetcher capable of executing the fetch - */ - public static InstalledAddOnExtensionFetcher fetcher(final String pathInstalledAddOnSid, - final String pathSid) { - return new InstalledAddOnExtensionFetcher(pathInstalledAddOnSid, pathSid); + public static InstalledAddOnExtensionFetcher fetcher( + final String pathInstalledAddOnSid, + final String pathSid + ) { + return new InstalledAddOnExtensionFetcher( + pathInstalledAddOnSid, + pathSid + ); } - /** - * Create a InstalledAddOnExtensionUpdater to execute update. - * - * @param pathInstalledAddOnSid The installed_add_on_sid - * @param pathSid The sid - * @param enabled A Boolean indicating if the Extension will be invoked - * @return InstalledAddOnExtensionUpdater capable of executing the update - */ - public static InstalledAddOnExtensionUpdater updater(final String pathInstalledAddOnSid, - final String pathSid, - final Boolean enabled) { - return new InstalledAddOnExtensionUpdater(pathInstalledAddOnSid, pathSid, enabled); + public static InstalledAddOnExtensionReader reader( + final String pathInstalledAddOnSid + ) { + return new InstalledAddOnExtensionReader(pathInstalledAddOnSid); } - /** - * Create a InstalledAddOnExtensionReader to execute read. - * - * @param pathInstalledAddOnSid The installed_add_on_sid - * @return InstalledAddOnExtensionReader capable of executing the read - */ - public static InstalledAddOnExtensionReader reader(final String pathInstalledAddOnSid) { - return new InstalledAddOnExtensionReader(pathInstalledAddOnSid); + public static InstalledAddOnExtensionUpdater updater( + final String pathInstalledAddOnSid, + final String pathSid, + final Boolean enabled + ) { + return new InstalledAddOnExtensionUpdater( + pathInstalledAddOnSid, + pathSid, + enabled + ); } /** - * Converts a JSON String into a InstalledAddOnExtension object using the - * provided ObjectMapper. - * + * Converts a JSON String into a InstalledAddOnExtension object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return InstalledAddOnExtension object represented by the provided JSON */ - public static InstalledAddOnExtension fromJson(final String json, final ObjectMapper objectMapper) { + public static InstalledAddOnExtension fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InstalledAddOnExtension.class); @@ -95,14 +89,17 @@ public static InstalledAddOnExtension fromJson(final String json, final ObjectMa } /** - * Converts a JSON InputStream into a InstalledAddOnExtension object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a InstalledAddOnExtension object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return InstalledAddOnExtension object represented by the provided JSON */ - public static InstalledAddOnExtension fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static InstalledAddOnExtension fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, InstalledAddOnExtension.class); @@ -113,101 +110,58 @@ public static InstalledAddOnExtension fromJson(final InputStream json, final Obj } } - private final String sid; - private final String installedAddOnSid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean enabled; + + @Getter private final String friendlyName; + + @Getter + private final String installedAddOnSid; + + @Getter private final String productName; + + @Getter + private final String sid; + + @Getter private final String uniqueName; - private final Boolean enabled; + + @Getter private final URI url; @JsonCreator - private InstalledAddOnExtension(@JsonProperty("sid") - final String sid, - @JsonProperty("installed_add_on_sid") - final String installedAddOnSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("product_name") - final String productName, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("enabled") - final Boolean enabled, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.installedAddOnSid = installedAddOnSid; + private InstalledAddOnExtension( + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("installed_add_on_sid") final String installedAddOnSid, + @JsonProperty("product_name") final String productName, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.enabled = enabled; this.friendlyName = friendlyName; + this.installedAddOnSid = installedAddOnSid; this.productName = productName; + this.sid = sid; this.uniqueName = uniqueName; - this.enabled = enabled; this.url = url; } - /** - * Returns The A string that uniquely identifies this Extension. - * - * @return A string that uniquely identifies this Extension - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The installed_add_on_sid. - * - * @return The installed_add_on_sid - */ - public final String getInstalledAddOnSid() { - return this.installedAddOnSid; - } - - /** - * Returns The A human-readable description of this Extension. - * - * @return A human-readable description of this Extension - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The A human-readable description of the Extension's Product. - * - * @return A human-readable description of the Extension's Product - */ - public final String getProductName() { - return this.productName; - } - - /** - * Returns The The string that uniquely identifies this Extension. - * - * @return The string that uniquely identifies this Extension - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The A Boolean indicating if the Extension will be invoked. - * - * @return A Boolean indicating if the Extension will be invoked - */ - public final Boolean getEnabled() { - return this.enabled; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -219,37 +173,27 @@ public boolean equals(final Object o) { } InstalledAddOnExtension other = (InstalledAddOnExtension) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(installedAddOnSid, other.installedAddOnSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(productName, other.productName) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(enabled, other.enabled) && - Objects.equals(url, other.url); + return ( + Objects.equals(enabled, other.enabled) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(installedAddOnSid, other.installedAddOnSid) && + Objects.equals(productName, other.productName) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - installedAddOnSid, - friendlyName, - productName, - uniqueName, - enabled, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("installedAddOnSid", installedAddOnSid) - .add("friendlyName", friendlyName) - .add("productName", productName) - .add("uniqueName", uniqueName) - .add("enabled", enabled) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + enabled, + friendlyName, + installedAddOnSid, + productName, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionFetcher.java b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionFetcher.java index aaa79cbfd3..a5094277ae 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionFetcher.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace.installedaddon; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,63 +24,85 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class InstalledAddOnExtensionFetcher extends Fetcher { - private final String pathInstalledAddOnSid; - private final String pathSid; +public class InstalledAddOnExtensionFetcher + extends Fetcher { + + private String pathInstalledAddOnSid; + private String pathSid; - /** - * Construct a new InstalledAddOnExtensionFetcher. - * - * @param pathInstalledAddOnSid The installed_add_on_sid - * @param pathSid The unique Extension Sid - */ - public InstalledAddOnExtensionFetcher(final String pathInstalledAddOnSid, - final String pathSid) { + public InstalledAddOnExtensionFetcher( + final String pathInstalledAddOnSid, + final String pathSid + ) { this.pathInstalledAddOnSid = pathInstalledAddOnSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched InstalledAddOnExtension - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public InstalledAddOnExtension fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}"; + + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/marketplace/InstalledAddOns/" + this.pathInstalledAddOnSid + "/Extensions/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOnExtension fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "InstalledAddOnExtension fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public InstalledAddOnExtension fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return InstalledAddOnExtension.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOnExtension content = InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionReader.java b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionReader.java index d300f3ab2a..8f19d0a734 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionReader.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace.installedaddon; @@ -10,164 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class InstalledAddOnExtensionReader + extends Reader { + + private String pathInstalledAddOnSid; + private Long pageSize; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class InstalledAddOnExtensionReader extends Reader { - private final String pathInstalledAddOnSid; - - /** - * Construct a new InstalledAddOnExtensionReader. - * - * @param pathInstalledAddOnSid The installed_add_on_sid - */ public InstalledAddOnExtensionReader(final String pathInstalledAddOnSid) { this.pathInstalledAddOnSid = pathInstalledAddOnSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return InstalledAddOnExtension ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public InstalledAddOnExtensionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return InstalledAddOnExtension ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + InstalledAddOnExtension.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions"; + + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/marketplace/InstalledAddOns/" + this.pathInstalledAddOnSid + "/Extensions", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return InstalledAddOnExtension ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "extensions", + response.getContent(), + InstalledAddOnExtension.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "InstalledAddOnExtension read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "extensions", + response.getContent(), + InstalledAddOnExtension.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of InstalledAddOnExtension Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("InstalledAddOnExtension read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "extensions", - response.getContent(), - InstalledAddOnExtension.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionUpdater.java b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionUpdater.java index 50e8b9ea9f..15517b3d95 100644 --- a/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionUpdater.java +++ b/src/main/java/com/twilio/rest/preview/marketplace/installedaddon/InstalledAddOnExtensionUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.marketplace.installedaddon; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,79 +27,106 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class InstalledAddOnExtensionUpdater extends Updater { - private final String pathInstalledAddOnSid; - private final String pathSid; - private final Boolean enabled; +public class InstalledAddOnExtensionUpdater + extends Updater { + + private String pathInstalledAddOnSid; + private String pathSid; + private Boolean enabled; - /** - * Construct a new InstalledAddOnExtensionUpdater. - * - * @param pathInstalledAddOnSid The installed_add_on_sid - * @param pathSid The sid - * @param enabled A Boolean indicating if the Extension will be invoked - */ - public InstalledAddOnExtensionUpdater(final String pathInstalledAddOnSid, - final String pathSid, - final Boolean enabled) { + public InstalledAddOnExtensionUpdater( + final String pathInstalledAddOnSid, + final String pathSid, + final Boolean enabled + ) { this.pathInstalledAddOnSid = pathInstalledAddOnSid; this.pathSid = pathSid; this.enabled = enabled; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated InstalledAddOnExtension - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public InstalledAddOnExtension update(final TwilioRestClient client) { + public InstalledAddOnExtensionUpdater setEnabled(final Boolean enabled) { + this.enabled = enabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/marketplace/InstalledAddOns/{InstalledAddOnSid}/Extensions/{Sid}"; + + path = + path.replace( + "{" + "InstalledAddOnSid" + "}", + this.pathInstalledAddOnSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/marketplace/InstalledAddOns/" + this.pathInstalledAddOnSid + "/Extensions/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("InstalledAddOnExtension update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "InstalledAddOnExtension update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return InstalledAddOnExtension.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public InstalledAddOnExtension update(final TwilioRestClient client) { + Response response = makeRequest(client); + return InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + InstalledAddOnExtension content = InstalledAddOnExtension.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (enabled != null) { - request.addPostParam("Enabled", enabled.toString()); + Serializer.toString( + request, + "Enabled", + enabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/proxy/Service.java b/src/main/java/com/twilio/rest/preview/proxy/Service.java deleted file mode 100644 index 22148454bd..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/Service.java +++ /dev/null @@ -1,300 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Service extends Resource { - private static final long serialVersionUID = 163526733488046L; - - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid A string that uniquely identifies this Service. - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); - } - - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ - public static ServiceReader reader() { - return new ServiceReader(); - } - - /** - * Create a ServiceCreator to execute create. - * - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator() { - return new ServiceCreator(); - } - - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid A string that uniquely identifies this Service. - * @return ServiceDeleter capable of executing the delete - */ - public static ServiceDeleter deleter(final String pathSid) { - return new ServiceDeleter(pathSid); - } - - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid A string that uniquely identifies this Service. - * @return ServiceUpdater capable of executing the update - */ - public static ServiceUpdater updater(final String pathSid) { - return new ServiceUpdater(pathSid); - } - - /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Service.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Service.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String friendlyName; - private final String accountSid; - private final Boolean autoCreate; - private final URI callbackUrl; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("auto_create") - final Boolean autoCreate, - @JsonProperty("callback_url") - final URI callbackUrl, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.friendlyName = friendlyName; - this.accountSid = accountSid; - this.autoCreate = autoCreate; - this.callbackUrl = callbackUrl; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; - } - - /** - * Returns The A string that uniquely identifies this Service.. - * - * @return A string that uniquely identifies this Service. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The A human readable description of this resource. - * - * @return A human readable description of this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Boolean flag specifying whether to auto-create threads.. - * - * @return Boolean flag specifying whether to auto-create threads. - */ - public final Boolean getAutoCreate() { - return this.autoCreate; - } - - /** - * Returns The URL Twilio will request for callbacks.. - * - * @return URL Twilio will request for callbacks. - */ - public final URI getCallbackUrl() { - return this.callbackUrl; - } - - /** - * Returns The The date this Service was created. - * - * @return The date this Service was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Service was updated. - * - * @return The date this Service was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(autoCreate, other.autoCreate) && - Objects.equals(callbackUrl, other.callbackUrl) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - friendlyName, - accountSid, - autoCreate, - callbackUrl, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("friendlyName", friendlyName) - .add("accountSid", accountSid) - .add("autoCreate", autoCreate) - .add("callbackUrl", callbackUrl) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/ServiceCreator.java b/src/main/java/com/twilio/rest/preview/proxy/ServiceCreator.java deleted file mode 100644 index 7a1bad8a4d..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/ServiceCreator.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceCreator extends Creator { - private String friendlyName; - private Boolean autoCreate; - private URI callbackUrl; - - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ - public ServiceCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Boolean flag specifying whether to create threads when a user communticates - * out of band.. - * - * @param autoCreate Boolean flag specifying whether to auto-create threads. - * @return this - */ - public ServiceCreator setAutoCreate(final Boolean autoCreate) { - this.autoCreate = autoCreate; - return this; - } - - /** - * The URL Twilio will request for callback notifications.. - * - * @param callbackUrl URL Twilio will request for callbacks. - * @return this - */ - public ServiceCreator setCallbackUrl(final URI callbackUrl) { - this.callbackUrl = callbackUrl; - return this; - } - - /** - * The URL Twilio will request for callback notifications.. - * - * @param callbackUrl URL Twilio will request for callbacks. - * @return this - */ - public ServiceCreator setCallbackUrl(final String callbackUrl) { - return setCallbackUrl(Promoter.uriFromString(callbackUrl)); - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (autoCreate != null) { - request.addPostParam("AutoCreate", autoCreate.toString()); - } - - if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/ServiceDeleter.java b/src/main/java/com/twilio/rest/preview/proxy/ServiceDeleter.java deleted file mode 100644 index 5624f573ad..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/ServiceDeleter.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceDeleter extends Deleter { - private final String pathSid; - - /** - * Construct a new ServiceDeleter. - * - * @param pathSid A string that uniquely identifies this Service. - */ - public ServiceDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/ServiceFetcher.java b/src/main/java/com/twilio/rest/preview/proxy/ServiceFetcher.java deleted file mode 100644 index 876a1cd99a..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/ServiceFetcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceFetcher extends Fetcher { - private final String pathSid; - - /** - * Construct a new ServiceFetcher. - * - * @param pathSid A string that uniquely identifies this Service. - */ - public ServiceFetcher(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/ServiceReader.java b/src/main/java/com/twilio/rest/preview/proxy/ServiceReader.java deleted file mode 100644 index 3c5a9f68a0..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/ServiceReader.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/ServiceUpdater.java b/src/main/java/com/twilio/rest/preview/proxy/ServiceUpdater.java deleted file mode 100644 index d4a4140f46..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/ServiceUpdater.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy; - -import com.twilio.base.Updater; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceUpdater extends Updater { - private final String pathSid; - private String friendlyName; - private Boolean autoCreate; - private URI callbackUrl; - - /** - * Construct a new ServiceUpdater. - * - * @param pathSid A string that uniquely identifies this Service. - */ - public ServiceUpdater(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ - public ServiceUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Boolean flag specifying whether to create threads when a user communticates - * out of band.. - * - * @param autoCreate Boolean flag specifying whether to auto-create threads. - * @return this - */ - public ServiceUpdater setAutoCreate(final Boolean autoCreate) { - this.autoCreate = autoCreate; - return this; - } - - /** - * The URL Twilio will request for callback notifications.. - * - * @param callbackUrl URL Twilio will request for callbacks. - * @return this - */ - public ServiceUpdater setCallbackUrl(final URI callbackUrl) { - this.callbackUrl = callbackUrl; - return this; - } - - /** - * The URL Twilio will request for callback notifications.. - * - * @param callbackUrl URL Twilio will request for callbacks. - * @return this - */ - public ServiceUpdater setCallbackUrl(final String callbackUrl) { - return setCallbackUrl(Promoter.uriFromString(callbackUrl)); - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (autoCreate != null) { - request.addPostParam("AutoCreate", autoCreate.toString()); - } - - if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumber.java b/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumber.java deleted file mode 100644 index d31ec7922a..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumber.java +++ /dev/null @@ -1,301 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class PhoneNumber extends Resource { - private static final long serialVersionUID = 193136223397872L; - - /** - * Create a PhoneNumberCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param sid Delete by unique phone-number Sid - * @return PhoneNumberCreator capable of executing the create - */ - public static PhoneNumberCreator creator(final String pathServiceSid, - final String sid) { - return new PhoneNumberCreator(pathServiceSid, sid); - } - - /** - * Create a PhoneNumberDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid Delete by unique phone-number Sid - * @return PhoneNumberDeleter capable of executing the delete - */ - public static PhoneNumberDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new PhoneNumberDeleter(pathServiceSid, pathSid); - } - - /** - * Create a PhoneNumberReader to execute read. - * - * @param pathServiceSid The service_sid - * @return PhoneNumberReader capable of executing the read - */ - public static PhoneNumberReader reader(final String pathServiceSid) { - return new PhoneNumberReader(pathServiceSid); - } - - /** - * Create a PhoneNumberFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid Fetch by unique phone-number Sid - * @return PhoneNumberFetcher capable of executing the fetch - */ - public static PhoneNumberFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new PhoneNumberFetcher(pathServiceSid, pathSid); - } - - /** - * Converts a JSON String into a PhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, PhoneNumber.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a PhoneNumber object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return PhoneNumber object represented by the provided JSON - */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, PhoneNumber.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String countryCode; - private final List capabilities; - private final URI url; - - @JsonCreator - private PhoneNumber(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("country_code") - final String countryCode, - @JsonProperty("capabilities") - final List capabilities, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.phoneNumber = phoneNumber; - this.countryCode = countryCode; - this.capabilities = capabilities; - this.url = url; - } - - /** - * Returns The A string that uniquely identifies this resource. - * - * @return A string that uniquely identifies this resource - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The phone number. - * - * @return The phone number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - - /** - * Returns The The ISO 3166-1 alpha-2 country code. - * - * @return The ISO 3166-1 alpha-2 country code - */ - public final String getCountryCode() { - return this.countryCode; - } - - /** - * Returns The Indicate if a phone can receive calls or messages. - * - * @return Indicate if a phone can receive calls or messages - */ - public final List getCapabilities() { - return this.capabilities; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - PhoneNumber other = (PhoneNumber) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(countryCode, other.countryCode) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - phoneNumber, - countryCode, - capabilities, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("phoneNumber", phoneNumber) - .add("countryCode", countryCode) - .add("capabilities", capabilities) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberCreator.java b/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberCreator.java deleted file mode 100644 index cbe30ac240..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberCreator.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class PhoneNumberCreator extends Creator { - private final String pathServiceSid; - private final String sid; - - /** - * Construct a new PhoneNumberCreator. - * - * @param pathServiceSid The service_sid - * @param sid Delete by unique phone-number Sid - */ - public PhoneNumberCreator(final String pathServiceSid, - final String sid) { - this.pathServiceSid = pathServiceSid; - this.sid = sid; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/PhoneNumbers", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("PhoneNumber creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (sid != null) { - request.addPostParam("Sid", sid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberDeleter.java b/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberDeleter.java deleted file mode 100644 index 62c00ba898..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class PhoneNumberDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new PhoneNumberDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid Delete by unique phone-number Sid - */ - public PhoneNumberDeleter(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/PhoneNumbers/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("PhoneNumber delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberFetcher.java deleted file mode 100644 index b2838bdbe8..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class PhoneNumberFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new PhoneNumberFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid Fetch by unique phone-number Sid - */ - public PhoneNumberFetcher(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/PhoneNumbers/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberReader.java b/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberReader.java deleted file mode 100644 index 8b18ee942f..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/PhoneNumberReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class PhoneNumberReader extends Reader { - private final String pathServiceSid; - - /** - * Construct a new PhoneNumberReader. - * - * @param pathServiceSid The service_sid - */ - public PhoneNumberReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/PhoneNumbers", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of PhoneNumber Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("PhoneNumber read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "phone_numbers", - response.getContent(), - PhoneNumber.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/Session.java b/src/main/java/com/twilio/rest/preview/proxy/service/Session.java deleted file mode 100644 index bef94a1cb6..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/Session.java +++ /dev/null @@ -1,382 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Session extends Resource { - private static final long serialVersionUID = 239445933669161L; - - public enum Status { - IN_PROGESS("in-progess"), - COMPLETED("completed"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - - /** - * Create a SessionFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - * @return SessionFetcher capable of executing the fetch - */ - public static SessionFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new SessionFetcher(pathServiceSid, pathSid); - } - - /** - * Create a SessionReader to execute read. - * - * @param pathServiceSid Service Sid. - * @return SessionReader capable of executing the read - */ - public static SessionReader reader(final String pathServiceSid) { - return new SessionReader(pathServiceSid); - } - - /** - * Create a SessionCreator to execute create. - * - * @param pathServiceSid Service Sid. - * @return SessionCreator capable of executing the create - */ - public static SessionCreator creator(final String pathServiceSid) { - return new SessionCreator(pathServiceSid); - } - - /** - * Create a SessionDeleter to execute delete. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - * @return SessionDeleter capable of executing the delete - */ - public static SessionDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new SessionDeleter(pathServiceSid, pathSid); - } - - /** - * Create a SessionUpdater to execute update. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - * @return SessionUpdater capable of executing the update - */ - public static SessionUpdater updater(final String pathServiceSid, - final String pathSid) { - return new SessionUpdater(pathServiceSid, pathSid); - } - - /** - * Converts a JSON String into a Session object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Session object represented by the provided JSON - */ - public static Session fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Session.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Session object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Session object represented by the provided JSON - */ - public static Session fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Session.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String serviceSid; - private final String accountSid; - private final String uniqueName; - private final Integer ttl; - private final Session.Status status; - private final DateTime startTime; - private final DateTime endTime; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Session(@JsonProperty("sid") - final String sid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("ttl") - final Integer ttl, - @JsonProperty("status") - final Session.Status status, - @JsonProperty("start_time") - final String startTime, - @JsonProperty("end_time") - final String endTime, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.serviceSid = serviceSid; - this.accountSid = accountSid; - this.uniqueName = uniqueName; - this.ttl = ttl; - this.status = status; - this.startTime = DateConverter.iso8601DateTimeFromString(startTime); - this.endTime = DateConverter.iso8601DateTimeFromString(endTime); - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; - } - - /** - * Returns The A string that uniquely identifies this Session.. - * - * @return A string that uniquely identifies this Session. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The A unique, developer assigned name of this Session.. - * - * @return A unique, developer assigned name of this Session. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The How long will this session stay open, in seconds.. - * - * @return How long will this session stay open, in seconds. - */ - public final Integer getTtl() { - return this.ttl; - } - - /** - * Returns The The Status of this Session. - * - * @return The Status of this Session - */ - public final Session.Status getStatus() { - return this.status; - } - - /** - * Returns The The date this Session was started. - * - * @return The date this Session was started - */ - public final DateTime getStartTime() { - return this.startTime; - } - - /** - * Returns The The date this Session was ended. - * - * @return The date this Session was ended - */ - public final DateTime getEndTime() { - return this.endTime; - } - - /** - * Returns The The date this Session was created. - * - * @return The date this Session was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Session was updated. - * - * @return The date this Session was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this Session.. - * - * @return The URL of this Session. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Session other = (Session) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(ttl, other.ttl) && - Objects.equals(status, other.status) && - Objects.equals(startTime, other.startTime) && - Objects.equals(endTime, other.endTime) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - serviceSid, - accountSid, - uniqueName, - ttl, - status, - startTime, - endTime, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("uniqueName", uniqueName) - .add("ttl", ttl) - .add("status", status) - .add("startTime", startTime) - .add("endTime", endTime) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/SessionCreator.java b/src/main/java/com/twilio/rest/preview/proxy/service/SessionCreator.java deleted file mode 100644 index c940e568ee..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/SessionCreator.java +++ /dev/null @@ -1,163 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.List; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SessionCreator extends Creator { - private final String pathServiceSid; - private String uniqueName; - private Integer ttl; - private Session.Status status; - private List participants; - - /** - * Construct a new SessionCreator. - * - * @param pathServiceSid Service Sid. - */ - public SessionCreator(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Provides a unique and addressable name to be assigned to this Session, - * assigned by the developer, to be optionally used in addition to SID.. - * - * @param uniqueName A unique, developer assigned name of this Session. - * @return this - */ - public SessionCreator setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * How long will this session stay open, in seconds. Each new interaction resets - * this timer.. - * - * @param ttl How long will this session stay open, in seconds. - * @return this - */ - public SessionCreator setTtl(final Integer ttl) { - this.ttl = ttl; - return this; - } - - /** - * The Status of this Session. One of `in-progess` or `completed`.. - * - * @param status The Status of this Session - * @return this - */ - public SessionCreator setStatus(final Session.Status status) { - this.status = status; - return this; - } - - /** - * The participants. - * - * @param participants The participants - * @return this - */ - public SessionCreator setParticipants(final List participants) { - this.participants = participants; - return this; - } - - /** - * The participants. - * - * @param participants The participants - * @return this - */ - public SessionCreator setParticipants(final String participants) { - return setParticipants(Promoter.listOfOne(participants)); - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Session - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Session create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Session creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Session.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - - if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); - } - - if (status != null) { - request.addPostParam("Status", status.toString()); - } - - if (participants != null) { - for (String prop : participants) { - request.addPostParam("Participants", prop); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/SessionDeleter.java b/src/main/java/com/twilio/rest/preview/proxy/service/SessionDeleter.java deleted file mode 100644 index 82e9f585bd..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/SessionDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SessionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new SessionDeleter. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - */ - public SessionDeleter(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Session delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/SessionFetcher.java b/src/main/java/com/twilio/rest/preview/proxy/service/SessionFetcher.java deleted file mode 100644 index 2df605a2fa..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/SessionFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SessionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new SessionFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - */ - public SessionFetcher(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Session - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Session fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Session fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Session.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/SessionReader.java b/src/main/java/com/twilio/rest/preview/proxy/service/SessionReader.java deleted file mode 100644 index f66a1ced4f..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/SessionReader.java +++ /dev/null @@ -1,206 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SessionReader extends Reader { - private final String pathServiceSid; - private String uniqueName; - private Session.Status status; - - /** - * Construct a new SessionReader. - * - * @param pathServiceSid Service Sid. - */ - public SessionReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Provides a unique and addressable name to be assigned to this Session, - * assigned by the developer, to be optionally used in addition to SID.. - * - * @param uniqueName A unique, developer assigned name of this Session. - * @return this - */ - public SessionReader setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * The Status of this Session. One of `in-progess` or `completed`.. - * - * @param status The Status of this Session - * @return this - */ - public SessionReader setStatus(final Session.Status status) { - this.status = status; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Session ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Session ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Session ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Session Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Session read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "sessions", - response.getContent(), - Session.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (uniqueName != null) { - request.addQueryParam("UniqueName", uniqueName); - } - - if (status != null) { - request.addQueryParam("Status", status.toString()); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/SessionUpdater.java b/src/main/java/com/twilio/rest/preview/proxy/service/SessionUpdater.java deleted file mode 100644 index b9d8271bc8..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/SessionUpdater.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Updater; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.List; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SessionUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; - private String uniqueName; - private Integer ttl; - private Session.Status status; - private List participants; - - /** - * Construct a new SessionUpdater. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - */ - public SessionUpdater(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Provides a unique and addressable name to be assigned to this Session, - * assigned by the developer, to be optionally used in addition to SID.. - * - * @param uniqueName A unique, developer assigned name of this Session. - * @return this - */ - public SessionUpdater setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * How long will this session stay open, in seconds. Each new interaction resets - * this timer.. - * - * @param ttl How long will this session stay open, in seconds. - * @return this - */ - public SessionUpdater setTtl(final Integer ttl) { - this.ttl = ttl; - return this; - } - - /** - * The Status of this Session. One of `in-progess` or `completed`.. - * - * @param status The Status of this Session - * @return this - */ - public SessionUpdater setStatus(final Session.Status status) { - this.status = status; - return this; - } - - /** - * The participants. - * - * @param participants The participants - * @return this - */ - public SessionUpdater setParticipants(final List participants) { - this.participants = participants; - return this; - } - - /** - * The participants. - * - * @param participants The participants - * @return this - */ - public SessionUpdater setParticipants(final String participants) { - return setParticipants(Promoter.listOfOne(participants)); - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Session - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Session update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Session update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Session.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - - if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); - } - - if (status != null) { - request.addPostParam("Status", status.toString()); - } - - if (participants != null) { - for (String prop : participants) { - request.addPostParam("Participants", prop); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCode.java b/src/main/java/com/twilio/rest/preview/proxy/service/ShortCode.java deleted file mode 100644 index 4ad535dec8..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCode.java +++ /dev/null @@ -1,301 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class ShortCode extends Resource { - private static final long serialVersionUID = 158453184063477L; - - /** - * Create a ShortCodeCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param sid Delete by unique shortcode Sid - * @return ShortCodeCreator capable of executing the create - */ - public static ShortCodeCreator creator(final String pathServiceSid, - final String sid) { - return new ShortCodeCreator(pathServiceSid, sid); - } - - /** - * Create a ShortCodeDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid Delete by unique shortcode Sid - * @return ShortCodeDeleter capable of executing the delete - */ - public static ShortCodeDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new ShortCodeDeleter(pathServiceSid, pathSid); - } - - /** - * Create a ShortCodeReader to execute read. - * - * @param pathServiceSid The service_sid - * @return ShortCodeReader capable of executing the read - */ - public static ShortCodeReader reader(final String pathServiceSid) { - return new ShortCodeReader(pathServiceSid); - } - - /** - * Create a ShortCodeFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid Fetch by unique shortcode Sid - * @return ShortCodeFetcher capable of executing the fetch - */ - public static ShortCodeFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new ShortCodeFetcher(pathServiceSid, pathSid); - } - - /** - * Converts a JSON String into a ShortCode object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, ShortCode.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a ShortCode object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, ShortCode.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String shortCode; - private final String countryCode; - private final List> capabilities; - private final URI url; - - @JsonCreator - private ShortCode(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("short_code") - final String shortCode, - @JsonProperty("country_code") - final String countryCode, - @JsonProperty("capabilities") - final List> capabilities, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.shortCode = shortCode; - this.countryCode = countryCode; - this.capabilities = capabilities; - this.url = url; - } - - /** - * Returns The A string that uniquely identifies this resource. - * - * @return A string that uniquely identifies this resource - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The short code. e.g., 894546.. - * - * @return The short code. e.g., 894546. - */ - public final String getShortCode() { - return this.shortCode; - } - - /** - * Returns The The ISO 3166-1 alpha-2 country code. - * - * @return The ISO 3166-1 alpha-2 country code - */ - public final String getCountryCode() { - return this.countryCode; - } - - /** - * Returns The Indicate if a shortcode can receive messages. - * - * @return Indicate if a shortcode can receive messages - */ - public final List> getCapabilities() { - return this.capabilities; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - ShortCode other = (ShortCode) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(shortCode, other.shortCode) && - Objects.equals(countryCode, other.countryCode) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - shortCode, - countryCode, - capabilities, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("shortCode", shortCode) - .add("countryCode", countryCode) - .add("capabilities", capabilities) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeCreator.java b/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeCreator.java deleted file mode 100644 index ba238068e6..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeCreator.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ShortCodeCreator extends Creator { - private final String pathServiceSid; - private final String sid; - - /** - * Construct a new ShortCodeCreator. - * - * @param pathServiceSid The service_sid - * @param sid Delete by unique shortcode Sid - */ - public ShortCodeCreator(final String pathServiceSid, - final String sid) { - this.pathServiceSid = pathServiceSid; - this.sid = sid; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created ShortCode - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ShortCode create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/ShortCodes", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (sid != null) { - request.addPostParam("Sid", sid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeDeleter.java b/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeDeleter.java deleted file mode 100644 index d66d55ecf4..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ShortCodeDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new ShortCodeDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid Delete by unique shortcode Sid - */ - public ShortCodeDeleter(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/ShortCodes/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeFetcher.java b/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeFetcher.java deleted file mode 100644 index ddd72ada3a..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ShortCodeFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new ShortCodeFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid Fetch by unique shortcode Sid - */ - public ShortCodeFetcher(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched ShortCode - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ShortCode fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/ShortCodes/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeReader.java b/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeReader.java deleted file mode 100644 index 7861a15027..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/ShortCodeReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ShortCodeReader extends Reader { - private final String pathServiceSid; - - /** - * Construct a new ShortCodeReader. - * - * @param pathServiceSid The service_sid - */ - public ShortCodeReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/ShortCodes", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of ShortCode Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "short_codes", - response.getContent(), - ShortCode.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/Interaction.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/Interaction.java deleted file mode 100644 index 72b19d379a..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/Interaction.java +++ /dev/null @@ -1,495 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Interaction extends Resource { - private static final long serialVersionUID = 79439226975965L; - - public enum Status { - COMPLETED("completed"), - IN_PROGRESS("in-progress"), - FAILED("failed"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - - public enum ResourceStatus { - QUEUED("queued"), - SENDING("sending"), - SENT("sent"), - FAILED("failed"), - DELIVERED("delivered"), - UNDELIVERED("undelivered"); - - private final String value; - - private ResourceStatus(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a ResourceStatus from a string. - * @param value string value - * @return generated ResourceStatus - */ - @JsonCreator - public static ResourceStatus forValue(final String value) { - return Promoter.enumFromString(value, ResourceStatus.values()); - } - } - - /** - * Create a InteractionFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Interaction. - * @return InteractionFetcher capable of executing the fetch - */ - public static InteractionFetcher fetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new InteractionFetcher(pathServiceSid, pathSessionSid, pathSid); - } - - /** - * Create a InteractionReader to execute read. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @return InteractionReader capable of executing the read - */ - public static InteractionReader reader(final String pathServiceSid, - final String pathSessionSid) { - return new InteractionReader(pathServiceSid, pathSessionSid); - } - - /** - * Converts a JSON String into a Interaction object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Interaction object represented by the provided JSON - */ - public static Interaction fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Interaction.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Interaction object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Interaction object represented by the provided JSON - */ - public static Interaction fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Interaction.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String sessionSid; - private final String serviceSid; - private final String accountSid; - private final String data; - private final Interaction.Status status; - private final String inboundParticipantSid; - private final String inboundResourceSid; - private final Interaction.ResourceStatus inboundResourceStatus; - private final String inboundResourceType; - private final URI inboundResourceUrl; - private final String outboundParticipantSid; - private final String outboundResourceSid; - private final Interaction.ResourceStatus outboundResourceStatus; - private final String outboundResourceType; - private final URI outboundResourceUrl; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private Interaction(@JsonProperty("sid") - final String sid, - @JsonProperty("session_sid") - final String sessionSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("data") - final String data, - @JsonProperty("status") - final Interaction.Status status, - @JsonProperty("inbound_participant_sid") - final String inboundParticipantSid, - @JsonProperty("inbound_resource_sid") - final String inboundResourceSid, - @JsonProperty("inbound_resource_status") - final Interaction.ResourceStatus inboundResourceStatus, - @JsonProperty("inbound_resource_type") - final String inboundResourceType, - @JsonProperty("inbound_resource_url") - final URI inboundResourceUrl, - @JsonProperty("outbound_participant_sid") - final String outboundParticipantSid, - @JsonProperty("outbound_resource_sid") - final String outboundResourceSid, - @JsonProperty("outbound_resource_status") - final Interaction.ResourceStatus outboundResourceStatus, - @JsonProperty("outbound_resource_type") - final String outboundResourceType, - @JsonProperty("outbound_resource_url") - final URI outboundResourceUrl, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.sessionSid = sessionSid; - this.serviceSid = serviceSid; - this.accountSid = accountSid; - this.data = data; - this.status = status; - this.inboundParticipantSid = inboundParticipantSid; - this.inboundResourceSid = inboundResourceSid; - this.inboundResourceStatus = inboundResourceStatus; - this.inboundResourceType = inboundResourceType; - this.inboundResourceUrl = inboundResourceUrl; - this.outboundParticipantSid = outboundParticipantSid; - this.outboundResourceSid = outboundResourceSid; - this.outboundResourceStatus = outboundResourceStatus; - this.outboundResourceType = outboundResourceType; - this.outboundResourceUrl = outboundResourceUrl; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - } - - /** - * Returns The A string that uniquely identifies this Interaction.. - * - * @return A string that uniquely identifies this Interaction. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Session Sid.. - * - * @return Session Sid. - */ - public final String getSessionSid() { - return this.sessionSid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The What happened in this Interaction.. - * - * @return What happened in this Interaction. - */ - public final String getData() { - return this.data; - } - - /** - * Returns The The Status of this Interaction. - * - * @return The Status of this Interaction - */ - public final Interaction.Status getStatus() { - return this.status; - } - - /** - * Returns The The inbound_participant_sid. - * - * @return The inbound_participant_sid - */ - public final String getInboundParticipantSid() { - return this.inboundParticipantSid; - } - - /** - * Returns The The SID of the inbound resource.. - * - * @return The SID of the inbound resource. - */ - public final String getInboundResourceSid() { - return this.inboundResourceSid; - } - - /** - * Returns The The Inbound Resource Status of this Interaction. - * - * @return The Inbound Resource Status of this Interaction - */ - public final Interaction.ResourceStatus getInboundResourceStatus() { - return this.inboundResourceStatus; - } - - /** - * Returns The The Twilio object type of the inbound resource.. - * - * @return The Twilio object type of the inbound resource. - */ - public final String getInboundResourceType() { - return this.inboundResourceType; - } - - /** - * Returns The The URL of the inbound resource.. - * - * @return The URL of the inbound resource. - */ - public final URI getInboundResourceUrl() { - return this.inboundResourceUrl; - } - - /** - * Returns The The outbound_participant_sid. - * - * @return The outbound_participant_sid - */ - public final String getOutboundParticipantSid() { - return this.outboundParticipantSid; - } - - /** - * Returns The The SID of the outbound resource.. - * - * @return The SID of the outbound resource. - */ - public final String getOutboundResourceSid() { - return this.outboundResourceSid; - } - - /** - * Returns The The Outbound Resource Status of this Interaction. - * - * @return The Outbound Resource Status of this Interaction - */ - public final Interaction.ResourceStatus getOutboundResourceStatus() { - return this.outboundResourceStatus; - } - - /** - * Returns The The Twilio object type of the outbound resource.. - * - * @return The Twilio object type of the outbound resource. - */ - public final String getOutboundResourceType() { - return this.outboundResourceType; - } - - /** - * Returns The The URL of the outbound resource.. - * - * @return The URL of the outbound resource. - */ - public final URI getOutboundResourceUrl() { - return this.outboundResourceUrl; - } - - /** - * Returns The The date this Interaction was created. - * - * @return The date this Interaction was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Interaction was updated. - * - * @return The date this Interaction was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this Interaction.. - * - * @return The URL of this Interaction. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Interaction other = (Interaction) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(sessionSid, other.sessionSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(data, other.data) && - Objects.equals(status, other.status) && - Objects.equals(inboundParticipantSid, other.inboundParticipantSid) && - Objects.equals(inboundResourceSid, other.inboundResourceSid) && - Objects.equals(inboundResourceStatus, other.inboundResourceStatus) && - Objects.equals(inboundResourceType, other.inboundResourceType) && - Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && - Objects.equals(outboundParticipantSid, other.outboundParticipantSid) && - Objects.equals(outboundResourceSid, other.outboundResourceSid) && - Objects.equals(outboundResourceStatus, other.outboundResourceStatus) && - Objects.equals(outboundResourceType, other.outboundResourceType) && - Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - sessionSid, - serviceSid, - accountSid, - data, - status, - inboundParticipantSid, - inboundResourceSid, - inboundResourceStatus, - inboundResourceType, - inboundResourceUrl, - outboundParticipantSid, - outboundResourceSid, - outboundResourceStatus, - outboundResourceType, - outboundResourceUrl, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("sessionSid", sessionSid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("data", data) - .add("status", status) - .add("inboundParticipantSid", inboundParticipantSid) - .add("inboundResourceSid", inboundResourceSid) - .add("inboundResourceStatus", inboundResourceStatus) - .add("inboundResourceType", inboundResourceType) - .add("inboundResourceUrl", inboundResourceUrl) - .add("outboundParticipantSid", outboundParticipantSid) - .add("outboundResourceSid", outboundResourceSid) - .add("outboundResourceStatus", outboundResourceStatus) - .add("outboundResourceType", outboundResourceType) - .add("outboundResourceUrl", outboundResourceUrl) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/InteractionFetcher.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/InteractionFetcher.java deleted file mode 100644 index e3e9412974..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/InteractionFetcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class InteractionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - - /** - * Construct a new InteractionFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Interaction. - */ - public InteractionFetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Interaction - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Interaction fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Interactions/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Interaction fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Interaction.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/InteractionReader.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/InteractionReader.java deleted file mode 100644 index bc139a6e68..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/InteractionReader.java +++ /dev/null @@ -1,213 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class InteractionReader extends Reader { - private final String pathServiceSid; - private final String pathSessionSid; - private Interaction.ResourceStatus inboundParticipantStatus; - private Interaction.ResourceStatus outboundParticipantStatus; - - /** - * Construct a new InteractionReader. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - */ - public InteractionReader(final String pathServiceSid, - final String pathSessionSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - } - - /** - * The Inbound Participant Status of this Interaction. One of `completed`, - * `in-progress` or `failed`.. - * - * @param inboundParticipantStatus The Inbound Participant Status of this - * Interaction - * @return this - */ - public InteractionReader setInboundParticipantStatus(final Interaction.ResourceStatus inboundParticipantStatus) { - this.inboundParticipantStatus = inboundParticipantStatus; - return this; - } - - /** - * The Outbound Participant Status of this Interaction. One of `completed`, - * `in-progress` or `failed`.. - * - * @param outboundParticipantStatus The Outbound Participant Status of this - * Interaction - * @return this - */ - public InteractionReader setOutboundParticipantStatus(final Interaction.ResourceStatus outboundParticipantStatus) { - this.outboundParticipantStatus = outboundParticipantStatus; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Interaction ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Interaction ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Interactions", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Interaction ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Interaction Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Interaction read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "interactions", - response.getContent(), - Interaction.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (inboundParticipantStatus != null) { - request.addQueryParam("InboundParticipantStatus", inboundParticipantStatus.toString()); - } - - if (outboundParticipantStatus != null) { - request.addQueryParam("OutboundParticipantStatus", outboundParticipantStatus.toString()); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/Participant.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/Participant.java deleted file mode 100644 index d0e6dfb414..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/Participant.java +++ /dev/null @@ -1,398 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Participant extends Resource { - private static final long serialVersionUID = 266625125959809L; - - public enum ParticipantType { - SMS("sms"), - VOICE("voice"), - PHONE("phone"); - - private final String value; - - private ParticipantType(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a ParticipantType from a string. - * @param value string value - * @return generated ParticipantType - */ - @JsonCreator - public static ParticipantType forValue(final String value) { - return Promoter.enumFromString(value, ParticipantType.values()); - } - } - - /** - * Create a ParticipantFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - * @return ParticipantFetcher capable of executing the fetch - */ - public static ParticipantFetcher fetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new ParticipantFetcher(pathServiceSid, pathSessionSid, pathSid); - } - - /** - * Create a ParticipantReader to execute read. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @return ParticipantReader capable of executing the read - */ - public static ParticipantReader reader(final String pathServiceSid, - final String pathSessionSid) { - return new ParticipantReader(pathServiceSid, pathSessionSid); - } - - /** - * Create a ParticipantCreator to execute create. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param identifier The Participant's contact identifier, normally a phone - * number. - * @return ParticipantCreator capable of executing the create - */ - public static ParticipantCreator creator(final String pathServiceSid, - final String pathSessionSid, - final String identifier) { - return new ParticipantCreator(pathServiceSid, pathSessionSid, identifier); - } - - /** - * Create a ParticipantDeleter to execute delete. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - * @return ParticipantDeleter capable of executing the delete - */ - public static ParticipantDeleter deleter(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new ParticipantDeleter(pathServiceSid, pathSessionSid, pathSid); - } - - /** - * Create a ParticipantUpdater to execute update. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - * @return ParticipantUpdater capable of executing the update - */ - public static ParticipantUpdater updater(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new ParticipantUpdater(pathServiceSid, pathSessionSid, pathSid); - } - - /** - * Converts a JSON String into a Participant object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Participant.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Participant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Participant object represented by the provided JSON - */ - public static Participant fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Participant.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String sessionSid; - private final String serviceSid; - private final String accountSid; - private final String friendlyName; - private final Participant.ParticipantType participantType; - private final String identifier; - private final String proxyIdentifier; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Participant(@JsonProperty("sid") - final String sid, - @JsonProperty("session_sid") - final String sessionSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("participant_type") - final Participant.ParticipantType participantType, - @JsonProperty("identifier") - final String identifier, - @JsonProperty("proxy_identifier") - final String proxyIdentifier, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.sessionSid = sessionSid; - this.serviceSid = serviceSid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.participantType = participantType; - this.identifier = identifier; - this.proxyIdentifier = proxyIdentifier; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; - } - - /** - * Returns The A string that uniquely identifies this Participant.. - * - * @return A string that uniquely identifies this Participant. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Session Sid.. - * - * @return Session Sid. - */ - public final String getSessionSid() { - return this.sessionSid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The A human readable description of this resource. - * - * @return A human readable description of this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The Type of this Participant. - * - * @return The Type of this Participant - */ - public final Participant.ParticipantType getParticipantType() { - return this.participantType; - } - - /** - * Returns The The Participant's contact identifier, normally a phone number.. - * - * @return The Participant's contact identifier, normally a phone number. - */ - public final String getIdentifier() { - return this.identifier; - } - - /** - * Returns The What this Participant communicates with, normally a phone - * number.. - * - * @return What this Participant communicates with, normally a phone number. - */ - public final String getProxyIdentifier() { - return this.proxyIdentifier; - } - - /** - * Returns The The date this Participant was created. - * - * @return The date this Participant was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Participant was updated. - * - * @return The date this Participant was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Participant other = (Participant) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(sessionSid, other.sessionSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(participantType, other.participantType) && - Objects.equals(identifier, other.identifier) && - Objects.equals(proxyIdentifier, other.proxyIdentifier) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - sessionSid, - serviceSid, - accountSid, - friendlyName, - participantType, - identifier, - proxyIdentifier, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("sessionSid", sessionSid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("participantType", participantType) - .add("identifier", identifier) - .add("proxyIdentifier", proxyIdentifier) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantCreator.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantCreator.java deleted file mode 100644 index 703df08def..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantCreator.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ParticipantCreator extends Creator { - private final String pathServiceSid; - private final String pathSessionSid; - private final String identifier; - private String friendlyName; - private Participant.ParticipantType participantType; - - /** - * Construct a new ParticipantCreator. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param identifier The Participant's contact identifier, normally a phone - * number. - */ - public ParticipantCreator(final String pathServiceSid, - final String pathSessionSid, - final String identifier) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.identifier = identifier; - } - - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ - public ParticipantCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * The Type of this Participant. One of `sms`, `voice` or `phone`.. - * - * @param participantType The Type of this Participant - * @return this - */ - public ParticipantCreator setParticipantType(final Participant.ParticipantType participantType) { - this.participantType = participantType; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Participant creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Participant.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (identifier != null) { - request.addPostParam("Identifier", identifier); - } - - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (participantType != null) { - request.addPostParam("ParticipantType", participantType.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantDeleter.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantDeleter.java deleted file mode 100644 index 213d9c39a7..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantDeleter.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ParticipantDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - - /** - * Construct a new ParticipantDeleter. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - */ - public ParticipantDeleter(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Participant delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantFetcher.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantFetcher.java deleted file mode 100644 index 03f874716a..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantFetcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ParticipantFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - - /** - * Construct a new ParticipantFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - */ - public ParticipantFetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Participant fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Participant.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantReader.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantReader.java deleted file mode 100644 index 8518ece575..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantReader.java +++ /dev/null @@ -1,210 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ParticipantReader extends Reader { - private final String pathServiceSid; - private final String pathSessionSid; - private String identifier; - private Participant.ParticipantType participantType; - - /** - * Construct a new ParticipantReader. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - */ - public ParticipantReader(final String pathServiceSid, - final String pathSessionSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - } - - /** - * The Participant's contact identifier, normally a phone number.. - * - * @param identifier The Participant's contact identifier, normally a phone - * number. - * @return this - */ - public ParticipantReader setIdentifier(final String identifier) { - this.identifier = identifier; - return this; - } - - /** - * The Type of this Participant. One of `sms`, `voice` or `phone`.. - * - * @param participantType The Type of this Participant - * @return this - */ - public ParticipantReader setParticipantType(final Participant.ParticipantType participantType) { - this.participantType = participantType; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Participant Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Participant read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "participants", - response.getContent(), - Participant.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (identifier != null) { - request.addQueryParam("Identifier", identifier); - } - - if (participantType != null) { - request.addQueryParam("ParticipantType", participantType.toString()); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantUpdater.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantUpdater.java deleted file mode 100644 index 4b945c8f26..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/ParticipantUpdater.java +++ /dev/null @@ -1,139 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ParticipantUpdater extends Updater { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - private Participant.ParticipantType participantType; - private String identifier; - private String friendlyName; - - /** - * Construct a new ParticipantUpdater. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - */ - public ParticipantUpdater(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathSid = pathSid; - } - - /** - * The Type of this Participant. One of `sms`, `voice` or `phone`.. - * - * @param participantType The Type of this Participant - * @return this - */ - public ParticipantUpdater setParticipantType(final Participant.ParticipantType participantType) { - this.participantType = participantType; - return this; - } - - /** - * The Participant's contact identifier, normally a phone number.. - * - * @param identifier The Participant's contact identifier, normally a phone - * number. - * @return this - */ - public ParticipantUpdater setIdentifier(final String identifier) { - this.identifier = identifier; - return this; - } - - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param friendlyName A human readable description of this resource - * @return this - */ - public ParticipantUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Participant update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Participant.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (participantType != null) { - request.addPostParam("ParticipantType", participantType.toString()); - } - - if (identifier != null) { - request.addPostParam("Identifier", identifier); - } - - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteraction.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteraction.java deleted file mode 100644 index 9e95b59d69..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteraction.java +++ /dev/null @@ -1,548 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session.participant; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class MessageInteraction extends Resource { - private static final long serialVersionUID = 12894339272840L; - - public enum Status { - COMPLETED("completed"), - IN_PROGRESS("in-progress"), - FAILED("failed"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - - public enum ResourceStatus { - QUEUED("queued"), - SENDING("sending"), - SENT("sent"), - FAILED("failed"), - DELIVERED("delivered"), - UNDELIVERED("undelivered"); - - private final String value; - - private ResourceStatus(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a ResourceStatus from a string. - * @param value string value - * @return generated ResourceStatus - */ - @JsonCreator - public static ResourceStatus forValue(final String value) { - return Promoter.enumFromString(value, ResourceStatus.values()); - } - } - - /** - * Create a MessageInteractionCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathParticipantSid The participant_sid - * @param body The body of the message. Up to 1600 characters long. - * @return MessageInteractionCreator capable of executing the create - */ - public static MessageInteractionCreator creator(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final String body) { - return new MessageInteractionCreator(pathServiceSid, pathSessionSid, pathParticipantSid, body); - } - - /** - * Create a MessageInteractionCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathParticipantSid The participant_sid - * @param mediaUrl The url of an image or video. - * @return MessageInteractionCreator capable of executing the create - */ - public static MessageInteractionCreator creator(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final List mediaUrl) { - return new MessageInteractionCreator(pathServiceSid, pathSessionSid, pathParticipantSid, mediaUrl); - } - - /** - * Create a MessageInteractionFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathParticipantSid Participant Sid. - * @param pathSid A string that uniquely identifies this Interaction. - * @return MessageInteractionFetcher capable of executing the fetch - */ - public static MessageInteractionFetcher fetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final String pathSid) { - return new MessageInteractionFetcher(pathServiceSid, pathSessionSid, pathParticipantSid, pathSid); - } - - /** - * Create a MessageInteractionReader to execute read. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathParticipantSid Participant Sid. - * @return MessageInteractionReader capable of executing the read - */ - public static MessageInteractionReader reader(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid) { - return new MessageInteractionReader(pathServiceSid, pathSessionSid, pathParticipantSid); - } - - /** - * Converts a JSON String into a MessageInteraction object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return MessageInteraction object represented by the provided JSON - */ - public static MessageInteraction fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, MessageInteraction.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a MessageInteraction object using the - * provided ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return MessageInteraction object represented by the provided JSON - */ - public static MessageInteraction fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, MessageInteraction.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String sessionSid; - private final String serviceSid; - private final String accountSid; - private final String data; - private final MessageInteraction.Status status; - private final String participantSid; - private final String inboundParticipantSid; - private final String inboundResourceSid; - private final MessageInteraction.ResourceStatus inboundResourceStatus; - private final String inboundResourceType; - private final URI inboundResourceUrl; - private final String outboundParticipantSid; - private final String outboundResourceSid; - private final MessageInteraction.ResourceStatus outboundResourceStatus; - private final String outboundResourceType; - private final URI outboundResourceUrl; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private MessageInteraction(@JsonProperty("sid") - final String sid, - @JsonProperty("session_sid") - final String sessionSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("data") - final String data, - @JsonProperty("status") - final MessageInteraction.Status status, - @JsonProperty("participant_sid") - final String participantSid, - @JsonProperty("inbound_participant_sid") - final String inboundParticipantSid, - @JsonProperty("inbound_resource_sid") - final String inboundResourceSid, - @JsonProperty("inbound_resource_status") - final MessageInteraction.ResourceStatus inboundResourceStatus, - @JsonProperty("inbound_resource_type") - final String inboundResourceType, - @JsonProperty("inbound_resource_url") - final URI inboundResourceUrl, - @JsonProperty("outbound_participant_sid") - final String outboundParticipantSid, - @JsonProperty("outbound_resource_sid") - final String outboundResourceSid, - @JsonProperty("outbound_resource_status") - final MessageInteraction.ResourceStatus outboundResourceStatus, - @JsonProperty("outbound_resource_type") - final String outboundResourceType, - @JsonProperty("outbound_resource_url") - final URI outboundResourceUrl, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.sessionSid = sessionSid; - this.serviceSid = serviceSid; - this.accountSid = accountSid; - this.data = data; - this.status = status; - this.participantSid = participantSid; - this.inboundParticipantSid = inboundParticipantSid; - this.inboundResourceSid = inboundResourceSid; - this.inboundResourceStatus = inboundResourceStatus; - this.inboundResourceType = inboundResourceType; - this.inboundResourceUrl = inboundResourceUrl; - this.outboundParticipantSid = outboundParticipantSid; - this.outboundResourceSid = outboundResourceSid; - this.outboundResourceStatus = outboundResourceStatus; - this.outboundResourceType = outboundResourceType; - this.outboundResourceUrl = outboundResourceUrl; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - } - - /** - * Returns The A string that uniquely identifies this Interaction.. - * - * @return A string that uniquely identifies this Interaction. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Session Sid.. - * - * @return Session Sid. - */ - public final String getSessionSid() { - return this.sessionSid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The What happened in this Interaction.. - * - * @return What happened in this Interaction. - */ - public final String getData() { - return this.data; - } - - /** - * Returns The The Status of this Interaction. - * - * @return The Status of this Interaction - */ - public final MessageInteraction.Status getStatus() { - return this.status; - } - - /** - * Returns The The participant_sid. - * - * @return The participant_sid - */ - public final String getParticipantSid() { - return this.participantSid; - } - - /** - * Returns The The inbound_participant_sid. - * - * @return The inbound_participant_sid - */ - public final String getInboundParticipantSid() { - return this.inboundParticipantSid; - } - - /** - * Returns The The SID of the inbound resource.. - * - * @return The SID of the inbound resource. - */ - public final String getInboundResourceSid() { - return this.inboundResourceSid; - } - - /** - * Returns The The Inbound Resource Status of this Interaction. - * - * @return The Inbound Resource Status of this Interaction - */ - public final MessageInteraction.ResourceStatus getInboundResourceStatus() { - return this.inboundResourceStatus; - } - - /** - * Returns The The Twilio object type of the inbound resource.. - * - * @return The Twilio object type of the inbound resource. - */ - public final String getInboundResourceType() { - return this.inboundResourceType; - } - - /** - * Returns The The URL of the inbound resource.. - * - * @return The URL of the inbound resource. - */ - public final URI getInboundResourceUrl() { - return this.inboundResourceUrl; - } - - /** - * Returns The The outbound_participant_sid. - * - * @return The outbound_participant_sid - */ - public final String getOutboundParticipantSid() { - return this.outboundParticipantSid; - } - - /** - * Returns The The SID of the outbound resource.. - * - * @return The SID of the outbound resource. - */ - public final String getOutboundResourceSid() { - return this.outboundResourceSid; - } - - /** - * Returns The The Outbound Resource Status of this Interaction. - * - * @return The Outbound Resource Status of this Interaction - */ - public final MessageInteraction.ResourceStatus getOutboundResourceStatus() { - return this.outboundResourceStatus; - } - - /** - * Returns The The Twilio object type of the outbound resource.. - * - * @return The Twilio object type of the outbound resource. - */ - public final String getOutboundResourceType() { - return this.outboundResourceType; - } - - /** - * Returns The The URL of the outbound resource.. - * - * @return The URL of the outbound resource. - */ - public final URI getOutboundResourceUrl() { - return this.outboundResourceUrl; - } - - /** - * Returns The The date this Interaction was created. - * - * @return The date this Interaction was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Interaction was updated. - * - * @return The date this Interaction was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this Interaction.. - * - * @return The URL of this Interaction. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - MessageInteraction other = (MessageInteraction) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(sessionSid, other.sessionSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(data, other.data) && - Objects.equals(status, other.status) && - Objects.equals(participantSid, other.participantSid) && - Objects.equals(inboundParticipantSid, other.inboundParticipantSid) && - Objects.equals(inboundResourceSid, other.inboundResourceSid) && - Objects.equals(inboundResourceStatus, other.inboundResourceStatus) && - Objects.equals(inboundResourceType, other.inboundResourceType) && - Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && - Objects.equals(outboundParticipantSid, other.outboundParticipantSid) && - Objects.equals(outboundResourceSid, other.outboundResourceSid) && - Objects.equals(outboundResourceStatus, other.outboundResourceStatus) && - Objects.equals(outboundResourceType, other.outboundResourceType) && - Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - sessionSid, - serviceSid, - accountSid, - data, - status, - participantSid, - inboundParticipantSid, - inboundResourceSid, - inboundResourceStatus, - inboundResourceType, - inboundResourceUrl, - outboundParticipantSid, - outboundResourceSid, - outboundResourceStatus, - outboundResourceType, - outboundResourceUrl, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("sessionSid", sessionSid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("data", data) - .add("status", status) - .add("participantSid", participantSid) - .add("inboundParticipantSid", inboundParticipantSid) - .add("inboundResourceSid", inboundResourceSid) - .add("inboundResourceStatus", inboundResourceStatus) - .add("inboundResourceType", inboundResourceType) - .add("inboundResourceUrl", inboundResourceUrl) - .add("outboundParticipantSid", outboundParticipantSid) - .add("outboundResourceSid", outboundResourceSid) - .add("outboundResourceStatus", outboundResourceStatus) - .add("outboundResourceType", outboundResourceType) - .add("outboundResourceUrl", outboundResourceUrl) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionCreator.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionCreator.java deleted file mode 100644 index 37acca41ee..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionCreator.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session.participant; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; -import java.util.List; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class MessageInteractionCreator extends Creator { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathParticipantSid; - private String body; - private List mediaUrl; - - /** - * Construct a new MessageInteractionCreator. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathParticipantSid The participant_sid - * @param body The body of the message. Up to 1600 characters long. - */ - public MessageInteractionCreator(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final String body) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathParticipantSid = pathParticipantSid; - this.body = body; - } - - /** - * Construct a new MessageInteractionCreator. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathParticipantSid The participant_sid - * @param mediaUrl The url of an image or video. - */ - public MessageInteractionCreator(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final List mediaUrl) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathParticipantSid = pathParticipantSid; - this.mediaUrl = mediaUrl; - } - - /** - * The text body of the message to send to the Participant. Up to 1600 - * characters long.. - * - * @param body The body of the message. Up to 1600 characters long. - * @return this - */ - public MessageInteractionCreator setBody(final String body) { - this.body = body; - return this; - } - - /** - * The public url of an image or video to send to the Participant.. - * - * @param mediaUrl The url of an image or video. - * @return this - */ - public MessageInteractionCreator setMediaUrl(final List mediaUrl) { - this.mediaUrl = mediaUrl; - return this; - } - - /** - * The public url of an image or video to send to the Participant.. - * - * @param mediaUrl The url of an image or video. - * @return this - */ - public MessageInteractionCreator setMediaUrl(final URI mediaUrl) { - return setMediaUrl(Promoter.listOfOne(mediaUrl)); - } - - /** - * The public url of an image or video to send to the Participant.. - * - * @param mediaUrl The url of an image or video. - * @return this - */ - public MessageInteractionCreator setMediaUrl(final String mediaUrl) { - return setMediaUrl(Promoter.uriFromString(mediaUrl)); - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created MessageInteraction - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public MessageInteraction create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathParticipantSid + "/MessageInteractions", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("MessageInteraction creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return MessageInteraction.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (body != null) { - request.addPostParam("Body", body); - } - - if (mediaUrl != null) { - for (URI prop : mediaUrl) { - request.addPostParam("MediaUrl", prop.toString()); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionFetcher.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionFetcher.java deleted file mode 100644 index 33da908e6d..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionFetcher.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session.participant; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class MessageInteractionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathParticipantSid; - private final String pathSid; - - /** - * Construct a new MessageInteractionFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathParticipantSid Participant Sid. - * @param pathSid A string that uniquely identifies this Interaction. - */ - public MessageInteractionFetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathParticipantSid = pathParticipantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched MessageInteraction - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public MessageInteraction fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathParticipantSid + "/MessageInteractions/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("MessageInteraction fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return MessageInteraction.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionReader.java b/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionReader.java deleted file mode 100644 index bcaaa447c6..0000000000 --- a/src/main/java/com/twilio/rest/preview/proxy/service/session/participant/MessageInteractionReader.java +++ /dev/null @@ -1,181 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.proxy.service.session.participant; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class MessageInteractionReader extends Reader { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathParticipantSid; - - /** - * Construct a new MessageInteractionReader. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathParticipantSid Participant Sid. - */ - public MessageInteractionReader(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathParticipantSid = pathParticipantSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return MessageInteraction ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return MessageInteraction ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Proxy/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathParticipantSid + "/MessageInteractions", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return MessageInteraction ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of MessageInteraction Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("MessageInteraction read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "interactions", - response.getContent(), - MessageInteraction.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/Flow.java b/src/main/java/com/twilio/rest/preview/studio/Flow.java deleted file mode 100644 index 5b017c11a6..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/Flow.java +++ /dev/null @@ -1,323 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Flow extends Resource { - private static final long serialVersionUID = 219120061630961L; - - public enum Status { - DRAFT("draft"), - PUBLISHED("published"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - - /** - * Create a FlowReader to execute read. - * - * @return FlowReader capable of executing the read - */ - public static FlowReader reader() { - return new FlowReader(); - } - - /** - * Create a FlowFetcher to execute fetch. - * - * @param pathSid The sid - * @return FlowFetcher capable of executing the fetch - */ - public static FlowFetcher fetcher(final String pathSid) { - return new FlowFetcher(pathSid); - } - - /** - * Create a FlowDeleter to execute delete. - * - * @param pathSid A string that uniquely identifies this Flow. - * @return FlowDeleter capable of executing the delete - */ - public static FlowDeleter deleter(final String pathSid) { - return new FlowDeleter(pathSid); - } - - /** - * Converts a JSON String into a Flow object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Flow object represented by the provided JSON - */ - public static Flow fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Flow.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Flow object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Flow object represented by the provided JSON - */ - public static Flow fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Flow.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String friendlyName; - private final Flow.Status status; - private final Boolean debug; - private final Integer version; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Flow(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("status") - final Flow.Status status, - @JsonProperty("debug") - final Boolean debug, - @JsonProperty("version") - final Integer version, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.status = status; - this.debug = debug; - this.version = version; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; - } - - /** - * Returns The A string that uniquely identifies this Flow.. - * - * @return A string that uniquely identifies this Flow. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The A human readable description of this resource.. - * - * @return A human readable description of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The Status of this Flow. - * - * @return The Status of this Flow - */ - public final Flow.Status getStatus() { - return this.status; - } - - /** - * Returns The Toggle extra logging.. - * - * @return Toggle extra logging. - */ - public final Boolean getDebug() { - return this.debug; - } - - /** - * Returns The The latest version number of this Flow's definition.. - * - * @return The latest version number of this Flow's definition. - */ - public final Integer getVersion() { - return this.version; - } - - /** - * Returns The The date this Flow was created. - * - * @return The date this Flow was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Flow was updated. - * - * @return The date this Flow was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Flow other = (Flow) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(status, other.status) && - Objects.equals(debug, other.debug) && - Objects.equals(version, other.version) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - status, - debug, - version, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("status", status) - .add("debug", debug) - .add("version", version) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/FlowDeleter.java b/src/main/java/com/twilio/rest/preview/studio/FlowDeleter.java deleted file mode 100644 index 9b0a46f821..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/FlowDeleter.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FlowDeleter extends Deleter { - private final String pathSid; - - /** - * Construct a new FlowDeleter. - * - * @param pathSid A string that uniquely identifies this Flow. - */ - public FlowDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Studio/Flows/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Flow delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/FlowFetcher.java b/src/main/java/com/twilio/rest/preview/studio/FlowFetcher.java deleted file mode 100644 index b28d32a73f..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/FlowFetcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FlowFetcher extends Fetcher { - private final String pathSid; - - /** - * Construct a new FlowFetcher. - * - * @param pathSid The sid - */ - public FlowFetcher(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Flow - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Flow fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Studio/Flows/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Flow fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Flow.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/FlowReader.java b/src/main/java/com/twilio/rest/preview/studio/FlowReader.java deleted file mode 100644 index 988736645a..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/FlowReader.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FlowReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Flow ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Flow ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Studio/Flows", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Flow ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Flow Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Flow read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "flows", - response.getContent(), - Flow.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/flow/Engagement.java b/src/main/java/com/twilio/rest/preview/studio/flow/Engagement.java deleted file mode 100644 index a75b107ae8..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/flow/Engagement.java +++ /dev/null @@ -1,350 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio.flow; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Engagement extends Resource { - private static final long serialVersionUID = 59724732183846L; - - public enum Status { - ACTIVE("active"), - ENDED("ended"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - - /** - * Create a EngagementReader to execute read. - * - * @param pathFlowSid Flow Sid. - * @return EngagementReader capable of executing the read - */ - public static EngagementReader reader(final String pathFlowSid) { - return new EngagementReader(pathFlowSid); - } - - /** - * Create a EngagementFetcher to execute fetch. - * - * @param pathFlowSid The flow_sid - * @param pathSid The sid - * @return EngagementFetcher capable of executing the fetch - */ - public static EngagementFetcher fetcher(final String pathFlowSid, - final String pathSid) { - return new EngagementFetcher(pathFlowSid, pathSid); - } - - /** - * Create a EngagementCreator to execute create. - * - * @param pathFlowSid Flow Sid. - * @param to The to - * @param from The from - * @return EngagementCreator capable of executing the create - */ - public static EngagementCreator creator(final String pathFlowSid, - final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from) { - return new EngagementCreator(pathFlowSid, to, from); - } - - /** - * Converts a JSON String into a Engagement object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Engagement object represented by the provided JSON - */ - public static Engagement fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Engagement.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Engagement object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Engagement object represented by the provided JSON - */ - public static Engagement fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Engagement.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String flowSid; - private final String contactSid; - private final com.twilio.type.PhoneNumber contactChannelAddress; - private final Engagement.Status status; - private final Map context; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Engagement(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("flow_sid") - final String flowSid, - @JsonProperty("contact_sid") - final String contactSid, - @JsonProperty("contact_channel_address") - final com.twilio.type.PhoneNumber contactChannelAddress, - @JsonProperty("status") - final Engagement.Status status, - @JsonProperty("context") - final Map context, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.flowSid = flowSid; - this.contactSid = contactSid; - this.contactChannelAddress = contactChannelAddress; - this.status = status; - this.context = context; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; - } - - /** - * Returns The A string that uniquely identifies this Engagement.. - * - * @return A string that uniquely identifies this Engagement. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Flow Sid.. - * - * @return Flow Sid. - */ - public final String getFlowSid() { - return this.flowSid; - } - - /** - * Returns The Contact Sid.. - * - * @return Contact Sid. - */ - public final String getContactSid() { - return this.contactSid; - } - - /** - * Returns The The phone number, SIP address or Client identifier that triggered - * this Engagement.. - * - * @return The phone number, SIP address or Client identifier that triggered - * this Engagement. - */ - public final com.twilio.type.PhoneNumber getContactChannelAddress() { - return this.contactChannelAddress; - } - - /** - * Returns The The Status of this Engagement. - * - * @return The Status of this Engagement - */ - public final Engagement.Status getStatus() { - return this.status; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getContext() { - return this.context; - } - - /** - * Returns The The date this Engagement was created. - * - * @return The date this Engagement was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Engagement was updated. - * - * @return The date this Engagement was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Engagement other = (Engagement) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(flowSid, other.flowSid) && - Objects.equals(contactSid, other.contactSid) && - Objects.equals(contactChannelAddress, other.contactChannelAddress) && - Objects.equals(status, other.status) && - Objects.equals(context, other.context) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - flowSid, - contactSid, - contactChannelAddress, - status, - context, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("flowSid", flowSid) - .add("contactSid", contactSid) - .add("contactChannelAddress", contactChannelAddress) - .add("status", status) - .add("context", context) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/flow/EngagementCreator.java b/src/main/java/com/twilio/rest/preview/studio/flow/EngagementCreator.java deleted file mode 100644 index a57c7ef5d8..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/flow/EngagementCreator.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio.flow; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class EngagementCreator extends Creator { - private final String pathFlowSid; - private final com.twilio.type.PhoneNumber to; - private final com.twilio.type.PhoneNumber from; - private String parameters; - - /** - * Construct a new EngagementCreator. - * - * @param pathFlowSid Flow Sid. - * @param to The to - * @param from The from - */ - public EngagementCreator(final String pathFlowSid, - final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from) { - this.pathFlowSid = pathFlowSid; - this.to = to; - this.from = from; - } - - /** - * The parameters. - * - * @param parameters The parameters - * @return this - */ - public EngagementCreator setParameters(final String parameters) { - this.parameters = parameters; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Engagement - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Engagement create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Studio/Flows/" + this.pathFlowSid + "/Engagements", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Engagement creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Engagement.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (to != null) { - request.addPostParam("To", to.toString()); - } - - if (from != null) { - request.addPostParam("From", from.toString()); - } - - if (parameters != null) { - request.addPostParam("Parameters", parameters); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/flow/EngagementFetcher.java b/src/main/java/com/twilio/rest/preview/studio/flow/EngagementFetcher.java deleted file mode 100644 index d44a049422..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/flow/EngagementFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio.flow; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class EngagementFetcher extends Fetcher { - private final String pathFlowSid; - private final String pathSid; - - /** - * Construct a new EngagementFetcher. - * - * @param pathFlowSid The flow_sid - * @param pathSid The sid - */ - public EngagementFetcher(final String pathFlowSid, - final String pathSid) { - this.pathFlowSid = pathFlowSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Engagement - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Engagement fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Studio/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Engagement fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Engagement.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/flow/EngagementReader.java b/src/main/java/com/twilio/rest/preview/studio/flow/EngagementReader.java deleted file mode 100644 index 3238d6ba78..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/flow/EngagementReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio.flow; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class EngagementReader extends Reader { - private final String pathFlowSid; - - /** - * Construct a new EngagementReader. - * - * @param pathFlowSid Flow Sid. - */ - public EngagementReader(final String pathFlowSid) { - this.pathFlowSid = pathFlowSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Engagement ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Engagement ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Studio/Flows/" + this.pathFlowSid + "/Engagements", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Engagement ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Engagement Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Engagement read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "engagements", - response.getContent(), - Engagement.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/flow/engagement/Step.java b/src/main/java/com/twilio/rest/preview/studio/flow/engagement/Step.java deleted file mode 100644 index 8d6024a4dd..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/flow/engagement/Step.java +++ /dev/null @@ -1,311 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio.flow.engagement; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Step extends Resource { - private static final long serialVersionUID = 99874208172157L; - - /** - * Create a StepReader to execute read. - * - * @param pathFlowSid Flow Sid. - * @param pathEngagementSid Engagement Sid. - * @return StepReader capable of executing the read - */ - public static StepReader reader(final String pathFlowSid, - final String pathEngagementSid) { - return new StepReader(pathFlowSid, pathEngagementSid); - } - - /** - * Create a StepFetcher to execute fetch. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - * @param pathSid The sid - * @return StepFetcher capable of executing the fetch - */ - public static StepFetcher fetcher(final String pathFlowSid, - final String pathEngagementSid, - final String pathSid) { - return new StepFetcher(pathFlowSid, pathEngagementSid, pathSid); - } - - /** - * Converts a JSON String into a Step object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Step object represented by the provided JSON - */ - public static Step fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Step.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Step object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Step object represented by the provided JSON - */ - public static Step fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Step.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String flowSid; - private final String engagementSid; - private final String name; - private final Map context; - private final String transitionedFrom; - private final String transitionedTo; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private Step(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("flow_sid") - final String flowSid, - @JsonProperty("engagement_sid") - final String engagementSid, - @JsonProperty("name") - final String name, - @JsonProperty("context") - final Map context, - @JsonProperty("transitioned_from") - final String transitionedFrom, - @JsonProperty("transitioned_to") - final String transitionedTo, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.flowSid = flowSid; - this.engagementSid = engagementSid; - this.name = name; - this.context = context; - this.transitionedFrom = transitionedFrom; - this.transitionedTo = transitionedTo; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - } - - /** - * Returns The A string that uniquely identifies this Step.. - * - * @return A string that uniquely identifies this Step. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Flow Sid.. - * - * @return Flow Sid. - */ - public final String getFlowSid() { - return this.flowSid; - } - - /** - * Returns The Engagement Sid.. - * - * @return Engagement Sid. - */ - public final String getEngagementSid() { - return this.engagementSid; - } - - /** - * Returns The The Widget that implemented this Step.. - * - * @return The Widget that implemented this Step. - */ - public final String getName() { - return this.name; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getContext() { - return this.context; - } - - /** - * Returns The The Widget that preceded the Widget for this Step.. - * - * @return The Widget that preceded the Widget for this Step. - */ - public final String getTransitionedFrom() { - return this.transitionedFrom; - } - - /** - * Returns The The Widget that will follow the Widget for this Step.. - * - * @return The Widget that will follow the Widget for this Step. - */ - public final String getTransitionedTo() { - return this.transitionedTo; - } - - /** - * Returns The The date this Step was created. - * - * @return The date this Step was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Step was updated. - * - * @return The date this Step was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Step other = (Step) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(flowSid, other.flowSid) && - Objects.equals(engagementSid, other.engagementSid) && - Objects.equals(name, other.name) && - Objects.equals(context, other.context) && - Objects.equals(transitionedFrom, other.transitionedFrom) && - Objects.equals(transitionedTo, other.transitionedTo) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - flowSid, - engagementSid, - name, - context, - transitionedFrom, - transitionedTo, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("flowSid", flowSid) - .add("engagementSid", engagementSid) - .add("name", name) - .add("context", context) - .add("transitionedFrom", transitionedFrom) - .add("transitionedTo", transitionedTo) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/flow/engagement/StepFetcher.java b/src/main/java/com/twilio/rest/preview/studio/flow/engagement/StepFetcher.java deleted file mode 100644 index 7ec73fba2b..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/flow/engagement/StepFetcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio.flow.engagement; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class StepFetcher extends Fetcher { - private final String pathFlowSid; - private final String pathEngagementSid; - private final String pathSid; - - /** - * Construct a new StepFetcher. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - * @param pathSid The sid - */ - public StepFetcher(final String pathFlowSid, - final String pathEngagementSid, - final String pathSid) { - this.pathFlowSid = pathFlowSid; - this.pathEngagementSid = pathEngagementSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Step - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Step fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Studio/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathEngagementSid + "/Steps/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Step fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Step.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/studio/flow/engagement/StepReader.java b/src/main/java/com/twilio/rest/preview/studio/flow/engagement/StepReader.java deleted file mode 100644 index 59753d62f5..0000000000 --- a/src/main/java/com/twilio/rest/preview/studio/flow/engagement/StepReader.java +++ /dev/null @@ -1,177 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.studio.flow.engagement; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class StepReader extends Reader { - private final String pathFlowSid; - private final String pathEngagementSid; - - /** - * Construct a new StepReader. - * - * @param pathFlowSid Flow Sid. - * @param pathEngagementSid Engagement Sid. - */ - public StepReader(final String pathFlowSid, - final String pathEngagementSid) { - this.pathFlowSid = pathFlowSid; - this.pathEngagementSid = pathEngagementSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Step ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Step ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Studio/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathEngagementSid + "/Steps", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Step ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Step Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Step read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "steps", - response.getContent(), - Step.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/Service.java b/src/main/java/com/twilio/rest/preview/sync/Service.java deleted file mode 100644 index 7c98a714a6..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/Service.java +++ /dev/null @@ -1,316 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Service extends Resource { - private static final long serialVersionUID = 133636516526090L; - - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid The sid - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); - } - - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid The sid - * @return ServiceDeleter capable of executing the delete - */ - public static ServiceDeleter deleter(final String pathSid) { - return new ServiceDeleter(pathSid); - } - - /** - * Create a ServiceCreator to execute create. - * - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator() { - return new ServiceCreator(); - } - - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ - public static ServiceReader reader() { - return new ServiceReader(); - } - - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid The sid - * @return ServiceUpdater capable of executing the update - */ - public static ServiceUpdater updater(final String pathSid) { - return new ServiceUpdater(pathSid); - } - - /** - * Converts a JSON String into a Service object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Service.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Service object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Service object represented by the provided JSON - */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Service.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final URI webhookUrl; - private final Boolean reachabilityWebhooksEnabled; - private final Boolean aclEnabled; - private final Map links; - - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("webhook_url") - final URI webhookUrl, - @JsonProperty("reachability_webhooks_enabled") - final Boolean reachabilityWebhooksEnabled, - @JsonProperty("acl_enabled") - final Boolean aclEnabled, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.webhookUrl = webhookUrl; - this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; - this.aclEnabled = aclEnabled; - this.links = links; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The webhook_url. - * - * @return The webhook_url - */ - public final URI getWebhookUrl() { - return this.webhookUrl; - } - - /** - * Returns The The reachability_webhooks_enabled. - * - * @return The reachability_webhooks_enabled - */ - public final Boolean getReachabilityWebhooksEnabled() { - return this.reachabilityWebhooksEnabled; - } - - /** - * Returns The The acl_enabled. - * - * @return The acl_enabled - */ - public final Boolean getAclEnabled() { - return this.aclEnabled; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(webhookUrl, other.webhookUrl) && - Objects.equals(reachabilityWebhooksEnabled, other.reachabilityWebhooksEnabled) && - Objects.equals(aclEnabled, other.aclEnabled) && - Objects.equals(links, other.links); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - url, - webhookUrl, - reachabilityWebhooksEnabled, - aclEnabled, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("webhookUrl", webhookUrl) - .add("reachabilityWebhooksEnabled", reachabilityWebhooksEnabled) - .add("aclEnabled", aclEnabled) - .add("links", links) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceCreator.java b/src/main/java/com/twilio/rest/preview/sync/ServiceCreator.java deleted file mode 100644 index c75d34c755..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceCreator.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceCreator extends Creator { - private String friendlyName; - private URI webhookUrl; - private Boolean reachabilityWebhooksEnabled; - private Boolean aclEnabled; - - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ - public ServiceCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * The webhook_url. - * - * @param webhookUrl The webhook_url - * @return this - */ - public ServiceCreator setWebhookUrl(final URI webhookUrl) { - this.webhookUrl = webhookUrl; - return this; - } - - /** - * The webhook_url. - * - * @param webhookUrl The webhook_url - * @return this - */ - public ServiceCreator setWebhookUrl(final String webhookUrl) { - return setWebhookUrl(Promoter.uriFromString(webhookUrl)); - } - - /** - * The reachability_webhooks_enabled. - * - * @param reachabilityWebhooksEnabled The reachability_webhooks_enabled - * @return this - */ - public ServiceCreator setReachabilityWebhooksEnabled(final Boolean reachabilityWebhooksEnabled) { - this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; - return this; - } - - /** - * The acl_enabled. - * - * @param aclEnabled The acl_enabled - * @return this - */ - public ServiceCreator setAclEnabled(final Boolean aclEnabled) { - this.aclEnabled = aclEnabled; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (webhookUrl != null) { - request.addPostParam("WebhookUrl", webhookUrl.toString()); - } - - if (reachabilityWebhooksEnabled != null) { - request.addPostParam("ReachabilityWebhooksEnabled", reachabilityWebhooksEnabled.toString()); - } - - if (aclEnabled != null) { - request.addPostParam("AclEnabled", aclEnabled.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceDeleter.java b/src/main/java/com/twilio/rest/preview/sync/ServiceDeleter.java deleted file mode 100644 index 5165f88bf2..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceDeleter.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceDeleter extends Deleter { - private final String pathSid; - - /** - * Construct a new ServiceDeleter. - * - * @param pathSid The sid - */ - public ServiceDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceFetcher.java b/src/main/java/com/twilio/rest/preview/sync/ServiceFetcher.java deleted file mode 100644 index 0d319d13fc..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceFetcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceFetcher extends Fetcher { - private final String pathSid; - - /** - * Construct a new ServiceFetcher. - * - * @param pathSid The sid - */ - public ServiceFetcher(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceReader.java b/src/main/java/com/twilio/rest/preview/sync/ServiceReader.java deleted file mode 100644 index 239d2949ef..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceReader.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/ServiceUpdater.java b/src/main/java/com/twilio/rest/preview/sync/ServiceUpdater.java deleted file mode 100644 index 4a51b11cc5..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/ServiceUpdater.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync; - -import com.twilio.base.Updater; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ServiceUpdater extends Updater { - private final String pathSid; - private URI webhookUrl; - private String friendlyName; - private Boolean reachabilityWebhooksEnabled; - private Boolean aclEnabled; - - /** - * Construct a new ServiceUpdater. - * - * @param pathSid The sid - */ - public ServiceUpdater(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * The webhook_url. - * - * @param webhookUrl The webhook_url - * @return this - */ - public ServiceUpdater setWebhookUrl(final URI webhookUrl) { - this.webhookUrl = webhookUrl; - return this; - } - - /** - * The webhook_url. - * - * @param webhookUrl The webhook_url - * @return this - */ - public ServiceUpdater setWebhookUrl(final String webhookUrl) { - return setWebhookUrl(Promoter.uriFromString(webhookUrl)); - } - - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ - public ServiceUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * The reachability_webhooks_enabled. - * - * @param reachabilityWebhooksEnabled The reachability_webhooks_enabled - * @return this - */ - public ServiceUpdater setReachabilityWebhooksEnabled(final Boolean reachabilityWebhooksEnabled) { - this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; - return this; - } - - /** - * The acl_enabled. - * - * @param aclEnabled The acl_enabled - * @return this - */ - public ServiceUpdater setAclEnabled(final Boolean aclEnabled) { - this.aclEnabled = aclEnabled; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Service.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (webhookUrl != null) { - request.addPostParam("WebhookUrl", webhookUrl.toString()); - } - - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (reachabilityWebhooksEnabled != null) { - request.addPostParam("ReachabilityWebhooksEnabled", reachabilityWebhooksEnabled.toString()); - } - - if (aclEnabled != null) { - request.addPostParam("AclEnabled", aclEnabled.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/Document.java b/src/main/java/com/twilio/rest/preview/sync/service/Document.java deleted file mode 100644 index 4bb6c3e916..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/Document.java +++ /dev/null @@ -1,344 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Document extends Resource { - private static final long serialVersionUID = 140626500811731L; - - /** - * Create a DocumentFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return DocumentFetcher capable of executing the fetch - */ - public static DocumentFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new DocumentFetcher(pathServiceSid, pathSid); - } - - /** - * Create a DocumentDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return DocumentDeleter capable of executing the delete - */ - public static DocumentDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new DocumentDeleter(pathServiceSid, pathSid); - } - - /** - * Create a DocumentCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return DocumentCreator capable of executing the create - */ - public static DocumentCreator creator(final String pathServiceSid) { - return new DocumentCreator(pathServiceSid); - } - - /** - * Create a DocumentReader to execute read. - * - * @param pathServiceSid The service_sid - * @return DocumentReader capable of executing the read - */ - public static DocumentReader reader(final String pathServiceSid) { - return new DocumentReader(pathServiceSid); - } - - /** - * Create a DocumentUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param data The data - * @return DocumentUpdater capable of executing the update - */ - public static DocumentUpdater updater(final String pathServiceSid, - final String pathSid, - final Map data) { - return new DocumentUpdater(pathServiceSid, pathSid, data); - } - - /** - * Converts a JSON String into a Document object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Document object represented by the provided JSON - */ - public static Document fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Document.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Document object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Document object represented by the provided JSON - */ - public static Document fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Document.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String uniqueName; - private final String accountSid; - private final String serviceSid; - private final URI url; - private final Map links; - private final String revision; - private final Map data; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private Document(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links, - @JsonProperty("revision") - final String revision, - @JsonProperty("data") - final Map data, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.url = url; - this.links = links; - this.revision = revision; - this.data = data; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique_name. - * - * @return The unique_name - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The The revision. - * - * @return The revision - */ - public final String getRevision() { - return this.revision; - } - - /** - * Returns The The data. - * - * @return The data - */ - public final Map getData() { - return this.data; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Document other = (Document) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links) && - Objects.equals(revision, other.revision) && - Objects.equals(data, other.data) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - serviceSid, - url, - links, - revision, - data, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("url", url) - .add("links", links) - .add("revision", revision) - .add("data", data) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentCreator.java deleted file mode 100644 index 3aa2877ac6..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentCreator.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Creator; -import com.twilio.converter.Converter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.Map; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentCreator extends Creator { - private final String pathServiceSid; - private String uniqueName; - private Map data; - - /** - * Construct a new DocumentCreator. - * - * @param pathServiceSid The service_sid - */ - public DocumentCreator(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * The unique_name. - * - * @param uniqueName The unique_name - * @return this - */ - public DocumentCreator setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * The data. - * - * @param data The data - * @return this - */ - public DocumentCreator setData(final Map data) { - this.data = data; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Document - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Document create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Document creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Document.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - - if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentDeleter.java deleted file mode 100644 index 56a51614f3..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new DocumentDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public DocumentDeleter(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Document delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentFetcher.java deleted file mode 100644 index 8e9128ab4d..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new DocumentFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public DocumentFetcher(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Document - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Document fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Document fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Document.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentReader.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentReader.java deleted file mode 100644 index 528cbe95fb..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentReader extends Reader { - private final String pathServiceSid; - - /** - * Construct a new DocumentReader. - * - * @param pathServiceSid The service_sid - */ - public DocumentReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Document ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Document ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Document ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Document Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Document read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "documents", - response.getContent(), - Document.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/DocumentUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/DocumentUpdater.java deleted file mode 100644 index d16c09f908..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/DocumentUpdater.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Updater; -import com.twilio.converter.Converter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.Map; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; - private final Map data; - - /** - * Construct a new DocumentUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @param data The data - */ - public DocumentUpdater(final String pathServiceSid, - final String pathSid, - final Map data) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - this.data = data; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Document - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Document update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Document update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Document.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncList.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncList.java deleted file mode 100644 index 58cc42701d..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncList.java +++ /dev/null @@ -1,313 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class SyncList extends Resource { - private static final long serialVersionUID = 198331554255718L; - - /** - * Create a SyncListFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncListFetcher capable of executing the fetch - */ - public static SyncListFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new SyncListFetcher(pathServiceSid, pathSid); - } - - /** - * Create a SyncListDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncListDeleter capable of executing the delete - */ - public static SyncListDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new SyncListDeleter(pathServiceSid, pathSid); - } - - /** - * Create a SyncListCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return SyncListCreator capable of executing the create - */ - public static SyncListCreator creator(final String pathServiceSid) { - return new SyncListCreator(pathServiceSid); - } - - /** - * Create a SyncListReader to execute read. - * - * @param pathServiceSid The service_sid - * @return SyncListReader capable of executing the read - */ - public static SyncListReader reader(final String pathServiceSid) { - return new SyncListReader(pathServiceSid); - } - - /** - * Converts a JSON String into a SyncList object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncList object represented by the provided JSON - */ - public static SyncList fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncList.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a SyncList object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncList object represented by the provided JSON - */ - public static SyncList fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncList.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String uniqueName; - private final String accountSid; - private final String serviceSid; - private final URI url; - private final Map links; - private final String revision; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncList(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links, - @JsonProperty("revision") - final String revision, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.url = url; - this.links = links; - this.revision = revision; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique_name. - * - * @return The unique_name - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The The revision. - * - * @return The revision - */ - public final String getRevision() { - return this.revision; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - SyncList other = (SyncList) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links) && - Objects.equals(revision, other.revision) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - serviceSid, - url, - links, - revision, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("url", url) - .add("links", links) - .add("revision", revision) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncListCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncListCreator.java deleted file mode 100644 index 3aa4f5517a..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncListCreator.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListCreator extends Creator { - private final String pathServiceSid; - private String uniqueName; - - /** - * Construct a new SyncListCreator. - * - * @param pathServiceSid The service_sid - */ - public SyncListCreator(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * The unique_name. - * - * @param uniqueName The unique_name - * @return this - */ - public SyncListCreator setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncList create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncList creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncListDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncListDeleter.java deleted file mode 100644 index a52d5a771e..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncListDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new SyncListDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncListDeleter(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncList delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncListFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncListFetcher.java deleted file mode 100644 index 98a7a656d2..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncListFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new SyncListFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncListFetcher(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncList fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncList fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncListReader.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncListReader.java deleted file mode 100644 index be11e5fda1..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncListReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListReader extends Reader { - private final String pathServiceSid; - - /** - * Construct a new SyncListReader. - * - * @param pathServiceSid The service_sid - */ - public SyncListReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncList ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncList ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncList ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of SyncList Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncList read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "lists", - response.getContent(), - SyncList.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMap.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMap.java deleted file mode 100644 index 9a1c0e1668..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMap.java +++ /dev/null @@ -1,312 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class SyncMap extends Resource { - private static final long serialVersionUID = 198331554255718L; - - /** - * Create a SyncMapFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncMapFetcher capable of executing the fetch - */ - public static SyncMapFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new SyncMapFetcher(pathServiceSid, pathSid); - } - - /** - * Create a SyncMapDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncMapDeleter capable of executing the delete - */ - public static SyncMapDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new SyncMapDeleter(pathServiceSid, pathSid); - } - - /** - * Create a SyncMapCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return SyncMapCreator capable of executing the create - */ - public static SyncMapCreator creator(final String pathServiceSid) { - return new SyncMapCreator(pathServiceSid); - } - - /** - * Create a SyncMapReader to execute read. - * - * @param pathServiceSid The service_sid - * @return SyncMapReader capable of executing the read - */ - public static SyncMapReader reader(final String pathServiceSid) { - return new SyncMapReader(pathServiceSid); - } - - /** - * Converts a JSON String into a SyncMap object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMap object represented by the provided JSON - */ - public static SyncMap fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncMap.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a SyncMap object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMap object represented by the provided JSON - */ - public static SyncMap fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncMap.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String uniqueName; - private final String accountSid; - private final String serviceSid; - private final URI url; - private final Map links; - private final String revision; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncMap(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links, - @JsonProperty("revision") - final String revision, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.url = url; - this.links = links; - this.revision = revision; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique_name. - * - * @return The unique_name - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The The revision. - * - * @return The revision - */ - public final String getRevision() { - return this.revision; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - SyncMap other = (SyncMap) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links) && - Objects.equals(revision, other.revision) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - serviceSid, - url, - links, - revision, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("url", url) - .add("links", links) - .add("revision", revision) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapCreator.java deleted file mode 100644 index 97810188e4..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapCreator.java +++ /dev/null @@ -1,98 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapCreator extends Creator { - private final String pathServiceSid; - private String uniqueName; - - /** - * Construct a new SyncMapCreator. - * - * @param pathServiceSid The service_sid - */ - public SyncMapCreator(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * The unique_name. - * - * @param uniqueName The unique_name - * @return this - */ - public SyncMapCreator setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncMap - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMap create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMap creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncMap.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapDeleter.java deleted file mode 100644 index 524532ed79..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new SyncMapDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncMapDeleter(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMap delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapFetcher.java deleted file mode 100644 index 0934d4bb31..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new SyncMapFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncMapFetcher(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncMap - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMap fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMap fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncMap.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapReader.java b/src/main/java/com/twilio/rest/preview/sync/service/SyncMapReader.java deleted file mode 100644 index 15f42088e5..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/SyncMapReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapReader extends Reader { - private final String pathServiceSid; - - /** - * Construct a new SyncMapReader. - * - * @param pathServiceSid The service_sid - */ - public SyncMapReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMap ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMap ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncMap ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of SyncMap Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMap read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "maps", - response.getContent(), - SyncMap.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermission.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermission.java deleted file mode 100644 index ae80ce846a..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermission.java +++ /dev/null @@ -1,299 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.document; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class DocumentPermission extends Resource { - private static final long serialVersionUID = 172715793000822L; - - /** - * Create a DocumentPermissionFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - * @return DocumentPermissionFetcher capable of executing the fetch - */ - public static DocumentPermissionFetcher fetcher(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity) { - return new DocumentPermissionFetcher(pathServiceSid, pathDocumentSid, pathIdentity); - } - - /** - * Create a DocumentPermissionDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - * @return DocumentPermissionDeleter capable of executing the delete - */ - public static DocumentPermissionDeleter deleter(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity) { - return new DocumentPermissionDeleter(pathServiceSid, pathDocumentSid, pathIdentity); - } - - /** - * Create a DocumentPermissionReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathDocumentSid Sync Document SID or unique name. - * @return DocumentPermissionReader capable of executing the read - */ - public static DocumentPermissionReader reader(final String pathServiceSid, - final String pathDocumentSid) { - return new DocumentPermissionReader(pathServiceSid, pathDocumentSid); - } - - /** - * Create a DocumentPermissionUpdater to execute update. - * - * @param pathServiceSid Sync Service Instance SID. - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - * @return DocumentPermissionUpdater capable of executing the update - */ - public static DocumentPermissionUpdater updater(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - return new DocumentPermissionUpdater(pathServiceSid, pathDocumentSid, pathIdentity, read, write, manage); - } - - /** - * Converts a JSON String into a DocumentPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return DocumentPermission object represented by the provided JSON - */ - public static DocumentPermission fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, DocumentPermission.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a DocumentPermission object using the - * provided ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return DocumentPermission object represented by the provided JSON - */ - public static DocumentPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, DocumentPermission.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final String serviceSid; - private final String documentSid; - private final String identity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - private final URI url; - - @JsonCreator - private DocumentPermission(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("document_sid") - final String documentSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("read") - final Boolean read, - @JsonProperty("write") - final Boolean write, - @JsonProperty("manage") - final Boolean manage, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.documentSid = documentSid; - this.identity = identity; - this.read = read; - this.write = write; - this.manage = manage; - this.url = url; - } - - /** - * Returns The Twilio Account SID.. - * - * @return Twilio Account SID. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Sync Service Instance SID.. - * - * @return Sync Service Instance SID. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Sync Document SID.. - * - * @return Sync Document SID. - */ - public final String getDocumentSid() { - return this.documentSid; - } - - /** - * Returns The Identity of the user to whom the Sync Document Permission - * applies.. - * - * @return Identity of the user to whom the Sync Document Permission applies. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Read access.. - * - * @return Read access. - */ - public final Boolean getRead() { - return this.read; - } - - /** - * Returns The Write access.. - * - * @return Write access. - */ - public final Boolean getWrite() { - return this.write; - } - - /** - * Returns The Manage access.. - * - * @return Manage access. - */ - public final Boolean getManage() { - return this.manage; - } - - /** - * Returns The URL of this Sync Document Permission.. - * - * @return URL of this Sync Document Permission. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - DocumentPermission other = (DocumentPermission) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(documentSid, other.documentSid) && - Objects.equals(identity, other.identity) && - Objects.equals(read, other.read) && - Objects.equals(write, other.write) && - Objects.equals(manage, other.manage) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - documentSid, - identity, - read, - write, - manage, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("documentSid", documentSid) - .add("identity", identity) - .add("read", read) - .add("write", write) - .add("manage", manage) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionDeleter.java deleted file mode 100644 index ba7660ceb8..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionDeleter.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.document; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentPermissionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathDocumentSid; - private final String pathIdentity; - - /** - * Construct a new DocumentPermissionDeleter. - * - * @param pathServiceSid The service_sid - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - */ - public DocumentPermissionDeleter(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathDocumentSid = pathDocumentSid; - this.pathIdentity = pathIdentity; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents/" + this.pathDocumentSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("DocumentPermission delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionFetcher.java deleted file mode 100644 index ca76709a19..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionFetcher.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.document; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentPermissionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathDocumentSid; - private final String pathIdentity; - - /** - * Construct a new DocumentPermissionFetcher. - * - * @param pathServiceSid The service_sid - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - */ - public DocumentPermissionFetcher(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathDocumentSid = pathDocumentSid; - this.pathIdentity = pathIdentity; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched DocumentPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public DocumentPermission fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents/" + this.pathDocumentSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("DocumentPermission fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return DocumentPermission.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionReader.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionReader.java deleted file mode 100644 index 9f9c36ddae..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionReader.java +++ /dev/null @@ -1,177 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.document; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentPermissionReader extends Reader { - private final String pathServiceSid; - private final String pathDocumentSid; - - /** - * Construct a new DocumentPermissionReader. - * - * @param pathServiceSid The service_sid - * @param pathDocumentSid Sync Document SID or unique name. - */ - public DocumentPermissionReader(final String pathServiceSid, - final String pathDocumentSid) { - this.pathServiceSid = pathServiceSid; - this.pathDocumentSid = pathDocumentSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return DocumentPermission ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return DocumentPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents/" + this.pathDocumentSid + "/Permissions", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return DocumentPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of DocumentPermission Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("DocumentPermission read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "permissions", - response.getContent(), - DocumentPermission.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionUpdater.java deleted file mode 100644 index 2352cb9524..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/document/DocumentPermissionUpdater.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.document; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class DocumentPermissionUpdater extends Updater { - private final String pathServiceSid; - private final String pathDocumentSid; - private final String pathIdentity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - - /** - * Construct a new DocumentPermissionUpdater. - * - * @param pathServiceSid Sync Service Instance SID. - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - */ - public DocumentPermissionUpdater(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - this.pathServiceSid = pathServiceSid; - this.pathDocumentSid = pathDocumentSid; - this.pathIdentity = pathIdentity; - this.read = read; - this.write = write; - this.manage = manage; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated DocumentPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public DocumentPermission update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Documents/" + this.pathDocumentSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("DocumentPermission update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return DocumentPermission.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (read != null) { - request.addPostParam("Read", read.toString()); - } - - if (write != null) { - request.addPostParam("Write", write.toString()); - } - - if (manage != null) { - request.addPostParam("Manage", manage.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItem.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItem.java deleted file mode 100644 index f5f4b273a4..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItem.java +++ /dev/null @@ -1,391 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class SyncListItem extends Resource { - private static final long serialVersionUID = 211432738907618L; - - public enum QueryResultOrder { - ASC("asc"), - DESC("desc"); - - private final String value; - - private QueryResultOrder(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a QueryResultOrder from a string. - * @param value string value - * @return generated QueryResultOrder - */ - @JsonCreator - public static QueryResultOrder forValue(final String value) { - return Promoter.enumFromString(value, QueryResultOrder.values()); - } - } - - public enum QueryFromBoundType { - INCLUSIVE("inclusive"), - EXCLUSIVE("exclusive"); - - private final String value; - - private QueryFromBoundType(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a QueryFromBoundType from a string. - * @param value string value - * @return generated QueryFromBoundType - */ - @JsonCreator - public static QueryFromBoundType forValue(final String value) { - return Promoter.enumFromString(value, QueryFromBoundType.values()); - } - } - - /** - * Create a SyncListItemFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - * @return SyncListItemFetcher capable of executing the fetch - */ - public static SyncListItemFetcher fetcher(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { - return new SyncListItemFetcher(pathServiceSid, pathListSid, pathIndex); - } - - /** - * Create a SyncListItemDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - * @return SyncListItemDeleter capable of executing the delete - */ - public static SyncListItemDeleter deleter(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { - return new SyncListItemDeleter(pathServiceSid, pathListSid, pathIndex); - } - - /** - * Create a SyncListItemCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param data The data - * @return SyncListItemCreator capable of executing the create - */ - public static SyncListItemCreator creator(final String pathServiceSid, - final String pathListSid, - final Map data) { - return new SyncListItemCreator(pathServiceSid, pathListSid, data); - } - - /** - * Create a SyncListItemReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @return SyncListItemReader capable of executing the read - */ - public static SyncListItemReader reader(final String pathServiceSid, - final String pathListSid) { - return new SyncListItemReader(pathServiceSid, pathListSid); - } - - /** - * Create a SyncListItemUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - * @param data The data - * @return SyncListItemUpdater capable of executing the update - */ - public static SyncListItemUpdater updater(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex, - final Map data) { - return new SyncListItemUpdater(pathServiceSid, pathListSid, pathIndex, data); - } - - /** - * Converts a JSON String into a SyncListItem object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncListItem object represented by the provided JSON - */ - public static SyncListItem fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncListItem.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a SyncListItem object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncListItem object represented by the provided JSON - */ - public static SyncListItem fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncListItem.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final Integer index; - private final String accountSid; - private final String serviceSid; - private final String listSid; - private final URI url; - private final String revision; - private final Map data; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncListItem(@JsonProperty("index") - final Integer index, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("list_sid") - final String listSid, - @JsonProperty("url") - final URI url, - @JsonProperty("revision") - final String revision, - @JsonProperty("data") - final Map data, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.index = index; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.listSid = listSid; - this.url = url; - this.revision = revision; - this.data = data; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - } - - /** - * Returns The The index. - * - * @return The index - */ - public final Integer getIndex() { - return this.index; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The list_sid. - * - * @return The list_sid - */ - public final String getListSid() { - return this.listSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The revision. - * - * @return The revision - */ - public final String getRevision() { - return this.revision; - } - - /** - * Returns The The data. - * - * @return The data - */ - public final Map getData() { - return this.data; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - SyncListItem other = (SyncListItem) o; - - return Objects.equals(index, other.index) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(listSid, other.listSid) && - Objects.equals(url, other.url) && - Objects.equals(revision, other.revision) && - Objects.equals(data, other.data) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); - } - - @Override - public int hashCode() { - return Objects.hash(index, - accountSid, - serviceSid, - listSid, - url, - revision, - data, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("index", index) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("listSid", listSid) - .add("url", url) - .add("revision", revision) - .add("data", data) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemCreator.java deleted file mode 100644 index 4f0d6605e4..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemCreator.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Creator; -import com.twilio.converter.Converter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.Map; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListItemCreator extends Creator { - private final String pathServiceSid; - private final String pathListSid; - private final Map data; - - /** - * Construct a new SyncListItemCreator. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param data The data - */ - public SyncListItemCreator(final String pathServiceSid, - final String pathListSid, - final Map data) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - this.data = data; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncListItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListItem create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListItem creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemDeleter.java deleted file mode 100644 index fd96e53188..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemDeleter.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListItemDeleter extends Deleter { - private final String pathServiceSid; - private final String pathListSid; - private final Integer pathIndex; - - /** - * Construct a new SyncListItemDeleter. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - */ - public SyncListItemDeleter(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - this.pathIndex = pathIndex; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items/" + this.pathIndex + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListItem delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemFetcher.java deleted file mode 100644 index cd0a90c854..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemFetcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListItemFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathListSid; - private final Integer pathIndex; - - /** - * Construct a new SyncListItemFetcher. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - */ - public SyncListItemFetcher(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - this.pathIndex = pathIndex; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncListItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListItem fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items/" + this.pathIndex + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListItem fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemReader.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemReader.java deleted file mode 100644 index 60aae1f925..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemReader.java +++ /dev/null @@ -1,225 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListItemReader extends Reader { - private final String pathServiceSid; - private final String pathListSid; - private SyncListItem.QueryResultOrder order; - private String from; - private SyncListItem.QueryFromBoundType bounds; - - /** - * Construct a new SyncListItemReader. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - */ - public SyncListItemReader(final String pathServiceSid, - final String pathListSid) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - } - - /** - * The order. - * - * @param order The order - * @return this - */ - public SyncListItemReader setOrder(final SyncListItem.QueryResultOrder order) { - this.order = order; - return this; - } - - /** - * The from. - * - * @param from The from - * @return this - */ - public SyncListItemReader setFrom(final String from) { - this.from = from; - return this; - } - - /** - * The bounds. - * - * @param bounds The bounds - * @return this - */ - public SyncListItemReader setBounds(final SyncListItem.QueryFromBoundType bounds) { - this.bounds = bounds; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncListItem ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncListItem ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncListItem ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of SyncListItem Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListItem read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "items", - response.getContent(), - SyncListItem.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (order != null) { - request.addQueryParam("Order", order.toString()); - } - - if (from != null) { - request.addQueryParam("From", from); - } - - if (bounds != null) { - request.addQueryParam("Bounds", bounds.toString()); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemUpdater.java deleted file mode 100644 index 71138b8b4c..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListItemUpdater.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Updater; -import com.twilio.converter.Converter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.Map; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListItemUpdater extends Updater { - private final String pathServiceSid; - private final String pathListSid; - private final Integer pathIndex; - private final Map data; - - /** - * Construct a new SyncListItemUpdater. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - * @param data The data - */ - public SyncListItemUpdater(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex, - final Map data) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - this.pathIndex = pathIndex; - this.data = data; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncListItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListItem update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items/" + this.pathIndex + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListItem update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermission.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermission.java deleted file mode 100644 index 7ae39d76c4..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermission.java +++ /dev/null @@ -1,298 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class SyncListPermission extends Resource { - private static final long serialVersionUID = 53631144313647L; - - /** - * Create a SyncListPermissionFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - * @return SyncListPermissionFetcher capable of executing the fetch - */ - public static SyncListPermissionFetcher fetcher(final String pathServiceSid, - final String pathListSid, - final String pathIdentity) { - return new SyncListPermissionFetcher(pathServiceSid, pathListSid, pathIdentity); - } - - /** - * Create a SyncListPermissionDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - * @return SyncListPermissionDeleter capable of executing the delete - */ - public static SyncListPermissionDeleter deleter(final String pathServiceSid, - final String pathListSid, - final String pathIdentity) { - return new SyncListPermissionDeleter(pathServiceSid, pathListSid, pathIdentity); - } - - /** - * Create a SyncListPermissionReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathListSid Sync List SID or unique name. - * @return SyncListPermissionReader capable of executing the read - */ - public static SyncListPermissionReader reader(final String pathServiceSid, - final String pathListSid) { - return new SyncListPermissionReader(pathServiceSid, pathListSid); - } - - /** - * Create a SyncListPermissionUpdater to execute update. - * - * @param pathServiceSid Sync Service Instance SID. - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - * @return SyncListPermissionUpdater capable of executing the update - */ - public static SyncListPermissionUpdater updater(final String pathServiceSid, - final String pathListSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - return new SyncListPermissionUpdater(pathServiceSid, pathListSid, pathIdentity, read, write, manage); - } - - /** - * Converts a JSON String into a SyncListPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncListPermission object represented by the provided JSON - */ - public static SyncListPermission fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncListPermission.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a SyncListPermission object using the - * provided ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncListPermission object represented by the provided JSON - */ - public static SyncListPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncListPermission.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final String serviceSid; - private final String listSid; - private final String identity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - private final URI url; - - @JsonCreator - private SyncListPermission(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("list_sid") - final String listSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("read") - final Boolean read, - @JsonProperty("write") - final Boolean write, - @JsonProperty("manage") - final Boolean manage, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.listSid = listSid; - this.identity = identity; - this.read = read; - this.write = write; - this.manage = manage; - this.url = url; - } - - /** - * Returns The Twilio Account SID.. - * - * @return Twilio Account SID. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Sync Service Instance SID.. - * - * @return Sync Service Instance SID. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Sync List SID.. - * - * @return Sync List SID. - */ - public final String getListSid() { - return this.listSid; - } - - /** - * Returns The Identity of the user to whom the Sync List Permission applies.. - * - * @return Identity of the user to whom the Sync List Permission applies. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Read access.. - * - * @return Read access. - */ - public final Boolean getRead() { - return this.read; - } - - /** - * Returns The Write access.. - * - * @return Write access. - */ - public final Boolean getWrite() { - return this.write; - } - - /** - * Returns The Manage access.. - * - * @return Manage access. - */ - public final Boolean getManage() { - return this.manage; - } - - /** - * Returns The URL of this Sync List Permission.. - * - * @return URL of this Sync List Permission. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - SyncListPermission other = (SyncListPermission) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(listSid, other.listSid) && - Objects.equals(identity, other.identity) && - Objects.equals(read, other.read) && - Objects.equals(write, other.write) && - Objects.equals(manage, other.manage) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - listSid, - identity, - read, - write, - manage, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("listSid", listSid) - .add("identity", identity) - .add("read", read) - .add("write", write) - .add("manage", manage) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionDeleter.java deleted file mode 100644 index 6655b9b31c..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionDeleter.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListPermissionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathListSid; - private final String pathIdentity; - - /** - * Construct a new SyncListPermissionDeleter. - * - * @param pathServiceSid The service_sid - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - */ - public SyncListPermissionDeleter(final String pathServiceSid, - final String pathListSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - this.pathIdentity = pathIdentity; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListPermission delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionFetcher.java deleted file mode 100644 index 5007e68428..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionFetcher.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListPermissionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathListSid; - private final String pathIdentity; - - /** - * Construct a new SyncListPermissionFetcher. - * - * @param pathServiceSid The service_sid - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - */ - public SyncListPermissionFetcher(final String pathServiceSid, - final String pathListSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - this.pathIdentity = pathIdentity; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncListPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListPermission fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListPermission fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncListPermission.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionReader.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionReader.java deleted file mode 100644 index e901ab680e..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionReader.java +++ /dev/null @@ -1,177 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListPermissionReader extends Reader { - private final String pathServiceSid; - private final String pathListSid; - - /** - * Construct a new SyncListPermissionReader. - * - * @param pathServiceSid The service_sid - * @param pathListSid Sync List SID or unique name. - */ - public SyncListPermissionReader(final String pathServiceSid, - final String pathListSid) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncListPermission ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncListPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Permissions", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncListPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of SyncListPermission Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListPermission read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "permissions", - response.getContent(), - SyncListPermission.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionUpdater.java deleted file mode 100644 index 71aeef5ad7..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/synclist/SyncListPermissionUpdater.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.synclist; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncListPermissionUpdater extends Updater { - private final String pathServiceSid; - private final String pathListSid; - private final String pathIdentity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - - /** - * Construct a new SyncListPermissionUpdater. - * - * @param pathServiceSid Sync Service Instance SID. - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - */ - public SyncListPermissionUpdater(final String pathServiceSid, - final String pathListSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - this.pathServiceSid = pathServiceSid; - this.pathListSid = pathListSid; - this.pathIdentity = pathIdentity; - this.read = read; - this.write = write; - this.manage = manage; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncListPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListPermission update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListPermission update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncListPermission.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (read != null) { - request.addPostParam("Read", read.toString()); - } - - if (write != null) { - request.addPostParam("Write", write.toString()); - } - - if (manage != null) { - request.addPostParam("Manage", manage.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItem.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItem.java deleted file mode 100644 index 3f67874d78..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItem.java +++ /dev/null @@ -1,393 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class SyncMapItem extends Resource { - private static final long serialVersionUID = 209160747826518L; - - public enum QueryResultOrder { - ASC("asc"), - DESC("desc"); - - private final String value; - - private QueryResultOrder(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a QueryResultOrder from a string. - * @param value string value - * @return generated QueryResultOrder - */ - @JsonCreator - public static QueryResultOrder forValue(final String value) { - return Promoter.enumFromString(value, QueryResultOrder.values()); - } - } - - public enum QueryFromBoundType { - INCLUSIVE("inclusive"), - EXCLUSIVE("exclusive"); - - private final String value; - - private QueryFromBoundType(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a QueryFromBoundType from a string. - * @param value string value - * @return generated QueryFromBoundType - */ - @JsonCreator - public static QueryFromBoundType forValue(final String value) { - return Promoter.enumFromString(value, QueryFromBoundType.values()); - } - } - - /** - * Create a SyncMapItemFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - * @return SyncMapItemFetcher capable of executing the fetch - */ - public static SyncMapItemFetcher fetcher(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { - return new SyncMapItemFetcher(pathServiceSid, pathMapSid, pathKey); - } - - /** - * Create a SyncMapItemDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - * @return SyncMapItemDeleter capable of executing the delete - */ - public static SyncMapItemDeleter deleter(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { - return new SyncMapItemDeleter(pathServiceSid, pathMapSid, pathKey); - } - - /** - * Create a SyncMapItemCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param key The key - * @param data The data - * @return SyncMapItemCreator capable of executing the create - */ - public static SyncMapItemCreator creator(final String pathServiceSid, - final String pathMapSid, - final String key, - final Map data) { - return new SyncMapItemCreator(pathServiceSid, pathMapSid, key, data); - } - - /** - * Create a SyncMapItemReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @return SyncMapItemReader capable of executing the read - */ - public static SyncMapItemReader reader(final String pathServiceSid, - final String pathMapSid) { - return new SyncMapItemReader(pathServiceSid, pathMapSid); - } - - /** - * Create a SyncMapItemUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - * @param data The data - * @return SyncMapItemUpdater capable of executing the update - */ - public static SyncMapItemUpdater updater(final String pathServiceSid, - final String pathMapSid, - final String pathKey, - final Map data) { - return new SyncMapItemUpdater(pathServiceSid, pathMapSid, pathKey, data); - } - - /** - * Converts a JSON String into a SyncMapItem object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMapItem object represented by the provided JSON - */ - public static SyncMapItem fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncMapItem.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a SyncMapItem object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMapItem object represented by the provided JSON - */ - public static SyncMapItem fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncMapItem.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String key; - private final String accountSid; - private final String serviceSid; - private final String mapSid; - private final URI url; - private final String revision; - private final Map data; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncMapItem(@JsonProperty("key") - final String key, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("map_sid") - final String mapSid, - @JsonProperty("url") - final URI url, - @JsonProperty("revision") - final String revision, - @JsonProperty("data") - final Map data, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.key = key; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.mapSid = mapSid; - this.url = url; - this.revision = revision; - this.data = data; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; - } - - /** - * Returns The The key. - * - * @return The key - */ - public final String getKey() { - return this.key; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The service_sid. - * - * @return The service_sid - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The map_sid. - * - * @return The map_sid - */ - public final String getMapSid() { - return this.mapSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The revision. - * - * @return The revision - */ - public final String getRevision() { - return this.revision; - } - - /** - * Returns The The data. - * - * @return The data - */ - public final Map getData() { - return this.data; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The created_by. - * - * @return The created_by - */ - public final String getCreatedBy() { - return this.createdBy; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - SyncMapItem other = (SyncMapItem) o; - - return Objects.equals(key, other.key) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(mapSid, other.mapSid) && - Objects.equals(url, other.url) && - Objects.equals(revision, other.revision) && - Objects.equals(data, other.data) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); - } - - @Override - public int hashCode() { - return Objects.hash(key, - accountSid, - serviceSid, - mapSid, - url, - revision, - data, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("key", key) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("mapSid", mapSid) - .add("url", url) - .add("revision", revision) - .add("data", data) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemCreator.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemCreator.java deleted file mode 100644 index b6e3336a0f..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemCreator.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Creator; -import com.twilio.converter.Converter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.Map; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapItemCreator extends Creator { - private final String pathServiceSid; - private final String pathMapSid; - private final String key; - private final Map data; - - /** - * Construct a new SyncMapItemCreator. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param key The key - * @param data The data - */ - public SyncMapItemCreator(final String pathServiceSid, - final String pathMapSid, - final String key, - final Map data) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - this.key = key; - this.data = data; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncMapItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapItem create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapItem creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (key != null) { - request.addPostParam("Key", key); - } - - if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemDeleter.java deleted file mode 100644 index 96fa8316a0..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemDeleter.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapItemDeleter extends Deleter { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathKey; - - /** - * Construct a new SyncMapItemDeleter. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - */ - public SyncMapItemDeleter(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - this.pathKey = pathKey; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items/" + this.pathKey + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapItem delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemFetcher.java deleted file mode 100644 index 94cfd27e17..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemFetcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapItemFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathKey; - - /** - * Construct a new SyncMapItemFetcher. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - */ - public SyncMapItemFetcher(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - this.pathKey = pathKey; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncMapItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapItem fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items/" + this.pathKey + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapItem fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemReader.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemReader.java deleted file mode 100644 index 6936464175..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemReader.java +++ /dev/null @@ -1,225 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapItemReader extends Reader { - private final String pathServiceSid; - private final String pathMapSid; - private SyncMapItem.QueryResultOrder order; - private String from; - private SyncMapItem.QueryFromBoundType bounds; - - /** - * Construct a new SyncMapItemReader. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - */ - public SyncMapItemReader(final String pathServiceSid, - final String pathMapSid) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - } - - /** - * The order. - * - * @param order The order - * @return this - */ - public SyncMapItemReader setOrder(final SyncMapItem.QueryResultOrder order) { - this.order = order; - return this; - } - - /** - * The from. - * - * @param from The from - * @return this - */ - public SyncMapItemReader setFrom(final String from) { - this.from = from; - return this; - } - - /** - * The bounds. - * - * @param bounds The bounds - * @return this - */ - public SyncMapItemReader setBounds(final SyncMapItem.QueryFromBoundType bounds) { - this.bounds = bounds; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMapItem ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMapItem ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncMapItem ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of SyncMapItem Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapItem read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "items", - response.getContent(), - SyncMapItem.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (order != null) { - request.addQueryParam("Order", order.toString()); - } - - if (from != null) { - request.addQueryParam("From", from); - } - - if (bounds != null) { - request.addQueryParam("Bounds", bounds.toString()); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemUpdater.java deleted file mode 100644 index 60982aed68..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapItemUpdater.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Updater; -import com.twilio.converter.Converter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.util.Map; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapItemUpdater extends Updater { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathKey; - private final Map data; - - /** - * Construct a new SyncMapItemUpdater. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - * @param data The data - */ - public SyncMapItemUpdater(final String pathServiceSid, - final String pathMapSid, - final String pathKey, - final Map data) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - this.pathKey = pathKey; - this.data = data; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncMapItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapItem update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items/" + this.pathKey + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapItem update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermission.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermission.java deleted file mode 100644 index b65c2bf184..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermission.java +++ /dev/null @@ -1,298 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class SyncMapPermission extends Resource { - private static final long serialVersionUID = 261843483205862L; - - /** - * Create a SyncMapPermissionFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - * @return SyncMapPermissionFetcher capable of executing the fetch - */ - public static SyncMapPermissionFetcher fetcher(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity) { - return new SyncMapPermissionFetcher(pathServiceSid, pathMapSid, pathIdentity); - } - - /** - * Create a SyncMapPermissionDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - * @return SyncMapPermissionDeleter capable of executing the delete - */ - public static SyncMapPermissionDeleter deleter(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity) { - return new SyncMapPermissionDeleter(pathServiceSid, pathMapSid, pathIdentity); - } - - /** - * Create a SyncMapPermissionReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathMapSid Sync Map SID or unique name. - * @return SyncMapPermissionReader capable of executing the read - */ - public static SyncMapPermissionReader reader(final String pathServiceSid, - final String pathMapSid) { - return new SyncMapPermissionReader(pathServiceSid, pathMapSid); - } - - /** - * Create a SyncMapPermissionUpdater to execute update. - * - * @param pathServiceSid Sync Service Instance SID. - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - * @return SyncMapPermissionUpdater capable of executing the update - */ - public static SyncMapPermissionUpdater updater(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - return new SyncMapPermissionUpdater(pathServiceSid, pathMapSid, pathIdentity, read, write, manage); - } - - /** - * Converts a JSON String into a SyncMapPermission object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return SyncMapPermission object represented by the provided JSON - */ - public static SyncMapPermission fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncMapPermission.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a SyncMapPermission object using the - * provided ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return SyncMapPermission object represented by the provided JSON - */ - public static SyncMapPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, SyncMapPermission.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final String serviceSid; - private final String mapSid; - private final String identity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - private final URI url; - - @JsonCreator - private SyncMapPermission(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("map_sid") - final String mapSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("read") - final Boolean read, - @JsonProperty("write") - final Boolean write, - @JsonProperty("manage") - final Boolean manage, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.mapSid = mapSid; - this.identity = identity; - this.read = read; - this.write = write; - this.manage = manage; - this.url = url; - } - - /** - * Returns The Twilio Account SID.. - * - * @return Twilio Account SID. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Sync Service Instance SID.. - * - * @return Sync Service Instance SID. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Sync Map SID.. - * - * @return Sync Map SID. - */ - public final String getMapSid() { - return this.mapSid; - } - - /** - * Returns The Identity of the user to whom the Sync Map Permission applies.. - * - * @return Identity of the user to whom the Sync Map Permission applies. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Read access.. - * - * @return Read access. - */ - public final Boolean getRead() { - return this.read; - } - - /** - * Returns The Write access.. - * - * @return Write access. - */ - public final Boolean getWrite() { - return this.write; - } - - /** - * Returns The Manage access.. - * - * @return Manage access. - */ - public final Boolean getManage() { - return this.manage; - } - - /** - * Returns The URL of this Sync Map Permission.. - * - * @return URL of this Sync Map Permission. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - SyncMapPermission other = (SyncMapPermission) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(mapSid, other.mapSid) && - Objects.equals(identity, other.identity) && - Objects.equals(read, other.read) && - Objects.equals(write, other.write) && - Objects.equals(manage, other.manage) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - mapSid, - identity, - read, - write, - manage, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("mapSid", mapSid) - .add("identity", identity) - .add("read", read) - .add("write", write) - .add("manage", manage) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionDeleter.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionDeleter.java deleted file mode 100644 index 6193eea365..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionDeleter.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapPermissionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathIdentity; - - /** - * Construct a new SyncMapPermissionDeleter. - * - * @param pathServiceSid The service_sid - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - */ - public SyncMapPermissionDeleter(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - this.pathIdentity = pathIdentity; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapPermission delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionFetcher.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionFetcher.java deleted file mode 100644 index b4af18b798..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionFetcher.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapPermissionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathIdentity; - - /** - * Construct a new SyncMapPermissionFetcher. - * - * @param pathServiceSid The service_sid - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - */ - public SyncMapPermissionFetcher(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - this.pathIdentity = pathIdentity; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncMapPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapPermission fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapPermission fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncMapPermission.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionReader.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionReader.java deleted file mode 100644 index 560c6bbcb7..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionReader.java +++ /dev/null @@ -1,177 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapPermissionReader extends Reader { - private final String pathServiceSid; - private final String pathMapSid; - - /** - * Construct a new SyncMapPermissionReader. - * - * @param pathServiceSid The service_sid - * @param pathMapSid Sync Map SID or unique name. - */ - public SyncMapPermissionReader(final String pathServiceSid, - final String pathMapSid) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMapPermission ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMapPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Permissions", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncMapPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of SyncMapPermission Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapPermission read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "permissions", - response.getContent(), - SyncMapPermission.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionUpdater.java b/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionUpdater.java deleted file mode 100644 index 04c91a49fe..0000000000 --- a/src/main/java/com/twilio/rest/preview/sync/service/syncmap/SyncMapPermissionUpdater.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.sync.service.syncmap; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SyncMapPermissionUpdater extends Updater { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathIdentity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - - /** - * Construct a new SyncMapPermissionUpdater. - * - * @param pathServiceSid Sync Service Instance SID. - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - */ - public SyncMapPermissionUpdater(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - this.pathServiceSid = pathServiceSid; - this.pathMapSid = pathMapSid; - this.pathIdentity = pathIdentity; - this.read = read; - this.write = write; - this.manage = manage; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncMapPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapPermission update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/Sync/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapPermission update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return SyncMapPermission.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (read != null) { - request.addPostParam("Read", read.toString()); - } - - if (write != null) { - request.addPostParam("Write", write.toString()); - } - - if (manage != null) { - request.addPostParam("Manage", manage.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/Assistant.java b/src/main/java/com/twilio/rest/preview/understand/Assistant.java deleted file mode 100644 index 456a82a366..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/Assistant.java +++ /dev/null @@ -1,395 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Assistant extends Resource { - private static final long serialVersionUID = 74560960830334L; - - /** - * Create a AssistantFetcher to execute fetch. - * - * @param pathSid The sid - * @return AssistantFetcher capable of executing the fetch - */ - public static AssistantFetcher fetcher(final String pathSid) { - return new AssistantFetcher(pathSid); - } - - /** - * Create a AssistantReader to execute read. - * - * @return AssistantReader capable of executing the read - */ - public static AssistantReader reader() { - return new AssistantReader(); - } - - /** - * Create a AssistantCreator to execute create. - * - * @return AssistantCreator capable of executing the create - */ - public static AssistantCreator creator() { - return new AssistantCreator(); - } - - /** - * Create a AssistantUpdater to execute update. - * - * @param pathSid The sid - * @return AssistantUpdater capable of executing the update - */ - public static AssistantUpdater updater(final String pathSid) { - return new AssistantUpdater(pathSid); - } - - /** - * Create a AssistantDeleter to execute delete. - * - * @param pathSid The sid - * @return AssistantDeleter capable of executing the delete - */ - public static AssistantDeleter deleter(final String pathSid) { - return new AssistantDeleter(pathSid); - } - - /** - * Converts a JSON String into a Assistant object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Assistant object represented by the provided JSON - */ - public static Assistant fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Assistant.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Assistant object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Assistant object represented by the provided JSON - */ - public static Assistant fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Assistant.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String friendlyName; - private final String latestModelBuildSid; - private final Map links; - private final Boolean logQueries; - private final String sid; - private final Integer ttl; - private final String uniqueName; - private final URI url; - private final URI responseUrl; - private final URI callbackUrl; - private final String callbackEvents; - - @JsonCreator - private Assistant(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("latest_model_build_sid") - final String latestModelBuildSid, - @JsonProperty("links") - final Map links, - @JsonProperty("log_queries") - final Boolean logQueries, - @JsonProperty("sid") - final String sid, - @JsonProperty("ttl") - final Integer ttl, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("url") - final URI url, - @JsonProperty("response_url") - final URI responseUrl, - @JsonProperty("callback_url") - final URI callbackUrl, - @JsonProperty("callback_events") - final String callbackEvents) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.friendlyName = friendlyName; - this.latestModelBuildSid = latestModelBuildSid; - this.links = links; - this.logQueries = logQueries; - this.sid = sid; - this.ttl = ttl; - this.uniqueName = uniqueName; - this.url = url; - this.responseUrl = responseUrl; - this.callbackUrl = callbackUrl; - this.callbackEvents = callbackEvents; - } - - /** - * Returns The The unique ID of the Account that created this Assistant.. - * - * @return The unique ID of the Account that created this Assistant. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A text description for the Assistant. It is non-unique and can up - * to 255 characters long.. - * - * @return A text description for the Assistant. It is non-unique and can up to - * 255 characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique ID (Sid) of the latest model build. Null if no model - * has been built.. - * - * @return The unique ID (Sid) of the latest model build. Null if no model has - * been built. - */ - public final String getLatestModelBuildSid() { - return this.latestModelBuildSid; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The A boolean that specifies whether queries should be logged for 30 - * days further training. If false, no queries will be stored, if true, queries - * will be stored for 30 days and deleted thereafter.. - * - * @return A boolean that specifies whether queries should be logged for 30 - * days further training. If false, no queries will be stored, if true, - * queries will be stored for 30 days and deleted thereafter. - */ - public final Boolean getLogQueries() { - return this.logQueries; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The ttl. - * - * @return The ttl - */ - public final Integer getTtl() { - return this.ttl; - } - - /** - * Returns The A user-provided string that uniquely identifies this resource as - * an alternative to the sid. You can use the unique name in the URL path. - * Unique up to 64 characters long.. - * - * @return A user-provided string that uniquely identifies this resource as an - * alternative to the sid. You can use the unique name in the URL path. - * Unique up to 64 characters long. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The webhook URL called to fetch the response to an incoming - * communication expressed in Assistant TwiML.. - * - * @return The webhook URL called to fetch the response to an incoming - * communication expressed in Assistant TwiML. - */ - public final URI getResponseUrl() { - return this.responseUrl; - } - - /** - * Returns The The callback_url. - * - * @return The callback_url - */ - public final URI getCallbackUrl() { - return this.callbackUrl; - } - - /** - * Returns The The callback_events. - * - * @return The callback_events - */ - public final String getCallbackEvents() { - return this.callbackEvents; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Assistant other = (Assistant) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(latestModelBuildSid, other.latestModelBuildSid) && - Objects.equals(links, other.links) && - Objects.equals(logQueries, other.logQueries) && - Objects.equals(sid, other.sid) && - Objects.equals(ttl, other.ttl) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(url, other.url) && - Objects.equals(responseUrl, other.responseUrl) && - Objects.equals(callbackUrl, other.callbackUrl) && - Objects.equals(callbackEvents, other.callbackEvents); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - friendlyName, - latestModelBuildSid, - links, - logQueries, - sid, - ttl, - uniqueName, - url, - responseUrl, - callbackUrl, - callbackEvents); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("latestModelBuildSid", latestModelBuildSid) - .add("links", links) - .add("logQueries", logQueries) - .add("sid", sid) - .add("ttl", ttl) - .add("uniqueName", uniqueName) - .add("url", url) - .add("responseUrl", responseUrl) - .add("callbackUrl", callbackUrl) - .add("callbackEvents", callbackEvents) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantCreator.java b/src/main/java/com/twilio/rest/preview/understand/AssistantCreator.java deleted file mode 100644 index 92f23f1340..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantCreator.java +++ /dev/null @@ -1,223 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AssistantCreator extends Creator { - private String friendlyName; - private Boolean logQueries; - private Integer ttl; - private String uniqueName; - private URI responseUrl; - private URI callbackUrl; - private String callbackEvents; - - /** - * A text description for the Assistant. It is non-unique and can up to 255 - * characters long.. - * - * @param friendlyName A text description for the Assistant. It is non-unique - * and can up to 255 characters long. - * @return this - */ - public AssistantCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * A boolean that specifies whether queries should be logged for 30 days further - * training. If false, no queries will be stored, if true, queries will be - * stored for 30 days and deleted thereafter. Defaults to true if no value is - * provided.. - * - * @param logQueries A boolean that specifies whether queries should be logged - * for 30 days further training. If false, no queries will be - * stored, if true, queries will be stored for 30 days and - * deleted thereafter. Defaults to true if no value is - * provided. - * @return this - */ - public AssistantCreator setLogQueries(final Boolean logQueries) { - this.logQueries = logQueries; - return this; - } - - /** - * The ttl. - * - * @param ttl The ttl - * @return this - */ - public AssistantCreator setTtl(final Integer ttl) { - this.ttl = ttl; - return this; - } - - /** - * A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long.. - * - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - * @return this - */ - public AssistantCreator setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * The webhook URL called to fetch the response to an incoming communication - * expressed in Assistant TwiML.. - * - * @param responseUrl The webhook URL called to fetch the response to an - * incoming communication expressed in Assistant TwiML. - * @return this - */ - public AssistantCreator setResponseUrl(final URI responseUrl) { - this.responseUrl = responseUrl; - return this; - } - - /** - * The webhook URL called to fetch the response to an incoming communication - * expressed in Assistant TwiML.. - * - * @param responseUrl The webhook URL called to fetch the response to an - * incoming communication expressed in Assistant TwiML. - * @return this - */ - public AssistantCreator setResponseUrl(final String responseUrl) { - return setResponseUrl(Promoter.uriFromString(responseUrl)); - } - - /** - * The callback_url. - * - * @param callbackUrl The callback_url - * @return this - */ - public AssistantCreator setCallbackUrl(final URI callbackUrl) { - this.callbackUrl = callbackUrl; - return this; - } - - /** - * The callback_url. - * - * @param callbackUrl The callback_url - * @return this - */ - public AssistantCreator setCallbackUrl(final String callbackUrl) { - return setCallbackUrl(Promoter.uriFromString(callbackUrl)); - } - - /** - * The callback_events. - * - * @param callbackEvents The callback_events - * @return this - */ - public AssistantCreator setCallbackEvents(final String callbackEvents) { - this.callbackEvents = callbackEvents; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Assistant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Assistant create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Assistant creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (logQueries != null) { - request.addPostParam("LogQueries", logQueries.toString()); - } - - if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); - } - - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - - if (responseUrl != null) { - request.addPostParam("ResponseUrl", responseUrl.toString()); - } - - if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); - } - - if (callbackEvents != null) { - request.addPostParam("CallbackEvents", callbackEvents); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantDeleter.java b/src/main/java/com/twilio/rest/preview/understand/AssistantDeleter.java deleted file mode 100644 index 755a8175e2..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantDeleter.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AssistantDeleter extends Deleter { - private final String pathSid; - - /** - * Construct a new AssistantDeleter. - * - * @param pathSid The sid - */ - public AssistantDeleter(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Assistant delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantFetcher.java b/src/main/java/com/twilio/rest/preview/understand/AssistantFetcher.java deleted file mode 100644 index d921738fb6..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantFetcher.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AssistantFetcher extends Fetcher { - private final String pathSid; - - /** - * Construct a new AssistantFetcher. - * - * @param pathSid The sid - */ - public AssistantFetcher(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Assistant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Assistant fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Assistant fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantReader.java b/src/main/java/com/twilio/rest/preview/understand/AssistantReader.java deleted file mode 100644 index 58a21a87c1..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantReader.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AssistantReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Assistant ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Assistant ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Assistant ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Assistant Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Assistant read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "assistants", - response.getContent(), - Assistant.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/AssistantUpdater.java b/src/main/java/com/twilio/rest/preview/understand/AssistantUpdater.java deleted file mode 100644 index f8074e3fc1..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/AssistantUpdater.java +++ /dev/null @@ -1,233 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand; - -import com.twilio.base.Updater; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class AssistantUpdater extends Updater { - private final String pathSid; - private String friendlyName; - private Boolean logQueries; - private Integer ttl; - private String uniqueName; - private URI responseUrl; - private URI callbackUrl; - private String callbackEvents; - - /** - * Construct a new AssistantUpdater. - * - * @param pathSid The sid - */ - public AssistantUpdater(final String pathSid) { - this.pathSid = pathSid; - } - - /** - * A text description for the Assistant. It is non-unique and can up to 255 - * characters long.. - * - * @param friendlyName A text description for the Assistant. It is non-unique - * and can up to 255 characters long. - * @return this - */ - public AssistantUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * A boolean that specifies whether queries should be logged for 30 days further - * training. If false, no queries will be stored, if true, queries will be - * stored for 30 days and deleted thereafter. Defaults to true if no value is - * provided.. - * - * @param logQueries A boolean that specifies whether queries should be logged - * for 30 days further training. If false, no queries will be - * stored, if true, queries will be stored for 30 days and - * deleted thereafter. Defaults to true if no value is - * provided. - * @return this - */ - public AssistantUpdater setLogQueries(final Boolean logQueries) { - this.logQueries = logQueries; - return this; - } - - /** - * The ttl. - * - * @param ttl The ttl - * @return this - */ - public AssistantUpdater setTtl(final Integer ttl) { - this.ttl = ttl; - return this; - } - - /** - * A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long.. - * - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - * @return this - */ - public AssistantUpdater setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * The webhook URL called to fetch the response to an incoming communication - * expressed in Assistant TwiML.. - * - * @param responseUrl The webhook URL called to fetch the response to an - * incoming communication expressed in Assistant TwiML. - * @return this - */ - public AssistantUpdater setResponseUrl(final URI responseUrl) { - this.responseUrl = responseUrl; - return this; - } - - /** - * The webhook URL called to fetch the response to an incoming communication - * expressed in Assistant TwiML.. - * - * @param responseUrl The webhook URL called to fetch the response to an - * incoming communication expressed in Assistant TwiML. - * @return this - */ - public AssistantUpdater setResponseUrl(final String responseUrl) { - return setResponseUrl(Promoter.uriFromString(responseUrl)); - } - - /** - * The callback_url. - * - * @param callbackUrl The callback_url - * @return this - */ - public AssistantUpdater setCallbackUrl(final URI callbackUrl) { - this.callbackUrl = callbackUrl; - return this; - } - - /** - * The callback_url. - * - * @param callbackUrl The callback_url - * @return this - */ - public AssistantUpdater setCallbackUrl(final String callbackUrl) { - return setCallbackUrl(Promoter.uriFromString(callbackUrl)); - } - - /** - * The callback_events. - * - * @param callbackEvents The callback_events - * @return this - */ - public AssistantUpdater setCallbackEvents(final String callbackEvents) { - this.callbackEvents = callbackEvents; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Assistant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Assistant update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Assistant update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Assistant.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (logQueries != null) { - request.addPostParam("LogQueries", logQueries.toString()); - } - - if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); - } - - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - - if (responseUrl != null) { - request.addPostParam("ResponseUrl", responseUrl.toString()); - } - - if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); - } - - if (callbackEvents != null) { - request.addPostParam("CallbackEvents", callbackEvents); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldType.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldType.java deleted file mode 100644 index d86fcf5839..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldType.java +++ /dev/null @@ -1,317 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class FieldType extends Resource { - private static final long serialVersionUID = 595362134429L; - - /** - * Create a FieldTypeFetcher to execute fetch. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return FieldTypeFetcher capable of executing the fetch - */ - public static FieldTypeFetcher fetcher(final String pathAssistantSid, - final String pathSid) { - return new FieldTypeFetcher(pathAssistantSid, pathSid); - } - - /** - * Create a FieldTypeReader to execute read. - * - * @param pathAssistantSid The assistant_sid - * @return FieldTypeReader capable of executing the read - */ - public static FieldTypeReader reader(final String pathAssistantSid) { - return new FieldTypeReader(pathAssistantSid); - } - - /** - * Create a FieldTypeCreator to execute create. - * - * @param pathAssistantSid The assistant_sid - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - * @return FieldTypeCreator capable of executing the create - */ - public static FieldTypeCreator creator(final String pathAssistantSid, - final String uniqueName) { - return new FieldTypeCreator(pathAssistantSid, uniqueName); - } - - /** - * Create a FieldTypeUpdater to execute update. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return FieldTypeUpdater capable of executing the update - */ - public static FieldTypeUpdater updater(final String pathAssistantSid, - final String pathSid) { - return new FieldTypeUpdater(pathAssistantSid, pathSid); - } - - /** - * Create a FieldTypeDeleter to execute delete. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return FieldTypeDeleter capable of executing the delete - */ - public static FieldTypeDeleter deleter(final String pathAssistantSid, - final String pathSid) { - return new FieldTypeDeleter(pathAssistantSid, pathSid); - } - - /** - * Converts a JSON String into a FieldType object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FieldType object represented by the provided JSON - */ - public static FieldType fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, FieldType.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a FieldType object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FieldType object represented by the provided JSON - */ - public static FieldType fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, FieldType.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String friendlyName; - private final Map links; - private final String assistantSid; - private final String sid; - private final String uniqueName; - private final URI url; - - @JsonCreator - private FieldType(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("links") - final Map links, - @JsonProperty("assistant_sid") - final String assistantSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.friendlyName = friendlyName; - this.links = links; - this.assistantSid = assistantSid; - this.sid = sid; - this.uniqueName = uniqueName; - this.url = url; - } - - /** - * Returns The The unique ID of the Account that created this Field Type.. - * - * @return The unique ID of the Account that created this Field Type. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A user-provided string that identifies this resource. It is - * non-unique and can up to 255 characters long.. - * - * @return A user-provided string that identifies this resource. It is - * non-unique and can up to 255 characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The The unique ID of the Assistant.. - * - * @return The unique ID of the Assistant. - */ - public final String getAssistantSid() { - return this.assistantSid; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The A user-provided string that uniquely identifies this resource as - * an alternative to the sid. Unique up to 64 characters long.. - * - * @return A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - FieldType other = (FieldType) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(links, other.links) && - Objects.equals(assistantSid, other.assistantSid) && - Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - friendlyName, - links, - assistantSid, - sid, - uniqueName, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("links", links) - .add("assistantSid", assistantSid) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeCreator.java deleted file mode 100644 index 48e06338ae..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeCreator.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldTypeCreator extends Creator { - private final String pathAssistantSid; - private final String uniqueName; - private String friendlyName; - - /** - * Construct a new FieldTypeCreator. - * - * @param pathAssistantSid The assistant_sid - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - */ - public FieldTypeCreator(final String pathAssistantSid, - final String uniqueName) { - this.pathAssistantSid = pathAssistantSid; - this.uniqueName = uniqueName; - } - - /** - * A user-provided string that identifies this resource. It is non-unique and - * can up to 255 characters long.. - * - * @param friendlyName A user-provided string that identifies this resource. It - * is non-unique and can up to 255 characters long. - * @return this - */ - public FieldTypeCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created FieldType - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public FieldType create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldType creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeDeleter.java deleted file mode 100644 index 2c8f890d07..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldTypeDeleter extends Deleter { - private final String pathAssistantSid; - private final String pathSid; - - /** - * Construct a new FieldTypeDeleter. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public FieldTypeDeleter(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldType delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeFetcher.java deleted file mode 100644 index 68433b7938..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldTypeFetcher extends Fetcher { - private final String pathAssistantSid; - private final String pathSid; - - /** - * Construct a new FieldTypeFetcher. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public FieldTypeFetcher(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched FieldType - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public FieldType fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldType fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeReader.java deleted file mode 100644 index 38ea086723..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldTypeReader extends Reader { - private final String pathAssistantSid; - - /** - * Construct a new FieldTypeReader. - * - * @param pathAssistantSid The assistant_sid - */ - public FieldTypeReader(final String pathAssistantSid) { - this.pathAssistantSid = pathAssistantSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return FieldType ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return FieldType ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return FieldType ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of FieldType Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldType read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "field_types", - response.getContent(), - FieldType.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeUpdater.java deleted file mode 100644 index f3db92b501..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/FieldTypeUpdater.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldTypeUpdater extends Updater { - private final String pathAssistantSid; - private final String pathSid; - private String friendlyName; - private String uniqueName; - - /** - * Construct a new FieldTypeUpdater. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public FieldTypeUpdater(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * A user-provided string that identifies this resource. It is non-unique and - * can up to 255 characters long.. - * - * @param friendlyName A user-provided string that identifies this resource. It - * is non-unique and can up to 255 characters long. - * @return this - */ - public FieldTypeUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long.. - * - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - * @return this - */ - public FieldTypeUpdater setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated FieldType - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public FieldType update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldType update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return FieldType.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/Intent.java b/src/main/java/com/twilio/rest/preview/understand/assistant/Intent.java deleted file mode 100644 index 73e91a36cf..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/Intent.java +++ /dev/null @@ -1,316 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Intent extends Resource { - private static final long serialVersionUID = 595362134429L; - - /** - * Create a IntentFetcher to execute fetch. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return IntentFetcher capable of executing the fetch - */ - public static IntentFetcher fetcher(final String pathAssistantSid, - final String pathSid) { - return new IntentFetcher(pathAssistantSid, pathSid); - } - - /** - * Create a IntentReader to execute read. - * - * @param pathAssistantSid The assistant_sid - * @return IntentReader capable of executing the read - */ - public static IntentReader reader(final String pathAssistantSid) { - return new IntentReader(pathAssistantSid); - } - - /** - * Create a IntentCreator to execute create. - * - * @param pathAssistantSid The assistant_sid - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - * @return IntentCreator capable of executing the create - */ - public static IntentCreator creator(final String pathAssistantSid, - final String uniqueName) { - return new IntentCreator(pathAssistantSid, uniqueName); - } - - /** - * Create a IntentUpdater to execute update. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return IntentUpdater capable of executing the update - */ - public static IntentUpdater updater(final String pathAssistantSid, - final String pathSid) { - return new IntentUpdater(pathAssistantSid, pathSid); - } - - /** - * Create a IntentDeleter to execute delete. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return IntentDeleter capable of executing the delete - */ - public static IntentDeleter deleter(final String pathAssistantSid, - final String pathSid) { - return new IntentDeleter(pathAssistantSid, pathSid); - } - - /** - * Converts a JSON String into a Intent object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Intent object represented by the provided JSON - */ - public static Intent fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Intent.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Intent object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Intent object represented by the provided JSON - */ - public static Intent fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Intent.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String friendlyName; - private final Map links; - private final String assistantSid; - private final String sid; - private final String uniqueName; - private final URI url; - - @JsonCreator - private Intent(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("links") - final Map links, - @JsonProperty("assistant_sid") - final String assistantSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.friendlyName = friendlyName; - this.links = links; - this.assistantSid = assistantSid; - this.sid = sid; - this.uniqueName = uniqueName; - this.url = url; - } - - /** - * Returns The The unique ID of the Account that created this Intent.. - * - * @return The unique ID of the Account that created this Intent. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The A user-provided string that identifies this resource. It is - * non-unique and can up to 255 characters long.. - * - * @return A user-provided string that identifies this resource. It is - * non-unique and can up to 255 characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The The unique ID of the Assistant.. - * - * @return The unique ID of the Assistant. - */ - public final String getAssistantSid() { - return this.assistantSid; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The A user-provided string that uniquely identifies this resource as - * an alternative to the sid. Unique up to 64 characters long.. - * - * @return A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Intent other = (Intent) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(links, other.links) && - Objects.equals(assistantSid, other.assistantSid) && - Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - friendlyName, - links, - assistantSid, - sid, - uniqueName, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("links", links) - .add("assistantSid", assistantSid) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/IntentCreator.java deleted file mode 100644 index 2da56e2868..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentCreator.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class IntentCreator extends Creator { - private final String pathAssistantSid; - private final String uniqueName; - private String friendlyName; - - /** - * Construct a new IntentCreator. - * - * @param pathAssistantSid The assistant_sid - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - */ - public IntentCreator(final String pathAssistantSid, - final String uniqueName) { - this.pathAssistantSid = pathAssistantSid; - this.uniqueName = uniqueName; - } - - /** - * A user-provided string that identifies this resource. It is non-unique and - * can up to 255 characters long.. - * - * @param friendlyName A user-provided string that identifies this resource. It - * is non-unique and can up to 255 characters long. - * @return this - */ - public IntentCreator setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Intent - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Intent create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Intent creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Intent.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/IntentDeleter.java deleted file mode 100644 index 53ab2ca9e7..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class IntentDeleter extends Deleter { - private final String pathAssistantSid; - private final String pathSid; - - /** - * Construct a new IntentDeleter. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public IntentDeleter(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Intent delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/IntentFetcher.java deleted file mode 100644 index 518fe64ebd..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class IntentFetcher extends Fetcher { - private final String pathAssistantSid; - private final String pathSid; - - /** - * Construct a new IntentFetcher. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public IntentFetcher(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Intent - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Intent fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Intent fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Intent.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/IntentReader.java deleted file mode 100644 index e798e092d8..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class IntentReader extends Reader { - private final String pathAssistantSid; - - /** - * Construct a new IntentReader. - * - * @param pathAssistantSid The assistant_sid - */ - public IntentReader(final String pathAssistantSid) { - this.pathAssistantSid = pathAssistantSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Intent ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Intent ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Intent ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Intent Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Intent read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "intents", - response.getContent(), - Intent.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/IntentUpdater.java deleted file mode 100644 index c1b8c286cf..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/IntentUpdater.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class IntentUpdater extends Updater { - private final String pathAssistantSid; - private final String pathSid; - private String friendlyName; - private String uniqueName; - - /** - * Construct a new IntentUpdater. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public IntentUpdater(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * A user-provided string that identifies this resource. It is non-unique and - * can up to 255 characters long.. - * - * @param friendlyName A user-provided string that identifies this resource. It - * is non-unique and can up to 255 characters long. - * @return this - */ - public IntentUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long.. - * - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - * @return this - */ - public IntentUpdater setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Intent - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Intent update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Intent update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Intent.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuild.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuild.java deleted file mode 100644 index fafd80bd39..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuild.java +++ /dev/null @@ -1,358 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class ModelBuild extends Resource { - private static final long serialVersionUID = 48078492703405L; - - public enum Status { - ENQUEUED("enqueued"), - BUILDING("building"), - COMPLETED("completed"), - FAILED("failed"), - CANCELED("canceled"); - - private final String value; - - private Status(final String value) { - this.value = value; - } - - public String toString() { - return value; - } - - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ - @JsonCreator - public static Status forValue(final String value) { - return Promoter.enumFromString(value, Status.values()); - } - } - - /** - * Create a ModelBuildFetcher to execute fetch. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return ModelBuildFetcher capable of executing the fetch - */ - public static ModelBuildFetcher fetcher(final String pathAssistantSid, - final String pathSid) { - return new ModelBuildFetcher(pathAssistantSid, pathSid); - } - - /** - * Create a ModelBuildReader to execute read. - * - * @param pathAssistantSid The assistant_sid - * @return ModelBuildReader capable of executing the read - */ - public static ModelBuildReader reader(final String pathAssistantSid) { - return new ModelBuildReader(pathAssistantSid); - } - - /** - * Create a ModelBuildCreator to execute create. - * - * @param pathAssistantSid The assistant_sid - * @return ModelBuildCreator capable of executing the create - */ - public static ModelBuildCreator creator(final String pathAssistantSid) { - return new ModelBuildCreator(pathAssistantSid); - } - - /** - * Create a ModelBuildUpdater to execute update. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return ModelBuildUpdater capable of executing the update - */ - public static ModelBuildUpdater updater(final String pathAssistantSid, - final String pathSid) { - return new ModelBuildUpdater(pathAssistantSid, pathSid); - } - - /** - * Create a ModelBuildDeleter to execute delete. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return ModelBuildDeleter capable of executing the delete - */ - public static ModelBuildDeleter deleter(final String pathAssistantSid, - final String pathSid) { - return new ModelBuildDeleter(pathAssistantSid, pathSid); - } - - /** - * Converts a JSON String into a ModelBuild object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ModelBuild object represented by the provided JSON - */ - public static ModelBuild fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, ModelBuild.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a ModelBuild object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ModelBuild object represented by the provided JSON - */ - public static ModelBuild fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, ModelBuild.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String assistantSid; - private final String sid; - private final ModelBuild.Status status; - private final String uniqueName; - private final URI url; - private final Integer buildDuration; - private final Integer errorCode; - - @JsonCreator - private ModelBuild(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("assistant_sid") - final String assistantSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("status") - final ModelBuild.Status status, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("url") - final URI url, - @JsonProperty("build_duration") - final Integer buildDuration, - @JsonProperty("error_code") - final Integer errorCode) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.assistantSid = assistantSid; - this.sid = sid; - this.status = status; - this.uniqueName = uniqueName; - this.url = url; - this.buildDuration = buildDuration; - this.errorCode = errorCode; - } - - /** - * Returns The The unique ID of the Account that created this Model Build.. - * - * @return The unique ID of the Account that created this Model Build. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The unique ID of the parent Assistant.. - * - * @return The unique ID of the parent Assistant. - */ - public final String getAssistantSid() { - return this.assistantSid; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The A string that described the model build status. The values can - * be: enqueued, building, completed, failed. - * - * @return A string that described the model build status. The values can be: - * enqueued, building, completed, failed - */ - public final ModelBuild.Status getStatus() { - return this.status; - } - - /** - * Returns The A user-provided string that uniquely identifies this resource as - * an alternative to the sid. Unique up to 64 characters long.. - * - * @return A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The time in seconds it took to build the model.. - * - * @return The time in seconds it took to build the model. - */ - public final Integer getBuildDuration() { - return this.buildDuration; - } - - /** - * Returns The The error_code. - * - * @return The error_code - */ - public final Integer getErrorCode() { - return this.errorCode; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - ModelBuild other = (ModelBuild) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(assistantSid, other.assistantSid) && - Objects.equals(sid, other.sid) && - Objects.equals(status, other.status) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(url, other.url) && - Objects.equals(buildDuration, other.buildDuration) && - Objects.equals(errorCode, other.errorCode); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - assistantSid, - sid, - status, - uniqueName, - url, - buildDuration, - errorCode); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("assistantSid", assistantSid) - .add("sid", sid) - .add("status", status) - .add("uniqueName", uniqueName) - .add("url", url) - .add("buildDuration", buildDuration) - .add("errorCode", errorCode) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildCreator.java deleted file mode 100644 index b77d466ccf..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildCreator.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Creator; -import com.twilio.converter.Promoter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -import java.net.URI; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ModelBuildCreator extends Creator { - private final String pathAssistantSid; - private URI statusCallback; - private String uniqueName; - - /** - * Construct a new ModelBuildCreator. - * - * @param pathAssistantSid The assistant_sid - */ - public ModelBuildCreator(final String pathAssistantSid) { - this.pathAssistantSid = pathAssistantSid; - } - - /** - * The status_callback. - * - * @param statusCallback The status_callback - * @return this - */ - public ModelBuildCreator setStatusCallback(final URI statusCallback) { - this.statusCallback = statusCallback; - return this; - } - - /** - * The status_callback. - * - * @param statusCallback The status_callback - * @return this - */ - public ModelBuildCreator setStatusCallback(final String statusCallback) { - return setStatusCallback(Promoter.uriFromString(statusCallback)); - } - - /** - * A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long. For example: v0.1. - * - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. For example: v0.1 - * @return this - */ - public ModelBuildCreator setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created ModelBuild - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ModelBuild create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/ModelBuilds", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ModelBuild creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); - } - - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildDeleter.java deleted file mode 100644 index 345b9c8845..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ModelBuildDeleter extends Deleter { - private final String pathAssistantSid; - private final String pathSid; - - /** - * Construct a new ModelBuildDeleter. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public ModelBuildDeleter(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/ModelBuilds/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ModelBuild delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildFetcher.java deleted file mode 100644 index b5bc8a8d8c..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ModelBuildFetcher extends Fetcher { - private final String pathAssistantSid; - private final String pathSid; - - /** - * Construct a new ModelBuildFetcher. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public ModelBuildFetcher(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched ModelBuild - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ModelBuild fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/ModelBuilds/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ModelBuild fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildReader.java deleted file mode 100644 index 1d48869ebb..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildReader.java +++ /dev/null @@ -1,173 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ModelBuildReader extends Reader { - private final String pathAssistantSid; - - /** - * Construct a new ModelBuildReader. - * - * @param pathAssistantSid The assistant_sid - */ - public ModelBuildReader(final String pathAssistantSid) { - this.pathAssistantSid = pathAssistantSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ModelBuild ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ModelBuild ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/ModelBuilds", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return ModelBuild ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of ModelBuild Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ModelBuild read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "model_builds", - response.getContent(), - ModelBuild.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildUpdater.java deleted file mode 100644 index 872c28e414..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/ModelBuildUpdater.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class ModelBuildUpdater extends Updater { - private final String pathAssistantSid; - private final String pathSid; - private String uniqueName; - - /** - * Construct a new ModelBuildUpdater. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public ModelBuildUpdater(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long. For example: v0.1. - * - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. For example: v0.1 - * @return this - */ - public ModelBuildUpdater setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated ModelBuild - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ModelBuild update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/ModelBuilds/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ModelBuild update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ModelBuild.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/Query.java b/src/main/java/com/twilio/rest/preview/understand/assistant/Query.java deleted file mode 100644 index c5c9794f6d..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/Query.java +++ /dev/null @@ -1,383 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Query extends Resource { - private static final long serialVersionUID = 54679602157752L; - - /** - * Create a QueryFetcher to execute fetch. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return QueryFetcher capable of executing the fetch - */ - public static QueryFetcher fetcher(final String pathAssistantSid, - final String pathSid) { - return new QueryFetcher(pathAssistantSid, pathSid); - } - - /** - * Create a QueryReader to execute read. - * - * @param pathAssistantSid The assistant_sid - * @return QueryReader capable of executing the read - */ - public static QueryReader reader(final String pathAssistantSid) { - return new QueryReader(pathAssistantSid); - } - - /** - * Create a QueryCreator to execute create. - * - * @param pathAssistantSid The assistant_sid - * @param language An ISO language-country string of the sample. - * @param query A user-provided string that uniquely identifies this resource - * as an alternative to the sid. It can be up to 2048 characters - * long. - * @return QueryCreator capable of executing the create - */ - public static QueryCreator creator(final String pathAssistantSid, - final String language, - final String query) { - return new QueryCreator(pathAssistantSid, language, query); - } - - /** - * Create a QueryUpdater to execute update. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return QueryUpdater capable of executing the update - */ - public static QueryUpdater updater(final String pathAssistantSid, - final String pathSid) { - return new QueryUpdater(pathAssistantSid, pathSid); - } - - /** - * Create a QueryDeleter to execute delete. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - * @return QueryDeleter capable of executing the delete - */ - public static QueryDeleter deleter(final String pathAssistantSid, - final String pathSid) { - return new QueryDeleter(pathAssistantSid, pathSid); - } - - /** - * Converts a JSON String into a Query object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Query object represented by the provided JSON - */ - public static Query fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Query.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Query object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Query object represented by the provided JSON - */ - public static Query fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Query.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final Map results; - private final String language; - private final String modelBuildSid; - private final String query; - private final String sampleSid; - private final String assistantSid; - private final String sid; - private final String status; - private final URI url; - private final String sourceChannel; - - @JsonCreator - private Query(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("results") - final Map results, - @JsonProperty("language") - final String language, - @JsonProperty("model_build_sid") - final String modelBuildSid, - @JsonProperty("query") - final String query, - @JsonProperty("sample_sid") - final String sampleSid, - @JsonProperty("assistant_sid") - final String assistantSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("status") - final String status, - @JsonProperty("url") - final URI url, - @JsonProperty("source_channel") - final String sourceChannel) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.results = results; - this.language = language; - this.modelBuildSid = modelBuildSid; - this.query = query; - this.sampleSid = sampleSid; - this.assistantSid = assistantSid; - this.sid = sid; - this.status = status; - this.url = url; - this.sourceChannel = sourceChannel; - } - - /** - * Returns The The unique ID of the Account that created this Query.. - * - * @return The unique ID of the Account that created this Query. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The natural language analysis results which include the Intent - * recognized, the confidence score and a list of identified Fields.. - * - * @return The natural language analysis results which include the Intent - * recognized, the confidence score and a list of identified Fields. - */ - public final Map getResults() { - return this.results; - } - - /** - * Returns The An ISO language-country string of the sample.. - * - * @return An ISO language-country string of the sample. - */ - public final String getLanguage() { - return this.language; - } - - /** - * Returns The The unique ID of the Model Build queried.. - * - * @return The unique ID of the Model Build queried. - */ - public final String getModelBuildSid() { - return this.modelBuildSid; - } - - /** - * Returns The The query. - * - * @return The query - */ - public final String getQuery() { - return this.query; - } - - /** - * Returns The An optional reference to the Sample created from this query.. - * - * @return An optional reference to the Sample created from this query. - */ - public final String getSampleSid() { - return this.sampleSid; - } - - /** - * Returns The The unique ID of the parent Assistant.. - * - * @return The unique ID of the parent Assistant. - */ - public final String getAssistantSid() { - return this.assistantSid; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The A string that described the query status. The values can be: - * to_review, reviewed, discarded. - * - * @return A string that described the query status. The values can be: - * to_review, reviewed, discarded - */ - public final String getStatus() { - return this.status; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The source_channel. - * - * @return The source_channel - */ - public final String getSourceChannel() { - return this.sourceChannel; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Query other = (Query) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(results, other.results) && - Objects.equals(language, other.language) && - Objects.equals(modelBuildSid, other.modelBuildSid) && - Objects.equals(query, other.query) && - Objects.equals(sampleSid, other.sampleSid) && - Objects.equals(assistantSid, other.assistantSid) && - Objects.equals(sid, other.sid) && - Objects.equals(status, other.status) && - Objects.equals(url, other.url) && - Objects.equals(sourceChannel, other.sourceChannel); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - results, - language, - modelBuildSid, - query, - sampleSid, - assistantSid, - sid, - status, - url, - sourceChannel); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("results", results) - .add("language", language) - .add("modelBuildSid", modelBuildSid) - .add("query", query) - .add("sampleSid", sampleSid) - .add("assistantSid", assistantSid) - .add("sid", sid) - .add("status", status) - .add("url", url) - .add("sourceChannel", sourceChannel) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryCreator.java deleted file mode 100644 index 5508a1d461..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryCreator.java +++ /dev/null @@ -1,157 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class QueryCreator extends Creator { - private final String pathAssistantSid; - private final String language; - private final String query; - private String intents; - private String modelBuild; - private String field; - - /** - * Construct a new QueryCreator. - * - * @param pathAssistantSid The assistant_sid - * @param language An ISO language-country string of the sample. - * @param query A user-provided string that uniquely identifies this resource - * as an alternative to the sid. It can be up to 2048 characters - * long. - */ - public QueryCreator(final String pathAssistantSid, - final String language, - final String query) { - this.pathAssistantSid = pathAssistantSid; - this.language = language; - this.query = query; - } - - /** - * Constraints the query to a set of intents. Useful when you need to constrain - * the paths the user can take. Intents should be comma separated - * *intent-unique-name-1*, *intent-unique-name-2*. - * - * @param intents Constraints the query to a set of intents. Useful when you - * need to constrain the paths the user can take. Intents should - * be comma separated intent-unique-name-1, intent-unique-name-2 - * @return this - */ - public QueryCreator setIntents(final String intents) { - this.intents = intents; - return this; - } - - /** - * The Model Build Sid or unique name of the Model Build to be queried.. - * - * @param modelBuild The Model Build Sid or unique name of the Model Build to - * be queried. - * @return this - */ - public QueryCreator setModelBuild(final String modelBuild) { - this.modelBuild = modelBuild; - return this; - } - - /** - * Constraints the query to a given Field with an intent. Useful when you know - * the Field you are expecting. It accepts one field in the format - * *intent-unique-name-1*:*field-unique-name*. - * - * @param field Constraints the query to a given Field with an intent. Useful - * when you know the Field you are expecting. It accepts one field - * in the format intent-unique-name-1:field-unique-name - * @return this - */ - public QueryCreator setField(final String field) { - this.field = field; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Query - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Query create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Queries", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Query creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Query.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (language != null) { - request.addPostParam("Language", language); - } - - if (query != null) { - request.addPostParam("Query", query); - } - - if (intents != null) { - request.addPostParam("Intents", intents); - } - - if (modelBuild != null) { - request.addPostParam("ModelBuild", modelBuild.toString()); - } - - if (field != null) { - request.addPostParam("Field", field); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryDeleter.java deleted file mode 100644 index 3f623b76e6..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryDeleter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class QueryDeleter extends Deleter { - private final String pathAssistantSid; - private final String pathSid; - - /** - * Construct a new QueryDeleter. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public QueryDeleter(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Queries/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Query delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryFetcher.java deleted file mode 100644 index 116e3dbee2..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryFetcher.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class QueryFetcher extends Fetcher { - private final String pathAssistantSid; - private final String pathSid; - - /** - * Construct a new QueryFetcher. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public QueryFetcher(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Query - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Query fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Queries/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Query fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Query.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryReader.java deleted file mode 100644 index 08ec4af428..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryReader.java +++ /dev/null @@ -1,224 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class QueryReader extends Reader { - private final String pathAssistantSid; - private String language; - private String modelBuild; - private String status; - - /** - * Construct a new QueryReader. - * - * @param pathAssistantSid The assistant_sid - */ - public QueryReader(final String pathAssistantSid) { - this.pathAssistantSid = pathAssistantSid; - } - - /** - * An ISO language-country string of the sample.. - * - * @param language An ISO language-country string of the sample. - * @return this - */ - public QueryReader setLanguage(final String language) { - this.language = language; - return this; - } - - /** - * The Model Build Sid or unique name of the Model Build to be queried.. - * - * @param modelBuild The Model Build Sid or unique name of the Model Build to - * be queried. - * @return this - */ - public QueryReader setModelBuild(final String modelBuild) { - this.modelBuild = modelBuild; - return this; - } - - /** - * A string that described the query status. The values can be: to_review, - * reviewed, discarded. - * - * @param status A string that described the query status. The values can be: - * to_review, reviewed, discarded - * @return this - */ - public QueryReader setStatus(final String status) { - this.status = status; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Query ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Query ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Queries", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Query ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Query Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Query read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "queries", - response.getContent(), - Query.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (language != null) { - request.addQueryParam("Language", language); - } - - if (modelBuild != null) { - request.addQueryParam("ModelBuild", modelBuild.toString()); - } - - if (status != null) { - request.addQueryParam("Status", status); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/QueryUpdater.java deleted file mode 100644 index ad72098d5c..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/QueryUpdater.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class QueryUpdater extends Updater { - private final String pathAssistantSid; - private final String pathSid; - private String sampleSid; - private String status; - - /** - * Construct a new QueryUpdater. - * - * @param pathAssistantSid The assistant_sid - * @param pathSid The sid - */ - public QueryUpdater(final String pathAssistantSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathSid = pathSid; - } - - /** - * The sample_sid. - * - * @param sampleSid The sample_sid - * @return this - */ - public QueryUpdater setSampleSid(final String sampleSid) { - this.sampleSid = sampleSid; - return this; - } - - /** - * A string that described the query status. The values can be: to_review, - * reviewed, discarded. - * - * @param status A string that described the query status. The values can be: - * to_review, reviewed, discarded - * @return this - */ - public QueryUpdater setStatus(final String status) { - this.status = status; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Query - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Query update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Queries/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Query update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Query.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (sampleSid != null) { - request.addPostParam("SampleSid", sampleSid); - } - - if (status != null) { - request.addPostParam("Status", status); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValue.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValue.java deleted file mode 100644 index 9a72668bab..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValue.java +++ /dev/null @@ -1,329 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.fieldtype; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class FieldValue extends Resource { - private static final long serialVersionUID = 196387084273361L; - - /** - * Create a FieldValueFetcher to execute fetch. - * - * @param pathAssistantSid The assistant_sid - * @param pathFieldTypeSid The field_type_sid - * @param pathSid The sid - * @return FieldValueFetcher capable of executing the fetch - */ - public static FieldValueFetcher fetcher(final String pathAssistantSid, - final String pathFieldTypeSid, - final String pathSid) { - return new FieldValueFetcher(pathAssistantSid, pathFieldTypeSid, pathSid); - } - - /** - * Create a FieldValueReader to execute read. - * - * @param pathAssistantSid The assistant_sid - * @param pathFieldTypeSid The field_type_sid - * @return FieldValueReader capable of executing the read - */ - public static FieldValueReader reader(final String pathAssistantSid, - final String pathFieldTypeSid) { - return new FieldValueReader(pathAssistantSid, pathFieldTypeSid); - } - - /** - * Create a FieldValueCreator to execute create. - * - * @param pathAssistantSid The assistant_sid - * @param pathFieldTypeSid The field_type_sid - * @param language An ISO language-country string of the value. - * @param value A user-provided string that uniquely identifies this resource - * as an alternative to the sid. Unique up to 64 characters long. - * @return FieldValueCreator capable of executing the create - */ - public static FieldValueCreator creator(final String pathAssistantSid, - final String pathFieldTypeSid, - final String language, - final String value) { - return new FieldValueCreator(pathAssistantSid, pathFieldTypeSid, language, value); - } - - /** - * Create a FieldValueDeleter to execute delete. - * - * @param pathAssistantSid The assistant_sid - * @param pathFieldTypeSid The field_type_sid - * @param pathSid The sid - * @return FieldValueDeleter capable of executing the delete - */ - public static FieldValueDeleter deleter(final String pathAssistantSid, - final String pathFieldTypeSid, - final String pathSid) { - return new FieldValueDeleter(pathAssistantSid, pathFieldTypeSid, pathSid); - } - - /** - * Converts a JSON String into a FieldValue object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return FieldValue object represented by the provided JSON - */ - public static FieldValue fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, FieldValue.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a FieldValue object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return FieldValue object represented by the provided JSON - */ - public static FieldValue fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, FieldValue.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String fieldTypeSid; - private final String language; - private final String assistantSid; - private final String sid; - private final String value; - private final URI url; - private final String synonymOf; - - @JsonCreator - private FieldValue(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("field_type_sid") - final String fieldTypeSid, - @JsonProperty("language") - final String language, - @JsonProperty("assistant_sid") - final String assistantSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("value") - final String value, - @JsonProperty("url") - final URI url, - @JsonProperty("synonym_of") - final String synonymOf) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.fieldTypeSid = fieldTypeSid; - this.language = language; - this.assistantSid = assistantSid; - this.sid = sid; - this.value = value; - this.url = url; - this.synonymOf = synonymOf; - } - - /** - * Returns The The unique ID of the Account that created this Field Value.. - * - * @return The unique ID of the Account that created this Field Value. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The unique ID of the Field Type associated with this Field - * Value.. - * - * @return The unique ID of the Field Type associated with this Field Value. - */ - public final String getFieldTypeSid() { - return this.fieldTypeSid; - } - - /** - * Returns The An ISO language-country string of the value.. - * - * @return An ISO language-country string of the value. - */ - public final String getLanguage() { - return this.language; - } - - /** - * Returns The The unique ID of the Assistant.. - * - * @return The unique ID of the Assistant. - */ - public final String getAssistantSid() { - return this.assistantSid; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The Field Value itself.. - * - * @return The Field Value itself. - */ - public final String getValue() { - return this.value; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The A value that indicates this field value is a synonym of. Empty if - * the value is not a synonym.. - * - * @return A value that indicates this field value is a synonym of. Empty if - * the value is not a synonym. - */ - public final String getSynonymOf() { - return this.synonymOf; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - FieldValue other = (FieldValue) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(fieldTypeSid, other.fieldTypeSid) && - Objects.equals(language, other.language) && - Objects.equals(assistantSid, other.assistantSid) && - Objects.equals(sid, other.sid) && - Objects.equals(value, other.value) && - Objects.equals(url, other.url) && - Objects.equals(synonymOf, other.synonymOf); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - fieldTypeSid, - language, - assistantSid, - sid, - value, - url, - synonymOf); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("fieldTypeSid", fieldTypeSid) - .add("language", language) - .add("assistantSid", assistantSid) - .add("sid", sid) - .add("value", value) - .add("url", url) - .add("synonymOf", synonymOf) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueCreator.java deleted file mode 100644 index af8a1cc656..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueCreator.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.fieldtype; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldValueCreator extends Creator { - private final String pathAssistantSid; - private final String pathFieldTypeSid; - private final String language; - private final String value; - private String synonymOf; - - /** - * Construct a new FieldValueCreator. - * - * @param pathAssistantSid The assistant_sid - * @param pathFieldTypeSid The field_type_sid - * @param language An ISO language-country string of the value. - * @param value A user-provided string that uniquely identifies this resource - * as an alternative to the sid. Unique up to 64 characters long. - */ - public FieldValueCreator(final String pathAssistantSid, - final String pathFieldTypeSid, - final String language, - final String value) { - this.pathAssistantSid = pathAssistantSid; - this.pathFieldTypeSid = pathFieldTypeSid; - this.language = language; - this.value = value; - } - - /** - * A value that indicates this field value is a synonym of. Empty if the value - * is not a synonym.. - * - * @param synonymOf A value that indicates this field value is a synonym of. - * Empty if the value is not a synonym. - * @return this - */ - public FieldValueCreator setSynonymOf(final String synonymOf) { - this.synonymOf = synonymOf; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created FieldValue - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public FieldValue create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes/" + this.pathFieldTypeSid + "/FieldValues", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldValue creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return FieldValue.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (language != null) { - request.addPostParam("Language", language); - } - - if (value != null) { - request.addPostParam("Value", value); - } - - if (synonymOf != null) { - request.addPostParam("SynonymOf", synonymOf.toString()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueDeleter.java deleted file mode 100644 index 8e9ba07737..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueDeleter.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.fieldtype; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldValueDeleter extends Deleter { - private final String pathAssistantSid; - private final String pathFieldTypeSid; - private final String pathSid; - - /** - * Construct a new FieldValueDeleter. - * - * @param pathAssistantSid The assistant_sid - * @param pathFieldTypeSid The field_type_sid - * @param pathSid The sid - */ - public FieldValueDeleter(final String pathAssistantSid, - final String pathFieldTypeSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathFieldTypeSid = pathFieldTypeSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes/" + this.pathFieldTypeSid + "/FieldValues/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldValue delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueFetcher.java deleted file mode 100644 index a5b732136a..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueFetcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.fieldtype; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldValueFetcher extends Fetcher { - private final String pathAssistantSid; - private final String pathFieldTypeSid; - private final String pathSid; - - /** - * Construct a new FieldValueFetcher. - * - * @param pathAssistantSid The assistant_sid - * @param pathFieldTypeSid The field_type_sid - * @param pathSid The sid - */ - public FieldValueFetcher(final String pathAssistantSid, - final String pathFieldTypeSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathFieldTypeSid = pathFieldTypeSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched FieldValue - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public FieldValue fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes/" + this.pathFieldTypeSid + "/FieldValues/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldValue fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return FieldValue.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueReader.java deleted file mode 100644 index a76e863e09..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/fieldtype/FieldValueReader.java +++ /dev/null @@ -1,194 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.fieldtype; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldValueReader extends Reader { - private final String pathAssistantSid; - private final String pathFieldTypeSid; - private String language; - - /** - * Construct a new FieldValueReader. - * - * @param pathAssistantSid The assistant_sid - * @param pathFieldTypeSid The field_type_sid - */ - public FieldValueReader(final String pathAssistantSid, - final String pathFieldTypeSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathFieldTypeSid = pathFieldTypeSid; - } - - /** - * An ISO language-country string of the value. For example: *en-US*. - * - * @param language An ISO language-country string of the value. For example: - * en-US - * @return this - */ - public FieldValueReader setLanguage(final String language) { - this.language = language; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return FieldValue ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return FieldValue ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/FieldTypes/" + this.pathFieldTypeSid + "/FieldValues", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return FieldValue ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of FieldValue Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("FieldValue read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "field_values", - response.getContent(), - FieldValue.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (language != null) { - request.addQueryParam("Language", language); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/Field.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/Field.java deleted file mode 100644 index dfb0f80454..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/Field.java +++ /dev/null @@ -1,314 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Field extends Resource { - private static final long serialVersionUID = 209912298498000L; - - /** - * Create a FieldFetcher to execute fetch. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - * @return FieldFetcher capable of executing the fetch - */ - public static FieldFetcher fetcher(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - return new FieldFetcher(pathAssistantSid, pathIntentSid, pathSid); - } - - /** - * Create a FieldReader to execute read. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @return FieldReader capable of executing the read - */ - public static FieldReader reader(final String pathAssistantSid, - final String pathIntentSid) { - return new FieldReader(pathAssistantSid, pathIntentSid); - } - - /** - * Create a FieldCreator to execute create. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param fieldType The unique name or sid of the FieldType - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - * @return FieldCreator capable of executing the create - */ - public static FieldCreator creator(final String pathAssistantSid, - final String pathIntentSid, - final String fieldType, - final String uniqueName) { - return new FieldCreator(pathAssistantSid, pathIntentSid, fieldType, uniqueName); - } - - /** - * Create a FieldDeleter to execute delete. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - * @return FieldDeleter capable of executing the delete - */ - public static FieldDeleter deleter(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - return new FieldDeleter(pathAssistantSid, pathIntentSid, pathSid); - } - - /** - * Converts a JSON String into a Field object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Field object represented by the provided JSON - */ - public static Field fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Field.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Field object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Field object represented by the provided JSON - */ - public static Field fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Field.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String fieldType; - private final String intentSid; - private final String assistantSid; - private final String sid; - private final String uniqueName; - private final URI url; - - @JsonCreator - private Field(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("field_type") - final String fieldType, - @JsonProperty("intent_sid") - final String intentSid, - @JsonProperty("assistant_sid") - final String assistantSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.fieldType = fieldType; - this.intentSid = intentSid; - this.assistantSid = assistantSid; - this.sid = sid; - this.uniqueName = uniqueName; - this.url = url; - } - - /** - * Returns The The unique ID of the Account that created this Field.. - * - * @return The unique ID of the Account that created this Field. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The Field Type of this field. Can be the Field Type unique_name - * or the Field Type sid.. - * - * @return The Field Type of this field. Can be the Field Type unique_name or - * the Field Type sid. - */ - public final String getFieldType() { - return this.fieldType; - } - - /** - * Returns The The unique ID of the Intent associated with this Field.. - * - * @return The unique ID of the Intent associated with this Field. - */ - public final String getIntentSid() { - return this.intentSid; - } - - /** - * Returns The The unique ID of the parent Assistant.. - * - * @return The unique ID of the parent Assistant. - */ - public final String getAssistantSid() { - return this.assistantSid; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The A user-provided string that uniquely identifies this resource as - * an alternative to the sid. Unique up to 64 characters long.. - * - * @return A user-provided string that uniquely identifies this resource as an - * alternative to the sid. Unique up to 64 characters long. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Field other = (Field) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(fieldType, other.fieldType) && - Objects.equals(intentSid, other.intentSid) && - Objects.equals(assistantSid, other.assistantSid) && - Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - fieldType, - intentSid, - assistantSid, - sid, - uniqueName, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("fieldType", fieldType) - .add("intentSid", intentSid) - .add("assistantSid", assistantSid) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldCreator.java deleted file mode 100644 index ae45ce2c44..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldCreator.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldCreator extends Creator { - private final String pathAssistantSid; - private final String pathIntentSid; - private final String fieldType; - private final String uniqueName; - - /** - * Construct a new FieldCreator. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param fieldType The unique name or sid of the FieldType - * @param uniqueName A user-provided string that uniquely identifies this - * resource as an alternative to the sid. Unique up to 64 - * characters long. - */ - public FieldCreator(final String pathAssistantSid, - final String pathIntentSid, - final String fieldType, - final String uniqueName) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - this.fieldType = fieldType; - this.uniqueName = uniqueName; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Field - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Field create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Fields", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Field creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Field.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (fieldType != null) { - request.addPostParam("FieldType", fieldType); - } - - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldDeleter.java deleted file mode 100644 index 1a24738004..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldDeleter.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldDeleter extends Deleter { - private final String pathAssistantSid; - private final String pathIntentSid; - private final String pathSid; - - /** - * Construct a new FieldDeleter. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - */ - public FieldDeleter(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Fields/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Field delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldFetcher.java deleted file mode 100644 index c73d091974..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldFetcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldFetcher extends Fetcher { - private final String pathAssistantSid; - private final String pathIntentSid; - private final String pathSid; - - /** - * Construct a new FieldFetcher. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - */ - public FieldFetcher(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Field - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Field fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Fields/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Field fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Field.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldReader.java deleted file mode 100644 index 8d205819d4..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/FieldReader.java +++ /dev/null @@ -1,177 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class FieldReader extends Reader { - private final String pathAssistantSid; - private final String pathIntentSid; - - /** - * Construct a new FieldReader. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - */ - public FieldReader(final String pathAssistantSid, - final String pathIntentSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Field ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Field ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Fields", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Field ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Field Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Field read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "fields", - response.getContent(), - Field.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/Sample.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/Sample.java deleted file mode 100644 index 525da09758..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/Sample.java +++ /dev/null @@ -1,345 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class Sample extends Resource { - private static final long serialVersionUID = 38835769479501L; - - /** - * Create a SampleFetcher to execute fetch. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - * @return SampleFetcher capable of executing the fetch - */ - public static SampleFetcher fetcher(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - return new SampleFetcher(pathAssistantSid, pathIntentSid, pathSid); - } - - /** - * Create a SampleReader to execute read. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @return SampleReader capable of executing the read - */ - public static SampleReader reader(final String pathAssistantSid, - final String pathIntentSid) { - return new SampleReader(pathAssistantSid, pathIntentSid); - } - - /** - * Create a SampleCreator to execute create. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param language An ISO language-country string of the sample. - * @param taggedText The text example of how end-users may express this intent. - * The sample may contain Field tag blocks. - * @return SampleCreator capable of executing the create - */ - public static SampleCreator creator(final String pathAssistantSid, - final String pathIntentSid, - final String language, - final String taggedText) { - return new SampleCreator(pathAssistantSid, pathIntentSid, language, taggedText); - } - - /** - * Create a SampleUpdater to execute update. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - * @return SampleUpdater capable of executing the update - */ - public static SampleUpdater updater(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - return new SampleUpdater(pathAssistantSid, pathIntentSid, pathSid); - } - - /** - * Create a SampleDeleter to execute delete. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - * @return SampleDeleter capable of executing the delete - */ - public static SampleDeleter deleter(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - return new SampleDeleter(pathAssistantSid, pathIntentSid, pathSid); - } - - /** - * Converts a JSON String into a Sample object using the provided ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return Sample object represented by the provided JSON - */ - public static Sample fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Sample.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a Sample object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return Sample object represented by the provided JSON - */ - public static Sample fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, Sample.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String intentSid; - private final String language; - private final String assistantSid; - private final String sid; - private final String taggedText; - private final URI url; - private final String sourceChannel; - - @JsonCreator - private Sample(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("intent_sid") - final String intentSid, - @JsonProperty("language") - final String language, - @JsonProperty("assistant_sid") - final String assistantSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("tagged_text") - final String taggedText, - @JsonProperty("url") - final URI url, - @JsonProperty("source_channel") - final String sourceChannel) { - this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.intentSid = intentSid; - this.language = language; - this.assistantSid = assistantSid; - this.sid = sid; - this.taggedText = taggedText; - this.url = url; - this.sourceChannel = sourceChannel; - } - - /** - * Returns The The unique ID of the Account that created this Sample.. - * - * @return The unique ID of the Account that created this Sample. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date that this resource was created. - * - * @return The date that this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date that this resource was last updated. - * - * @return The date that this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The unique ID of the Intent associated with this Sample.. - * - * @return The unique ID of the Intent associated with this Sample. - */ - public final String getIntentSid() { - return this.intentSid; - } - - /** - * Returns The An ISO language-country string of the sample.. - * - * @return An ISO language-country string of the sample. - */ - public final String getLanguage() { - return this.language; - } - - /** - * Returns The The unique ID of the Assistant.. - * - * @return The unique ID of the Assistant. - */ - public final String getAssistantSid() { - return this.assistantSid; - } - - /** - * Returns The A 34 character string that uniquely identifies this resource.. - * - * @return A 34 character string that uniquely identifies this resource. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The text example of how end-users may express this intent. The - * sample may contain Field tag blocks.. - * - * @return The text example of how end-users may express this intent. The - * sample may contain Field tag blocks. - */ - public final String getTaggedText() { - return this.taggedText; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The communication channel the sample was captured. It can be: - * voice, sms, chat, alexa, google-assistant, or slack. If not included the - * value will be null. - * - * @return The communication channel the sample was captured. It can be: voice, - * sms, chat, alexa, google-assistant, or slack. If not included the - * value will be null - */ - public final String getSourceChannel() { - return this.sourceChannel; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - Sample other = (Sample) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(intentSid, other.intentSid) && - Objects.equals(language, other.language) && - Objects.equals(assistantSid, other.assistantSid) && - Objects.equals(sid, other.sid) && - Objects.equals(taggedText, other.taggedText) && - Objects.equals(url, other.url) && - Objects.equals(sourceChannel, other.sourceChannel); - } - - @Override - public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - intentSid, - language, - assistantSid, - sid, - taggedText, - url, - sourceChannel); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("intentSid", intentSid) - .add("language", language) - .add("assistantSid", assistantSid) - .add("sid", sid) - .add("taggedText", taggedText) - .add("url", url) - .add("sourceChannel", sourceChannel) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleCreator.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleCreator.java deleted file mode 100644 index 4669f41fc8..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleCreator.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SampleCreator extends Creator { - private final String pathAssistantSid; - private final String pathIntentSid; - private final String language; - private final String taggedText; - private String sourceChannel; - - /** - * Construct a new SampleCreator. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param language An ISO language-country string of the sample. - * @param taggedText The text example of how end-users may express this intent. - * The sample may contain Field tag blocks. - */ - public SampleCreator(final String pathAssistantSid, - final String pathIntentSid, - final String language, - final String taggedText) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - this.language = language; - this.taggedText = taggedText; - } - - /** - * The communication channel the sample was captured. It can be: *voice*, *sms*, - * *chat*, *alexa*, *google-assistant*, or *slack*. If not included the value - * will be null. - * - * @param sourceChannel The communication channel the sample was captured. It - * can be: voice, sms, chat, alexa, google-assistant, or - * slack. If not included the value will be null - * @return this - */ - public SampleCreator setSourceChannel(final String sourceChannel) { - this.sourceChannel = sourceChannel; - return this; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Sample - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Sample create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Samples", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Sample creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Sample.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (language != null) { - request.addPostParam("Language", language); - } - - if (taggedText != null) { - request.addPostParam("TaggedText", taggedText); - } - - if (sourceChannel != null) { - request.addPostParam("SourceChannel", sourceChannel); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleDeleter.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleDeleter.java deleted file mode 100644 index cb1397ef08..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleDeleter.java +++ /dev/null @@ -1,81 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SampleDeleter extends Deleter { - private final String pathAssistantSid; - private final String pathIntentSid; - private final String pathSid; - - /** - * Construct a new SampleDeleter. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - */ - public SampleDeleter(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Samples/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Sample delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleFetcher.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleFetcher.java deleted file mode 100644 index d15e59a77d..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleFetcher.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SampleFetcher extends Fetcher { - private final String pathAssistantSid; - private final String pathIntentSid; - private final String pathSid; - - /** - * Construct a new SampleFetcher. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - */ - public SampleFetcher(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Sample - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Sample fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Samples/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Sample fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Sample.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleReader.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleReader.java deleted file mode 100644 index 5bca5911cf..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleReader.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SampleReader extends Reader { - private final String pathAssistantSid; - private final String pathIntentSid; - private String language; - - /** - * Construct a new SampleReader. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - */ - public SampleReader(final String pathAssistantSid, - final String pathIntentSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - } - - /** - * An ISO language-country string of the sample.. - * - * @param language An ISO language-country string of the sample. - * @return this - */ - public SampleReader setLanguage(final String language) { - this.language = language; - return this; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Sample ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Sample ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Samples", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Sample ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of Sample Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Sample read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "samples", - response.getContent(), - Sample.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (language != null) { - request.addQueryParam("Language", language); - } - - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleUpdater.java b/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleUpdater.java deleted file mode 100644 index be12abc2f5..0000000000 --- a/src/main/java/com/twilio/rest/preview/understand/assistant/intent/SampleUpdater.java +++ /dev/null @@ -1,144 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.preview.understand.assistant.intent; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ -public class SampleUpdater extends Updater { - private final String pathAssistantSid; - private final String pathIntentSid; - private final String pathSid; - private String language; - private String taggedText; - private String sourceChannel; - - /** - * Construct a new SampleUpdater. - * - * @param pathAssistantSid The assistant_sid - * @param pathIntentSid The intent_sid - * @param pathSid The sid - */ - public SampleUpdater(final String pathAssistantSid, - final String pathIntentSid, - final String pathSid) { - this.pathAssistantSid = pathAssistantSid; - this.pathIntentSid = pathIntentSid; - this.pathSid = pathSid; - } - - /** - * An ISO language-country string of the sample.. - * - * @param language An ISO language-country string of the sample. - * @return this - */ - public SampleUpdater setLanguage(final String language) { - this.language = language; - return this; - } - - /** - * The text example of how end-users may express this intent. The sample may - * contain Field tag blocks.. - * - * @param taggedText The text example of how end-users may express this intent. - * The sample may contain Field tag blocks. - * @return this - */ - public SampleUpdater setTaggedText(final String taggedText) { - this.taggedText = taggedText; - return this; - } - - /** - * The communication channel the sample was captured. It can be: *voice*, *sms*, - * *chat*, *alexa*, *google-assistant*, or *slack*. If not included the value - * will be null. - * - * @param sourceChannel The communication channel the sample was captured. It - * can be: voice, sms, chat, alexa, google-assistant, or - * slack. If not included the value will be null - * @return this - */ - public SampleUpdater setSourceChannel(final String sourceChannel) { - this.sourceChannel = sourceChannel; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Sample - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Sample update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PREVIEW.toString(), - "/understand/Assistants/" + this.pathAssistantSid + "/Intents/" + this.pathIntentSid + "/Samples/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Sample update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Sample.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (language != null) { - request.addPostParam("Language", language); - } - - if (taggedText != null) { - request.addPostParam("TaggedText", taggedText); - } - - if (sourceChannel != null) { - request.addPostParam("SourceChannel", sourceChannel); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/preview/wireless/Command.java b/src/main/java/com/twilio/rest/preview/wireless/Command.java index bf200087bf..12748304c0 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/Command.java +++ b/src/main/java/com/twilio/rest/preview/wireless/Command.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; @@ -11,73 +18,53 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Command extends Resource { - private static final long serialVersionUID = 102379842720145L; - /** - * Create a CommandFetcher to execute fetch. - * - * @param pathSid The sid - * @return CommandFetcher capable of executing the fetch - */ + public static CommandCreator creator(final String command) { + return new CommandCreator(command); + } + public static CommandFetcher fetcher(final String pathSid) { return new CommandFetcher(pathSid); } - /** - * Create a CommandReader to execute read. - * - * @return CommandReader capable of executing the read - */ public static CommandReader reader() { return new CommandReader(); } - /** - * Create a CommandCreator to execute create. - * - * @param command The command - * @return CommandCreator capable of executing the create - */ - public static CommandCreator creator(final String command) { - return new CommandCreator(command); - } - /** * Converts a JSON String into a Command object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Command object represented by the provided JSON */ - public static Command fromJson(final String json, final ObjectMapper objectMapper) { + public static Command fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Command.class); @@ -91,12 +78,15 @@ public static Command fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Command object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Command object represented by the provided JSON */ - public static Command fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Command fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Command.class); @@ -107,151 +97,86 @@ public static Command fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String accountSid; - private final String deviceSid; - private final String simSid; - private final String command; - private final String commandMode; - private final String status; - private final String direction; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private Command(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("device_sid") - final String deviceSid, - @JsonProperty("sim_sid") - final String simSid, - @JsonProperty("command") - final String command, - @JsonProperty("command_mode") - final String commandMode, - @JsonProperty("status") - final String status, - @JsonProperty("direction") - final String direction, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.deviceSid = deviceSid; - this.simSid = simSid; - this.command = command; - this.commandMode = commandMode; - this.status = status; - this.direction = direction; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String command; - /** - * Returns The The device_sid. - * - * @return The device_sid - */ - public final String getDeviceSid() { - return this.deviceSid; - } + @Getter + private final String commandMode; - /** - * Returns The The sim_sid. - * - * @return The sim_sid - */ - public final String getSimSid() { - return this.simSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The command. - * - * @return The command - */ - public final String getCommand() { - return this.command; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The command_mode. - * - * @return The command_mode - */ - public final String getCommandMode() { - return this.commandMode; - } + @Getter + private final String deviceSid; - /** - * Returns The The status. - * - * @return The status - */ - public final String getStatus() { - return this.status; - } + @Getter + private final String direction; - /** - * Returns The The direction. - * - * @return The direction - */ - public final String getDirection() { - return this.direction; - } + @Getter + private final String sid; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String simSid; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String status; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private Command( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("command") final String command, + @JsonProperty("command_mode") final String commandMode, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("device_sid") final String deviceSid, + @JsonProperty("direction") final String direction, + @JsonProperty("sid") final String sid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("status") final String status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.command = command; + this.commandMode = commandMode; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.deviceSid = deviceSid; + this.direction = direction; + this.sid = sid; + this.simSid = simSid; + this.status = status; + this.url = url; } @Override @@ -265,49 +190,35 @@ public boolean equals(final Object o) { } Command other = (Command) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(deviceSid, other.deviceSid) && - Objects.equals(simSid, other.simSid) && - Objects.equals(command, other.command) && - Objects.equals(commandMode, other.commandMode) && - Objects.equals(status, other.status) && - Objects.equals(direction, other.direction) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(command, other.command) && + Objects.equals(commandMode, other.commandMode) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(deviceSid, other.deviceSid) && + Objects.equals(direction, other.direction) && + Objects.equals(sid, other.sid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - deviceSid, - simSid, - command, - commandMode, - status, - direction, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("deviceSid", deviceSid) - .add("simSid", simSid) - .add("command", command) - .add("commandMode", commandMode) - .add("status", status) - .add("direction", direction) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + command, + commandMode, + dateCreated, + dateUpdated, + deviceSid, + direction, + sid, + simSid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/CommandCreator.java b/src/main/java/com/twilio/rest/preview/wireless/CommandCreator.java index d387ed50c0..ea3233a56e 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/CommandCreator.java +++ b/src/main/java/com/twilio/rest/preview/wireless/CommandCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,16 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class CommandCreator extends Creator { - private final String command; + + private String command; private String device; private String sim; private String callbackMethod; @@ -34,162 +42,162 @@ public class CommandCreator extends Creator { private String commandMode; private String includeSid; - /** - * Construct a new CommandCreator. - * - * @param command The command - */ public CommandCreator(final String command) { this.command = command; } - /** - * The device. - * - * @param device The device - * @return this - */ + public CommandCreator setCommand(final String command) { + this.command = command; + return this; + } + public CommandCreator setDevice(final String device) { this.device = device; return this; } - /** - * The sim. - * - * @param sim The sim - * @return this - */ public CommandCreator setSim(final String sim) { this.sim = sim; return this; } - /** - * The callback_method. - * - * @param callbackMethod The callback_method - * @return this - */ public CommandCreator setCallbackMethod(final String callbackMethod) { this.callbackMethod = callbackMethod; return this; } - /** - * The callback_url. - * - * @param callbackUrl The callback_url - * @return this - */ public CommandCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - /** - * The callback_url. - * - * @param callbackUrl The callback_url - * @return this - */ public CommandCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - /** - * The command_mode. - * - * @param commandMode The command_mode - * @return this - */ public CommandCreator setCommandMode(final String commandMode) { this.commandMode = commandMode; return this; } - /** - * The include_sid. - * - * @param includeSid The include_sid - * @return this - */ public CommandCreator setIncludeSid(final String includeSid) { this.includeSid = includeSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Command - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Command create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/Commands"; + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/wireless/Commands", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Command creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Command creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Command create(final TwilioRestClient client) { + Response response = makeRequest(client); return Command.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Command content = Command.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (command != null) { - request.addPostParam("Command", command); + Serializer.toString( + request, + "Command", + command, + ParameterType.URLENCODED + ); } if (device != null) { - request.addPostParam("Device", device); + Serializer.toString( + request, + "Device", + device, + ParameterType.URLENCODED + ); } if (sim != null) { - request.addPostParam("Sim", sim); + Serializer.toString(request, "Sim", sim, ParameterType.URLENCODED); } if (callbackMethod != null) { - request.addPostParam("CallbackMethod", callbackMethod); + Serializer.toString( + request, + "CallbackMethod", + callbackMethod, + ParameterType.URLENCODED + ); } if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); } if (commandMode != null) { - request.addPostParam("CommandMode", commandMode); + Serializer.toString( + request, + "CommandMode", + commandMode, + ParameterType.URLENCODED + ); } if (includeSid != null) { - request.addPostParam("IncludeSid", includeSid); + Serializer.toString( + request, + "IncludeSid", + includeSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/CommandFetcher.java b/src/main/java/com/twilio/rest/preview/wireless/CommandFetcher.java index 912a1119ca..44b3989515 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/CommandFetcher.java +++ b/src/main/java/com/twilio/rest/preview/wireless/CommandFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,59 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class CommandFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new CommandFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public CommandFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Command - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Command fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/Commands/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/wireless/Commands/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Command fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Command fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Command fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Command.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Command content = Command.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/CommandReader.java b/src/main/java/com/twilio/rest/preview/wireless/CommandReader.java index 6051f0b0af..057e62c196 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/CommandReader.java +++ b/src/main/java/com/twilio/rest/preview/wireless/CommandReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; @@ -10,218 +17,231 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class CommandReader extends Reader { + private String device; private String sim; private String status; private String direction; + private Long pageSize; + + public CommandReader() {} - /** - * The device. - * - * @param device The device - * @return this - */ public CommandReader setDevice(final String device) { this.device = device; return this; } - /** - * The sim. - * - * @param sim The sim - * @return this - */ public CommandReader setSim(final String sim) { this.sim = sim; return this; } - /** - * The status. - * - * @param status The status - * @return this - */ public CommandReader setStatus(final String status) { this.status = status; return this; } - /** - * The direction. - * - * @param direction The direction - * @return this - */ public CommandReader setDirection(final String direction) { this.direction = direction; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Command ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public CommandReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Command ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "commands", + response.getContent(), + Command.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/wireless/Commands"; + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/wireless/Commands", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Command ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "commands", + response.getContent(), + Command.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Command read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "commands", + response.getContent(), + Command.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Command Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Command read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "commands", - response.getContent(), - Command.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (device != null) { - request.addQueryParam("Device", device); + Serializer.toString(request, "Device", device, ParameterType.QUERY); } if (sim != null) { - request.addQueryParam("Sim", sim); + Serializer.toString(request, "Sim", sim, ParameterType.QUERY); } if (status != null) { - request.addQueryParam("Status", status); + Serializer.toString(request, "Status", status, ParameterType.QUERY); } if (direction != null) { - request.addQueryParam("Direction", direction); + Serializer.toString( + request, + "Direction", + direction, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlan.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlan.java index e79a63edea..cd2483797f 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlan.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlan.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; @@ -11,94 +18,62 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class RatePlan extends Resource { - private static final long serialVersionUID = 263617052418126L; - /** - * Create a RatePlanReader to execute read. - * - * @return RatePlanReader capable of executing the read - */ - public static RatePlanReader reader() { - return new RatePlanReader(); + public static RatePlanCreator creator() { + return new RatePlanCreator(); + } + + public static RatePlanDeleter deleter(final String pathSid) { + return new RatePlanDeleter(pathSid); } - /** - * Create a RatePlanFetcher to execute fetch. - * - * @param pathSid The sid - * @return RatePlanFetcher capable of executing the fetch - */ public static RatePlanFetcher fetcher(final String pathSid) { return new RatePlanFetcher(pathSid); } - /** - * Create a RatePlanCreator to execute create. - * - * @return RatePlanCreator capable of executing the create - */ - public static RatePlanCreator creator() { - return new RatePlanCreator(); + public static RatePlanReader reader() { + return new RatePlanReader(); } - /** - * Create a RatePlanUpdater to execute update. - * - * @param pathSid The sid - * @return RatePlanUpdater capable of executing the update - */ public static RatePlanUpdater updater(final String pathSid) { return new RatePlanUpdater(pathSid); } /** - * Create a RatePlanDeleter to execute delete. - * - * @param pathSid The sid - * @return RatePlanDeleter capable of executing the delete - */ - public static RatePlanDeleter deleter(final String pathSid) { - return new RatePlanDeleter(pathSid); - } - - /** - * Converts a JSON String into a RatePlan object using the provided - * ObjectMapper. - * + * Converts a JSON String into a RatePlan object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return RatePlan object represented by the provided JSON */ - public static RatePlan fromJson(final String json, final ObjectMapper objectMapper) { + public static RatePlan fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, RatePlan.class); @@ -112,12 +87,15 @@ public static RatePlan fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a RatePlan object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return RatePlan object represented by the provided JSON */ - public static RatePlan fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static RatePlan fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, RatePlan.class); @@ -128,190 +106,105 @@ public static RatePlan fromJson(final InputStream json, final ObjectMapper objec } } - private final String sid; - private final String uniqueName; - private final String accountSid; - private final String friendlyName; - private final Boolean dataEnabled; - private final String dataMetering; - private final Integer dataLimit; - private final Boolean messagingEnabled; - private final Boolean voiceEnabled; - private final Boolean nationalRoamingEnabled; - private final List internationalRoaming; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private RatePlan(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("data_enabled") - final Boolean dataEnabled, - @JsonProperty("data_metering") - final String dataMetering, - @JsonProperty("data_limit") - final Integer dataLimit, - @JsonProperty("messaging_enabled") - final Boolean messagingEnabled, - @JsonProperty("voice_enabled") - final Boolean voiceEnabled, - @JsonProperty("national_roaming_enabled") - final Boolean nationalRoamingEnabled, - @JsonProperty("international_roaming") - final List internationalRoaming, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dataEnabled = dataEnabled; - this.dataMetering = dataMetering; - this.dataLimit = dataLimit; - this.messagingEnabled = messagingEnabled; - this.voiceEnabled = voiceEnabled; - this.nationalRoamingEnabled = nationalRoamingEnabled; - this.internationalRoaming = internationalRoaming; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique_name. - * - * @return The unique_name - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final Boolean dataEnabled; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Integer dataLimit; - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String dataMetering; - /** - * Returns The The data_enabled. - * - * @return The data_enabled - */ - public final Boolean getDataEnabled() { - return this.dataEnabled; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The data_metering. - * - * @return The data_metering - */ - public final String getDataMetering() { - return this.dataMetering; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The data_limit. - * - * @return The data_limit - */ - public final Integer getDataLimit() { - return this.dataLimit; - } + @Getter + private final String friendlyName; - /** - * Returns The The messaging_enabled. - * - * @return The messaging_enabled - */ - public final Boolean getMessagingEnabled() { - return this.messagingEnabled; - } + @Getter + private final List internationalRoaming; - /** - * Returns The The voice_enabled. - * - * @return The voice_enabled - */ - public final Boolean getVoiceEnabled() { - return this.voiceEnabled; - } + @Getter + private final Boolean messagingEnabled; - /** - * Returns The The national_roaming_enabled. - * - * @return The national_roaming_enabled - */ - public final Boolean getNationalRoamingEnabled() { - return this.nationalRoamingEnabled; - } + @Getter + private final Boolean nationalRoamingEnabled; - /** - * Returns The The international_roaming. - * - * @return The international_roaming - */ - public final List getInternationalRoaming() { - return this.internationalRoaming; - } + @Getter + private final String sid; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String uniqueName; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final URI url; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + @Getter + private final Boolean voiceEnabled; + + @JsonCreator + private RatePlan( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("data_enabled") final Boolean dataEnabled, + @JsonProperty("data_limit") final Integer dataLimit, + @JsonProperty("data_metering") final String dataMetering, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("international_roaming") final List< + String + > internationalRoaming, + @JsonProperty("messaging_enabled") final Boolean messagingEnabled, + @JsonProperty( + "national_roaming_enabled" + ) final Boolean nationalRoamingEnabled, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("voice_enabled") final Boolean voiceEnabled + ) { + this.accountSid = accountSid; + this.dataEnabled = dataEnabled; + this.dataLimit = dataLimit; + this.dataMetering = dataMetering; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.internationalRoaming = internationalRoaming; + this.messagingEnabled = messagingEnabled; + this.nationalRoamingEnabled = nationalRoamingEnabled; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + this.voiceEnabled = voiceEnabled; } @Override @@ -325,58 +218,44 @@ public boolean equals(final Object o) { } RatePlan other = (RatePlan) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dataEnabled, other.dataEnabled) && - Objects.equals(dataMetering, other.dataMetering) && - Objects.equals(dataLimit, other.dataLimit) && - Objects.equals(messagingEnabled, other.messagingEnabled) && - Objects.equals(voiceEnabled, other.voiceEnabled) && - Objects.equals(nationalRoamingEnabled, other.nationalRoamingEnabled) && - Objects.equals(internationalRoaming, other.internationalRoaming) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dataEnabled, other.dataEnabled) && + Objects.equals(dataLimit, other.dataLimit) && + Objects.equals(dataMetering, other.dataMetering) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(internationalRoaming, other.internationalRoaming) && + Objects.equals(messagingEnabled, other.messagingEnabled) && + Objects.equals( + nationalRoamingEnabled, + other.nationalRoamingEnabled + ) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(voiceEnabled, other.voiceEnabled) + ); } @Override public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - friendlyName, - dataEnabled, - dataMetering, - dataLimit, - messagingEnabled, - voiceEnabled, - nationalRoamingEnabled, - internationalRoaming, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dataEnabled", dataEnabled) - .add("dataMetering", dataMetering) - .add("dataLimit", dataLimit) - .add("messagingEnabled", messagingEnabled) - .add("voiceEnabled", voiceEnabled) - .add("nationalRoamingEnabled", nationalRoamingEnabled) - .add("internationalRoaming", internationalRoaming) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + dataEnabled, + dataLimit, + dataMetering, + dateCreated, + dateUpdated, + friendlyName, + internationalRoaming, + messagingEnabled, + nationalRoamingEnabled, + sid, + uniqueName, + url, + voiceEnabled + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanCreator.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanCreator.java index 137d0213ac..39556c17f0 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanCreator.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,15 +28,12 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class RatePlanCreator extends Creator { + private String uniqueName; private String friendlyName; private Boolean dataEnabled; @@ -37,211 +45,220 @@ public class RatePlanCreator extends Creator { private Boolean nationalRoamingEnabled; private List internationalRoaming; - /** - * The unique_name. - * - * @param uniqueName The unique_name - * @return this - */ + public RatePlanCreator() {} + public RatePlanCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public RatePlanCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The data_enabled. - * - * @param dataEnabled The data_enabled - * @return this - */ public RatePlanCreator setDataEnabled(final Boolean dataEnabled) { this.dataEnabled = dataEnabled; return this; } - /** - * The data_limit. - * - * @param dataLimit The data_limit - * @return this - */ public RatePlanCreator setDataLimit(final Integer dataLimit) { this.dataLimit = dataLimit; return this; } - /** - * The data_metering. - * - * @param dataMetering The data_metering - * @return this - */ public RatePlanCreator setDataMetering(final String dataMetering) { this.dataMetering = dataMetering; return this; } - /** - * The messaging_enabled. - * - * @param messagingEnabled The messaging_enabled - * @return this - */ public RatePlanCreator setMessagingEnabled(final Boolean messagingEnabled) { this.messagingEnabled = messagingEnabled; return this; } - /** - * The voice_enabled. - * - * @param voiceEnabled The voice_enabled - * @return this - */ public RatePlanCreator setVoiceEnabled(final Boolean voiceEnabled) { this.voiceEnabled = voiceEnabled; return this; } - /** - * The commands_enabled. - * - * @param commandsEnabled The commands_enabled - * @return this - */ public RatePlanCreator setCommandsEnabled(final Boolean commandsEnabled) { this.commandsEnabled = commandsEnabled; return this; } - /** - * The national_roaming_enabled. - * - * @param nationalRoamingEnabled The national_roaming_enabled - * @return this - */ - public RatePlanCreator setNationalRoamingEnabled(final Boolean nationalRoamingEnabled) { + public RatePlanCreator setNationalRoamingEnabled( + final Boolean nationalRoamingEnabled + ) { this.nationalRoamingEnabled = nationalRoamingEnabled; return this; } - /** - * The international_roaming. - * - * @param internationalRoaming The international_roaming - * @return this - */ - public RatePlanCreator setInternationalRoaming(final List internationalRoaming) { + public RatePlanCreator setInternationalRoaming( + final List internationalRoaming + ) { this.internationalRoaming = internationalRoaming; return this; } - /** - * The international_roaming. - * - * @param internationalRoaming The international_roaming - * @return this - */ - public RatePlanCreator setInternationalRoaming(final String internationalRoaming) { - return setInternationalRoaming(Promoter.listOfOne(internationalRoaming)); + public RatePlanCreator setInternationalRoaming( + final String internationalRoaming + ) { + return setInternationalRoaming( + Promoter.listOfOne(internationalRoaming) + ); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created RatePlan - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public RatePlan create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/RatePlans"; + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/wireless/RatePlans", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "RatePlan creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public RatePlan create(final TwilioRestClient client) { + Response response = makeRequest(client); + return RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return RatePlan.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + RatePlan content = RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (dataEnabled != null) { - request.addPostParam("DataEnabled", dataEnabled.toString()); + Serializer.toString( + request, + "DataEnabled", + dataEnabled, + ParameterType.URLENCODED + ); } if (dataLimit != null) { - request.addPostParam("DataLimit", dataLimit.toString()); + Serializer.toString( + request, + "DataLimit", + dataLimit, + ParameterType.URLENCODED + ); } if (dataMetering != null) { - request.addPostParam("DataMetering", dataMetering); + Serializer.toString( + request, + "DataMetering", + dataMetering, + ParameterType.URLENCODED + ); } if (messagingEnabled != null) { - request.addPostParam("MessagingEnabled", messagingEnabled.toString()); + Serializer.toString( + request, + "MessagingEnabled", + messagingEnabled, + ParameterType.URLENCODED + ); } if (voiceEnabled != null) { - request.addPostParam("VoiceEnabled", voiceEnabled.toString()); + Serializer.toString( + request, + "VoiceEnabled", + voiceEnabled, + ParameterType.URLENCODED + ); } if (commandsEnabled != null) { - request.addPostParam("CommandsEnabled", commandsEnabled.toString()); + Serializer.toString( + request, + "CommandsEnabled", + commandsEnabled, + ParameterType.URLENCODED + ); } if (nationalRoamingEnabled != null) { - request.addPostParam("NationalRoamingEnabled", nationalRoamingEnabled.toString()); + Serializer.toString( + request, + "NationalRoamingEnabled", + nationalRoamingEnabled, + ParameterType.URLENCODED + ); } if (internationalRoaming != null) { - for (String prop : internationalRoaming) { - request.addPostParam("InternationalRoaming", prop); + for (String param : internationalRoaming) { + Serializer.toString( + request, + "InternationalRoaming", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanDeleter.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanDeleter.java index 32112d3857..26e3eed004 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanDeleter.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class RatePlanDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new RatePlanDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public RatePlanDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/RatePlans/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.PREVIEW.toString(), - "/wireless/RatePlans/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "RatePlan delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanFetcher.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanFetcher.java index cd18b45c43..5332e86d3b 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanFetcher.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,59 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class RatePlanFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new RatePlanFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public RatePlanFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched RatePlan - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public RatePlan fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/RatePlans/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/wireless/RatePlans/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "RatePlan fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return RatePlan.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public RatePlan fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + RatePlan content = RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanReader.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanReader.java index 511913be93..ca1644d537 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanReader.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; @@ -10,153 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class RatePlanReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return RatePlan ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public RatePlanReader() {} + + public RatePlanReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return RatePlan ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "rate_plans", + response.getContent(), + RatePlan.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/wireless/RatePlans"; + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/wireless/RatePlans", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return RatePlan ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "rate_plans", + response.getContent(), + RatePlan.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "RatePlan read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "rate_plans", + response.getContent(), + RatePlan.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of RatePlan Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("RatePlan read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "rate_plans", - response.getContent(), - RatePlan.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/RatePlanUpdater.java b/src/main/java/com/twilio/rest/preview/wireless/RatePlanUpdater.java index 2052cf4b8b..bf808b1f0f 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/RatePlanUpdater.java +++ b/src/main/java/com/twilio/rest/preview/wireless/RatePlanUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,99 +27,107 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class RatePlanUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String uniqueName; private String friendlyName; - /** - * Construct a new RatePlanUpdater. - * - * @param pathSid The sid - */ public RatePlanUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * The unique_name. - * - * @param uniqueName The unique_name - * @return this - */ public RatePlanUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public RatePlanUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated RatePlan - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public RatePlan update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/RatePlans/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/wireless/RatePlans/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("RatePlan update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "RatePlan update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return RatePlan.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public RatePlan update(final TwilioRestClient client) { + Response response = makeRequest(client); + return RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + RatePlan content = RatePlan.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/Sim.java b/src/main/java/com/twilio/rest/preview/wireless/Sim.java index 1791ce9414..4de829b0a3 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/Sim.java +++ b/src/main/java/com/twilio/rest/preview/wireless/Sim.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; @@ -11,73 +18,55 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Sim extends Resource { - private static final long serialVersionUID = 114188106016645L; - /** - * Create a SimFetcher to execute fetch. - * - * @param pathSid The sid - * @return SimFetcher capable of executing the fetch - */ public static SimFetcher fetcher(final String pathSid) { return new SimFetcher(pathSid); } - /** - * Create a SimReader to execute read. - * - * @return SimReader capable of executing the read - */ public static SimReader reader() { return new SimReader(); } - /** - * Create a SimUpdater to execute update. - * - * @param pathSid The sid - * @return SimUpdater capable of executing the update - */ public static SimUpdater updater(final String pathSid) { return new SimUpdater(pathSid); } /** * Converts a JSON String into a Sim object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Sim object represented by the provided JSON */ - public static Sim fromJson(final String json, final ObjectMapper objectMapper) { + public static Sim fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sim.class); @@ -91,12 +80,15 @@ public static Sim fromJson(final String json, final ObjectMapper objectMapper) { /** * Converts a JSON InputStream into a Sim object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Sim object represented by the provided JSON */ - public static Sim fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Sim fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Sim.class); @@ -107,294 +99,145 @@ public static Sim fromJson(final InputStream json, final ObjectMapper objectMapp } } - private final String sid; - private final String uniqueName; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String ratePlanSid; + + @Getter + private final String commandsCallbackMethod; + + @Getter + private final URI commandsCallbackUrl; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String eId; + + @Getter private final String friendlyName; + + @Getter private final String iccid; - private final String eId; - private final String status; - private final URI commandsCallbackUrl; - private final String commandsCallbackMethod; + + @Getter + private final Map links; + + @Getter + private final String ratePlanSid; + + @Getter + private final String sid; + + @Getter private final HttpMethod smsFallbackMethod; + + @Getter private final URI smsFallbackUrl; + + @Getter private final HttpMethod smsMethod; + + @Getter private final URI smsUrl; + + @Getter + private final String status; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @Getter private final HttpMethod voiceFallbackMethod; + + @Getter private final URI voiceFallbackUrl; + + @Getter private final HttpMethod voiceMethod; + + @Getter private final URI voiceUrl; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; @JsonCreator - private Sim(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("rate_plan_sid") - final String ratePlanSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("iccid") - final String iccid, - @JsonProperty("e_id") - final String eId, - @JsonProperty("status") - final String status, - @JsonProperty("commands_callback_url") - final URI commandsCallbackUrl, - @JsonProperty("commands_callback_method") - final String commandsCallbackMethod, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_url") - final URI voiceUrl, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.uniqueName = uniqueName; + private Sim( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "commands_callback_method" + ) final String commandsCallbackMethod, + @JsonProperty("commands_callback_url") final URI commandsCallbackUrl, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("e_id") final String eId, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("iccid") final String iccid, + @JsonProperty("links") final Map links, + @JsonProperty("rate_plan_sid") final String ratePlanSid, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status") final String status, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl + ) { this.accountSid = accountSid; - this.ratePlanSid = ratePlanSid; + this.commandsCallbackMethod = commandsCallbackMethod; + this.commandsCallbackUrl = commandsCallbackUrl; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.eId = eId; this.friendlyName = friendlyName; this.iccid = iccid; - this.eId = eId; - this.status = status; - this.commandsCallbackUrl = commandsCallbackUrl; - this.commandsCallbackMethod = commandsCallbackMethod; + this.links = links; + this.ratePlanSid = ratePlanSid; + this.sid = sid; this.smsFallbackMethod = smsFallbackMethod; this.smsFallbackUrl = smsFallbackUrl; this.smsMethod = smsMethod; this.smsUrl = smsUrl; + this.status = status; + this.uniqueName = uniqueName; + this.url = url; this.voiceFallbackMethod = voiceFallbackMethod; this.voiceFallbackUrl = voiceFallbackUrl; this.voiceMethod = voiceMethod; this.voiceUrl = voiceUrl; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique_name. - * - * @return The unique_name - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The rate_plan_sid. - * - * @return The rate_plan_sid - */ - public final String getRatePlanSid() { - return this.ratePlanSid; - } - - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The iccid. - * - * @return The iccid - */ - public final String getIccid() { - return this.iccid; - } - - /** - * Returns The The e_id. - * - * @return The e_id - */ - public final String getEId() { - return this.eId; - } - - /** - * Returns The The status. - * - * @return The status - */ - public final String getStatus() { - return this.status; - } - - /** - * Returns The The commands_callback_url. - * - * @return The commands_callback_url - */ - public final URI getCommandsCallbackUrl() { - return this.commandsCallbackUrl; - } - - /** - * Returns The The commands_callback_method. - * - * @return The commands_callback_method - */ - public final String getCommandsCallbackMethod() { - return this.commandsCallbackMethod; - } - - /** - * Returns The The sms_fallback_method. - * - * @return The sms_fallback_method - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - - /** - * Returns The The sms_fallback_url. - * - * @return The sms_fallback_url - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - - /** - * Returns The The sms_method. - * - * @return The sms_method - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - - /** - * Returns The The sms_url. - * - * @return The sms_url - */ - public final URI getSmsUrl() { - return this.smsUrl; - } - - /** - * Returns The The voice_fallback_method. - * - * @return The voice_fallback_method - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - - /** - * Returns The The voice_fallback_url. - * - * @return The voice_fallback_url - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - - /** - * Returns The The voice_method. - * - * @return The voice_method - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - - /** - * Returns The The voice_url. - * - * @return The voice_url - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -408,82 +251,60 @@ public boolean equals(final Object o) { } Sim other = (Sim) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(ratePlanSid, other.ratePlanSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(iccid, other.iccid) && - Objects.equals(eId, other.eId) && - Objects.equals(status, other.status) && - Objects.equals(commandsCallbackUrl, other.commandsCallbackUrl) && - Objects.equals(commandsCallbackMethod, other.commandsCallbackMethod) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceUrl, other.voiceUrl) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + commandsCallbackMethod, + other.commandsCallbackMethod + ) && + Objects.equals(commandsCallbackUrl, other.commandsCallbackUrl) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(eId, other.eId) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(iccid, other.iccid) && + Objects.equals(links, other.links) && + Objects.equals(ratePlanSid, other.ratePlanSid) && + Objects.equals(sid, other.sid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(status, other.status) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - ratePlanSid, - friendlyName, - iccid, - eId, - status, - commandsCallbackUrl, - commandsCallbackMethod, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsUrl, - voiceFallbackMethod, - voiceFallbackUrl, - voiceMethod, - voiceUrl, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("ratePlanSid", ratePlanSid) - .add("friendlyName", friendlyName) - .add("iccid", iccid) - .add("eId", eId) - .add("status", status) - .add("commandsCallbackUrl", commandsCallbackUrl) - .add("commandsCallbackMethod", commandsCallbackMethod) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsUrl", smsUrl) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceMethod", voiceMethod) - .add("voiceUrl", voiceUrl) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + commandsCallbackMethod, + commandsCallbackUrl, + dateCreated, + dateUpdated, + eId, + friendlyName, + iccid, + links, + ratePlanSid, + sid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + status, + uniqueName, + url, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/SimFetcher.java b/src/main/java/com/twilio/rest/preview/wireless/SimFetcher.java index 1da790cc07..e4a887b310 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/SimFetcher.java +++ b/src/main/java/com/twilio/rest/preview/wireless/SimFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,59 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class SimFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new SimFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public SimFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Sim - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Sim fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/Sims/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/wireless/Sims/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Sim fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Sim fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Sim.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Sim content = Sim.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/SimReader.java b/src/main/java/com/twilio/rest/preview/wireless/SimReader.java index 80ffb31749..c3ac330f31 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/SimReader.java +++ b/src/main/java/com/twilio/rest/preview/wireless/SimReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; @@ -10,234 +17,242 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class SimReader extends Reader { + private String status; private String iccid; private String ratePlan; - private String eId; + private String eid; private String simRegistrationCode; + private Long pageSize; + + public SimReader() {} - /** - * The status. - * - * @param status The status - * @return this - */ public SimReader setStatus(final String status) { this.status = status; return this; } - /** - * The iccid. - * - * @param iccid The iccid - * @return this - */ public SimReader setIccid(final String iccid) { this.iccid = iccid; return this; } - /** - * The rate_plan. - * - * @param ratePlan The rate_plan - * @return this - */ public SimReader setRatePlan(final String ratePlan) { this.ratePlan = ratePlan; return this; } - /** - * The e_id. - * - * @param eId The e_id - * @return this - */ - public SimReader setEId(final String eId) { - this.eId = eId; + public SimReader setEid(final String eid) { + this.eid = eid; return this; } - /** - * The sim_registration_code. - * - * @param simRegistrationCode The sim_registration_code - * @return this - */ public SimReader setSimRegistrationCode(final String simRegistrationCode) { this.simRegistrationCode = simRegistrationCode; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Sim ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SimReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Sim ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sims", + response.getContent(), + Sim.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/wireless/Sims"; + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/wireless/Sims", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Sim ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sims", + response.getContent(), + Sim.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Sim read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "sims", + response.getContent(), + Sim.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PREVIEW.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Sim Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Sim read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "sims", - response.getContent(), - Sim.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (status != null) { - request.addQueryParam("Status", status); + Serializer.toString(request, "Status", status, ParameterType.QUERY); } if (iccid != null) { - request.addQueryParam("Iccid", iccid); + Serializer.toString(request, "Iccid", iccid, ParameterType.QUERY); } if (ratePlan != null) { - request.addQueryParam("RatePlan", ratePlan); + Serializer.toString( + request, + "RatePlan", + ratePlan, + ParameterType.QUERY + ); } - if (eId != null) { - request.addQueryParam("EId", eId); + if (eid != null) { + Serializer.toString(request, "EId", eid, ParameterType.QUERY); } if (simRegistrationCode != null) { - request.addQueryParam("SimRegistrationCode", simRegistrationCode); + Serializer.toString( + request, + "SimRegistrationCode", + simRegistrationCode, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/SimUpdater.java b/src/main/java/com/twilio/rest/preview/wireless/SimUpdater.java index fc20c533a0..dade14f3e5 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/SimUpdater.java +++ b/src/main/java/com/twilio/rest/preview/wireless/SimUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,16 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class SimUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String uniqueName; private String callbackMethod; private URI callbackUrl; @@ -44,358 +52,321 @@ public class SimUpdater extends Updater { private HttpMethod voiceMethod; private URI voiceUrl; - /** - * Construct a new SimUpdater. - * - * @param pathSid The sid - */ public SimUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * The unique_name. - * - * @param uniqueName The unique_name - * @return this - */ public SimUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * The callback_method. - * - * @param callbackMethod The callback_method - * @return this - */ public SimUpdater setCallbackMethod(final String callbackMethod) { this.callbackMethod = callbackMethod; return this; } - /** - * The callback_url. - * - * @param callbackUrl The callback_url - * @return this - */ public SimUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - /** - * The callback_url. - * - * @param callbackUrl The callback_url - * @return this - */ public SimUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public SimUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The rate_plan. - * - * @param ratePlan The rate_plan - * @return this - */ public SimUpdater setRatePlan(final String ratePlan) { this.ratePlan = ratePlan; return this; } - /** - * The status. - * - * @param status The status - * @return this - */ public SimUpdater setStatus(final String status) { this.status = status; return this; } - /** - * The commands_callback_method. - * - * @param commandsCallbackMethod The commands_callback_method - * @return this - */ - public SimUpdater setCommandsCallbackMethod(final HttpMethod commandsCallbackMethod) { + public SimUpdater setCommandsCallbackMethod( + final HttpMethod commandsCallbackMethod + ) { this.commandsCallbackMethod = commandsCallbackMethod; return this; } - /** - * The commands_callback_url. - * - * @param commandsCallbackUrl The commands_callback_url - * @return this - */ public SimUpdater setCommandsCallbackUrl(final URI commandsCallbackUrl) { this.commandsCallbackUrl = commandsCallbackUrl; return this; } - /** - * The commands_callback_url. - * - * @param commandsCallbackUrl The commands_callback_url - * @return this - */ public SimUpdater setCommandsCallbackUrl(final String commandsCallbackUrl) { - return setCommandsCallbackUrl(Promoter.uriFromString(commandsCallbackUrl)); + return setCommandsCallbackUrl( + Promoter.uriFromString(commandsCallbackUrl) + ); } - /** - * The sms_fallback_method. - * - * @param smsFallbackMethod The sms_fallback_method - * @return this - */ public SimUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod) { this.smsFallbackMethod = smsFallbackMethod; return this; } - /** - * The sms_fallback_url. - * - * @param smsFallbackUrl The sms_fallback_url - * @return this - */ public SimUpdater setSmsFallbackUrl(final URI smsFallbackUrl) { this.smsFallbackUrl = smsFallbackUrl; return this; } - /** - * The sms_fallback_url. - * - * @param smsFallbackUrl The sms_fallback_url - * @return this - */ public SimUpdater setSmsFallbackUrl(final String smsFallbackUrl) { return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl)); } - /** - * The sms_method. - * - * @param smsMethod The sms_method - * @return this - */ public SimUpdater setSmsMethod(final HttpMethod smsMethod) { this.smsMethod = smsMethod; return this; } - /** - * The sms_url. - * - * @param smsUrl The sms_url - * @return this - */ public SimUpdater setSmsUrl(final URI smsUrl) { this.smsUrl = smsUrl; return this; } - /** - * The sms_url. - * - * @param smsUrl The sms_url - * @return this - */ public SimUpdater setSmsUrl(final String smsUrl) { return setSmsUrl(Promoter.uriFromString(smsUrl)); } - /** - * The voice_fallback_method. - * - * @param voiceFallbackMethod The voice_fallback_method - * @return this - */ - public SimUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) { + public SimUpdater setVoiceFallbackMethod( + final HttpMethod voiceFallbackMethod + ) { this.voiceFallbackMethod = voiceFallbackMethod; return this; } - /** - * The voice_fallback_url. - * - * @param voiceFallbackUrl The voice_fallback_url - * @return this - */ public SimUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl) { this.voiceFallbackUrl = voiceFallbackUrl; return this; } - /** - * The voice_fallback_url. - * - * @param voiceFallbackUrl The voice_fallback_url - * @return this - */ public SimUpdater setVoiceFallbackUrl(final String voiceFallbackUrl) { return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl)); } - /** - * The voice_method. - * - * @param voiceMethod The voice_method - * @return this - */ public SimUpdater setVoiceMethod(final HttpMethod voiceMethod) { this.voiceMethod = voiceMethod; return this; } - /** - * The voice_url. - * - * @param voiceUrl The voice_url - * @return this - */ public SimUpdater setVoiceUrl(final URI voiceUrl) { this.voiceUrl = voiceUrl; return this; } - /** - * The voice_url. - * - * @param voiceUrl The voice_url - * @return this - */ public SimUpdater setVoiceUrl(final String voiceUrl) { return setVoiceUrl(Promoter.uriFromString(voiceUrl)); } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Sim - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Sim update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/Sims/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.PREVIEW.toString(), - "/wireless/Sims/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Sim update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Sim update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Sim update(final TwilioRestClient client) { + Response response = makeRequest(client); return Sim.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Sim content = Sim.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (callbackMethod != null) { - request.addPostParam("CallbackMethod", callbackMethod); + Serializer.toString( + request, + "CallbackMethod", + callbackMethod, + ParameterType.URLENCODED + ); } if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (ratePlan != null) { - request.addPostParam("RatePlan", ratePlan.toString()); + Serializer.toString( + request, + "RatePlan", + ratePlan, + ParameterType.URLENCODED + ); } if (status != null) { - request.addPostParam("Status", status); + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); } if (commandsCallbackMethod != null) { - request.addPostParam("CommandsCallbackMethod", commandsCallbackMethod.toString()); + Serializer.toString( + request, + "CommandsCallbackMethod", + commandsCallbackMethod, + ParameterType.URLENCODED + ); } if (commandsCallbackUrl != null) { - request.addPostParam("CommandsCallbackUrl", commandsCallbackUrl.toString()); + Serializer.toString( + request, + "CommandsCallbackUrl", + commandsCallbackUrl, + ParameterType.URLENCODED + ); } if (smsFallbackMethod != null) { - request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString()); + Serializer.toString( + request, + "SmsFallbackMethod", + smsFallbackMethod, + ParameterType.URLENCODED + ); } if (smsFallbackUrl != null) { - request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString()); + Serializer.toString( + request, + "SmsFallbackUrl", + smsFallbackUrl, + ParameterType.URLENCODED + ); } if (smsMethod != null) { - request.addPostParam("SmsMethod", smsMethod.toString()); + Serializer.toString( + request, + "SmsMethod", + smsMethod, + ParameterType.URLENCODED + ); } if (smsUrl != null) { - request.addPostParam("SmsUrl", smsUrl.toString()); + Serializer.toString( + request, + "SmsUrl", + smsUrl, + ParameterType.URLENCODED + ); } if (voiceFallbackMethod != null) { - request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString()); + Serializer.toString( + request, + "VoiceFallbackMethod", + voiceFallbackMethod, + ParameterType.URLENCODED + ); } if (voiceFallbackUrl != null) { - request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString()); + Serializer.toString( + request, + "VoiceFallbackUrl", + voiceFallbackUrl, + ParameterType.URLENCODED + ); } if (voiceMethod != null) { - request.addPostParam("VoiceMethod", voiceMethod.toString()); + Serializer.toString( + request, + "VoiceMethod", + voiceMethod, + ParameterType.URLENCODED + ); } if (voiceUrl != null) { - request.addPostParam("VoiceUrl", voiceUrl.toString()); + Serializer.toString( + request, + "VoiceUrl", + voiceUrl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/sim/Usage.java b/src/main/java/com/twilio/rest/preview/wireless/sim/Usage.java index c58e3b3ddd..064a9e4a37 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/sim/Usage.java +++ b/src/main/java/com/twilio/rest/preview/wireless/sim/Usage.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless.sim; @@ -11,53 +18,42 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Usage extends Resource { - private static final long serialVersionUID = 16456693522984L; - /** - * Create a UsageFetcher to execute fetch. - * - * @param pathSimSid The sim_sid - * @return UsageFetcher capable of executing the fetch - */ public static UsageFetcher fetcher(final String pathSimSid) { return new UsageFetcher(pathSimSid); } /** * Converts a JSON String into a Usage object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Usage object represented by the provided JSON */ - public static Usage fromJson(final String json, final ObjectMapper objectMapper) { + public static Usage fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Usage.class); @@ -71,12 +67,15 @@ public static Usage fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Usage object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Usage object represented by the provided JSON */ - public static Usage fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Usage fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Usage.class); @@ -87,125 +86,66 @@ public static Usage fromJson(final InputStream json, final ObjectMapper objectMa } } - private final String simSid; - private final String simUniqueName; - private final String accountSid; - private final Map period; - private final Map commandsUsage; - private final Map commandsCosts; - private final Map dataUsage; - private final Map dataCosts; - private final URI url; - - @JsonCreator - private Usage(@JsonProperty("sim_sid") - final String simSid, - @JsonProperty("sim_unique_name") - final String simUniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("period") - final Map period, - @JsonProperty("commands_usage") - final Map commandsUsage, - @JsonProperty("commands_costs") - final Map commandsCosts, - @JsonProperty("data_usage") - final Map dataUsage, - @JsonProperty("data_costs") - final Map dataCosts, - @JsonProperty("url") - final URI url) { - this.simSid = simSid; - this.simUniqueName = simUniqueName; - this.accountSid = accountSid; - this.period = period; - this.commandsUsage = commandsUsage; - this.commandsCosts = commandsCosts; - this.dataUsage = dataUsage; - this.dataCosts = dataCosts; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sim_sid. - * - * @return The sim_sid - */ - public final String getSimSid() { - return this.simSid; - } + @Getter + private final String accountSid; - /** - * Returns The The sim_unique_name. - * - * @return The sim_unique_name - */ - public final String getSimUniqueName() { - return this.simUniqueName; - } + @Getter + private final Object commandsCosts; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Object commandsUsage; - /** - * Returns The The period. - * - * @return The period - */ - public final Map getPeriod() { - return this.period; - } + @Getter + private final Object dataCosts; - /** - * Returns The The commands_usage. - * - * @return The commands_usage - */ - public final Map getCommandsUsage() { - return this.commandsUsage; - } + @Getter + private final Object dataUsage; - /** - * Returns The The commands_costs. - * - * @return The commands_costs - */ - public final Map getCommandsCosts() { - return this.commandsCosts; - } + @Getter + private final Object period; - /** - * Returns The The data_usage. - * - * @return The data_usage - */ - public final Map getDataUsage() { - return this.dataUsage; - } + @Getter + private final String simSid; - /** - * Returns The The data_costs. - * - * @return The data_costs - */ - public final Map getDataCosts() { - return this.dataCosts; - } + @Getter + private final String simUniqueName; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + @Getter + private final URI url; + + @JsonCreator + private Usage( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("commands_costs") final Object commandsCosts, + @JsonProperty("commands_usage") final Object commandsUsage, + @JsonProperty("data_costs") final Object dataCosts, + @JsonProperty("data_usage") final Object dataUsage, + @JsonProperty("period") final Object period, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("sim_unique_name") final String simUniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.commandsCosts = commandsCosts; + this.commandsUsage = commandsUsage; + this.dataCosts = dataCosts; + this.dataUsage = dataUsage; + this.period = period; + this.simSid = simSid; + this.simUniqueName = simUniqueName; + this.url = url; } @Override @@ -219,43 +159,31 @@ public boolean equals(final Object o) { } Usage other = (Usage) o; - - return Objects.equals(simSid, other.simSid) && - Objects.equals(simUniqueName, other.simUniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(period, other.period) && - Objects.equals(commandsUsage, other.commandsUsage) && - Objects.equals(commandsCosts, other.commandsCosts) && - Objects.equals(dataUsage, other.dataUsage) && - Objects.equals(dataCosts, other.dataCosts) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(commandsCosts, other.commandsCosts) && + Objects.equals(commandsUsage, other.commandsUsage) && + Objects.equals(dataCosts, other.dataCosts) && + Objects.equals(dataUsage, other.dataUsage) && + Objects.equals(period, other.period) && + Objects.equals(simSid, other.simSid) && + Objects.equals(simUniqueName, other.simUniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(simSid, - simUniqueName, - accountSid, - period, - commandsUsage, - commandsCosts, - dataUsage, - dataCosts, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("simSid", simSid) - .add("simUniqueName", simUniqueName) - .add("accountSid", accountSid) - .add("period", period) - .add("commandsUsage", commandsUsage) - .add("commandsCosts", commandsCosts) - .add("dataUsage", dataUsage) - .add("dataCosts", dataCosts) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + commandsCosts, + commandsUsage, + dataCosts, + dataUsage, + period, + simSid, + simUniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/preview/wireless/sim/UsageFetcher.java b/src/main/java/com/twilio/rest/preview/wireless/sim/UsageFetcher.java index 54ce827ce8..9ec7966945 100644 --- a/src/main/java/com/twilio/rest/preview/wireless/sim/UsageFetcher.java +++ b/src/main/java/com/twilio/rest/preview/wireless/sim/UsageFetcher.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Preview + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.preview.wireless.sim; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,99 +26,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains preview products that are subject to - * change. Use them with caution. If you currently do not have developer preview - * access, please contact help@twilio.com. - */ public class UsageFetcher extends Fetcher { - private final String pathSimSid; + + private String pathSimSid; private String end; private String start; - /** - * Construct a new UsageFetcher. - * - * @param pathSimSid The sim_sid - */ public UsageFetcher(final String pathSimSid) { this.pathSimSid = pathSimSid; } - /** - * The end. - * - * @param end The end - * @return this - */ public UsageFetcher setEnd(final String end) { this.end = end; return this; } - /** - * The start. - * - * @param start The start - * @return this - */ public UsageFetcher setStart(final String start) { this.start = start; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Usage - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Usage fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/wireless/Sims/{SimSid}/Usage"; + + path = path.replace("{" + "SimSid" + "}", this.pathSimSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PREVIEW.toString(), - "/wireless/Sims/" + this.pathSimSid + "/Usage", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Usage fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Usage fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Usage fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Usage.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Usage content = Usage.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addQueryParams(final Request request) { if (end != null) { - request.addQueryParam("End", end); + Serializer.toString(request, "End", end, ParameterType.QUERY); } if (start != null) { - request.addQueryParam("Start", start); + Serializer.toString(request, "Start", start, ParameterType.QUERY); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/Account.java b/src/main/java/com/twilio/rest/previewiam/organizations/Account.java new file mode 100644 index 0000000000..8cba346b24 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/Account.java @@ -0,0 +1,200 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Account extends Resource { + + public static AccountFetcher fetcher( + final String pathOrganizationSid, + final String pathAccountSid + ) { + return new AccountFetcher(pathOrganizationSid, pathAccountSid); + } + + public static AccountReader reader(final String pathOrganizationSid) { + return new AccountReader(pathOrganizationSid); + } + + public enum Status { + ACTIVE("active"), + SUSPENDED("suspended"), + PENDING_CLOSURE("pending_closure"), + CLOSED("closed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a Account object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Account object represented by the provided JSON + */ + public static Account fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Account.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Account object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Account object represented by the provided JSON + */ + public static Account fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Account.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String friendlyName; + + @Getter + private final String ownerSid; + + @Getter + private final Account.Status status; + + @JsonCreator + private Account( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("owner_sid") final String ownerSid, + @JsonProperty("status") final Account.Status status + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.friendlyName = friendlyName; + this.ownerSid = ownerSid; + this.status = status; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Account other = (Account) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(ownerSid, other.ownerSid) && + Objects.equals(status, other.status) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + friendlyName, + ownerSid, + status + ); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/AccountFetcher.java b/src/main/java/com/twilio/rest/previewiam/organizations/AccountFetcher.java new file mode 100644 index 0000000000..72ad33430d --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/AccountFetcher.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AccountFetcher extends Fetcher { + + private String pathOrganizationSid; + private String pathAccountSid; + + public AccountFetcher( + final String pathOrganizationSid, + final String pathAccountSid + ) { + this.pathOrganizationSid = pathOrganizationSid; + this.pathAccountSid = pathAccountSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/Accounts/{AccountSid}"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + path = + path.replace( + "{" + "AccountSid" + "}", + this.pathAccountSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.PREVIEWIAM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Account fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Account fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Account.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Account content = Account.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/AccountReader.java b/src/main/java/com/twilio/rest/previewiam/organizations/AccountReader.java new file mode 100644 index 0000000000..d801925e27 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/AccountReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AccountReader extends Reader { + + private String pathOrganizationSid; + private Integer pageSize; + + public AccountReader(final String pathOrganizationSid) { + this.pathOrganizationSid = pathOrganizationSid; + } + + public AccountReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "content", + response.getContent(), + Account.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/Accounts"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.PREVIEWIAM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "content", + response.getContent(), + Account.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Account read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "content", + response.getContent(), + Account.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignment.java b/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignment.java new file mode 100644 index 0000000000..648522a789 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignment.java @@ -0,0 +1,334 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class RoleAssignment extends Resource { + + public static RoleAssignmentCreator creator( + final String pathOrganizationSid, + final RoleAssignment.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest + ) { + return new RoleAssignmentCreator( + pathOrganizationSid, + publicApiCreateRoleAssignmentRequest + ); + } + + public static RoleAssignmentDeleter deleter( + final String pathOrganizationSid, + final String pathRoleAssignmentSid + ) { + return new RoleAssignmentDeleter( + pathOrganizationSid, + pathRoleAssignmentSid + ); + } + + public static RoleAssignmentReader reader( + final String pathOrganizationSid + ) { + return new RoleAssignmentReader(pathOrganizationSid); + } + + @JsonDeserialize( + builder = PublicApiCreateRoleAssignmentRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class PublicApiCreateRoleAssignmentRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("role_sid") + @Getter + private final String roleSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("scope") + @Getter + private final String scope; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("identity") + @Getter + private final String identity; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resource_type") + @Getter + private final String resourceType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resource_id") + @Getter + private final String resourceId; + + private PublicApiCreateRoleAssignmentRequest(Builder builder) { + this.roleSid = builder.roleSid; + this.scope = builder.scope; + this.identity = builder.identity; + this.resourceType = builder.resourceType; + this.resourceId = builder.resourceId; + } + + public static Builder builder( + final String roleSid, + final String scope, + final String identity + ) { + return new Builder(roleSid, scope, identity); + } + + public static PublicApiCreateRoleAssignmentRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + PublicApiCreateRoleAssignmentRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("role_sid") + private String roleSid; + + @JsonProperty("scope") + private String scope; + + @JsonProperty("identity") + private String identity; + + @JsonProperty("resource_type") + private String resourceType; + + @JsonProperty("resource_id") + private String resourceId; + + @JsonCreator + public Builder( + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("scope") final String scope, + @JsonProperty("identity") final String identity + ) { + this.roleSid = roleSid; + this.scope = scope; + this.identity = identity; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resource_type") + public Builder resourceType(String resourceType) { + this.resourceType = resourceType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resource_id") + public Builder resourceId(String resourceId) { + this.resourceId = resourceId; + return this; + } + + public PublicApiCreateRoleAssignmentRequest build() { + return new PublicApiCreateRoleAssignmentRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PublicApiCreateRoleAssignmentRequest other = + (PublicApiCreateRoleAssignmentRequest) o; + return ( + Objects.equals(roleSid, other.roleSid) && + Objects.equals(scope, other.scope) && + Objects.equals(identity, other.identity) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(resourceId, other.resourceId) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + roleSid, + scope, + identity, + resourceType, + resourceId + ); + } + } + + /** + * Converts a JSON String into a RoleAssignment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return RoleAssignment object represented by the provided JSON + */ + public static RoleAssignment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RoleAssignment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a RoleAssignment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return RoleAssignment object represented by the provided JSON + */ + public static RoleAssignment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, RoleAssignment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String identity; + + @Getter + private final String resourceId; + + @Getter + private final String resourceType; + + @Getter + private final String roleSid; + + @Getter + private final String scope; + + @Getter + private final String sid; + + @JsonCreator + private RoleAssignment( + @JsonProperty("identity") final String identity, + @JsonProperty("resource_id") final String resourceId, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("role_sid") final String roleSid, + @JsonProperty("scope") final String scope, + @JsonProperty("sid") final String sid + ) { + this.identity = identity; + this.resourceId = resourceId; + this.resourceType = resourceType; + this.roleSid = roleSid; + this.scope = scope; + this.sid = sid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + RoleAssignment other = (RoleAssignment) o; + return ( + Objects.equals(identity, other.identity) && + Objects.equals(resourceId, other.resourceId) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(roleSid, other.roleSid) && + Objects.equals(scope, other.scope) && + Objects.equals(sid, other.sid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + identity, + resourceId, + resourceType, + roleSid, + scope, + sid + ); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentCreator.java b/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentCreator.java new file mode 100644 index 0000000000..8374ac254c --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentCreator.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RoleAssignmentCreator extends Creator { + + private String pathOrganizationSid; + private RoleAssignment.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest; + + public RoleAssignmentCreator( + final String pathOrganizationSid, + final RoleAssignment.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest + ) { + this.pathOrganizationSid = pathOrganizationSid; + this.publicApiCreateRoleAssignmentRequest = + publicApiCreateRoleAssignmentRequest; + } + + public RoleAssignmentCreator setPublicApiCreateRoleAssignmentRequest( + final RoleAssignment.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest + ) { + this.publicApiCreateRoleAssignmentRequest = + publicApiCreateRoleAssignmentRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/RoleAssignments"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "RoleAssignment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public RoleAssignment create(final TwilioRestClient client) { + Response response = makeRequest(client); + return RoleAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + RoleAssignment content = RoleAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (publicApiCreateRoleAssignmentRequest != null) { + request.setBody( + RoleAssignment.toJson( + publicApiCreateRoleAssignmentRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentDeleter.java b/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentDeleter.java new file mode 100644 index 0000000000..b8f4f665a1 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentDeleter.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class RoleAssignmentDeleter extends Deleter { + + private String pathOrganizationSid; + private String pathRoleAssignmentSid; + + public RoleAssignmentDeleter( + final String pathOrganizationSid, + final String pathRoleAssignmentSid + ) { + this.pathOrganizationSid = pathOrganizationSid; + this.pathRoleAssignmentSid = pathRoleAssignmentSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/Organizations/{OrganizationSid}/RoleAssignments/{RoleAssignmentSid}"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + path = + path.replace( + "{" + "RoleAssignmentSid" + "}", + this.pathRoleAssignmentSid.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.PREVIEWIAM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "RoleAssignment delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentReader.java b/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentReader.java new file mode 100644 index 0000000000..7f0a9ca660 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/RoleAssignmentReader.java @@ -0,0 +1,266 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RoleAssignmentReader extends Reader { + + private String pathOrganizationSid; + private Integer pageSize; + private String identity; + private String scope; + private String resourceType; + private String resourceId; + + public RoleAssignmentReader(final String pathOrganizationSid) { + this.pathOrganizationSid = pathOrganizationSid; + } + + public RoleAssignmentReader setPageSize(final Integer pageSize) { + this.pageSize = pageSize; + return this; + } + + public RoleAssignmentReader setIdentity(final String identity) { + this.identity = identity; + return this; + } + + public RoleAssignmentReader setScope(final String scope) { + this.scope = scope; + return this; + } + + public RoleAssignmentReader setResourceType(final String resourceType) { + this.resourceType = resourceType; + return this; + } + + public RoleAssignmentReader setResourceId(final String resourceId) { + this.resourceId = resourceId; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "content", + response.getContent(), + RoleAssignment.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/RoleAssignments"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.PREVIEWIAM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "content", + response.getContent(), + RoleAssignment.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "RoleAssignment read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "content", + response.getContent(), + RoleAssignment.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (identity != null) { + Serializer.toString( + request, + "Identity", + identity, + ParameterType.QUERY + ); + } + + if (scope != null) { + Serializer.toString(request, "Scope", scope, ParameterType.QUERY); + } + + if (resourceType != null) { + Serializer.toString( + request, + "ResourceType", + resourceType, + ParameterType.QUERY + ); + } + + if (resourceId != null) { + Serializer.toString( + request, + "ResourceId", + resourceId, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/User.java b/src/main/java/com/twilio/rest/previewiam/organizations/User.java new file mode 100644 index 0000000000..2a2076f331 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/User.java @@ -0,0 +1,999 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class User extends Resource { + + public static UserCreator creator( + final String pathOrganizationSid, + final User.ScimUser scimUser + ) { + return new UserCreator(pathOrganizationSid, scimUser); + } + + public static UserDeleter deleter( + final String pathOrganizationSid, + final String pathUserSid + ) { + return new UserDeleter(pathOrganizationSid, pathUserSid); + } + + public static UserFetcher fetcher( + final String pathOrganizationSid, + final String pathUserSid + ) { + return new UserFetcher(pathOrganizationSid, pathUserSid); + } + + public static UserReader reader(final String pathOrganizationSid) { + return new UserReader(pathOrganizationSid); + } + + public static UserPatcher patcher( + final String pathOrganizationSid, + final String pathUserSid, + final User.ScimPatchRequest scimPatchRequest + ) { + return new UserPatcher( + pathOrganizationSid, + pathUserSid, + scimPatchRequest + ); + } + + public static UserUpdater updater( + final String pathOrganizationSid, + final String pathUserSid, + final User.ScimUser scimUser + ) { + return new UserUpdater(pathOrganizationSid, pathUserSid, scimUser); + } + + @JsonDeserialize(builder = ScimUser.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ScimUser { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + @Getter + private final String id; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("externalId") + @Getter + private final String externalId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("userName") + @Getter + private final String userName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + @Getter + private final String displayName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + @Getter + private final ScimName name; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("emails") + @Getter + private final List emails; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("active") + @Getter + private final Boolean active; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("locale") + @Getter + private final String locale; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("timezone") + @Getter + private final String timezone; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("schemas") + @Getter + private final List schemas; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("meta") + @Getter + private final ScimMeta meta; + + private ScimUser(Builder builder) { + this.id = builder.id; + this.externalId = builder.externalId; + this.userName = builder.userName; + this.displayName = builder.displayName; + this.name = builder.name; + this.emails = builder.emails; + this.active = builder.active; + this.locale = builder.locale; + this.timezone = builder.timezone; + this.schemas = builder.schemas; + this.meta = builder.meta; + } + + public static Builder builder(final String userName) { + return new Builder(userName); + } + + public static ScimUser fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, ScimUser.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("id") + private String id; + + @JsonProperty("externalId") + private String externalId; + + @JsonProperty("userName") + private String userName; + + @JsonProperty("displayName") + private String displayName; + + @JsonProperty("name") + private ScimName name; + + @JsonProperty("emails") + private List emails; + + @JsonProperty("active") + private Boolean active; + + @JsonProperty("locale") + private String locale; + + @JsonProperty("timezone") + private String timezone; + + @JsonProperty("schemas") + private List schemas; + + @JsonProperty("meta") + private ScimMeta meta; + + @JsonCreator + public Builder(@JsonProperty("userName") final String userName) { + this.userName = userName; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("id") + public Builder id(String id) { + this.id = id; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("externalId") + public Builder externalId(String externalId) { + this.externalId = externalId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("displayName") + public Builder displayName(String displayName) { + this.displayName = displayName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("name") + public Builder name(ScimName name) { + this.name = name; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("emails") + public Builder emails(List emails) { + this.emails = emails; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("active") + public Builder active(Boolean active) { + this.active = active; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("locale") + public Builder locale(String locale) { + this.locale = locale; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("timezone") + public Builder timezone(String timezone) { + this.timezone = timezone; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("schemas") + public Builder schemas(List schemas) { + this.schemas = schemas; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("meta") + public Builder meta(ScimMeta meta) { + this.meta = meta; + return this; + } + + public ScimUser build() { + return new ScimUser(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ScimUser other = (ScimUser) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(externalId, other.externalId) && + Objects.equals(userName, other.userName) && + Objects.equals(displayName, other.displayName) && + Objects.equals(name, other.name) && + Objects.equals(emails, other.emails) && + Objects.equals(active, other.active) && + Objects.equals(locale, other.locale) && + Objects.equals(timezone, other.timezone) && + Objects.equals(schemas, other.schemas) && + Objects.equals(meta, other.meta) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + externalId, + userName, + displayName, + name, + emails, + active, + locale, + timezone, + schemas, + meta + ); + } + } + + @JsonDeserialize(builder = ScimEmailAddress.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ScimEmailAddress { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("primary") + @Getter + private final Boolean primary; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + @Getter + private final String value; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + @Getter + private final String type; + + private ScimEmailAddress(Builder builder) { + this.primary = builder.primary; + this.value = builder.value; + this.type = builder.type; + } + + public static Builder builder() { + return new Builder(); + } + + public static ScimEmailAddress fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ScimEmailAddress.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("primary") + private Boolean primary; + + @JsonProperty("value") + private String value; + + @JsonProperty("type") + private String type; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("primary") + public Builder primary(Boolean primary) { + this.primary = primary; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + public Builder value(String value) { + this.value = value; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("type") + public Builder type(String type) { + this.type = type; + return this; + } + + public ScimEmailAddress build() { + return new ScimEmailAddress(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ScimEmailAddress other = (ScimEmailAddress) o; + return ( + Objects.equals(primary, other.primary) && + Objects.equals(value, other.value) && + Objects.equals(type, other.type) + ); + } + + @Override + public int hashCode() { + return Objects.hash(primary, value, type); + } + } + + @JsonDeserialize(builder = ScimMeta.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ScimMeta { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resourceType") + @Getter + private final String resourceType; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("created") + @Getter + private final ZonedDateTime created; + + @JsonDeserialize(using = com.twilio.converter.ISO8601Deserializer.class) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("lastModified") + @Getter + private final ZonedDateTime lastModified; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + @Getter + private final String version; + + private ScimMeta(Builder builder) { + this.resourceType = builder.resourceType; + this.created = builder.created; + this.lastModified = builder.lastModified; + this.version = builder.version; + } + + public static Builder builder() { + return new Builder(); + } + + public static ScimMeta fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, ScimMeta.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("resourceType") + private String resourceType; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("created") + private ZonedDateTime created; + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonProperty("lastModified") + private ZonedDateTime lastModified; + + @JsonProperty("version") + private String version; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("resourceType") + public Builder resourceType(String resourceType) { + this.resourceType = resourceType; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("created") + public Builder created(ZonedDateTime created) { + this.created = created; + return this; + } + + @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("lastModified") + public Builder lastModified(ZonedDateTime lastModified) { + this.lastModified = lastModified; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("version") + public Builder version(String version) { + this.version = version; + return this; + } + + public ScimMeta build() { + return new ScimMeta(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ScimMeta other = (ScimMeta) o; + return ( + Objects.equals(resourceType, other.resourceType) && + Objects.equals(created, other.created) && + Objects.equals(lastModified, other.lastModified) && + Objects.equals(version, other.version) + ); + } + + @Override + public int hashCode() { + return Objects.hash(resourceType, created, lastModified, version); + } + } + + @JsonDeserialize(builder = ScimName.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ScimName { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("givenName") + @Getter + private final String givenName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("familyName") + @Getter + private final String familyName; + + private ScimName(Builder builder) { + this.givenName = builder.givenName; + this.familyName = builder.familyName; + } + + public static Builder builder() { + return new Builder(); + } + + public static ScimName fromJson(String jsonString, ObjectMapper mapper) + throws IOException { + return mapper.readValue(jsonString, ScimName.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("givenName") + private String givenName; + + @JsonProperty("familyName") + private String familyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("givenName") + public Builder givenName(String givenName) { + this.givenName = givenName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("familyName") + public Builder familyName(String familyName) { + this.familyName = familyName; + return this; + } + + public ScimName build() { + return new ScimName(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ScimName other = (ScimName) o; + return ( + Objects.equals(givenName, other.givenName) && + Objects.equals(familyName, other.familyName) + ); + } + + @Override + public int hashCode() { + return Objects.hash(givenName, familyName); + } + } + + @JsonDeserialize(builder = ScimPatchOperation.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ScimPatchOperation { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("op") + @Getter + private final String op; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("path") + @Getter + private final String path; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + @Getter + private final Object value; + + private ScimPatchOperation(Builder builder) { + this.op = builder.op; + this.path = builder.path; + this.value = builder.value; + } + + public static Builder builder() { + return new Builder(); + } + + public static ScimPatchOperation fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ScimPatchOperation.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("op") + private String op; + + @JsonProperty("path") + private String path; + + @JsonProperty("value") + private Object value; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("op") + public Builder op(String op) { + this.op = op; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("path") + public Builder path(String path) { + this.path = path; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("value") + public Builder value(Object value) { + this.value = value; + return this; + } + + public ScimPatchOperation build() { + return new ScimPatchOperation(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ScimPatchOperation other = (ScimPatchOperation) o; + return ( + Objects.equals(op, other.op) && + Objects.equals(path, other.path) && + Objects.equals(value, other.value) + ); + } + + @Override + public int hashCode() { + return Objects.hash(op, path, value); + } + } + + @JsonDeserialize(builder = ScimPatchRequest.Builder.class) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class ScimPatchRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("schemas") + @Getter + private final List schemas; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("Operations") + @Getter + private final List operations; + + private ScimPatchRequest(Builder builder) { + this.schemas = builder.schemas; + this.operations = builder.operations; + } + + public static Builder builder() { + return new Builder(); + } + + public static ScimPatchRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue(jsonString, ScimPatchRequest.class); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("schemas") + private List schemas; + + @JsonProperty("Operations") + private List operations; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("schemas") + public Builder schemas(List schemas) { + this.schemas = schemas; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("Operations") + public Builder operations(List operations) { + this.operations = operations; + return this; + } + + public ScimPatchRequest build() { + return new ScimPatchRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ScimPatchRequest other = (ScimPatchRequest) o; + return ( + Objects.equals(schemas, other.schemas) && + Objects.equals(operations, other.operations) + ); + } + + @Override + public int hashCode() { + return Objects.hash(schemas, operations); + } + } + + /** + * Converts a JSON String into a User object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a User object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return User object represented by the provided JSON + */ + public static User fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, User.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean active; + + @Getter + private final String displayName; + + @Getter + private final List emails; + + @Getter + private final String externalId; + + @Getter + private final String id; + + @Getter + private final String locale; + + @Getter + private final ScimMeta meta; + + @Getter + private final ScimName name; + + @Getter + private final List schemas; + + @Getter + private final String timezone; + + @Getter + private final String userName; + + @JsonCreator + private User( + @JsonProperty("active") final Boolean active, + @JsonProperty("displayName") final String displayName, + @JsonProperty("emails") final List emails, + @JsonProperty("externalId") final String externalId, + @JsonProperty("id") final String id, + @JsonProperty("locale") final String locale, + @JsonProperty("meta") final ScimMeta meta, + @JsonProperty("name") final ScimName name, + @JsonProperty("schemas") final List schemas, + @JsonProperty("timezone") final String timezone, + @JsonProperty("userName") final String userName + ) { + this.active = active; + this.displayName = displayName; + this.emails = emails; + this.externalId = externalId; + this.id = id; + this.locale = locale; + this.meta = meta; + this.name = name; + this.schemas = schemas; + this.timezone = timezone; + this.userName = userName; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + User other = (User) o; + return ( + Objects.equals(active, other.active) && + Objects.equals(displayName, other.displayName) && + Objects.equals(emails, other.emails) && + Objects.equals(externalId, other.externalId) && + Objects.equals(id, other.id) && + Objects.equals(locale, other.locale) && + Objects.equals(meta, other.meta) && + Objects.equals(name, other.name) && + Objects.equals(schemas, other.schemas) && + Objects.equals(timezone, other.timezone) && + Objects.equals(userName, other.userName) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + active, + displayName, + emails, + externalId, + id, + locale, + meta, + name, + schemas, + timezone, + userName + ); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/UserCreator.java b/src/main/java/com/twilio/rest/previewiam/organizations/UserCreator.java new file mode 100644 index 0000000000..02d0cd5f93 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/UserCreator.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserCreator extends Creator { + + private String pathOrganizationSid; + private User.ScimUser scimUser; + + public UserCreator( + final String pathOrganizationSid, + final User.ScimUser scimUser + ) { + this.pathOrganizationSid = pathOrganizationSid; + this.scimUser = scimUser; + } + + public UserCreator setScimUser(final User.ScimUser scimUser) { + this.scimUser = scimUser; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/scim/Users"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User create(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (scimUser != null) { + request.setBody(User.toJson(scimUser, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/UserDeleter.java b/src/main/java/com/twilio/rest/previewiam/organizations/UserDeleter.java new file mode 100644 index 0000000000..8be362f625 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/UserDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class UserDeleter extends Deleter { + + private String pathOrganizationSid; + private String pathUserSid; + + public UserDeleter( + final String pathOrganizationSid, + final String pathUserSid + ) { + this.pathOrganizationSid = pathOrganizationSid; + this.pathUserSid = pathUserSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.PREVIEWIAM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/UserFetcher.java b/src/main/java/com/twilio/rest/previewiam/organizations/UserFetcher.java new file mode 100644 index 0000000000..f8c87ecdd4 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/UserFetcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserFetcher extends Fetcher { + + private String pathOrganizationSid; + private String pathUserSid; + + public UserFetcher( + final String pathOrganizationSid, + final String pathUserSid + ) { + this.pathOrganizationSid = pathOrganizationSid; + this.pathUserSid = pathUserSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.PREVIEWIAM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/UserPatcher.java b/src/main/java/com/twilio/rest/previewiam/organizations/UserPatcher.java new file mode 100644 index 0000000000..416f332aa0 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/UserPatcher.java @@ -0,0 +1,123 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Patcher; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserPatcher extends Patcher { + + private String pathOrganizationSid; + private String pathUserSid; + private String ifMatch; + private User.ScimPatchRequest scimPatchRequest; + + public UserPatcher( + final String pathOrganizationSid, + final String pathUserSid, + final User.ScimPatchRequest scimPatchRequest + ) { + this.pathOrganizationSid = pathOrganizationSid; + this.pathUserSid = pathUserSid; + this.scimPatchRequest = scimPatchRequest; + } + + public UserPatcher setScimPatchRequest( + final User.ScimPatchRequest scimPatchRequest + ) { + this.scimPatchRequest = scimPatchRequest; + return this; + } + + public UserPatcher setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + @Override + public User patch(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + + Request request = new Request( + HttpMethod.PATCH, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User patch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (scimPatchRequest != null) { + request.setBody(User.toJson(scimPatchRequest, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/UserReader.java b/src/main/java/com/twilio/rest/previewiam/organizations/UserReader.java new file mode 100644 index 0000000000..e78283041a --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/UserReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserReader extends Reader { + + private String pathOrganizationSid; + private String filter; + + public UserReader(final String pathOrganizationSid) { + this.pathOrganizationSid = pathOrganizationSid; + } + + public UserReader setFilter(final String filter) { + this.filter = filter; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "Resources", + response.getContent(), + User.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/scim/Users"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.PREVIEWIAM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "Resources", + response.getContent(), + User.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "User read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "Resources", + response.getContent(), + User.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (filter != null) { + Serializer.toString(request, "filter", filter, ParameterType.QUERY); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/organizations/UserUpdater.java b/src/main/java/com/twilio/rest/previewiam/organizations/UserUpdater.java new file mode 100644 index 0000000000..bfe4f94617 --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/organizations/UserUpdater.java @@ -0,0 +1,142 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.organizations; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class UserUpdater extends Updater { + + private String pathOrganizationSid; + private String pathUserSid; + private String ifMatch; + private User.ScimUser scimUser; + + public UserUpdater( + final String pathOrganizationSid, + final String pathUserSid, + final User.ScimUser scimUser + ) { + this.pathOrganizationSid = pathOrganizationSid; + this.pathUserSid = pathUserSid; + this.scimUser = scimUser; + } + + public UserUpdater setScimUser(final User.ScimUser scimUser) { + this.scimUser = scimUser; + return this; + } + + public UserUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; + + path = + path.replace( + "{" + "OrganizationSid" + "}", + this.pathOrganizationSid.toString() + ); + path = path.replace("{" + "UserSid" + "}", this.pathUserSid.toString()); + + Request request = new Request( + HttpMethod.PUT, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addHeaderParams(request); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "User update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public User update(final TwilioRestClient client) { + Response response = makeRequest(client); + return User.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + User content = User.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); + } + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (scimUser != null) { + request.setBody(User.toJson(scimUser, objectMapper)); + } + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/v1/Authorize.java b/src/main/java/com/twilio/rest/previewiam/v1/Authorize.java new file mode 100644 index 0000000000..e7a119fddb --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/v1/Authorize.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Authorize extends Resource { + + public static AuthorizeFetcher fetcher() { + return new AuthorizeFetcher(); + } + + /** + * Converts a JSON String into a Authorize object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Authorize object represented by the provided JSON + */ + public static Authorize fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Authorize.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Authorize object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Authorize object represented by the provided JSON + */ + public static Authorize fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Authorize.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final URI redirectTo; + + @JsonCreator + private Authorize(@JsonProperty("redirect_to") final URI redirectTo) { + this.redirectTo = redirectTo; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Authorize other = (Authorize) o; + return (Objects.equals(redirectTo, other.redirectTo)); + } + + @Override + public int hashCode() { + return Objects.hash(redirectTo); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/v1/AuthorizeFetcher.java b/src/main/java/com/twilio/rest/previewiam/v1/AuthorizeFetcher.java new file mode 100644 index 0000000000..61e230ecae --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/v1/AuthorizeFetcher.java @@ -0,0 +1,163 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.v1; + +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AuthorizeFetcher extends Fetcher { + + private String responseType; + private String clientId; + private String redirectUri; + private String scope; + private String state; + + public AuthorizeFetcher() {} + + public AuthorizeFetcher setResponseType(final String responseType) { + this.responseType = responseType; + return this; + } + + public AuthorizeFetcher setClientId(final String clientId) { + this.clientId = clientId; + return this; + } + + public AuthorizeFetcher setRedirectUri(final String redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + public AuthorizeFetcher setScope(final String scope) { + this.scope = scope; + return this; + } + + public AuthorizeFetcher setState(final String state) { + this.state = state; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/authorize"; + + Request request = new Request( + HttpMethod.GET, + Domains.PREVIEWIAM.toString(), + path + ); + request.setAuth(NoAuthStrategy.getInstance()); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Authorize fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Authorize fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Authorize.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Authorize content = Authorize.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (responseType != null) { + Serializer.toString( + request, + "response_type", + responseType, + ParameterType.QUERY + ); + } + + if (clientId != null) { + Serializer.toString( + request, + "client_id", + clientId, + ParameterType.QUERY + ); + } + + if (redirectUri != null) { + Serializer.toString( + request, + "redirect_uri", + redirectUri, + ParameterType.QUERY + ); + } + + if (scope != null) { + Serializer.toString(request, "scope", scope, ParameterType.QUERY); + } + + if (state != null) { + Serializer.toString(request, "state", state, ParameterType.QUERY); + } + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/v1/Token.java b/src/main/java/com/twilio/rest/previewiam/v1/Token.java new file mode 100644 index 0000000000..fd951d2c5b --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/v1/Token.java @@ -0,0 +1,163 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Token extends Resource { + + public static TokenCreator creator( + final String grantType, + final String clientId + ) { + return new TokenCreator(grantType, clientId); + } + + /** + * Converts a JSON String into a Token object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Token.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Token object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Token object represented by the provided JSON + */ + public static Token fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Token.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accessToken; + + @Getter + private final Long expiresIn; + + @Getter + private final String idToken; + + @Getter + private final String refreshToken; + + @Getter + private final String tokenType; + + @JsonCreator + private Token( + @JsonProperty("access_token") final String accessToken, + @JsonProperty("expires_in") final Long expiresIn, + @JsonProperty("id_token") final String idToken, + @JsonProperty("refresh_token") final String refreshToken, + @JsonProperty("token_type") final String tokenType + ) { + this.accessToken = accessToken; + this.expiresIn = expiresIn; + this.idToken = idToken; + this.refreshToken = refreshToken; + this.tokenType = tokenType; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Token other = (Token) o; + return ( + Objects.equals(accessToken, other.accessToken) && + Objects.equals(expiresIn, other.expiresIn) && + Objects.equals(idToken, other.idToken) && + Objects.equals(refreshToken, other.refreshToken) && + Objects.equals(tokenType, other.tokenType) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accessToken, + expiresIn, + idToken, + refreshToken, + tokenType + ); + } +} diff --git a/src/main/java/com/twilio/rest/previewiam/v1/TokenCreator.java b/src/main/java/com/twilio/rest/previewiam/v1/TokenCreator.java new file mode 100644 index 0000000000..4a30497dbc --- /dev/null +++ b/src/main/java/com/twilio/rest/previewiam/v1/TokenCreator.java @@ -0,0 +1,220 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.previewiam.v1; + +import com.twilio.auth_strategy.NoAuthStrategy; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TokenCreator extends Creator { + + private String grantType; + private String clientId; + private String clientSecret; + private String code; + private String redirectUri; + private String audience; + private String refreshToken; + private String scope; + + public TokenCreator(final String grantType, final String clientId) { + this.grantType = grantType; + this.clientId = clientId; + } + + public TokenCreator setGrantType(final String grantType) { + this.grantType = grantType; + return this; + } + + public TokenCreator setClientId(final String clientId) { + this.clientId = clientId; + return this; + } + + public TokenCreator setClientSecret(final String clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + public TokenCreator setCode(final String code) { + this.code = code; + return this; + } + + public TokenCreator setRedirectUri(final String redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + public TokenCreator setAudience(final String audience) { + this.audience = audience; + return this; + } + + public TokenCreator setRefreshToken(final String refreshToken) { + this.refreshToken = refreshToken; + return this; + } + + public TokenCreator setScope(final String scope) { + this.scope = scope; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/token"; + + Request request = new Request( + HttpMethod.POST, + Domains.PREVIEWIAM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + request.setAuth(NoAuthStrategy.getInstance()); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Token creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Token create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Token.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Token content = Token.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (grantType != null) { + Serializer.toString( + request, + "grant_type", + grantType, + ParameterType.URLENCODED + ); + } + + if (clientId != null) { + Serializer.toString( + request, + "client_id", + clientId, + ParameterType.URLENCODED + ); + } + + if (clientSecret != null) { + Serializer.toString( + request, + "client_secret", + clientSecret, + ParameterType.URLENCODED + ); + } + + if (code != null) { + Serializer.toString( + request, + "code", + code, + ParameterType.URLENCODED + ); + } + + if (redirectUri != null) { + Serializer.toString( + request, + "redirect_uri", + redirectUri, + ParameterType.URLENCODED + ); + } + + if (audience != null) { + Serializer.toString( + request, + "audience", + audience, + ParameterType.URLENCODED + ); + } + + if (refreshToken != null) { + Serializer.toString( + request, + "refresh_token", + refreshToken, + ParameterType.URLENCODED + ); + } + + if (scope != null) { + Serializer.toString( + request, + "scope", + scope, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/messaging/Country.java b/src/main/java/com/twilio/rest/pricing/v1/messaging/Country.java index db0f400da9..5e3a78594e 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/messaging/Country.java +++ b/src/main/java/com/twilio/rest/pricing/v1/messaging/Country.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.messaging; @@ -11,61 +18,51 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.InboundSmsPrice; import com.twilio.type.OutboundSmsPrice; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.Currency; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Country extends Resource { - private static final long serialVersionUID = 155838537182593L; - - /** - * Create a CountryReader to execute read. - * - * @return CountryReader capable of executing the read - */ - public static CountryReader reader() { - return new CountryReader(); - } - /** - * Create a CountryFetcher to execute fetch. - * - * @param pathIsoCountry The iso_country - * @return CountryFetcher capable of executing the fetch - */ public static CountryFetcher fetcher(final String pathIsoCountry) { return new CountryFetcher(pathIsoCountry); } + public static CountryReader reader() { + return new CountryReader(); + } + /** * Converts a JSON String into a Country object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Country object represented by the provided JSON */ - public static Country fromJson(final String json, final ObjectMapper objectMapper) { + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -79,12 +76,15 @@ public static Country fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Country object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Country object represented by the provided JSON */ - public static Country fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -95,91 +95,59 @@ public static Country fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String country; + + @Getter + private final List inboundSmsPrices; + + @Getter private final String isoCountry; + + @Getter private final List outboundSmsPrices; - private final List inboundSmsPrices; + + @Getter private final Currency priceUnit; + + @Getter private final URI url; @JsonCreator - private Country(@JsonProperty("country") - final String country, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("outbound_sms_prices") - final List outboundSmsPrices, - @JsonProperty("inbound_sms_prices") - final List inboundSmsPrices, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("url") - final URI url) { + private Country( + @JsonProperty("country") final String country, + @JsonProperty("inbound_sms_prices") final List< + InboundSmsPrice + > inboundSmsPrices, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("outbound_sms_prices") final List< + OutboundSmsPrice + > outboundSmsPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url + ) { this.country = country; + this.inboundSmsPrices = inboundSmsPrices; this.isoCountry = isoCountry; this.outboundSmsPrices = outboundSmsPrices; - this.inboundSmsPrices = inboundSmsPrices; this.priceUnit = priceUnit; this.url = url; } - /** - * Returns The Name of the country. - * - * @return Name of the country - */ - public final String getCountry() { - return this.country; - } - - /** - * Returns The The ISO country code. - * - * @return The ISO country code - */ - public final String getIsoCountry() { - return this.isoCountry; - } - - /** - * Returns The List of OutboundSMSPrice records. - * - * @return List of OutboundSMSPrice records - */ - public final List getOutboundSmsPrices() { - return this.outboundSmsPrices; - } - - /** - * Returns The List of InboundPrice records. - * - * @return List of InboundPrice records - */ - public final List getInboundSmsPrices() { - return this.inboundSmsPrices; - } - - /** - * Returns The The currency in which prices are measured, in ISO 4127 format - * (e.g. usd, eur, jpy).. - * - * @return The currency in which prices are measured, in ISO 4127 format (e.g. - * usd, eur, jpy). - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -191,34 +159,25 @@ public boolean equals(final Object o) { } Country other = (Country) o; - - return Objects.equals(country, other.country) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(outboundSmsPrices, other.outboundSmsPrices) && - Objects.equals(inboundSmsPrices, other.inboundSmsPrices) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(url, other.url); + return ( + Objects.equals(country, other.country) && + Objects.equals(inboundSmsPrices, other.inboundSmsPrices) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(outboundSmsPrices, other.outboundSmsPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(country, - isoCountry, - outboundSmsPrices, - inboundSmsPrices, - priceUnit, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("country", country) - .add("isoCountry", isoCountry) - .add("outboundSmsPrices", outboundSmsPrices) - .add("inboundSmsPrices", inboundSmsPrices) - .add("priceUnit", priceUnit) - .add("url", url) - .toString(); + return Objects.hash( + country, + inboundSmsPrices, + isoCountry, + outboundSmsPrices, + priceUnit, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryFetcher.java index ccf7463299..21d91e71fa 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.messaging; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CountryFetcher extends Fetcher { - private final String pathIsoCountry; - /** - * Construct a new CountryFetcher. - * - * @param pathIsoCountry The iso_country - */ + private String pathIsoCountry; + public CountryFetcher(final String pathIsoCountry) { this.pathIsoCountry = pathIsoCountry; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Country - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Country fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Messaging/Countries/{IsoCountry}"; + + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PRICING.toString(), - "/v1/Messaging/Countries/" + this.pathIsoCountry + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Country fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Country.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Country content = Country.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryReader.java index 9dd30fecd3..6708426ddf 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryReader.java +++ b/src/main/java/com/twilio/rest/pricing/v1/messaging/CountryReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.messaging; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CountryReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public CountryReader() {} + + public CountryReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Messaging/Countries"; + Request request = new Request( HttpMethod.GET, Domains.PRICING.toString(), - "/v1/Messaging/Countries", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PRICING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PRICING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Country Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Country read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "countries", - response.getContent(), - Country.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/Country.java b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/Country.java index ea0e86f9b2..2e3b990163 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/Country.java +++ b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/Country.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.phonenumber; @@ -11,60 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberPrice; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.Currency; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Country extends Resource { - private static final long serialVersionUID = 214707935181184L; - /** - * Create a CountryReader to execute read. - * - * @return CountryReader capable of executing the read - */ - public static CountryReader reader() { - return new CountryReader(); - } - - /** - * Create a CountryFetcher to execute fetch. - * - * @param pathIsoCountry The iso_country - * @return CountryFetcher capable of executing the fetch - */ public static CountryFetcher fetcher(final String pathIsoCountry) { return new CountryFetcher(pathIsoCountry); } + public static CountryReader reader() { + return new CountryReader(); + } + /** * Converts a JSON String into a Country object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Country object represented by the provided JSON */ - public static Country fromJson(final String json, final ObjectMapper objectMapper) { + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -78,12 +75,15 @@ public static Country fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Country object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Country object represented by the provided JSON */ - public static Country fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -94,24 +94,45 @@ public static Country fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String country; + + @Getter private final String isoCountry; + + @Getter private final List phoneNumberPrices; + + @Getter private final Currency priceUnit; + + @Getter private final URI url; @JsonCreator - private Country(@JsonProperty("country") - final String country, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("phone_number_prices") - final List phoneNumberPrices, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("url") - final URI url) { + private Country( + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("phone_number_prices") final List< + PhoneNumberPrice + > phoneNumberPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url + ) { this.country = country; this.isoCountry = isoCountry; this.phoneNumberPrices = phoneNumberPrices; @@ -119,53 +140,6 @@ private Country(@JsonProperty("country") this.url = url; } - /** - * Returns The Name of the country. - * - * @return Name of the country - */ - public final String getCountry() { - return this.country; - } - - /** - * Returns The The ISO country code of this number. - * - * @return The ISO country code of this number - */ - public final String getIsoCountry() { - return this.isoCountry; - } - - /** - * Returns The List of PhoneNumberPrices records. - * - * @return List of PhoneNumberPrices records - */ - public final List getPhoneNumberPrices() { - return this.phoneNumberPrices; - } - - /** - * Returns The The currency in which prices are measured, in ISO 4127 format - * (e.g. usd, eur, jpy).. - * - * @return The currency in which prices are measured, in ISO 4127 format (e.g. - * usd, eur, jpy). - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -177,31 +151,23 @@ public boolean equals(final Object o) { } Country other = (Country) o; - - return Objects.equals(country, other.country) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(phoneNumberPrices, other.phoneNumberPrices) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(url, other.url); + return ( + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(phoneNumberPrices, other.phoneNumberPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(country, - isoCountry, - phoneNumberPrices, - priceUnit, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("country", country) - .add("isoCountry", isoCountry) - .add("phoneNumberPrices", phoneNumberPrices) - .add("priceUnit", priceUnit) - .add("url", url) - .toString(); + return Objects.hash( + country, + isoCountry, + phoneNumberPrices, + priceUnit, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryFetcher.java index a31fce2112..765dd58385 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.phonenumber; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CountryFetcher extends Fetcher { - private final String pathIsoCountry; - /** - * Construct a new CountryFetcher. - * - * @param pathIsoCountry The iso_country - */ + private String pathIsoCountry; + public CountryFetcher(final String pathIsoCountry) { this.pathIsoCountry = pathIsoCountry; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Country - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Country fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/PhoneNumbers/Countries/{IsoCountry}"; + + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PRICING.toString(), - "/v1/PhoneNumbers/Countries/" + this.pathIsoCountry + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Country fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Country.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Country content = Country.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryReader.java index 0974e24e4f..1d7cfd7698 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryReader.java +++ b/src/main/java/com/twilio/rest/pricing/v1/phonenumber/CountryReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.phonenumber; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CountryReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public CountryReader() {} + + public CountryReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/PhoneNumbers/Countries"; + Request request = new Request( HttpMethod.GET, Domains.PRICING.toString(), - "/v1/PhoneNumbers/Countries", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PRICING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PRICING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Country Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Country read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "countries", - response.getContent(), - Country.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/Country.java b/src/main/java/com/twilio/rest/pricing/v1/voice/Country.java index 13d7a52125..e0f06002f7 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/Country.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/Country.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.voice; @@ -11,61 +18,51 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.InboundCallPrice; import com.twilio.type.OutboundPrefixPrice; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.Currency; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Country extends Resource { - private static final long serialVersionUID = 270847470775437L; - - /** - * Create a CountryReader to execute read. - * - * @return CountryReader capable of executing the read - */ - public static CountryReader reader() { - return new CountryReader(); - } - /** - * Create a CountryFetcher to execute fetch. - * - * @param pathIsoCountry The iso_country - * @return CountryFetcher capable of executing the fetch - */ public static CountryFetcher fetcher(final String pathIsoCountry) { return new CountryFetcher(pathIsoCountry); } + public static CountryReader reader() { + return new CountryReader(); + } + /** * Converts a JSON String into a Country object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Country object represented by the provided JSON */ - public static Country fromJson(final String json, final ObjectMapper objectMapper) { + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -79,12 +76,15 @@ public static Country fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Country object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Country object represented by the provided JSON */ - public static Country fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Country.class); @@ -95,91 +95,59 @@ public static Country fromJson(final InputStream json, final ObjectMapper object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String country; + + @Getter + private final List inboundCallPrices; + + @Getter private final String isoCountry; + + @Getter private final List outboundPrefixPrices; - private final List inboundCallPrices; + + @Getter private final Currency priceUnit; + + @Getter private final URI url; @JsonCreator - private Country(@JsonProperty("country") - final String country, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("outbound_prefix_prices") - final List outboundPrefixPrices, - @JsonProperty("inbound_call_prices") - final List inboundCallPrices, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("url") - final URI url) { + private Country( + @JsonProperty("country") final String country, + @JsonProperty("inbound_call_prices") final List< + InboundCallPrice + > inboundCallPrices, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("outbound_prefix_prices") final List< + OutboundPrefixPrice + > outboundPrefixPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url + ) { this.country = country; + this.inboundCallPrices = inboundCallPrices; this.isoCountry = isoCountry; this.outboundPrefixPrices = outboundPrefixPrices; - this.inboundCallPrices = inboundCallPrices; this.priceUnit = priceUnit; this.url = url; } - /** - * Returns The Name of the country. - * - * @return Name of the country - */ - public final String getCountry() { - return this.country; - } - - /** - * Returns The The ISO country code. - * - * @return The ISO country code - */ - public final String getIsoCountry() { - return this.isoCountry; - } - - /** - * Returns The The outbound_prefix_prices. - * - * @return The outbound_prefix_prices - */ - public final List getOutboundPrefixPrices() { - return this.outboundPrefixPrices; - } - - /** - * Returns The The inbound_call_prices. - * - * @return The inbound_call_prices - */ - public final List getInboundCallPrices() { - return this.inboundCallPrices; - } - - /** - * Returns The The currency in which prices are measured, in ISO 4127 format - * (e.g. usd, eur, jpy).. - * - * @return The currency in which prices are measured, in ISO 4127 format (e.g. - * usd, eur, jpy). - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -191,34 +159,25 @@ public boolean equals(final Object o) { } Country other = (Country) o; - - return Objects.equals(country, other.country) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(outboundPrefixPrices, other.outboundPrefixPrices) && - Objects.equals(inboundCallPrices, other.inboundCallPrices) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(url, other.url); + return ( + Objects.equals(country, other.country) && + Objects.equals(inboundCallPrices, other.inboundCallPrices) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(outboundPrefixPrices, other.outboundPrefixPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(country, - isoCountry, - outboundPrefixPrices, - inboundCallPrices, - priceUnit, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("country", country) - .add("isoCountry", isoCountry) - .add("outboundPrefixPrices", outboundPrefixPrices) - .add("inboundCallPrices", inboundCallPrices) - .add("priceUnit", priceUnit) - .add("url", url) - .toString(); + return Objects.hash( + country, + inboundCallPrices, + isoCountry, + outboundPrefixPrices, + priceUnit, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v1/voice/CountryFetcher.java index 98c804ec7b..61f08efbe5 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/CountryFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/CountryFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.voice; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CountryFetcher extends Fetcher { - private final String pathIsoCountry; - /** - * Construct a new CountryFetcher. - * - * @param pathIsoCountry The iso_country - */ + private String pathIsoCountry; + public CountryFetcher(final String pathIsoCountry) { this.pathIsoCountry = pathIsoCountry; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Country - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Country fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Voice/Countries/{IsoCountry}"; + + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PRICING.toString(), - "/v1/Voice/Countries/" + this.pathIsoCountry + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Country fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Country fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Country.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Country content = Country.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v1/voice/CountryReader.java index c8fe8f225e..e94c98cde7 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/CountryReader.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/CountryReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.voice; @@ -10,148 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CountryReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public CountryReader() {} + + public CountryReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Voice/Countries"; + Request request = new Request( HttpMethod.GET, Domains.PRICING.toString(), - "/v1/Voice/Countries", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Country ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PRICING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PRICING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Country Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Country read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "countries", - response.getContent(), - Country.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/Number.java b/src/main/java/com/twilio/rest/pricing/v1/voice/Number.java index 55eee0a008..a076aa02b2 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/Number.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/Number.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.voice; @@ -11,51 +18,48 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.InboundCallPrice; import com.twilio.type.OutboundCallPrice; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.Currency; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Number extends Resource { - private static final long serialVersionUID = 198694876395979L; - /** - * Create a NumberFetcher to execute fetch. - * - * @param pathNumber The number - * @return NumberFetcher capable of executing the fetch - */ - public static NumberFetcher fetcher(final com.twilio.type.PhoneNumber pathNumber) { + public static NumberFetcher fetcher( + final com.twilio.type.PhoneNumber pathNumber + ) { return new NumberFetcher(pathNumber); } /** * Converts a JSON String into a Number object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Number object represented by the provided JSON */ - public static Number fromJson(final String json, final ObjectMapper objectMapper) { + public static Number fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Number.class); @@ -69,12 +73,15 @@ public static Number fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Number object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Number object represented by the provided JSON */ - public static Number fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Number fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Number.class); @@ -85,106 +92,64 @@ public static Number fromJson(final InputStream json, final ObjectMapper objectM } } - private final com.twilio.type.PhoneNumber number; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String country; + + @Getter + private final InboundCallPrice inboundCallPrice; + + @Getter private final String isoCountry; + + @Getter + private final com.twilio.type.PhoneNumber number; + + @Getter private final OutboundCallPrice outboundCallPrice; - private final InboundCallPrice inboundCallPrice; + + @Getter private final Currency priceUnit; + + @Getter private final URI url; @JsonCreator - private Number(@JsonProperty("number") - final com.twilio.type.PhoneNumber number, - @JsonProperty("country") - final String country, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("outbound_call_price") - final OutboundCallPrice outboundCallPrice, - @JsonProperty("inbound_call_price") - final InboundCallPrice inboundCallPrice, - @JsonProperty("price_unit") - @JsonDeserialize(using = com.twilio.converter.CurrencyDeserializer.class) - final Currency priceUnit, - @JsonProperty("url") - final URI url) { - this.number = number; + private Number( + @JsonProperty("country") final String country, + @JsonProperty( + "inbound_call_price" + ) final InboundCallPrice inboundCallPrice, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("number") final com.twilio.type.PhoneNumber number, + @JsonProperty( + "outbound_call_price" + ) final OutboundCallPrice outboundCallPrice, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url + ) { this.country = country; + this.inboundCallPrice = inboundCallPrice; this.isoCountry = isoCountry; + this.number = number; this.outboundCallPrice = outboundCallPrice; - this.inboundCallPrice = inboundCallPrice; this.priceUnit = priceUnit; this.url = url; } - /** - * Returns The The number. - * - * @return The number - */ - public final com.twilio.type.PhoneNumber getNumber() { - return this.number; - } - - /** - * Returns The Name of the country. - * - * @return Name of the country - */ - public final String getCountry() { - return this.country; - } - - /** - * Returns The The ISO country code. - * - * @return The ISO country code - */ - public final String getIsoCountry() { - return this.isoCountry; - } - - /** - * Returns The See OutboundCallPrice record. - * - * @return See OutboundCallPrice record - */ - public final OutboundCallPrice getOutboundCallPrice() { - return this.outboundCallPrice; - } - - /** - * Returns The See InboundCallPrice record (returned as null if the Phone Number - * provided is not a Twilio number owned by this account). - * - * @return See InboundCallPrice record (returned as null if the Phone Number - * provided is not a Twilio number owned by this account) - */ - public final InboundCallPrice getInboundCallPrice() { - return this.inboundCallPrice; - } - - /** - * Returns The The currency in which prices are measured, in ISO 4127 format - * (e.g. usd, eur, jpy).. - * - * @return The currency in which prices are measured, in ISO 4127 format (e.g. - * usd, eur, jpy). - */ - public final Currency getPriceUnit() { - return this.priceUnit; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -196,37 +161,27 @@ public boolean equals(final Object o) { } Number other = (Number) o; - - return Objects.equals(number, other.number) && - Objects.equals(country, other.country) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(outboundCallPrice, other.outboundCallPrice) && - Objects.equals(inboundCallPrice, other.inboundCallPrice) && - Objects.equals(priceUnit, other.priceUnit) && - Objects.equals(url, other.url); + return ( + Objects.equals(country, other.country) && + Objects.equals(inboundCallPrice, other.inboundCallPrice) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(number, other.number) && + Objects.equals(outboundCallPrice, other.outboundCallPrice) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(number, - country, - isoCountry, - outboundCallPrice, - inboundCallPrice, - priceUnit, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("number", number) - .add("country", country) - .add("isoCountry", isoCountry) - .add("outboundCallPrice", outboundCallPrice) - .add("inboundCallPrice", inboundCallPrice) - .add("priceUnit", priceUnit) - .add("url", url) - .toString(); + return Objects.hash( + country, + inboundCallPrice, + isoCountry, + number, + outboundCallPrice, + priceUnit, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/pricing/v1/voice/NumberFetcher.java b/src/main/java/com/twilio/rest/pricing/v1/voice/NumberFetcher.java index d29aa87ae3..fda5cba9db 100644 --- a/src/main/java/com/twilio/rest/pricing/v1/voice/NumberFetcher.java +++ b/src/main/java/com/twilio/rest/pricing/v1/voice/NumberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.pricing.v1.voice; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class NumberFetcher extends Fetcher { - private final com.twilio.type.PhoneNumber pathNumber; - /** - * Construct a new NumberFetcher. - * - * @param pathNumber The number - */ + private com.twilio.type.PhoneNumber pathNumber; + public NumberFetcher(final com.twilio.type.PhoneNumber pathNumber) { this.pathNumber = pathNumber; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Number - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Number fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Voice/Numbers/{Number}"; + + path = path.replace("{" + "Number" + "}", this.pathNumber.toString()); + Request request = new Request( HttpMethod.GET, Domains.PRICING.toString(), - "/v1/Voice/Numbers/" + this.pathNumber + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Number fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Number fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Number fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Number.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Number content = Number.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/Country.java b/src/main/java/com/twilio/rest/pricing/v2/Country.java new file mode 100644 index 0000000000..42860480ed --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/Country.java @@ -0,0 +1,189 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundPrefixPriceWithOrigin; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Currency; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Country extends Resource { + + public static CountryFetcher fetcher(final String pathIsoCountry) { + return new CountryFetcher(pathIsoCountry); + } + + public static CountryReader reader() { + return new CountryReader(); + } + + /** + * Converts a JSON String into a Country object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Country.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Country object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Country.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String country; + + @Getter + private final String isoCountry; + + @Getter + private final List originatingCallPrices; + + @Getter + private final Currency priceUnit; + + @Getter + private final List terminatingPrefixPrices; + + @Getter + private final URI url; + + @JsonCreator + private Country( + @JsonProperty("country") final String country, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("originating_call_prices") final List< + InboundCallPrice + > originatingCallPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("terminating_prefix_prices") final List< + OutboundPrefixPriceWithOrigin + > terminatingPrefixPrices, + @JsonProperty("url") final URI url + ) { + this.country = country; + this.isoCountry = isoCountry; + this.originatingCallPrices = originatingCallPrices; + this.priceUnit = priceUnit; + this.terminatingPrefixPrices = terminatingPrefixPrices; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Country other = (Country) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals( + originatingCallPrices, + other.originatingCallPrices + ) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals( + terminatingPrefixPrices, + other.terminatingPrefixPrices + ) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + country, + isoCountry, + originatingCallPrices, + priceUnit, + terminatingPrefixPrices, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v2/CountryFetcher.java new file mode 100644 index 0000000000..ac91df0b6a --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/CountryFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CountryFetcher extends Fetcher { + + private String pathIsoCountry; + + public CountryFetcher(final String pathIsoCountry) { + this.pathIsoCountry = pathIsoCountry; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Trunking/Countries/{IsoCountry}"; + + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.PRICING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Country fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Country.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Country content = Country.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v2/CountryReader.java new file mode 100644 index 0000000000..b4c2af9e50 --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/CountryReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CountryReader extends Reader { + + private Long pageSize; + + public CountryReader() {} + + public CountryReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Trunking/Countries"; + + Request request = new Request( + HttpMethod.GET, + Domains.PRICING.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/Number.java b/src/main/java/com/twilio/rest/pricing/v2/Number.java new file mode 100644 index 0000000000..0f14b808f9 --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/Number.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundPrefixPriceWithOrigin; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Currency; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Number extends Resource { + + public static NumberFetcher fetcher( + final com.twilio.type.PhoneNumber pathDestinationNumber + ) { + return new NumberFetcher(pathDestinationNumber); + } + + /** + * Converts a JSON String into a Number object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Number.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Number object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Number.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String country; + + @Getter + private final com.twilio.type.PhoneNumber destinationNumber; + + @Getter + private final String isoCountry; + + @Getter + private final InboundCallPrice originatingCallPrice; + + @Getter + private final com.twilio.type.PhoneNumber originationNumber; + + @Getter + private final Currency priceUnit; + + @Getter + private final List terminatingPrefixPrices; + + @Getter + private final URI url; + + @JsonCreator + private Number( + @JsonProperty("country") final String country, + @JsonProperty( + "destination_number" + ) final com.twilio.type.PhoneNumber destinationNumber, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "originating_call_price" + ) final InboundCallPrice originatingCallPrice, + @JsonProperty( + "origination_number" + ) final com.twilio.type.PhoneNumber originationNumber, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("terminating_prefix_prices") final List< + OutboundPrefixPriceWithOrigin + > terminatingPrefixPrices, + @JsonProperty("url") final URI url + ) { + this.country = country; + this.destinationNumber = destinationNumber; + this.isoCountry = isoCountry; + this.originatingCallPrice = originatingCallPrice; + this.originationNumber = originationNumber; + this.priceUnit = priceUnit; + this.terminatingPrefixPrices = terminatingPrefixPrices; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Number other = (Number) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(destinationNumber, other.destinationNumber) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(originatingCallPrice, other.originatingCallPrice) && + Objects.equals(originationNumber, other.originationNumber) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals( + terminatingPrefixPrices, + other.terminatingPrefixPrices + ) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + country, + destinationNumber, + isoCountry, + originatingCallPrice, + originationNumber, + priceUnit, + terminatingPrefixPrices, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/NumberFetcher.java b/src/main/java/com/twilio/rest/pricing/v2/NumberFetcher.java new file mode 100644 index 0000000000..2757534771 --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/NumberFetcher.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NumberFetcher extends Fetcher { + + private com.twilio.type.PhoneNumber pathDestinationNumber; + private com.twilio.type.PhoneNumber originationNumber; + + public NumberFetcher( + final com.twilio.type.PhoneNumber pathDestinationNumber + ) { + this.pathDestinationNumber = pathDestinationNumber; + } + + public NumberFetcher setOriginationNumber( + final com.twilio.type.PhoneNumber originationNumber + ) { + this.originationNumber = originationNumber; + return this; + } + + public NumberFetcher setOriginationNumber(final String originationNumber) { + return setOriginationNumber( + Promoter.phoneNumberFromString(originationNumber) + ); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Trunking/Numbers/{DestinationNumber}"; + + path = + path.replace( + "{" + "DestinationNumber" + "}", + this.pathDestinationNumber.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.PRICING.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Number fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Number fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Number.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Number content = Number.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (originationNumber != null) { + Serializer.toString( + request, + "OriginationNumber", + originationNumber, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/Country.java b/src/main/java/com/twilio/rest/pricing/v2/voice/Country.java new file mode 100644 index 0000000000..42e453af60 --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/Country.java @@ -0,0 +1,183 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2.voice; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundPrefixPriceWithOrigin; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Currency; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Country extends Resource { + + public static CountryFetcher fetcher(final String pathIsoCountry) { + return new CountryFetcher(pathIsoCountry); + } + + public static CountryReader reader() { + return new CountryReader(); + } + + /** + * Converts a JSON String into a Country object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Country.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Country object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Country object represented by the provided JSON + */ + public static Country fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Country.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String country; + + @Getter + private final List inboundCallPrices; + + @Getter + private final String isoCountry; + + @Getter + private final List outboundPrefixPrices; + + @Getter + private final Currency priceUnit; + + @Getter + private final URI url; + + @JsonCreator + private Country( + @JsonProperty("country") final String country, + @JsonProperty("inbound_call_prices") final List< + InboundCallPrice + > inboundCallPrices, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("outbound_prefix_prices") final List< + OutboundPrefixPriceWithOrigin + > outboundPrefixPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url + ) { + this.country = country; + this.inboundCallPrices = inboundCallPrices; + this.isoCountry = isoCountry; + this.outboundPrefixPrices = outboundPrefixPrices; + this.priceUnit = priceUnit; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Country other = (Country) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(inboundCallPrices, other.inboundCallPrices) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(outboundPrefixPrices, other.outboundPrefixPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + country, + inboundCallPrices, + isoCountry, + outboundPrefixPrices, + priceUnit, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/CountryFetcher.java b/src/main/java/com/twilio/rest/pricing/v2/voice/CountryFetcher.java new file mode 100644 index 0000000000..95cf9bd108 --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/CountryFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2.voice; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CountryFetcher extends Fetcher { + + private String pathIsoCountry; + + public CountryFetcher(final String pathIsoCountry) { + this.pathIsoCountry = pathIsoCountry; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Countries/{IsoCountry}"; + + path = + path.replace( + "{" + "IsoCountry" + "}", + this.pathIsoCountry.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.PRICING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Country fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Country fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Country.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Country content = Country.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/CountryReader.java b/src/main/java/com/twilio/rest/pricing/v2/voice/CountryReader.java new file mode 100644 index 0000000000..c5d8755c1e --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/CountryReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2.voice; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CountryReader extends Reader { + + private Long pageSize; + + public CountryReader() {} + + public CountryReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Countries"; + + Request request = new Request( + HttpMethod.GET, + Domains.PRICING.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Country read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "countries", + response.getContent(), + Country.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/Number.java b/src/main/java/com/twilio/rest/pricing/v2/voice/Number.java new file mode 100644 index 0000000000..f7e3b0358a --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/Number.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2.voice; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import com.twilio.type.InboundCallPrice; +import com.twilio.type.OutboundCallPriceWithOrigin; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Currency; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Number extends Resource { + + public static NumberFetcher fetcher( + final com.twilio.type.PhoneNumber pathDestinationNumber + ) { + return new NumberFetcher(pathDestinationNumber); + } + + /** + * Converts a JSON String into a Number object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Number.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Number object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Number object represented by the provided JSON + */ + public static Number fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Number.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String country; + + @Getter + private final com.twilio.type.PhoneNumber destinationNumber; + + @Getter + private final InboundCallPrice inboundCallPrice; + + @Getter + private final String isoCountry; + + @Getter + private final com.twilio.type.PhoneNumber originationNumber; + + @Getter + private final List outboundCallPrices; + + @Getter + private final Currency priceUnit; + + @Getter + private final URI url; + + @JsonCreator + private Number( + @JsonProperty("country") final String country, + @JsonProperty( + "destination_number" + ) final com.twilio.type.PhoneNumber destinationNumber, + @JsonProperty( + "inbound_call_price" + ) final InboundCallPrice inboundCallPrice, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "origination_number" + ) final com.twilio.type.PhoneNumber originationNumber, + @JsonProperty("outbound_call_prices") final List< + OutboundCallPriceWithOrigin + > outboundCallPrices, + @JsonProperty("price_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency priceUnit, + @JsonProperty("url") final URI url + ) { + this.country = country; + this.destinationNumber = destinationNumber; + this.inboundCallPrice = inboundCallPrice; + this.isoCountry = isoCountry; + this.originationNumber = originationNumber; + this.outboundCallPrices = outboundCallPrices; + this.priceUnit = priceUnit; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Number other = (Number) o; + return ( + Objects.equals(country, other.country) && + Objects.equals(destinationNumber, other.destinationNumber) && + Objects.equals(inboundCallPrice, other.inboundCallPrice) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(originationNumber, other.originationNumber) && + Objects.equals(outboundCallPrices, other.outboundCallPrices) && + Objects.equals(priceUnit, other.priceUnit) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + country, + destinationNumber, + inboundCallPrice, + isoCountry, + originationNumber, + outboundCallPrices, + priceUnit, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/pricing/v2/voice/NumberFetcher.java b/src/main/java/com/twilio/rest/pricing/v2/voice/NumberFetcher.java new file mode 100644 index 0000000000..036ab37a93 --- /dev/null +++ b/src/main/java/com/twilio/rest/pricing/v2/voice/NumberFetcher.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Pricing + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.pricing.v2.voice; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NumberFetcher extends Fetcher { + + private com.twilio.type.PhoneNumber pathDestinationNumber; + private com.twilio.type.PhoneNumber originationNumber; + + public NumberFetcher( + final com.twilio.type.PhoneNumber pathDestinationNumber + ) { + this.pathDestinationNumber = pathDestinationNumber; + } + + public NumberFetcher setOriginationNumber( + final com.twilio.type.PhoneNumber originationNumber + ) { + this.originationNumber = originationNumber; + return this; + } + + public NumberFetcher setOriginationNumber(final String originationNumber) { + return setOriginationNumber( + Promoter.phoneNumberFromString(originationNumber) + ); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Voice/Numbers/{DestinationNumber}"; + + path = + path.replace( + "{" + "DestinationNumber" + "}", + this.pathDestinationNumber.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.PRICING.toString(), + path + ); + addQueryParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Number fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Number fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Number.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Number content = Number.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addQueryParams(final Request request) { + if (originationNumber != null) { + Serializer.toString( + request, + "OriginationNumber", + originationNumber, + ParameterType.QUERY + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/Service.java b/src/main/java/com/twilio/rest/proxy/v1/Service.java index 0687034170..3495190fa2 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/Service.java +++ b/src/main/java/com/twilio/rest/proxy/v1/Service.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1; @@ -10,36 +17,53 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Service extends Resource { - private static final long serialVersionUID = 38310522618070L; + + public static ServiceCreator creator(final String uniqueName) { + return new ServiceCreator(uniqueName); + } + + public static ServiceDeleter deleter(final String pathSid) { + return new ServiceDeleter(pathSid); + } + + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); + } + + public static ServiceReader reader() { + return new ServiceReader(); + } + + public static ServiceUpdater updater(final String pathSid) { + return new ServiceUpdater(pathSid); + } public enum GeoMatchLevel { AREA_CODE("area-code"), @@ -53,15 +77,11 @@ private GeoMatchLevel(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a GeoMatchLevel from a string. - * @param value string value - * @return generated GeoMatchLevel - */ @JsonCreator public static GeoMatchLevel forValue(final String value) { return Promoter.enumFromString(value, GeoMatchLevel.values()); @@ -78,79 +98,31 @@ private NumberSelectionBehavior(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a NumberSelectionBehavior from a string. - * @param value string value - * @return generated NumberSelectionBehavior - */ @JsonCreator public static NumberSelectionBehavior forValue(final String value) { - return Promoter.enumFromString(value, NumberSelectionBehavior.values()); + return Promoter.enumFromString( + value, + NumberSelectionBehavior.values() + ); } } - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid A string that uniquely identifies this Service. - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); - } - - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ - public static ServiceReader reader() { - return new ServiceReader(); - } - - /** - * Create a ServiceCreator to execute create. - * - * @param uniqueName The human-readable string that uniquely identifies this - * Service. - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator(final String uniqueName) { - return new ServiceCreator(uniqueName); - } - - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid A string that uniquely identifies this Service. - * @return ServiceDeleter capable of executing the delete - */ - public static ServiceDeleter deleter(final String pathSid) { - return new ServiceDeleter(pathSid); - } - - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid A string that uniquely identifies this Service. - * @return ServiceUpdater capable of executing the update - */ - public static ServiceUpdater updater(final String pathSid) { - return new ServiceUpdater(pathSid); - } - /** * Converts a JSON String into a Service object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -164,12 +136,15 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Service object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -180,179 +155,107 @@ public static Service fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String uniqueName; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final URI callbackUrl; + + @Getter + private final String chatInstanceSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final Integer defaultTtl; - private final Service.NumberSelectionBehavior numberSelectionBehavior; + + @Getter private final Service.GeoMatchLevel geoMatchLevel; + + @Getter private final URI interceptCallbackUrl; + + @Getter + private final Map links; + + @Getter + private final Service.NumberSelectionBehavior numberSelectionBehavior; + + @Getter private final URI outOfSessionCallbackUrl; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter private final URI url; - private final Map links; @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("callback_url") - final URI callbackUrl, - @JsonProperty("default_ttl") - final Integer defaultTtl, - @JsonProperty("number_selection_behavior") - final Service.NumberSelectionBehavior numberSelectionBehavior, - @JsonProperty("geo_match_level") - final Service.GeoMatchLevel geoMatchLevel, - @JsonProperty("intercept_callback_url") - final URI interceptCallbackUrl, - @JsonProperty("out_of_session_callback_url") - final URI outOfSessionCallbackUrl, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.uniqueName = uniqueName; + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("callback_url") final URI callbackUrl, + @JsonProperty("chat_instance_sid") final String chatInstanceSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("default_ttl") final Integer defaultTtl, + @JsonProperty( + "geo_match_level" + ) final Service.GeoMatchLevel geoMatchLevel, + @JsonProperty("intercept_callback_url") final URI interceptCallbackUrl, + @JsonProperty("links") final Map links, + @JsonProperty( + "number_selection_behavior" + ) final Service.NumberSelectionBehavior numberSelectionBehavior, + @JsonProperty( + "out_of_session_callback_url" + ) final URI outOfSessionCallbackUrl, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.callbackUrl = callbackUrl; + this.chatInstanceSid = chatInstanceSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.defaultTtl = defaultTtl; - this.numberSelectionBehavior = numberSelectionBehavior; this.geoMatchLevel = geoMatchLevel; this.interceptCallbackUrl = interceptCallbackUrl; + this.links = links; + this.numberSelectionBehavior = numberSelectionBehavior; this.outOfSessionCallbackUrl = outOfSessionCallbackUrl; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.sid = sid; + this.uniqueName = uniqueName; this.url = url; - this.links = links; - } - - /** - * Returns The A string that uniquely identifies this Service.. - * - * @return A string that uniquely identifies this Service. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The A human readable description of this resource.. - * - * @return A human readable description of this resource. - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The URL Twilio will send callbacks to. - * - * @return URL Twilio will send callbacks to - */ - public final URI getCallbackUrl() { - return this.callbackUrl; - } - - /** - * Returns The Default TTL for a Session, in seconds.. - * - * @return Default TTL for a Session, in seconds. - */ - public final Integer getDefaultTtl() { - return this.defaultTtl; - } - - /** - * Returns The What behavior to use when choosing a proxy number.. - * - * @return What behavior to use when choosing a proxy number. - */ - public final Service.NumberSelectionBehavior getNumberSelectionBehavior() { - return this.numberSelectionBehavior; - } - - /** - * Returns The Whether proxy number selected must be in the same area code as - * the participant identifier.. - * - * @return Whether proxy number selected must be in the same area code as the - * participant identifier. - */ - public final Service.GeoMatchLevel getGeoMatchLevel() { - return this.geoMatchLevel; - } - - /** - * Returns The A URL for Twilio call before each Interaction.. - * - * @return A URL for Twilio call before each Interaction. - */ - public final URI getInterceptCallbackUrl() { - return this.interceptCallbackUrl; - } - - /** - * Returns The A URL for Twilio call when a new Interaction has no Session.. - * - * @return A URL for Twilio call when a new Interaction has no Session. - */ - public final URI getOutOfSessionCallbackUrl() { - return this.outOfSessionCallbackUrl; - } - - /** - * Returns The The date this Service was created. - * - * @return The date this Service was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Service was last updated. - * - * @return The date this Service was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; } @Override @@ -366,55 +269,47 @@ public boolean equals(final Object o) { } Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(callbackUrl, other.callbackUrl) && - Objects.equals(defaultTtl, other.defaultTtl) && - Objects.equals(numberSelectionBehavior, other.numberSelectionBehavior) && - Objects.equals(geoMatchLevel, other.geoMatchLevel) && - Objects.equals(interceptCallbackUrl, other.interceptCallbackUrl) && - Objects.equals(outOfSessionCallbackUrl, other.outOfSessionCallbackUrl) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(callbackUrl, other.callbackUrl) && + Objects.equals(chatInstanceSid, other.chatInstanceSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(defaultTtl, other.defaultTtl) && + Objects.equals(geoMatchLevel, other.geoMatchLevel) && + Objects.equals(interceptCallbackUrl, other.interceptCallbackUrl) && + Objects.equals(links, other.links) && + Objects.equals( + numberSelectionBehavior, + other.numberSelectionBehavior + ) && + Objects.equals( + outOfSessionCallbackUrl, + other.outOfSessionCallbackUrl + ) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - callbackUrl, - defaultTtl, - numberSelectionBehavior, - geoMatchLevel, - interceptCallbackUrl, - outOfSessionCallbackUrl, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("callbackUrl", callbackUrl) - .add("defaultTtl", defaultTtl) - .add("numberSelectionBehavior", numberSelectionBehavior) - .add("geoMatchLevel", geoMatchLevel) - .add("interceptCallbackUrl", interceptCallbackUrl) - .add("outOfSessionCallbackUrl", outOfSessionCallbackUrl) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + callbackUrl, + chatInstanceSid, + dateCreated, + dateUpdated, + defaultTtl, + geoMatchLevel, + interceptCallbackUrl, + links, + numberSelectionBehavior, + outOfSessionCallbackUrl, + sid, + uniqueName, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceCreator.java index 7746cfb349..ccf46d9cdb 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,212 +28,220 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceCreator extends Creator { - private final String uniqueName; + + private String uniqueName; private Integer defaultTtl; private URI callbackUrl; private Service.GeoMatchLevel geoMatchLevel; private Service.NumberSelectionBehavior numberSelectionBehavior; private URI interceptCallbackUrl; private URI outOfSessionCallbackUrl; + private String chatInstanceSid; - /** - * Construct a new ServiceCreator. - * - * @param uniqueName The human-readable string that uniquely identifies this - * Service. - */ public ServiceCreator(final String uniqueName) { this.uniqueName = uniqueName; } - /** - * The default time delay in seconds after the latest of Session create time or - * the Session's last Interaction time, after which a session will expire. Used - * for sessions where ttl is not specified.. - * - * @param defaultTtl Default TTL for Sessions in Service, in seconds. - * @return this - */ + public ServiceCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + public ServiceCreator setDefaultTtl(final Integer defaultTtl) { this.defaultTtl = defaultTtl; return this; } - /** - * The URL to which Twilio will make callbacks on interaction status changes.. - * - * @param callbackUrl URL Twilio will send callbacks to - * @return this - */ public ServiceCreator setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - /** - * The URL to which Twilio will make callbacks on interaction status changes.. - * - * @param callbackUrl URL Twilio will send callbacks to - * @return this - */ public ServiceCreator setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - /** - * Whether proxy number selected must be in the same area code as the - * participant identifier. Options: `country`, `area-code`, - * `extended-area-code`. Default: `country`. Levels lower than country are only - * available in North America.. - * - * @param geoMatchLevel Whether proxy number selected must be in the same area - * code as the participant identifier. - * @return this - */ - public ServiceCreator setGeoMatchLevel(final Service.GeoMatchLevel geoMatchLevel) { + public ServiceCreator setGeoMatchLevel( + final Service.GeoMatchLevel geoMatchLevel + ) { this.geoMatchLevel = geoMatchLevel; return this; } - /** - * Options: `prefer-sticky`, `avoid-sticky`. Default: `prefer-sticky`.. - * - * @param numberSelectionBehavior What behavior to use when choosing a proxy - * number. - * @return this - */ - public ServiceCreator setNumberSelectionBehavior(final Service.NumberSelectionBehavior numberSelectionBehavior) { + public ServiceCreator setNumberSelectionBehavior( + final Service.NumberSelectionBehavior numberSelectionBehavior + ) { this.numberSelectionBehavior = numberSelectionBehavior; return this; } - /** - * A URL for Twilio call before each Interaction. Returning a 403 status code - * will prevent the interaction from continuing.. - * - * @param interceptCallbackUrl A URL for Twilio call before each Interaction. - * @return this - */ - public ServiceCreator setInterceptCallbackUrl(final URI interceptCallbackUrl) { + public ServiceCreator setInterceptCallbackUrl( + final URI interceptCallbackUrl + ) { this.interceptCallbackUrl = interceptCallbackUrl; return this; } - /** - * A URL for Twilio call before each Interaction. Returning a 403 status code - * will prevent the interaction from continuing.. - * - * @param interceptCallbackUrl A URL for Twilio call before each Interaction. - * @return this - */ - public ServiceCreator setInterceptCallbackUrl(final String interceptCallbackUrl) { - return setInterceptCallbackUrl(Promoter.uriFromString(interceptCallbackUrl)); - } - - /** - * A URL for Twilio call when a new Interaction has no - * [Session](https://www.twilio.com/docs/proxy/api/session).. - * - * @param outOfSessionCallbackUrl A URL for Twilio call when a new Interaction - * has no Session. - * @return this - */ - public ServiceCreator setOutOfSessionCallbackUrl(final URI outOfSessionCallbackUrl) { + public ServiceCreator setInterceptCallbackUrl( + final String interceptCallbackUrl + ) { + return setInterceptCallbackUrl( + Promoter.uriFromString(interceptCallbackUrl) + ); + } + + public ServiceCreator setOutOfSessionCallbackUrl( + final URI outOfSessionCallbackUrl + ) { this.outOfSessionCallbackUrl = outOfSessionCallbackUrl; return this; } - /** - * A URL for Twilio call when a new Interaction has no - * [Session](https://www.twilio.com/docs/proxy/api/session).. - * - * @param outOfSessionCallbackUrl A URL for Twilio call when a new Interaction - * has no Session. - * @return this - */ - public ServiceCreator setOutOfSessionCallbackUrl(final String outOfSessionCallbackUrl) { - return setOutOfSessionCallbackUrl(Promoter.uriFromString(outOfSessionCallbackUrl)); - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { + public ServiceCreator setOutOfSessionCallbackUrl( + final String outOfSessionCallbackUrl + ) { + return setOutOfSessionCallbackUrl( + Promoter.uriFromString(outOfSessionCallbackUrl) + ); + } + + public ServiceCreator setChatInstanceSid(final String chatInstanceSid) { + this.chatInstanceSid = chatInstanceSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), - "/v1/Services", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (defaultTtl != null) { - request.addPostParam("DefaultTtl", defaultTtl.toString()); + Serializer.toString( + request, + "DefaultTtl", + defaultTtl, + ParameterType.URLENCODED + ); } if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); } if (geoMatchLevel != null) { - request.addPostParam("GeoMatchLevel", geoMatchLevel.toString()); + Serializer.toString( + request, + "GeoMatchLevel", + geoMatchLevel, + ParameterType.URLENCODED + ); } if (numberSelectionBehavior != null) { - request.addPostParam("NumberSelectionBehavior", numberSelectionBehavior.toString()); + Serializer.toString( + request, + "NumberSelectionBehavior", + numberSelectionBehavior, + ParameterType.URLENCODED + ); } if (interceptCallbackUrl != null) { - request.addPostParam("InterceptCallbackUrl", interceptCallbackUrl.toString()); + Serializer.toString( + request, + "InterceptCallbackUrl", + interceptCallbackUrl, + ParameterType.URLENCODED + ); } if (outOfSessionCallbackUrl != null) { - request.addPostParam("OutOfSessionCallbackUrl", outOfSessionCallbackUrl.toString()); + Serializer.toString( + request, + "OutOfSessionCallbackUrl", + outOfSessionCallbackUrl, + ParameterType.URLENCODED + ); + } + + if (chatInstanceSid != null) { + Serializer.toString( + request, + "ChatInstanceSid", + chatInstanceSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceDeleter.java index 39bd66a462..9e30f9c9a6 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new ServiceDeleter. - * - * @param pathSid A string that uniquely identifies this Service. - */ + private String pathSid; + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.PROXY.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceFetcher.java index da6dd3ba83..de475028c2 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new ServiceFetcher. - * - * @param pathSid A string that uniquely identifies this Service. - */ + private String pathSid; + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceReader.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceReader.java index 6fd4b5d685..903e4a759a 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1; @@ -10,152 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/proxy/v1/ServiceUpdater.java index aff8ccbe22..9a1323c90d 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/proxy/v1/ServiceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,15 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String uniqueName; private Integer defaultTtl; private URI callbackUrl; @@ -33,207 +42,209 @@ public class ServiceUpdater extends Updater { private Service.NumberSelectionBehavior numberSelectionBehavior; private URI interceptCallbackUrl; private URI outOfSessionCallbackUrl; + private String chatInstanceSid; - /** - * Construct a new ServiceUpdater. - * - * @param pathSid A string that uniquely identifies this Service. - */ public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * A human readable description of this resource, up to 64 characters.. - * - * @param uniqueName A human readable description of this resource. - * @return this - */ public ServiceUpdater setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * The default time delay in seconds after the latest of Session create time or - * the Session's last Interaction time, after which a session will expire. Used - * for sessions where ttl is not specified.. - * - * @param defaultTtl Default TTL for Sessions in Service, in seconds. - * @return this - */ public ServiceUpdater setDefaultTtl(final Integer defaultTtl) { this.defaultTtl = defaultTtl; return this; } - /** - * The URL to which Twilio will make callbacks on interaction status changes.. - * - * @param callbackUrl URL Twilio will send callbacks to - * @return this - */ public ServiceUpdater setCallbackUrl(final URI callbackUrl) { this.callbackUrl = callbackUrl; return this; } - /** - * The URL to which Twilio will make callbacks on interaction status changes.. - * - * @param callbackUrl URL Twilio will send callbacks to - * @return this - */ public ServiceUpdater setCallbackUrl(final String callbackUrl) { return setCallbackUrl(Promoter.uriFromString(callbackUrl)); } - /** - * Whether proxy number selected must be in the same area code as the - * participant identifier. Options: `country`, `area-code`, - * `extended-area-code`. Default: `country`. Levels lower than country are only - * available in North America.. - * - * @param geoMatchLevel Whether proxy number selected must be in the same area - * code as the participant identifier. - * @return this - */ - public ServiceUpdater setGeoMatchLevel(final Service.GeoMatchLevel geoMatchLevel) { + public ServiceUpdater setGeoMatchLevel( + final Service.GeoMatchLevel geoMatchLevel + ) { this.geoMatchLevel = geoMatchLevel; return this; } - /** - * Options: `prefer-sticky`, `avoid-sticky`. Default: `prefer-sticky`.. - * - * @param numberSelectionBehavior What behavior to use when choosing a proxy - * number. - * @return this - */ - public ServiceUpdater setNumberSelectionBehavior(final Service.NumberSelectionBehavior numberSelectionBehavior) { + public ServiceUpdater setNumberSelectionBehavior( + final Service.NumberSelectionBehavior numberSelectionBehavior + ) { this.numberSelectionBehavior = numberSelectionBehavior; return this; } - /** - * A URL for Twilio call before each Interaction. Returning a 403 status code - * will prevent the interaction from continuing.. - * - * @param interceptCallbackUrl A URL for Twilio call before each Interaction. - * @return this - */ - public ServiceUpdater setInterceptCallbackUrl(final URI interceptCallbackUrl) { + public ServiceUpdater setInterceptCallbackUrl( + final URI interceptCallbackUrl + ) { this.interceptCallbackUrl = interceptCallbackUrl; return this; } - /** - * A URL for Twilio call before each Interaction. Returning a 403 status code - * will prevent the interaction from continuing.. - * - * @param interceptCallbackUrl A URL for Twilio call before each Interaction. - * @return this - */ - public ServiceUpdater setInterceptCallbackUrl(final String interceptCallbackUrl) { - return setInterceptCallbackUrl(Promoter.uriFromString(interceptCallbackUrl)); - } - - /** - * A URL for Twilio call when a new Interaction has no - * [Session](https://www.twilio.com/docs/proxy/api/session).. - * - * @param outOfSessionCallbackUrl A URL for Twilio call when a new Interaction - * has no Session. - * @return this - */ - public ServiceUpdater setOutOfSessionCallbackUrl(final URI outOfSessionCallbackUrl) { + public ServiceUpdater setInterceptCallbackUrl( + final String interceptCallbackUrl + ) { + return setInterceptCallbackUrl( + Promoter.uriFromString(interceptCallbackUrl) + ); + } + + public ServiceUpdater setOutOfSessionCallbackUrl( + final URI outOfSessionCallbackUrl + ) { this.outOfSessionCallbackUrl = outOfSessionCallbackUrl; return this; } - /** - * A URL for Twilio call when a new Interaction has no - * [Session](https://www.twilio.com/docs/proxy/api/session).. - * - * @param outOfSessionCallbackUrl A URL for Twilio call when a new Interaction - * has no Session. - * @return this - */ - public ServiceUpdater setOutOfSessionCallbackUrl(final String outOfSessionCallbackUrl) { - return setOutOfSessionCallbackUrl(Promoter.uriFromString(outOfSessionCallbackUrl)); - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { + public ServiceUpdater setOutOfSessionCallbackUrl( + final String outOfSessionCallbackUrl + ) { + return setOutOfSessionCallbackUrl( + Promoter.uriFromString(outOfSessionCallbackUrl) + ); + } + + public ServiceUpdater setChatInstanceSid(final String chatInstanceSid) { + this.chatInstanceSid = chatInstanceSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (defaultTtl != null) { - request.addPostParam("DefaultTtl", defaultTtl.toString()); + Serializer.toString( + request, + "DefaultTtl", + defaultTtl, + ParameterType.URLENCODED + ); } if (callbackUrl != null) { - request.addPostParam("CallbackUrl", callbackUrl.toString()); + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); } if (geoMatchLevel != null) { - request.addPostParam("GeoMatchLevel", geoMatchLevel.toString()); + Serializer.toString( + request, + "GeoMatchLevel", + geoMatchLevel, + ParameterType.URLENCODED + ); } if (numberSelectionBehavior != null) { - request.addPostParam("NumberSelectionBehavior", numberSelectionBehavior.toString()); + Serializer.toString( + request, + "NumberSelectionBehavior", + numberSelectionBehavior, + ParameterType.URLENCODED + ); } if (interceptCallbackUrl != null) { - request.addPostParam("InterceptCallbackUrl", interceptCallbackUrl.toString()); + Serializer.toString( + request, + "InterceptCallbackUrl", + interceptCallbackUrl, + ParameterType.URLENCODED + ); } if (outOfSessionCallbackUrl != null) { - request.addPostParam("OutOfSessionCallbackUrl", outOfSessionCallbackUrl.toString()); + Serializer.toString( + request, + "OutOfSessionCallbackUrl", + outOfSessionCallbackUrl, + ParameterType.URLENCODED + ); + } + + if (chatInstanceSid != null) { + Serializer.toString( + request, + "ChatInstanceSid", + chatInstanceSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumber.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumber.java index 62e41f51c1..55b9e34feb 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumber.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; @@ -11,89 +18,71 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; +import com.twilio.type.*; import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class PhoneNumber extends Resource { - private static final long serialVersionUID = 266492066414172L; - /** - * Create a PhoneNumberCreator to execute create. - * - * @param pathServiceSid Service Sid. - * @return PhoneNumberCreator capable of executing the create - */ public static PhoneNumberCreator creator(final String pathServiceSid) { return new PhoneNumberCreator(pathServiceSid); } - /** - * Create a PhoneNumberDeleter to execute delete. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Phone Number. - * @return PhoneNumberDeleter capable of executing the delete - */ - public static PhoneNumberDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static PhoneNumberDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new PhoneNumberDeleter(pathServiceSid, pathSid); } - /** - * Create a PhoneNumberReader to execute read. - * - * @param pathServiceSid Service Sid. - * @return PhoneNumberReader capable of executing the read - */ + public static PhoneNumberFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new PhoneNumberFetcher(pathServiceSid, pathSid); + } + public static PhoneNumberReader reader(final String pathServiceSid) { return new PhoneNumberReader(pathServiceSid); } - /** - * Create a PhoneNumberFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Phone Number. - * @return PhoneNumberFetcher capable of executing the fetch - */ - public static PhoneNumberFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new PhoneNumberFetcher(pathServiceSid, pathSid); + public static PhoneNumberUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new PhoneNumberUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a PhoneNumber object using the provided - * ObjectMapper. - * + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return PhoneNumber object represented by the provided JSON */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -107,12 +96,15 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a PhoneNumber object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return PhoneNumber object represented by the provided JSON */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -123,138 +115,95 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final com.twilio.type.PhoneNumber phoneNumber; - private final String friendlyName; - private final String isoCountry; + + @Getter private final PhoneNumberCapabilities capabilities; - private final URI url; - @JsonCreator - private PhoneNumber(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.phoneNumber = phoneNumber; - this.friendlyName = friendlyName; - this.isoCountry = isoCountry; - this.capabilities = capabilities; - this.url = url; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The A string that uniquely identifies this Phone Number.. - * - * @return A string that uniquely identifies this Phone Number. - */ - public final String getSid() { - return this.sid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String friendlyName; - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final Integer inUse; - /** - * Returns The The date this Phone Number was added to the service. - * - * @return The date this Phone Number was added to the service - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Boolean isReserved; - /** - * Returns The The date this Phone Number was updated. - * - * @return The date this Phone Number was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String isoCountry; - /** - * Returns The The phone number.. - * - * @return The phone number. - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } + @Getter + private final com.twilio.type.PhoneNumber phoneNumber; - /** - * Returns The A human readable description of this resource.. - * - * @return A human readable description of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String serviceSid; - /** - * Returns The ISO Country Code,. - * - * @return ISO Country Code, - */ - public final String getIsoCountry() { - return this.isoCountry; - } + @Getter + private final String sid; - /** - * Returns The A list of capabilities.. - * - * @return A list of capabilities. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } + @Getter + private final URI url; - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; + @JsonCreator + private PhoneNumber( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("in_use") final Integer inUse, + @JsonProperty("is_reserved") final Boolean isReserved, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.capabilities = capabilities; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.inUse = inUse; + this.isReserved = isReserved; + this.isoCountry = isoCountry; + this.phoneNumber = phoneNumber; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; } @Override @@ -268,46 +217,37 @@ public boolean equals(final Object o) { } PhoneNumber other = (PhoneNumber) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(inUse, other.inUse) && + Objects.equals(isReserved, other.isReserved) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - phoneNumber, - friendlyName, - isoCountry, - capabilities, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("phoneNumber", phoneNumber) - .add("friendlyName", friendlyName) - .add("isoCountry", isoCountry) - .add("capabilities", capabilities) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + capabilities, + dateCreated, + dateUpdated, + friendlyName, + inUse, + isReserved, + isoCountry, + phoneNumber, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberCreator.java index 6ad6370d52..70da551576 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,108 +28,127 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class PhoneNumberCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; private String sid; private com.twilio.type.PhoneNumber phoneNumber; + private Boolean isReserved; - /** - * Construct a new PhoneNumberCreator. - * - * @param pathServiceSid Service Sid. - */ public PhoneNumberCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * A 34 character string that uniquely identifies this Phone Number.. - * - * @param sid A string that uniquely identifies this Phone Number. - * @return this - */ public PhoneNumberCreator setSid(final String sid) { this.sid = sid; return this; } - /** - * The phone_number. - * - * @param phoneNumber The phone_number - * @return this - */ - public PhoneNumberCreator setPhoneNumber(final com.twilio.type.PhoneNumber phoneNumber) { + public PhoneNumberCreator setPhoneNumber( + final com.twilio.type.PhoneNumber phoneNumber + ) { this.phoneNumber = phoneNumber; return this; } - /** - * The phone_number. - * - * @param phoneNumber The phone_number - * @return this - */ public PhoneNumberCreator setPhoneNumber(final String phoneNumber) { return setPhoneNumber(Promoter.phoneNumberFromString(phoneNumber)); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber create(final TwilioRestClient client) { + public PhoneNumberCreator setIsReserved(final Boolean isReserved) { + this.isReserved = isReserved; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/PhoneNumbers", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public PhoneNumber create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (sid != null) { - request.addPostParam("Sid", sid); + Serializer.toString(request, "Sid", sid, ParameterType.URLENCODED); } if (phoneNumber != null) { - request.addPostParam("PhoneNumber", phoneNumber.toString()); + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); + } + + if (isReserved != null) { + Serializer.toString( + request, + "IsReserved", + isReserved, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberDeleter.java index ba89024843..3033f28bdb 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,84 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class PhoneNumberDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new PhoneNumberDeleter. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Phone Number. - */ - public PhoneNumberDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public PhoneNumberDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/PhoneNumbers/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberFetcher.java index 3d6035bdb0..0edb691898 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class PhoneNumberFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new PhoneNumberFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Phone Number. - */ - public PhoneNumberFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public PhoneNumberFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/PhoneNumbers/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public PhoneNumber fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberReader.java index 15c0d712a6..415819c659 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; @@ -10,163 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class PhoneNumberReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new PhoneNumberReader. - * - * @param pathServiceSid Service Sid. - */ + private String pathServiceSid; + private Long pageSize; + public PhoneNumberReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public PhoneNumberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/PhoneNumbers", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of PhoneNumber Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("PhoneNumber read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "phone_numbers", - response.getContent(), - PhoneNumber.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberUpdater.java b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberUpdater.java new file mode 100644 index 0000000000..e81baf0924 --- /dev/null +++ b/src/main/java/com/twilio/rest/proxy/v1/service/PhoneNumberUpdater.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.proxy.v1.service; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PhoneNumberUpdater extends Updater { + + private String pathServiceSid; + private String pathSid; + private Boolean isReserved; + + public PhoneNumberUpdater( + final String pathServiceSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + public PhoneNumberUpdater setIsReserved(final Boolean isReserved) { + this.isReserved = isReserved; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.PROXY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PhoneNumber update(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (isReserved != null) { + Serializer.toString( + request, + "IsReserved", + isReserved, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/Session.java b/src/main/java/com/twilio/rest/proxy/v1/service/Session.java index 346d9a50d1..3b0633c394 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/Session.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/Session.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; @@ -10,43 +17,69 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Session extends Resource { - private static final long serialVersionUID = 199644364043028L; + + public static SessionCreator creator(final String pathServiceSid) { + return new SessionCreator(pathServiceSid); + } + + public static SessionDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new SessionDeleter(pathServiceSid, pathSid); + } + + public static SessionFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new SessionFetcher(pathServiceSid, pathSid); + } + + public static SessionReader reader(final String pathServiceSid) { + return new SessionReader(pathServiceSid); + } + + public static SessionUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new SessionUpdater(pathServiceSid, pathSid); + } public enum Status { + OPEN("open"), IN_PROGRESS("in-progress"), CLOSED("closed"), FAILED("failed"), - UNKNOWN("unknown"), - COMPLETED("completed"); + UNKNOWN("unknown"); private final String value; @@ -54,15 +87,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -80,85 +109,28 @@ private Mode(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Mode from a string. - * @param value string value - * @return generated Mode - */ @JsonCreator public static Mode forValue(final String value) { return Promoter.enumFromString(value, Mode.values()); } } - /** - * Create a SessionFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - * @return SessionFetcher capable of executing the fetch - */ - public static SessionFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new SessionFetcher(pathServiceSid, pathSid); - } - - /** - * Create a SessionReader to execute read. - * - * @param pathServiceSid Service Sid. - * @return SessionReader capable of executing the read - */ - public static SessionReader reader(final String pathServiceSid) { - return new SessionReader(pathServiceSid); - } - - /** - * Create a SessionCreator to execute create. - * - * @param pathServiceSid Service Sid. - * @return SessionCreator capable of executing the create - */ - public static SessionCreator creator(final String pathServiceSid) { - return new SessionCreator(pathServiceSid); - } - - /** - * Create a SessionDeleter to execute delete. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - * @return SessionDeleter capable of executing the delete - */ - public static SessionDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new SessionDeleter(pathServiceSid, pathSid); - } - - /** - * Create a SessionUpdater to execute update. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - * @return SessionUpdater capable of executing the update - */ - public static SessionUpdater updater(final String pathServiceSid, - final String pathSid) { - return new SessionUpdater(pathServiceSid, pathSid); - } - /** * Converts a JSON String into a Session object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Session object represented by the provided JSON */ - public static Session fromJson(final String json, final ObjectMapper objectMapper) { + public static Session fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Session.class); @@ -172,12 +144,15 @@ public static Session fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Session object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Session object represented by the provided JSON */ - public static Session fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Session fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Session.class); @@ -188,216 +163,131 @@ public static Session fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String serviceSid; - private final String accountSid; - private final DateTime dateStarted; - private final DateTime dateEnded; - private final DateTime dateLastInteraction; - private final DateTime dateExpiry; - private final String uniqueName; - private final Session.Status status; - private final String closedReason; - private final Integer ttl; - private final Session.Mode mode; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Session(@JsonProperty("sid") - final String sid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_started") - final String dateStarted, - @JsonProperty("date_ended") - final String dateEnded, - @JsonProperty("date_last_interaction") - final String dateLastInteraction, - @JsonProperty("date_expiry") - final String dateExpiry, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("status") - final Session.Status status, - @JsonProperty("closed_reason") - final String closedReason, - @JsonProperty("ttl") - final Integer ttl, - @JsonProperty("mode") - final Session.Mode mode, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.serviceSid = serviceSid; - this.accountSid = accountSid; - this.dateStarted = DateConverter.iso8601DateTimeFromString(dateStarted); - this.dateEnded = DateConverter.iso8601DateTimeFromString(dateEnded); - this.dateLastInteraction = DateConverter.iso8601DateTimeFromString(dateLastInteraction); - this.dateExpiry = DateConverter.iso8601DateTimeFromString(dateExpiry); - this.uniqueName = uniqueName; - this.status = status; - this.closedReason = closedReason; - this.ttl = ttl; - this.mode = mode; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A string that uniquely identifies this Session.. - * - * @return A string that uniquely identifies this Session. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final String closedReason; - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The date this Session was started. - * - * @return The date this Session was started - */ - public final DateTime getDateStarted() { - return this.dateStarted; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateEnded; - /** - * Returns The The date this Session was ended. - * - * @return The date this Session was ended - */ - public final DateTime getDateEnded() { - return this.dateEnded; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpiry; - /** - * Returns The The date this Session last had an interaction. - * - * @return The date this Session last had an interaction - */ - public final DateTime getDateLastInteraction() { - return this.dateLastInteraction; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateLastInteraction; - /** - * Returns The The date this Session should expire. - * - * @return The date this Session should expire - */ - public final DateTime getDateExpiry() { - return this.dateExpiry; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateStarted; - /** - * Returns The A unique, developer assigned identifier for this Session.. - * - * @return A unique, developer assigned identifier for this Session. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The Status of this Session. - * - * @return The Status of this Session - */ - public final Session.Status getStatus() { - return this.status; - } + @Getter + private final Map links; - /** - * Returns The Reason Session ended.. - * - * @return Reason Session ended. - */ - public final String getClosedReason() { - return this.closedReason; - } + @Getter + private final Session.Mode mode; - /** - * Returns The TTL for a Session, in seconds.. - * - * @return TTL for a Session, in seconds. - */ - public final Integer getTtl() { - return this.ttl; - } + @Getter + private final String serviceSid; - /** - * Returns The The Mode of this Session. - * - * @return The Mode of this Session - */ - public final Session.Mode getMode() { - return this.mode; - } + @Getter + private final String sid; - /** - * Returns The The date this Session was created. - * - * @return The date this Session was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Session.Status status; - /** - * Returns The The date this Session was last updated. - * - * @return The date this Session was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Integer ttl; - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String uniqueName; - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Session( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("closed_reason") final String closedReason, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_ended") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateEnded, + @JsonProperty("date_expiry") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpiry, + @JsonProperty("date_last_interaction") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateLastInteraction, + @JsonProperty("date_started") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateStarted, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("links") final Map links, + @JsonProperty("mode") final Session.Mode mode, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Session.Status status, + @JsonProperty("ttl") final Integer ttl, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.closedReason = closedReason; + this.dateCreated = dateCreated; + this.dateEnded = dateEnded; + this.dateExpiry = dateExpiry; + this.dateLastInteraction = dateLastInteraction; + this.dateStarted = dateStarted; + this.dateUpdated = dateUpdated; + this.links = links; + this.mode = mode; + this.serviceSid = serviceSid; + this.sid = sid; + this.status = status; + this.ttl = ttl; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -411,64 +301,45 @@ public boolean equals(final Object o) { } Session other = (Session) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateStarted, other.dateStarted) && - Objects.equals(dateEnded, other.dateEnded) && - Objects.equals(dateLastInteraction, other.dateLastInteraction) && - Objects.equals(dateExpiry, other.dateExpiry) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(status, other.status) && - Objects.equals(closedReason, other.closedReason) && - Objects.equals(ttl, other.ttl) && - Objects.equals(mode, other.mode) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(closedReason, other.closedReason) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateEnded, other.dateEnded) && + Objects.equals(dateExpiry, other.dateExpiry) && + Objects.equals(dateLastInteraction, other.dateLastInteraction) && + Objects.equals(dateStarted, other.dateStarted) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) && + Objects.equals(mode, other.mode) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(ttl, other.ttl) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - serviceSid, - accountSid, - dateStarted, - dateEnded, - dateLastInteraction, - dateExpiry, - uniqueName, - status, - closedReason, - ttl, - mode, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("dateStarted", dateStarted) - .add("dateEnded", dateEnded) - .add("dateLastInteraction", dateLastInteraction) - .add("dateExpiry", dateExpiry) - .add("uniqueName", uniqueName) - .add("status", status) - .add("closedReason", closedReason) - .add("ttl", ttl) - .add("mode", mode) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + closedReason, + dateCreated, + dateEnded, + dateExpiry, + dateLastInteraction, + dateStarted, + dateUpdated, + links, + mode, + serviceSid, + sid, + status, + ttl, + uniqueName, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionCreator.java index 9d13591ac8..c79adfad85 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionCreator.java @@ -1,16 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Creator; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -19,184 +28,171 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SessionCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; private String uniqueName; - private DateTime dateExpiry; + private ZonedDateTime dateExpiry; private Integer ttl; private Session.Mode mode; private Session.Status status; - private List> participants; + private List participants; - /** - * Construct a new SessionCreator. - * - * @param pathServiceSid Service Sid. - */ public SessionCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Your unique identifier for this Session such as a Job ID or conversation ID. - * Should not contain PII.. - * - * @param uniqueName A unique, developer assigned name of this Session. - * @return this - */ public SessionCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * An absolute time (ISO 8601) at which this Session should close. If this is - * populated, it takes precedence over TTL values.. - * - * @param dateExpiry The date this Session should expire - * @return this - */ - public SessionCreator setDateExpiry(final DateTime dateExpiry) { + public SessionCreator setDateExpiry(final ZonedDateTime dateExpiry) { this.dateExpiry = dateExpiry; return this; } - /** - * The time, in seconds, after the latest of Session create time or the - * Session's last Interaction time at which the session will expire.. - * - * @param ttl TTL for a Session, in seconds. - * @return this - */ public SessionCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * The type of communications mediums allowed on a Session. Defaults to - * `voice-and-message`. Other options are `voice-only` or `message-only`.. - * - * @param mode The Mode of this Session - * @return this - */ public SessionCreator setMode(final Session.Mode mode) { this.mode = mode; return this; } - /** - * Set this value to `closed` to close the session. A Session can be re-opened - * by posting to a closed session with the value `in-progress`. This will be - * `open` by default on create.. - * - * @param status Session status - * @return this - */ public SessionCreator setStatus(final Session.Status status) { this.status = status; return this; } - /** - * The participants. - * - * @param participants The participants - * @return this - */ - public SessionCreator setParticipants(final List> participants) { + public SessionCreator setParticipants(final List participants) { this.participants = participants; return this; } - /** - * The participants. - * - * @param participants The participants - * @return this - */ - public SessionCreator setParticipants(final Map participants) { + public SessionCreator setParticipants(final Object participants) { return setParticipants(Promoter.listOfOne(participants)); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Session - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Session create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Sessions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Session creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Session create(final TwilioRestClient client) { + Response response = makeRequest(client); return Session.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Session content = Session.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (dateExpiry != null) { - request.addPostParam("DateExpiry", dateExpiry.toString()); + Serializer.toString( + request, + "DateExpiry", + dateExpiry, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); } if (mode != null) { - request.addPostParam("Mode", mode.toString()); + Serializer.toString( + request, + "Mode", + mode, + ParameterType.URLENCODED + ); } if (status != null) { - request.addPostParam("Status", status.toString()); + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); } if (participants != null) { - for (Map prop : participants) { - request.addPostParam("Participants", Converter.mapToJson(prop)); + for (Object param : participants) { + Serializer.toString( + request, + "Participants", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionDeleter.java index 198de48c18..f3009e5edc 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SessionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new SessionDeleter. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - */ - public SessionDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public SessionDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Sessions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Session delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionFetcher.java index d504433aef..851d37773d 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SessionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new SessionFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - */ - public SessionFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public SessionFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Session - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Session fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Sessions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Session fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Session fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Session.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Session content = Session.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionReader.java index 5ef4ab1276..12ce3ce9ec 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; @@ -10,172 +17,137 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SessionReader extends Reader { - private final String pathServiceSid; - private String uniqueName; - private Session.Status status; - - /** - * Construct a new SessionReader. - * - * @param pathServiceSid Service Sid. - */ + + private String pathServiceSid; + private Long pageSize; + public SessionReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * The unique_name. - * - * @param uniqueName The unique_name - * @return this - */ - public SessionReader setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; + public SessionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; return this; } - /** - * The Status of this Session. One of `in-progress`, `closed`, `failed`, - * `unknown` or `completed`.. - * - * @param status The Status of this Session - * @return this - */ - public SessionReader setStatus(final Session.Status status) { - this.status = status; - return this; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sessions", + response.getContent(), + Session.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Session ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Sessions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Session ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Session ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) - ); + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sessions", + response.getContent(), + Session.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() ); - return pageForRequest(client, request); } - /** - * Generate a Page of Session Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); - if (response == null) { - throw new ApiConnectionException("Session read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Session read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); return Page.fromJson( "sessions", response.getContent(), @@ -184,22 +156,56 @@ private Page pageForRequest(final TwilioRestClient client, final Reques ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (uniqueName != null) { - request.addQueryParam("UniqueName", uniqueName); + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } - if (status != null) { - request.addQueryParam("Status", status.toString()); + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/SessionUpdater.java b/src/main/java/com/twilio/rest/proxy/v1/service/SessionUpdater.java index 5f3047bd96..3593cc16fd 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/SessionUpdater.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/SessionUpdater.java @@ -1,16 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; -import com.twilio.converter.Promoter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -19,184 +27,122 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; -import java.util.List; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SessionUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; - private String uniqueName; - private DateTime dateExpiry; + + private String pathServiceSid; + private String pathSid; + private ZonedDateTime dateExpiry; private Integer ttl; - private Session.Mode mode; private Session.Status status; - private List> participants; - - /** - * Construct a new SessionUpdater. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Session. - */ - public SessionUpdater(final String pathServiceSid, - final String pathSid) { + + public SessionUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * The unique_name. - * - * @param uniqueName The unique_name - * @return this - */ - public SessionUpdater setUniqueName(final String uniqueName) { - this.uniqueName = uniqueName; - return this; - } - - /** - * The date that this Session should expire, given in ISO 8601 format.. - * - * @param dateExpiry The date this Session should expire - * @return this - */ - public SessionUpdater setDateExpiry(final DateTime dateExpiry) { + public SessionUpdater setDateExpiry(final ZonedDateTime dateExpiry) { this.dateExpiry = dateExpiry; return this; } - /** - * The time, in seconds, after the latest of Session create time or the - * Session's last Interaction time at which the session will expire.. - * - * @param ttl TTL for a Session, in seconds. - * @return this - */ public SessionUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * The mode. - * - * @param mode The mode - * @return this - */ - public SessionUpdater setMode(final Session.Mode mode) { - this.mode = mode; - return this; - } - - /** - * The Status of this Session. Set to `in-progress` to re-open a session or - * `closed` to close a session.. - * - * @param status The Status of this Session - * @return this - */ public SessionUpdater setStatus(final Session.Status status) { this.status = status; return this; } - /** - * The participants. - * - * @param participants The participants - * @return this - */ - public SessionUpdater setParticipants(final List> participants) { - this.participants = participants; - return this; - } + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Sessions/{Sid}"; - /** - * The participants. - * - * @param participants The participants - * @return this - */ - public SessionUpdater setParticipants(final Map participants) { - return setParticipants(Promoter.listOfOne(participants)); - } + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Session - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Session update(final TwilioRestClient client) { Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Session update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Session update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Session update(final TwilioRestClient client) { + Response response = makeRequest(client); return Session.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); - } + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Session content = Session.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (dateExpiry != null) { - request.addPostParam("DateExpiry", dateExpiry.toString()); + Serializer.toString( + request, + "DateExpiry", + dateExpiry, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); - } - - if (mode != null) { - request.addPostParam("Mode", mode.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); } if (status != null) { - request.addPostParam("Status", status.toString()); - } - - if (participants != null) { - for (Map prop : participants) { - request.addPostParam("Participants", Converter.mapToJson(prop)); - } + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCode.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCode.java deleted file mode 100644 index 78aaa6acdb..0000000000 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCode.java +++ /dev/null @@ -1,299 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.proxy.v1.service; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; -import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import com.twilio.type.PhoneNumberCapabilities; -import org.joda.time.DateTime; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.util.Map; -import java.util.Objects; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public class ShortCode extends Resource { - private static final long serialVersionUID = 205194223187327L; - - /** - * Create a ShortCodeCreator to execute create. - * - * @param pathServiceSid Service Sid. - * @param sid A string that uniquely identifies this Short Code. - * @return ShortCodeCreator capable of executing the create - */ - public static ShortCodeCreator creator(final String pathServiceSid, - final String sid) { - return new ShortCodeCreator(pathServiceSid, sid); - } - - /** - * Create a ShortCodeDeleter to execute delete. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Short Code. - * @return ShortCodeDeleter capable of executing the delete - */ - public static ShortCodeDeleter deleter(final String pathServiceSid, - final String pathSid) { - return new ShortCodeDeleter(pathServiceSid, pathSid); - } - - /** - * Create a ShortCodeReader to execute read. - * - * @param pathServiceSid Service Sid. - * @return ShortCodeReader capable of executing the read - */ - public static ShortCodeReader reader(final String pathServiceSid) { - return new ShortCodeReader(pathServiceSid); - } - - /** - * Create a ShortCodeFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Short Code. - * @return ShortCodeFetcher capable of executing the fetch - */ - public static ShortCodeFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new ShortCodeFetcher(pathServiceSid, pathSid); - } - - /** - * Converts a JSON String into a ShortCode object using the provided - * ObjectMapper. - * - * @param json Raw JSON String - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final String json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, ShortCode.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - /** - * Converts a JSON InputStream into a ShortCode object using the provided - * ObjectMapper. - * - * @param json Raw JSON InputStream - * @param objectMapper Jackson ObjectMapper - * @return ShortCode object represented by the provided JSON - */ - public static ShortCode fromJson(final InputStream json, final ObjectMapper objectMapper) { - // Convert all checked exceptions to Runtime - try { - return objectMapper.readValue(json, ShortCode.class); - } catch (final JsonMappingException | JsonParseException e) { - throw new ApiException(e.getMessage(), e); - } catch (final IOException e) { - throw new ApiConnectionException(e.getMessage(), e); - } - } - - private final String sid; - private final String accountSid; - private final String serviceSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String shortCode; - private final String isoCountry; - private final PhoneNumberCapabilities capabilities; - private final URI url; - - @JsonCreator - private ShortCode(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("short_code") - final String shortCode, - @JsonProperty("iso_country") - final String isoCountry, - @JsonProperty("capabilities") - final PhoneNumberCapabilities capabilities, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.shortCode = shortCode; - this.isoCountry = isoCountry; - this.capabilities = capabilities; - this.url = url; - } - - /** - * Returns The A string that uniquely identifies this Short Code.. - * - * @return A string that uniquely identifies this Short Code. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The The date this Short Code was added to the service. - * - * @return The date this Short Code was added to the service - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Short Code was updated. - * - * @return The date this Short Code was updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Shortcode.. - * - * @return Shortcode. - */ - public final String getShortCode() { - return this.shortCode; - } - - /** - * Returns The ISO Country Code,. - * - * @return ISO Country Code, - */ - public final String getIsoCountry() { - return this.isoCountry; - } - - /** - * Returns The A list of capabilities.. - * - * @return A list of capabilities. - */ - public final PhoneNumberCapabilities getCapabilities() { - return this.capabilities; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - - @Override - public boolean equals(final Object o) { - if (this == o) { - return true; - } - - if (o == null || getClass() != o.getClass()) { - return false; - } - - ShortCode other = (ShortCode) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(shortCode, other.shortCode) && - Objects.equals(isoCountry, other.isoCountry) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(url, other.url); - } - - @Override - public int hashCode() { - return Objects.hash(sid, - accountSid, - serviceSid, - dateCreated, - dateUpdated, - shortCode, - isoCountry, - capabilities, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("shortCode", shortCode) - .add("isoCountry", isoCountry) - .add("capabilities", capabilities) - .add("url", url) - .toString(); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeCreator.java deleted file mode 100644 index 4879188c03..0000000000 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeCreator.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.proxy.v1.service; - -import com.twilio.base.Creator; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class ShortCodeCreator extends Creator { - private final String pathServiceSid; - private final String sid; - - /** - * Construct a new ShortCodeCreator. - * - * @param pathServiceSid Service Sid. - * @param sid A string that uniquely identifies this Short Code. - */ - public ShortCodeCreator(final String pathServiceSid, - final String sid) { - this.pathServiceSid = pathServiceSid; - this.sid = sid; - } - - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created ShortCode - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ShortCode create(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/ShortCodes", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (sid != null) { - request.addPostParam("Sid", sid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeDeleter.java deleted file mode 100644 index 3909c4271d..0000000000 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeDeleter.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.proxy.v1.service; - -import com.twilio.base.Deleter; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class ShortCodeDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new ShortCodeDeleter. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Short Code. - */ - public ShortCodeDeleter(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.DELETE, - Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/ShortCodes/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return response.getStatusCode() == 204; - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeFetcher.java deleted file mode 100644 index fbdab23aaa..0000000000 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeFetcher.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.proxy.v1.service; - -import com.twilio.base.Fetcher; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class ShortCodeFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - - /** - * Construct a new ShortCodeFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSid A string that uniquely identifies this Short Code. - */ - public ShortCodeFetcher(final String pathServiceSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSid = pathSid; - } - - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched ShortCode - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public ShortCode fetch(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/ShortCodes/" + this.pathSid + "", - client.getRegion() - ); - - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return ShortCode.fromJson(response.getStream(), client.getObjectMapper()); - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeReader.java deleted file mode 100644 index 122a5687a1..0000000000 --- a/src/main/java/com/twilio/rest/proxy/v1/service/ShortCodeReader.java +++ /dev/null @@ -1,172 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.proxy.v1.service; - -import com.twilio.base.Page; -import com.twilio.base.Reader; -import com.twilio.base.ResourceSet; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class ShortCodeReader extends Reader { - private final String pathServiceSid; - - /** - * Construct a new ShortCodeReader. - * - * @param pathServiceSid Service Sid. - */ - public ShortCodeReader(final String pathServiceSid) { - this.pathServiceSid = pathServiceSid; - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } - - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/ShortCodes", - client.getRegion() - ); - - addQueryParams(request); - return pageForRequest(client, request); - } - - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return ShortCode ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); - } - - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) - ); - return pageForRequest(client, request); - } - - /** - * Generate a Page of ShortCode Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("ShortCode read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Page.fromJson( - "short_codes", - response.getContent(), - ShortCode.class, - client.getObjectMapper() - ); - } - - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (getPageSize() != null) { - request.addQueryParam("PageSize", Integer.toString(getPageSize())); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/Interaction.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/Interaction.java index 3c7beb7cf2..aed37e4032 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/Interaction.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/Interaction.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; @@ -10,36 +17,55 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Interaction extends Resource { - private static final long serialVersionUID = 184706954085822L; + + public static InteractionDeleter deleter( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { + return new InteractionDeleter(pathServiceSid, pathSessionSid, pathSid); + } + + public static InteractionFetcher fetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { + return new InteractionFetcher(pathServiceSid, pathSessionSid, pathSid); + } + + public static InteractionReader reader( + final String pathServiceSid, + final String pathSessionSid + ) { + return new InteractionReader(pathServiceSid, pathSessionSid); + } public enum Type { MESSAGE("message"), @@ -52,15 +78,11 @@ private Type(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Type from a string. - * @param value string value - * @return generated Type - */ @JsonCreator public static Type forValue(final String value) { return Promoter.enumFromString(value, Type.values()); @@ -96,15 +118,11 @@ private ResourceStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ResourceStatus from a string. - * @param value string value - * @return generated ResourceStatus - */ @JsonCreator public static ResourceStatus forValue(final String value) { return Promoter.enumFromString(value, ResourceStatus.values()); @@ -112,54 +130,16 @@ public static ResourceStatus forValue(final String value) { } /** - * Create a InteractionFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Interaction. - * @return InteractionFetcher capable of executing the fetch - */ - public static InteractionFetcher fetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new InteractionFetcher(pathServiceSid, pathSessionSid, pathSid); - } - - /** - * Create a InteractionReader to execute read. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @return InteractionReader capable of executing the read - */ - public static InteractionReader reader(final String pathServiceSid, - final String pathSessionSid) { - return new InteractionReader(pathServiceSid, pathSessionSid); - } - - /** - * Create a InteractionDeleter to execute delete. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Interaction. - * @return InteractionDeleter capable of executing the delete - */ - public static InteractionDeleter deleter(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new InteractionDeleter(pathServiceSid, pathSessionSid, pathSid); - } - - /** - * Converts a JSON String into a Interaction object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Interaction object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Interaction object represented by the provided JSON */ - public static Interaction fromJson(final String json, final ObjectMapper objectMapper) { + public static Interaction fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Interaction.class); @@ -173,12 +153,15 @@ public static Interaction fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a Interaction object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Interaction object represented by the provided JSON */ - public static Interaction fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Interaction fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Interaction.class); @@ -189,71 +172,121 @@ public static Interaction fromJson(final InputStream json, final ObjectMapper ob } } - private final String sid; - private final String sessionSid; - private final String serviceSid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String data; - private final Interaction.Type type; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String inboundParticipantSid; + + @Getter private final String inboundResourceSid; + + @Getter private final Interaction.ResourceStatus inboundResourceStatus; + + @Getter private final String inboundResourceType; + + @Getter private final URI inboundResourceUrl; + + @Getter private final String outboundParticipantSid; + + @Getter private final String outboundResourceSid; + + @Getter private final Interaction.ResourceStatus outboundResourceStatus; + + @Getter private final String outboundResourceType; + + @Getter private final URI outboundResourceUrl; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String serviceSid; + + @Getter + private final String sessionSid; + + @Getter + private final String sid; + + @Getter + private final Interaction.Type type; + + @Getter private final URI url; @JsonCreator - private Interaction(@JsonProperty("sid") - final String sid, - @JsonProperty("session_sid") - final String sessionSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("data") - final String data, - @JsonProperty("type") - final Interaction.Type type, - @JsonProperty("inbound_participant_sid") - final String inboundParticipantSid, - @JsonProperty("inbound_resource_sid") - final String inboundResourceSid, - @JsonProperty("inbound_resource_status") - final Interaction.ResourceStatus inboundResourceStatus, - @JsonProperty("inbound_resource_type") - final String inboundResourceType, - @JsonProperty("inbound_resource_url") - final URI inboundResourceUrl, - @JsonProperty("outbound_participant_sid") - final String outboundParticipantSid, - @JsonProperty("outbound_resource_sid") - final String outboundResourceSid, - @JsonProperty("outbound_resource_status") - final Interaction.ResourceStatus outboundResourceStatus, - @JsonProperty("outbound_resource_type") - final String outboundResourceType, - @JsonProperty("outbound_resource_url") - final URI outboundResourceUrl, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.sessionSid = sessionSid; - this.serviceSid = serviceSid; + private Interaction( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("data") final String data, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "inbound_participant_sid" + ) final String inboundParticipantSid, + @JsonProperty("inbound_resource_sid") final String inboundResourceSid, + @JsonProperty( + "inbound_resource_status" + ) final Interaction.ResourceStatus inboundResourceStatus, + @JsonProperty("inbound_resource_type") final String inboundResourceType, + @JsonProperty("inbound_resource_url") final URI inboundResourceUrl, + @JsonProperty( + "outbound_participant_sid" + ) final String outboundParticipantSid, + @JsonProperty("outbound_resource_sid") final String outboundResourceSid, + @JsonProperty( + "outbound_resource_status" + ) final Interaction.ResourceStatus outboundResourceStatus, + @JsonProperty( + "outbound_resource_type" + ) final String outboundResourceType, + @JsonProperty("outbound_resource_url") final URI outboundResourceUrl, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("session_sid") final String sessionSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final Interaction.Type type, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.data = data; - this.type = type; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.inboundParticipantSid = inboundParticipantSid; this.inboundResourceSid = inboundResourceSid; this.inboundResourceStatus = inboundResourceStatus; @@ -264,182 +297,13 @@ private Interaction(@JsonProperty("sid") this.outboundResourceStatus = outboundResourceStatus; this.outboundResourceType = outboundResourceType; this.outboundResourceUrl = outboundResourceUrl; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.serviceSid = serviceSid; + this.sessionSid = sessionSid; + this.sid = sid; + this.type = type; this.url = url; } - /** - * Returns The A string that uniquely identifies this Interaction.. - * - * @return A string that uniquely identifies this Interaction. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Session Sid.. - * - * @return Session Sid. - */ - public final String getSessionSid() { - return this.sessionSid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Further details about an interaction.. - * - * @return Further details about an interaction. - */ - public final String getData() { - return this.data; - } - - /** - * Returns The The Type of this Interaction. - * - * @return The Type of this Interaction - */ - public final Interaction.Type getType() { - return this.type; - } - - /** - * Returns The Inbound Participant Sid.. - * - * @return Inbound Participant Sid. - */ - public final String getInboundParticipantSid() { - return this.inboundParticipantSid; - } - - /** - * Returns The Inbound Resource Sid.. - * - * @return Inbound Resource Sid. - */ - public final String getInboundResourceSid() { - return this.inboundResourceSid; - } - - /** - * Returns The The Inbound Resource Status of this Interaction. - * - * @return The Inbound Resource Status of this Interaction - */ - public final Interaction.ResourceStatus getInboundResourceStatus() { - return this.inboundResourceStatus; - } - - /** - * Returns The The type of the Inbound Resource, Call or Message.. - * - * @return The type of the Inbound Resource, Call or Message. - */ - public final String getInboundResourceType() { - return this.inboundResourceType; - } - - /** - * Returns The The URL of the Twilio inbound resource.. - * - * @return The URL of the Twilio inbound resource. - */ - public final URI getInboundResourceUrl() { - return this.inboundResourceUrl; - } - - /** - * Returns The Outbound Participant Sid.. - * - * @return Outbound Participant Sid. - */ - public final String getOutboundParticipantSid() { - return this.outboundParticipantSid; - } - - /** - * Returns The Outbound Resource Sid.. - * - * @return Outbound Resource Sid. - */ - public final String getOutboundResourceSid() { - return this.outboundResourceSid; - } - - /** - * Returns The The Outbound Resource Status of this Interaction. - * - * @return The Outbound Resource Status of this Interaction - */ - public final Interaction.ResourceStatus getOutboundResourceStatus() { - return this.outboundResourceStatus; - } - - /** - * Returns The The type of the Outbound Resource, Call or Message.. - * - * @return The type of the Outbound Resource, Call or Message. - */ - public final String getOutboundResourceType() { - return this.outboundResourceType; - } - - /** - * Returns The The URL of the Twilio outbound resource.. - * - * @return The URL of the Twilio outbound resource. - */ - public final URI getOutboundResourceUrl() { - return this.outboundResourceUrl; - } - - /** - * Returns The The date this Interaction was created. - * - * @return The date this Interaction was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Interaction was last updated. - * - * @return The date this Interaction was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -451,73 +315,63 @@ public boolean equals(final Object o) { } Interaction other = (Interaction) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(sessionSid, other.sessionSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(data, other.data) && - Objects.equals(type, other.type) && - Objects.equals(inboundParticipantSid, other.inboundParticipantSid) && - Objects.equals(inboundResourceSid, other.inboundResourceSid) && - Objects.equals(inboundResourceStatus, other.inboundResourceStatus) && - Objects.equals(inboundResourceType, other.inboundResourceType) && - Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && - Objects.equals(outboundParticipantSid, other.outboundParticipantSid) && - Objects.equals(outboundResourceSid, other.outboundResourceSid) && - Objects.equals(outboundResourceStatus, other.outboundResourceStatus) && - Objects.equals(outboundResourceType, other.outboundResourceType) && - Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + inboundParticipantSid, + other.inboundParticipantSid + ) && + Objects.equals(inboundResourceSid, other.inboundResourceSid) && + Objects.equals( + inboundResourceStatus, + other.inboundResourceStatus + ) && + Objects.equals(inboundResourceType, other.inboundResourceType) && + Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && + Objects.equals( + outboundParticipantSid, + other.outboundParticipantSid + ) && + Objects.equals(outboundResourceSid, other.outboundResourceSid) && + Objects.equals( + outboundResourceStatus, + other.outboundResourceStatus + ) && + Objects.equals(outboundResourceType, other.outboundResourceType) && + Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sessionSid, other.sessionSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - sessionSid, - serviceSid, - accountSid, - data, - type, - inboundParticipantSid, - inboundResourceSid, - inboundResourceStatus, - inboundResourceType, - inboundResourceUrl, - outboundParticipantSid, - outboundResourceSid, - outboundResourceStatus, - outboundResourceType, - outboundResourceUrl, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("sessionSid", sessionSid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("data", data) - .add("type", type) - .add("inboundParticipantSid", inboundParticipantSid) - .add("inboundResourceSid", inboundResourceSid) - .add("inboundResourceStatus", inboundResourceStatus) - .add("inboundResourceType", inboundResourceType) - .add("inboundResourceUrl", inboundResourceUrl) - .add("outboundParticipantSid", outboundParticipantSid) - .add("outboundResourceSid", outboundResourceSid) - .add("outboundResourceStatus", outboundResourceStatus) - .add("outboundResourceType", outboundResourceType) - .add("outboundResourceUrl", outboundResourceUrl) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + data, + dateCreated, + dateUpdated, + inboundParticipantSid, + inboundResourceSid, + inboundResourceStatus, + inboundResourceType, + inboundResourceUrl, + outboundParticipantSid, + outboundResourceSid, + outboundResourceStatus, + outboundResourceType, + outboundResourceUrl, + serviceSid, + sessionSid, + sid, + type, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionDeleter.java index 212b8352f3..c948b91a63 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,65 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class InteractionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - /** - * Construct a new InteractionDeleter. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Interaction. - */ - public InteractionDeleter(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { + private String pathServiceSid; + private String pathSessionSid; + private String pathSid; + + public InteractionDeleter( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Interactions/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Interaction delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Interaction delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionFetcher.java index 1cf333e23d..cb7411e4f5 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class InteractionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - /** - * Construct a new InteractionFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Interaction. - */ - public InteractionFetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { + private String pathServiceSid; + private String pathSessionSid; + private String pathSid; + + public InteractionFetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Interaction - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Interaction fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Interactions/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Interaction fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Interaction fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Interaction fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Interaction.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Interaction content = Interaction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionReader.java index e9c1c2ef81..2faf794e78 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/InteractionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; @@ -10,175 +17,148 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class InteractionReader extends Reader { - private final String pathServiceSid; - private final String pathSessionSid; - private Interaction.ResourceStatus inboundParticipantStatus; - private Interaction.ResourceStatus outboundParticipantStatus; - - /** - * Construct a new InteractionReader. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - */ - public InteractionReader(final String pathServiceSid, - final String pathSessionSid) { + + private String pathServiceSid; + private String pathSessionSid; + private Long pageSize; + + public InteractionReader( + final String pathServiceSid, + final String pathSessionSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; } - /** - * The inbound_participant_status. - * - * @param inboundParticipantStatus The inbound_participant_status - * @return this - */ - public InteractionReader setInboundParticipantStatus(final Interaction.ResourceStatus inboundParticipantStatus) { - this.inboundParticipantStatus = inboundParticipantStatus; + public InteractionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; return this; } - /** - * The outbound_participant_status. - * - * @param outboundParticipantStatus The outbound_participant_status - * @return this - */ - public InteractionReader setOutboundParticipantStatus(final Interaction.ResourceStatus outboundParticipantStatus) { - this.outboundParticipantStatus = outboundParticipantStatus; - return this; + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "interactions", + response.getContent(), + Interaction.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Interaction ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); - } + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Interactions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Interaction ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Interactions", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Interaction ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); - - return pageForRequest(client, request); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ - @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getNextPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) - ); + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ - @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "interactions", + response.getContent(), + Interaction.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() ); - return pageForRequest(client, request); } - /** - * Generate a Page of Interaction Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { Response response = client.request(request); - if (response == null) { - throw new ApiConnectionException("Interaction read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Interaction read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); return Page.fromJson( "interactions", response.getContent(), @@ -187,22 +167,56 @@ private Page pageForRequest(final TwilioRestClient client, final Re ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ - private void addQueryParams(final Request request) { - if (inboundParticipantStatus != null) { - request.addQueryParam("InboundParticipantStatus", inboundParticipantStatus.toString()); + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } - if (outboundParticipantStatus != null) { - request.addQueryParam("OutboundParticipantStatus", outboundParticipantStatus.toString()); + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/Participant.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/Participant.java index 166170c105..a67dadd76e 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/Participant.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/Participant.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; @@ -11,112 +18,77 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Participant extends Resource { - private static final long serialVersionUID = 233073623535354L; - /** - * Create a ParticipantFetcher to execute fetch. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - * @return ParticipantFetcher capable of executing the fetch - */ - public static ParticipantFetcher fetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new ParticipantFetcher(pathServiceSid, pathSessionSid, pathSid); + public static ParticipantCreator creator( + final String pathServiceSid, + final String pathSessionSid, + final String identifier + ) { + return new ParticipantCreator( + pathServiceSid, + pathSessionSid, + identifier + ); } - /** - * Create a ParticipantReader to execute read. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @return ParticipantReader capable of executing the read - */ - public static ParticipantReader reader(final String pathServiceSid, - final String pathSessionSid) { - return new ParticipantReader(pathServiceSid, pathSessionSid); - } - - /** - * Create a ParticipantCreator to execute create. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param identifier The phone number of this Participant. - * @return ParticipantCreator capable of executing the create - */ - public static ParticipantCreator creator(final String pathServiceSid, - final String pathSessionSid, - final String identifier) { - return new ParticipantCreator(pathServiceSid, pathSessionSid, identifier); + public static ParticipantDeleter deleter( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { + return new ParticipantDeleter(pathServiceSid, pathSessionSid, pathSid); } - /** - * Create a ParticipantDeleter to execute delete. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - * @return ParticipantDeleter capable of executing the delete - */ - public static ParticipantDeleter deleter(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new ParticipantDeleter(pathServiceSid, pathSessionSid, pathSid); + public static ParticipantFetcher fetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { + return new ParticipantFetcher(pathServiceSid, pathSessionSid, pathSid); } - /** - * Create a ParticipantUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathSid The sid - * @return ParticipantUpdater capable of executing the update - */ - public static ParticipantUpdater updater(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - return new ParticipantUpdater(pathServiceSid, pathSessionSid, pathSid); + public static ParticipantReader reader( + final String pathServiceSid, + final String pathSessionSid + ) { + return new ParticipantReader(pathServiceSid, pathSessionSid); } /** - * Converts a JSON String into a Participant object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Participant object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Participant object represented by the provided JSON */ - public static Participant fromJson(final String json, final ObjectMapper objectMapper) { + public static Participant fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -130,12 +102,15 @@ public static Participant fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a Participant object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Participant object represented by the provided JSON */ - public static Participant fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Participant fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Participant.class); @@ -146,177 +121,101 @@ public static Participant fromJson(final InputStream json, final ObjectMapper ob } } - private final String sid; - private final String sessionSid; - private final String serviceSid; - private final String accountSid; - private final String friendlyName; - private final String identifier; - private final String proxyIdentifier; - private final String proxyIdentifierSid; - private final DateTime dateDeleted; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Participant(@JsonProperty("sid") - final String sid, - @JsonProperty("session_sid") - final String sessionSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("identifier") - final String identifier, - @JsonProperty("proxy_identifier") - final String proxyIdentifier, - @JsonProperty("proxy_identifier_sid") - final String proxyIdentifierSid, - @JsonProperty("date_deleted") - final String dateDeleted, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.sessionSid = sessionSid; - this.serviceSid = serviceSid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.identifier = identifier; - this.proxyIdentifier = proxyIdentifier; - this.proxyIdentifierSid = proxyIdentifierSid; - this.dateDeleted = DateConverter.iso8601DateTimeFromString(dateDeleted); - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The A string that uniquely identifies this Participant.. - * - * @return A string that uniquely identifies this Participant. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The Session Sid.. - * - * @return Session Sid. - */ - public final String getSessionSid() { - return this.sessionSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateDeleted; - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A human readable description of this resource.. - * - * @return A human readable description of this resource. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String friendlyName; - /** - * Returns The The phone number of this Participant.. - * - * @return The phone number of this Participant. - */ - public final String getIdentifier() { - return this.identifier; - } + @Getter + private final String identifier; - /** - * Returns The Proxy Identifier.. - * - * @return Proxy Identifier. - */ - public final String getProxyIdentifier() { - return this.proxyIdentifier; - } + @Getter + private final Map links; - /** - * Returns The Proxy Identifier Sid.. - * - * @return Proxy Identifier Sid. - */ - public final String getProxyIdentifierSid() { - return this.proxyIdentifierSid; - } + @Getter + private final String proxyIdentifier; - /** - * Returns The The date this Participant was deleted. - * - * @return The date this Participant was deleted - */ - public final DateTime getDateDeleted() { - return this.dateDeleted; - } + @Getter + private final String proxyIdentifierSid; - /** - * Returns The The date this Participant was created. - * - * @return The date this Participant was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String serviceSid; - /** - * Returns The The date this Participant was last updated. - * - * @return The date this Participant was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String sessionSid; - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String sid; - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Participant( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_deleted") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateDeleted, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identifier") final String identifier, + @JsonProperty("links") final Map links, + @JsonProperty("proxy_identifier") final String proxyIdentifier, + @JsonProperty("proxy_identifier_sid") final String proxyIdentifierSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("session_sid") final String sessionSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateDeleted = dateDeleted; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.identifier = identifier; + this.links = links; + this.proxyIdentifier = proxyIdentifier; + this.proxyIdentifierSid = proxyIdentifierSid; + this.serviceSid = serviceSid; + this.sessionSid = sessionSid; + this.sid = sid; + this.url = url; } @Override @@ -330,55 +229,39 @@ public boolean equals(final Object o) { } Participant other = (Participant) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(sessionSid, other.sessionSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(identifier, other.identifier) && - Objects.equals(proxyIdentifier, other.proxyIdentifier) && - Objects.equals(proxyIdentifierSid, other.proxyIdentifierSid) && - Objects.equals(dateDeleted, other.dateDeleted) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateDeleted, other.dateDeleted) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identifier, other.identifier) && + Objects.equals(links, other.links) && + Objects.equals(proxyIdentifier, other.proxyIdentifier) && + Objects.equals(proxyIdentifierSid, other.proxyIdentifierSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sessionSid, other.sessionSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - sessionSid, - serviceSid, - accountSid, - friendlyName, - identifier, - proxyIdentifier, - proxyIdentifierSid, - dateDeleted, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("sessionSid", sessionSid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("identifier", identifier) - .add("proxyIdentifier", proxyIdentifier) - .add("proxyIdentifierSid", proxyIdentifierSid) - .add("dateDeleted", dateDeleted) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateDeleted, + dateUpdated, + friendlyName, + identifier, + links, + proxyIdentifier, + proxyIdentifierSid, + serviceSid, + sessionSid, + sid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantCreator.java index 4a72b71f40..077af4c908 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,128 +27,156 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ParticipantCreator extends Creator { - private final String pathServiceSid; - private final String pathSessionSid; - private final String identifier; + + private String pathServiceSid; + private String pathSessionSid; + private String identifier; private String friendlyName; private String proxyIdentifier; private String proxyIdentifierSid; - /** - * Construct a new ParticipantCreator. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param identifier The phone number of this Participant. - */ - public ParticipantCreator(final String pathServiceSid, - final String pathSessionSid, - final String identifier) { + public ParticipantCreator( + final String pathServiceSid, + final String pathSessionSid, + final String identifier + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.identifier = identifier; } - /** - * A human readable description of this resource, up to 64 characters. Should - * not include PII.. - * - * @param friendlyName A human readable description of this resource. - * @return this - */ + public ParticipantCreator setIdentifier(final String identifier) { + this.identifier = identifier; + return this; + } + public ParticipantCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The proxy phone number to use for this Participant. If not specified, Proxy - * will select a number from the pool.. - * - * @param proxyIdentifier The proxy phone number to use for this Participant. - * @return this - */ public ParticipantCreator setProxyIdentifier(final String proxyIdentifier) { this.proxyIdentifier = proxyIdentifier; return this; } - /** - * The proxy_identifier_sid. - * - * @param proxyIdentifierSid The proxy_identifier_sid - * @return this - */ - public ParticipantCreator setProxyIdentifierSid(final String proxyIdentifierSid) { + public ParticipantCreator setProxyIdentifierSid( + final String proxyIdentifierSid + ) { this.proxyIdentifierSid = proxyIdentifierSid; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Participant creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Participant create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (identifier != null) { - request.addPostParam("Identifier", identifier); + Serializer.toString( + request, + "Identifier", + identifier, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (proxyIdentifier != null) { - request.addPostParam("ProxyIdentifier", proxyIdentifier); + Serializer.toString( + request, + "ProxyIdentifier", + proxyIdentifier, + ParameterType.URLENCODED + ); } if (proxyIdentifierSid != null) { - request.addPostParam("ProxyIdentifierSid", proxyIdentifierSid); + Serializer.toString( + request, + "ProxyIdentifierSid", + proxyIdentifierSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantDeleter.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantDeleter.java index fc4e83f393..be2c9066ab 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantDeleter.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,65 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ParticipantDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - /** - * Construct a new ParticipantDeleter. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - */ - public ParticipantDeleter(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { + private String pathServiceSid; + private String pathSessionSid; + private String pathSid; + + public ParticipantDeleter( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Participant delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantFetcher.java index 7d3fc5a4b9..ee842c5b2b 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ParticipantFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - /** - * Construct a new ParticipantFetcher. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - * @param pathSid A string that uniquely identifies this Participant. - */ - public ParticipantFetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { + private String pathServiceSid; + private String pathSessionSid; + private String pathSid; + + public ParticipantFetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Participant fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Participant fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Participant fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Participant.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Participant content = Participant.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantReader.java index 4c49d5798e..0a1c7a427b 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session; @@ -10,183 +17,206 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ParticipantReader extends Reader { - private final String pathServiceSid; - private final String pathSessionSid; - private String identifier; - - /** - * Construct a new ParticipantReader. - * - * @param pathServiceSid Service Sid. - * @param pathSessionSid Session Sid. - */ - public ParticipantReader(final String pathServiceSid, - final String pathSessionSid) { + + private String pathServiceSid; + private String pathSessionSid; + private Long pageSize; + + public ParticipantReader( + final String pathServiceSid, + final String pathSessionSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; } - /** - * The identifier. - * - * @param identifier The identifier - * @return this - */ - public ParticipantReader setIdentifier(final String identifier) { - this.identifier = identifier; + public ParticipantReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Participant ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Participant read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "participants", + response.getContent(), + Participant.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Participant Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Participant read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "participants", - response.getContent(), - Participant.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { - if (identifier != null) { - request.addQueryParam("Identifier", identifier); + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantUpdater.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantUpdater.java deleted file mode 100644 index 1fac81a3a5..0000000000 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/ParticipantUpdater.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / - */ - -package com.twilio.rest.proxy.v1.service.session; - -import com.twilio.base.Updater; -import com.twilio.exception.ApiConnectionException; -import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ -public class ParticipantUpdater extends Updater { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathSid; - private String identifier; - private String friendlyName; - private String proxyIdentifier; - private String proxyIdentifierSid; - - /** - * Construct a new ParticipantUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathSid The sid - */ - public ParticipantUpdater(final String pathServiceSid, - final String pathSessionSid, - final String pathSid) { - this.pathServiceSid = pathServiceSid; - this.pathSessionSid = pathSessionSid; - this.pathSid = pathSid; - } - - /** - * The identifier. - * - * @param identifier The identifier - * @return this - */ - public ParticipantUpdater setIdentifier(final String identifier) { - this.identifier = identifier; - return this; - } - - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ - public ParticipantUpdater setFriendlyName(final String friendlyName) { - this.friendlyName = friendlyName; - return this; - } - - /** - * The proxy_identifier. - * - * @param proxyIdentifier The proxy_identifier - * @return this - */ - public ParticipantUpdater setProxyIdentifier(final String proxyIdentifier) { - this.proxyIdentifier = proxyIdentifier; - return this; - } - - /** - * The proxy_identifier_sid. - * - * @param proxyIdentifierSid The proxy_identifier_sid - * @return this - */ - public ParticipantUpdater setProxyIdentifierSid(final String proxyIdentifierSid) { - this.proxyIdentifierSid = proxyIdentifierSid; - return this; - } - - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Participant - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Participant update(final TwilioRestClient client) { - Request request = new Request( - HttpMethod.POST, - Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathSid + "", - client.getRegion() - ); - - addPostParams(request); - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Participant update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); - } - - return Participant.fromJson(response.getStream(), client.getObjectMapper()); - } - - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ - private void addPostParams(final Request request) { - if (identifier != null) { - request.addPostParam("Identifier", identifier); - } - - if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); - } - - if (proxyIdentifier != null) { - request.addPostParam("ProxyIdentifier", proxyIdentifier); - } - - if (proxyIdentifierSid != null) { - request.addPostParam("ProxyIdentifierSid", proxyIdentifierSid); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteraction.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteraction.java index 7e90aefba9..c7e40eb5e6 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteraction.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteraction.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session.participant; @@ -10,37 +17,87 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class MessageInteraction extends Resource { - private static final long serialVersionUID = 180423233818859L; + + public static MessageInteractionCreator creator( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final String body + ) { + return new MessageInteractionCreator( + pathServiceSid, + pathSessionSid, + pathParticipantSid, + body + ); + } + + public static MessageInteractionCreator creator( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final List mediaUrl + ) { + return new MessageInteractionCreator( + pathServiceSid, + pathSessionSid, + pathParticipantSid, + mediaUrl + ); + } + + public static MessageInteractionFetcher fetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final String pathSid + ) { + return new MessageInteractionFetcher( + pathServiceSid, + pathSessionSid, + pathParticipantSid, + pathSid + ); + } + + public static MessageInteractionReader reader( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid + ) { + return new MessageInteractionReader( + pathServiceSid, + pathSessionSid, + pathParticipantSid + ); + } public enum Type { MESSAGE("message"), @@ -53,15 +110,11 @@ private Type(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Type from a string. - * @param value string value - * @return generated Type - */ @JsonCreator public static Type forValue(final String value) { return Promoter.enumFromString(value, Type.values()); @@ -97,15 +150,11 @@ private ResourceStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ResourceStatus from a string. - * @param value string value - * @return generated ResourceStatus - */ @JsonCreator public static ResourceStatus forValue(final String value) { return Promoter.enumFromString(value, ResourceStatus.values()); @@ -113,76 +162,16 @@ public static ResourceStatus forValue(final String value) { } /** - * Create a MessageInteractionCreator to execute create. - * - * @param pathServiceSid Service Sid - * @param pathSessionSid Session Sid - * @param pathParticipantSid Participant Sid - * @param body Message body - * @return MessageInteractionCreator capable of executing the create - */ - public static MessageInteractionCreator creator(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final String body) { - return new MessageInteractionCreator(pathServiceSid, pathSessionSid, pathParticipantSid, body); - } - - /** - * Create a MessageInteractionCreator to execute create. - * - * @param pathServiceSid Service Sid - * @param pathSessionSid Session Sid - * @param pathParticipantSid Participant Sid - * @param mediaUrl The media_url - * @return MessageInteractionCreator capable of executing the create - */ - public static MessageInteractionCreator creator(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final List mediaUrl) { - return new MessageInteractionCreator(pathServiceSid, pathSessionSid, pathParticipantSid, mediaUrl); - } - - /** - * Create a MessageInteractionFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathParticipantSid The participant_sid - * @param pathSid The sid - * @return MessageInteractionFetcher capable of executing the fetch - */ - public static MessageInteractionFetcher fetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final String pathSid) { - return new MessageInteractionFetcher(pathServiceSid, pathSessionSid, pathParticipantSid, pathSid); - } - - /** - * Create a MessageInteractionReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathParticipantSid The participant_sid - * @return MessageInteractionReader capable of executing the read - */ - public static MessageInteractionReader reader(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid) { - return new MessageInteractionReader(pathServiceSid, pathSessionSid, pathParticipantSid); - } - - /** - * Converts a JSON String into a MessageInteraction object using the provided - * ObjectMapper. - * + * Converts a JSON String into a MessageInteraction object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return MessageInteraction object represented by the provided JSON */ - public static MessageInteraction fromJson(final String json, final ObjectMapper objectMapper) { + public static MessageInteraction fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MessageInteraction.class); @@ -194,14 +183,17 @@ public static MessageInteraction fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a MessageInteraction object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a MessageInteraction object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return MessageInteraction object represented by the provided JSON */ - public static MessageInteraction fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static MessageInteraction fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, MessageInteraction.class); @@ -212,75 +204,125 @@ public static MessageInteraction fromJson(final InputStream json, final ObjectMa } } - private final String sid; - private final String sessionSid; - private final String serviceSid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String data; - private final MessageInteraction.Type type; - private final String participantSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String inboundParticipantSid; + + @Getter private final String inboundResourceSid; + + @Getter private final MessageInteraction.ResourceStatus inboundResourceStatus; + + @Getter private final String inboundResourceType; + + @Getter private final URI inboundResourceUrl; + + @Getter private final String outboundParticipantSid; + + @Getter private final String outboundResourceSid; + + @Getter private final MessageInteraction.ResourceStatus outboundResourceStatus; + + @Getter private final String outboundResourceType; + + @Getter private final URI outboundResourceUrl; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String participantSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sessionSid; + + @Getter + private final String sid; + + @Getter + private final MessageInteraction.Type type; + + @Getter private final URI url; @JsonCreator - private MessageInteraction(@JsonProperty("sid") - final String sid, - @JsonProperty("session_sid") - final String sessionSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("data") - final String data, - @JsonProperty("type") - final MessageInteraction.Type type, - @JsonProperty("participant_sid") - final String participantSid, - @JsonProperty("inbound_participant_sid") - final String inboundParticipantSid, - @JsonProperty("inbound_resource_sid") - final String inboundResourceSid, - @JsonProperty("inbound_resource_status") - final MessageInteraction.ResourceStatus inboundResourceStatus, - @JsonProperty("inbound_resource_type") - final String inboundResourceType, - @JsonProperty("inbound_resource_url") - final URI inboundResourceUrl, - @JsonProperty("outbound_participant_sid") - final String outboundParticipantSid, - @JsonProperty("outbound_resource_sid") - final String outboundResourceSid, - @JsonProperty("outbound_resource_status") - final MessageInteraction.ResourceStatus outboundResourceStatus, - @JsonProperty("outbound_resource_type") - final String outboundResourceType, - @JsonProperty("outbound_resource_url") - final URI outboundResourceUrl, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.sid = sid; - this.sessionSid = sessionSid; - this.serviceSid = serviceSid; + private MessageInteraction( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("data") final String data, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "inbound_participant_sid" + ) final String inboundParticipantSid, + @JsonProperty("inbound_resource_sid") final String inboundResourceSid, + @JsonProperty( + "inbound_resource_status" + ) final MessageInteraction.ResourceStatus inboundResourceStatus, + @JsonProperty("inbound_resource_type") final String inboundResourceType, + @JsonProperty("inbound_resource_url") final URI inboundResourceUrl, + @JsonProperty( + "outbound_participant_sid" + ) final String outboundParticipantSid, + @JsonProperty("outbound_resource_sid") final String outboundResourceSid, + @JsonProperty( + "outbound_resource_status" + ) final MessageInteraction.ResourceStatus outboundResourceStatus, + @JsonProperty( + "outbound_resource_type" + ) final String outboundResourceType, + @JsonProperty("outbound_resource_url") final URI outboundResourceUrl, + @JsonProperty("participant_sid") final String participantSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("session_sid") final String sessionSid, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final MessageInteraction.Type type, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.data = data; - this.type = type; - this.participantSid = participantSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.inboundParticipantSid = inboundParticipantSid; this.inboundResourceSid = inboundResourceSid; this.inboundResourceStatus = inboundResourceStatus; @@ -291,191 +333,14 @@ private MessageInteraction(@JsonProperty("sid") this.outboundResourceStatus = outboundResourceStatus; this.outboundResourceType = outboundResourceType; this.outboundResourceUrl = outboundResourceUrl; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.participantSid = participantSid; + this.serviceSid = serviceSid; + this.sessionSid = sessionSid; + this.sid = sid; + this.type = type; this.url = url; } - /** - * Returns The A string that uniquely identifies this Message Interaction.. - * - * @return A string that uniquely identifies this Message Interaction. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Session Sid.. - * - * @return Session Sid. - */ - public final String getSessionSid() { - return this.sessionSid; - } - - /** - * Returns The Service Sid.. - * - * @return Service Sid. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Account Sid.. - * - * @return Account Sid. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Message body. - * - * @return Message body - */ - public final String getData() { - return this.data; - } - - /** - * Returns The The Type of this Message Interaction. - * - * @return The Type of this Message Interaction - */ - public final MessageInteraction.Type getType() { - return this.type; - } - - /** - * Returns The Participant Sid.. - * - * @return Participant Sid. - */ - public final String getParticipantSid() { - return this.participantSid; - } - - /** - * Returns The Always empty for Message Interactions.. - * - * @return Always empty for Message Interactions. - */ - public final String getInboundParticipantSid() { - return this.inboundParticipantSid; - } - - /** - * Returns The Always empty for Message Interactions.. - * - * @return Always empty for Message Interactions. - */ - public final String getInboundResourceSid() { - return this.inboundResourceSid; - } - - /** - * Returns The Always empty for Message Interactions.. - * - * @return Always empty for Message Interactions. - */ - public final MessageInteraction.ResourceStatus getInboundResourceStatus() { - return this.inboundResourceStatus; - } - - /** - * Returns The Always empty for Message Interactions.. - * - * @return Always empty for Message Interactions. - */ - public final String getInboundResourceType() { - return this.inboundResourceType; - } - - /** - * Returns The Always empty for Message Interactions.. - * - * @return Always empty for Message Interactions. - */ - public final URI getInboundResourceUrl() { - return this.inboundResourceUrl; - } - - /** - * Returns The Outbound Participant Sid.. - * - * @return Outbound Participant Sid. - */ - public final String getOutboundParticipantSid() { - return this.outboundParticipantSid; - } - - /** - * Returns The Outbound message resource Sid.. - * - * @return Outbound message resource Sid. - */ - public final String getOutboundResourceSid() { - return this.outboundResourceSid; - } - - /** - * Returns The The Outbound Resource Status of this Message Interaction. - * - * @return The Outbound Resource Status of this Message Interaction - */ - public final MessageInteraction.ResourceStatus getOutboundResourceStatus() { - return this.outboundResourceStatus; - } - - /** - * Returns The Message. - * - * @return Message - */ - public final String getOutboundResourceType() { - return this.outboundResourceType; - } - - /** - * Returns The The URL of the Twilio message resource.. - * - * @return The URL of the Twilio message resource. - */ - public final URI getOutboundResourceUrl() { - return this.outboundResourceUrl; - } - - /** - * Returns The The date this Message Interaction was created. - * - * @return The date this Message Interaction was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Message Interaction was last updated. - * - * @return The date this Message Interaction was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The URL of this resource.. - * - * @return The URL of this resource. - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -487,76 +352,65 @@ public boolean equals(final Object o) { } MessageInteraction other = (MessageInteraction) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(sessionSid, other.sessionSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(data, other.data) && - Objects.equals(type, other.type) && - Objects.equals(participantSid, other.participantSid) && - Objects.equals(inboundParticipantSid, other.inboundParticipantSid) && - Objects.equals(inboundResourceSid, other.inboundResourceSid) && - Objects.equals(inboundResourceStatus, other.inboundResourceStatus) && - Objects.equals(inboundResourceType, other.inboundResourceType) && - Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && - Objects.equals(outboundParticipantSid, other.outboundParticipantSid) && - Objects.equals(outboundResourceSid, other.outboundResourceSid) && - Objects.equals(outboundResourceStatus, other.outboundResourceStatus) && - Objects.equals(outboundResourceType, other.outboundResourceType) && - Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + inboundParticipantSid, + other.inboundParticipantSid + ) && + Objects.equals(inboundResourceSid, other.inboundResourceSid) && + Objects.equals( + inboundResourceStatus, + other.inboundResourceStatus + ) && + Objects.equals(inboundResourceType, other.inboundResourceType) && + Objects.equals(inboundResourceUrl, other.inboundResourceUrl) && + Objects.equals( + outboundParticipantSid, + other.outboundParticipantSid + ) && + Objects.equals(outboundResourceSid, other.outboundResourceSid) && + Objects.equals( + outboundResourceStatus, + other.outboundResourceStatus + ) && + Objects.equals(outboundResourceType, other.outboundResourceType) && + Objects.equals(outboundResourceUrl, other.outboundResourceUrl) && + Objects.equals(participantSid, other.participantSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sessionSid, other.sessionSid) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - sessionSid, - serviceSid, - accountSid, - data, - type, - participantSid, - inboundParticipantSid, - inboundResourceSid, - inboundResourceStatus, - inboundResourceType, - inboundResourceUrl, - outboundParticipantSid, - outboundResourceSid, - outboundResourceStatus, - outboundResourceType, - outboundResourceUrl, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("sessionSid", sessionSid) - .add("serviceSid", serviceSid) - .add("accountSid", accountSid) - .add("data", data) - .add("type", type) - .add("participantSid", participantSid) - .add("inboundParticipantSid", inboundParticipantSid) - .add("inboundResourceSid", inboundResourceSid) - .add("inboundResourceStatus", inboundResourceStatus) - .add("inboundResourceType", inboundResourceType) - .add("inboundResourceUrl", inboundResourceUrl) - .add("outboundParticipantSid", outboundParticipantSid) - .add("outboundResourceSid", outboundResourceSid) - .add("outboundResourceStatus", outboundResourceStatus) - .add("outboundResourceType", outboundResourceType) - .add("outboundResourceUrl", outboundResourceUrl) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + data, + dateCreated, + dateUpdated, + inboundParticipantSid, + inboundResourceSid, + inboundResourceStatus, + inboundResourceType, + inboundResourceUrl, + outboundParticipantSid, + outboundResourceSid, + outboundResourceStatus, + outboundResourceType, + outboundResourceUrl, + participantSid, + serviceSid, + sessionSid, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionCreator.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionCreator.java index 8a97a2b03c..277cb76605 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionCreator.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session.participant; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,152 +28,156 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class MessageInteractionCreator extends Creator { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathParticipantSid; + + private String pathServiceSid; + private String pathSessionSid; + private String pathParticipantSid; private String body; private List mediaUrl; - /** - * Construct a new MessageInteractionCreator. - * - * @param pathServiceSid Service Sid - * @param pathSessionSid Session Sid - * @param pathParticipantSid Participant Sid - * @param body Message body - */ - public MessageInteractionCreator(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final String body) { + public MessageInteractionCreator( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final String body + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathParticipantSid = pathParticipantSid; this.body = body; } - /** - * Construct a new MessageInteractionCreator. - * - * @param pathServiceSid Service Sid - * @param pathSessionSid Session Sid - * @param pathParticipantSid Participant Sid - * @param mediaUrl The media_url - */ - public MessageInteractionCreator(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final List mediaUrl) { + public MessageInteractionCreator( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final List mediaUrl + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathParticipantSid = pathParticipantSid; this.mediaUrl = mediaUrl; } - /** - * The message to send to the participant. - * - * @param body Message body - * @return this - */ public MessageInteractionCreator setBody(final String body) { this.body = body; return this; } - /** - * The media_url. - * - * @param mediaUrl The media_url - * @return this - */ public MessageInteractionCreator setMediaUrl(final List mediaUrl) { this.mediaUrl = mediaUrl; return this; } - /** - * The media_url. - * - * @param mediaUrl The media_url - * @return this - */ public MessageInteractionCreator setMediaUrl(final URI mediaUrl) { return setMediaUrl(Promoter.listOfOne(mediaUrl)); } - /** - * The media_url. - * - * @param mediaUrl The media_url - * @return this - */ public MessageInteractionCreator setMediaUrl(final String mediaUrl) { return setMediaUrl(Promoter.uriFromString(mediaUrl)); } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created MessageInteraction - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public MessageInteraction create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathParticipantSid + "/MessageInteractions", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MessageInteraction creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "MessageInteraction creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return MessageInteraction.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public MessageInteraction create(final TwilioRestClient client) { + Response response = makeRequest(client); + return MessageInteraction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + MessageInteraction content = MessageInteraction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (body != null) { - request.addPostParam("Body", body); + Serializer.toString( + request, + "Body", + body, + ParameterType.URLENCODED + ); } if (mediaUrl != null) { - for (URI prop : mediaUrl) { - request.addPostParam("MediaUrl", prop.toString()); + for (URI param : mediaUrl) { + Serializer.toString( + request, + "MediaUrl", + param, + ParameterType.URLENCODED + ); } } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionFetcher.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionFetcher.java index 0dc093223c..c1d382036f 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionFetcher.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session.participant; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,70 +24,100 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class MessageInteractionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathParticipantSid; - private final String pathSid; - /** - * Construct a new MessageInteractionFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathParticipantSid The participant_sid - * @param pathSid The sid - */ - public MessageInteractionFetcher(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid, - final String pathSid) { + private String pathServiceSid; + private String pathSessionSid; + private String pathParticipantSid; + private String pathSid; + + public MessageInteractionFetcher( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathParticipantSid = pathParticipantSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched MessageInteraction - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public MessageInteraction fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathParticipantSid + "/MessageInteractions/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("MessageInteraction fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "MessageInteraction fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return MessageInteraction.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public MessageInteraction fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return MessageInteraction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + MessageInteraction content = MessageInteraction.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionReader.java b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionReader.java index dc86388b15..f1eca18422 100644 --- a/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionReader.java +++ b/src/main/java/com/twilio/rest/proxy/v1/service/session/participant/MessageInteractionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Proxy + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.proxy.v1.service.session.participant; @@ -10,171 +17,214 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class MessageInteractionReader extends Reader { - private final String pathServiceSid; - private final String pathSessionSid; - private final String pathParticipantSid; - - /** - * Construct a new MessageInteractionReader. - * - * @param pathServiceSid The service_sid - * @param pathSessionSid The session_sid - * @param pathParticipantSid The participant_sid - */ - public MessageInteractionReader(final String pathServiceSid, - final String pathSessionSid, - final String pathParticipantSid) { + + private String pathServiceSid; + private String pathSessionSid; + private String pathParticipantSid; + private Long pageSize; + + public MessageInteractionReader( + final String pathServiceSid, + final String pathSessionSid, + final String pathParticipantSid + ) { this.pathServiceSid = pathServiceSid; this.pathSessionSid = pathSessionSid; this.pathParticipantSid = pathParticipantSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return MessageInteraction ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public MessageInteractionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return MessageInteraction ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "interactions", + response.getContent(), + MessageInteraction.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Sessions/{SessionSid}/Participants/{ParticipantSid}/MessageInteractions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "SessionSid" + "}", + this.pathSessionSid.toString() + ); + path = + path.replace( + "{" + "ParticipantSid" + "}", + this.pathParticipantSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.PROXY.toString(), - "/v1/Services/" + this.pathServiceSid + "/Sessions/" + this.pathSessionSid + "/Participants/" + this.pathParticipantSid + "/MessageInteractions", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return MessageInteraction ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "interactions", + response.getContent(), + MessageInteraction.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "MessageInteraction read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "interactions", + response.getContent(), + MessageInteraction.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.PROXY.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of MessageInteraction Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("MessageInteraction read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "interactions", - response.getContent(), - MessageInteraction.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/routes/v2/PhoneNumber.java b/src/main/java/com/twilio/rest/routes/v2/PhoneNumber.java new file mode 100644 index 0000000000..a4da81f6fb --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/PhoneNumber.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PhoneNumber extends Resource { + + public static PhoneNumberFetcher fetcher(final String pathPhoneNumber) { + return new PhoneNumberFetcher(pathPhoneNumber); + } + + public static PhoneNumberUpdater updater(final String pathPhoneNumber) { + return new PhoneNumberUpdater(pathPhoneNumber); + } + + /** + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PhoneNumber.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PhoneNumber.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String phoneNumber; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final String voiceRegion; + + @JsonCreator + private PhoneNumber( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("phone_number") final String phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("voice_region") final String voiceRegion + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.phoneNumber = phoneNumber; + this.sid = sid; + this.url = url; + this.voiceRegion = voiceRegion; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + PhoneNumber other = (PhoneNumber) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(voiceRegion, other.voiceRegion) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + phoneNumber, + sid, + url, + voiceRegion + ); + } +} diff --git a/src/main/java/com/twilio/rest/routes/v2/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/routes/v2/PhoneNumberFetcher.java new file mode 100644 index 0000000000..f18e9b8c0f --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/PhoneNumberFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PhoneNumberFetcher extends Fetcher { + + private String pathPhoneNumber; + + public PhoneNumberFetcher(final String pathPhoneNumber) { + this.pathPhoneNumber = pathPhoneNumber; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/PhoneNumbers/{PhoneNumber}"; + + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.ROUTES.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PhoneNumber fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/routes/v2/PhoneNumberUpdater.java b/src/main/java/com/twilio/rest/routes/v2/PhoneNumberUpdater.java new file mode 100644 index 0000000000..f973820069 --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/PhoneNumberUpdater.java @@ -0,0 +1,137 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PhoneNumberUpdater extends Updater { + + private String pathPhoneNumber; + private String voiceRegion; + private String friendlyName; + + public PhoneNumberUpdater(final String pathPhoneNumber) { + this.pathPhoneNumber = pathPhoneNumber; + } + + public PhoneNumberUpdater setVoiceRegion(final String voiceRegion) { + this.voiceRegion = voiceRegion; + return this; + } + + public PhoneNumberUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/PhoneNumbers/{PhoneNumber}"; + + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ROUTES.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PhoneNumber update(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (voiceRegion != null) { + Serializer.toString( + request, + "VoiceRegion", + voiceRegion, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/routes/v2/SipDomain.java b/src/main/java/com/twilio/rest/routes/v2/SipDomain.java new file mode 100644 index 0000000000..d2d2bbe8dd --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/SipDomain.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SipDomain extends Resource { + + public static SipDomainFetcher fetcher(final String pathSipDomain) { + return new SipDomainFetcher(pathSipDomain); + } + + public static SipDomainUpdater updater(final String pathSipDomain) { + return new SipDomainUpdater(pathSipDomain); + } + + /** + * Converts a JSON String into a SipDomain object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SipDomain object represented by the provided JSON + */ + public static SipDomain fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SipDomain.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SipDomain object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SipDomain object represented by the provided JSON + */ + public static SipDomain fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SipDomain.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @Getter + private final String sipDomain; + + @Getter + private final URI url; + + @Getter + private final String voiceRegion; + + @JsonCreator + private SipDomain( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("sip_domain") final String sipDomain, + @JsonProperty("url") final URI url, + @JsonProperty("voice_region") final String voiceRegion + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; + this.sipDomain = sipDomain; + this.url = url; + this.voiceRegion = voiceRegion; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SipDomain other = (SipDomain) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(sipDomain, other.sipDomain) && + Objects.equals(url, other.url) && + Objects.equals(voiceRegion, other.voiceRegion) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + sipDomain, + url, + voiceRegion + ); + } +} diff --git a/src/main/java/com/twilio/rest/routes/v2/SipDomainFetcher.java b/src/main/java/com/twilio/rest/routes/v2/SipDomainFetcher.java new file mode 100644 index 0000000000..0f49b89533 --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/SipDomainFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SipDomainFetcher extends Fetcher { + + private String pathSipDomain; + + public SipDomainFetcher(final String pathSipDomain) { + this.pathSipDomain = pathSipDomain; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/SipDomains/{SipDomain}"; + + path = + path.replace( + "{" + "SipDomain" + "}", + this.pathSipDomain.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.ROUTES.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SipDomain fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SipDomain fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SipDomain.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SipDomain content = SipDomain.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/routes/v2/SipDomainUpdater.java b/src/main/java/com/twilio/rest/routes/v2/SipDomainUpdater.java new file mode 100644 index 0000000000..74e90658b9 --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/SipDomainUpdater.java @@ -0,0 +1,137 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SipDomainUpdater extends Updater { + + private String pathSipDomain; + private String voiceRegion; + private String friendlyName; + + public SipDomainUpdater(final String pathSipDomain) { + this.pathSipDomain = pathSipDomain; + } + + public SipDomainUpdater setVoiceRegion(final String voiceRegion) { + this.voiceRegion = voiceRegion; + return this; + } + + public SipDomainUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/SipDomains/{SipDomain}"; + + path = + path.replace( + "{" + "SipDomain" + "}", + this.pathSipDomain.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ROUTES.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SipDomain update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SipDomain update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SipDomain.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SipDomain content = SipDomain.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (voiceRegion != null) { + Serializer.toString( + request, + "VoiceRegion", + voiceRegion, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/routes/v2/Trunk.java b/src/main/java/com/twilio/rest/routes/v2/Trunk.java new file mode 100644 index 0000000000..dde16e4955 --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/Trunk.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Trunk extends Resource { + + public static TrunkFetcher fetcher(final String pathSipTrunkDomain) { + return new TrunkFetcher(pathSipTrunkDomain); + } + + public static TrunkUpdater updater(final String pathSipTrunkDomain) { + return new TrunkUpdater(pathSipTrunkDomain); + } + + /** + * Converts a JSON String into a Trunk object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Trunk object represented by the provided JSON + */ + public static Trunk fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Trunk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Trunk object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Trunk object represented by the provided JSON + */ + public static Trunk fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Trunk.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @Getter + private final String sipTrunkDomain; + + @Getter + private final URI url; + + @Getter + private final String voiceRegion; + + @JsonCreator + private Trunk( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("sip_trunk_domain") final String sipTrunkDomain, + @JsonProperty("url") final URI url, + @JsonProperty("voice_region") final String voiceRegion + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; + this.sipTrunkDomain = sipTrunkDomain; + this.url = url; + this.voiceRegion = voiceRegion; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Trunk other = (Trunk) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(sipTrunkDomain, other.sipTrunkDomain) && + Objects.equals(url, other.url) && + Objects.equals(voiceRegion, other.voiceRegion) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + sipTrunkDomain, + url, + voiceRegion + ); + } +} diff --git a/src/main/java/com/twilio/rest/routes/v2/TrunkFetcher.java b/src/main/java/com/twilio/rest/routes/v2/TrunkFetcher.java new file mode 100644 index 0000000000..ce73d2c4fb --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/TrunkFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrunkFetcher extends Fetcher { + + private String pathSipTrunkDomain; + + public TrunkFetcher(final String pathSipTrunkDomain) { + this.pathSipTrunkDomain = pathSipTrunkDomain; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Trunks/{SipTrunkDomain}"; + + path = + path.replace( + "{" + "SipTrunkDomain" + "}", + this.pathSipTrunkDomain.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.ROUTES.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Trunk fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Trunk fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Trunk.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Trunk content = Trunk.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/routes/v2/TrunkUpdater.java b/src/main/java/com/twilio/rest/routes/v2/TrunkUpdater.java new file mode 100644 index 0000000000..d41e9ef012 --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v2/TrunkUpdater.java @@ -0,0 +1,134 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrunkUpdater extends Updater { + + private String pathSipTrunkDomain; + private String voiceRegion; + private String friendlyName; + + public TrunkUpdater(final String pathSipTrunkDomain) { + this.pathSipTrunkDomain = pathSipTrunkDomain; + } + + public TrunkUpdater setVoiceRegion(final String voiceRegion) { + this.voiceRegion = voiceRegion; + return this; + } + + public TrunkUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Trunks/{SipTrunkDomain}"; + + path = + path.replace( + "{" + "SipTrunkDomain" + "}", + this.pathSipTrunkDomain.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ROUTES.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Trunk update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Trunk update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Trunk.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Trunk content = Trunk.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (voiceRegion != null) { + Serializer.toString( + request, + "VoiceRegion", + voiceRegion, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/routes/v3/IsoCountryCode.java b/src/main/java/com/twilio/rest/routes/v3/IsoCountryCode.java new file mode 100644 index 0000000000..326cf6b71c --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v3/IsoCountryCode.java @@ -0,0 +1,499 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class IsoCountryCode extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreateIsoCountryCodeResponse extends Resource { + + @JsonCreator + private CreateIsoCountryCodeResponse() {} + + public static CreateIsoCountryCodeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreateIsoCountryCodeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreateIsoCountryCodeResponse other = + (CreateIsoCountryCodeResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdateIsoCountryCodeResponse extends Resource { + + @Getter + private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String isoCountryCode; + + @Getter + private final String messagingRegion; + + @Getter + private final String shortCode; + + @Getter + private final URI url; + + @JsonCreator + private UpdateIsoCountryCodeResponse( + @JsonProperty("accountSid") final String accountSid, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated, + @JsonProperty("friendlyName") final String friendlyName, + @JsonProperty("isoCountryCode") final String isoCountryCode, + @JsonProperty("messagingRegion") final String messagingRegion, + @JsonProperty("shortCode") final String shortCode, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.isoCountryCode = isoCountryCode; + this.messagingRegion = messagingRegion; + this.shortCode = shortCode; + this.url = url; + } + + public static UpdateIsoCountryCodeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdateIsoCountryCodeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateIsoCountryCodeResponse other = + (UpdateIsoCountryCodeResponse) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountryCode, other.isoCountryCode) && + Objects.equals(messagingRegion, other.messagingRegion) && + Objects.equals(shortCode, other.shortCode) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + isoCountryCode, + messagingRegion, + shortCode, + url + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeleteIsoCountryCodeResponse extends Resource { + + @JsonCreator + private DeleteIsoCountryCodeResponse() {} + + public static DeleteIsoCountryCodeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeleteIsoCountryCodeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeleteIsoCountryCodeResponse other = + (DeleteIsoCountryCodeResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListIsoCountryCodeResponse extends Resource { + + @JsonCreator + private ListIsoCountryCodeResponse() {} + + public static ListIsoCountryCodeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListIsoCountryCodeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListIsoCountryCodeResponse other = (ListIsoCountryCodeResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchIsoCountryCodeResponse extends Resource { + + @JsonCreator + private PatchIsoCountryCodeResponse() {} + + public static PatchIsoCountryCodeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchIsoCountryCodeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchIsoCountryCodeResponse other = (PatchIsoCountryCodeResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchIsoCountryCodeResponse extends Resource { + + @Getter + private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String isoCountryCode; + + @Getter + private final String messagingRegion; + + @Getter + private final String shortCode; + + @Getter + private final URI url; + + @JsonCreator + private FetchIsoCountryCodeResponse( + @JsonProperty("accountSid") final String accountSid, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated, + @JsonProperty("friendlyName") final String friendlyName, + @JsonProperty("isoCountryCode") final String isoCountryCode, + @JsonProperty("messagingRegion") final String messagingRegion, + @JsonProperty("shortCode") final String shortCode, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.isoCountryCode = isoCountryCode; + this.messagingRegion = messagingRegion; + this.shortCode = shortCode; + this.url = url; + } + + public static FetchIsoCountryCodeResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchIsoCountryCodeResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchIsoCountryCodeResponse other = (FetchIsoCountryCodeResponse) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(isoCountryCode, other.isoCountryCode) && + Objects.equals(messagingRegion, other.messagingRegion) && + Objects.equals(shortCode, other.shortCode) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + isoCountryCode, + messagingRegion, + shortCode, + url + ); + } + } + + public static IsoCountryCodeFetcher fetcher( + final String pathIsoCountryCode, + final String pathShortCode + ) { + return new IsoCountryCodeFetcher(pathIsoCountryCode, pathShortCode); + } + + public static IsoCountryCodeUpdater updater( + final String pathIsoCountryCode, + final String pathShortCode + ) { + return new IsoCountryCodeUpdater(pathIsoCountryCode, pathShortCode); + } + + /** + * Converts a JSON String into a IsoCountryCode object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IsoCountryCode object represented by the provided JSON + */ + public static IsoCountryCode fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, IsoCountryCode.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a IsoCountryCode object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IsoCountryCode object represented by the provided JSON + */ + public static IsoCountryCode fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, IsoCountryCode.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private IsoCountryCode() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/routes/v3/IsoCountryCodeFetcher.java b/src/main/java/com/twilio/rest/routes/v3/IsoCountryCodeFetcher.java new file mode 100644 index 0000000000..2139a05713 --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v3/IsoCountryCodeFetcher.java @@ -0,0 +1,114 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IsoCountryCodeFetcher + extends Fetcher { + + private String pathIsoCountryCode; + private String pathShortCode; + + public IsoCountryCodeFetcher( + final String pathIsoCountryCode, + final String pathShortCode + ) { + this.pathIsoCountryCode = pathIsoCountryCode; + this.pathShortCode = pathShortCode; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ShortCodes/{isoCountryCode}/{shortCode}"; + + path = + path.replace( + "{" + "isoCountryCode" + "}", + this.pathIsoCountryCode.toString() + ); + path = + path.replace( + "{" + "shortCode" + "}", + this.pathShortCode.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.ROUTES.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "IsoCountryCode fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public IsoCountryCode.FetchIsoCountryCodeResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return IsoCountryCode.FetchIsoCountryCodeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + IsoCountryCode.FetchIsoCountryCodeResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + IsoCountryCode.FetchIsoCountryCodeResponse content = + IsoCountryCode.FetchIsoCountryCodeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/routes/v3/IsoCountryCodeUpdater.java b/src/main/java/com/twilio/rest/routes/v3/IsoCountryCodeUpdater.java new file mode 100644 index 0000000000..1632238d52 --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v3/IsoCountryCodeUpdater.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v3; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IsoCountryCodeUpdater + extends Updater { + + private String pathIsoCountryCode; + private String pathShortCode; + private String messagingRegion; + private String friendlyName; + + public IsoCountryCodeUpdater( + final String pathIsoCountryCode, + final String pathShortCode + ) { + this.pathIsoCountryCode = pathIsoCountryCode; + this.pathShortCode = pathShortCode; + } + + public IsoCountryCodeUpdater setMessagingRegion( + final String messagingRegion + ) { + this.messagingRegion = messagingRegion; + return this; + } + + public IsoCountryCodeUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/ShortCodes/{isoCountryCode}/{shortCode}"; + + path = + path.replace( + "{" + "isoCountryCode" + "}", + this.pathIsoCountryCode.toString() + ); + path = + path.replace( + "{" + "shortCode" + "}", + this.pathShortCode.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ROUTES.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "IsoCountryCode update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public IsoCountryCode.UpdateIsoCountryCodeResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return IsoCountryCode.UpdateIsoCountryCodeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + IsoCountryCode.UpdateIsoCountryCodeResponse + > updateWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + IsoCountryCode.UpdateIsoCountryCodeResponse content = + IsoCountryCode.UpdateIsoCountryCodeResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (messagingRegion != null) { + Serializer.toString( + request, + "messagingRegion", + messagingRegion, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "friendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/routes/v3/PhoneNumber.java b/src/main/java/com/twilio/rest/routes/v3/PhoneNumber.java new file mode 100644 index 0000000000..173601a22b --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v3/PhoneNumber.java @@ -0,0 +1,490 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v3; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class PhoneNumber extends Resource { + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class CreatePhoneNumberResponse extends Resource { + + @JsonCreator + private CreatePhoneNumberResponse() {} + + public static CreatePhoneNumberResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CreatePhoneNumberResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + CreatePhoneNumberResponse other = (CreatePhoneNumberResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class UpdatePhoneNumberResponse extends Resource { + + @Getter + private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String messagingRegion; + + @Getter + private final String phoneNumber; + + @Getter + private final URI url; + + @Getter + private final String voiceRegion; + + @JsonCreator + private UpdatePhoneNumberResponse( + @JsonProperty("accountSid") final String accountSid, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated, + @JsonProperty("friendlyName") final String friendlyName, + @JsonProperty("messagingRegion") final String messagingRegion, + @JsonProperty("phoneNumber") final String phoneNumber, + @JsonProperty("url") final URI url, + @JsonProperty("voiceRegion") final String voiceRegion + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.messagingRegion = messagingRegion; + this.phoneNumber = phoneNumber; + this.url = url; + this.voiceRegion = voiceRegion; + } + + public static UpdatePhoneNumberResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + UpdatePhoneNumberResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdatePhoneNumberResponse other = (UpdatePhoneNumberResponse) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(messagingRegion, other.messagingRegion) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(url, other.url) && + Objects.equals(voiceRegion, other.voiceRegion) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + messagingRegion, + phoneNumber, + url, + voiceRegion + ); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class DeletePhoneNumberResponse extends Resource { + + @JsonCreator + private DeletePhoneNumberResponse() {} + + public static DeletePhoneNumberResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + DeletePhoneNumberResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + DeletePhoneNumberResponse other = (DeletePhoneNumberResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class ListPhoneNumberResponse extends Resource { + + @JsonCreator + private ListPhoneNumberResponse() {} + + public static ListPhoneNumberResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ListPhoneNumberResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + ListPhoneNumberResponse other = (ListPhoneNumberResponse) o; + return (true); + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class PatchPhoneNumberResponse extends Resource { + + @JsonCreator + private PatchPhoneNumberResponse() {} + + public static PatchPhoneNumberResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + PatchPhoneNumberResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + PatchPhoneNumberResponse other = (PatchPhoneNumberResponse) o; + return true; + } + + @Override + public int hashCode() { + return Objects.hash(); + } + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class FetchPhoneNumberResponse extends Resource { + + @Getter + private final String accountSid; + + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String messagingRegion; + + @Getter + private final String phoneNumber; + + @Getter + private final URI url; + + @Getter + private final String voiceRegion; + + @JsonCreator + private FetchPhoneNumberResponse( + @JsonProperty("accountSid") final String accountSid, + @JsonProperty("dateCreated") final ZonedDateTime dateCreated, + @JsonProperty("dateUpdated") final ZonedDateTime dateUpdated, + @JsonProperty("friendlyName") final String friendlyName, + @JsonProperty("messagingRegion") final String messagingRegion, + @JsonProperty("phoneNumber") final String phoneNumber, + @JsonProperty("url") final URI url, + @JsonProperty("voiceRegion") final String voiceRegion + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.messagingRegion = messagingRegion; + this.phoneNumber = phoneNumber; + this.url = url; + this.voiceRegion = voiceRegion; + } + + public static FetchPhoneNumberResponse fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + FetchPhoneNumberResponse.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + FetchPhoneNumberResponse other = (FetchPhoneNumberResponse) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(messagingRegion, other.messagingRegion) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(url, other.url) && + Objects.equals(voiceRegion, other.voiceRegion) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + messagingRegion, + phoneNumber, + url, + voiceRegion + ); + } + } + + public static PhoneNumberFetcher fetcher(final String pathPhoneNumber) { + return new PhoneNumberFetcher(pathPhoneNumber); + } + + public static PhoneNumberUpdater updater(final String pathPhoneNumber) { + return new PhoneNumberUpdater(pathPhoneNumber); + } + + /** + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PhoneNumber.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a PhoneNumber object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return PhoneNumber object represented by the provided JSON + */ + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, PhoneNumber.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonCreator + private PhoneNumber() {} + + @Override + public boolean equals(Object obj) { + return obj != null && obj.getClass() == this.getClass(); + } + + @Override + public int hashCode() { + return 1; + } +} diff --git a/src/main/java/com/twilio/rest/routes/v3/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/routes/v3/PhoneNumberFetcher.java new file mode 100644 index 0000000000..3d746326ed --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v3/PhoneNumberFetcher.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v3; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PhoneNumberFetcher + extends Fetcher { + + private String pathPhoneNumber; + + public PhoneNumberFetcher(final String pathPhoneNumber) { + this.pathPhoneNumber = pathPhoneNumber; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/PhoneNumbers/{phoneNumber}"; + + path = + path.replace( + "{" + "phoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.ROUTES.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PhoneNumber.FetchPhoneNumberResponse fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return PhoneNumber.FetchPhoneNumberResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + PhoneNumber.FetchPhoneNumberResponse + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + PhoneNumber.FetchPhoneNumberResponse content = + PhoneNumber.FetchPhoneNumberResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/routes/v3/PhoneNumberUpdater.java b/src/main/java/com/twilio/rest/routes/v3/PhoneNumberUpdater.java new file mode 100644 index 0000000000..29286673fb --- /dev/null +++ b/src/main/java/com/twilio/rest/routes/v3/PhoneNumberUpdater.java @@ -0,0 +1,156 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Routes + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.routes.v3; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PhoneNumberUpdater + extends Updater { + + private String pathPhoneNumber; + private String voiceRegion; + private String messagingRegion; + private String friendlyName; + + public PhoneNumberUpdater(final String pathPhoneNumber) { + this.pathPhoneNumber = pathPhoneNumber; + } + + public PhoneNumberUpdater setVoiceRegion(final String voiceRegion) { + this.voiceRegion = voiceRegion; + return this; + } + + public PhoneNumberUpdater setMessagingRegion(final String messagingRegion) { + this.messagingRegion = messagingRegion; + return this; + } + + public PhoneNumberUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v3/PhoneNumbers/{phoneNumber}"; + + path = + path.replace( + "{" + "phoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.ROUTES.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public PhoneNumber.UpdatePhoneNumberResponse update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return PhoneNumber.UpdatePhoneNumberResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + PhoneNumber.UpdatePhoneNumberResponse + > updateWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + PhoneNumber.UpdatePhoneNumberResponse content = + PhoneNumber.UpdatePhoneNumberResponse.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (voiceRegion != null) { + Serializer.toString( + request, + "voiceRegion", + voiceRegion, + ParameterType.URLENCODED + ); + } + + if (messagingRegion != null) { + Serializer.toString( + request, + "messagingRegion", + messagingRegion, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "friendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/Service.java b/src/main/java/com/twilio/rest/serverless/v1/Service.java new file mode 100644 index 0000000000..7ee09b5fb6 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/Service.java @@ -0,0 +1,236 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Service extends Resource { + + public static ServiceCreator creator( + final String uniqueName, + final String friendlyName + ) { + return new ServiceCreator(uniqueName, friendlyName); + } + + public static ServiceDeleter deleter(final String pathSid) { + return new ServiceDeleter(pathSid); + } + + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); + } + + public static ServiceReader reader() { + return new ServiceReader(); + } + + public static ServiceUpdater updater(final String pathSid) { + return new ServiceUpdater(pathSid); + } + + /** + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Service.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Service.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String domainBase; + + @Getter + private final String friendlyName; + + @Getter + private final Boolean includeCredentials; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final Boolean uiEditable; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_base") final String domainBase, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("include_credentials") final Boolean includeCredentials, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("ui_editable") final Boolean uiEditable, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.domainBase = domainBase; + this.friendlyName = friendlyName; + this.includeCredentials = includeCredentials; + this.links = links; + this.sid = sid; + this.uiEditable = uiEditable; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Service other = (Service) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainBase, other.domainBase) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(includeCredentials, other.includeCredentials) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(uiEditable, other.uiEditable) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + domainBase, + friendlyName, + includeCredentials, + links, + sid, + uiEditable, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceCreator.java new file mode 100644 index 0000000000..abd81d7cdc --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceCreator.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceCreator extends Creator { + + private String uniqueName; + private String friendlyName; + private Boolean includeCredentials; + private Boolean uiEditable; + + public ServiceCreator(final String uniqueName, final String friendlyName) { + this.uniqueName = uniqueName; + this.friendlyName = friendlyName; + } + + public ServiceCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ServiceCreator setIncludeCredentials( + final Boolean includeCredentials + ) { + this.includeCredentials = includeCredentials; + return this; + } + + public ServiceCreator setUiEditable(final Boolean uiEditable) { + this.uiEditable = uiEditable; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (includeCredentials != null) { + Serializer.toString( + request, + "IncludeCredentials", + includeCredentials, + ParameterType.URLENCODED + ); + } + + if (uiEditable != null) { + Serializer.toString( + request, + "UiEditable", + uiEditable, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceDeleter.java new file mode 100644 index 0000000000..523950e1f0 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ServiceDeleter extends Deleter { + + private String pathSid; + + public ServiceDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceFetcher.java new file mode 100644 index 0000000000..662833173a --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceFetcher extends Fetcher { + + private String pathSid; + + public ServiceFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceReader.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceReader.java new file mode 100644 index 0000000000..d5bb89e0e9 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceReader extends Reader { + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/serverless/v1/ServiceUpdater.java new file mode 100644 index 0000000000..8d6f01a8ae --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/ServiceUpdater.java @@ -0,0 +1,147 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceUpdater extends Updater { + + private String pathSid; + private Boolean includeCredentials; + private String friendlyName; + private Boolean uiEditable; + + public ServiceUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public ServiceUpdater setIncludeCredentials( + final Boolean includeCredentials + ) { + this.includeCredentials = includeCredentials; + return this; + } + + public ServiceUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ServiceUpdater setUiEditable(final Boolean uiEditable) { + this.uiEditable = uiEditable; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (includeCredentials != null) { + Serializer.toString( + request, + "IncludeCredentials", + includeCredentials, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (uiEditable != null) { + Serializer.toString( + request, + "UiEditable", + uiEditable, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/Asset.java b/src/main/java/com/twilio/rest/serverless/v1/service/Asset.java new file mode 100644 index 0000000000..7d5726cb43 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/Asset.java @@ -0,0 +1,225 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Asset extends Resource { + + public static AssetCreator creator( + final String pathServiceSid, + final String friendlyName + ) { + return new AssetCreator(pathServiceSid, friendlyName); + } + + public static AssetDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new AssetDeleter(pathServiceSid, pathSid); + } + + public static AssetFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new AssetFetcher(pathServiceSid, pathSid); + } + + public static AssetReader reader(final String pathServiceSid) { + return new AssetReader(pathServiceSid); + } + + public static AssetUpdater updater( + final String pathServiceSid, + final String pathSid, + final String friendlyName + ) { + return new AssetUpdater(pathServiceSid, pathSid, friendlyName); + } + + /** + * Converts a JSON String into a Asset object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Asset object represented by the provided JSON + */ + public static Asset fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Asset.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Asset object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Asset object represented by the provided JSON + */ + public static Asset fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Asset.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Asset( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Asset other = (Asset) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + links, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetCreator.java new file mode 100644 index 0000000000..3c82625692 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetCreator.java @@ -0,0 +1,123 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssetCreator extends Creator { + + private String pathServiceSid; + private String friendlyName; + + public AssetCreator( + final String pathServiceSid, + final String friendlyName + ) { + this.pathServiceSid = pathServiceSid; + this.friendlyName = friendlyName; + } + + public AssetCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Assets"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Asset creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Asset create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Asset.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Asset content = Asset.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetDeleter.java new file mode 100644 index 0000000000..15b9593317 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetDeleter.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class AssetDeleter extends Deleter { + + private String pathServiceSid; + private String pathSid; + + public AssetDeleter(final String pathServiceSid, final String pathSid) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Assets/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Asset delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetFetcher.java new file mode 100644 index 0000000000..7a0a1c0898 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssetFetcher extends Fetcher { + + private String pathServiceSid; + private String pathSid; + + public AssetFetcher(final String pathServiceSid, final String pathSid) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Assets/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Asset fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Asset fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Asset.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Asset content = Asset.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetReader.java new file mode 100644 index 0000000000..f5e82b9d7c --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssetReader extends Reader { + + private String pathServiceSid; + private Long pageSize; + + public AssetReader(final String pathServiceSid) { + this.pathServiceSid = pathServiceSid; + } + + public AssetReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "assets", + response.getContent(), + Asset.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Assets"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "assets", + response.getContent(), + Asset.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Asset read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "assets", + response.getContent(), + Asset.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/AssetUpdater.java b/src/main/java/com/twilio/rest/serverless/v1/service/AssetUpdater.java new file mode 100644 index 0000000000..44d6e224fa --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/AssetUpdater.java @@ -0,0 +1,127 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssetUpdater extends Updater { + + private String pathServiceSid; + private String pathSid; + private String friendlyName; + + public AssetUpdater( + final String pathServiceSid, + final String pathSid, + final String friendlyName + ) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + this.friendlyName = friendlyName; + } + + public AssetUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Assets/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Asset update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Asset update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Asset.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Asset content = Asset.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/Build.java b/src/main/java/com/twilio/rest/serverless/v1/service/Build.java new file mode 100644 index 0000000000..70d7eff59d --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/Build.java @@ -0,0 +1,295 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Build extends Resource { + + public static BuildCreator creator(final String pathServiceSid) { + return new BuildCreator(pathServiceSid); + } + + public static BuildDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new BuildDeleter(pathServiceSid, pathSid); + } + + public static BuildFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new BuildFetcher(pathServiceSid, pathSid); + } + + public static BuildReader reader(final String pathServiceSid) { + return new BuildReader(pathServiceSid); + } + + public enum Status { + BUILDING("building"), + COMPLETED("completed"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Runtime { + NODE8("node8"), + NODE10("node10"), + NODE12("node12"), + NODE14("node14"), + NODE16("node16"), + NODE18("node18"), + NODE20("node20"), + NODE22("node22"), + NODE24("node24"); + + private final String value; + + private Runtime(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Runtime forValue(final String value) { + return Promoter.enumFromString(value, Runtime.values()); + } + } + + /** + * Converts a JSON String into a Build object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Build object represented by the provided JSON + */ + public static Build fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Build.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Build object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Build object represented by the provided JSON + */ + public static Build fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Build.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final List assetVersions; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final List dependencies; + + @Getter + private final List functionVersions; + + @Getter + private final Map links; + + @Getter + private final Build.Runtime runtime; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final Build.Status status; + + @Getter + private final URI url; + + @JsonCreator + private Build( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("asset_versions") final List assetVersions, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("dependencies") final List dependencies, + @JsonProperty("function_versions") final List functionVersions, + @JsonProperty("links") final Map links, + @JsonProperty("runtime") final Build.Runtime runtime, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Build.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.assetVersions = assetVersions; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.dependencies = dependencies; + this.functionVersions = functionVersions; + this.links = links; + this.runtime = runtime; + this.serviceSid = serviceSid; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Build other = (Build) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assetVersions, other.assetVersions) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(dependencies, other.dependencies) && + Objects.equals(functionVersions, other.functionVersions) && + Objects.equals(links, other.links) && + Objects.equals(runtime, other.runtime) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + assetVersions, + dateCreated, + dateUpdated, + dependencies, + functionVersions, + links, + runtime, + serviceSid, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/BuildCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/BuildCreator.java new file mode 100644 index 0000000000..94a4722553 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/BuildCreator.java @@ -0,0 +1,180 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class BuildCreator extends Creator { + + private String pathServiceSid; + private List assetVersions; + private List functionVersions; + private String dependencies; + private String runtime; + + public BuildCreator(final String pathServiceSid) { + this.pathServiceSid = pathServiceSid; + } + + public BuildCreator setAssetVersions(final List assetVersions) { + this.assetVersions = assetVersions; + return this; + } + + public BuildCreator setAssetVersions(final String assetVersions) { + return setAssetVersions(Promoter.listOfOne(assetVersions)); + } + + public BuildCreator setFunctionVersions( + final List functionVersions + ) { + this.functionVersions = functionVersions; + return this; + } + + public BuildCreator setFunctionVersions(final String functionVersions) { + return setFunctionVersions(Promoter.listOfOne(functionVersions)); + } + + public BuildCreator setDependencies(final String dependencies) { + this.dependencies = dependencies; + return this; + } + + public BuildCreator setRuntime(final String runtime) { + this.runtime = runtime; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Builds"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Build creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Build create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Build.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Build content = Build.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (assetVersions != null) { + for (String param : assetVersions) { + Serializer.toString( + request, + "AssetVersions", + param, + ParameterType.URLENCODED + ); + } + } + + if (functionVersions != null) { + for (String param : functionVersions) { + Serializer.toString( + request, + "FunctionVersions", + param, + ParameterType.URLENCODED + ); + } + } + + if (dependencies != null) { + Serializer.toString( + request, + "Dependencies", + dependencies, + ParameterType.URLENCODED + ); + } + + if (runtime != null) { + Serializer.toString( + request, + "Runtime", + runtime, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/BuildDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/BuildDeleter.java new file mode 100644 index 0000000000..c988c5e08c --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/BuildDeleter.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class BuildDeleter extends Deleter { + + private String pathServiceSid; + private String pathSid; + + public BuildDeleter(final String pathServiceSid, final String pathSid) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Builds/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Build delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/BuildFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/BuildFetcher.java new file mode 100644 index 0000000000..215e5fcd3c --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/BuildFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BuildFetcher extends Fetcher { + + private String pathServiceSid; + private String pathSid; + + public BuildFetcher(final String pathServiceSid, final String pathSid) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Builds/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Build fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Build fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Build.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Build content = Build.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/BuildReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/BuildReader.java new file mode 100644 index 0000000000..4ddc1930e0 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/BuildReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BuildReader extends Reader { + + private String pathServiceSid; + private Long pageSize; + + public BuildReader(final String pathServiceSid) { + this.pathServiceSid = pathServiceSid; + } + + public BuildReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "builds", + response.getContent(), + Build.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Builds"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "builds", + response.getContent(), + Build.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Build read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "builds", + response.getContent(), + Build.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/Environment.java b/src/main/java/com/twilio/rest/serverless/v1/service/Environment.java new file mode 100644 index 0000000000..a904c726d6 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/Environment.java @@ -0,0 +1,238 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Environment extends Resource { + + public static EnvironmentCreator creator( + final String pathServiceSid, + final String uniqueName + ) { + return new EnvironmentCreator(pathServiceSid, uniqueName); + } + + public static EnvironmentDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new EnvironmentDeleter(pathServiceSid, pathSid); + } + + public static EnvironmentFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new EnvironmentFetcher(pathServiceSid, pathSid); + } + + public static EnvironmentReader reader(final String pathServiceSid) { + return new EnvironmentReader(pathServiceSid); + } + + /** + * Converts a JSON String into a Environment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Environment object represented by the provided JSON + */ + public static Environment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Environment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Environment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Environment object represented by the provided JSON + */ + public static Environment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Environment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String buildSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String domainName; + + @Getter + private final String domainSuffix; + + @Getter + private final Map links; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private Environment( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("build_sid") final String buildSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("domain_name") final String domainName, + @JsonProperty("domain_suffix") final String domainSuffix, + @JsonProperty("links") final Map links, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.buildSid = buildSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.domainName = domainName; + this.domainSuffix = domainSuffix; + this.links = links; + this.serviceSid = serviceSid; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Environment other = (Environment) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(buildSid, other.buildSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(domainName, other.domainName) && + Objects.equals(domainSuffix, other.domainSuffix) && + Objects.equals(links, other.links) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + buildSid, + dateCreated, + dateUpdated, + domainName, + domainSuffix, + links, + serviceSid, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentCreator.java new file mode 100644 index 0000000000..3eec744742 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentCreator.java @@ -0,0 +1,141 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EnvironmentCreator extends Creator { + + private String pathServiceSid; + private String uniqueName; + private String domainSuffix; + + public EnvironmentCreator( + final String pathServiceSid, + final String uniqueName + ) { + this.pathServiceSid = pathServiceSid; + this.uniqueName = uniqueName; + } + + public EnvironmentCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public EnvironmentCreator setDomainSuffix(final String domainSuffix) { + this.domainSuffix = domainSuffix; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Environments"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Environment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Environment create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Environment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Environment content = Environment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (domainSuffix != null) { + Serializer.toString( + request, + "DomainSuffix", + domainSuffix, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentDeleter.java new file mode 100644 index 0000000000..e6f952ed69 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class EnvironmentDeleter extends Deleter { + + private String pathServiceSid; + private String pathSid; + + public EnvironmentDeleter( + final String pathServiceSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Environments/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Environment delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentFetcher.java new file mode 100644 index 0000000000..abd9332b98 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EnvironmentFetcher extends Fetcher { + + private String pathServiceSid; + private String pathSid; + + public EnvironmentFetcher( + final String pathServiceSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Environments/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Environment fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Environment fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Environment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Environment content = Environment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentReader.java new file mode 100644 index 0000000000..ab7249ca94 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/EnvironmentReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EnvironmentReader extends Reader { + + private String pathServiceSid; + private Long pageSize; + + public EnvironmentReader(final String pathServiceSid) { + this.pathServiceSid = pathServiceSid; + } + + public EnvironmentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "environments", + response.getContent(), + Environment.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Environments"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "environments", + response.getContent(), + Environment.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Environment read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "environments", + response.getContent(), + Environment.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/Function.java b/src/main/java/com/twilio/rest/serverless/v1/service/Function.java new file mode 100644 index 0000000000..ea57bfa95e --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/Function.java @@ -0,0 +1,225 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Function extends Resource { + + public static FunctionCreator creator( + final String pathServiceSid, + final String friendlyName + ) { + return new FunctionCreator(pathServiceSid, friendlyName); + } + + public static FunctionDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { + return new FunctionDeleter(pathServiceSid, pathSid); + } + + public static FunctionFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new FunctionFetcher(pathServiceSid, pathSid); + } + + public static FunctionReader reader(final String pathServiceSid) { + return new FunctionReader(pathServiceSid); + } + + public static FunctionUpdater updater( + final String pathServiceSid, + final String pathSid, + final String friendlyName + ) { + return new FunctionUpdater(pathServiceSid, pathSid, friendlyName); + } + + /** + * Converts a JSON String into a Function object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Function object represented by the provided JSON + */ + public static Function fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Function.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Function object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Function object represented by the provided JSON + */ + public static Function fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Function.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Function( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Function other = (Function) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + links, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionCreator.java new file mode 100644 index 0000000000..750f851415 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionCreator.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FunctionCreator extends Creator { + + private String pathServiceSid; + private String friendlyName; + + public FunctionCreator( + final String pathServiceSid, + final String friendlyName + ) { + this.pathServiceSid = pathServiceSid; + this.friendlyName = friendlyName; + } + + public FunctionCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Functions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Function creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Function create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Function content = Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionDeleter.java new file mode 100644 index 0000000000..56b59f8407 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionDeleter.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class FunctionDeleter extends Deleter { + + private String pathServiceSid; + private String pathSid; + + public FunctionDeleter(final String pathServiceSid, final String pathSid) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Functions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Function delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionFetcher.java new file mode 100644 index 0000000000..6cb09d99df --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionFetcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FunctionFetcher extends Fetcher { + + private String pathServiceSid; + private String pathSid; + + public FunctionFetcher(final String pathServiceSid, final String pathSid) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Functions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Function fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Function fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Function content = Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionReader.java new file mode 100644 index 0000000000..5bcb6246f2 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionReader.java @@ -0,0 +1,211 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FunctionReader extends Reader { + + private String pathServiceSid; + private Long pageSize; + + public FunctionReader(final String pathServiceSid) { + this.pathServiceSid = pathServiceSid; + } + + public FunctionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "functions", + response.getContent(), + Function.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Functions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "functions", + response.getContent(), + Function.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Function read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "functions", + response.getContent(), + Function.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/FunctionUpdater.java b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionUpdater.java new file mode 100644 index 0000000000..e2ed8bc42e --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/FunctionUpdater.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FunctionUpdater extends Updater { + + private String pathServiceSid; + private String pathSid; + private String friendlyName; + + public FunctionUpdater( + final String pathServiceSid, + final String pathSid, + final String friendlyName + ) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + this.friendlyName = friendlyName; + } + + public FunctionUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Functions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Function update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Function update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Function content = Function.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersion.java b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersion.java new file mode 100644 index 0000000000..2fabb709cb --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersion.java @@ -0,0 +1,225 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.asset; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class AssetVersion extends Resource { + + public static AssetVersionFetcher fetcher( + final String pathServiceSid, + final String pathAssetSid, + final String pathSid + ) { + return new AssetVersionFetcher(pathServiceSid, pathAssetSid, pathSid); + } + + public static AssetVersionReader reader( + final String pathServiceSid, + final String pathAssetSid + ) { + return new AssetVersionReader(pathServiceSid, pathAssetSid); + } + + public enum Visibility { + PUBLIC("public"), + PRIVATE("private"), + PROTECTED("protected"); + + private final String value; + + private Visibility(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Visibility forValue(final String value) { + return Promoter.enumFromString(value, Visibility.values()); + } + } + + /** + * Converts a JSON String into a AssetVersion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return AssetVersion object represented by the provided JSON + */ + public static AssetVersion fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AssetVersion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a AssetVersion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return AssetVersion object represented by the provided JSON + */ + public static AssetVersion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, AssetVersion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String assetSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String path; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final AssetVersion.Visibility visibility; + + @JsonCreator + private AssetVersion( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("asset_sid") final String assetSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("path") final String path, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("visibility") final AssetVersion.Visibility visibility + ) { + this.accountSid = accountSid; + this.assetSid = assetSid; + this.dateCreated = dateCreated; + this.path = path; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + this.visibility = visibility; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + AssetVersion other = (AssetVersion) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assetSid, other.assetSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(path, other.path) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(visibility, other.visibility) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + assetSid, + dateCreated, + path, + serviceSid, + sid, + url, + visibility + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionFetcher.java new file mode 100644 index 0000000000..2ef8dcf8c4 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionFetcher.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.asset; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssetVersionFetcher extends Fetcher { + + private String pathServiceSid; + private String pathAssetSid; + private String pathSid; + + public AssetVersionFetcher( + final String pathServiceSid, + final String pathAssetSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathAssetSid = pathAssetSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace("{" + "AssetSid" + "}", this.pathAssetSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "AssetVersion fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public AssetVersion fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return AssetVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + AssetVersion content = AssetVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionReader.java new file mode 100644 index 0000000000..fc013e4696 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/asset/AssetVersionReader.java @@ -0,0 +1,218 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.asset; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class AssetVersionReader extends Reader { + + private String pathServiceSid; + private String pathAssetSid; + private Long pageSize; + + public AssetVersionReader( + final String pathServiceSid, + final String pathAssetSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathAssetSid = pathAssetSid; + } + + public AssetVersionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "asset_versions", + response.getContent(), + AssetVersion.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Assets/{AssetSid}/Versions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace("{" + "AssetSid" + "}", this.pathAssetSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "asset_versions", + response.getContent(), + AssetVersion.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "AssetVersion read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "asset_versions", + response.getContent(), + AssetVersion.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatus.java b/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatus.java new file mode 100644 index 0000000000..229c7b2905 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatus.java @@ -0,0 +1,182 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.build; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BuildStatus extends Resource { + + public static BuildStatusFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new BuildStatusFetcher(pathServiceSid, pathSid); + } + + public enum Status { + BUILDING("building"), + COMPLETED("completed"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a BuildStatus object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BuildStatus object represented by the provided JSON + */ + public static BuildStatus fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BuildStatus.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BuildStatus object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BuildStatus object represented by the provided JSON + */ + public static BuildStatus fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BuildStatus.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final BuildStatus.Status status; + + @Getter + private final URI url; + + @JsonCreator + private BuildStatus( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final BuildStatus.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BuildStatus other = (BuildStatus) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, serviceSid, sid, status, url); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatusFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatusFetcher.java new file mode 100644 index 0000000000..273524bf31 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/build/BuildStatusFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.build; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BuildStatusFetcher extends Fetcher { + + private String pathServiceSid; + private String pathSid; + + public BuildStatusFetcher( + final String pathServiceSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Builds/{Sid}/Status"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "BuildStatus fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public BuildStatus fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return BuildStatus.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + BuildStatus content = BuildStatus.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Deployment.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Deployment.java new file mode 100644 index 0000000000..3225e45ae3 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Deployment.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Deployment extends Resource { + + public static DeploymentCreator creator( + final String pathServiceSid, + final String pathEnvironmentSid + ) { + return new DeploymentCreator(pathServiceSid, pathEnvironmentSid); + } + + public static DeploymentFetcher fetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + return new DeploymentFetcher( + pathServiceSid, + pathEnvironmentSid, + pathSid + ); + } + + public static DeploymentReader reader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { + return new DeploymentReader(pathServiceSid, pathEnvironmentSid); + } + + /** + * Converts a JSON String into a Deployment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Deployment object represented by the provided JSON + */ + public static Deployment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Deployment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Deployment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Deployment object represented by the provided JSON + */ + public static Deployment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Deployment.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String buildSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String environmentSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Deployment( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("build_sid") final String buildSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("environment_sid") final String environmentSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.buildSid = buildSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.environmentSid = environmentSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Deployment other = (Deployment) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(buildSid, other.buildSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(environmentSid, other.environmentSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + buildSid, + dateCreated, + dateUpdated, + environmentSid, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentCreator.java new file mode 100644 index 0000000000..8343108748 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentCreator.java @@ -0,0 +1,148 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DeploymentCreator extends Creator { + + private String pathServiceSid; + private String pathEnvironmentSid; + private String buildSid; + private Boolean isPlugin; + + public DeploymentCreator( + final String pathServiceSid, + final String pathEnvironmentSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + } + + public DeploymentCreator setBuildSid(final String buildSid) { + this.buildSid = buildSid; + return this; + } + + public DeploymentCreator setIsPlugin(final Boolean isPlugin) { + this.isPlugin = isPlugin; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Deployment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Deployment create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Deployment content = Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (buildSid != null) { + Serializer.toString( + request, + "BuildSid", + buildSid, + ParameterType.URLENCODED + ); + } + + if (isPlugin != null) { + Serializer.toString( + request, + "IsPlugin", + isPlugin, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentFetcher.java new file mode 100644 index 0000000000..7e18d38eba --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DeploymentFetcher extends Fetcher { + + private String pathServiceSid; + private String pathEnvironmentSid; + private String pathSid; + + public DeploymentFetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Deployment fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Deployment fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Deployment content = Deployment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentReader.java new file mode 100644 index 0000000000..66b84853ba --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/DeploymentReader.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class DeploymentReader extends Reader { + + private String pathServiceSid; + private String pathEnvironmentSid; + private Long pageSize; + + public DeploymentReader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + } + + public DeploymentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "deployments", + response.getContent(), + Deployment.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Deployments"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "deployments", + response.getContent(), + Deployment.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Deployment read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "deployments", + response.getContent(), + Deployment.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Log.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Log.java new file mode 100644 index 0000000000..770a882441 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Log.java @@ -0,0 +1,229 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Log extends Resource { + + public static LogFetcher fetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + return new LogFetcher(pathServiceSid, pathEnvironmentSid, pathSid); + } + + public static LogReader reader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { + return new LogReader(pathServiceSid, pathEnvironmentSid); + } + + /** + * Converts a JSON String into a Log object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Log object represented by the provided JSON + */ + public static Log fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Log.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Log object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Log object represented by the provided JSON + */ + public static Log fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Log.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String buildSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String deploymentSid; + + @Getter + private final String environmentSid; + + @Getter + private final String functionSid; + + @Getter + private final String level; + + @Getter + private final String message; + + @Getter + private final String requestSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Log( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("build_sid") final String buildSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("deployment_sid") final String deploymentSid, + @JsonProperty("environment_sid") final String environmentSid, + @JsonProperty("function_sid") final String functionSid, + @JsonProperty("level") final String level, + @JsonProperty("message") final String message, + @JsonProperty("request_sid") final String requestSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.buildSid = buildSid; + this.dateCreated = dateCreated; + this.deploymentSid = deploymentSid; + this.environmentSid = environmentSid; + this.functionSid = functionSid; + this.level = level; + this.message = message; + this.requestSid = requestSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Log other = (Log) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(buildSid, other.buildSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(deploymentSid, other.deploymentSid) && + Objects.equals(environmentSid, other.environmentSid) && + Objects.equals(functionSid, other.functionSid) && + Objects.equals(level, other.level) && + Objects.equals(message, other.message) && + Objects.equals(requestSid, other.requestSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + buildSid, + dateCreated, + deploymentSid, + environmentSid, + functionSid, + level, + message, + requestSid, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogFetcher.java new file mode 100644 index 0000000000..10916a2b9a --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogFetcher.java @@ -0,0 +1,112 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class LogFetcher extends Fetcher { + + private String pathServiceSid; + private String pathEnvironmentSid; + private String pathSid; + + public LogFetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Log fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Log fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Log.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Log content = Log.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogReader.java new file mode 100644 index 0000000000..f7c42c6f00 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/LogReader.java @@ -0,0 +1,264 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class LogReader extends Reader { + + private String pathServiceSid; + private String pathEnvironmentSid; + private String functionSid; + private ZonedDateTime startDate; + private ZonedDateTime endDate; + private Long pageSize; + + public LogReader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + } + + public LogReader setFunctionSid(final String functionSid) { + this.functionSid = functionSid; + return this; + } + + public LogReader setStartDate(final ZonedDateTime startDate) { + this.startDate = startDate; + return this; + } + + public LogReader setEndDate(final ZonedDateTime endDate) { + this.endDate = endDate; + return this; + } + + public LogReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "logs", + response.getContent(), + Log.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Logs"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "logs", + response.getContent(), + Log.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Log read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "logs", + response.getContent(), + Log.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (functionSid != null) { + Serializer.toString( + request, + "FunctionSid", + functionSid, + ParameterType.QUERY + ); + } + + if (startDate != null) { + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); + } + + if (endDate != null) { + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/Variable.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Variable.java new file mode 100644 index 0000000000..dd6c875a78 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/Variable.java @@ -0,0 +1,243 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Variable extends Resource { + + public static VariableCreator creator( + final String pathServiceSid, + final String pathEnvironmentSid, + final String key, + final String value + ) { + return new VariableCreator( + pathServiceSid, + pathEnvironmentSid, + key, + value + ); + } + + public static VariableDeleter deleter( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + return new VariableDeleter(pathServiceSid, pathEnvironmentSid, pathSid); + } + + public static VariableFetcher fetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + return new VariableFetcher(pathServiceSid, pathEnvironmentSid, pathSid); + } + + public static VariableReader reader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { + return new VariableReader(pathServiceSid, pathEnvironmentSid); + } + + public static VariableUpdater updater( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + return new VariableUpdater(pathServiceSid, pathEnvironmentSid, pathSid); + } + + /** + * Converts a JSON String into a Variable object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Variable object represented by the provided JSON + */ + public static Variable fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Variable.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Variable object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Variable object represented by the provided JSON + */ + public static Variable fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Variable.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String environmentSid; + + @Getter + private final String key; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final String value; + + @JsonCreator + private Variable( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("environment_sid") final String environmentSid, + @JsonProperty("key") final String key, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("value") final String value + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.environmentSid = environmentSid; + this.key = key; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + this.value = value; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Variable other = (Variable) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(environmentSid, other.environmentSid) && + Objects.equals(key, other.key) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(value, other.value) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + environmentSid, + key, + serviceSid, + sid, + url, + value + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableCreator.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableCreator.java new file mode 100644 index 0000000000..0d0ac12448 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableCreator.java @@ -0,0 +1,147 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class VariableCreator extends Creator { + + private String pathServiceSid; + private String pathEnvironmentSid; + private String key; + private String value; + + public VariableCreator( + final String pathServiceSid, + final String pathEnvironmentSid, + final String key, + final String value + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + this.key = key; + this.value = value; + } + + public VariableCreator setKey(final String key) { + this.key = key; + return this; + } + + public VariableCreator setValue(final String value) { + this.value = value; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Variable creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Variable create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Variable content = Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (key != null) { + Serializer.toString(request, "Key", key, ParameterType.URLENCODED); + } + + if (value != null) { + Serializer.toString( + request, + "Value", + value, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableDeleter.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableDeleter.java new file mode 100644 index 0000000000..456b9a15d7 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableDeleter.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class VariableDeleter extends Deleter { + + private String pathServiceSid; + private String pathEnvironmentSid; + private String pathSid; + + public VariableDeleter( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Variable delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableFetcher.java new file mode 100644 index 0000000000..a81ca8fb23 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class VariableFetcher extends Fetcher { + + private String pathServiceSid; + private String pathEnvironmentSid; + private String pathSid; + + public VariableFetcher( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Variable fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Variable fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Variable content = Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableReader.java new file mode 100644 index 0000000000..86fa6b5744 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableReader.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class VariableReader extends Reader { + + private String pathServiceSid; + private String pathEnvironmentSid; + private Long pageSize; + + public VariableReader( + final String pathServiceSid, + final String pathEnvironmentSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + } + + public VariableReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "variables", + response.getContent(), + Variable.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "variables", + response.getContent(), + Variable.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Variable read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "variables", + response.getContent(), + Variable.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableUpdater.java b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableUpdater.java new file mode 100644 index 0000000000..0534f43d90 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/environment/VariableUpdater.java @@ -0,0 +1,147 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.environment; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class VariableUpdater extends Updater { + + private String pathServiceSid; + private String pathEnvironmentSid; + private String pathSid; + private String key; + private String value; + + public VariableUpdater( + final String pathServiceSid, + final String pathEnvironmentSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathEnvironmentSid = pathEnvironmentSid; + this.pathSid = pathSid; + } + + public VariableUpdater setKey(final String key) { + this.key = key; + return this; + } + + public VariableUpdater setValue(final String value) { + this.value = value; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Environments/{EnvironmentSid}/Variables/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "EnvironmentSid" + "}", + this.pathEnvironmentSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.SERVERLESS.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Variable update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Variable update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Variable content = Variable.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (key != null) { + Serializer.toString(request, "Key", key, ParameterType.URLENCODED); + } + + if (value != null) { + Serializer.toString( + request, + "Value", + value, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersion.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersion.java new file mode 100644 index 0000000000..933d548164 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersion.java @@ -0,0 +1,237 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.function; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class FunctionVersion extends Resource { + + public static FunctionVersionFetcher fetcher( + final String pathServiceSid, + final String pathFunctionSid, + final String pathSid + ) { + return new FunctionVersionFetcher( + pathServiceSid, + pathFunctionSid, + pathSid + ); + } + + public static FunctionVersionReader reader( + final String pathServiceSid, + final String pathFunctionSid + ) { + return new FunctionVersionReader(pathServiceSid, pathFunctionSid); + } + + public enum Visibility { + PUBLIC("public"), + PRIVATE("private"), + PROTECTED("protected"); + + private final String value; + + private Visibility(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Visibility forValue(final String value) { + return Promoter.enumFromString(value, Visibility.values()); + } + } + + /** + * Converts a JSON String into a FunctionVersion object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FunctionVersion object represented by the provided JSON + */ + public static FunctionVersion fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FunctionVersion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a FunctionVersion object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FunctionVersion object represented by the provided JSON + */ + public static FunctionVersion fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FunctionVersion.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String functionSid; + + @Getter + private final Map links; + + @Getter + private final String path; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @Getter + private final FunctionVersion.Visibility visibility; + + @JsonCreator + private FunctionVersion( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("function_sid") final String functionSid, + @JsonProperty("links") final Map links, + @JsonProperty("path") final String path, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("visibility") final FunctionVersion.Visibility visibility + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.functionSid = functionSid; + this.links = links; + this.path = path; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + this.visibility = visibility; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FunctionVersion other = (FunctionVersion) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(functionSid, other.functionSid) && + Objects.equals(links, other.links) && + Objects.equals(path, other.path) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(visibility, other.visibility) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + functionSid, + links, + path, + serviceSid, + sid, + url, + visibility + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionFetcher.java new file mode 100644 index 0000000000..2de999c2ae --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionFetcher.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.function; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FunctionVersionFetcher extends Fetcher { + + private String pathServiceSid; + private String pathFunctionSid; + private String pathSid; + + public FunctionVersionFetcher( + final String pathServiceSid, + final String pathFunctionSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathFunctionSid = pathFunctionSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FunctionSid" + "}", + this.pathFunctionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FunctionVersion fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FunctionVersion fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return FunctionVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FunctionVersion content = FunctionVersion.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionReader.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionReader.java new file mode 100644 index 0000000000..6bc0d4eb96 --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/FunctionVersionReader.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.function; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FunctionVersionReader extends Reader { + + private String pathServiceSid; + private String pathFunctionSid; + private Long pageSize; + + public FunctionVersionReader( + final String pathServiceSid, + final String pathFunctionSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathFunctionSid = pathFunctionSid; + } + + public FunctionVersionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "function_versions", + response.getContent(), + FunctionVersion.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FunctionSid" + "}", + this.pathFunctionSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "function_versions", + response.getContent(), + FunctionVersion.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "FunctionVersion read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "function_versions", + response.getContent(), + FunctionVersion.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContent.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContent.java new file mode 100644 index 0000000000..4664238d5c --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContent.java @@ -0,0 +1,176 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.function.functionversion; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class FunctionVersionContent extends Resource { + + public static FunctionVersionContentFetcher fetcher( + final String pathServiceSid, + final String pathFunctionSid, + final String pathSid + ) { + return new FunctionVersionContentFetcher( + pathServiceSid, + pathFunctionSid, + pathSid + ); + } + + /** + * Converts a JSON String into a FunctionVersionContent object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FunctionVersionContent object represented by the provided JSON + */ + public static FunctionVersionContent fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FunctionVersionContent.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a FunctionVersionContent object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FunctionVersionContent object represented by the provided JSON + */ + public static FunctionVersionContent fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FunctionVersionContent.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String content; + + @Getter + private final String functionSid; + + @Getter + private final String serviceSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private FunctionVersionContent( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("content") final String content, + @JsonProperty("function_sid") final String functionSid, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.content = content; + this.functionSid = functionSid; + this.serviceSid = serviceSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FunctionVersionContent other = (FunctionVersionContent) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(content, other.content) && + Objects.equals(functionSid, other.functionSid) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + content, + functionSid, + serviceSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContentFetcher.java b/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContentFetcher.java new file mode 100644 index 0000000000..e2f5cb641c --- /dev/null +++ b/src/main/java/com/twilio/rest/serverless/v1/service/function/functionversion/FunctionVersionContentFetcher.java @@ -0,0 +1,116 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Serverless + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.serverless.v1.service.function.functionversion; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FunctionVersionContentFetcher + extends Fetcher { + + private String pathServiceSid; + private String pathFunctionSid; + private String pathSid; + + public FunctionVersionContentFetcher( + final String pathServiceSid, + final String pathFunctionSid, + final String pathSid + ) { + this.pathServiceSid = pathServiceSid; + this.pathFunctionSid = pathFunctionSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Functions/{FunctionSid}/Versions/{Sid}/Content"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "FunctionSid" + "}", + this.pathFunctionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SERVERLESS.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FunctionVersionContent fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FunctionVersionContent fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return FunctionVersionContent.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FunctionVersionContent content = FunctionVersionContent.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/Flow.java b/src/main/java/com/twilio/rest/studio/v1/Flow.java index 7d8af4bd8b..54cf11ccce 100644 --- a/src/main/java/com/twilio/rest/studio/v1/Flow.java +++ b/src/main/java/com/twilio/rest/studio/v1/Flow.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1; @@ -10,36 +17,45 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Flow extends Resource { - private static final long serialVersionUID = 111627712697750L; + + public static FlowDeleter deleter(final String pathSid) { + return new FlowDeleter(pathSid); + } + + public static FlowFetcher fetcher(final String pathSid) { + return new FlowFetcher(pathSid); + } + + public static FlowReader reader() { + return new FlowReader(); + } public enum Status { DRAFT("draft"), @@ -51,58 +67,28 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } - /** - * Create a FlowReader to execute read. - * - * @return FlowReader capable of executing the read - */ - public static FlowReader reader() { - return new FlowReader(); - } - - /** - * Create a FlowFetcher to execute fetch. - * - * @param pathSid The sid - * @return FlowFetcher capable of executing the fetch - */ - public static FlowFetcher fetcher(final String pathSid) { - return new FlowFetcher(pathSid); - } - - /** - * Create a FlowDeleter to execute delete. - * - * @param pathSid The sid - * @return FlowDeleter capable of executing the delete - */ - public static FlowDeleter deleter(final String pathSid) { - return new FlowDeleter(pathSid); - } - /** * Converts a JSON String into a Flow object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Flow object represented by the provided JSON */ - public static Flow fromJson(final String json, final ObjectMapper objectMapper) { + public static Flow fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Flow.class); @@ -116,12 +102,15 @@ public static Flow fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Flow object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Flow object represented by the provided JSON */ - public static Flow fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Flow fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Flow.class); @@ -132,125 +121,76 @@ public static Flow fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; - private final String accountSid; - private final String friendlyName; - private final Flow.Status status; - private final Integer version; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Flow(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("status") - final Flow.Status status, - @JsonProperty("version") - final Integer version, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.status = status; - this.version = version; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The status. - * - * @return The status - */ - public final Flow.Status getStatus() { - return this.status; - } + @Getter + private final String friendlyName; - /** - * Returns The The version. - * - * @return The version - */ - public final Integer getVersion() { - return this.version; - } + @Getter + private final Map links; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Flow.Status status; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final URI url; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @Getter + private final Integer version; + + @JsonCreator + private Flow( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Flow.Status status, + @JsonProperty("url") final URI url, + @JsonProperty("version") final Integer version + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.sid = sid; + this.status = status; + this.url = url; + this.version = version; } @Override @@ -264,43 +204,31 @@ public boolean equals(final Object o) { } Flow other = (Flow) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(status, other.status) && - Objects.equals(version, other.version) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(version, other.version) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - friendlyName, - status, - version, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("status", status) - .add("version", version) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + links, + sid, + status, + url, + version + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/FlowDeleter.java b/src/main/java/com/twilio/rest/studio/v1/FlowDeleter.java index 2b02a47290..7c03ee9bfb 100644 --- a/src/main/java/com/twilio/rest/studio/v1/FlowDeleter.java +++ b/src/main/java/com/twilio/rest/studio/v1/FlowDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class FlowDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new FlowDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public FlowDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Flow delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/FlowFetcher.java b/src/main/java/com/twilio/rest/studio/v1/FlowFetcher.java index 9df7530c83..4c8acac248 100644 --- a/src/main/java/com/twilio/rest/studio/v1/FlowFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/FlowFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class FlowFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new FlowFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public FlowFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Flow - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Flow fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Flow fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Flow fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Flow fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Flow.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Flow content = Flow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/FlowReader.java b/src/main/java/com/twilio/rest/studio/v1/FlowReader.java index 67af027b83..61b9412f90 100644 --- a/src/main/java/com/twilio/rest/studio/v1/FlowReader.java +++ b/src/main/java/com/twilio/rest/studio/v1/FlowReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1; @@ -10,152 +17,182 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class FlowReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Flow ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public FlowReader() {} + + public FlowReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Flow ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flows", + response.getContent(), + Flow.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Flows"; + Request request = new Request( HttpMethod.GET, Domains.STUDIO.toString(), - "/v1/Flows", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Flow ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flows", + response.getContent(), + Flow.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Flow read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "flows", + response.getContent(), + Flow.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.STUDIO.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.STUDIO.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Flow Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Flow read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "flows", - response.getContent(), - Flow.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/Engagement.java b/src/main/java/com/twilio/rest/studio/v1/flow/Engagement.java index 7cc0fb77b1..0f76f8196d 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/Engagement.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/Engagement.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow; @@ -10,37 +17,59 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Engagement extends Resource { - private static final long serialVersionUID = 131970036431728L; + + public static EngagementCreator creator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { + return new EngagementCreator(pathFlowSid, to, from); + } + + public static EngagementDeleter deleter( + final String pathFlowSid, + final String pathSid + ) { + return new EngagementDeleter(pathFlowSid, pathSid); + } + + public static EngagementFetcher fetcher( + final String pathFlowSid, + final String pathSid + ) { + return new EngagementFetcher(pathFlowSid, pathSid); + } + + public static EngagementReader reader(final String pathFlowSid) { + return new EngagementReader(pathFlowSid); + } public enum Status { ACTIVE("active"), @@ -52,15 +81,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -68,62 +93,16 @@ public static Status forValue(final String value) { } /** - * Create a EngagementReader to execute read. - * - * @param pathFlowSid The flow_sid - * @return EngagementReader capable of executing the read - */ - public static EngagementReader reader(final String pathFlowSid) { - return new EngagementReader(pathFlowSid); - } - - /** - * Create a EngagementFetcher to execute fetch. - * - * @param pathFlowSid The flow_sid - * @param pathSid The sid - * @return EngagementFetcher capable of executing the fetch - */ - public static EngagementFetcher fetcher(final String pathFlowSid, - final String pathSid) { - return new EngagementFetcher(pathFlowSid, pathSid); - } - - /** - * Create a EngagementCreator to execute create. - * - * @param pathFlowSid The flow_sid - * @param to The to - * @param from The from - * @return EngagementCreator capable of executing the create - */ - public static EngagementCreator creator(final String pathFlowSid, - final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from) { - return new EngagementCreator(pathFlowSid, to, from); - } - - /** - * Create a EngagementDeleter to execute delete. - * - * @param pathFlowSid The flow_sid - * @param pathSid The sid - * @return EngagementDeleter capable of executing the delete - */ - public static EngagementDeleter deleter(final String pathFlowSid, - final String pathSid) { - return new EngagementDeleter(pathFlowSid, pathSid); - } - - /** - * Converts a JSON String into a Engagement object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Engagement object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Engagement object represented by the provided JSON */ - public static Engagement fromJson(final String json, final ObjectMapper objectMapper) { + public static Engagement fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Engagement.class); @@ -137,12 +116,15 @@ public static Engagement fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a Engagement object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Engagement object represented by the provided JSON */ - public static Engagement fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Engagement fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Engagement.class); @@ -153,151 +135,88 @@ public static Engagement fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; - private final String accountSid; - private final String flowSid; - private final String contactSid; - private final String contactChannelAddress; - private final Map context; - private final Engagement.Status status; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - - @JsonCreator - private Engagement(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("flow_sid") - final String flowSid, - @JsonProperty("contact_sid") - final String contactSid, - @JsonProperty("contact_channel_address") - final String contactChannelAddress, - @JsonProperty("context") - final Map context, - @JsonProperty("status") - final Engagement.Status status, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.flowSid = flowSid; - this.contactSid = contactSid; - this.contactChannelAddress = contactChannelAddress; - this.context = context; - this.status = status; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String contactChannelAddress; - /** - * Returns The The flow_sid. - * - * @return The flow_sid - */ - public final String getFlowSid() { - return this.flowSid; - } + @Getter + private final String contactSid; - /** - * Returns The The contact_sid. - * - * @return The contact_sid - */ - public final String getContactSid() { - return this.contactSid; - } + @Getter + private final Object context; - /** - * Returns The The contact_channel_address. - * - * @return The contact_channel_address - */ - public final String getContactChannelAddress() { - return this.contactChannelAddress; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The context. - * - * @return The context - */ - public final Map getContext() { - return this.context; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The status. - * - * @return The status - */ - public final Engagement.Status getStatus() { - return this.status; - } + @Getter + private final String flowSid; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Map links; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String sid; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final Engagement.Status status; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Engagement( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "contact_channel_address" + ) final String contactChannelAddress, + @JsonProperty("contact_sid") final String contactSid, + @JsonProperty("context") final Object context, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Engagement.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.contactChannelAddress = contactChannelAddress; + this.contactSid = contactSid; + this.context = context; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.flowSid = flowSid; + this.links = links; + this.sid = sid; + this.status = status; + this.url = url; } @Override @@ -311,49 +230,38 @@ public boolean equals(final Object o) { } Engagement other = (Engagement) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(flowSid, other.flowSid) && - Objects.equals(contactSid, other.contactSid) && - Objects.equals(contactChannelAddress, other.contactChannelAddress) && - Objects.equals(context, other.context) && - Objects.equals(status, other.status) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + contactChannelAddress, + other.contactChannelAddress + ) && + Objects.equals(contactSid, other.contactSid) && + Objects.equals(context, other.context) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - flowSid, - contactSid, - contactChannelAddress, - context, - status, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("flowSid", flowSid) - .add("contactSid", contactSid) - .add("contactChannelAddress", contactChannelAddress) - .add("context", context) - .add("status", status) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + contactChannelAddress, + contactSid, + context, + dateCreated, + dateUpdated, + flowSid, + links, + sid, + status, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementCreator.java b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementCreator.java index a667254c43..5d8ea6dcec 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementCreator.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow; import com.twilio.base.Creator; -import com.twilio.converter.Converter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,100 +28,131 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class EngagementCreator extends Creator { - private final String pathFlowSid; - private final com.twilio.type.PhoneNumber to; - private final com.twilio.type.PhoneNumber from; - private Map parameters; - - /** - * Construct a new EngagementCreator. - * - * @param pathFlowSid The flow_sid - * @param to The to - * @param from The from - */ - public EngagementCreator(final String pathFlowSid, - final com.twilio.type.PhoneNumber to, - final com.twilio.type.PhoneNumber from) { + + private String pathFlowSid; + private com.twilio.type.PhoneNumber to; + private com.twilio.type.PhoneNumber from; + private Object parameters; + + public EngagementCreator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { this.pathFlowSid = pathFlowSid; this.to = to; this.from = from; } - /** - * The parameters. - * - * @param parameters The parameters - * @return this - */ - public EngagementCreator setParameters(final Map parameters) { + public EngagementCreator setTo(final com.twilio.type.PhoneNumber to) { + this.to = to; + return this; + } + + public EngagementCreator setTo(final String to) { + return setTo(Promoter.phoneNumberFromString(to)); + } + + public EngagementCreator setFrom(final com.twilio.type.PhoneNumber from) { + this.from = from; + return this; + } + + public EngagementCreator setFrom(final String from) { + return setFrom(Promoter.phoneNumberFromString(from)); + } + + public EngagementCreator setParameters(final Object parameters) { this.parameters = parameters; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Engagement - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Engagement create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Engagements"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathFlowSid + "/Engagements", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Engagement creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Engagement creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Engagement create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Engagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Engagement.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Engagement content = Engagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (to != null) { - request.addPostParam("To", to.toString()); + Serializer.toString(request, "To", to, ParameterType.URLENCODED); } if (from != null) { - request.addPostParam("From", from.toString()); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (parameters != null) { - request.addPostParam("Parameters", Converter.mapToJson(parameters)); + Serializer.toString( + request, + "Parameters", + parameters, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementDeleter.java b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementDeleter.java index 8c97e1aeba..b65a632b7a 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementDeleter.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class EngagementDeleter extends Deleter { - private final String pathFlowSid; - private final String pathSid; - /** - * Construct a new EngagementDeleter. - * - * @param pathFlowSid The flow_sid - * @param pathSid The sid - */ - public EngagementDeleter(final String pathFlowSid, - final String pathSid) { + private String pathFlowSid; + private String pathSid; + + public EngagementDeleter(final String pathFlowSid, final String pathSid) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Engagements/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Engagement delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Engagement delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementFetcher.java index a8b1a903fb..5c45a7e211 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,76 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class EngagementFetcher extends Fetcher { - private final String pathFlowSid; - private final String pathSid; - /** - * Construct a new EngagementFetcher. - * - * @param pathFlowSid The flow_sid - * @param pathSid The sid - */ - public EngagementFetcher(final String pathFlowSid, - final String pathSid) { + private String pathFlowSid; + private String pathSid; + + public EngagementFetcher(final String pathFlowSid, final String pathSid) { this.pathFlowSid = pathFlowSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Engagement - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Engagement fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Engagements/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Engagement fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Engagement fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Engagement.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Engagement fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Engagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Engagement content = Engagement.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementReader.java b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementReader.java index 2c2d65f894..fdf1f3cbc7 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/EngagementReader.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/EngagementReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow; @@ -10,163 +17,191 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class EngagementReader extends Reader { - private final String pathFlowSid; - /** - * Construct a new EngagementReader. - * - * @param pathFlowSid The flow_sid - */ + private String pathFlowSid; + private Long pageSize; + public EngagementReader(final String pathFlowSid) { this.pathFlowSid = pathFlowSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Engagement ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public EngagementReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Engagement ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "engagements", + response.getContent(), + Engagement.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Engagements"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathFlowSid + "/Engagements", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Engagement ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "engagements", + response.getContent(), + Engagement.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Engagement read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "engagements", + response.getContent(), + Engagement.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.STUDIO.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.STUDIO.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Engagement Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Engagement read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "engagements", - response.getContent(), - Engagement.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/Execution.java b/src/main/java/com/twilio/rest/studio/v1/flow/Execution.java new file mode 100644 index 0000000000..29c5fcef8e --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/Execution.java @@ -0,0 +1,275 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Execution extends Resource { + + public static ExecutionCreator creator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { + return new ExecutionCreator(pathFlowSid, to, from); + } + + public static ExecutionDeleter deleter( + final String pathFlowSid, + final String pathSid + ) { + return new ExecutionDeleter(pathFlowSid, pathSid); + } + + public static ExecutionFetcher fetcher( + final String pathFlowSid, + final String pathSid + ) { + return new ExecutionFetcher(pathFlowSid, pathSid); + } + + public static ExecutionReader reader(final String pathFlowSid) { + return new ExecutionReader(pathFlowSid); + } + + public static ExecutionUpdater updater( + final String pathFlowSid, + final String pathSid, + final Execution.Status status + ) { + return new ExecutionUpdater(pathFlowSid, pathSid, status); + } + + public enum Status { + ACTIVE("active"), + ENDED("ended"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a Execution object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Execution object represented by the provided JSON + */ + public static Execution fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Execution.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Execution object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Execution object represented by the provided JSON + */ + public static Execution fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Execution.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String contactChannelAddress; + + @Getter + private final String contactSid; + + @Getter + private final Object context; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String flowSid; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final Execution.Status status; + + @Getter + private final URI url; + + @JsonCreator + private Execution( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "contact_channel_address" + ) final String contactChannelAddress, + @JsonProperty("contact_sid") final String contactSid, + @JsonProperty("context") final Object context, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Execution.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.contactChannelAddress = contactChannelAddress; + this.contactSid = contactSid; + this.context = context; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.flowSid = flowSid; + this.links = links; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Execution other = (Execution) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + contactChannelAddress, + other.contactChannelAddress + ) && + Objects.equals(contactSid, other.contactSid) && + Objects.equals(context, other.context) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + contactChannelAddress, + contactSid, + context, + dateCreated, + dateUpdated, + flowSid, + links, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionCreator.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionCreator.java new file mode 100644 index 0000000000..c9e1f8d4c2 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionCreator.java @@ -0,0 +1,158 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionCreator extends Creator { + + private String pathFlowSid; + private com.twilio.type.PhoneNumber to; + private com.twilio.type.PhoneNumber from; + private Object parameters; + + public ExecutionCreator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { + this.pathFlowSid = pathFlowSid; + this.to = to; + this.from = from; + } + + public ExecutionCreator setTo(final com.twilio.type.PhoneNumber to) { + this.to = to; + return this; + } + + public ExecutionCreator setTo(final String to) { + return setTo(Promoter.phoneNumberFromString(to)); + } + + public ExecutionCreator setFrom(final com.twilio.type.PhoneNumber from) { + this.from = from; + return this; + } + + public ExecutionCreator setFrom(final String from) { + return setFrom(Promoter.phoneNumberFromString(from)); + } + + public ExecutionCreator setParameters(final Object parameters) { + this.parameters = parameters; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Executions"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.STUDIO.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Execution creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Execution create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Execution content = Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (to != null) { + Serializer.toString(request, "To", to, ParameterType.URLENCODED); + } + + if (from != null) { + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); + } + + if (parameters != null) { + Serializer.toString( + request, + "Parameters", + parameters, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionDeleter.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionDeleter.java new file mode 100644 index 0000000000..c3e9e1611a --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionDeleter.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ExecutionDeleter extends Deleter { + + private String pathFlowSid; + private String pathSid; + + public ExecutionDeleter(final String pathFlowSid, final String pathSid) { + this.pathFlowSid = pathFlowSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Executions/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Execution delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionFetcher.java new file mode 100644 index 0000000000..68f87943d6 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionFetcher.java @@ -0,0 +1,99 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionFetcher extends Fetcher { + + private String pathFlowSid; + private String pathSid; + + public ExecutionFetcher(final String pathFlowSid, final String pathSid) { + this.pathFlowSid = pathFlowSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Executions/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Execution fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Execution fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Execution content = Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionReader.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionReader.java new file mode 100644 index 0000000000..2a5496eb4b --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionReader.java @@ -0,0 +1,240 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ExecutionReader extends Reader { + + private String pathFlowSid; + private ZonedDateTime dateCreatedFrom; + private ZonedDateTime dateCreatedTo; + private Long pageSize; + + public ExecutionReader(final String pathFlowSid) { + this.pathFlowSid = pathFlowSid; + } + + public ExecutionReader setDateCreatedFrom( + final ZonedDateTime dateCreatedFrom + ) { + this.dateCreatedFrom = dateCreatedFrom; + return this; + } + + public ExecutionReader setDateCreatedTo(final ZonedDateTime dateCreatedTo) { + this.dateCreatedTo = dateCreatedTo; + return this; + } + + public ExecutionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "executions", + response.getContent(), + Execution.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Executions"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "executions", + response.getContent(), + Execution.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Execution read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "executions", + response.getContent(), + Execution.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (dateCreatedFrom != null) { + Serializer.toString( + request, + "DateCreatedFrom", + dateCreatedFrom, + ParameterType.QUERY + ); + } + + if (dateCreatedTo != null) { + Serializer.toString( + request, + "DateCreatedTo", + dateCreatedTo, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionUpdater.java b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionUpdater.java new file mode 100644 index 0000000000..e3691e6a74 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/ExecutionUpdater.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionUpdater extends Updater { + + private String pathFlowSid; + private String pathSid; + private Execution.Status status; + + public ExecutionUpdater( + final String pathFlowSid, + final String pathSid, + final Execution.Status status + ) { + this.pathFlowSid = pathFlowSid; + this.pathSid = pathSid; + this.status = status; + } + + public ExecutionUpdater setStatus(final Execution.Status status) { + this.status = status; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Executions/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.STUDIO.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Execution update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Execution update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Execution content = Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContext.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContext.java index e8e6853b18..842f852af7 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContext.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContext.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow.engagement; @@ -11,55 +18,45 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class EngagementContext extends Resource { - private static final long serialVersionUID = 165571935124227L; - /** - * Create a EngagementContextFetcher to execute fetch. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - * @return EngagementContextFetcher capable of executing the fetch - */ - public static EngagementContextFetcher fetcher(final String pathFlowSid, - final String pathEngagementSid) { + public static EngagementContextFetcher fetcher( + final String pathFlowSid, + final String pathEngagementSid + ) { return new EngagementContextFetcher(pathFlowSid, pathEngagementSid); } /** - * Converts a JSON String into a EngagementContext object using the provided - * ObjectMapper. - * + * Converts a JSON String into a EngagementContext object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return EngagementContext object represented by the provided JSON */ - public static EngagementContext fromJson(final String json, final ObjectMapper objectMapper) { + public static EngagementContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EngagementContext.class); @@ -71,14 +68,17 @@ public static EngagementContext fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a EngagementContext object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a EngagementContext object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return EngagementContext object represented by the provided JSON */ - public static EngagementContext fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static EngagementContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, EngagementContext.class); @@ -89,23 +89,41 @@ public static EngagementContext fromJson(final InputStream json, final ObjectMap } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final Map context; + + @Getter + private final Object context; + + @Getter private final String engagementSid; + + @Getter private final String flowSid; + + @Getter private final URI url; @JsonCreator - private EngagementContext(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("context") - final Map context, - @JsonProperty("engagement_sid") - final String engagementSid, - @JsonProperty("flow_sid") - final String flowSid, - @JsonProperty("url") - final URI url) { + private EngagementContext( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("engagement_sid") final String engagementSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.context = context; this.engagementSid = engagementSid; @@ -113,51 +131,6 @@ private EngagementContext(@JsonProperty("account_sid") this.url = url; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The context. - * - * @return The context - */ - public final Map getContext() { - return this.context; - } - - /** - * Returns The The engagement_sid. - * - * @return The engagement_sid - */ - public final String getEngagementSid() { - return this.engagementSid; - } - - /** - * Returns The The flow_sid. - * - * @return The flow_sid - */ - public final String getFlowSid() { - return this.flowSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -169,31 +142,17 @@ public boolean equals(final Object o) { } EngagementContext other = (EngagementContext) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(context, other.context) && - Objects.equals(engagementSid, other.engagementSid) && - Objects.equals(flowSid, other.flowSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(engagementSid, other.engagementSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - context, - engagementSid, - flowSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("context", context) - .add("engagementSid", engagementSid) - .add("flowSid", flowSid) - .add("url", url) - .toString(); + return Objects.hash(accountSid, context, engagementSid, flowSid, url); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContextFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContextFetcher.java index 9854c63025..67d931f8cf 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContextFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/EngagementContextFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow.engagement; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class EngagementContextFetcher extends Fetcher { - private final String pathFlowSid; - private final String pathEngagementSid; - /** - * Construct a new EngagementContextFetcher. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - */ - public EngagementContextFetcher(final String pathFlowSid, - final String pathEngagementSid) { + private String pathFlowSid; + private String pathEngagementSid; + + public EngagementContextFetcher( + final String pathFlowSid, + final String pathEngagementSid + ) { this.pathFlowSid = pathFlowSid; this.pathEngagementSid = pathEngagementSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched EngagementContext - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public EngagementContext fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Context"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "EngagementSid" + "}", + this.pathEngagementSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathEngagementSid + "/Context", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("EngagementContext fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "EngagementContext fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public EngagementContext fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EngagementContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return EngagementContext.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EngagementContext content = EngagementContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/Step.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/Step.java index 438d028fbd..b31b0b340e 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/Step.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/Step.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow.engagement; @@ -11,70 +18,57 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Step extends Resource { - private static final long serialVersionUID = 221317830784095L; - /** - * Create a StepReader to execute read. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - * @return StepReader capable of executing the read - */ - public static StepReader reader(final String pathFlowSid, - final String pathEngagementSid) { - return new StepReader(pathFlowSid, pathEngagementSid); + public static StepFetcher fetcher( + final String pathFlowSid, + final String pathEngagementSid, + final String pathSid + ) { + return new StepFetcher(pathFlowSid, pathEngagementSid, pathSid); } - /** - * Create a StepFetcher to execute fetch. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - * @param pathSid The sid - * @return StepFetcher capable of executing the fetch - */ - public static StepFetcher fetcher(final String pathFlowSid, - final String pathEngagementSid, - final String pathSid) { - return new StepFetcher(pathFlowSid, pathEngagementSid, pathSid); + public static StepReader reader( + final String pathFlowSid, + final String pathEngagementSid + ) { + return new StepReader(pathFlowSid, pathEngagementSid); } /** * Converts a JSON String into a Step object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Step object represented by the provided JSON */ - public static Step fromJson(final String json, final ObjectMapper objectMapper) { + public static Step fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Step.class); @@ -88,12 +82,15 @@ public static Step fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Step object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Step object represented by the provided JSON */ - public static Step fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Step fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Step.class); @@ -104,164 +101,101 @@ public static Step fromJson(final InputStream json, final ObjectMapper objectMap } } - private final String sid; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String flowSid; - private final String engagementSid; - private final String name; - private final Map context; - private final String transitionedFrom; - private final String transitionedTo; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final Map links; - @JsonCreator - private Step(@JsonProperty("sid") - final String sid, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("flow_sid") - final String flowSid, - @JsonProperty("engagement_sid") - final String engagementSid, - @JsonProperty("name") - final String name, - @JsonProperty("context") - final Map context, - @JsonProperty("transitioned_from") - final String transitionedFrom, - @JsonProperty("transitioned_to") - final String transitionedTo, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.accountSid = accountSid; - this.flowSid = flowSid; - this.engagementSid = engagementSid; - this.name = name; - this.context = context; - this.transitionedFrom = transitionedFrom; - this.transitionedTo = transitionedTo; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.links = links; - } + @Getter + private final Object context; - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The flow_sid. - * - * @return The flow_sid - */ - public final String getFlowSid() { - return this.flowSid; - } + @Getter + private final String engagementSid; - /** - * Returns The The engagement_sid. - * - * @return The engagement_sid - */ - public final String getEngagementSid() { - return this.engagementSid; - } + @Getter + private final String flowSid; - /** - * Returns The The name. - * - * @return The name - */ - public final String getName() { - return this.name; - } + @Getter + private final Map links; - /** - * Returns The The context. - * - * @return The context - */ - public final Map getContext() { - return this.context; - } + @Getter + private final String name; - /** - * Returns The The transitioned_from. - * - * @return The transitioned_from - */ - public final String getTransitionedFrom() { - return this.transitionedFrom; - } + @Getter + private final String parentStepSid; - /** - * Returns The The transitioned_to. - * - * @return The transitioned_to - */ - public final String getTransitionedTo() { - return this.transitionedTo; - } + @Getter + private final String sid; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String transitionedFrom; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String transitionedTo; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String type; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @Getter + private final URI url; + + @JsonCreator + private Step( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("engagement_sid") final String engagementSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("links") final Map links, + @JsonProperty("name") final String name, + @JsonProperty("parent_step_sid") final String parentStepSid, + @JsonProperty("sid") final String sid, + @JsonProperty("transitioned_from") final String transitionedFrom, + @JsonProperty("transitioned_to") final String transitionedTo, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.context = context; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.engagementSid = engagementSid; + this.flowSid = flowSid; + this.links = links; + this.name = name; + this.parentStepSid = parentStepSid; + this.sid = sid; + this.transitionedFrom = transitionedFrom; + this.transitionedTo = transitionedTo; + this.type = type; + this.url = url; } @Override @@ -275,52 +209,41 @@ public boolean equals(final Object o) { } Step other = (Step) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(flowSid, other.flowSid) && - Objects.equals(engagementSid, other.engagementSid) && - Objects.equals(name, other.name) && - Objects.equals(context, other.context) && - Objects.equals(transitionedFrom, other.transitionedFrom) && - Objects.equals(transitionedTo, other.transitionedTo) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(engagementSid, other.engagementSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(links, other.links) && + Objects.equals(name, other.name) && + Objects.equals(parentStepSid, other.parentStepSid) && + Objects.equals(sid, other.sid) && + Objects.equals(transitionedFrom, other.transitionedFrom) && + Objects.equals(transitionedTo, other.transitionedTo) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - accountSid, - flowSid, - engagementSid, - name, - context, - transitionedFrom, - transitionedTo, - dateCreated, - dateUpdated, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("accountSid", accountSid) - .add("flowSid", flowSid) - .add("engagementSid", engagementSid) - .add("name", name) - .add("context", context) - .add("transitionedFrom", transitionedFrom) - .add("transitionedTo", transitionedTo) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + context, + dateCreated, + dateUpdated, + engagementSid, + flowSid, + links, + name, + parentStepSid, + sid, + transitionedFrom, + transitionedTo, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepFetcher.java index c18fc46c51..b77a1a1ecc 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow.engagement; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,85 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class StepFetcher extends Fetcher { - private final String pathFlowSid; - private final String pathEngagementSid; - private final String pathSid; - /** - * Construct a new StepFetcher. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - * @param pathSid The sid - */ - public StepFetcher(final String pathFlowSid, - final String pathEngagementSid, - final String pathSid) { + private String pathFlowSid; + private String pathEngagementSid; + private String pathSid; + + public StepFetcher( + final String pathFlowSid, + final String pathEngagementSid, + final String pathSid + ) { this.pathFlowSid = pathFlowSid; this.pathEngagementSid = pathEngagementSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Step - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Step fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "EngagementSid" + "}", + this.pathEngagementSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathEngagementSid + "/Steps/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Step fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Step fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Step fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Step.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Step content = Step.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepReader.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepReader.java index cdd938cb61..fbe338f698 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepReader.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/StepReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow.engagement; @@ -10,167 +17,197 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class StepReader extends Reader { - private final String pathFlowSid; - private final String pathEngagementSid; - - /** - * Construct a new StepReader. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - */ - public StepReader(final String pathFlowSid, - final String pathEngagementSid) { + + private String pathFlowSid; + private String pathEngagementSid; + private Long pageSize; + + public StepReader( + final String pathFlowSid, + final String pathEngagementSid + ) { this.pathFlowSid = pathFlowSid; this.pathEngagementSid = pathEngagementSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Step ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public StepReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Step ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "steps", + response.getContent(), + Step.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "EngagementSid" + "}", + this.pathEngagementSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathEngagementSid + "/Steps", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Step ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "steps", + response.getContent(), + Step.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Step read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "steps", + response.getContent(), + Step.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.STUDIO.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.STUDIO.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Step Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Step read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "steps", - response.getContent(), - Step.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContext.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContext.java index 08141aa9ed..ed362ef291 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContext.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContext.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow.engagement.step; @@ -11,57 +18,50 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class StepContext extends Resource { - private static final long serialVersionUID = 27085286936981L; - /** - * Create a StepContextFetcher to execute fetch. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - * @param pathStepSid The step_sid - * @return StepContextFetcher capable of executing the fetch - */ - public static StepContextFetcher fetcher(final String pathFlowSid, - final String pathEngagementSid, - final String pathStepSid) { - return new StepContextFetcher(pathFlowSid, pathEngagementSid, pathStepSid); + public static StepContextFetcher fetcher( + final String pathFlowSid, + final String pathEngagementSid, + final String pathStepSid + ) { + return new StepContextFetcher( + pathFlowSid, + pathEngagementSid, + pathStepSid + ); } /** - * Converts a JSON String into a StepContext object using the provided - * ObjectMapper. - * + * Converts a JSON String into a StepContext object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return StepContext object represented by the provided JSON */ - public static StepContext fromJson(final String json, final ObjectMapper objectMapper) { + public static StepContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StepContext.class); @@ -75,12 +75,15 @@ public static StepContext fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a StepContext object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return StepContext object represented by the provided JSON */ - public static StepContext fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static StepContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StepContext.class); @@ -91,26 +94,45 @@ public static StepContext fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final Map context; + + @Getter + private final Object context; + + @Getter private final String engagementSid; + + @Getter private final String flowSid; + + @Getter private final String stepSid; + + @Getter private final URI url; @JsonCreator - private StepContext(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("context") - final Map context, - @JsonProperty("engagement_sid") - final String engagementSid, - @JsonProperty("flow_sid") - final String flowSid, - @JsonProperty("step_sid") - final String stepSid, - @JsonProperty("url") - final URI url) { + private StepContext( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("engagement_sid") final String engagementSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("step_sid") final String stepSid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; this.context = context; this.engagementSid = engagementSid; @@ -119,60 +141,6 @@ private StepContext(@JsonProperty("account_sid") this.url = url; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The context. - * - * @return The context - */ - public final Map getContext() { - return this.context; - } - - /** - * Returns The The engagement_sid. - * - * @return The engagement_sid - */ - public final String getEngagementSid() { - return this.engagementSid; - } - - /** - * Returns The The flow_sid. - * - * @return The flow_sid - */ - public final String getFlowSid() { - return this.flowSid; - } - - /** - * Returns The The step_sid. - * - * @return The step_sid - */ - public final String getStepSid() { - return this.stepSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -184,34 +152,25 @@ public boolean equals(final Object o) { } StepContext other = (StepContext) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(context, other.context) && - Objects.equals(engagementSid, other.engagementSid) && - Objects.equals(flowSid, other.flowSid) && - Objects.equals(stepSid, other.stepSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(engagementSid, other.engagementSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(stepSid, other.stepSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - context, - engagementSid, - flowSid, - stepSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("context", context) - .add("engagementSid", engagementSid) - .add("flowSid", flowSid) - .add("stepSid", stepSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + context, + engagementSid, + flowSid, + stepSid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContextFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContextFetcher.java index 8853139d14..61ebf4bae5 100644 --- a/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContextFetcher.java +++ b/src/main/java/com/twilio/rest/studio/v1/flow/engagement/step/StepContextFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.studio.v1.flow.engagement.step; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,88 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class StepContextFetcher extends Fetcher { - private final String pathFlowSid; - private final String pathEngagementSid; - private final String pathStepSid; - /** - * Construct a new StepContextFetcher. - * - * @param pathFlowSid The flow_sid - * @param pathEngagementSid The engagement_sid - * @param pathStepSid The step_sid - */ - public StepContextFetcher(final String pathFlowSid, - final String pathEngagementSid, - final String pathStepSid) { + private String pathFlowSid; + private String pathEngagementSid; + private String pathStepSid; + + public StepContextFetcher( + final String pathFlowSid, + final String pathEngagementSid, + final String pathStepSid + ) { this.pathFlowSid = pathFlowSid; this.pathEngagementSid = pathEngagementSid; this.pathStepSid = pathStepSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched StepContext - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public StepContext fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Flows/{FlowSid}/Engagements/{EngagementSid}/Steps/{StepSid}/Context"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "EngagementSid" + "}", + this.pathEngagementSid.toString() + ); + path = path.replace("{" + "StepSid" + "}", this.pathStepSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.STUDIO.toString(), - "/v1/Flows/" + this.pathFlowSid + "/Engagements/" + this.pathEngagementSid + "/Steps/" + this.pathStepSid + "/Context", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("StepContext fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "StepContext fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public StepContext fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return StepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return StepContext.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + StepContext content = StepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContext.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContext.java new file mode 100644 index 0000000000..e6e7339ff8 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContext.java @@ -0,0 +1,158 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExecutionContext extends Resource { + + public static ExecutionContextFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid + ) { + return new ExecutionContextFetcher(pathFlowSid, pathExecutionSid); + } + + /** + * Converts a JSON String into a ExecutionContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionContext object represented by the provided JSON + */ + public static ExecutionContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionContext.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExecutionContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionContext object represented by the provided JSON + */ + public static ExecutionContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionContext.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object context; + + @Getter + private final String executionSid; + + @Getter + private final String flowSid; + + @Getter + private final URI url; + + @JsonCreator + private ExecutionContext( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.context = context; + this.executionSid = executionSid; + this.flowSid = flowSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionContext other = (ExecutionContext) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, context, executionSid, flowSid, url); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContextFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContextFetcher.java new file mode 100644 index 0000000000..bfc60f7589 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionContextFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow.execution; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionContextFetcher extends Fetcher { + + private String pathFlowSid; + private String pathExecutionSid; + + public ExecutionContextFetcher( + final String pathFlowSid, + final String pathExecutionSid + ) { + this.pathFlowSid = pathFlowSid; + this.pathExecutionSid = pathExecutionSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Context"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExecutionContext fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExecutionContext fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExecutionContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExecutionContext content = ExecutionContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStep.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStep.java new file mode 100644 index 0000000000..13f0f0c510 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStep.java @@ -0,0 +1,249 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExecutionStep extends Resource { + + public static ExecutionStepFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathSid + ) { + return new ExecutionStepFetcher(pathFlowSid, pathExecutionSid, pathSid); + } + + public static ExecutionStepReader reader( + final String pathFlowSid, + final String pathExecutionSid + ) { + return new ExecutionStepReader(pathFlowSid, pathExecutionSid); + } + + /** + * Converts a JSON String into a ExecutionStep object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStep object represented by the provided JSON + */ + public static ExecutionStep fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionStep.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExecutionStep object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStep object represented by the provided JSON + */ + public static ExecutionStep fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionStep.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object context; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String executionSid; + + @Getter + private final String flowSid; + + @Getter + private final Map links; + + @Getter + private final String name; + + @Getter + private final String parentStepSid; + + @Getter + private final String sid; + + @Getter + private final String transitionedFrom; + + @Getter + private final String transitionedTo; + + @Getter + private final String type; + + @Getter + private final URI url; + + @JsonCreator + private ExecutionStep( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("links") final Map links, + @JsonProperty("name") final String name, + @JsonProperty("parent_step_sid") final String parentStepSid, + @JsonProperty("sid") final String sid, + @JsonProperty("transitioned_from") final String transitionedFrom, + @JsonProperty("transitioned_to") final String transitionedTo, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.context = context; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.executionSid = executionSid; + this.flowSid = flowSid; + this.links = links; + this.name = name; + this.parentStepSid = parentStepSid; + this.sid = sid; + this.transitionedFrom = transitionedFrom; + this.transitionedTo = transitionedTo; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionStep other = (ExecutionStep) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(links, other.links) && + Objects.equals(name, other.name) && + Objects.equals(parentStepSid, other.parentStepSid) && + Objects.equals(sid, other.sid) && + Objects.equals(transitionedFrom, other.transitionedFrom) && + Objects.equals(transitionedTo, other.transitionedTo) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + context, + dateCreated, + dateUpdated, + executionSid, + flowSid, + links, + name, + parentStepSid, + sid, + transitionedFrom, + transitionedTo, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepFetcher.java new file mode 100644 index 0000000000..17662d575b --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow.execution; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionStepFetcher extends Fetcher { + + private String pathFlowSid; + private String pathExecutionSid; + private String pathSid; + + public ExecutionStepFetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathSid + ) { + this.pathFlowSid = pathFlowSid; + this.pathExecutionSid = pathExecutionSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExecutionStep fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExecutionStep fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExecutionStep.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExecutionStep content = ExecutionStep.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepReader.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepReader.java new file mode 100644 index 0000000000..827b22e889 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/ExecutionStepReader.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow.execution; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionStepReader extends Reader { + + private String pathFlowSid; + private String pathExecutionSid; + private Long pageSize; + + public ExecutionStepReader( + final String pathFlowSid, + final String pathExecutionSid + ) { + this.pathFlowSid = pathFlowSid; + this.pathExecutionSid = pathExecutionSid; + } + + public ExecutionStepReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "steps", + response.getContent(), + ExecutionStep.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "steps", + response.getContent(), + ExecutionStep.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ExecutionStep read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "steps", + response.getContent(), + ExecutionStep.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContext.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContext.java new file mode 100644 index 0000000000..d748acb275 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContext.java @@ -0,0 +1,176 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow.execution.executionstep; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExecutionStepContext extends Resource { + + public static ExecutionStepContextFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathStepSid + ) { + return new ExecutionStepContextFetcher( + pathFlowSid, + pathExecutionSid, + pathStepSid + ); + } + + /** + * Converts a JSON String into a ExecutionStepContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStepContext object represented by the provided JSON + */ + public static ExecutionStepContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionStepContext.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExecutionStepContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStepContext object represented by the provided JSON + */ + public static ExecutionStepContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionStepContext.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object context; + + @Getter + private final String executionSid; + + @Getter + private final String flowSid; + + @Getter + private final String stepSid; + + @Getter + private final URI url; + + @JsonCreator + private ExecutionStepContext( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("step_sid") final String stepSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.context = context; + this.executionSid = executionSid; + this.flowSid = flowSid; + this.stepSid = stepSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionStepContext other = (ExecutionStepContext) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(stepSid, other.stepSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + context, + executionSid, + flowSid, + stepSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContextFetcher.java b/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContextFetcher.java new file mode 100644 index 0000000000..5b89ba89a2 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v1/flow/execution/executionstep/ExecutionStepContextFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v1.flow.execution.executionstep; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionStepContextFetcher extends Fetcher { + + private String pathFlowSid; + private String pathExecutionSid; + private String pathStepSid; + + public ExecutionStepContextFetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathStepSid + ) { + this.pathFlowSid = pathFlowSid; + this.pathExecutionSid = pathExecutionSid; + this.pathStepSid = pathStepSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{StepSid}/Context"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + path = path.replace("{" + "StepSid" + "}", this.pathStepSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExecutionStepContext fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExecutionStepContext fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExecutionStepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExecutionStepContext content = ExecutionStepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/Flow.java b/src/main/java/com/twilio/rest/studio/v2/Flow.java new file mode 100644 index 0000000000..2e7493fecf --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/Flow.java @@ -0,0 +1,299 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Flow extends Resource { + + public static FlowCreator creator( + final String friendlyName, + final Flow.Status status, + final Object definition + ) { + return new FlowCreator(friendlyName, status, definition); + } + + public static FlowDeleter deleter(final String pathSid) { + return new FlowDeleter(pathSid); + } + + public static FlowFetcher fetcher(final String pathSid) { + return new FlowFetcher(pathSid); + } + + public static FlowReader reader() { + return new FlowReader(); + } + + public static FlowUpdater updater( + final String pathSid, + final Flow.Status status + ) { + return new FlowUpdater(pathSid, status); + } + + public enum Status { + DRAFT("draft"), + PUBLISHED("published"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a Flow object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Flow object represented by the provided JSON + */ + public static Flow fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Flow.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Flow object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Flow object represented by the provided JSON + */ + public static Flow fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Flow.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String authorSid; + + @Getter + private final String commitMessage; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Object definition; + + @Getter + private final List errors; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final Integer revision; + + @Getter + private final String sid; + + @Getter + private final Flow.Status status; + + @Getter + private final URI url; + + @Getter + private final Boolean valid; + + @Getter + private final List warnings; + + @Getter + private final URI webhookUrl; + + @JsonCreator + private Flow( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("author_sid") final String authorSid, + @JsonProperty("commit_message") final String commitMessage, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("definition") final Object definition, + @JsonProperty("errors") final List errors, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final Integer revision, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Flow.Status status, + @JsonProperty("url") final URI url, + @JsonProperty("valid") final Boolean valid, + @JsonProperty("warnings") final List warnings, + @JsonProperty("webhook_url") final URI webhookUrl + ) { + this.accountSid = accountSid; + this.authorSid = authorSid; + this.commitMessage = commitMessage; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.definition = definition; + this.errors = errors; + this.friendlyName = friendlyName; + this.links = links; + this.revision = revision; + this.sid = sid; + this.status = status; + this.url = url; + this.valid = valid; + this.warnings = warnings; + this.webhookUrl = webhookUrl; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Flow other = (Flow) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(authorSid, other.authorSid) && + Objects.equals(commitMessage, other.commitMessage) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(definition, other.definition) && + Objects.equals(errors, other.errors) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(valid, other.valid) && + Objects.equals(warnings, other.warnings) && + Objects.equals(webhookUrl, other.webhookUrl) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + authorSid, + commitMessage, + dateCreated, + dateUpdated, + definition, + errors, + friendlyName, + links, + revision, + sid, + status, + url, + valid, + warnings, + webhookUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowCreator.java b/src/main/java/com/twilio/rest/studio/v2/FlowCreator.java new file mode 100644 index 0000000000..460d235678 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/FlowCreator.java @@ -0,0 +1,178 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlowCreator extends Creator { + + private String friendlyName; + private Flow.Status status; + private Object definition; + private String commitMessage; + private String authorSid; + + public FlowCreator( + final String friendlyName, + final Flow.Status status, + final Object definition + ) { + this.friendlyName = friendlyName; + this.status = status; + this.definition = definition; + } + + public FlowCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public FlowCreator setStatus(final Flow.Status status) { + this.status = status; + return this; + } + + public FlowCreator setDefinition(final Object definition) { + this.definition = definition; + return this; + } + + public FlowCreator setCommitMessage(final String commitMessage) { + this.commitMessage = commitMessage; + return this; + } + + public FlowCreator setAuthorSid(final String authorSid) { + this.authorSid = authorSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows"; + + Request request = new Request( + HttpMethod.POST, + Domains.STUDIO.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Flow creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Flow create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Flow.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Flow content = Flow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (definition != null) { + Serializer.toString( + request, + "Definition", + definition, + ParameterType.URLENCODED + ); + } + + if (commitMessage != null) { + Serializer.toString( + request, + "CommitMessage", + commitMessage, + ParameterType.URLENCODED + ); + } + + if (authorSid != null) { + Serializer.toString( + request, + "AuthorSid", + authorSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowDeleter.java b/src/main/java/com/twilio/rest/studio/v2/FlowDeleter.java new file mode 100644 index 0000000000..1436fd90a7 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/FlowDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class FlowDeleter extends Deleter { + + private String pathSid; + + public FlowDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Flow delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowFetcher.java b/src/main/java/com/twilio/rest/studio/v2/FlowFetcher.java new file mode 100644 index 0000000000..8c3973e5fa --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/FlowFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlowFetcher extends Fetcher { + + private String pathSid; + + public FlowFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Flow fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Flow fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Flow.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Flow content = Flow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowReader.java b/src/main/java/com/twilio/rest/studio/v2/FlowReader.java new file mode 100644 index 0000000000..8bcdea72d5 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/FlowReader.java @@ -0,0 +1,198 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlowReader extends Reader { + + private Long pageSize; + + public FlowReader() {} + + public FlowReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flows", + response.getContent(), + Flow.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Flows"; + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "flows", + response.getContent(), + Flow.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Flow read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "flows", + response.getContent(), + Flow.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowUpdater.java b/src/main/java/com/twilio/rest/studio/v2/FlowUpdater.java new file mode 100644 index 0000000000..0735f1ac5e --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/FlowUpdater.java @@ -0,0 +1,176 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlowUpdater extends Updater { + + private String pathSid; + private Flow.Status status; + private String friendlyName; + private Object definition; + private String commitMessage; + private String authorSid; + + public FlowUpdater(final String pathSid, final Flow.Status status) { + this.pathSid = pathSid; + this.status = status; + } + + public FlowUpdater setStatus(final Flow.Status status) { + this.status = status; + return this; + } + + public FlowUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public FlowUpdater setDefinition(final Object definition) { + this.definition = definition; + return this; + } + + public FlowUpdater setCommitMessage(final String commitMessage) { + this.commitMessage = commitMessage; + return this; + } + + public FlowUpdater setAuthorSid(final String authorSid) { + this.authorSid = authorSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.STUDIO.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Flow update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Flow update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Flow.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Flow content = Flow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (definition != null) { + Serializer.toString( + request, + "Definition", + definition, + ParameterType.URLENCODED + ); + } + + if (commitMessage != null) { + Serializer.toString( + request, + "CommitMessage", + commitMessage, + ParameterType.URLENCODED + ); + } + + if (authorSid != null) { + Serializer.toString( + request, + "AuthorSid", + authorSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowValidate.java b/src/main/java/com/twilio/rest/studio/v2/FlowValidate.java new file mode 100644 index 0000000000..1a3a15e94f --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/FlowValidate.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class FlowValidate extends Resource { + + public static FlowValidateUpdater updater( + final String friendlyName, + final FlowValidate.Status status, + final Object definition + ) { + return new FlowValidateUpdater(friendlyName, status, definition); + } + + public enum Status { + DRAFT("draft"), + PUBLISHED("published"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a FlowValidate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlowValidate object represented by the provided JSON + */ + public static FlowValidate fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlowValidate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a FlowValidate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlowValidate object represented by the provided JSON + */ + public static FlowValidate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlowValidate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Boolean valid; + + @JsonCreator + private FlowValidate(@JsonProperty("valid") final Boolean valid) { + this.valid = valid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FlowValidate other = (FlowValidate) o; + return (Objects.equals(valid, other.valid)); + } + + @Override + public int hashCode() { + return Objects.hash(valid); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/FlowValidateUpdater.java b/src/main/java/com/twilio/rest/studio/v2/FlowValidateUpdater.java new file mode 100644 index 0000000000..54a08f47be --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/FlowValidateUpdater.java @@ -0,0 +1,166 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlowValidateUpdater extends Updater { + + private String friendlyName; + private FlowValidate.Status status; + private Object definition; + private String commitMessage; + + public FlowValidateUpdater( + final String friendlyName, + final FlowValidate.Status status, + final Object definition + ) { + this.friendlyName = friendlyName; + this.status = status; + this.definition = definition; + } + + public FlowValidateUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public FlowValidateUpdater setStatus(final FlowValidate.Status status) { + this.status = status; + return this; + } + + public FlowValidateUpdater setDefinition(final Object definition) { + this.definition = definition; + return this; + } + + public FlowValidateUpdater setCommitMessage(final String commitMessage) { + this.commitMessage = commitMessage; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/Validate"; + + Request request = new Request( + HttpMethod.POST, + Domains.STUDIO.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlowValidate update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlowValidate update(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlowValidate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlowValidate content = FlowValidate.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (definition != null) { + Serializer.toString( + request, + "Definition", + definition, + ParameterType.URLENCODED + ); + } + + if (commitMessage != null) { + Serializer.toString( + request, + "CommitMessage", + commitMessage, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/Execution.java b/src/main/java/com/twilio/rest/studio/v2/flow/Execution.java new file mode 100644 index 0000000000..fce7d5419f --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/Execution.java @@ -0,0 +1,289 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Execution extends Resource { + + public static ExecutionCreator creator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { + return new ExecutionCreator(pathFlowSid, to, from); + } + + public static ExecutionDeleter deleter( + final String pathFlowSid, + final String pathSid + ) { + return new ExecutionDeleter(pathFlowSid, pathSid); + } + + public static ExecutionFetcher fetcher( + final String pathFlowSid, + final String pathSid + ) { + return new ExecutionFetcher(pathFlowSid, pathSid); + } + + public static ExecutionReader reader(final String pathFlowSid) { + return new ExecutionReader(pathFlowSid); + } + + public static ExecutionUpdater updater( + final String pathFlowSid, + final String pathSid, + final Execution.Status status + ) { + return new ExecutionUpdater(pathFlowSid, pathSid, status); + } + + public enum Status { + ACTIVE("active"), + ENDED("ended"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a Execution object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Execution object represented by the provided JSON + */ + public static Execution fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Execution.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Execution object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Execution object represented by the provided JSON + */ + public static Execution fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Execution.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String contactChannelAddress; + + @Getter + private final String contactSid; + + @Getter + private final Object context; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String flowSid; + + @Getter + private final Integer flowVersion; + + @Getter + private final String initiatedBy; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final Execution.Status status; + + @Getter + private final URI url; + + @JsonCreator + private Execution( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "contact_channel_address" + ) final String contactChannelAddress, + @JsonProperty("contact_sid") final String contactSid, + @JsonProperty("context") final Object context, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("flow_version") final Integer flowVersion, + @JsonProperty("initiated_by") final String initiatedBy, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Execution.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.contactChannelAddress = contactChannelAddress; + this.contactSid = contactSid; + this.context = context; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.flowSid = flowSid; + this.flowVersion = flowVersion; + this.initiatedBy = initiatedBy; + this.links = links; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Execution other = (Execution) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + contactChannelAddress, + other.contactChannelAddress + ) && + Objects.equals(contactSid, other.contactSid) && + Objects.equals(context, other.context) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(flowVersion, other.flowVersion) && + Objects.equals(initiatedBy, other.initiatedBy) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + contactChannelAddress, + contactSid, + context, + dateCreated, + dateUpdated, + flowSid, + flowVersion, + initiatedBy, + links, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionCreator.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionCreator.java new file mode 100644 index 0000000000..d49d54858a --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionCreator.java @@ -0,0 +1,158 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionCreator extends Creator { + + private String pathFlowSid; + private com.twilio.type.PhoneNumber to; + private com.twilio.type.PhoneNumber from; + private Object parameters; + + public ExecutionCreator( + final String pathFlowSid, + final com.twilio.type.PhoneNumber to, + final com.twilio.type.PhoneNumber from + ) { + this.pathFlowSid = pathFlowSid; + this.to = to; + this.from = from; + } + + public ExecutionCreator setTo(final com.twilio.type.PhoneNumber to) { + this.to = to; + return this; + } + + public ExecutionCreator setTo(final String to) { + return setTo(Promoter.phoneNumberFromString(to)); + } + + public ExecutionCreator setFrom(final com.twilio.type.PhoneNumber from) { + this.from = from; + return this; + } + + public ExecutionCreator setFrom(final String from) { + return setFrom(Promoter.phoneNumberFromString(from)); + } + + public ExecutionCreator setParameters(final Object parameters) { + this.parameters = parameters; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{FlowSid}/Executions"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.STUDIO.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Execution creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Execution create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Execution content = Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (to != null) { + Serializer.toString(request, "To", to, ParameterType.URLENCODED); + } + + if (from != null) { + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); + } + + if (parameters != null) { + Serializer.toString( + request, + "Parameters", + parameters, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionDeleter.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionDeleter.java new file mode 100644 index 0000000000..7600faed9b --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionDeleter.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ExecutionDeleter extends Deleter { + + private String pathFlowSid; + private String pathSid; + + public ExecutionDeleter(final String pathFlowSid, final String pathSid) { + this.pathFlowSid = pathFlowSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{FlowSid}/Executions/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Execution delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionFetcher.java new file mode 100644 index 0000000000..30396861d5 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionFetcher.java @@ -0,0 +1,99 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionFetcher extends Fetcher { + + private String pathFlowSid; + private String pathSid; + + public ExecutionFetcher(final String pathFlowSid, final String pathSid) { + this.pathFlowSid = pathFlowSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{FlowSid}/Executions/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Execution fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Execution fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Execution content = Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionReader.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionReader.java new file mode 100644 index 0000000000..62cb6a5fc0 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionReader.java @@ -0,0 +1,250 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class ExecutionReader extends Reader { + + private String pathFlowSid; + private Execution.Status status; + private ZonedDateTime dateCreatedFrom; + private ZonedDateTime dateCreatedTo; + private Long pageSize; + + public ExecutionReader(final String pathFlowSid) { + this.pathFlowSid = pathFlowSid; + } + + public ExecutionReader setStatus(final Execution.Status status) { + this.status = status; + return this; + } + + public ExecutionReader setDateCreatedFrom( + final ZonedDateTime dateCreatedFrom + ) { + this.dateCreatedFrom = dateCreatedFrom; + return this; + } + + public ExecutionReader setDateCreatedTo(final ZonedDateTime dateCreatedTo) { + this.dateCreatedTo = dateCreatedTo; + return this; + } + + public ExecutionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "executions", + response.getContent(), + Execution.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{FlowSid}/Executions"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "executions", + response.getContent(), + Execution.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Execution read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "executions", + response.getContent(), + Execution.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (status != null) { + Serializer.toString(request, "status", status, ParameterType.QUERY); + } + + if (dateCreatedFrom != null) { + Serializer.toString( + request, + "DateCreatedFrom", + dateCreatedFrom, + ParameterType.QUERY + ); + } + + if (dateCreatedTo != null) { + Serializer.toString( + request, + "DateCreatedTo", + dateCreatedTo, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionUpdater.java b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionUpdater.java new file mode 100644 index 0000000000..708aa43583 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/ExecutionUpdater.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionUpdater extends Updater { + + private String pathFlowSid; + private String pathSid; + private Execution.Status status; + + public ExecutionUpdater( + final String pathFlowSid, + final String pathSid, + final Execution.Status status + ) { + this.pathFlowSid = pathFlowSid; + this.pathSid = pathSid; + this.status = status; + } + + public ExecutionUpdater setStatus(final Execution.Status status) { + this.status = status; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{FlowSid}/Executions/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.STUDIO.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Execution update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Execution update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Execution content = Execution.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevision.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevision.java new file mode 100644 index 0000000000..e7f5f50151 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevision.java @@ -0,0 +1,261 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class FlowRevision extends Resource { + + public static FlowRevisionFetcher fetcher( + final String pathSid, + final String pathRevision + ) { + return new FlowRevisionFetcher(pathSid, pathRevision); + } + + public static FlowRevisionReader reader(final String pathSid) { + return new FlowRevisionReader(pathSid); + } + + public enum Status { + DRAFT("draft"), + PUBLISHED("published"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a FlowRevision object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlowRevision object represented by the provided JSON + */ + public static FlowRevision fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlowRevision.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a FlowRevision object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlowRevision object represented by the provided JSON + */ + public static FlowRevision fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlowRevision.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String authorSid; + + @Getter + private final String commitMessage; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Object definition; + + @Getter + private final List errors; + + @Getter + private final String friendlyName; + + @Getter + private final Integer revision; + + @Getter + private final String sid; + + @Getter + private final FlowRevision.Status status; + + @Getter + private final URI url; + + @Getter + private final Boolean valid; + + @JsonCreator + private FlowRevision( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("author_sid") final String authorSid, + @JsonProperty("commit_message") final String commitMessage, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("definition") final Object definition, + @JsonProperty("errors") final List errors, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("revision") final Integer revision, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final FlowRevision.Status status, + @JsonProperty("url") final URI url, + @JsonProperty("valid") final Boolean valid + ) { + this.accountSid = accountSid; + this.authorSid = authorSid; + this.commitMessage = commitMessage; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.definition = definition; + this.errors = errors; + this.friendlyName = friendlyName; + this.revision = revision; + this.sid = sid; + this.status = status; + this.url = url; + this.valid = valid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FlowRevision other = (FlowRevision) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(authorSid, other.authorSid) && + Objects.equals(commitMessage, other.commitMessage) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(definition, other.definition) && + Objects.equals(errors, other.errors) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(revision, other.revision) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) && + Objects.equals(valid, other.valid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + authorSid, + commitMessage, + dateCreated, + dateUpdated, + definition, + errors, + friendlyName, + revision, + sid, + status, + url, + valid + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionFetcher.java new file mode 100644 index 0000000000..f4d8fba02f --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionFetcher.java @@ -0,0 +1,103 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlowRevisionFetcher extends Fetcher { + + private String pathSid; + private String pathRevision; + + public FlowRevisionFetcher( + final String pathSid, + final String pathRevision + ) { + this.pathSid = pathSid; + this.pathRevision = pathRevision; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{Sid}/Revisions/{Revision}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + path = + path.replace("{" + "Revision" + "}", this.pathRevision.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlowRevision fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlowRevision fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlowRevision.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlowRevision content = FlowRevision.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionReader.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionReader.java new file mode 100644 index 0000000000..5d8a997c30 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowRevisionReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlowRevisionReader extends Reader { + + private String pathSid; + private Long pageSize; + + public FlowRevisionReader(final String pathSid) { + this.pathSid = pathSid; + } + + public FlowRevisionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "revisions", + response.getContent(), + FlowRevision.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{Sid}/Revisions"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "revisions", + response.getContent(), + FlowRevision.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "FlowRevision read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "revisions", + response.getContent(), + FlowRevision.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUser.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUser.java new file mode 100644 index 0000000000..82d5102620 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUser.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class FlowTestUser extends Resource { + + public static FlowTestUserFetcher fetcher(final String pathSid) { + return new FlowTestUserFetcher(pathSid); + } + + public static FlowTestUserUpdater updater( + final String pathSid, + final List testUsers + ) { + return new FlowTestUserUpdater(pathSid, testUsers); + } + + /** + * Converts a JSON String into a FlowTestUser object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return FlowTestUser object represented by the provided JSON + */ + public static FlowTestUser fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlowTestUser.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a FlowTestUser object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return FlowTestUser object represented by the provided JSON + */ + public static FlowTestUser fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, FlowTestUser.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String sid; + + @Getter + private final List testUsers; + + @Getter + private final URI url; + + @JsonCreator + private FlowTestUser( + @JsonProperty("sid") final String sid, + @JsonProperty("test_users") final List testUsers, + @JsonProperty("url") final URI url + ) { + this.sid = sid; + this.testUsers = testUsers; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + FlowTestUser other = (FlowTestUser) o; + return ( + Objects.equals(sid, other.sid) && + Objects.equals(testUsers, other.testUsers) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(sid, testUsers, url); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserFetcher.java new file mode 100644 index 0000000000..19b96e18fa --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FlowTestUserFetcher extends Fetcher { + + private String pathSid; + + public FlowTestUserFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{Sid}/TestUsers"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlowTestUser fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlowTestUser fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlowTestUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlowTestUser content = FlowTestUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserUpdater.java b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserUpdater.java new file mode 100644 index 0000000000..22248d0e47 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/FlowTestUserUpdater.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class FlowTestUserUpdater extends Updater { + + private String pathSid; + private List testUsers; + + public FlowTestUserUpdater( + final String pathSid, + final List testUsers + ) { + this.pathSid = pathSid; + this.testUsers = testUsers; + } + + public FlowTestUserUpdater setTestUsers(final List testUsers) { + this.testUsers = testUsers; + return this; + } + + public FlowTestUserUpdater setTestUsers(final String testUsers) { + return setTestUsers(Promoter.listOfOne(testUsers)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{Sid}/TestUsers"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.STUDIO.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "FlowTestUser update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public FlowTestUser update(final TwilioRestClient client) { + Response response = makeRequest(client); + return FlowTestUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + FlowTestUser content = FlowTestUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (testUsers != null) { + for (String param : testUsers) { + Serializer.toString( + request, + "TestUsers", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContext.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContext.java new file mode 100644 index 0000000000..04541256a4 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContext.java @@ -0,0 +1,158 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExecutionContext extends Resource { + + public static ExecutionContextFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid + ) { + return new ExecutionContextFetcher(pathFlowSid, pathExecutionSid); + } + + /** + * Converts a JSON String into a ExecutionContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionContext object represented by the provided JSON + */ + public static ExecutionContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionContext.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExecutionContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionContext object represented by the provided JSON + */ + public static ExecutionContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionContext.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object context; + + @Getter + private final String executionSid; + + @Getter + private final String flowSid; + + @Getter + private final URI url; + + @JsonCreator + private ExecutionContext( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.context = context; + this.executionSid = executionSid; + this.flowSid = flowSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionContext other = (ExecutionContext) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(accountSid, context, executionSid, flowSid, url); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContextFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContextFetcher.java new file mode 100644 index 0000000000..bf2c00a50a --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionContextFetcher.java @@ -0,0 +1,106 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow.execution; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionContextFetcher extends Fetcher { + + private String pathFlowSid; + private String pathExecutionSid; + + public ExecutionContextFetcher( + final String pathFlowSid, + final String pathExecutionSid + ) { + this.pathFlowSid = pathFlowSid; + this.pathExecutionSid = pathExecutionSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Context"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExecutionContext fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExecutionContext fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExecutionContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExecutionContext content = ExecutionContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStep.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStep.java new file mode 100644 index 0000000000..9a33ef109c --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStep.java @@ -0,0 +1,249 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow.execution; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExecutionStep extends Resource { + + public static ExecutionStepFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathSid + ) { + return new ExecutionStepFetcher(pathFlowSid, pathExecutionSid, pathSid); + } + + public static ExecutionStepReader reader( + final String pathFlowSid, + final String pathExecutionSid + ) { + return new ExecutionStepReader(pathFlowSid, pathExecutionSid); + } + + /** + * Converts a JSON String into a ExecutionStep object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStep object represented by the provided JSON + */ + public static ExecutionStep fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionStep.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExecutionStep object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStep object represented by the provided JSON + */ + public static ExecutionStep fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionStep.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object context; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String executionSid; + + @Getter + private final String flowSid; + + @Getter + private final Map links; + + @Getter + private final String name; + + @Getter + private final String parentStepSid; + + @Getter + private final String sid; + + @Getter + private final String transitionedFrom; + + @Getter + private final String transitionedTo; + + @Getter + private final String type; + + @Getter + private final URI url; + + @JsonCreator + private ExecutionStep( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("links") final Map links, + @JsonProperty("name") final String name, + @JsonProperty("parent_step_sid") final String parentStepSid, + @JsonProperty("sid") final String sid, + @JsonProperty("transitioned_from") final String transitionedFrom, + @JsonProperty("transitioned_to") final String transitionedTo, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.context = context; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.executionSid = executionSid; + this.flowSid = flowSid; + this.links = links; + this.name = name; + this.parentStepSid = parentStepSid; + this.sid = sid; + this.transitionedFrom = transitionedFrom; + this.transitionedTo = transitionedTo; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionStep other = (ExecutionStep) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(links, other.links) && + Objects.equals(name, other.name) && + Objects.equals(parentStepSid, other.parentStepSid) && + Objects.equals(sid, other.sid) && + Objects.equals(transitionedFrom, other.transitionedFrom) && + Objects.equals(transitionedTo, other.transitionedTo) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + context, + dateCreated, + dateUpdated, + executionSid, + flowSid, + links, + name, + parentStepSid, + sid, + transitionedFrom, + transitionedTo, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepFetcher.java new file mode 100644 index 0000000000..00c9d1d62c --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow.execution; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionStepFetcher extends Fetcher { + + private String pathFlowSid; + private String pathExecutionSid; + private String pathSid; + + public ExecutionStepFetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathSid + ) { + this.pathFlowSid = pathFlowSid; + this.pathExecutionSid = pathExecutionSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{Sid}"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExecutionStep fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExecutionStep fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExecutionStep.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExecutionStep content = ExecutionStep.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepReader.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepReader.java new file mode 100644 index 0000000000..bdf847a008 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/ExecutionStepReader.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow.execution; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionStepReader extends Reader { + + private String pathFlowSid; + private String pathExecutionSid; + private Long pageSize; + + public ExecutionStepReader( + final String pathFlowSid, + final String pathExecutionSid + ) { + this.pathFlowSid = pathFlowSid; + this.pathExecutionSid = pathExecutionSid; + } + + public ExecutionStepReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "steps", + response.getContent(), + ExecutionStep.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "steps", + response.getContent(), + ExecutionStep.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "ExecutionStep read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "steps", + response.getContent(), + ExecutionStep.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContext.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContext.java new file mode 100644 index 0000000000..05a4469f35 --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContext.java @@ -0,0 +1,176 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow.execution.executionstep; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ExecutionStepContext extends Resource { + + public static ExecutionStepContextFetcher fetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathStepSid + ) { + return new ExecutionStepContextFetcher( + pathFlowSid, + pathExecutionSid, + pathStepSid + ); + } + + /** + * Converts a JSON String into a ExecutionStepContext object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStepContext object represented by the provided JSON + */ + public static ExecutionStepContext fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionStepContext.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ExecutionStepContext object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ExecutionStepContext object represented by the provided JSON + */ + public static ExecutionStepContext fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ExecutionStepContext.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object context; + + @Getter + private final String executionSid; + + @Getter + private final String flowSid; + + @Getter + private final String stepSid; + + @Getter + private final URI url; + + @JsonCreator + private ExecutionStepContext( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("context") final Object context, + @JsonProperty("execution_sid") final String executionSid, + @JsonProperty("flow_sid") final String flowSid, + @JsonProperty("step_sid") final String stepSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.context = context; + this.executionSid = executionSid; + this.flowSid = flowSid; + this.stepSid = stepSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ExecutionStepContext other = (ExecutionStepContext) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(context, other.context) && + Objects.equals(executionSid, other.executionSid) && + Objects.equals(flowSid, other.flowSid) && + Objects.equals(stepSid, other.stepSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + context, + executionSid, + flowSid, + stepSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContextFetcher.java b/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContextFetcher.java new file mode 100644 index 0000000000..733b6a516b --- /dev/null +++ b/src/main/java/com/twilio/rest/studio/v2/flow/execution/executionstep/ExecutionStepContextFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Studio + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.studio.v2.flow.execution.executionstep; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ExecutionStepContextFetcher extends Fetcher { + + private String pathFlowSid; + private String pathExecutionSid; + private String pathStepSid; + + public ExecutionStepContextFetcher( + final String pathFlowSid, + final String pathExecutionSid, + final String pathStepSid + ) { + this.pathFlowSid = pathFlowSid; + this.pathExecutionSid = pathExecutionSid; + this.pathStepSid = pathStepSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v2/Flows/{FlowSid}/Executions/{ExecutionSid}/Steps/{StepSid}/Context"; + + path = path.replace("{" + "FlowSid" + "}", this.pathFlowSid.toString()); + path = + path.replace( + "{" + "ExecutionSid" + "}", + this.pathExecutionSid.toString() + ); + path = path.replace("{" + "StepSid" + "}", this.pathStepSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.STUDIO.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ExecutionStepContext fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ExecutionStepContext fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return ExecutionStepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ExecutionStepContext content = ExecutionStepContext.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/EsimProfile.java b/src/main/java/com/twilio/rest/supersim/v1/EsimProfile.java new file mode 100644 index 0000000000..32935e1fc2 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/EsimProfile.java @@ -0,0 +1,272 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EsimProfile extends Resource { + + public static EsimProfileCreator creator() { + return new EsimProfileCreator(); + } + + public static EsimProfileFetcher fetcher(final String pathSid) { + return new EsimProfileFetcher(pathSid); + } + + public static EsimProfileReader reader() { + return new EsimProfileReader(); + } + + public enum Status { + NEW("new"), + RESERVING("reserving"), + AVAILABLE("available"), + DOWNLOADED("downloaded"), + INSTALLED("installed"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a EsimProfile object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EsimProfile object represented by the provided JSON + */ + public static EsimProfile fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EsimProfile.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EsimProfile object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EsimProfile object represented by the provided JSON + */ + public static EsimProfile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EsimProfile.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String activationCode; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String eid; + + @Getter + private final String errorCode; + + @Getter + private final String errorMessage; + + @Getter + private final String iccid; + + @Getter + private final String matchingId; + + @Getter + private final String sid; + + @Getter + private final String simSid; + + @Getter + private final URI smdpPlusAddress; + + @Getter + private final EsimProfile.Status status; + + @Getter + private final URI url; + + @JsonCreator + private EsimProfile( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("activation_code") final String activationCode, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("eid") final String eid, + @JsonProperty("error_code") final String errorCode, + @JsonProperty("error_message") final String errorMessage, + @JsonProperty("iccid") final String iccid, + @JsonProperty("matching_id") final String matchingId, + @JsonProperty("sid") final String sid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("smdp_plus_address") final URI smdpPlusAddress, + @JsonProperty("status") final EsimProfile.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.activationCode = activationCode; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.eid = eid; + this.errorCode = errorCode; + this.errorMessage = errorMessage; + this.iccid = iccid; + this.matchingId = matchingId; + this.sid = sid; + this.simSid = simSid; + this.smdpPlusAddress = smdpPlusAddress; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EsimProfile other = (EsimProfile) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activationCode, other.activationCode) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(eid, other.eid) && + Objects.equals(errorCode, other.errorCode) && + Objects.equals(errorMessage, other.errorMessage) && + Objects.equals(iccid, other.iccid) && + Objects.equals(matchingId, other.matchingId) && + Objects.equals(sid, other.sid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(smdpPlusAddress, other.smdpPlusAddress) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + activationCode, + dateCreated, + dateUpdated, + eid, + errorCode, + errorMessage, + iccid, + matchingId, + sid, + simSid, + smdpPlusAddress, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileCreator.java b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileCreator.java new file mode 100644 index 0000000000..4d5aeaa74a --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileCreator.java @@ -0,0 +1,157 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EsimProfileCreator extends Creator { + + private String callbackUrl; + private HttpMethod callbackMethod; + private Boolean generateMatchingId; + private String eid; + + public EsimProfileCreator() {} + + public EsimProfileCreator setCallbackUrl(final String callbackUrl) { + this.callbackUrl = callbackUrl; + return this; + } + + public EsimProfileCreator setCallbackMethod( + final HttpMethod callbackMethod + ) { + this.callbackMethod = callbackMethod; + return this; + } + + public EsimProfileCreator setGenerateMatchingId( + final Boolean generateMatchingId + ) { + this.generateMatchingId = generateMatchingId; + return this; + } + + public EsimProfileCreator setEid(final String eid) { + this.eid = eid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ESimProfiles"; + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EsimProfile creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EsimProfile create(final TwilioRestClient client) { + Response response = makeRequest(client); + return EsimProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EsimProfile content = EsimProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (callbackUrl != null) { + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); + } + + if (callbackMethod != null) { + Serializer.toString( + request, + "CallbackMethod", + callbackMethod, + ParameterType.URLENCODED + ); + } + + if (generateMatchingId != null) { + Serializer.toString( + request, + "GenerateMatchingId", + generateMatchingId, + ParameterType.URLENCODED + ); + } + + if (eid != null) { + Serializer.toString(request, "Eid", eid, ParameterType.URLENCODED); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileFetcher.java new file mode 100644 index 0000000000..4719afb030 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EsimProfileFetcher extends Fetcher { + + private String pathSid; + + public EsimProfileFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ESimProfiles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EsimProfile fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EsimProfile fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EsimProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EsimProfile content = EsimProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/EsimProfileReader.java b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileReader.java new file mode 100644 index 0000000000..ccc344a4d3 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/EsimProfileReader.java @@ -0,0 +1,232 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EsimProfileReader extends Reader { + + private String eid; + private String simSid; + private EsimProfile.Status status; + private Long pageSize; + + public EsimProfileReader() {} + + public EsimProfileReader setEid(final String eid) { + this.eid = eid; + return this; + } + + public EsimProfileReader setSimSid(final String simSid) { + this.simSid = simSid; + return this; + } + + public EsimProfileReader setStatus(final EsimProfile.Status status) { + this.status = status; + return this; + } + + public EsimProfileReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "esim_profiles", + response.getContent(), + EsimProfile.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/ESimProfiles"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "esim_profiles", + response.getContent(), + EsimProfile.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "EsimProfile read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "esim_profiles", + response.getContent(), + EsimProfile.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (eid != null) { + Serializer.toString(request, "Eid", eid, ParameterType.QUERY); + } + + if (simSid != null) { + Serializer.toString(request, "SimSid", simSid, ParameterType.QUERY); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/Fleet.java b/src/main/java/com/twilio/rest/supersim/v1/Fleet.java new file mode 100644 index 0000000000..5892e11614 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/Fleet.java @@ -0,0 +1,284 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.http.HttpMethod; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Fleet extends Resource { + + public static FleetCreator creator(final String networkAccessProfile) { + return new FleetCreator(networkAccessProfile); + } + + public static FleetFetcher fetcher(final String pathSid) { + return new FleetFetcher(pathSid); + } + + public static FleetReader reader() { + return new FleetReader(); + } + + public static FleetUpdater updater(final String pathSid) { + return new FleetUpdater(pathSid); + } + + public enum DataMetering { + PAYG("payg"); + + private final String value; + + private DataMetering(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static DataMetering forValue(final String value) { + return Promoter.enumFromString(value, DataMetering.values()); + } + } + + /** + * Converts a JSON String into a Fleet object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Fleet object represented by the provided JSON + */ + public static Fleet fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Fleet.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Fleet object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Fleet object represented by the provided JSON + */ + public static Fleet fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Fleet.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Boolean dataEnabled; + + @Getter + private final Integer dataLimit; + + @Getter + private final Fleet.DataMetering dataMetering; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final HttpMethod ipCommandsMethod; + + @Getter + private final URI ipCommandsUrl; + + @Getter + private final String networkAccessProfileSid; + + @Getter + private final String sid; + + @Getter + private final Boolean smsCommandsEnabled; + + @Getter + private final HttpMethod smsCommandsMethod; + + @Getter + private final URI smsCommandsUrl; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private Fleet( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("data_enabled") final Boolean dataEnabled, + @JsonProperty("data_limit") final Integer dataLimit, + @JsonProperty("data_metering") final Fleet.DataMetering dataMetering, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("ip_commands_method") final HttpMethod ipCommandsMethod, + @JsonProperty("ip_commands_url") final URI ipCommandsUrl, + @JsonProperty( + "network_access_profile_sid" + ) final String networkAccessProfileSid, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_commands_enabled") final Boolean smsCommandsEnabled, + @JsonProperty("sms_commands_method") final HttpMethod smsCommandsMethod, + @JsonProperty("sms_commands_url") final URI smsCommandsUrl, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dataEnabled = dataEnabled; + this.dataLimit = dataLimit; + this.dataMetering = dataMetering; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.ipCommandsMethod = ipCommandsMethod; + this.ipCommandsUrl = ipCommandsUrl; + this.networkAccessProfileSid = networkAccessProfileSid; + this.sid = sid; + this.smsCommandsEnabled = smsCommandsEnabled; + this.smsCommandsMethod = smsCommandsMethod; + this.smsCommandsUrl = smsCommandsUrl; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Fleet other = (Fleet) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dataEnabled, other.dataEnabled) && + Objects.equals(dataLimit, other.dataLimit) && + Objects.equals(dataMetering, other.dataMetering) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(ipCommandsMethod, other.ipCommandsMethod) && + Objects.equals(ipCommandsUrl, other.ipCommandsUrl) && + Objects.equals( + networkAccessProfileSid, + other.networkAccessProfileSid + ) && + Objects.equals(sid, other.sid) && + Objects.equals(smsCommandsEnabled, other.smsCommandsEnabled) && + Objects.equals(smsCommandsMethod, other.smsCommandsMethod) && + Objects.equals(smsCommandsUrl, other.smsCommandsUrl) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dataEnabled, + dataLimit, + dataMetering, + dateCreated, + dateUpdated, + ipCommandsMethod, + ipCommandsUrl, + networkAccessProfileSid, + sid, + smsCommandsEnabled, + smsCommandsMethod, + smsCommandsUrl, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/FleetCreator.java b/src/main/java/com/twilio/rest/supersim/v1/FleetCreator.java new file mode 100644 index 0000000000..1147bb3334 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/FleetCreator.java @@ -0,0 +1,248 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class FleetCreator extends Creator { + + private String networkAccessProfile; + private String uniqueName; + private Boolean dataEnabled; + private Integer dataLimit; + private URI ipCommandsUrl; + private HttpMethod ipCommandsMethod; + private Boolean smsCommandsEnabled; + private URI smsCommandsUrl; + private HttpMethod smsCommandsMethod; + + public FleetCreator(final String networkAccessProfile) { + this.networkAccessProfile = networkAccessProfile; + } + + public FleetCreator setNetworkAccessProfile( + final String networkAccessProfile + ) { + this.networkAccessProfile = networkAccessProfile; + return this; + } + + public FleetCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public FleetCreator setDataEnabled(final Boolean dataEnabled) { + this.dataEnabled = dataEnabled; + return this; + } + + public FleetCreator setDataLimit(final Integer dataLimit) { + this.dataLimit = dataLimit; + return this; + } + + public FleetCreator setIpCommandsUrl(final URI ipCommandsUrl) { + this.ipCommandsUrl = ipCommandsUrl; + return this; + } + + public FleetCreator setIpCommandsUrl(final String ipCommandsUrl) { + return setIpCommandsUrl(Promoter.uriFromString(ipCommandsUrl)); + } + + public FleetCreator setIpCommandsMethod(final HttpMethod ipCommandsMethod) { + this.ipCommandsMethod = ipCommandsMethod; + return this; + } + + public FleetCreator setSmsCommandsEnabled( + final Boolean smsCommandsEnabled + ) { + this.smsCommandsEnabled = smsCommandsEnabled; + return this; + } + + public FleetCreator setSmsCommandsUrl(final URI smsCommandsUrl) { + this.smsCommandsUrl = smsCommandsUrl; + return this; + } + + public FleetCreator setSmsCommandsUrl(final String smsCommandsUrl) { + return setSmsCommandsUrl(Promoter.uriFromString(smsCommandsUrl)); + } + + public FleetCreator setSmsCommandsMethod( + final HttpMethod smsCommandsMethod + ) { + this.smsCommandsMethod = smsCommandsMethod; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Fleets"; + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Fleet creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Fleet create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Fleet.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Fleet content = Fleet.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (networkAccessProfile != null) { + Serializer.toString( + request, + "NetworkAccessProfile", + networkAccessProfile, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (dataEnabled != null) { + Serializer.toString( + request, + "DataEnabled", + dataEnabled, + ParameterType.URLENCODED + ); + } + + if (dataLimit != null) { + Serializer.toString( + request, + "DataLimit", + dataLimit, + ParameterType.URLENCODED + ); + } + + if (ipCommandsUrl != null) { + Serializer.toString( + request, + "IpCommandsUrl", + ipCommandsUrl, + ParameterType.URLENCODED + ); + } + + if (ipCommandsMethod != null) { + Serializer.toString( + request, + "IpCommandsMethod", + ipCommandsMethod, + ParameterType.URLENCODED + ); + } + + if (smsCommandsEnabled != null) { + Serializer.toString( + request, + "SmsCommandsEnabled", + smsCommandsEnabled, + ParameterType.URLENCODED + ); + } + + if (smsCommandsUrl != null) { + Serializer.toString( + request, + "SmsCommandsUrl", + smsCommandsUrl, + ParameterType.URLENCODED + ); + } + + if (smsCommandsMethod != null) { + Serializer.toString( + request, + "SmsCommandsMethod", + smsCommandsMethod, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/FleetFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/FleetFetcher.java new file mode 100644 index 0000000000..022be5cf5e --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/FleetFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FleetFetcher extends Fetcher { + + private String pathSid; + + public FleetFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Fleets/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Fleet fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Fleet fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Fleet.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Fleet content = Fleet.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/FleetReader.java b/src/main/java/com/twilio/rest/supersim/v1/FleetReader.java new file mode 100644 index 0000000000..11293cdd29 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/FleetReader.java @@ -0,0 +1,215 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FleetReader extends Reader { + + private String networkAccessProfile; + private Long pageSize; + + public FleetReader() {} + + public FleetReader setNetworkAccessProfile( + final String networkAccessProfile + ) { + this.networkAccessProfile = networkAccessProfile; + return this; + } + + public FleetReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "fleets", + response.getContent(), + Fleet.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Fleets"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "fleets", + response.getContent(), + Fleet.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Fleet read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "fleets", + response.getContent(), + Fleet.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (networkAccessProfile != null) { + Serializer.toString( + request, + "NetworkAccessProfile", + networkAccessProfile, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/FleetUpdater.java b/src/main/java/com/twilio/rest/supersim/v1/FleetUpdater.java new file mode 100644 index 0000000000..2c418ba7ea --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/FleetUpdater.java @@ -0,0 +1,219 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class FleetUpdater extends Updater { + + private String pathSid; + private String uniqueName; + private String networkAccessProfile; + private URI ipCommandsUrl; + private HttpMethod ipCommandsMethod; + private URI smsCommandsUrl; + private HttpMethod smsCommandsMethod; + private Integer dataLimit; + + public FleetUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public FleetUpdater setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public FleetUpdater setNetworkAccessProfile( + final String networkAccessProfile + ) { + this.networkAccessProfile = networkAccessProfile; + return this; + } + + public FleetUpdater setIpCommandsUrl(final URI ipCommandsUrl) { + this.ipCommandsUrl = ipCommandsUrl; + return this; + } + + public FleetUpdater setIpCommandsUrl(final String ipCommandsUrl) { + return setIpCommandsUrl(Promoter.uriFromString(ipCommandsUrl)); + } + + public FleetUpdater setIpCommandsMethod(final HttpMethod ipCommandsMethod) { + this.ipCommandsMethod = ipCommandsMethod; + return this; + } + + public FleetUpdater setSmsCommandsUrl(final URI smsCommandsUrl) { + this.smsCommandsUrl = smsCommandsUrl; + return this; + } + + public FleetUpdater setSmsCommandsUrl(final String smsCommandsUrl) { + return setSmsCommandsUrl(Promoter.uriFromString(smsCommandsUrl)); + } + + public FleetUpdater setSmsCommandsMethod( + final HttpMethod smsCommandsMethod + ) { + this.smsCommandsMethod = smsCommandsMethod; + return this; + } + + public FleetUpdater setDataLimit(final Integer dataLimit) { + this.dataLimit = dataLimit; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Fleets/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Fleet update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Fleet update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Fleet.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Fleet content = Fleet.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (networkAccessProfile != null) { + Serializer.toString( + request, + "NetworkAccessProfile", + networkAccessProfile, + ParameterType.URLENCODED + ); + } + + if (ipCommandsUrl != null) { + Serializer.toString( + request, + "IpCommandsUrl", + ipCommandsUrl, + ParameterType.URLENCODED + ); + } + + if (ipCommandsMethod != null) { + Serializer.toString( + request, + "IpCommandsMethod", + ipCommandsMethod, + ParameterType.URLENCODED + ); + } + + if (smsCommandsUrl != null) { + Serializer.toString( + request, + "SmsCommandsUrl", + smsCommandsUrl, + ParameterType.URLENCODED + ); + } + + if (smsCommandsMethod != null) { + Serializer.toString( + request, + "SmsCommandsMethod", + smsCommandsMethod, + ParameterType.URLENCODED + ); + } + + if (dataLimit != null) { + Serializer.toString( + request, + "DataLimit", + dataLimit, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/IpCommand.java b/src/main/java/com/twilio/rest/supersim/v1/IpCommand.java new file mode 100644 index 0000000000..46350aefe1 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/IpCommand.java @@ -0,0 +1,309 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class IpCommand extends Resource { + + public static IpCommandCreator creator( + final String sim, + final String payload, + final Integer devicePort + ) { + return new IpCommandCreator(sim, payload, devicePort); + } + + public static IpCommandFetcher fetcher(final String pathSid) { + return new IpCommandFetcher(pathSid); + } + + public static IpCommandReader reader() { + return new IpCommandReader(); + } + + public enum Status { + QUEUED("queued"), + SENT("sent"), + RECEIVED("received"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Direction { + TO_SIM("to_sim"), + FROM_SIM("from_sim"); + + private final String value; + + private Direction(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Direction forValue(final String value) { + return Promoter.enumFromString(value, Direction.values()); + } + } + + public enum PayloadType { + TEXT("text"), + BINARY("binary"); + + private final String value; + + private PayloadType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static PayloadType forValue(final String value) { + return Promoter.enumFromString(value, PayloadType.values()); + } + } + + /** + * Converts a JSON String into a IpCommand object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return IpCommand object represented by the provided JSON + */ + public static IpCommand fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, IpCommand.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a IpCommand object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return IpCommand object represented by the provided JSON + */ + public static IpCommand fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, IpCommand.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String deviceIp; + + @Getter + private final Integer devicePort; + + @Getter + private final IpCommand.Direction direction; + + @Getter + private final String payload; + + @Getter + private final IpCommand.PayloadType payloadType; + + @Getter + private final String sid; + + @Getter + private final String simIccid; + + @Getter + private final String simSid; + + @Getter + private final IpCommand.Status status; + + @Getter + private final URI url; + + @JsonCreator + private IpCommand( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("device_ip") final String deviceIp, + @JsonProperty("device_port") final Integer devicePort, + @JsonProperty("direction") final IpCommand.Direction direction, + @JsonProperty("payload") final String payload, + @JsonProperty("payload_type") final IpCommand.PayloadType payloadType, + @JsonProperty("sid") final String sid, + @JsonProperty("sim_iccid") final String simIccid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("status") final IpCommand.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.deviceIp = deviceIp; + this.devicePort = devicePort; + this.direction = direction; + this.payload = payload; + this.payloadType = payloadType; + this.sid = sid; + this.simIccid = simIccid; + this.simSid = simSid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + IpCommand other = (IpCommand) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(deviceIp, other.deviceIp) && + Objects.equals(devicePort, other.devicePort) && + Objects.equals(direction, other.direction) && + Objects.equals(payload, other.payload) && + Objects.equals(payloadType, other.payloadType) && + Objects.equals(sid, other.sid) && + Objects.equals(simIccid, other.simIccid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + deviceIp, + devicePort, + direction, + payload, + payloadType, + sid, + simIccid, + simSid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/IpCommandCreator.java b/src/main/java/com/twilio/rest/supersim/v1/IpCommandCreator.java new file mode 100644 index 0000000000..d418a465fb --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/IpCommandCreator.java @@ -0,0 +1,199 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class IpCommandCreator extends Creator { + + private String sim; + private String payload; + private Integer devicePort; + private IpCommand.PayloadType payloadType; + private URI callbackUrl; + private HttpMethod callbackMethod; + + public IpCommandCreator( + final String sim, + final String payload, + final Integer devicePort + ) { + this.sim = sim; + this.payload = payload; + this.devicePort = devicePort; + } + + public IpCommandCreator setSim(final String sim) { + this.sim = sim; + return this; + } + + public IpCommandCreator setPayload(final String payload) { + this.payload = payload; + return this; + } + + public IpCommandCreator setDevicePort(final Integer devicePort) { + this.devicePort = devicePort; + return this; + } + + public IpCommandCreator setPayloadType( + final IpCommand.PayloadType payloadType + ) { + this.payloadType = payloadType; + return this; + } + + public IpCommandCreator setCallbackUrl(final URI callbackUrl) { + this.callbackUrl = callbackUrl; + return this; + } + + public IpCommandCreator setCallbackUrl(final String callbackUrl) { + return setCallbackUrl(Promoter.uriFromString(callbackUrl)); + } + + public IpCommandCreator setCallbackMethod(final HttpMethod callbackMethod) { + this.callbackMethod = callbackMethod; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/IpCommands"; + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "IpCommand creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public IpCommand create(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpCommand content = IpCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (sim != null) { + Serializer.toString(request, "Sim", sim, ParameterType.URLENCODED); + } + + if (payload != null) { + Serializer.toString( + request, + "Payload", + payload, + ParameterType.URLENCODED + ); + } + + if (devicePort != null) { + Serializer.toString( + request, + "DevicePort", + devicePort, + ParameterType.URLENCODED + ); + } + + if (payloadType != null) { + Serializer.toString( + request, + "PayloadType", + payloadType, + ParameterType.URLENCODED + ); + } + + if (callbackUrl != null) { + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); + } + + if (callbackMethod != null) { + Serializer.toString( + request, + "CallbackMethod", + callbackMethod, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/IpCommandFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/IpCommandFetcher.java new file mode 100644 index 0000000000..fc7470ac50 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/IpCommandFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IpCommandFetcher extends Fetcher { + + private String pathSid; + + public IpCommandFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/IpCommands/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "IpCommand fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public IpCommand fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpCommand content = IpCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/IpCommandReader.java b/src/main/java/com/twilio/rest/supersim/v1/IpCommandReader.java new file mode 100644 index 0000000000..5cd5823d39 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/IpCommandReader.java @@ -0,0 +1,252 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class IpCommandReader extends Reader { + + private String sim; + private String simIccid; + private IpCommand.Status status; + private IpCommand.Direction direction; + private Long pageSize; + + public IpCommandReader() {} + + public IpCommandReader setSim(final String sim) { + this.sim = sim; + return this; + } + + public IpCommandReader setSimIccid(final String simIccid) { + this.simIccid = simIccid; + return this; + } + + public IpCommandReader setStatus(final IpCommand.Status status) { + this.status = status; + return this; + } + + public IpCommandReader setDirection(final IpCommand.Direction direction) { + this.direction = direction; + return this; + } + + public IpCommandReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_commands", + response.getContent(), + IpCommand.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/IpCommands"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_commands", + response.getContent(), + IpCommand.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "IpCommand read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "ip_commands", + response.getContent(), + IpCommand.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (sim != null) { + Serializer.toString(request, "Sim", sim, ParameterType.QUERY); + } + + if (simIccid != null) { + Serializer.toString( + request, + "SimIccid", + simIccid, + ParameterType.QUERY + ); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (direction != null) { + Serializer.toString( + request, + "Direction", + direction, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/Network.java b/src/main/java/com/twilio/rest/supersim/v1/Network.java new file mode 100644 index 0000000000..2cec60fb82 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/Network.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Network extends Resource { + + public static NetworkFetcher fetcher(final String pathSid) { + return new NetworkFetcher(pathSid); + } + + public static NetworkReader reader() { + return new NetworkReader(); + } + + /** + * Converts a JSON String into a Network object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Network object represented by the provided JSON + */ + public static Network fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Network.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Network object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Network object represented by the provided JSON + */ + public static Network fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Network.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String friendlyName; + + @Getter + private final List identifiers; + + @Getter + private final String isoCountry; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Network( + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identifiers") final List identifiers, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.friendlyName = friendlyName; + this.identifiers = identifiers; + this.isoCountry = isoCountry; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Network other = (Network) o; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identifiers, other.identifiers) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(friendlyName, identifiers, isoCountry, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfile.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfile.java new file mode 100644 index 0000000000..bb8617aebe --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfile.java @@ -0,0 +1,201 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class NetworkAccessProfile extends Resource { + + public static NetworkAccessProfileCreator creator() { + return new NetworkAccessProfileCreator(); + } + + public static NetworkAccessProfileFetcher fetcher(final String pathSid) { + return new NetworkAccessProfileFetcher(pathSid); + } + + public static NetworkAccessProfileReader reader() { + return new NetworkAccessProfileReader(); + } + + public static NetworkAccessProfileUpdater updater(final String pathSid) { + return new NetworkAccessProfileUpdater(pathSid); + } + + /** + * Converts a JSON String into a NetworkAccessProfile object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return NetworkAccessProfile object represented by the provided JSON + */ + public static NetworkAccessProfile fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, NetworkAccessProfile.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a NetworkAccessProfile object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return NetworkAccessProfile object represented by the provided JSON + */ + public static NetworkAccessProfile fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, NetworkAccessProfile.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private NetworkAccessProfile( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.links = links; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NetworkAccessProfile other = (NetworkAccessProfile) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + links, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileCreator.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileCreator.java new file mode 100644 index 0000000000..e77083eafc --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileCreator.java @@ -0,0 +1,138 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class NetworkAccessProfileCreator extends Creator { + + private String uniqueName; + private List networks; + + public NetworkAccessProfileCreator() {} + + public NetworkAccessProfileCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public NetworkAccessProfileCreator setNetworks( + final List networks + ) { + this.networks = networks; + return this; + } + + public NetworkAccessProfileCreator setNetworks(final String networks) { + return setNetworks(Promoter.listOfOne(networks)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/NetworkAccessProfiles"; + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "NetworkAccessProfile creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public NetworkAccessProfile create(final TwilioRestClient client) { + Response response = makeRequest(client); + return NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + NetworkAccessProfile content = NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (networks != null) { + for (String param : networks) { + Serializer.toString( + request, + "Networks", + param, + ParameterType.URLENCODED + ); + } + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileFetcher.java new file mode 100644 index 0000000000..ba4f84ef5a --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NetworkAccessProfileFetcher extends Fetcher { + + private String pathSid; + + public NetworkAccessProfileFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/NetworkAccessProfiles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "NetworkAccessProfile fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public NetworkAccessProfile fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + NetworkAccessProfile content = NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileReader.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileReader.java new file mode 100644 index 0000000000..4759bb160a --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileReader.java @@ -0,0 +1,204 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NetworkAccessProfileReader extends Reader { + + private Long pageSize; + + public NetworkAccessProfileReader() {} + + public NetworkAccessProfileReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "network_access_profiles", + response.getContent(), + NetworkAccessProfile.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/NetworkAccessProfiles"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "network_access_profiles", + response.getContent(), + NetworkAccessProfile.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "NetworkAccessProfile read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "network_access_profiles", + response.getContent(), + NetworkAccessProfile.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileUpdater.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileUpdater.java new file mode 100644 index 0000000000..3fbc77ba79 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkAccessProfileUpdater.java @@ -0,0 +1,118 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NetworkAccessProfileUpdater extends Updater { + + private String pathSid; + private String uniqueName; + + public NetworkAccessProfileUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public NetworkAccessProfileUpdater setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/NetworkAccessProfiles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "NetworkAccessProfile update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public NetworkAccessProfile update(final TwilioRestClient client) { + Response response = makeRequest(client); + return NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + NetworkAccessProfile content = NetworkAccessProfile.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkFetcher.java new file mode 100644 index 0000000000..eaa1be385c --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NetworkFetcher extends Fetcher { + + private String pathSid; + + public NetworkFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Networks/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Network fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Network fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Network.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Network content = Network.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/NetworkReader.java b/src/main/java/com/twilio/rest/supersim/v1/NetworkReader.java new file mode 100644 index 0000000000..f32d17cb58 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/NetworkReader.java @@ -0,0 +1,237 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NetworkReader extends Reader { + + private String isoCountry; + private String mcc; + private String mnc; + private Long pageSize; + + public NetworkReader() {} + + public NetworkReader setIsoCountry(final String isoCountry) { + this.isoCountry = isoCountry; + return this; + } + + public NetworkReader setMcc(final String mcc) { + this.mcc = mcc; + return this; + } + + public NetworkReader setMnc(final String mnc) { + this.mnc = mnc; + return this; + } + + public NetworkReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "networks", + response.getContent(), + Network.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Networks"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "networks", + response.getContent(), + Network.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Network read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "networks", + response.getContent(), + Network.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (isoCountry != null) { + Serializer.toString( + request, + "IsoCountry", + isoCountry, + ParameterType.QUERY + ); + } + + if (mcc != null) { + Serializer.toString(request, "Mcc", mcc, ParameterType.QUERY); + } + + if (mnc != null) { + Serializer.toString(request, "Mnc", mnc, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdate.java b/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdate.java new file mode 100644 index 0000000000..156984924b --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdate.java @@ -0,0 +1,225 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SettingsUpdate extends Resource { + + public static SettingsUpdateReader reader() { + return new SettingsUpdateReader(); + } + + public enum Status { + SCHEDULED("scheduled"), + IN_PROGRESS("in-progress"), + SUCCESSFUL("successful"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a SettingsUpdate object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SettingsUpdate object represented by the provided JSON + */ + public static SettingsUpdate fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SettingsUpdate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SettingsUpdate object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SettingsUpdate object represented by the provided JSON + */ + public static SettingsUpdate fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SettingsUpdate.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCompleted; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String iccid; + + @Getter + private final List packages; + + @Getter + private final String sid; + + @Getter + private final String simSid; + + @Getter + private final SettingsUpdate.Status status; + + @JsonCreator + private SettingsUpdate( + @JsonProperty("date_completed") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCompleted, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("iccid") final String iccid, + @JsonProperty("packages") final List packages, + @JsonProperty("sid") final String sid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("status") final SettingsUpdate.Status status + ) { + this.dateCompleted = dateCompleted; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.iccid = iccid; + this.packages = packages; + this.sid = sid; + this.simSid = simSid; + this.status = status; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SettingsUpdate other = (SettingsUpdate) o; + return ( + Objects.equals(dateCompleted, other.dateCompleted) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(iccid, other.iccid) && + Objects.equals(packages, other.packages) && + Objects.equals(sid, other.sid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(status, other.status) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + dateCompleted, + dateCreated, + dateUpdated, + iccid, + packages, + sid, + simSid, + status + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdateReader.java b/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdateReader.java new file mode 100644 index 0000000000..eafdf684d0 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SettingsUpdateReader.java @@ -0,0 +1,222 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SettingsUpdateReader extends Reader { + + private String sim; + private SettingsUpdate.Status status; + private Long pageSize; + + public SettingsUpdateReader() {} + + public SettingsUpdateReader setSim(final String sim) { + this.sim = sim; + return this; + } + + public SettingsUpdateReader setStatus(final SettingsUpdate.Status status) { + this.status = status; + return this; + } + + public SettingsUpdateReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "settings_updates", + response.getContent(), + SettingsUpdate.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/SettingsUpdates"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "settings_updates", + response.getContent(), + SettingsUpdate.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SettingsUpdate read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "settings_updates", + response.getContent(), + SettingsUpdate.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (sim != null) { + Serializer.toString(request, "Sim", sim, ParameterType.QUERY); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/Sim.java b/src/main/java/com/twilio/rest/supersim/v1/Sim.java new file mode 100644 index 0000000000..791bd2e02b --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/Sim.java @@ -0,0 +1,273 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Sim extends Resource { + + public static SimCreator creator( + final String iccid, + final String registrationCode + ) { + return new SimCreator(iccid, registrationCode); + } + + public static SimFetcher fetcher(final String pathSid) { + return new SimFetcher(pathSid); + } + + public static SimReader reader() { + return new SimReader(); + } + + public static SimUpdater updater(final String pathSid) { + return new SimUpdater(pathSid); + } + + public enum Status { + NEW("new"), + READY("ready"), + ACTIVE("active"), + INACTIVE("inactive"), + SCHEDULED("scheduled"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum StatusUpdate { + READY("ready"), + ACTIVE("active"), + INACTIVE("inactive"); + + private final String value; + + private StatusUpdate(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static StatusUpdate forValue(final String value) { + return Promoter.enumFromString(value, StatusUpdate.values()); + } + } + + /** + * Converts a JSON String into a Sim object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Sim object represented by the provided JSON + */ + public static Sim fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Sim.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Sim object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Sim object represented by the provided JSON + */ + public static Sim fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Sim.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String fleetSid; + + @Getter + private final String iccid; + + @Getter + private final Map links; + + @Getter + private final String sid; + + @Getter + private final Sim.Status status; + + @Getter + private final String uniqueName; + + @Getter + private final URI url; + + @JsonCreator + private Sim( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("fleet_sid") final String fleetSid, + @JsonProperty("iccid") final String iccid, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final Sim.Status status, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.fleetSid = fleetSid; + this.iccid = iccid; + this.links = links; + this.sid = sid; + this.status = status; + this.uniqueName = uniqueName; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Sim other = (Sim) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(fleetSid, other.fleetSid) && + Objects.equals(iccid, other.iccid) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + fleetSid, + iccid, + links, + sid, + status, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SimCreator.java b/src/main/java/com/twilio/rest/supersim/v1/SimCreator.java new file mode 100644 index 0000000000..6e3098b35f --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SimCreator.java @@ -0,0 +1,128 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SimCreator extends Creator { + + private String iccid; + private String registrationCode; + + public SimCreator(final String iccid, final String registrationCode) { + this.iccid = iccid; + this.registrationCode = registrationCode; + } + + public SimCreator setIccid(final String iccid) { + this.iccid = iccid; + return this; + } + + public SimCreator setRegistrationCode(final String registrationCode) { + this.registrationCode = registrationCode; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sims"; + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Sim creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Sim create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Sim.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Sim content = Sim.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (iccid != null) { + Serializer.toString( + request, + "Iccid", + iccid, + ParameterType.URLENCODED + ); + } + + if (registrationCode != null) { + Serializer.toString( + request, + "RegistrationCode", + registrationCode, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SimFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/SimFetcher.java new file mode 100644 index 0000000000..62ba3a6561 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SimFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SimFetcher extends Fetcher { + + private String pathSid; + + public SimFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sims/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Sim fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Sim fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Sim.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Sim content = Sim.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SimReader.java b/src/main/java/com/twilio/rest/supersim/v1/SimReader.java new file mode 100644 index 0000000000..eee8d57110 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SimReader.java @@ -0,0 +1,228 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SimReader extends Reader { + + private Sim.Status status; + private String fleet; + private String iccid; + private Long pageSize; + + public SimReader() {} + + public SimReader setStatus(final Sim.Status status) { + this.status = status; + return this; + } + + public SimReader setFleet(final String fleet) { + this.fleet = fleet; + return this; + } + + public SimReader setIccid(final String iccid) { + this.iccid = iccid; + return this; + } + + public SimReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sims", + response.getContent(), + Sim.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Sims"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sims", + response.getContent(), + Sim.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Sim read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "sims", + response.getContent(), + Sim.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (fleet != null) { + Serializer.toString(request, "Fleet", fleet, ParameterType.QUERY); + } + + if (iccid != null) { + Serializer.toString(request, "Iccid", iccid, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SimUpdater.java b/src/main/java/com/twilio/rest/supersim/v1/SimUpdater.java new file mode 100644 index 0000000000..e60e61b1fa --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SimUpdater.java @@ -0,0 +1,196 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class SimUpdater extends Updater { + + private String pathSid; + private String uniqueName; + private Sim.StatusUpdate status; + private String fleet; + private URI callbackUrl; + private HttpMethod callbackMethod; + private String accountSid; + + public SimUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public SimUpdater setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public SimUpdater setStatus(final Sim.StatusUpdate status) { + this.status = status; + return this; + } + + public SimUpdater setFleet(final String fleet) { + this.fleet = fleet; + return this; + } + + public SimUpdater setCallbackUrl(final URI callbackUrl) { + this.callbackUrl = callbackUrl; + return this; + } + + public SimUpdater setCallbackUrl(final String callbackUrl) { + return setCallbackUrl(Promoter.uriFromString(callbackUrl)); + } + + public SimUpdater setCallbackMethod(final HttpMethod callbackMethod) { + this.callbackMethod = callbackMethod; + return this; + } + + public SimUpdater setAccountSid(final String accountSid) { + this.accountSid = accountSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Sims/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Sim update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Sim update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Sim.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Sim content = Sim.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (fleet != null) { + Serializer.toString( + request, + "Fleet", + fleet, + ParameterType.URLENCODED + ); + } + + if (callbackUrl != null) { + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); + } + + if (callbackMethod != null) { + Serializer.toString( + request, + "CallbackMethod", + callbackMethod, + ParameterType.URLENCODED + ); + } + + if (accountSid != null) { + Serializer.toString( + request, + "AccountSid", + accountSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SmsCommand.java b/src/main/java/com/twilio/rest/supersim/v1/SmsCommand.java new file mode 100644 index 0000000000..baaf2247bc --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SmsCommand.java @@ -0,0 +1,260 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SmsCommand extends Resource { + + public static SmsCommandCreator creator( + final String sim, + final String payload + ) { + return new SmsCommandCreator(sim, payload); + } + + public static SmsCommandFetcher fetcher(final String pathSid) { + return new SmsCommandFetcher(pathSid); + } + + public static SmsCommandReader reader() { + return new SmsCommandReader(); + } + + public enum Status { + QUEUED("queued"), + SENT("sent"), + DELIVERED("delivered"), + RECEIVED("received"), + FAILED("failed"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + public enum Direction { + TO_SIM("to_sim"), + FROM_SIM("from_sim"); + + private final String value; + + private Direction(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Direction forValue(final String value) { + return Promoter.enumFromString(value, Direction.values()); + } + } + + /** + * Converts a JSON String into a SmsCommand object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SmsCommand object represented by the provided JSON + */ + public static SmsCommand fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SmsCommand.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SmsCommand object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SmsCommand object represented by the provided JSON + */ + public static SmsCommand fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SmsCommand.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final SmsCommand.Direction direction; + + @Getter + private final String payload; + + @Getter + private final String sid; + + @Getter + private final String simSid; + + @Getter + private final SmsCommand.Status status; + + @Getter + private final URI url; + + @JsonCreator + private SmsCommand( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("direction") final SmsCommand.Direction direction, + @JsonProperty("payload") final String payload, + @JsonProperty("sid") final String sid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("status") final SmsCommand.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.direction = direction; + this.payload = payload; + this.sid = sid; + this.simSid = simSid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SmsCommand other = (SmsCommand) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(direction, other.direction) && + Objects.equals(payload, other.payload) && + Objects.equals(sid, other.sid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + direction, + payload, + sid, + simSid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandCreator.java b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandCreator.java new file mode 100644 index 0000000000..057ba8ef91 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandCreator.java @@ -0,0 +1,164 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class SmsCommandCreator extends Creator { + + private String sim; + private String payload; + private HttpMethod callbackMethod; + private URI callbackUrl; + + public SmsCommandCreator(final String sim, final String payload) { + this.sim = sim; + this.payload = payload; + } + + public SmsCommandCreator setSim(final String sim) { + this.sim = sim; + return this; + } + + public SmsCommandCreator setPayload(final String payload) { + this.payload = payload; + return this; + } + + public SmsCommandCreator setCallbackMethod( + final HttpMethod callbackMethod + ) { + this.callbackMethod = callbackMethod; + return this; + } + + public SmsCommandCreator setCallbackUrl(final URI callbackUrl) { + this.callbackUrl = callbackUrl; + return this; + } + + public SmsCommandCreator setCallbackUrl(final String callbackUrl) { + return setCallbackUrl(Promoter.uriFromString(callbackUrl)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SmsCommands"; + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SmsCommand creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SmsCommand create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SmsCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SmsCommand content = SmsCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (sim != null) { + Serializer.toString(request, "Sim", sim, ParameterType.URLENCODED); + } + + if (payload != null) { + Serializer.toString( + request, + "Payload", + payload, + ParameterType.URLENCODED + ); + } + + if (callbackMethod != null) { + Serializer.toString( + request, + "CallbackMethod", + callbackMethod, + ParameterType.URLENCODED + ); + } + + if (callbackUrl != null) { + Serializer.toString( + request, + "CallbackUrl", + callbackUrl, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandFetcher.java new file mode 100644 index 0000000000..ccca6d2876 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SmsCommandFetcher extends Fetcher { + + private String pathSid; + + public SmsCommandFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SmsCommands/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SmsCommand fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SmsCommand fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SmsCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SmsCommand content = SmsCommand.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/SmsCommandReader.java b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandReader.java new file mode 100644 index 0000000000..f833f6b29d --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/SmsCommandReader.java @@ -0,0 +1,237 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SmsCommandReader extends Reader { + + private String sim; + private SmsCommand.Status status; + private SmsCommand.Direction direction; + private Long pageSize; + + public SmsCommandReader() {} + + public SmsCommandReader setSim(final String sim) { + this.sim = sim; + return this; + } + + public SmsCommandReader setStatus(final SmsCommand.Status status) { + this.status = status; + return this; + } + + public SmsCommandReader setDirection(final SmsCommand.Direction direction) { + this.direction = direction; + return this; + } + + public SmsCommandReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sms_commands", + response.getContent(), + SmsCommand.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/SmsCommands"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "sms_commands", + response.getContent(), + SmsCommand.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SmsCommand read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "sms_commands", + response.getContent(), + SmsCommand.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (sim != null) { + Serializer.toString(request, "Sim", sim, ParameterType.QUERY); + } + + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (direction != null) { + Serializer.toString( + request, + "Direction", + direction, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/UsageRecord.java b/src/main/java/com/twilio/rest/supersim/v1/UsageRecord.java new file mode 100644 index 0000000000..a82bef1116 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/UsageRecord.java @@ -0,0 +1,254 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.Currency; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class UsageRecord extends Resource { + + public static UsageRecordReader reader() { + return new UsageRecordReader(); + } + + public enum Group { + SIM("sim"), + FLEET("fleet"), + NETWORK("network"), + ISO_COUNTRY("isoCountry"); + + private final String value; + + private Group(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Group forValue(final String value) { + return Promoter.enumFromString(value, Group.values()); + } + } + + public enum Granularity { + HOUR("hour"), + DAY("day"), + ALL("all"); + + private final String value; + + private Granularity(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Granularity forValue(final String value) { + return Promoter.enumFromString(value, Granularity.values()); + } + } + + /** + * Converts a JSON String into a UsageRecord object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return UsageRecord object represented by the provided JSON + */ + public static UsageRecord fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UsageRecord.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a UsageRecord object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return UsageRecord object represented by the provided JSON + */ + public static UsageRecord fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, UsageRecord.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Currency billedUnit; + + @Getter + private final Long dataDownload; + + @Getter + private final Long dataTotal; + + @Getter + private final BigDecimal dataTotalBilled; + + @Getter + private final Long dataUpload; + + @Getter + private final String fleetSid; + + @Getter + private final String isoCountry; + + @Getter + private final String networkSid; + + @Getter + private final Object period; + + @Getter + private final String simSid; + + @JsonCreator + private UsageRecord( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("billed_unit") @JsonDeserialize( + using = com.twilio.converter.CurrencyDeserializer.class + ) final Currency billedUnit, + @JsonProperty("data_download") final Long dataDownload, + @JsonProperty("data_total") final Long dataTotal, + @JsonProperty("data_total_billed") final BigDecimal dataTotalBilled, + @JsonProperty("data_upload") final Long dataUpload, + @JsonProperty("fleet_sid") final String fleetSid, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty("network_sid") final String networkSid, + @JsonProperty("period") final Object period, + @JsonProperty("sim_sid") final String simSid + ) { + this.accountSid = accountSid; + this.billedUnit = billedUnit; + this.dataDownload = dataDownload; + this.dataTotal = dataTotal; + this.dataTotalBilled = dataTotalBilled; + this.dataUpload = dataUpload; + this.fleetSid = fleetSid; + this.isoCountry = isoCountry; + this.networkSid = networkSid; + this.period = period; + this.simSid = simSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + UsageRecord other = (UsageRecord) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(billedUnit, other.billedUnit) && + Objects.equals(dataDownload, other.dataDownload) && + Objects.equals(dataTotal, other.dataTotal) && + Objects.equals(dataTotalBilled, other.dataTotalBilled) && + Objects.equals(dataUpload, other.dataUpload) && + Objects.equals(fleetSid, other.fleetSid) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals(networkSid, other.networkSid) && + Objects.equals(period, other.period) && + Objects.equals(simSid, other.simSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + billedUnit, + dataDownload, + dataTotal, + dataTotalBilled, + dataUpload, + fleetSid, + isoCountry, + networkSid, + period, + simSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/UsageRecordReader.java b/src/main/java/com/twilio/rest/supersim/v1/UsageRecordReader.java new file mode 100644 index 0000000000..1944ae040a --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/UsageRecordReader.java @@ -0,0 +1,310 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; + +public class UsageRecordReader extends Reader { + + private String sim; + private String fleet; + private String network; + private String isoCountry; + private UsageRecord.Group group; + private UsageRecord.Granularity granularity; + private ZonedDateTime startTime; + private ZonedDateTime endTime; + private Long pageSize; + + public UsageRecordReader() {} + + public UsageRecordReader setSim(final String sim) { + this.sim = sim; + return this; + } + + public UsageRecordReader setFleet(final String fleet) { + this.fleet = fleet; + return this; + } + + public UsageRecordReader setNetwork(final String network) { + this.network = network; + return this; + } + + public UsageRecordReader setIsoCountry(final String isoCountry) { + this.isoCountry = isoCountry; + return this; + } + + public UsageRecordReader setGroup(final UsageRecord.Group group) { + this.group = group; + return this; + } + + public UsageRecordReader setGranularity( + final UsageRecord.Granularity granularity + ) { + this.granularity = granularity; + return this; + } + + public UsageRecordReader setStartTime(final ZonedDateTime startTime) { + this.startTime = startTime; + return this; + } + + public UsageRecordReader setEndTime(final ZonedDateTime endTime) { + this.endTime = endTime; + return this; + } + + public UsageRecordReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + UsageRecord.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/UsageRecords"; + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "usage_records", + response.getContent(), + UsageRecord.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "UsageRecord read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "usage_records", + response.getContent(), + UsageRecord.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (sim != null) { + Serializer.toString(request, "Sim", sim, ParameterType.QUERY); + } + + if (fleet != null) { + Serializer.toString(request, "Fleet", fleet, ParameterType.QUERY); + } + + if (network != null) { + Serializer.toString( + request, + "Network", + network, + ParameterType.QUERY + ); + } + + if (isoCountry != null) { + Serializer.toString( + request, + "IsoCountry", + isoCountry, + ParameterType.QUERY + ); + } + + if (group != null) { + Serializer.toString(request, "Group", group, ParameterType.QUERY); + } + + if (granularity != null) { + Serializer.toString( + request, + "Granularity", + granularity, + ParameterType.QUERY + ); + } + + if (startTime != null) { + Serializer.toString( + request, + "StartTime", + startTime, + ParameterType.QUERY + ); + } + + if (endTime != null) { + Serializer.toString( + request, + "EndTime", + endTime, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetwork.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetwork.java new file mode 100644 index 0000000000..ec680816c0 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetwork.java @@ -0,0 +1,214 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.networkaccessprofile; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class NetworkAccessProfileNetwork extends Resource { + + public static NetworkAccessProfileNetworkCreator creator( + final String pathNetworkAccessProfileSid, + final String network + ) { + return new NetworkAccessProfileNetworkCreator( + pathNetworkAccessProfileSid, + network + ); + } + + public static NetworkAccessProfileNetworkDeleter deleter( + final String pathNetworkAccessProfileSid, + final String pathSid + ) { + return new NetworkAccessProfileNetworkDeleter( + pathNetworkAccessProfileSid, + pathSid + ); + } + + public static NetworkAccessProfileNetworkFetcher fetcher( + final String pathNetworkAccessProfileSid, + final String pathSid + ) { + return new NetworkAccessProfileNetworkFetcher( + pathNetworkAccessProfileSid, + pathSid + ); + } + + public static NetworkAccessProfileNetworkReader reader( + final String pathNetworkAccessProfileSid + ) { + return new NetworkAccessProfileNetworkReader( + pathNetworkAccessProfileSid + ); + } + + /** + * Converts a JSON String into a NetworkAccessProfileNetwork object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return NetworkAccessProfileNetwork object represented by the provided JSON + */ + public static NetworkAccessProfileNetwork fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + NetworkAccessProfileNetwork.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a NetworkAccessProfileNetwork object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return NetworkAccessProfileNetwork object represented by the provided JSON + */ + public static NetworkAccessProfileNetwork fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + NetworkAccessProfileNetwork.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String friendlyName; + + @Getter + private final List identifiers; + + @Getter + private final String isoCountry; + + @Getter + private final String networkAccessProfileSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private NetworkAccessProfileNetwork( + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("identifiers") final List identifiers, + @JsonProperty("iso_country") final String isoCountry, + @JsonProperty( + "network_access_profile_sid" + ) final String networkAccessProfileSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.friendlyName = friendlyName; + this.identifiers = identifiers; + this.isoCountry = isoCountry; + this.networkAccessProfileSid = networkAccessProfileSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + NetworkAccessProfileNetwork other = (NetworkAccessProfileNetwork) o; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(identifiers, other.identifiers) && + Objects.equals(isoCountry, other.isoCountry) && + Objects.equals( + networkAccessProfileSid, + other.networkAccessProfileSid + ) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + friendlyName, + identifiers, + isoCountry, + networkAccessProfileSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkCreator.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkCreator.java new file mode 100644 index 0000000000..4c6076e830 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkCreator.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.networkaccessprofile; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NetworkAccessProfileNetworkCreator + extends Creator { + + private String pathNetworkAccessProfileSid; + private String network; + + public NetworkAccessProfileNetworkCreator( + final String pathNetworkAccessProfileSid, + final String network + ) { + this.pathNetworkAccessProfileSid = pathNetworkAccessProfileSid; + this.network = network; + } + + public NetworkAccessProfileNetworkCreator setNetwork(final String network) { + this.network = network; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks"; + + path = + path.replace( + "{" + "NetworkAccessProfileSid" + "}", + this.pathNetworkAccessProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.SUPERSIM.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "NetworkAccessProfileNetwork creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public NetworkAccessProfileNetwork create(final TwilioRestClient client) { + Response response = makeRequest(client); + return NetworkAccessProfileNetwork.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + NetworkAccessProfileNetwork content = + NetworkAccessProfileNetwork.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (network != null) { + Serializer.toString( + request, + "Network", + network, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkDeleter.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkDeleter.java new file mode 100644 index 0000000000..89a20b2d64 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkDeleter.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.networkaccessprofile; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class NetworkAccessProfileNetworkDeleter + extends Deleter { + + private String pathNetworkAccessProfileSid; + private String pathSid; + + public NetworkAccessProfileNetworkDeleter( + final String pathNetworkAccessProfileSid, + final String pathSid + ) { + this.pathNetworkAccessProfileSid = pathNetworkAccessProfileSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks/{Sid}"; + + path = + path.replace( + "{" + "NetworkAccessProfileSid" + "}", + this.pathNetworkAccessProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "NetworkAccessProfileNetwork delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkFetcher.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkFetcher.java new file mode 100644 index 0000000000..307a3a418a --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkFetcher.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.networkaccessprofile; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NetworkAccessProfileNetworkFetcher + extends Fetcher { + + private String pathNetworkAccessProfileSid; + private String pathSid; + + public NetworkAccessProfileNetworkFetcher( + final String pathNetworkAccessProfileSid, + final String pathSid + ) { + this.pathNetworkAccessProfileSid = pathNetworkAccessProfileSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks/{Sid}"; + + path = + path.replace( + "{" + "NetworkAccessProfileSid" + "}", + this.pathNetworkAccessProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "NetworkAccessProfileNetwork fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public NetworkAccessProfileNetwork fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return NetworkAccessProfileNetwork.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + NetworkAccessProfileNetwork content = + NetworkAccessProfileNetwork.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkReader.java b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkReader.java new file mode 100644 index 0000000000..39a1bceb7a --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/networkaccessprofile/NetworkAccessProfileNetworkReader.java @@ -0,0 +1,216 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.networkaccessprofile; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class NetworkAccessProfileNetworkReader + extends Reader { + + private String pathNetworkAccessProfileSid; + private Long pageSize; + + public NetworkAccessProfileNetworkReader( + final String pathNetworkAccessProfileSid + ) { + this.pathNetworkAccessProfileSid = pathNetworkAccessProfileSid; + } + + public NetworkAccessProfileNetworkReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "networks", + response.getContent(), + NetworkAccessProfileNetwork.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/NetworkAccessProfiles/{NetworkAccessProfileSid}/Networks"; + + path = + path.replace( + "{" + "NetworkAccessProfileSid" + "}", + this.pathNetworkAccessProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "networks", + response.getContent(), + NetworkAccessProfileNetwork.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "NetworkAccessProfileNetwork read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "networks", + response.getContent(), + NetworkAccessProfileNetwork.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriod.java b/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriod.java new file mode 100644 index 0000000000..7d0954a46e --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriod.java @@ -0,0 +1,227 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.sim; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class BillingPeriod extends Resource { + + public static BillingPeriodReader reader(final String pathSimSid) { + return new BillingPeriodReader(pathSimSid); + } + + public enum BpType { + READY("ready"), + ACTIVE("active"); + + private final String value; + + private BpType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BpType forValue(final String value) { + return Promoter.enumFromString(value, BpType.values()); + } + } + + /** + * Converts a JSON String into a BillingPeriod object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return BillingPeriod object represented by the provided JSON + */ + public static BillingPeriod fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BillingPeriod.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a BillingPeriod object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return BillingPeriod object represented by the provided JSON + */ + public static BillingPeriod fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, BillingPeriod.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; + + @Getter + private final BillingPeriod.BpType periodType; + + @Getter + private final String sid; + + @Getter + private final String simSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime startTime; + + @JsonCreator + private BillingPeriod( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty("period_type") final BillingPeriod.BpType periodType, + @JsonProperty("sid") final String sid, + @JsonProperty("sim_sid") final String simSid, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime startTime + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.endTime = endTime; + this.periodType = periodType; + this.sid = sid; + this.simSid = simSid; + this.startTime = startTime; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + BillingPeriod other = (BillingPeriod) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(endTime, other.endTime) && + Objects.equals(periodType, other.periodType) && + Objects.equals(sid, other.sid) && + Objects.equals(simSid, other.simSid) && + Objects.equals(startTime, other.startTime) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + endTime, + periodType, + sid, + simSid, + startTime + ); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriodReader.java b/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriodReader.java new file mode 100644 index 0000000000..c7ee3e7a77 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/sim/BillingPeriodReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.sim; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class BillingPeriodReader extends Reader { + + private String pathSimSid; + private Long pageSize; + + public BillingPeriodReader(final String pathSimSid) { + this.pathSimSid = pathSimSid; + } + + public BillingPeriodReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "billing_periods", + response.getContent(), + BillingPeriod.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Sims/{SimSid}/BillingPeriods"; + + path = path.replace("{" + "SimSid" + "}", this.pathSimSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "billing_periods", + response.getContent(), + BillingPeriod.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "BillingPeriod read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "billing_periods", + response.getContent(), + BillingPeriod.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddress.java b/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddress.java new file mode 100644 index 0000000000..5881c2463b --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddress.java @@ -0,0 +1,161 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.sim; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SimIpAddress extends Resource { + + public static SimIpAddressReader reader(final String pathSimSid) { + return new SimIpAddressReader(pathSimSid); + } + + public enum IpAddressVersion { + I_PV4("IPv4"), + I_PV6("IPv6"); + + private final String value; + + private IpAddressVersion(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static IpAddressVersion forValue(final String value) { + return Promoter.enumFromString(value, IpAddressVersion.values()); + } + } + + /** + * Converts a JSON String into a SimIpAddress object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SimIpAddress object represented by the provided JSON + */ + public static SimIpAddress fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SimIpAddress.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SimIpAddress object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SimIpAddress object represented by the provided JSON + */ + public static SimIpAddress fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SimIpAddress.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String ipAddress; + + @Getter + private final SimIpAddress.IpAddressVersion ipAddressVersion; + + @JsonCreator + private SimIpAddress( + @JsonProperty("ip_address") final String ipAddress, + @JsonProperty( + "ip_address_version" + ) final SimIpAddress.IpAddressVersion ipAddressVersion + ) { + this.ipAddress = ipAddress; + this.ipAddressVersion = ipAddressVersion; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SimIpAddress other = (SimIpAddress) o; + return ( + Objects.equals(ipAddress, other.ipAddress) && + Objects.equals(ipAddressVersion, other.ipAddressVersion) + ); + } + + @Override + public int hashCode() { + return Objects.hash(ipAddress, ipAddressVersion); + } +} diff --git a/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddressReader.java b/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddressReader.java new file mode 100644 index 0000000000..17df611f81 --- /dev/null +++ b/src/main/java/com/twilio/rest/supersim/v1/sim/SimIpAddressReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Supersim + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.supersim.v1.sim; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SimIpAddressReader extends Reader { + + private String pathSimSid; + private Long pageSize; + + public SimIpAddressReader(final String pathSimSid) { + this.pathSimSid = pathSimSid; + } + + public SimIpAddressReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_addresses", + response.getContent(), + SimIpAddress.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Sims/{SimSid}/IpAddresses"; + + path = path.replace("{" + "SimSid" + "}", this.pathSimSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.SUPERSIM.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_addresses", + response.getContent(), + SimIpAddress.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SimIpAddress read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "ip_addresses", + response.getContent(), + SimIpAddress.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/Service.java b/src/main/java/com/twilio/rest/sync/v1/Service.java index 93133ffebf..99e156ac1b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/Service.java +++ b/src/main/java/com/twilio/rest/sync/v1/Service.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1; @@ -11,91 +18,62 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Service extends Resource { - private static final long serialVersionUID = 123093367857654L; - /** - * Create a ServiceFetcher to execute fetch. - * - * @param pathSid The sid - * @return ServiceFetcher capable of executing the fetch - */ - public static ServiceFetcher fetcher(final String pathSid) { - return new ServiceFetcher(pathSid); + public static ServiceCreator creator() { + return new ServiceCreator(); } - /** - * Create a ServiceDeleter to execute delete. - * - * @param pathSid The sid - * @return ServiceDeleter capable of executing the delete - */ public static ServiceDeleter deleter(final String pathSid) { return new ServiceDeleter(pathSid); } - /** - * Create a ServiceCreator to execute create. - * - * @return ServiceCreator capable of executing the create - */ - public static ServiceCreator creator() { - return new ServiceCreator(); + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); } - /** - * Create a ServiceReader to execute read. - * - * @return ServiceReader capable of executing the read - */ public static ServiceReader reader() { return new ServiceReader(); } - /** - * Create a ServiceUpdater to execute update. - * - * @param pathSid The sid - * @return ServiceUpdater capable of executing the update - */ public static ServiceUpdater updater(final String pathSid) { return new ServiceUpdater(pathSid); } /** * Converts a JSON String into a Service object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final String json, final ObjectMapper objectMapper) { + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -109,12 +87,15 @@ public static Service fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a Service object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Service object represented by the provided JSON */ - public static Service fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Service.class); @@ -125,156 +106,109 @@ public static Service fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String uniqueName; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - private final URI webhookUrl; - private final Boolean reachabilityWebhooksEnabled; + + @Getter private final Boolean aclEnabled; - private final Map links; - @JsonCreator - private Service(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url, - @JsonProperty("webhook_url") - final URI webhookUrl, - @JsonProperty("reachability_webhooks_enabled") - final Boolean reachabilityWebhooksEnabled, - @JsonProperty("acl_enabled") - final Boolean aclEnabled, - @JsonProperty("links") - final Map links) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; - this.webhookUrl = webhookUrl; - this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; - this.aclEnabled = aclEnabled; - this.links = links; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The unique_name. - * - * @return The unique_name - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String friendlyName; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Map links; - /** - * Returns The Human-readable name for this service instance. - * - * @return Human-readable name for this service instance - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final Boolean reachabilityDebouncingEnabled; - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Integer reachabilityDebouncingWindow; - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Boolean reachabilityWebhooksEnabled; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final String sid; - /** - * Returns The A URL that will receive event updates when objects are - * manipulated.. - * - * @return A URL that will receive event updates when objects are manipulated. - */ - public final URI getWebhookUrl() { - return this.webhookUrl; - } + @Getter + private final String uniqueName; - /** - * Returns The true or false - controls whether this instance fires webhooks - * when client endpoints connect to Sync. - * - * @return true or false - controls whether this instance fires webhooks when - * client endpoints connect to Sync - */ - public final Boolean getReachabilityWebhooksEnabled() { - return this.reachabilityWebhooksEnabled; - } + @Getter + private final URI url; - /** - * Returns The true or false - determines whether token identities must be - * granted access to Sync objects via the Permissions API in this Service.. - * - * @return true or false - determines whether token identities must be granted - * access to Sync objects via the Permissions API in this Service. - */ - public final Boolean getAclEnabled() { - return this.aclEnabled; - } + @Getter + private final URI webhookUrl; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @Getter + private final Boolean webhooksFromRestEnabled; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("acl_enabled") final Boolean aclEnabled, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty( + "reachability_debouncing_enabled" + ) final Boolean reachabilityDebouncingEnabled, + @JsonProperty( + "reachability_debouncing_window" + ) final Integer reachabilityDebouncingWindow, + @JsonProperty( + "reachability_webhooks_enabled" + ) final Boolean reachabilityWebhooksEnabled, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("webhook_url") final URI webhookUrl, + @JsonProperty( + "webhooks_from_rest_enabled" + ) final Boolean webhooksFromRestEnabled + ) { + this.accountSid = accountSid; + this.aclEnabled = aclEnabled; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.links = links; + this.reachabilityDebouncingEnabled = reachabilityDebouncingEnabled; + this.reachabilityDebouncingWindow = reachabilityDebouncingWindow; + this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; + this.webhookUrl = webhookUrl; + this.webhooksFromRestEnabled = webhooksFromRestEnabled; } @Override @@ -288,49 +222,53 @@ public boolean equals(final Object o) { } Service other = (Service) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url) && - Objects.equals(webhookUrl, other.webhookUrl) && - Objects.equals(reachabilityWebhooksEnabled, other.reachabilityWebhooksEnabled) && - Objects.equals(aclEnabled, other.aclEnabled) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(aclEnabled, other.aclEnabled) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals( + reachabilityDebouncingEnabled, + other.reachabilityDebouncingEnabled + ) && + Objects.equals( + reachabilityDebouncingWindow, + other.reachabilityDebouncingWindow + ) && + Objects.equals( + reachabilityWebhooksEnabled, + other.reachabilityWebhooksEnabled + ) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(webhookUrl, other.webhookUrl) && + Objects.equals( + webhooksFromRestEnabled, + other.webhooksFromRestEnabled + ) + ); } @Override public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - friendlyName, - dateCreated, - dateUpdated, - url, - webhookUrl, - reachabilityWebhooksEnabled, - aclEnabled, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .add("webhookUrl", webhookUrl) - .add("reachabilityWebhooksEnabled", reachabilityWebhooksEnabled) - .add("aclEnabled", aclEnabled) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + aclEnabled, + dateCreated, + dateUpdated, + friendlyName, + links, + reachabilityDebouncingEnabled, + reachabilityDebouncingWindow, + reachabilityWebhooksEnabled, + sid, + uniqueName, + url, + webhookUrl, + webhooksFromRestEnabled + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceCreator.java b/src/main/java/com/twilio/rest/sync/v1/ServiceCreator.java index e96329587c..817d2068ca 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,142 +28,187 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceCreator extends Creator { + private String friendlyName; private URI webhookUrl; private Boolean reachabilityWebhooksEnabled; private Boolean aclEnabled; + private Boolean reachabilityDebouncingEnabled; + private Integer reachabilityDebouncingWindow; + private Boolean webhooksFromRestEnabled; + + public ServiceCreator() {} - /** - * Human-readable name for this service instance. - * - * @param friendlyName Human-readable name for this service instance - * @return this - */ public ServiceCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A URL that will receive event updates when objects are manipulated.. - * - * @param webhookUrl A URL that will receive event updates when objects are - * manipulated. - * @return this - */ public ServiceCreator setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - /** - * A URL that will receive event updates when objects are manipulated.. - * - * @param webhookUrl A URL that will receive event updates when objects are - * manipulated. - * @return this - */ public ServiceCreator setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - /** - * `true` or `false` - controls whether this instance fires webhooks when client - * endpoints connect to Sync Defaults to false.. - * - * @param reachabilityWebhooksEnabled true or false - controls whether this - * instance fires webhooks when client - * endpoints connect to Sync - * @return this - */ - public ServiceCreator setReachabilityWebhooksEnabled(final Boolean reachabilityWebhooksEnabled) { + public ServiceCreator setReachabilityWebhooksEnabled( + final Boolean reachabilityWebhooksEnabled + ) { this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; return this; } - /** - * `true` or `false` - determines whether token identities must be granted - * access to Sync objects via the [Permissions - * API](https://www.twilio.com/docs/api/sync/rest/sync-rest-api-permissions) in - * this Service.. - * - * @param aclEnabled true or false - determines whether token identities must - * be granted access to Sync objects via the Permissions API - * in this Service. - * @return this - */ public ServiceCreator setAclEnabled(final Boolean aclEnabled) { this.aclEnabled = aclEnabled; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service create(final TwilioRestClient client) { + public ServiceCreator setReachabilityDebouncingEnabled( + final Boolean reachabilityDebouncingEnabled + ) { + this.reachabilityDebouncingEnabled = reachabilityDebouncingEnabled; + return this; + } + + public ServiceCreator setReachabilityDebouncingWindow( + final Integer reachabilityDebouncingWindow + ) { + this.reachabilityDebouncingWindow = reachabilityDebouncingWindow; + return this; + } + + public ServiceCreator setWebhooksFromRestEnabled( + final Boolean webhooksFromRestEnabled + ) { + this.webhooksFromRestEnabled = webhooksFromRestEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (webhookUrl != null) { - request.addPostParam("WebhookUrl", webhookUrl.toString()); + Serializer.toString( + request, + "WebhookUrl", + webhookUrl, + ParameterType.URLENCODED + ); } if (reachabilityWebhooksEnabled != null) { - request.addPostParam("ReachabilityWebhooksEnabled", reachabilityWebhooksEnabled.toString()); + Serializer.toString( + request, + "ReachabilityWebhooksEnabled", + reachabilityWebhooksEnabled, + ParameterType.URLENCODED + ); } if (aclEnabled != null) { - request.addPostParam("AclEnabled", aclEnabled.toString()); + Serializer.toString( + request, + "AclEnabled", + aclEnabled, + ParameterType.URLENCODED + ); + } + + if (reachabilityDebouncingEnabled != null) { + Serializer.toString( + request, + "ReachabilityDebouncingEnabled", + reachabilityDebouncingEnabled, + ParameterType.URLENCODED + ); + } + + if (reachabilityDebouncingWindow != null) { + Serializer.toString( + request, + "ReachabilityDebouncingWindow", + reachabilityDebouncingWindow, + ParameterType.URLENCODED + ); + } + + if (webhooksFromRestEnabled != null) { + Serializer.toString( + request, + "WebhooksFromRestEnabled", + webhooksFromRestEnabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceDeleter.java b/src/main/java/com/twilio/rest/sync/v1/ServiceDeleter.java index e4b23c2192..93aa67d1df 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new ServiceDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceFetcher.java b/src/main/java/com/twilio/rest/sync/v1/ServiceFetcher.java index 1c5459fea5..8092a5d685 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new ServiceFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public ServiceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceReader.java b/src/main/java/com/twilio/rest/sync/v1/ServiceReader.java index d6464a314d..85efa14c7e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1; @@ -10,152 +17,186 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services"; + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Service ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Service Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Service read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "services", - response.getContent(), - Service.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/ServiceUpdater.java b/src/main/java/com/twilio/rest/sync/v1/ServiceUpdater.java index a69e17e8f7..6c3aa0f03d 100644 --- a/src/main/java/com/twilio/rest/sync/v1/ServiceUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/ServiceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,152 +28,192 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class ServiceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private URI webhookUrl; private String friendlyName; private Boolean reachabilityWebhooksEnabled; private Boolean aclEnabled; + private Boolean reachabilityDebouncingEnabled; + private Integer reachabilityDebouncingWindow; + private Boolean webhooksFromRestEnabled; - /** - * Construct a new ServiceUpdater. - * - * @param pathSid The sid - */ public ServiceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * A URL that will receive event updates when objects are manipulated.. - * - * @param webhookUrl A URL that will receive event updates when objects are - * manipulated. - * @return this - */ public ServiceUpdater setWebhookUrl(final URI webhookUrl) { this.webhookUrl = webhookUrl; return this; } - /** - * A URL that will receive event updates when objects are manipulated.. - * - * @param webhookUrl A URL that will receive event updates when objects are - * manipulated. - * @return this - */ public ServiceUpdater setWebhookUrl(final String webhookUrl) { return setWebhookUrl(Promoter.uriFromString(webhookUrl)); } - /** - * Human-readable name for this service instance. - * - * @param friendlyName Human-readable name for this service instance - * @return this - */ public ServiceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * True or false - controls whether this instance fires webhooks when client - * endpoints connect to Sync Defaults to false.. - * - * @param reachabilityWebhooksEnabled True or false - controls whether this - * instance fires webhooks when client - * endpoints connect to Sync - * @return this - */ - public ServiceUpdater setReachabilityWebhooksEnabled(final Boolean reachabilityWebhooksEnabled) { + public ServiceUpdater setReachabilityWebhooksEnabled( + final Boolean reachabilityWebhooksEnabled + ) { this.reachabilityWebhooksEnabled = reachabilityWebhooksEnabled; return this; } - /** - * `true` or `false` - determines whether token identities must be granted - * access to Sync objects via the [Permissions - * API](https://www.twilio.com/docs/api/sync/rest/sync-rest-api-permissions) in - * this Service.. - * - * @param aclEnabled true or false - determines whether token identities must - * be granted access to Sync objects via the Permissions API - * in this Service. - * @return this - */ public ServiceUpdater setAclEnabled(final Boolean aclEnabled) { this.aclEnabled = aclEnabled; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Service - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Service update(final TwilioRestClient client) { + public ServiceUpdater setReachabilityDebouncingEnabled( + final Boolean reachabilityDebouncingEnabled + ) { + this.reachabilityDebouncingEnabled = reachabilityDebouncingEnabled; + return this; + } + + public ServiceUpdater setReachabilityDebouncingWindow( + final Integer reachabilityDebouncingWindow + ) { + this.reachabilityDebouncingWindow = reachabilityDebouncingWindow; + return this; + } + + public ServiceUpdater setWebhooksFromRestEnabled( + final Boolean webhooksFromRestEnabled + ) { + this.webhooksFromRestEnabled = webhooksFromRestEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Service update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); return Service.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (webhookUrl != null) { - request.addPostParam("WebhookUrl", webhookUrl.toString()); + Serializer.toString( + request, + "WebhookUrl", + webhookUrl, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (reachabilityWebhooksEnabled != null) { - request.addPostParam("ReachabilityWebhooksEnabled", reachabilityWebhooksEnabled.toString()); + Serializer.toString( + request, + "ReachabilityWebhooksEnabled", + reachabilityWebhooksEnabled, + ParameterType.URLENCODED + ); } if (aclEnabled != null) { - request.addPostParam("AclEnabled", aclEnabled.toString()); + Serializer.toString( + request, + "AclEnabled", + aclEnabled, + ParameterType.URLENCODED + ); + } + + if (reachabilityDebouncingEnabled != null) { + Serializer.toString( + request, + "ReachabilityDebouncingEnabled", + reachabilityDebouncingEnabled, + ParameterType.URLENCODED + ); + } + + if (reachabilityDebouncingWindow != null) { + Serializer.toString( + request, + "ReachabilityDebouncingWindow", + reachabilityDebouncingWindow, + ParameterType.URLENCODED + ); + } + + if (webhooksFromRestEnabled != null) { + Serializer.toString( + request, + "WebhooksFromRestEnabled", + webhooksFromRestEnabled, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/Document.java b/src/main/java/com/twilio/rest/sync/v1/service/Document.java index dd0da22ac9..e89752accf 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/Document.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/Document.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; @@ -11,101 +18,71 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Document extends Resource { - private static final long serialVersionUID = 114918671939352L; - /** - * Create a DocumentFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return DocumentFetcher capable of executing the fetch - */ - public static DocumentFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new DocumentFetcher(pathServiceSid, pathSid); + public static DocumentCreator creator(final String pathServiceSid) { + return new DocumentCreator(pathServiceSid); } - /** - * Create a DocumentDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return DocumentDeleter capable of executing the delete - */ - public static DocumentDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static DocumentDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new DocumentDeleter(pathServiceSid, pathSid); } - /** - * Create a DocumentCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return DocumentCreator capable of executing the create - */ - public static DocumentCreator creator(final String pathServiceSid) { - return new DocumentCreator(pathServiceSid); + public static DocumentFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new DocumentFetcher(pathServiceSid, pathSid); } - /** - * Create a DocumentReader to execute read. - * - * @param pathServiceSid The service_sid - * @return DocumentReader capable of executing the read - */ public static DocumentReader reader(final String pathServiceSid) { return new DocumentReader(pathServiceSid); } - /** - * Create a DocumentUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return DocumentUpdater capable of executing the update - */ - public static DocumentUpdater updater(final String pathServiceSid, - final String pathSid) { + public static DocumentUpdater updater( + final String pathServiceSid, + final String pathSid + ) { return new DocumentUpdater(pathServiceSid, pathSid); } /** - * Converts a JSON String into a Document object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Document object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Document object represented by the provided JSON */ - public static Document fromJson(final String json, final ObjectMapper objectMapper) { + public static Document fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Document.class); @@ -119,12 +96,15 @@ public static Document fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a Document object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Document object represented by the provided JSON */ - public static Document fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Document fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Document.class); @@ -135,175 +115,96 @@ public static Document fromJson(final InputStream json, final ObjectMapper objec } } - private final String sid; - private final String uniqueName; - private final String accountSid; - private final String serviceSid; - private final URI url; - private final Map links; - private final String revision; - private final Map data; - private final DateTime dateExpires; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private Document(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links, - @JsonProperty("revision") - final String revision, - @JsonProperty("data") - final Map data, - @JsonProperty("date_expires") - final String dateExpires, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.url = url; - this.links = links; - this.revision = revision; - this.data = data; - this.dateExpires = DateConverter.iso8601DateTimeFromString(dateExpires); - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The unique 34-character SID identifier of the Document.. - * - * @return The unique 34-character SID identifier of the Document. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique and addressable name of this Document.. - * - * @return The unique and addressable name of this Document. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String createdBy; - /** - * Returns The The unique SID identifier of the Twilio Account.. - * - * @return The unique SID identifier of the Twilio Account. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Object data; - /** - * Returns The The unique SID identifier of the Service Instance that hosts this - * Document.. - * - * @return The unique SID identifier of the Service Instance that hosts this - * Document. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The absolute URL for this Document.. - * - * @return The absolute URL for this Document. - */ - public final URI getUrl() { - return this.url; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; - /** - * Returns The A dictionary of URL links to nested resources of this Document.. - * - * @return A dictionary of URL links to nested resources of this Document. - */ - public final Map getLinks() { - return this.links; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The Contains the current revision of this Document, represented by a - * string identifier.. - * - * @return Contains the current revision of this Document, represented by a - * string identifier. - */ - public final String getRevision() { - return this.revision; - } + @Getter + private final Map links; - /** - * Returns The Contains arbitrary user-defined, schema-less data that this - * Document stores, represented by a JSON object, up to 16KB.. - * - * @return Contains arbitrary user-defined, schema-less data that this Document - * stores, represented by a JSON object, up to 16KB. - */ - public final Map getData() { - return this.data; - } + @Getter + private final String revision; - /** - * Returns The Contains the date this Document expires and gets deleted - * automatically.. - * - * @return Contains the date this Document expires and gets deleted - * automatically. - */ - public final DateTime getDateExpires() { - return this.dateExpires; - } + @Getter + private final String serviceSid; - /** - * Returns The The date this Document was created, given in UTC ISO 8601 - * format.. - * - * @return The date this Document was created, given in UTC ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The Specifies the date this Document was last updated, given in UTC - * ISO 8601 format.. - * - * @return Specifies the date this Document was last updated, given in UTC ISO - * 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String uniqueName; - /** - * Returns The The identity of the Document creator.. - * - * @return The identity of the Document creator. - */ - public final String getCreatedBy() { - return this.createdBy; + @Getter + private final URI url; + + @JsonCreator + private Document( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("data") final Object data, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.createdBy = createdBy; + this.data = data; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.links = links; + this.revision = revision; + this.serviceSid = serviceSid; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -317,52 +218,37 @@ public boolean equals(final Object o) { } Document other = (Document) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links) && - Objects.equals(revision, other.revision) && - Objects.equals(data, other.data) && - Objects.equals(dateExpires, other.dateExpires) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - serviceSid, - url, - links, - revision, - data, - dateExpires, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("url", url) - .add("links", links) - .add("revision", revision) - .add("data", data) - .add("dateExpires", dateExpires) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + createdBy, + data, + dateCreated, + dateExpires, + dateUpdated, + links, + revision, + serviceSid, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentCreator.java index 923bb77c72..0b206f42e6 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Creator; -import com.twilio.converter.Converter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,118 +27,121 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; private String uniqueName; - private Map data; + private Object data; private Integer ttl; - /** - * Construct a new DocumentCreator. - * - * @param pathServiceSid The service_sid - */ public DocumentCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Human-readable name for this document. - * - * @param uniqueName Human-readable name for this document - * @return this - */ public DocumentCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * JSON data to be stored in this document. - * - * @param data JSON data to be stored in this document - * @return this - */ - public DocumentCreator setData(final Map data) { + public DocumentCreator setData(final Object data) { this.data = data; return this; } - /** - * Time-to-live of this Document in seconds, defaults to no expiration. In the - * range [1, 31 536 000 (1 year)], or 0 for infinity.. - * - * @param ttl Time-to-live of this Document in seconds, defaults to no - * expiration. - * @return this - */ public DocumentCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Document - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Document create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Documents"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Document creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Document create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Document content = Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); + Serializer.toString( + request, + "Data", + data, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentDeleter.java index 14a44e721e..ad467b1cf4 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new DocumentDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public DocumentDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public DocumentDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Documents/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Document delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentFetcher.java index ced639337a..c8f4a55370 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,80 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new DocumentFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public DocumentFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public DocumentFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Document - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Document fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Documents/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Document fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Document fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Document content = Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentReader.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentReader.java index 4cb460b7fb..d2988064b1 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; @@ -10,163 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new DocumentReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public DocumentReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Document ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public DocumentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Document ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "documents", + response.getContent(), + Document.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Documents"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Document ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "documents", + response.getContent(), + Document.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Document read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "documents", + response.getContent(), + Document.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Document Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Document read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "documents", - response.getContent(), - Document.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/DocumentUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/DocumentUpdater.java index 0fe10e31df..28361e36d1 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/DocumentUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/DocumentUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.Converter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,106 +27,127 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; - private Map data; + + private String pathServiceSid; + private String pathSid; + private String ifMatch; + private Object data; private Integer ttl; - /** - * Construct a new DocumentUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public DocumentUpdater(final String pathServiceSid, - final String pathSid) { + public DocumentUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Contains an arbitrary JSON object to be stored in this Document. Serialized - * to string to respect HTTP form input, up to 16KB.. - * - * @param data Contains an arbitrary JSON object to be stored in this Document. - * @return this - */ - public DocumentUpdater setData(final Map data) { + public DocumentUpdater setData(final Object data) { this.data = data; return this; } - /** - * New time-to-live of this Document in seconds. In the range [1, 31 536 000 (1 - * year)], or 0 for infinity.. - * - * @param ttl New time-to-live of this Document in seconds. - * @return this - */ public DocumentUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Document - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Document update(final TwilioRestClient client) { + public DocumentUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Documents/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Document update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Document update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Document.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Document update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Document content = Document.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); + Serializer.toString( + request, + "Data", + data, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncList.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncList.java index 882ab26b3b..c045647b45 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncList.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncList.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; @@ -11,100 +18,71 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SyncList extends Resource { - private static final long serialVersionUID = 113063121662943L; - /** - * Create a SyncListFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncListFetcher capable of executing the fetch - */ - public static SyncListFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new SyncListFetcher(pathServiceSid, pathSid); + public static SyncListCreator creator(final String pathServiceSid) { + return new SyncListCreator(pathServiceSid); } - /** - * Create a SyncListDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncListDeleter capable of executing the delete - */ - public static SyncListDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static SyncListDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SyncListDeleter(pathServiceSid, pathSid); } - /** - * Create a SyncListCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return SyncListCreator capable of executing the create - */ - public static SyncListCreator creator(final String pathServiceSid) { - return new SyncListCreator(pathServiceSid); - } - - /** - * Create a SyncListUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncListUpdater capable of executing the update - */ - public static SyncListUpdater updater(final String pathServiceSid, - final String pathSid) { - return new SyncListUpdater(pathServiceSid, pathSid); + public static SyncListFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new SyncListFetcher(pathServiceSid, pathSid); } - /** - * Create a SyncListReader to execute read. - * - * @param pathServiceSid The service_sid - * @return SyncListReader capable of executing the read - */ public static SyncListReader reader(final String pathServiceSid) { return new SyncListReader(pathServiceSid); } + public static SyncListUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new SyncListUpdater(pathServiceSid, pathSid); + } + /** - * Converts a JSON String into a SyncList object using the provided - * ObjectMapper. - * + * Converts a JSON String into a SyncList object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SyncList object represented by the provided JSON */ - public static SyncList fromJson(final String json, final ObjectMapper objectMapper) { + public static SyncList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncList.class); @@ -118,12 +96,15 @@ public static SyncList fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a SyncList object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SyncList object represented by the provided JSON */ - public static SyncList fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SyncList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncList.class); @@ -134,158 +115,91 @@ public static SyncList fromJson(final InputStream json, final ObjectMapper objec } } - private final String sid; - private final String uniqueName; - private final String accountSid; - private final String serviceSid; - private final URI url; - private final Map links; - private final String revision; - private final DateTime dateExpires; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncList(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links, - @JsonProperty("revision") - final String revision, - @JsonProperty("date_expires") - final String dateExpires, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.url = url; - this.links = links; - this.revision = revision; - this.dateExpires = DateConverter.iso8601DateTimeFromString(dateExpires); - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The unique 34-character SID identifier of the List.. - * - * @return The unique 34-character SID identifier of the List. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique and addressable name of this List.. - * - * @return The unique and addressable name of this List. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String createdBy; - /** - * Returns The The unique SID identifier of the Twilio Account.. - * - * @return The unique SID identifier of the Twilio Account. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique SID identifier of the Service Instance that hosts this - * List object.. - * - * @return The unique SID identifier of the Service Instance that hosts this - * List object. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; - /** - * Returns The The absolute URL for this List.. - * - * @return The absolute URL for this List. - */ - public final URI getUrl() { - return this.url; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A dictionary of URL links to nested resources of this List.. - * - * @return A dictionary of URL links to nested resources of this List. - */ - public final Map getLinks() { - return this.links; - } + @Getter + private final Map links; - /** - * Returns The Contains the current revision of this List, represented by a - * string identifier.. - * - * @return Contains the current revision of this List, represented by a string - * identifier. - */ - public final String getRevision() { - return this.revision; - } + @Getter + private final String revision; - /** - * Returns The Contains the date this List expires and gets deleted - * automatically.. - * - * @return Contains the date this List expires and gets deleted automatically. - */ - public final DateTime getDateExpires() { - return this.dateExpires; - } + @Getter + private final String serviceSid; - /** - * Returns The The date this List was created, given in UTC ISO 8601 format.. - * - * @return The date this List was created, given in UTC ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The Specifies the date this List was last updated, given in UTC ISO - * 8601 format.. - * - * @return Specifies the date this List was last updated, given in UTC ISO 8601 - * format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String uniqueName; - /** - * Returns The The identity of the List creator.. - * - * @return The identity of the List creator. - */ - public final String getCreatedBy() { - return this.createdBy; + @Getter + private final URI url; + + @JsonCreator + private SyncList( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.links = links; + this.revision = revision; + this.serviceSid = serviceSid; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -299,49 +213,35 @@ public boolean equals(final Object o) { } SyncList other = (SyncList) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links) && - Objects.equals(revision, other.revision) && - Objects.equals(dateExpires, other.dateExpires) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - serviceSid, - url, - links, - revision, - dateExpires, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("url", url) - .add("links", links) - .add("revision", revision) - .add("dateExpires", dateExpires) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + createdBy, + dateCreated, + dateExpires, + dateUpdated, + links, + revision, + serviceSid, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListCreator.java index df8bbf8bbe..5385b4be5d 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,99 +27,121 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; private String uniqueName; private Integer ttl; + private Integer collectionTtl; - /** - * Construct a new SyncListCreator. - * - * @param pathServiceSid The service_sid - */ public SyncListCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Human-readable name for this list. - * - * @param uniqueName Human-readable name for this list - * @return this - */ public SyncListCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * Time-to-live of this List in seconds, defaults to no expiration. In the range - * [1, 31 536 000 (1 year)], or 0 for infinity.. - * - * @param ttl Time-to-live of this List in seconds, defaults to no expiration. - * @return this - */ public SyncListCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncList create(final TwilioRestClient client) { + public SyncListCreator setCollectionTtl(final Integer collectionTtl) { + this.collectionTtl = collectionTtl; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncList creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncList create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncList content = SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + + if (collectionTtl != null) { + Serializer.toString( + request, + "CollectionTtl", + collectionTtl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListDeleter.java index e91b4b7b7b..23e4d5d013 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new SyncListDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncListDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public SyncListDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncList delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListFetcher.java index 28d73dcba1..016840860e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,80 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new SyncListFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncListFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public SyncListFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncList fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncList fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncList fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncList content = SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListReader.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListReader.java index e14e1e3ba0..0f45569686 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; @@ -10,163 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new SyncListReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public SyncListReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncList ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SyncListReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncList ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "lists", + response.getContent(), + SyncList.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncList ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "lists", + response.getContent(), + SyncList.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SyncList read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "lists", + response.getContent(), + SyncList.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SyncList Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncList read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "lists", - response.getContent(), - SyncList.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncListUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncListUpdater.java index a4c92516d4..c4f5cb8e69 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncListUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncListUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,87 +27,109 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; private Integer ttl; + private Integer collectionTtl; - /** - * Construct a new SyncListUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncListUpdater(final String pathServiceSid, - final String pathSid) { + public SyncListUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Time-to-live of this List in seconds, defaults to no expiration. In the range - * [1, 31 536 000 (1 year)], or 0 for infinity.. - * - * @param ttl Time-to-live of this List in seconds, defaults to no expiration. - * @return this - */ public SyncListUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncList update(final TwilioRestClient client) { + public SyncListUpdater setCollectionTtl(final Integer collectionTtl) { + this.collectionTtl = collectionTtl; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncList update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncList update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncList update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncList content = SyncList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + + if (collectionTtl != null) { + Serializer.toString( + request, + "CollectionTtl", + collectionTtl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMap.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMap.java index f0926fe9bf..3407204a78 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMap.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMap.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; @@ -11,99 +18,71 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SyncMap extends Resource { - private static final long serialVersionUID = 113063121662943L; - /** - * Create a SyncMapFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncMapFetcher capable of executing the fetch - */ - public static SyncMapFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new SyncMapFetcher(pathServiceSid, pathSid); + public static SyncMapCreator creator(final String pathServiceSid) { + return new SyncMapCreator(pathServiceSid); } - /** - * Create a SyncMapDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncMapDeleter capable of executing the delete - */ - public static SyncMapDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static SyncMapDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SyncMapDeleter(pathServiceSid, pathSid); } - /** - * Create a SyncMapCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return SyncMapCreator capable of executing the create - */ - public static SyncMapCreator creator(final String pathServiceSid) { - return new SyncMapCreator(pathServiceSid); - } - - /** - * Create a SyncMapUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncMapUpdater capable of executing the update - */ - public static SyncMapUpdater updater(final String pathServiceSid, - final String pathSid) { - return new SyncMapUpdater(pathServiceSid, pathSid); + public static SyncMapFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new SyncMapFetcher(pathServiceSid, pathSid); } - /** - * Create a SyncMapReader to execute read. - * - * @param pathServiceSid The service_sid - * @return SyncMapReader capable of executing the read - */ public static SyncMapReader reader(final String pathServiceSid) { return new SyncMapReader(pathServiceSid); } + public static SyncMapUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new SyncMapUpdater(pathServiceSid, pathSid); + } + /** * Converts a JSON String into a SyncMap object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SyncMap object represented by the provided JSON */ - public static SyncMap fromJson(final String json, final ObjectMapper objectMapper) { + public static SyncMap fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMap.class); @@ -117,12 +96,15 @@ public static SyncMap fromJson(final String json, final ObjectMapper objectMappe /** * Converts a JSON InputStream into a SyncMap object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SyncMap object represented by the provided JSON */ - public static SyncMap fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SyncMap fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMap.class); @@ -133,158 +115,91 @@ public static SyncMap fromJson(final InputStream json, final ObjectMapper object } } - private final String sid; - private final String uniqueName; - private final String accountSid; - private final String serviceSid; - private final URI url; - private final Map links; - private final String revision; - private final DateTime dateExpires; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncMap(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links, - @JsonProperty("revision") - final String revision, - @JsonProperty("date_expires") - final String dateExpires, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.url = url; - this.links = links; - this.revision = revision; - this.dateExpires = DateConverter.iso8601DateTimeFromString(dateExpires); - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The unique 34-character SID identifier of the Map.. - * - * @return The unique 34-character SID identifier of the Map. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The The unique and addressable name of this Map.. - * - * @return The unique and addressable name of this Map. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String createdBy; - /** - * Returns The The unique SID identifier of the Twilio Account.. - * - * @return The unique SID identifier of the Twilio Account. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique SID identifier of the Service Instance that hosts this - * Map object.. - * - * @return The unique SID identifier of the Service Instance that hosts this - * Map object. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; - /** - * Returns The The absolute URL for this Map.. - * - * @return The absolute URL for this Map. - */ - public final URI getUrl() { - return this.url; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The A dictionary of URL links to nested resources of this Map.. - * - * @return A dictionary of URL links to nested resources of this Map. - */ - public final Map getLinks() { - return this.links; - } + @Getter + private final Map links; - /** - * Returns The Contains the current revision of this Map, represented by a - * string identifier.. - * - * @return Contains the current revision of this Map, represented by a string - * identifier. - */ - public final String getRevision() { - return this.revision; - } + @Getter + private final String revision; - /** - * Returns The Contains the date this Map expires and gets deleted - * automatically.. - * - * @return Contains the date this Map expires and gets deleted automatically. - */ - public final DateTime getDateExpires() { - return this.dateExpires; - } + @Getter + private final String serviceSid; - /** - * Returns The The date this Map was created, given in UTC ISO 8601 format.. - * - * @return The date this Map was created, given in UTC ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The Specifies the date this Map was last updated, given in UTC ISO - * 8601 format.. - * - * @return Specifies the date this Map was last updated, given in UTC ISO 8601 - * format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String uniqueName; - /** - * Returns The The identity of the Map creator.. - * - * @return The identity of the Map creator. - */ - public final String getCreatedBy() { - return this.createdBy; + @Getter + private final URI url; + + @JsonCreator + private SyncMap( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("links") final Map links, + @JsonProperty("revision") final String revision, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.links = links; + this.revision = revision; + this.serviceSid = serviceSid; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -298,49 +213,35 @@ public boolean equals(final Object o) { } SyncMap other = (SyncMap) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links) && - Objects.equals(revision, other.revision) && - Objects.equals(dateExpires, other.dateExpires) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) && + Objects.equals(revision, other.revision) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - serviceSid, - url, - links, - revision, - dateExpires, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("url", url) - .add("links", links) - .add("revision", revision) - .add("dateExpires", dateExpires) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + createdBy, + dateCreated, + dateExpires, + dateUpdated, + links, + revision, + serviceSid, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapCreator.java index 65c3454b0a..2ec12911e6 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,99 +27,118 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; private String uniqueName; private Integer ttl; + private Integer collectionTtl; - /** - * Construct a new SyncMapCreator. - * - * @param pathServiceSid The service_sid - */ public SyncMapCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Human-readable name for this map. - * - * @param uniqueName Human-readable name for this map - * @return this - */ public SyncMapCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * Time-to-live of this Map in seconds, defaults to no expiration. In the range - * [1, 31 536 000 (1 year)], or 0 for infinity.. - * - * @param ttl Time-to-live of this Map in seconds, defaults to no expiration. - * @return this - */ public SyncMapCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncMap - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMap create(final TwilioRestClient client) { + public SyncMapCreator setCollectionTtl(final Integer collectionTtl) { + this.collectionTtl = collectionTtl; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMap creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public SyncMap create(final TwilioRestClient client) { + Response response = makeRequest(client); return SyncMap.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncMap content = SyncMap.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + + if (collectionTtl != null) { + Serializer.toString( + request, + "CollectionTtl", + collectionTtl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapDeleter.java index 88c3f8e3b6..03f221efc6 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new SyncMapDeleter. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncMapDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public SyncMapDeleter(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMap delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapFetcher.java index 22f21e59db..94d500bcca 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new SyncMapFetcher. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncMapFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public SyncMapFetcher(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncMap - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMap fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMap fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public SyncMap fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return SyncMap.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncMap content = SyncMap.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapReader.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapReader.java index 22ad61b395..b8dd69457f 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; @@ -10,163 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new SyncMapReader. - * - * @param pathServiceSid The service_sid - */ + private String pathServiceSid; + private Long pageSize; + public SyncMapReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMap ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SyncMapReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMap ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "maps", + response.getContent(), + SyncMap.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncMap ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "maps", + response.getContent(), + SyncMap.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SyncMap read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "maps", + response.getContent(), + SyncMap.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SyncMap Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMap read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "maps", - response.getContent(), - SyncMap.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapUpdater.java index cc0e10fe9a..bac68120a5 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncMapUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncMapUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,87 +27,106 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; private Integer ttl; + private Integer collectionTtl; - /** - * Construct a new SyncMapUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncMapUpdater(final String pathServiceSid, - final String pathSid) { + public SyncMapUpdater(final String pathServiceSid, final String pathSid) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * New time-to-live of this Map in seconds. In the range [1, 31 536 000 (1 - * year)], or 0 for infinity.. - * - * @param ttl New time-to-live of this Map in seconds. - * @return this - */ public SyncMapUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncMap - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMap update(final TwilioRestClient client) { + public SyncMapUpdater setCollectionTtl(final Integer collectionTtl) { + this.collectionTtl = collectionTtl; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMap update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMap update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public SyncMap update(final TwilioRestClient client) { + Response response = makeRequest(client); return SyncMap.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncMap content = SyncMap.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + + if (collectionTtl != null) { + Serializer.toString( + request, + "CollectionTtl", + collectionTtl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStream.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStream.java index 97b9317228..eb22b682d5 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStream.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStream.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; @@ -11,100 +18,71 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SyncStream extends Resource { - private static final long serialVersionUID = 240146789601739L; - /** - * Create a SyncStreamFetcher to execute fetch. - * - * @param pathServiceSid Service Instance SID or unique name. - * @param pathSid Stream SID or unique name. - * @return SyncStreamFetcher capable of executing the fetch - */ - public static SyncStreamFetcher fetcher(final String pathServiceSid, - final String pathSid) { - return new SyncStreamFetcher(pathServiceSid, pathSid); + public static SyncStreamCreator creator(final String pathServiceSid) { + return new SyncStreamCreator(pathServiceSid); } - /** - * Create a SyncStreamDeleter to execute delete. - * - * @param pathServiceSid Service Instance SID or unique name. - * @param pathSid Stream SID or unique name. - * @return SyncStreamDeleter capable of executing the delete - */ - public static SyncStreamDeleter deleter(final String pathServiceSid, - final String pathSid) { + public static SyncStreamDeleter deleter( + final String pathServiceSid, + final String pathSid + ) { return new SyncStreamDeleter(pathServiceSid, pathSid); } - /** - * Create a SyncStreamCreator to execute create. - * - * @param pathServiceSid The service_sid - * @return SyncStreamCreator capable of executing the create - */ - public static SyncStreamCreator creator(final String pathServiceSid) { - return new SyncStreamCreator(pathServiceSid); - } - - /** - * Create a SyncStreamUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - * @return SyncStreamUpdater capable of executing the update - */ - public static SyncStreamUpdater updater(final String pathServiceSid, - final String pathSid) { - return new SyncStreamUpdater(pathServiceSid, pathSid); + public static SyncStreamFetcher fetcher( + final String pathServiceSid, + final String pathSid + ) { + return new SyncStreamFetcher(pathServiceSid, pathSid); } - /** - * Create a SyncStreamReader to execute read. - * - * @param pathServiceSid Service Instance SID or unique name. - * @return SyncStreamReader capable of executing the read - */ public static SyncStreamReader reader(final String pathServiceSid) { return new SyncStreamReader(pathServiceSid); } + public static SyncStreamUpdater updater( + final String pathServiceSid, + final String pathSid + ) { + return new SyncStreamUpdater(pathServiceSid, pathSid); + } + /** - * Converts a JSON String into a SyncStream object using the provided - * ObjectMapper. - * + * Converts a JSON String into a SyncStream object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SyncStream object represented by the provided JSON */ - public static SyncStream fromJson(final String json, final ObjectMapper objectMapper) { + public static SyncStream fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncStream.class); @@ -118,12 +96,15 @@ public static SyncStream fromJson(final String json, final ObjectMapper objectMa /** * Converts a JSON InputStream into a SyncStream object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SyncStream object represented by the provided JSON */ - public static SyncStream fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SyncStream fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncStream.class); @@ -134,138 +115,86 @@ public static SyncStream fromJson(final InputStream json, final ObjectMapper obj } } - private final String sid; - private final String uniqueName; - private final String accountSid; - private final String serviceSid; - private final URI url; - private final Map links; - private final DateTime dateExpires; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncStream(@JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links, - @JsonProperty("date_expires") - final String dateExpires, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.sid = sid; - this.uniqueName = uniqueName; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.url = url; - this.links = links; - this.dateExpires = DateConverter.iso8601DateTimeFromString(dateExpires); - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The Stream SID.. - * - * @return Stream SID. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final String accountSid; - /** - * Returns The Stream unique name.. - * - * @return Stream unique name. - */ - public final String getUniqueName() { - return this.uniqueName; - } + @Getter + private final String createdBy; - /** - * Returns The Twilio Account SID.. - * - * @return Twilio Account SID. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The Service Instance SID.. - * - * @return Service Instance SID. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; - /** - * Returns The URL of this Stream.. - * - * @return URL of this Stream. - */ - public final URI getUrl() { - return this.url; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The Nested resource URLs.. - * - * @return Nested resource URLs. - */ - public final Map getLinks() { - return this.links; - } + @Getter + private final Map links; - /** - * Returns The The date this Stream expires.. - * - * @return The date this Stream expires. - */ - public final DateTime getDateExpires() { - return this.dateExpires; - } + @Getter + private final String serviceSid; - /** - * Returns The The date this Stream was created.. - * - * @return The date this Stream was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String sid; - /** - * Returns The The date this Stream was updated.. - * - * @return The date this Stream was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String uniqueName; - /** - * Returns The Identity of the Stream creator.. - * - * @return Identity of the Stream creator. - */ - public final String getCreatedBy() { - return this.createdBy; + @Getter + private final URI url; + + @JsonCreator + private SyncStream( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("links") final Map links, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.createdBy = createdBy; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.links = links; + this.serviceSid = serviceSid; + this.sid = sid; + this.uniqueName = uniqueName; + this.url = url; } @Override @@ -279,46 +208,33 @@ public boolean equals(final Object o) { } SyncStream other = (SyncStream) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links) && - Objects.equals(dateExpires, other.dateExpires) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(sid, - uniqueName, - accountSid, - serviceSid, - url, - links, - dateExpires, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("url", url) - .add("links", links) - .add("dateExpires", dateExpires) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + createdBy, + dateCreated, + dateExpires, + dateUpdated, + links, + serviceSid, + sid, + uniqueName, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamCreator.java index 66d01a1350..c4e4c9c100 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,100 +27,106 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncStreamCreator extends Creator { - private final String pathServiceSid; + + private String pathServiceSid; private String uniqueName; private Integer ttl; - /** - * Construct a new SyncStreamCreator. - * - * @param pathServiceSid The service_sid - */ public SyncStreamCreator(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * The unique and addressable name of this Stream. Optional, up to 256 - * characters long.. - * - * @param uniqueName Stream unique name. - * @return this - */ public SyncStreamCreator setUniqueName(final String uniqueName) { this.uniqueName = uniqueName; return this; } - /** - * Time-to-live of this Stream in seconds, defaults to no expiration. In the - * range [1, 31 536 000 (1 year)], or 0 for infinity.. - * - * @param ttl Stream TTL. - * @return this - */ public SyncStreamCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncStream - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncStream create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Streams"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Streams", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncStream creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return SyncStream.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public SyncStream create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncStream content = SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (uniqueName != null) { - request.addPostParam("UniqueName", uniqueName); + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamDeleter.java index 1b53b24f68..d550447a0c 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,61 +24,84 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncStreamDeleter extends Deleter { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new SyncStreamDeleter. - * - * @param pathServiceSid Service Instance SID or unique name. - * @param pathSid Stream SID or unique name. - */ - public SyncStreamDeleter(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public SyncStreamDeleter( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Streams/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Streams/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncStream delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamFetcher.java index 22c33ca5d6..a3683791a4 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncStreamFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathSid; - /** - * Construct a new SyncStreamFetcher. - * - * @param pathServiceSid Service Instance SID or unique name. - * @param pathSid Stream SID or unique name. - */ - public SyncStreamFetcher(final String pathServiceSid, - final String pathSid) { + private String pathServiceSid; + private String pathSid; + + public SyncStreamFetcher( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncStream - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncStream fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Streams/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Streams/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncStream fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncStream fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncStream.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncStream content = SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamReader.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamReader.java index d2eabdbc88..633819565e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; @@ -10,163 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncStreamReader extends Reader { - private final String pathServiceSid; - /** - * Construct a new SyncStreamReader. - * - * @param pathServiceSid Service Instance SID or unique name. - */ + private String pathServiceSid; + private Long pageSize; + public SyncStreamReader(final String pathServiceSid) { this.pathServiceSid = pathServiceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncStream ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SyncStreamReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncStream ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "streams", + response.getContent(), + SyncStream.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Streams"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Streams", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncStream ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "streams", + response.getContent(), + SyncStream.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SyncStream read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "streams", + response.getContent(), + SyncStream.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SyncStream Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncStream read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "streams", - response.getContent(), - SyncStream.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamUpdater.java index c73a9d8824..f81fd17f4b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/SyncStreamUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,87 +27,97 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncStreamUpdater extends Updater { - private final String pathServiceSid; - private final String pathSid; + + private String pathServiceSid; + private String pathSid; private Integer ttl; - /** - * Construct a new SyncStreamUpdater. - * - * @param pathServiceSid The service_sid - * @param pathSid The sid - */ - public SyncStreamUpdater(final String pathServiceSid, - final String pathSid) { + public SyncStreamUpdater( + final String pathServiceSid, + final String pathSid + ) { this.pathServiceSid = pathServiceSid; this.pathSid = pathSid; } - /** - * New time-to-live of this Stream in seconds. In the range [1, 31 536 000 (1 - * year)], or 0 for infinity.. - * - * @param ttl Stream TTL. - * @return this - */ public SyncStreamUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncStream - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncStream update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Streams/{Sid}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Streams/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncStream update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncStream update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return SyncStream.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public SyncStream update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncStream content = SyncStream.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermission.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermission.java index e9c6c9e4af..16c23f7a22 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermission.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermission.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.document; @@ -11,105 +18,87 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class DocumentPermission extends Resource { - private static final long serialVersionUID = 172715793000822L; - /** - * Create a DocumentPermissionFetcher to execute fetch. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - * @return DocumentPermissionFetcher capable of executing the fetch - */ - public static DocumentPermissionFetcher fetcher(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity) { - return new DocumentPermissionFetcher(pathServiceSid, pathDocumentSid, pathIdentity); - } - - /** - * Create a DocumentPermissionDeleter to execute delete. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - * @return DocumentPermissionDeleter capable of executing the delete - */ - public static DocumentPermissionDeleter deleter(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity) { - return new DocumentPermissionDeleter(pathServiceSid, pathDocumentSid, pathIdentity); - } - - /** - * Create a DocumentPermissionReader to execute read. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathDocumentSid Sync Document SID or unique name. - * @return DocumentPermissionReader capable of executing the read - */ - public static DocumentPermissionReader reader(final String pathServiceSid, - final String pathDocumentSid) { + public static DocumentPermissionDeleter deleter( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { + return new DocumentPermissionDeleter( + pathServiceSid, + pathDocumentSid, + pathIdentity + ); + } + + public static DocumentPermissionFetcher fetcher( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { + return new DocumentPermissionFetcher( + pathServiceSid, + pathDocumentSid, + pathIdentity + ); + } + + public static DocumentPermissionReader reader( + final String pathServiceSid, + final String pathDocumentSid + ) { return new DocumentPermissionReader(pathServiceSid, pathDocumentSid); } - /** - * Create a DocumentPermissionUpdater to execute update. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - * @return DocumentPermissionUpdater capable of executing the update - */ - public static DocumentPermissionUpdater updater(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - return new DocumentPermissionUpdater(pathServiceSid, pathDocumentSid, pathIdentity, read, write, manage); + public static DocumentPermissionUpdater updater( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new DocumentPermissionUpdater( + pathServiceSid, + pathDocumentSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a DocumentPermission object using the provided - * ObjectMapper. - * + * Converts a JSON String into a DocumentPermission object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return DocumentPermission object represented by the provided JSON */ - public static DocumentPermission fromJson(final String json, final ObjectMapper objectMapper) { + public static DocumentPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DocumentPermission.class); @@ -121,14 +110,17 @@ public static DocumentPermission fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a DocumentPermission object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a DocumentPermission object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return DocumentPermission object represented by the provided JSON */ - public static DocumentPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static DocumentPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, DocumentPermission.class); @@ -139,113 +131,61 @@ public static DocumentPermission fromJson(final InputStream json, final ObjectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; + + @Getter private final String documentSid; + + @Getter private final String identity; - private final Boolean read; - private final Boolean write; + + @Getter private final Boolean manage; + + @Getter + private final Boolean read; + + @Getter + private final String serviceSid; + + @Getter private final URI url; + @Getter + private final Boolean write; + @JsonCreator - private DocumentPermission(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("document_sid") - final String documentSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("read") - final Boolean read, - @JsonProperty("write") - final Boolean write, - @JsonProperty("manage") - final Boolean manage, - @JsonProperty("url") - final URI url) { + private DocumentPermission( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("document_sid") final String documentSid, + @JsonProperty("identity") final String identity, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("read") final Boolean read, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("write") final Boolean write + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; this.documentSid = documentSid; this.identity = identity; - this.read = read; - this.write = write; this.manage = manage; + this.read = read; + this.serviceSid = serviceSid; this.url = url; - } - - /** - * Returns The Twilio Account SID.. - * - * @return Twilio Account SID. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Sync Service Instance SID.. - * - * @return Sync Service Instance SID. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Sync Document SID.. - * - * @return Sync Document SID. - */ - public final String getDocumentSid() { - return this.documentSid; - } - - /** - * Returns The Identity of the user to whom the Sync Document Permission - * applies.. - * - * @return Identity of the user to whom the Sync Document Permission applies. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Read access.. - * - * @return Read access. - */ - public final Boolean getRead() { - return this.read; - } - - /** - * Returns The Write access.. - * - * @return Write access. - */ - public final Boolean getWrite() { - return this.write; - } - - /** - * Returns The Manage access.. - * - * @return Manage access. - */ - public final Boolean getManage() { - return this.manage; - } - - /** - * Returns The URL of this Sync Document Permission.. - * - * @return URL of this Sync Document Permission. - */ - public final URI getUrl() { - return this.url; + this.write = write; } @Override @@ -259,40 +199,29 @@ public boolean equals(final Object o) { } DocumentPermission other = (DocumentPermission) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(documentSid, other.documentSid) && - Objects.equals(identity, other.identity) && - Objects.equals(read, other.read) && - Objects.equals(write, other.write) && - Objects.equals(manage, other.manage) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(documentSid, other.documentSid) && + Objects.equals(identity, other.identity) && + Objects.equals(manage, other.manage) && + Objects.equals(read, other.read) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(write, other.write) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - documentSid, - identity, - read, - write, - manage, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("documentSid", documentSid) - .add("identity", identity) - .add("read", read) - .add("write", write) - .add("manage", manage) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + documentSid, + identity, + manage, + read, + serviceSid, + url, + write + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionDeleter.java index 6642c0e46b..d6034abc5c 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.document; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,94 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentPermissionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathDocumentSid; - private final String pathIdentity; - /** - * Construct a new DocumentPermissionDeleter. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - */ - public DocumentPermissionDeleter(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity) { + private String pathServiceSid; + private String pathDocumentSid; + private String pathIdentity; + + public DocumentPermissionDeleter( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents/" + this.pathDocumentSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "DocumentPermission delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionFetcher.java index e4fd940315..4c52e8b4e4 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.document; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,93 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentPermissionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathDocumentSid; - private final String pathIdentity; - /** - * Construct a new DocumentPermissionFetcher. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - */ - public DocumentPermissionFetcher(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity) { + private String pathServiceSid; + private String pathDocumentSid; + private String pathIdentity; + + public DocumentPermissionFetcher( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched DocumentPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public DocumentPermission fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents/" + this.pathDocumentSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "DocumentPermission fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public DocumentPermission fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return DocumentPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return DocumentPermission.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DocumentPermission content = DocumentPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionReader.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionReader.java index ed844133c0..899019ea9b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.document; @@ -10,167 +17,206 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentPermissionReader extends Reader { - private final String pathServiceSid; - private final String pathDocumentSid; - - /** - * Construct a new DocumentPermissionReader. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathDocumentSid Sync Document SID or unique name. - */ - public DocumentPermissionReader(final String pathServiceSid, - final String pathDocumentSid) { + + private String pathServiceSid; + private String pathDocumentSid; + private Long pageSize; + + public DocumentPermissionReader( + final String pathServiceSid, + final String pathDocumentSid + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return DocumentPermission ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public DocumentPermissionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return DocumentPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "permissions", + response.getContent(), + DocumentPermission.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents/" + this.pathDocumentSid + "/Permissions", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return DocumentPermission ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "permissions", + response.getContent(), + DocumentPermission.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "DocumentPermission read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "permissions", + response.getContent(), + DocumentPermission.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of DocumentPermission Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("DocumentPermission read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "permissions", - response.getContent(), - DocumentPermission.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionUpdater.java index 391762447d..689c895ef1 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/document/DocumentPermissionUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.document; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,36 +27,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class DocumentPermissionUpdater extends Updater { - private final String pathServiceSid; - private final String pathDocumentSid; - private final String pathIdentity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - - /** - * Construct a new DocumentPermissionUpdater. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathDocumentSid Sync Document SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Document - * Permission applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - */ - public DocumentPermissionUpdater(final String pathServiceSid, - final String pathDocumentSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { + + private String pathServiceSid; + private String pathDocumentSid; + private String pathIdentity; + private Boolean read; + private Boolean write; + private Boolean manage; + + public DocumentPermissionUpdater( + final String pathServiceSid, + final String pathDocumentSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathDocumentSid = pathDocumentSid; this.pathIdentity = pathIdentity; @@ -54,61 +55,120 @@ public DocumentPermissionUpdater(final String pathServiceSid, this.manage = manage; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated DocumentPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public DocumentPermission update(final TwilioRestClient client) { + public DocumentPermissionUpdater setRead(final Boolean read) { + this.read = read; + return this; + } + + public DocumentPermissionUpdater setWrite(final Boolean write) { + this.write = write; + return this; + } + + public DocumentPermissionUpdater setManage(final Boolean manage) { + this.manage = manage; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Documents/{DocumentSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "DocumentSid" + "}", + this.pathDocumentSid.toString() + ); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Documents/" + this.pathDocumentSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("DocumentPermission update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "DocumentPermission update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public DocumentPermission update(final TwilioRestClient client) { + Response response = makeRequest(client); + return DocumentPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return DocumentPermission.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + DocumentPermission content = DocumentPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (read != null) { - request.addPostParam("Read", read.toString()); + Serializer.toString( + request, + "Read", + read, + ParameterType.URLENCODED + ); } if (write != null) { - request.addPostParam("Write", write.toString()); + Serializer.toString( + request, + "Write", + write, + ParameterType.URLENCODED + ); } if (manage != null) { - request.addPostParam("Manage", manage.toString()); + Serializer.toString( + request, + "Manage", + manage, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItem.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItem.java index b9907d2cf3..6aa5430663 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItem.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItem.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; @@ -10,37 +17,71 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SyncListItem extends Resource { - private static final long serialVersionUID = 156990163506527L; + + public static SyncListItemCreator creator( + final String pathServiceSid, + final String pathListSid, + final Object data + ) { + return new SyncListItemCreator(pathServiceSid, pathListSid, data); + } + + public static SyncListItemDeleter deleter( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { + return new SyncListItemDeleter(pathServiceSid, pathListSid, pathIndex); + } + + public static SyncListItemFetcher fetcher( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { + return new SyncListItemFetcher(pathServiceSid, pathListSid, pathIndex); + } + + public static SyncListItemReader reader( + final String pathServiceSid, + final String pathListSid + ) { + return new SyncListItemReader(pathServiceSid, pathListSid); + } + + public static SyncListItemUpdater updater( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { + return new SyncListItemUpdater(pathServiceSid, pathListSid, pathIndex); + } public enum QueryResultOrder { ASC("asc"), @@ -52,15 +93,11 @@ private QueryResultOrder(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a QueryResultOrder from a string. - * @param value string value - * @return generated QueryResultOrder - */ @JsonCreator public static QueryResultOrder forValue(final String value) { return Promoter.enumFromString(value, QueryResultOrder.values()); @@ -77,15 +114,11 @@ private QueryFromBoundType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a QueryFromBoundType from a string. - * @param value string value - * @return generated QueryFromBoundType - */ @JsonCreator public static QueryFromBoundType forValue(final String value) { return Promoter.enumFromString(value, QueryFromBoundType.values()); @@ -93,83 +126,16 @@ public static QueryFromBoundType forValue(final String value) { } /** - * Create a SyncListItemFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - * @return SyncListItemFetcher capable of executing the fetch - */ - public static SyncListItemFetcher fetcher(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { - return new SyncListItemFetcher(pathServiceSid, pathListSid, pathIndex); - } - - /** - * Create a SyncListItemDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - * @return SyncListItemDeleter capable of executing the delete - */ - public static SyncListItemDeleter deleter(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { - return new SyncListItemDeleter(pathServiceSid, pathListSid, pathIndex); - } - - /** - * Create a SyncListItemCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param data Contains arbitrary user-defined, schema-less data that this List - * Item stores, represented by a JSON object, up to 16KB. - * @return SyncListItemCreator capable of executing the create - */ - public static SyncListItemCreator creator(final String pathServiceSid, - final String pathListSid, - final Map data) { - return new SyncListItemCreator(pathServiceSid, pathListSid, data); - } - - /** - * Create a SyncListItemReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @return SyncListItemReader capable of executing the read - */ - public static SyncListItemReader reader(final String pathServiceSid, - final String pathListSid) { - return new SyncListItemReader(pathServiceSid, pathListSid); - } - - /** - * Create a SyncListItemUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - * @return SyncListItemUpdater capable of executing the update - */ - public static SyncListItemUpdater updater(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { - return new SyncListItemUpdater(pathServiceSid, pathListSid, pathIndex); - } - - /** - * Converts a JSON String into a SyncListItem object using the provided - * ObjectMapper. - * + * Converts a JSON String into a SyncListItem object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SyncListItem object represented by the provided JSON */ - public static SyncListItem fromJson(final String json, final ObjectMapper objectMapper) { + public static SyncListItem fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListItem.class); @@ -183,12 +149,15 @@ public static SyncListItem fromJson(final String json, final ObjectMapper object /** * Converts a JSON InputStream into a SyncListItem object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SyncListItem object represented by the provided JSON */ - public static SyncListItem fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SyncListItem fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListItem.class); @@ -199,162 +168,91 @@ public static SyncListItem fromJson(final InputStream json, final ObjectMapper o } } - private final Integer index; - private final String accountSid; - private final String serviceSid; - private final String listSid; - private final URI url; - private final String revision; - private final Map data; - private final DateTime dateExpires; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncListItem(@JsonProperty("index") - final Integer index, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("list_sid") - final String listSid, - @JsonProperty("url") - final URI url, - @JsonProperty("revision") - final String revision, - @JsonProperty("data") - final Map data, - @JsonProperty("date_expires") - final String dateExpires, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.index = index; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.listSid = listSid; - this.url = url; - this.revision = revision; - this.data = data; - this.dateExpires = DateConverter.iso8601DateTimeFromString(dateExpires); - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The Contains the numeric index of this List Item.. - * - * @return Contains the numeric index of this List Item. - */ - public final Integer getIndex() { - return this.index; - } + @Getter + private final String accountSid; - /** - * Returns The The unique SID identifier of the Twilio Account.. - * - * @return The unique SID identifier of the Twilio Account. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String createdBy; - /** - * Returns The The unique SID identifier of the Service Instance that hosts this - * List object.. - * - * @return The unique SID identifier of the Service Instance that hosts this - * List object. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final Object data; - /** - * Returns The The unique 34-character SID identifier of the List containing - * this Item.. - * - * @return The unique 34-character SID identifier of the List containing this - * Item. - */ - public final String getListSid() { - return this.listSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The absolute URL for this item.. - * - * @return The absolute URL for this item. - */ - public final URI getUrl() { - return this.url; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; - /** - * Returns The Contains the current revision of this item, represented by a - * string identifier.. - * - * @return Contains the current revision of this item, represented by a string - * identifier. - */ - public final String getRevision() { - return this.revision; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The Contains arbitrary user-defined, schema-less data that this List - * Item stores, represented by a JSON object, up to 16KB.. - * - * @return Contains arbitrary user-defined, schema-less data that this List - * Item stores, represented by a JSON object, up to 16KB. - */ - public final Map getData() { - return this.data; - } + @Getter + private final Integer index; - /** - * Returns The Contains the date this item expires and gets deleted - * automatically.. - * - * @return Contains the date this item expires and gets deleted automatically. - */ - public final DateTime getDateExpires() { - return this.dateExpires; - } + @Getter + private final String listSid; - /** - * Returns The The date this item was created, given in UTC ISO 8601 format.. - * - * @return The date this item was created, given in UTC ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String revision; - /** - * Returns The Specifies the date this item was last updated, given in UTC ISO - * 8601 format.. - * - * @return Specifies the date this item was last updated, given in UTC ISO 8601 - * format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String serviceSid; - /** - * Returns The The identity of this item's creator.. - * - * @return The identity of this item's creator. - */ - public final String getCreatedBy() { - return this.createdBy; + @Getter + private final URI url; + + @JsonCreator + private SyncListItem( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("data") final Object data, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("index") final Integer index, + @JsonProperty("list_sid") final String listSid, + @JsonProperty("revision") final String revision, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.createdBy = createdBy; + this.data = data; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.index = index; + this.listSid = listSid; + this.revision = revision; + this.serviceSid = serviceSid; + this.url = url; } @Override @@ -368,49 +266,35 @@ public boolean equals(final Object o) { } SyncListItem other = (SyncListItem) o; - - return Objects.equals(index, other.index) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(listSid, other.listSid) && - Objects.equals(url, other.url) && - Objects.equals(revision, other.revision) && - Objects.equals(data, other.data) && - Objects.equals(dateExpires, other.dateExpires) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(index, other.index) && + Objects.equals(listSid, other.listSid) && + Objects.equals(revision, other.revision) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(index, - accountSid, - serviceSid, - listSid, - url, - revision, - data, - dateExpires, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("index", index) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("listSid", listSid) - .add("url", url) - .add("revision", revision) - .add("data", data) - .add("dateExpires", dateExpires) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); + return Objects.hash( + accountSid, + createdBy, + data, + dateCreated, + dateExpires, + dateUpdated, + index, + listSid, + revision, + serviceSid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemCreator.java index d2a851817e..a8328efaf4 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; import com.twilio.base.Creator; -import com.twilio.converter.Converter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,100 +27,144 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListItemCreator extends Creator { - private final String pathServiceSid; - private final String pathListSid; - private final Map data; + + private String pathServiceSid; + private String pathListSid; + private Object data; private Integer ttl; + private Integer itemTtl; + private Integer collectionTtl; - /** - * Construct a new SyncListItemCreator. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param data Contains arbitrary user-defined, schema-less data that this List - * Item stores, represented by a JSON object, up to 16KB. - */ - public SyncListItemCreator(final String pathServiceSid, - final String pathListSid, - final Map data) { + public SyncListItemCreator( + final String pathServiceSid, + final String pathListSid, + final Object data + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.data = data; } - /** - * Time-to-live of this item in seconds, defaults to no expiration. In the range - * [1, 31 536 000 (1 year)], or 0 for infinity. Upon expiry, the list item will - * be cleaned up at least in a matter of hours, and often within seconds, making - * this a good tool for garbage management.. - * - * @param ttl Time-to-live of this item in seconds, defaults to no expiration. - * @return this - */ + public SyncListItemCreator setData(final Object data) { + this.data = data; + return this; + } + public SyncListItemCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncListItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListItem create(final TwilioRestClient client) { + public SyncListItemCreator setItemTtl(final Integer itemTtl) { + this.itemTtl = itemTtl; + return this; + } + + public SyncListItemCreator setCollectionTtl(final Integer collectionTtl) { + this.collectionTtl = collectionTtl; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncListItem creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncListItem create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncListItem content = SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); + Serializer.toString( + request, + "Data", + data, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + + if (itemTtl != null) { + Serializer.toString( + request, + "ItemTtl", + itemTtl, + ParameterType.URLENCODED + ); + } + + if (collectionTtl != null) { + Serializer.toString( + request, + "CollectionTtl", + collectionTtl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemDeleter.java index 3a8e2deb00..0975a950ea 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,65 +26,106 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListItemDeleter extends Deleter { - private final String pathServiceSid; - private final String pathListSid; - private final Integer pathIndex; - /** - * Construct a new SyncListItemDeleter. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - */ - public SyncListItemDeleter(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { + private String pathServiceSid; + private String pathListSid; + private Integer pathIndex; + private String ifMatch; + + public SyncListItemDeleter( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public SyncListItemDeleter setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items/" + this.pathIndex + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncListItem delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemFetcher.java index 0d87e6bd81..eb24536f88 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,87 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListItemFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathListSid; - private final Integer pathIndex; - /** - * Construct a new SyncListItemFetcher. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - */ - public SyncListItemFetcher(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { + private String pathServiceSid; + private String pathListSid; + private Integer pathIndex; + + public SyncListItemFetcher( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncListItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListItem fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items/" + this.pathIndex + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncListItem fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncListItem fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncListItem content = SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemReader.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemReader.java index 8f6027afb8..2f0497c016 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; @@ -10,216 +17,235 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListItemReader extends Reader { - private final String pathServiceSid; - private final String pathListSid; + + private String pathServiceSid; + private String pathListSid; private SyncListItem.QueryResultOrder order; private String from; private SyncListItem.QueryFromBoundType bounds; + private Long pageSize; - /** - * Construct a new SyncListItemReader. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - */ - public SyncListItemReader(final String pathServiceSid, - final String pathListSid) { + public SyncListItemReader( + final String pathServiceSid, + final String pathListSid + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; } - /** - * A string; `asc` or `desc`. - * - * @param order A string; asc or desc - * @return this - */ - public SyncListItemReader setOrder(final SyncListItem.QueryResultOrder order) { + public SyncListItemReader setOrder( + final SyncListItem.QueryResultOrder order + ) { this.order = order; return this; } - /** - * An integer representing Item index offset (inclusive). If not present, query - * is performed from the start or end, depending on the Order query parameter.. - * - * @param from An integer representing Item index offset. - * @return this - */ public SyncListItemReader setFrom(final String from) { this.from = from; return this; } - /** - * The bounds. - * - * @param bounds The bounds - * @return this - */ - public SyncListItemReader setBounds(final SyncListItem.QueryFromBoundType bounds) { + public SyncListItemReader setBounds( + final SyncListItem.QueryFromBoundType bounds + ) { this.bounds = bounds; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncListItem ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SyncListItemReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncListItem ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + SyncListItem.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncListItem ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + SyncListItem.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SyncListItem read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "items", + response.getContent(), + SyncListItem.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SyncListItem Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListItem read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "items", - response.getContent(), - SyncListItem.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); + Serializer.toString(request, "Order", order, ParameterType.QUERY); } if (from != null) { - request.addQueryParam("From", from); + Serializer.toString(request, "From", from, ParameterType.QUERY); } if (bounds != null) { - request.addQueryParam("Bounds", bounds.toString()); + Serializer.toString(request, "Bounds", bounds, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemUpdater.java index dc04426a9f..ef8c16f76b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListItemUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.Converter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,113 +27,164 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListItemUpdater extends Updater { - private final String pathServiceSid; - private final String pathListSid; - private final Integer pathIndex; - private Map data; + + private String pathServiceSid; + private String pathListSid; + private Integer pathIndex; + private String ifMatch; + private Object data; private Integer ttl; + private Integer itemTtl; + private Integer collectionTtl; - /** - * Construct a new SyncListItemUpdater. - * - * @param pathServiceSid The service_sid - * @param pathListSid The list_sid - * @param pathIndex The index - */ - public SyncListItemUpdater(final String pathServiceSid, - final String pathListSid, - final Integer pathIndex) { + public SyncListItemUpdater( + final String pathServiceSid, + final String pathListSid, + final Integer pathIndex + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIndex = pathIndex; } - /** - * Contains arbitrary user-defined, schema-less data that this List Item stores, - * represented by a JSON object, up to 16KB.. - * - * @param data Contains arbitrary user-defined, schema-less data that this List - * Item stores, represented by a JSON object, up to 16KB. - * @return this - */ - public SyncListItemUpdater setData(final Map data) { + public SyncListItemUpdater setData(final Object data) { this.data = data; return this; } - /** - * Time-to-live of this item in seconds, defaults to no expiration. In the range - * [1, 31 536 000 (1 year)], or 0 for infinity. Upon expiry, the list item will - * be cleaned up at least in a matter of hours, and often within seconds, making - * this a good tool for garbage management.. - * - * @param ttl Time-to-live of this item in seconds, defaults to no expiration. - * @return this - */ public SyncListItemUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncListItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListItem update(final TwilioRestClient client) { + public SyncListItemUpdater setItemTtl(final Integer itemTtl) { + this.itemTtl = itemTtl; + return this; + } + + public SyncListItemUpdater setCollectionTtl(final Integer collectionTtl) { + this.collectionTtl = collectionTtl; + return this; + } + + public SyncListItemUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Items/{Index}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = path.replace("{" + "Index" + "}", this.pathIndex.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Items/" + this.pathIndex + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListItem update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncListItem update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return SyncListItem.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public SyncListItem update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncListItem content = SyncListItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); + Serializer.toString( + request, + "Data", + data, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + + if (itemTtl != null) { + Serializer.toString( + request, + "ItemTtl", + itemTtl, + ParameterType.URLENCODED + ); + } + + if (collectionTtl != null) { + Serializer.toString( + request, + "CollectionTtl", + collectionTtl, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermission.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermission.java index 6efe40748c..2a15e30f2c 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermission.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermission.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; @@ -11,105 +18,87 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SyncListPermission extends Resource { - private static final long serialVersionUID = 53631144313647L; - - /** - * Create a SyncListPermissionFetcher to execute fetch. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - * @return SyncListPermissionFetcher capable of executing the fetch - */ - public static SyncListPermissionFetcher fetcher(final String pathServiceSid, - final String pathListSid, - final String pathIdentity) { - return new SyncListPermissionFetcher(pathServiceSid, pathListSid, pathIdentity); - } - - /** - * Create a SyncListPermissionDeleter to execute delete. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - * @return SyncListPermissionDeleter capable of executing the delete - */ - public static SyncListPermissionDeleter deleter(final String pathServiceSid, - final String pathListSid, - final String pathIdentity) { - return new SyncListPermissionDeleter(pathServiceSid, pathListSid, pathIdentity); - } - /** - * Create a SyncListPermissionReader to execute read. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathListSid Sync List SID or unique name. - * @return SyncListPermissionReader capable of executing the read - */ - public static SyncListPermissionReader reader(final String pathServiceSid, - final String pathListSid) { + public static SyncListPermissionDeleter deleter( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { + return new SyncListPermissionDeleter( + pathServiceSid, + pathListSid, + pathIdentity + ); + } + + public static SyncListPermissionFetcher fetcher( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { + return new SyncListPermissionFetcher( + pathServiceSid, + pathListSid, + pathIdentity + ); + } + + public static SyncListPermissionReader reader( + final String pathServiceSid, + final String pathListSid + ) { return new SyncListPermissionReader(pathServiceSid, pathListSid); } - /** - * Create a SyncListPermissionUpdater to execute update. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - * @return SyncListPermissionUpdater capable of executing the update - */ - public static SyncListPermissionUpdater updater(final String pathServiceSid, - final String pathListSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - return new SyncListPermissionUpdater(pathServiceSid, pathListSid, pathIdentity, read, write, manage); + public static SyncListPermissionUpdater updater( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new SyncListPermissionUpdater( + pathServiceSid, + pathListSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a SyncListPermission object using the provided - * ObjectMapper. - * + * Converts a JSON String into a SyncListPermission object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SyncListPermission object represented by the provided JSON */ - public static SyncListPermission fromJson(final String json, final ObjectMapper objectMapper) { + public static SyncListPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListPermission.class); @@ -121,14 +110,17 @@ public static SyncListPermission fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a SyncListPermission object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a SyncListPermission object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SyncListPermission object represented by the provided JSON */ - public static SyncListPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SyncListPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncListPermission.class); @@ -139,112 +131,61 @@ public static SyncListPermission fromJson(final InputStream json, final ObjectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; - private final String listSid; + + @Getter private final String identity; - private final Boolean read; - private final Boolean write; + + @Getter + private final String listSid; + + @Getter private final Boolean manage; + + @Getter + private final Boolean read; + + @Getter + private final String serviceSid; + + @Getter private final URI url; + @Getter + private final Boolean write; + @JsonCreator - private SyncListPermission(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("list_sid") - final String listSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("read") - final Boolean read, - @JsonProperty("write") - final Boolean write, - @JsonProperty("manage") - final Boolean manage, - @JsonProperty("url") - final URI url) { + private SyncListPermission( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("identity") final String identity, + @JsonProperty("list_sid") final String listSid, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("read") final Boolean read, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("write") final Boolean write + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.listSid = listSid; this.identity = identity; - this.read = read; - this.write = write; + this.listSid = listSid; this.manage = manage; + this.read = read; + this.serviceSid = serviceSid; this.url = url; - } - - /** - * Returns The Twilio Account SID.. - * - * @return Twilio Account SID. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Sync Service Instance SID.. - * - * @return Sync Service Instance SID. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Sync List SID.. - * - * @return Sync List SID. - */ - public final String getListSid() { - return this.listSid; - } - - /** - * Returns The Identity of the user to whom the Sync List Permission applies.. - * - * @return Identity of the user to whom the Sync List Permission applies. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Read access.. - * - * @return Read access. - */ - public final Boolean getRead() { - return this.read; - } - - /** - * Returns The Write access.. - * - * @return Write access. - */ - public final Boolean getWrite() { - return this.write; - } - - /** - * Returns The Manage access.. - * - * @return Manage access. - */ - public final Boolean getManage() { - return this.manage; - } - - /** - * Returns The URL of this Sync List Permission.. - * - * @return URL of this Sync List Permission. - */ - public final URI getUrl() { - return this.url; + this.write = write; } @Override @@ -258,40 +199,29 @@ public boolean equals(final Object o) { } SyncListPermission other = (SyncListPermission) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(listSid, other.listSid) && - Objects.equals(identity, other.identity) && - Objects.equals(read, other.read) && - Objects.equals(write, other.write) && - Objects.equals(manage, other.manage) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(identity, other.identity) && + Objects.equals(listSid, other.listSid) && + Objects.equals(manage, other.manage) && + Objects.equals(read, other.read) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(write, other.write) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - listSid, - identity, - read, - write, - manage, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("listSid", listSid) - .add("identity", identity) - .add("read", read) - .add("write", write) - .add("manage", manage) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + identity, + listSid, + manage, + read, + serviceSid, + url, + write + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionDeleter.java index b2e640aef9..b77915aafa 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,90 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListPermissionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathListSid; - private final String pathIdentity; - /** - * Construct a new SyncListPermissionDeleter. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - */ - public SyncListPermissionDeleter(final String pathServiceSid, - final String pathListSid, - final String pathIdentity) { + private String pathServiceSid; + private String pathListSid; + private String pathIdentity; + + public SyncListPermissionDeleter( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncListPermission delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionFetcher.java index de293d09e1..34763ce956 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListPermissionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathListSid; - private final String pathIdentity; - /** - * Construct a new SyncListPermissionFetcher. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - */ - public SyncListPermissionFetcher(final String pathServiceSid, - final String pathListSid, - final String pathIdentity) { + private String pathServiceSid; + private String pathListSid; + private String pathIdentity; + + public SyncListPermissionFetcher( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncListPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListPermission fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncListPermission fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncListPermission fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncListPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncListPermission.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncListPermission content = SyncListPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionReader.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionReader.java index 93af9ba776..1916868443 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; @@ -10,167 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListPermissionReader extends Reader { - private final String pathServiceSid; - private final String pathListSid; - - /** - * Construct a new SyncListPermissionReader. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathListSid Sync List SID or unique name. - */ - public SyncListPermissionReader(final String pathServiceSid, - final String pathListSid) { + + private String pathServiceSid; + private String pathListSid; + private Long pageSize; + + public SyncListPermissionReader( + final String pathServiceSid, + final String pathListSid + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncListPermission ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SyncListPermissionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncListPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "permissions", + response.getContent(), + SyncListPermission.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Permissions", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncListPermission ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "permissions", + response.getContent(), + SyncListPermission.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SyncListPermission read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "permissions", + response.getContent(), + SyncListPermission.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SyncListPermission Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncListPermission read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "permissions", - response.getContent(), - SyncListPermission.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionUpdater.java index abe0382bb5..3dcc555cad 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/synclist/SyncListPermissionUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.synclist; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,36 +27,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncListPermissionUpdater extends Updater { - private final String pathServiceSid; - private final String pathListSid; - private final String pathIdentity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - - /** - * Construct a new SyncListPermissionUpdater. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathListSid Sync List SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync List Permission - * applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - */ - public SyncListPermissionUpdater(final String pathServiceSid, - final String pathListSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { + + private String pathServiceSid; + private String pathListSid; + private String pathIdentity; + private Boolean read; + private Boolean write; + private Boolean manage; + + public SyncListPermissionUpdater( + final String pathServiceSid, + final String pathListSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathListSid = pathListSid; this.pathIdentity = pathIdentity; @@ -54,61 +55,116 @@ public SyncListPermissionUpdater(final String pathServiceSid, this.manage = manage; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncListPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncListPermission update(final TwilioRestClient client) { + public SyncListPermissionUpdater setRead(final Boolean read) { + this.read = read; + return this; + } + + public SyncListPermissionUpdater setWrite(final Boolean write) { + this.write = write; + return this; + } + + public SyncListPermissionUpdater setManage(final Boolean manage) { + this.manage = manage; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Lists/{ListSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "ListSid" + "}", this.pathListSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Lists/" + this.pathListSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncListPermission update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncListPermission update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return SyncListPermission.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public SyncListPermission update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncListPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncListPermission content = SyncListPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (read != null) { - request.addPostParam("Read", read.toString()); + Serializer.toString( + request, + "Read", + read, + ParameterType.URLENCODED + ); } if (write != null) { - request.addPostParam("Write", write.toString()); + Serializer.toString( + request, + "Write", + write, + ParameterType.URLENCODED + ); } if (manage != null) { - request.addPostParam("Manage", manage.toString()); + Serializer.toString( + request, + "Manage", + manage, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItem.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItem.java index c22e7bbb22..8998fcfad0 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItem.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItem.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; @@ -10,37 +17,72 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SyncMapItem extends Resource { - private static final long serialVersionUID = 280430240185290L; + + public static SyncMapItemCreator creator( + final String pathServiceSid, + final String pathMapSid, + final String key, + final Object data + ) { + return new SyncMapItemCreator(pathServiceSid, pathMapSid, key, data); + } + + public static SyncMapItemDeleter deleter( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { + return new SyncMapItemDeleter(pathServiceSid, pathMapSid, pathKey); + } + + public static SyncMapItemFetcher fetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { + return new SyncMapItemFetcher(pathServiceSid, pathMapSid, pathKey); + } + + public static SyncMapItemReader reader( + final String pathServiceSid, + final String pathMapSid + ) { + return new SyncMapItemReader(pathServiceSid, pathMapSid); + } + + public static SyncMapItemUpdater updater( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { + return new SyncMapItemUpdater(pathServiceSid, pathMapSid, pathKey); + } public enum QueryResultOrder { ASC("asc"), @@ -52,15 +94,11 @@ private QueryResultOrder(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a QueryResultOrder from a string. - * @param value string value - * @return generated QueryResultOrder - */ @JsonCreator public static QueryResultOrder forValue(final String value) { return Promoter.enumFromString(value, QueryResultOrder.values()); @@ -77,15 +115,11 @@ private QueryFromBoundType(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a QueryFromBoundType from a string. - * @param value string value - * @return generated QueryFromBoundType - */ @JsonCreator public static QueryFromBoundType forValue(final String value) { return Promoter.enumFromString(value, QueryFromBoundType.values()); @@ -93,85 +127,16 @@ public static QueryFromBoundType forValue(final String value) { } /** - * Create a SyncMapItemFetcher to execute fetch. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - * @return SyncMapItemFetcher capable of executing the fetch - */ - public static SyncMapItemFetcher fetcher(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { - return new SyncMapItemFetcher(pathServiceSid, pathMapSid, pathKey); - } - - /** - * Create a SyncMapItemDeleter to execute delete. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - * @return SyncMapItemDeleter capable of executing the delete - */ - public static SyncMapItemDeleter deleter(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { - return new SyncMapItemDeleter(pathServiceSid, pathMapSid, pathKey); - } - - /** - * Create a SyncMapItemCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param key The unique user-defined key of this Map Item. - * @param data Contains arbitrary user-defined, schema-less data that this Map - * Item stores, represented by a JSON object, up to 16KB. - * @return SyncMapItemCreator capable of executing the create - */ - public static SyncMapItemCreator creator(final String pathServiceSid, - final String pathMapSid, - final String key, - final Map data) { - return new SyncMapItemCreator(pathServiceSid, pathMapSid, key, data); - } - - /** - * Create a SyncMapItemReader to execute read. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @return SyncMapItemReader capable of executing the read - */ - public static SyncMapItemReader reader(final String pathServiceSid, - final String pathMapSid) { - return new SyncMapItemReader(pathServiceSid, pathMapSid); - } - - /** - * Create a SyncMapItemUpdater to execute update. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - * @return SyncMapItemUpdater capable of executing the update - */ - public static SyncMapItemUpdater updater(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { - return new SyncMapItemUpdater(pathServiceSid, pathMapSid, pathKey); - } - - /** - * Converts a JSON String into a SyncMapItem object using the provided - * ObjectMapper. - * + * Converts a JSON String into a SyncMapItem object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SyncMapItem object represented by the provided JSON */ - public static SyncMapItem fromJson(final String json, final ObjectMapper objectMapper) { + public static SyncMapItem fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapItem.class); @@ -185,12 +150,15 @@ public static SyncMapItem fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a SyncMapItem object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SyncMapItem object represented by the provided JSON */ - public static SyncMapItem fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SyncMapItem fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapItem.class); @@ -201,162 +169,91 @@ public static SyncMapItem fromJson(final InputStream json, final ObjectMapper ob } } - private final String key; - private final String accountSid; - private final String serviceSid; - private final String mapSid; - private final URI url; - private final String revision; - private final Map data; - private final DateTime dateExpires; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String createdBy; - - @JsonCreator - private SyncMapItem(@JsonProperty("key") - final String key, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("map_sid") - final String mapSid, - @JsonProperty("url") - final URI url, - @JsonProperty("revision") - final String revision, - @JsonProperty("data") - final Map data, - @JsonProperty("date_expires") - final String dateExpires, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("created_by") - final String createdBy) { - this.key = key; - this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.mapSid = mapSid; - this.url = url; - this.revision = revision; - this.data = data; - this.dateExpires = DateConverter.iso8601DateTimeFromString(dateExpires); - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.createdBy = createdBy; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The unique user-defined key of this Map Item.. - * - * @return The unique user-defined key of this Map Item. - */ - public final String getKey() { - return this.key; - } + @Getter + private final String accountSid; - /** - * Returns The The unique SID identifier of the Twilio Account.. - * - * @return The unique SID identifier of the Twilio Account. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String createdBy; - /** - * Returns The The unique SID identifier of the Service Instance that hosts this - * Map object.. - * - * @return The unique SID identifier of the Service Instance that hosts this - * Map object. - */ - public final String getServiceSid() { - return this.serviceSid; - } + @Getter + private final Object data; - /** - * Returns The The unique 34-character SID identifier of the Map containing this - * Item.. - * - * @return The unique 34-character SID identifier of the Map containing this - * Item. - */ - public final String getMapSid() { - return this.mapSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The absolute URL for this Map.. - * - * @return The absolute URL for this Map. - */ - public final URI getUrl() { - return this.url; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateExpires; - /** - * Returns The Contains the current revision of this Map, represented by a - * string identifier.. - * - * @return Contains the current revision of this Map, represented by a string - * identifier. - */ - public final String getRevision() { - return this.revision; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The Contains arbitrary user-defined, schema-less data that this Map - * Item stores, represented by a JSON object, up to 16KB.. - * - * @return Contains arbitrary user-defined, schema-less data that this Map Item - * stores, represented by a JSON object, up to 16KB. - */ - public final Map getData() { - return this.data; - } + @Getter + private final String key; - /** - * Returns The Contains the date this Map expires and gets deleted - * automatically.. - * - * @return Contains the date this Map expires and gets deleted automatically. - */ - public final DateTime getDateExpires() { - return this.dateExpires; - } + @Getter + private final String mapSid; - /** - * Returns The The date this Map was created, given in UTC ISO 8601 format.. - * - * @return The date this Map was created, given in UTC ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String revision; - /** - * Returns The Specifies the date this Map was last updated, given in UTC ISO - * 8601 format.. - * - * @return Specifies the date this Map was last updated, given in UTC ISO 8601 - * format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final String serviceSid; - /** - * Returns The The identity of the Map creator.. - * - * @return The identity of the Map creator. - */ - public final String getCreatedBy() { - return this.createdBy; + @Getter + private final URI url; + + @JsonCreator + private SyncMapItem( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("created_by") final String createdBy, + @JsonProperty("data") final Object data, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_expires") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateExpires, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("key") final String key, + @JsonProperty("map_sid") final String mapSid, + @JsonProperty("revision") final String revision, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.createdBy = createdBy; + this.data = data; + this.dateCreated = dateCreated; + this.dateExpires = dateExpires; + this.dateUpdated = dateUpdated; + this.key = key; + this.mapSid = mapSid; + this.revision = revision; + this.serviceSid = serviceSid; + this.url = url; } @Override @@ -370,49 +267,35 @@ public boolean equals(final Object o) { } SyncMapItem other = (SyncMapItem) o; - - return Objects.equals(key, other.key) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(mapSid, other.mapSid) && - Objects.equals(url, other.url) && - Objects.equals(revision, other.revision) && - Objects.equals(data, other.data) && - Objects.equals(dateExpires, other.dateExpires) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(createdBy, other.createdBy); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(createdBy, other.createdBy) && + Objects.equals(data, other.data) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateExpires, other.dateExpires) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(key, other.key) && + Objects.equals(mapSid, other.mapSid) && + Objects.equals(revision, other.revision) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(key, - accountSid, - serviceSid, - mapSid, - url, - revision, - data, - dateExpires, - dateCreated, - dateUpdated, - createdBy); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("key", key) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("mapSid", mapSid) - .add("url", url) - .add("revision", revision) - .add("data", data) - .add("dateExpires", dateExpires) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("createdBy", createdBy) - .toString(); + return Objects.hash( + accountSid, + createdBy, + data, + dateCreated, + dateExpires, + dateUpdated, + key, + mapSid, + revision, + serviceSid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemCreator.java index 82c88e735e..325dd2f4cc 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; import com.twilio.base.Creator; -import com.twilio.converter.Converter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,106 +27,156 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapItemCreator extends Creator { - private final String pathServiceSid; - private final String pathMapSid; - private final String key; - private final Map data; + + private String pathServiceSid; + private String pathMapSid; + private String key; + private Object data; private Integer ttl; + private Integer itemTtl; + private Integer collectionTtl; - /** - * Construct a new SyncMapItemCreator. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param key The unique user-defined key of this Map Item. - * @param data Contains arbitrary user-defined, schema-less data that this Map - * Item stores, represented by a JSON object, up to 16KB. - */ - public SyncMapItemCreator(final String pathServiceSid, - final String pathMapSid, - final String key, - final Map data) { + public SyncMapItemCreator( + final String pathServiceSid, + final String pathMapSid, + final String key, + final Object data + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.key = key; this.data = data; } - /** - * Time-to-live of this Map in seconds, defaults to no expiration. In the range - * [1, 31 536 000 (1 year)], or 0 for infinity.. - * - * @param ttl Time-to-live of this Map in seconds, defaults to no expiration. - * @return this - */ + public SyncMapItemCreator setKey(final String key) { + this.key = key; + return this; + } + + public SyncMapItemCreator setData(final Object data) { + this.data = data; + return this; + } + public SyncMapItemCreator setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created SyncMapItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapItem create(final TwilioRestClient client) { + public SyncMapItemCreator setItemTtl(final Integer itemTtl) { + this.itemTtl = itemTtl; + return this; + } + + public SyncMapItemCreator setCollectionTtl(final Integer collectionTtl) { + this.collectionTtl = collectionTtl; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMapItem creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncMapItem create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncMapItem content = SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (key != null) { - request.addPostParam("Key", key); + Serializer.toString(request, "Key", key, ParameterType.URLENCODED); } if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); + Serializer.toString( + request, + "Data", + data, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + + if (itemTtl != null) { + Serializer.toString( + request, + "ItemTtl", + itemTtl, + ParameterType.URLENCODED + ); + } + + if (collectionTtl != null) { + Serializer.toString( + request, + "CollectionTtl", + collectionTtl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemDeleter.java index 103babbbda..c08560f48b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,65 +26,106 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapItemDeleter extends Deleter { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathKey; - /** - * Construct a new SyncMapItemDeleter. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - */ - public SyncMapItemDeleter(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { + private String pathServiceSid; + private String pathMapSid; + private String pathKey; + private String ifMatch; + + public SyncMapItemDeleter( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public SyncMapItemDeleter setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items/" + this.pathKey + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMapItem delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemFetcher.java index acef83ae1b..43343677e0 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,87 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapItemFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathKey; - /** - * Construct a new SyncMapItemFetcher. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - */ - public SyncMapItemFetcher(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { + private String pathServiceSid; + private String pathMapSid; + private String pathKey; + + public SyncMapItemFetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncMapItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapItem fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items/" + this.pathKey + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMapItem fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncMapItem fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncMapItem content = SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemReader.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemReader.java index b35c751b28..fe176d6e63 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; @@ -10,219 +17,235 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapItemReader extends Reader { - private final String pathServiceSid; - private final String pathMapSid; + + private String pathServiceSid; + private String pathMapSid; private SyncMapItem.QueryResultOrder order; private String from; private SyncMapItem.QueryFromBoundType bounds; + private Long pageSize; - /** - * Construct a new SyncMapItemReader. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - */ - public SyncMapItemReader(final String pathServiceSid, - final String pathMapSid) { + public SyncMapItemReader( + final String pathServiceSid, + final String pathMapSid + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; } - /** - * A string; asc or desc. Map Items are [ordered - * lexicographically](https://en.wikipedia.org/wiki/Lexicographical_order) by - * Item key.. - * - * @param order A string; asc or desc. Map Items are ordered lexicographically - * by Item key. - * @return this - */ - public SyncMapItemReader setOrder(final SyncMapItem.QueryResultOrder order) { + public SyncMapItemReader setOrder( + final SyncMapItem.QueryResultOrder order + ) { this.order = order; return this; } - /** - * The Item key offset (including the specified key). If not present, query is - * performed from the start or end, depending on the Order query parameter.. - * - * @param from The Item key offset (including the specified key). - * @return this - */ public SyncMapItemReader setFrom(final String from) { this.from = from; return this; } - /** - * The bounds. - * - * @param bounds The bounds - * @return this - */ - public SyncMapItemReader setBounds(final SyncMapItem.QueryFromBoundType bounds) { + public SyncMapItemReader setBounds( + final SyncMapItem.QueryFromBoundType bounds + ) { this.bounds = bounds; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMapItem ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SyncMapItemReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMapItem ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + SyncMapItem.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncMapItem ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "items", + response.getContent(), + SyncMapItem.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SyncMapItem read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "items", + response.getContent(), + SyncMapItem.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SyncMapItem Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapItem read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "items", - response.getContent(), - SyncMapItem.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (order != null) { - request.addQueryParam("Order", order.toString()); + Serializer.toString(request, "Order", order, ParameterType.QUERY); } if (from != null) { - request.addQueryParam("From", from); + Serializer.toString(request, "From", from, ParameterType.QUERY); } if (bounds != null) { - request.addQueryParam("Bounds", bounds.toString()); + Serializer.toString(request, "Bounds", bounds, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemUpdater.java index 2f1307f217..14e186bd1b 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapItemUpdater.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; -import com.twilio.converter.Converter; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,110 +27,164 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapItemUpdater extends Updater { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathKey; - private Map data; + + private String pathServiceSid; + private String pathMapSid; + private String pathKey; + private String ifMatch; + private Object data; private Integer ttl; + private Integer itemTtl; + private Integer collectionTtl; - /** - * Construct a new SyncMapItemUpdater. - * - * @param pathServiceSid The service_sid - * @param pathMapSid The map_sid - * @param pathKey The key - */ - public SyncMapItemUpdater(final String pathServiceSid, - final String pathMapSid, - final String pathKey) { + public SyncMapItemUpdater( + final String pathServiceSid, + final String pathMapSid, + final String pathKey + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathKey = pathKey; } - /** - * Contains an arbitrary JSON object to be stored in this Map Item. Serialized - * to string to respect HTTP form input, up to 16KB.. - * - * @param data Contains an arbitrary JSON object to be stored in this Map Item. - * @return this - */ - public SyncMapItemUpdater setData(final Map data) { + public SyncMapItemUpdater setData(final Object data) { this.data = data; return this; } - /** - * New time-to-live of this Map in seconds. In the range [1, 31 536 000 (1 - * year)], or 0 for infinity.. - * - * @param ttl New time-to-live of this Map in seconds. - * @return this - */ public SyncMapItemUpdater setTtl(final Integer ttl) { this.ttl = ttl; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncMapItem - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapItem update(final TwilioRestClient client) { + public SyncMapItemUpdater setItemTtl(final Integer itemTtl) { + this.itemTtl = itemTtl; + return this; + } + + public SyncMapItemUpdater setCollectionTtl(final Integer collectionTtl) { + this.collectionTtl = collectionTtl; + return this; + } + + public SyncMapItemUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Key}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = path.replace("{" + "Key" + "}", this.pathKey.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Items/" + this.pathKey + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapItem update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMapItem update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return SyncMapItem.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public SyncMapItem update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncMapItem content = SyncMapItem.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); + Serializer.toString( + request, + "Data", + data, + ParameterType.URLENCODED + ); } if (ttl != null) { - request.addPostParam("Ttl", ttl.toString()); + Serializer.toString(request, "Ttl", ttl, ParameterType.URLENCODED); + } + + if (itemTtl != null) { + Serializer.toString( + request, + "ItemTtl", + itemTtl, + ParameterType.URLENCODED + ); + } + + if (collectionTtl != null) { + Serializer.toString( + request, + "CollectionTtl", + collectionTtl, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermission.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermission.java index 7d9aee8ddd..2c5a90254e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermission.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermission.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; @@ -11,105 +18,87 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.twilio.base.Resource; import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class SyncMapPermission extends Resource { - private static final long serialVersionUID = 261843483205862L; - - /** - * Create a SyncMapPermissionFetcher to execute fetch. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - * @return SyncMapPermissionFetcher capable of executing the fetch - */ - public static SyncMapPermissionFetcher fetcher(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity) { - return new SyncMapPermissionFetcher(pathServiceSid, pathMapSid, pathIdentity); - } - - /** - * Create a SyncMapPermissionDeleter to execute delete. - * - * @param pathServiceSid Sync Service Instance SID or unique name - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - * @return SyncMapPermissionDeleter capable of executing the delete - */ - public static SyncMapPermissionDeleter deleter(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity) { - return new SyncMapPermissionDeleter(pathServiceSid, pathMapSid, pathIdentity); - } - /** - * Create a SyncMapPermissionReader to execute read. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathMapSid Sync Map SID or unique name. - * @return SyncMapPermissionReader capable of executing the read - */ - public static SyncMapPermissionReader reader(final String pathServiceSid, - final String pathMapSid) { + public static SyncMapPermissionDeleter deleter( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { + return new SyncMapPermissionDeleter( + pathServiceSid, + pathMapSid, + pathIdentity + ); + } + + public static SyncMapPermissionFetcher fetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { + return new SyncMapPermissionFetcher( + pathServiceSid, + pathMapSid, + pathIdentity + ); + } + + public static SyncMapPermissionReader reader( + final String pathServiceSid, + final String pathMapSid + ) { return new SyncMapPermissionReader(pathServiceSid, pathMapSid); } - /** - * Create a SyncMapPermissionUpdater to execute update. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - * @return SyncMapPermissionUpdater capable of executing the update - */ - public static SyncMapPermissionUpdater updater(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { - return new SyncMapPermissionUpdater(pathServiceSid, pathMapSid, pathIdentity, read, write, manage); + public static SyncMapPermissionUpdater updater( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { + return new SyncMapPermissionUpdater( + pathServiceSid, + pathMapSid, + pathIdentity, + read, + write, + manage + ); } /** - * Converts a JSON String into a SyncMapPermission object using the provided - * ObjectMapper. - * + * Converts a JSON String into a SyncMapPermission object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return SyncMapPermission object represented by the provided JSON */ - public static SyncMapPermission fromJson(final String json, final ObjectMapper objectMapper) { + public static SyncMapPermission fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapPermission.class); @@ -121,14 +110,17 @@ public static SyncMapPermission fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a SyncMapPermission object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a SyncMapPermission object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return SyncMapPermission object represented by the provided JSON */ - public static SyncMapPermission fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static SyncMapPermission fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, SyncMapPermission.class); @@ -139,112 +131,61 @@ public static SyncMapPermission fromJson(final InputStream json, final ObjectMap } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String serviceSid; - private final String mapSid; + + @Getter private final String identity; - private final Boolean read; - private final Boolean write; + + @Getter private final Boolean manage; + + @Getter + private final String mapSid; + + @Getter + private final Boolean read; + + @Getter + private final String serviceSid; + + @Getter private final URI url; + @Getter + private final Boolean write; + @JsonCreator - private SyncMapPermission(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("service_sid") - final String serviceSid, - @JsonProperty("map_sid") - final String mapSid, - @JsonProperty("identity") - final String identity, - @JsonProperty("read") - final Boolean read, - @JsonProperty("write") - final Boolean write, - @JsonProperty("manage") - final Boolean manage, - @JsonProperty("url") - final URI url) { + private SyncMapPermission( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("identity") final String identity, + @JsonProperty("manage") final Boolean manage, + @JsonProperty("map_sid") final String mapSid, + @JsonProperty("read") final Boolean read, + @JsonProperty("service_sid") final String serviceSid, + @JsonProperty("url") final URI url, + @JsonProperty("write") final Boolean write + ) { this.accountSid = accountSid; - this.serviceSid = serviceSid; - this.mapSid = mapSid; this.identity = identity; - this.read = read; - this.write = write; this.manage = manage; + this.mapSid = mapSid; + this.read = read; + this.serviceSid = serviceSid; this.url = url; - } - - /** - * Returns The Twilio Account SID.. - * - * @return Twilio Account SID. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Sync Service Instance SID.. - * - * @return Sync Service Instance SID. - */ - public final String getServiceSid() { - return this.serviceSid; - } - - /** - * Returns The Sync Map SID.. - * - * @return Sync Map SID. - */ - public final String getMapSid() { - return this.mapSid; - } - - /** - * Returns The Identity of the user to whom the Sync Map Permission applies.. - * - * @return Identity of the user to whom the Sync Map Permission applies. - */ - public final String getIdentity() { - return this.identity; - } - - /** - * Returns The Read access.. - * - * @return Read access. - */ - public final Boolean getRead() { - return this.read; - } - - /** - * Returns The Write access.. - * - * @return Write access. - */ - public final Boolean getWrite() { - return this.write; - } - - /** - * Returns The Manage access.. - * - * @return Manage access. - */ - public final Boolean getManage() { - return this.manage; - } - - /** - * Returns The URL of this Sync Map Permission.. - * - * @return URL of this Sync Map Permission. - */ - public final URI getUrl() { - return this.url; + this.write = write; } @Override @@ -258,40 +199,29 @@ public boolean equals(final Object o) { } SyncMapPermission other = (SyncMapPermission) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(serviceSid, other.serviceSid) && - Objects.equals(mapSid, other.mapSid) && - Objects.equals(identity, other.identity) && - Objects.equals(read, other.read) && - Objects.equals(write, other.write) && - Objects.equals(manage, other.manage) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(identity, other.identity) && + Objects.equals(manage, other.manage) && + Objects.equals(mapSid, other.mapSid) && + Objects.equals(read, other.read) && + Objects.equals(serviceSid, other.serviceSid) && + Objects.equals(url, other.url) && + Objects.equals(write, other.write) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - serviceSid, - mapSid, - identity, - read, - write, - manage, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("serviceSid", serviceSid) - .add("mapSid", mapSid) - .add("identity", identity) - .add("read", read) - .add("write", write) - .add("manage", manage) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + identity, + manage, + mapSid, + read, + serviceSid, + url, + write + ); + } +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionDeleter.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionDeleter.java index 0652ef9fe7..31d7ed5ad2 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionDeleter.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,66 +24,90 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapPermissionDeleter extends Deleter { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathIdentity; - /** - * Construct a new SyncMapPermissionDeleter. - * - * @param pathServiceSid Sync Service Instance SID or unique name - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - */ - public SyncMapPermissionDeleter(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity) { + private String pathServiceSid; + private String pathMapSid; + private String pathIdentity; + + public SyncMapPermissionDeleter( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMapPermission delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return response.getStatusCode() == 204; + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionFetcher.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionFetcher.java index 6edb5bcff7..ad700a6103 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionFetcher.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,67 +24,89 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapPermissionFetcher extends Fetcher { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathIdentity; - /** - * Construct a new SyncMapPermissionFetcher. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - */ - public SyncMapPermissionFetcher(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity) { + private String pathServiceSid; + private String pathMapSid; + private String pathIdentity; + + public SyncMapPermissionFetcher( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched SyncMapPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapPermission fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMapPermission fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public SyncMapPermission fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncMapPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return SyncMapPermission.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncMapPermission content = SyncMapPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionReader.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionReader.java index 64a4fc30bb..053e472752 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionReader.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; @@ -10,167 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapPermissionReader extends Reader { - private final String pathServiceSid; - private final String pathMapSid; - - /** - * Construct a new SyncMapPermissionReader. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathMapSid Sync Map SID or unique name. - */ - public SyncMapPermissionReader(final String pathServiceSid, - final String pathMapSid) { + + private String pathServiceSid; + private String pathMapSid; + private Long pageSize; + + public SyncMapPermissionReader( + final String pathServiceSid, + final String pathMapSid + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMapPermission ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public SyncMapPermissionReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return SyncMapPermission ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "permissions", + response.getContent(), + SyncMapPermission.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Permissions", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return SyncMapPermission ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "permissions", + response.getContent(), + SyncMapPermission.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SyncMapPermission read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "permissions", + response.getContent(), + SyncMapPermission.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.SYNC.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of SyncMapPermission Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("SyncMapPermission read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "permissions", - response.getContent(), - SyncMapPermission.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionUpdater.java b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionUpdater.java index f57fbbd011..681cdad53e 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionUpdater.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncmap/SyncMapPermissionUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncmap; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,36 +27,26 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class SyncMapPermissionUpdater extends Updater { - private final String pathServiceSid; - private final String pathMapSid; - private final String pathIdentity; - private final Boolean read; - private final Boolean write; - private final Boolean manage; - - /** - * Construct a new SyncMapPermissionUpdater. - * - * @param pathServiceSid Sync Service Instance SID or unique name. - * @param pathMapSid Sync Map SID or unique name. - * @param pathIdentity Identity of the user to whom the Sync Map Permission - * applies. - * @param read Read access. - * @param write Write access. - * @param manage Manage access. - */ - public SyncMapPermissionUpdater(final String pathServiceSid, - final String pathMapSid, - final String pathIdentity, - final Boolean read, - final Boolean write, - final Boolean manage) { + + private String pathServiceSid; + private String pathMapSid; + private String pathIdentity; + private Boolean read; + private Boolean write; + private Boolean manage; + + public SyncMapPermissionUpdater( + final String pathServiceSid, + final String pathMapSid, + final String pathIdentity, + final Boolean read, + final Boolean write, + final Boolean manage + ) { this.pathServiceSid = pathServiceSid; this.pathMapSid = pathMapSid; this.pathIdentity = pathIdentity; @@ -54,61 +55,116 @@ public SyncMapPermissionUpdater(final String pathServiceSid, this.manage = manage; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated SyncMapPermission - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public SyncMapPermission update(final TwilioRestClient client) { + public SyncMapPermissionUpdater setRead(final Boolean read) { + this.read = read; + return this; + } + + public SyncMapPermissionUpdater setWrite(final Boolean write) { + this.write = write; + return this; + } + + public SyncMapPermissionUpdater setManage(final Boolean manage) { + this.manage = manage; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Services/{ServiceSid}/Maps/{MapSid}/Permissions/{Identity}"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = path.replace("{" + "MapSid" + "}", this.pathMapSid.toString()); + path = + path.replace("{" + "Identity" + "}", this.pathIdentity.toString()); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Maps/" + this.pathMapSid + "/Permissions/" + this.pathIdentity + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("SyncMapPermission update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "SyncMapPermission update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return SyncMapPermission.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public SyncMapPermission update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SyncMapPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SyncMapPermission content = SyncMapPermission.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (read != null) { - request.addPostParam("Read", read.toString()); + Serializer.toString( + request, + "Read", + read, + ParameterType.URLENCODED + ); } if (write != null) { - request.addPostParam("Write", write.toString()); + Serializer.toString( + request, + "Write", + write, + ParameterType.URLENCODED + ); } if (manage != null) { - request.addPostParam("Manage", manage.toString()); + Serializer.toString( + request, + "Manage", + manage, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessage.java b/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessage.java index 53eceeed2f..c5eef39b51 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessage.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessage.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncstream; @@ -11,56 +18,45 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class StreamMessage extends Resource { - private static final long serialVersionUID = 144642288348060L; - /** - * Create a StreamMessageCreator to execute create. - * - * @param pathServiceSid The service_sid - * @param pathStreamSid The stream_sid - * @param data Stream Message body. - * @return StreamMessageCreator capable of executing the create - */ - public static StreamMessageCreator creator(final String pathServiceSid, - final String pathStreamSid, - final Map data) { + public static StreamMessageCreator creator( + final String pathServiceSid, + final String pathStreamSid, + final Object data + ) { return new StreamMessageCreator(pathServiceSid, pathStreamSid, data); } /** - * Converts a JSON String into a StreamMessage object using the provided - * ObjectMapper. - * + * Converts a JSON String into a StreamMessage object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return StreamMessage object represented by the provided JSON */ - public static StreamMessage fromJson(final String json, final ObjectMapper objectMapper) { + public static StreamMessage fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StreamMessage.class); @@ -74,12 +70,15 @@ public static StreamMessage fromJson(final String json, final ObjectMapper objec /** * Converts a JSON InputStream into a StreamMessage object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return StreamMessage object represented by the provided JSON */ - public static StreamMessage fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static StreamMessage fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, StreamMessage.class); @@ -90,34 +89,31 @@ public static StreamMessage fromJson(final InputStream json, final ObjectMapper } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object data; + + @Getter private final String sid; - private final Map data; @JsonCreator - private StreamMessage(@JsonProperty("sid") - final String sid, - @JsonProperty("data") - final Map data) { - this.sid = sid; + private StreamMessage( + @JsonProperty("data") final Object data, + @JsonProperty("sid") final String sid + ) { this.data = data; - } - - /** - * Returns The Stream Message SID.. - * - * @return Stream Message SID. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Stream Message body.. - * - * @return Stream Message body. - */ - public final Map getData() { - return this.data; + this.sid = sid; } @Override @@ -131,22 +127,13 @@ public boolean equals(final Object o) { } StreamMessage other = (StreamMessage) o; - - return Objects.equals(sid, other.sid) && - Objects.equals(data, other.data); + return ( + Objects.equals(data, other.data) && Objects.equals(sid, other.sid) + ); } @Override public int hashCode() { - return Objects.hash(sid, - data); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("sid", sid) - .add("data", data) - .toString(); + return Objects.hash(data, sid); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessageCreator.java b/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessageCreator.java index c2fd7baaec..afe0836003 100644 --- a/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessageCreator.java +++ b/src/main/java/com/twilio/rest/sync/v1/service/syncstream/StreamMessageCreator.java @@ -1,14 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Sync + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.sync.v1.service.syncstream; import com.twilio.base.Creator; -import com.twilio.converter.Converter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,80 +27,108 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -import java.util.Map; - -/** - * PLEASE NOTE that this class contains beta products that are subject to - * change. Use them with caution. - */ public class StreamMessageCreator extends Creator { - private final String pathServiceSid; - private final String pathStreamSid; - private final Map data; - /** - * Construct a new StreamMessageCreator. - * - * @param pathServiceSid The service_sid - * @param pathStreamSid The stream_sid - * @param data Stream Message body. - */ - public StreamMessageCreator(final String pathServiceSid, - final String pathStreamSid, - final Map data) { + private String pathServiceSid; + private String pathStreamSid; + private Object data; + + public StreamMessageCreator( + final String pathServiceSid, + final String pathStreamSid, + final Object data + ) { this.pathServiceSid = pathServiceSid; this.pathStreamSid = pathStreamSid; this.data = data; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created StreamMessage - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public StreamMessage create(final TwilioRestClient client) { + public StreamMessageCreator setData(final Object data) { + this.data = data; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Services/{ServiceSid}/Streams/{StreamSid}/Messages"; + + path = + path.replace( + "{" + "ServiceSid" + "}", + this.pathServiceSid.toString() + ); + path = + path.replace( + "{" + "StreamSid" + "}", + this.pathStreamSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.SYNC.toString(), - "/v1/Services/" + this.pathServiceSid + "/Streams/" + this.pathStreamSid + "/Messages", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("StreamMessage creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "StreamMessage creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public StreamMessage create(final TwilioRestClient client) { + Response response = makeRequest(client); + return StreamMessage.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return StreamMessage.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + StreamMessage content = StreamMessage.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (data != null) { - request.addPostParam("Data", Converter.mapToJson(data)); + Serializer.toString( + request, + "Data", + data, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/Workspace.java b/src/main/java/com/twilio/rest/taskrouter/v1/Workspace.java index 0f482d4d41..f25c411bfa 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/Workspace.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/Workspace.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1; @@ -10,32 +17,53 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Workspace extends Resource { - private static final long serialVersionUID = 173419493907327L; + + public static WorkspaceCreator creator(final String friendlyName) { + return new WorkspaceCreator(friendlyName); + } + + public static WorkspaceDeleter deleter(final String pathSid) { + return new WorkspaceDeleter(pathSid); + } + + public static WorkspaceFetcher fetcher(final String pathSid) { + return new WorkspaceFetcher(pathSid); + } + + public static WorkspaceReader reader() { + return new WorkspaceReader(); + } + + public static WorkspaceUpdater updater(final String pathSid) { + return new WorkspaceUpdater(pathSid); + } public enum QueueOrder { FIFO("FIFO"), @@ -47,15 +75,11 @@ private QueueOrder(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a QueueOrder from a string. - * @param value string value - * @return generated QueueOrder - */ @JsonCreator public static QueueOrder forValue(final String value) { return Promoter.enumFromString(value, QueueOrder.values()); @@ -63,63 +87,16 @@ public static QueueOrder forValue(final String value) { } /** - * Create a WorkspaceFetcher to execute fetch. - * - * @param pathSid The sid - * @return WorkspaceFetcher capable of executing the fetch - */ - public static WorkspaceFetcher fetcher(final String pathSid) { - return new WorkspaceFetcher(pathSid); - } - - /** - * Create a WorkspaceUpdater to execute update. - * - * @param pathSid The sid - * @return WorkspaceUpdater capable of executing the update - */ - public static WorkspaceUpdater updater(final String pathSid) { - return new WorkspaceUpdater(pathSid); - } - - /** - * Create a WorkspaceReader to execute read. - * - * @return WorkspaceReader capable of executing the read - */ - public static WorkspaceReader reader() { - return new WorkspaceReader(); - } - - /** - * Create a WorkspaceCreator to execute create. - * - * @param friendlyName Human readable description of this workspace - * @return WorkspaceCreator capable of executing the create - */ - public static WorkspaceCreator creator(final String friendlyName) { - return new WorkspaceCreator(friendlyName); - } - - /** - * Create a WorkspaceDeleter to execute delete. - * - * @param pathSid The sid - * @return WorkspaceDeleter capable of executing the delete - */ - public static WorkspaceDeleter deleter(final String pathSid) { - return new WorkspaceDeleter(pathSid); - } - - /** - * Converts a JSON String into a Workspace object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Workspace object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Workspace object represented by the provided JSON */ - public static Workspace fromJson(final String json, final ObjectMapper objectMapper) { + public static Workspace fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Workspace.class); @@ -133,12 +110,15 @@ public static Workspace fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a Workspace object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Workspace object represented by the provided JSON */ - public static Workspace fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Workspace fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Workspace.class); @@ -149,217 +129,108 @@ public static Workspace fromJson(final InputStream json, final ObjectMapper obje } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String defaultActivityName; + + @Getter private final String defaultActivitySid; + + @Getter private final URI eventCallbackUrl; + + @Getter private final String eventsFilter; + + @Getter private final String friendlyName; + + @Getter + private final Map links; + + @Getter private final Boolean multiTaskEnabled; + + @Getter + private final Workspace.QueueOrder prioritizeQueueOrder; + + @Getter private final String sid; + + @Getter private final String timeoutActivityName; + + @Getter private final String timeoutActivitySid; - private final Workspace.QueueOrder prioritizeQueueOrder; + + @Getter private final URI url; - private final Map links; @JsonCreator - private Workspace(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("default_activity_name") - final String defaultActivityName, - @JsonProperty("default_activity_sid") - final String defaultActivitySid, - @JsonProperty("event_callback_url") - final URI eventCallbackUrl, - @JsonProperty("events_filter") - final String eventsFilter, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("multi_task_enabled") - final Boolean multiTaskEnabled, - @JsonProperty("sid") - final String sid, - @JsonProperty("timeout_activity_name") - final String timeoutActivityName, - @JsonProperty("timeout_activity_sid") - final String timeoutActivitySid, - @JsonProperty("prioritize_queue_order") - final Workspace.QueueOrder prioritizeQueueOrder, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { + private Workspace( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("default_activity_name") final String defaultActivityName, + @JsonProperty("default_activity_sid") final String defaultActivitySid, + @JsonProperty("event_callback_url") final URI eventCallbackUrl, + @JsonProperty("events_filter") final String eventsFilter, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("multi_task_enabled") final Boolean multiTaskEnabled, + @JsonProperty( + "prioritize_queue_order" + ) final Workspace.QueueOrder prioritizeQueueOrder, + @JsonProperty("sid") final String sid, + @JsonProperty("timeout_activity_name") final String timeoutActivityName, + @JsonProperty("timeout_activity_sid") final String timeoutActivitySid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.defaultActivityName = defaultActivityName; this.defaultActivitySid = defaultActivitySid; this.eventCallbackUrl = eventCallbackUrl; this.eventsFilter = eventsFilter; this.friendlyName = friendlyName; + this.links = links; this.multiTaskEnabled = multiTaskEnabled; + this.prioritizeQueueOrder = prioritizeQueueOrder; this.sid = sid; this.timeoutActivityName = timeoutActivityName; this.timeoutActivitySid = timeoutActivitySid; - this.prioritizeQueueOrder = prioritizeQueueOrder; this.url = url; - this.links = links; - } - - /** - * Returns The The ID of the account that owns this Workflow. - * - * @return The ID of the account that owns this Workflow - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The time the Workspace was created, given as GMT in ISO 8601 - * format.. - * - * @return The time the Workspace was created, given as GMT in ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The time the Workspace was last updated, given as GMT in ISO 8601 - * format.. - * - * @return The time the Workspace was last updated, given as GMT in ISO 8601 - * format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The human readable name of the default activity.. - * - * @return The human readable name of the default activity. - */ - public final String getDefaultActivityName() { - return this.defaultActivityName; - } - - /** - * Returns The The ID of the Activity that will be used when new Workers are - * created in this Workspace.. - * - * @return The ID of the Activity that will be used when new Workers are - * created in this Workspace. - */ - public final String getDefaultActivitySid() { - return this.defaultActivitySid; - } - - /** - * Returns The If provided, the Workspace will publish events to this URL.. - * - * @return If provided, the Workspace will publish events to this URL. - */ - public final URI getEventCallbackUrl() { - return this.eventCallbackUrl; - } - - /** - * Returns The Use this parameter to receive webhooks on EventCallbackUrl for - * specific events on a workspace.. - * - * @return Use this parameter to receive webhooks on EventCallbackUrl for - * specific events on a workspace. - */ - public final String getEventsFilter() { - return this.eventsFilter; - } - - /** - * Returns The Filter by a workspace’s friendly name.. - * - * @return Filter by a workspace’s friendly name. - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The Multi tasking allows workers to handle multiple tasks - * simultaneously.. - * - * @return Multi tasking allows workers to handle multiple tasks simultaneously. - */ - public final Boolean getMultiTaskEnabled() { - return this.multiTaskEnabled; - } - - /** - * Returns The The unique ID of the Workspace. - * - * @return The unique ID of the Workspace - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The human readable name of the timeout activity.. - * - * @return The human readable name of the timeout activity. - */ - public final String getTimeoutActivityName() { - return this.timeoutActivityName; - } - - /** - * Returns The The ID of the Activity that will be assigned to a Worker when a - * Task reservation times out without a response.. - * - * @return The ID of the Activity that will be assigned to a Worker when a Task - * reservation times out without a response. - */ - public final String getTimeoutActivitySid() { - return this.timeoutActivitySid; - } - - /** - * Returns The Use this parameter to configure whether to prioritize LIFO or - * FIFO when workers are receiving Tasks from combination of LIFO and FIFO - * TaskQueues.. - * - * @return Use this parameter to configure whether to prioritize LIFO or FIFO - * when workers are receiving Tasks from combination of LIFO and FIFO - * TaskQueues. - */ - public final Workspace.QueueOrder getPrioritizeQueueOrder() { - return this.prioritizeQueueOrder; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -373,61 +244,43 @@ public boolean equals(final Object o) { } Workspace other = (Workspace) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(defaultActivityName, other.defaultActivityName) && - Objects.equals(defaultActivitySid, other.defaultActivitySid) && - Objects.equals(eventCallbackUrl, other.eventCallbackUrl) && - Objects.equals(eventsFilter, other.eventsFilter) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(multiTaskEnabled, other.multiTaskEnabled) && - Objects.equals(sid, other.sid) && - Objects.equals(timeoutActivityName, other.timeoutActivityName) && - Objects.equals(timeoutActivitySid, other.timeoutActivitySid) && - Objects.equals(prioritizeQueueOrder, other.prioritizeQueueOrder) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(defaultActivityName, other.defaultActivityName) && + Objects.equals(defaultActivitySid, other.defaultActivitySid) && + Objects.equals(eventCallbackUrl, other.eventCallbackUrl) && + Objects.equals(eventsFilter, other.eventsFilter) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(multiTaskEnabled, other.multiTaskEnabled) && + Objects.equals(prioritizeQueueOrder, other.prioritizeQueueOrder) && + Objects.equals(sid, other.sid) && + Objects.equals(timeoutActivityName, other.timeoutActivityName) && + Objects.equals(timeoutActivitySid, other.timeoutActivitySid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - defaultActivityName, - defaultActivitySid, - eventCallbackUrl, - eventsFilter, - friendlyName, - multiTaskEnabled, - sid, - timeoutActivityName, - timeoutActivitySid, - prioritizeQueueOrder, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("defaultActivityName", defaultActivityName) - .add("defaultActivitySid", defaultActivitySid) - .add("eventCallbackUrl", eventCallbackUrl) - .add("eventsFilter", eventsFilter) - .add("friendlyName", friendlyName) - .add("multiTaskEnabled", multiTaskEnabled) - .add("sid", sid) - .add("timeoutActivityName", timeoutActivityName) - .add("timeoutActivitySid", timeoutActivitySid) - .add("prioritizeQueueOrder", prioritizeQueueOrder) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + defaultActivityName, + defaultActivitySid, + eventCallbackUrl, + eventsFilter, + friendlyName, + links, + multiTaskEnabled, + prioritizeQueueOrder, + sid, + timeoutActivityName, + timeoutActivitySid, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceCreator.java index dee0bd7e86..0528fab5f7 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,185 +28,173 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class WorkspaceCreator extends Creator { - private final String friendlyName; + + private String friendlyName; private URI eventCallbackUrl; private String eventsFilter; private Boolean multiTaskEnabled; private String template; private Workspace.QueueOrder prioritizeQueueOrder; - /** - * Construct a new WorkspaceCreator. - * - * @param friendlyName Human readable description of this workspace - */ public WorkspaceCreator(final String friendlyName) { this.friendlyName = friendlyName; } - /** - * If provided, the Workspace will publish events to this URL. You can use this - * to gather data for reporting. See Workspace Events for more information.. - * - * @param eventCallbackUrl If provided, the Workspace will publish events to - * this URL. - * @return this - */ + public WorkspaceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + public WorkspaceCreator setEventCallbackUrl(final URI eventCallbackUrl) { this.eventCallbackUrl = eventCallbackUrl; return this; } - /** - * If provided, the Workspace will publish events to this URL. You can use this - * to gather data for reporting. See Workspace Events for more information.. - * - * @param eventCallbackUrl If provided, the Workspace will publish events to - * this URL. - * @return this - */ public WorkspaceCreator setEventCallbackUrl(final String eventCallbackUrl) { return setEventCallbackUrl(Promoter.uriFromString(eventCallbackUrl)); } - /** - * Use this parameter to receive webhooks on EventCallbackUrl for specific - * events on a workspace. For example if - * 'EventsFilter=task.created,task.canceled,worker.activity.update', then - * TaskRouter will webhook to EventCallbackUrl only when a task is created, - * canceled or a worker activity is updated.. - * - * @param eventsFilter Use this parameter to receive webhooks on - * EventCallbackUrl for specific events on a workspace. - * @return this - */ public WorkspaceCreator setEventsFilter(final String eventsFilter) { this.eventsFilter = eventsFilter; return this; } - /** - * Multi tasking allows workers to handle multiple tasks simultaneously. When - * enabled (MultiTaskEnabled=true), each worker will be eligible to receive - * parallel reservations up to the per-channel maximums defined in the Workers - * section. Default is disabled (MultiTaskEnabled=false), where each worker will - * only receive a new reservation when the previous task is completed. Learn - * more by visiting [Multitasking][/docs/taskrouter/multitasking].. - * - * @param multiTaskEnabled Multi tasking allows workers to handle multiple - * tasks simultaneously. - * @return this - */ - public WorkspaceCreator setMultiTaskEnabled(final Boolean multiTaskEnabled) { + public WorkspaceCreator setMultiTaskEnabled( + final Boolean multiTaskEnabled + ) { this.multiTaskEnabled = multiTaskEnabled; return this; } - /** - * One of the available template names. Will pre-configure this Workspace with - * the Workflow and Activities specified in the template. "NONE" will create a - * Workspace with a set of default activities and nothing else. "FIFO" will - * configure TaskRouter with a set of default activities and a single task queue - * for first-in, first-out distribution, useful if you want to see a simple - * TaskRouter configuration when getting started. Defaults to "NONE".. - * - * @param template One of the available template names. - * @return this - */ public WorkspaceCreator setTemplate(final String template) { this.template = template; return this; } - /** - * Use this parameter to configure whether to prioritize LIFO or FIFO when - * workers are receiving Tasks from combination of LIFO and FIFO TaskQueues. - * Default is FIFO. [Click - * here][/docs/taskrouter/queue-ordering-last-first-out-lifo] to learn more - * about LIFO and the use of the parameter.. - * - * @param prioritizeQueueOrder Use this parameter to configure whether to - * prioritize LIFO or FIFO when workers are - * receiving Tasks from combination of LIFO and FIFO - * TaskQueues. - * @return this - */ - public WorkspaceCreator setPrioritizeQueueOrder(final Workspace.QueueOrder prioritizeQueueOrder) { + public WorkspaceCreator setPrioritizeQueueOrder( + final Workspace.QueueOrder prioritizeQueueOrder + ) { this.prioritizeQueueOrder = prioritizeQueueOrder; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Workspace - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Workspace create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces"; + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Workspace creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Workspace.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Workspace create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Workspace content = Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (eventCallbackUrl != null) { - request.addPostParam("EventCallbackUrl", eventCallbackUrl.toString()); + Serializer.toString( + request, + "EventCallbackUrl", + eventCallbackUrl, + ParameterType.URLENCODED + ); } if (eventsFilter != null) { - request.addPostParam("EventsFilter", eventsFilter); + Serializer.toString( + request, + "EventsFilter", + eventsFilter, + ParameterType.URLENCODED + ); } if (multiTaskEnabled != null) { - request.addPostParam("MultiTaskEnabled", multiTaskEnabled.toString()); + Serializer.toString( + request, + "MultiTaskEnabled", + multiTaskEnabled, + ParameterType.URLENCODED + ); } if (template != null) { - request.addPostParam("Template", template); + Serializer.toString( + request, + "Template", + template, + ParameterType.URLENCODED + ); } if (prioritizeQueueOrder != null) { - request.addPostParam("PrioritizeQueueOrder", prioritizeQueueOrder.toString()); + Serializer.toString( + request, + "PrioritizeQueueOrder", + prioritizeQueueOrder, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceDeleter.java index ccb52b397d..62528e8c29 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class WorkspaceDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new WorkspaceDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public WorkspaceDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Workspace delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceFetcher.java index 3092ec8230..2842e60f9b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,73 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkspaceFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new WorkspaceFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public WorkspaceFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Workspace - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Workspace fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Workspace fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Workspace.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Workspace fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Workspace content = Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceReader.java index 608fd9b5d1..22a819bac8 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1; @@ -10,167 +17,201 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkspaceReader extends Reader { + private String friendlyName; + private Long pageSize; + + public WorkspaceReader() {} - /** - * Filter by a workspace’s friendly name. This is a human readable description - * of this Workspace (for example "Customer Support" or "2014 Election - * Campaign"). - * - * @param friendlyName Filter by a workspace’s friendly name. - * @return this - */ public WorkspaceReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Workspace ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public WorkspaceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Workspace ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "workspaces", + response.getContent(), + Workspace.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces"; + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Workspace ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "workspaces", + response.getContent(), + Workspace.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Workspace read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "workspaces", + response.getContent(), + Workspace.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Workspace Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Workspace read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "workspaces", - response.getContent(), - Workspace.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceUpdater.java index c836a183fd..7855276069 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/WorkspaceUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,11 +28,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class WorkspaceUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String defaultActivitySid; private URI eventCallbackUrl; private String eventsFilter; @@ -30,198 +43,180 @@ public class WorkspaceUpdater extends Updater { private String timeoutActivitySid; private Workspace.QueueOrder prioritizeQueueOrder; - /** - * Construct a new WorkspaceUpdater. - * - * @param pathSid The sid - */ public WorkspaceUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * The ID of the Activity that will be used when new Workers are created in this - * Workspace.. - * - * @param defaultActivitySid The ID of the Activity that will be used when new - * Workers are created in this Workspace. - * @return this - */ - public WorkspaceUpdater setDefaultActivitySid(final String defaultActivitySid) { + public WorkspaceUpdater setDefaultActivitySid( + final String defaultActivitySid + ) { this.defaultActivitySid = defaultActivitySid; return this; } - /** - * The Workspace will publish events to this URL. You can use this to gather - * data for reporting. See [Events][/docs/taskrouter/api/events] for more - * information.. - * - * @param eventCallbackUrl The Workspace will publish events to this URL. - * @return this - */ public WorkspaceUpdater setEventCallbackUrl(final URI eventCallbackUrl) { this.eventCallbackUrl = eventCallbackUrl; return this; } - /** - * The Workspace will publish events to this URL. You can use this to gather - * data for reporting. See [Events][/docs/taskrouter/api/events] for more - * information.. - * - * @param eventCallbackUrl The Workspace will publish events to this URL. - * @return this - */ public WorkspaceUpdater setEventCallbackUrl(final String eventCallbackUrl) { return setEventCallbackUrl(Promoter.uriFromString(eventCallbackUrl)); } - /** - * Use this parameter to receive webhooks on EventCallbackUrl for specific - * events on a workspace. For example if - * 'EventsFilter=task.created,task.canceled,worker.activity.update', then - * TaskRouter will webhook to EventCallbackUrl only when a task is created, - * canceled or a worker activity is updated.. - * - * @param eventsFilter Use this parameter to receive webhooks on - * EventCallbackUrl for specific events on a workspace. - * @return this - */ public WorkspaceUpdater setEventsFilter(final String eventsFilter) { this.eventsFilter = eventsFilter; return this; } - /** - * Human readable description of this workspace (for example "Sales Call Center" - * or "Customer Support Team"). - * - * @param friendlyName Human readable description of this workspace - * @return this - */ public WorkspaceUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Enable or Disable Multitasking by passing either *true* or *False* with the - * POST request. Learn more by visiting - * [Multitasking][/docs/taskrouter/multitasking].. - * - * @param multiTaskEnabled Enable or Disable Multitasking by passing either - * true or False with the POST request. - * @return this - */ - public WorkspaceUpdater setMultiTaskEnabled(final Boolean multiTaskEnabled) { + public WorkspaceUpdater setMultiTaskEnabled( + final Boolean multiTaskEnabled + ) { this.multiTaskEnabled = multiTaskEnabled; return this; } - /** - * The ID of the Activity that will be assigned to a Worker when a Task - * reservation times out without a response.. - * - * @param timeoutActivitySid The ID of the Activity that will be assigned to a - * Worker when a Task reservation times out without a - * response. - * @return this - */ - public WorkspaceUpdater setTimeoutActivitySid(final String timeoutActivitySid) { + public WorkspaceUpdater setTimeoutActivitySid( + final String timeoutActivitySid + ) { this.timeoutActivitySid = timeoutActivitySid; return this; } - /** - * Use this parameter to configure whether to prioritize LIFO or FIFO when - * workers are receiving Tasks from combination of LIFO and FIFO TaskQueues. - * Default is FIFO. [Click - * here][/docs/taskrouter/queue-ordering-last-first-out-lifo] to learn more - * about LIFO and the use of the parameter.. - * - * @param prioritizeQueueOrder Use this parameter to configure whether to - * prioritize LIFO or FIFO when workers are - * receiving Tasks from combination of LIFO and FIFO - * TaskQueues. - * @return this - */ - public WorkspaceUpdater setPrioritizeQueueOrder(final Workspace.QueueOrder prioritizeQueueOrder) { + public WorkspaceUpdater setPrioritizeQueueOrder( + final Workspace.QueueOrder prioritizeQueueOrder + ) { this.prioritizeQueueOrder = prioritizeQueueOrder; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Workspace - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Workspace update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workspace update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Workspace update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Workspace update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Workspace.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Workspace content = Workspace.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (defaultActivitySid != null) { - request.addPostParam("DefaultActivitySid", defaultActivitySid); + Serializer.toString( + request, + "DefaultActivitySid", + defaultActivitySid, + ParameterType.URLENCODED + ); } if (eventCallbackUrl != null) { - request.addPostParam("EventCallbackUrl", eventCallbackUrl.toString()); + Serializer.toString( + request, + "EventCallbackUrl", + eventCallbackUrl, + ParameterType.URLENCODED + ); } if (eventsFilter != null) { - request.addPostParam("EventsFilter", eventsFilter); + Serializer.toString( + request, + "EventsFilter", + eventsFilter, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (multiTaskEnabled != null) { - request.addPostParam("MultiTaskEnabled", multiTaskEnabled.toString()); + Serializer.toString( + request, + "MultiTaskEnabled", + multiTaskEnabled, + ParameterType.URLENCODED + ); } if (timeoutActivitySid != null) { - request.addPostParam("TimeoutActivitySid", timeoutActivitySid); + Serializer.toString( + request, + "TimeoutActivitySid", + timeoutActivitySid, + ParameterType.URLENCODED + ); } if (prioritizeQueueOrder != null) { - request.addPostParam("PrioritizeQueueOrder", prioritizeQueueOrder.toString()); + Serializer.toString( + request, + "PrioritizeQueueOrder", + prioritizeQueueOrder, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Activity.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Activity.java index ffe76132e5..4455151c20 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Activity.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Activity.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -11,99 +18,74 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Activity extends Resource { - private static final long serialVersionUID = 66226006406843L; - /** - * Create a ActivityFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return ActivityFetcher capable of executing the fetch - */ - public static ActivityFetcher fetcher(final String pathWorkspaceSid, - final String pathSid) { - return new ActivityFetcher(pathWorkspaceSid, pathSid); + public static ActivityCreator creator( + final String pathWorkspaceSid, + final String friendlyName + ) { + return new ActivityCreator(pathWorkspaceSid, friendlyName); } - /** - * Create a ActivityUpdater to execute update. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return ActivityUpdater capable of executing the update - */ - public static ActivityUpdater updater(final String pathWorkspaceSid, - final String pathSid) { - return new ActivityUpdater(pathWorkspaceSid, pathSid); + public static ActivityDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { + return new ActivityDeleter(pathWorkspaceSid, pathSid); } - /** - * Create a ActivityDeleter to execute delete. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return ActivityDeleter capable of executing the delete - */ - public static ActivityDeleter deleter(final String pathWorkspaceSid, - final String pathSid) { - return new ActivityDeleter(pathWorkspaceSid, pathSid); + public static ActivityFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { + return new ActivityFetcher(pathWorkspaceSid, pathSid); } - /** - * Create a ActivityReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @return ActivityReader capable of executing the read - */ public static ActivityReader reader(final String pathWorkspaceSid) { return new ActivityReader(pathWorkspaceSid); } - /** - * Create a ActivityCreator to execute create. - * - * @param pathWorkspaceSid The workspace_sid - * @param friendlyName A human-readable name for the Activity, such as 'On - * Call', 'Break', 'Email', etc. - * @return ActivityCreator capable of executing the create - */ - public static ActivityCreator creator(final String pathWorkspaceSid, - final String friendlyName) { - return new ActivityCreator(pathWorkspaceSid, friendlyName); + public static ActivityUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { + return new ActivityUpdater(pathWorkspaceSid, pathSid); } /** - * Converts a JSON String into a Activity object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Activity object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Activity object represented by the provided JSON */ - public static Activity fromJson(final String json, final ObjectMapper objectMapper) { + public static Activity fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Activity.class); @@ -117,12 +99,15 @@ public static Activity fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a Activity object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Activity object represented by the provided JSON */ - public static Activity fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Activity fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Activity.class); @@ -133,112 +118,76 @@ public static Activity fromJson(final InputStream json, final ObjectMapper objec } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final Boolean available; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter + private final Map links; + + @Getter private final String sid; - private final String workspaceSid; + + @Getter private final URI url; + @Getter + private final String workspaceSid; + @JsonCreator - private Activity(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("available") - final Boolean available, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("sid") - final String sid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private Activity( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("available") final Boolean available, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.available = available; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; + this.links = links; this.sid = sid; - this.workspaceSid = workspaceSid; this.url = url; - } - - /** - * Returns The The unique ID of the Account that owns this Activity.. - * - * @return The unique ID of the Account that owns this Activity. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Filter by activities that are available or unavailable.. - * - * @return Filter by activities that are available or unavailable. - */ - public final Boolean getAvailable() { - return this.available; - } - - /** - * Returns The The date this Activity was created.. - * - * @return The date this Activity was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Activity was updated.. - * - * @return The date this Activity was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Filter by an Activity's friendly name. - * - * @return Filter by an Activity's friendly name - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique ID for this Activity.. - * - * @return The unique ID for this Activity. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique ID of the Workspace that this Activity belongs to.. - * - * @return The unique ID of the Workspace that this Activity belongs to. - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.workspaceSid = workspaceSid; } @Override @@ -252,40 +201,31 @@ public boolean equals(final Object o) { } Activity other = (Activity) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(available, other.available) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(sid, other.sid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(available, other.available) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - available, - dateCreated, - dateUpdated, - friendlyName, - sid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("available", available) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("sid", sid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + available, + dateCreated, + dateUpdated, + friendlyName, + links, + sid, + url, + workspaceSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityCreator.java index 1d186bf40d..eb8f0196a8 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,92 +27,115 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ActivityCreator extends Creator { - private final String pathWorkspaceSid; - private final String friendlyName; + + private String pathWorkspaceSid; + private String friendlyName; private Boolean available; - /** - * Construct a new ActivityCreator. - * - * @param pathWorkspaceSid The workspace_sid - * @param friendlyName A human-readable name for the Activity, such as 'On - * Call', 'Break', 'Email', etc. - */ - public ActivityCreator(final String pathWorkspaceSid, - final String friendlyName) { + public ActivityCreator( + final String pathWorkspaceSid, + final String friendlyName + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; } - /** - * Boolean value indicating whether the worker should be eligible to receive a - * Task when they occupy this Activity. For example, a call center might have an - * activity named 'On Call' with an availability set to 'false'. Note: This can - * be 'true', '1' or 'yes' to indicate a true value. All other values will - * represent false. Defaults to false.. - * - * @param available Boolean value indicating whether the worker should be - * eligible to receive a Task when they occupy this Activity. - * @return this - */ + public ActivityCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + public ActivityCreator setAvailable(final Boolean available) { this.available = available; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Activity - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Activity create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Activities"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Activities", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Activity creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Activity.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Activity create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Activity content = Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (available != null) { - request.addPostParam("Available", available.toString()); + Serializer.toString( + request, + "Available", + available, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityDeleter.java index 6657a415d0..0cbf856fd4 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,84 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class ActivityDeleter extends Deleter { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new ActivityDeleter. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public ActivityDeleter(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public ActivityDeleter( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Activities/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Activity delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityFetcher.java index 75bef80dd2..437ffe880e 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ActivityFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new ActivityFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public ActivityFetcher(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public ActivityFetcher( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Activity - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Activity fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Activities/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Activity fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Activity.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Activity fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Activity content = Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityReader.java index d71b00ba3e..23e95ad8a9 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,193 +17,225 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ActivityReader extends Reader { - private final String pathWorkspaceSid; + + private String pathWorkspaceSid; private String friendlyName; private String available; + private Long pageSize; - /** - * Construct a new ActivityReader. - * - * @param pathWorkspaceSid The workspace_sid - */ public ActivityReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter by an Activity's friendly name. - * - * @param friendlyName Filter by an Activity's friendly name - * @return this - */ public ActivityReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Filter by activities that are available or unavailable. (Note: This can be - * 'true', '1'' or 'yes' to indicate a true value. All other values will - * represent false). - * - * @param available Filter by activities that are available or unavailable. - * @return this - */ public ActivityReader setAvailable(final String available) { this.available = available; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Activity ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ActivityReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Activity ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "activities", + response.getContent(), + Activity.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Activities"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Activities", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Activity ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "activities", + response.getContent(), + Activity.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Activity read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "activities", + response.getContent(), + Activity.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Activity Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Activity read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "activities", - response.getContent(), - Activity.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (available != null) { - request.addQueryParam("Available", available); + Serializer.toString( + request, + "Available", + available, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityUpdater.java index 44de8f1ae9..0fa95fccc6 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/ActivityUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,85 +27,102 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ActivityUpdater extends Updater { - private final String pathWorkspaceSid; - private final String pathSid; + + private String pathWorkspaceSid; + private String pathSid; private String friendlyName; - /** - * Construct a new ActivityUpdater. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public ActivityUpdater(final String pathWorkspaceSid, - final String pathSid) { + public ActivityUpdater( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * A human-readable name for the Activity, such as 'on-call', 'break', 'email', - * etc. These names will be used to calculate and expose statistics about - * workers, and give you visibility into the state of each of your workers.. - * - * @param friendlyName A human-readable name for the Activity, such as - * 'on-call', 'break', 'email', etc. - * @return this - */ public ActivityUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Activity - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Activity update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Activities/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Activities/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Activity update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Activity update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Activity.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Activity update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Activity content = Activity.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Event.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Event.java index d3214952be..ad6265a9ef 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Event.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Event.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -11,61 +18,52 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Event extends Resource { - private static final long serialVersionUID = 208699778685630L; - /** - * Create a EventFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return EventFetcher capable of executing the fetch - */ - public static EventFetcher fetcher(final String pathWorkspaceSid, - final String pathSid) { + public static EventFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new EventFetcher(pathWorkspaceSid, pathSid); } - /** - * Create a EventReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @return EventReader capable of executing the read - */ public static EventReader reader(final String pathWorkspaceSid) { return new EventReader(pathWorkspaceSid); } /** * Converts a JSON String into a Event object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Event object represented by the provided JSON */ - public static Event fromJson(final String json, final ObjectMapper objectMapper) { + public static Event fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -79,12 +77,15 @@ public static Event fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Event object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Event object represented by the provided JSON */ - public static Event fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Event fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Event.class); @@ -95,60 +96,102 @@ public static Event fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String actorSid; + + @Getter private final String actorType; + + @Getter private final URI actorUrl; + + @Getter private final String description; - private final Map eventData; - private final DateTime eventDate; + + @Getter + private final Object eventData; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime eventDate; + + @Getter + private final Long eventDateMs; + + @Getter private final String eventType; + + @Getter private final String resourceSid; + + @Getter private final String resourceType; + + @Getter private final URI resourceUrl; + + @Getter private final String sid; + + @Getter private final String source; + + @Getter private final String sourceIpAddress; + + @Getter private final URI url; + @Getter + private final String workspaceSid; + @JsonCreator - private Event(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("actor_sid") - final String actorSid, - @JsonProperty("actor_type") - final String actorType, - @JsonProperty("actor_url") - final URI actorUrl, - @JsonProperty("description") - final String description, - @JsonProperty("event_data") - final Map eventData, - @JsonProperty("event_date") - final String eventDate, - @JsonProperty("event_type") - final String eventType, - @JsonProperty("resource_sid") - final String resourceSid, - @JsonProperty("resource_type") - final String resourceType, - @JsonProperty("resource_url") - final URI resourceUrl, - @JsonProperty("sid") - final String sid, - @JsonProperty("source") - final String source, - @JsonProperty("source_ip_address") - final String sourceIpAddress, - @JsonProperty("url") - final URI url) { + private Event( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("actor_sid") final String actorSid, + @JsonProperty("actor_type") final String actorType, + @JsonProperty("actor_url") final URI actorUrl, + @JsonProperty("description") final String description, + @JsonProperty("event_data") final Object eventData, + @JsonProperty("event_date") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime eventDate, + @JsonProperty("event_date_ms") final Long eventDateMs, + @JsonProperty("event_type") final String eventType, + @JsonProperty("resource_sid") final String resourceSid, + @JsonProperty("resource_type") final String resourceType, + @JsonProperty("resource_url") final URI resourceUrl, + @JsonProperty("sid") final String sid, + @JsonProperty("source") final String source, + @JsonProperty("source_ip_address") final String sourceIpAddress, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.actorSid = actorSid; this.actorType = actorType; this.actorUrl = actorUrl; this.description = description; this.eventData = eventData; - this.eventDate = DateConverter.iso8601DateTimeFromString(eventDate); + this.eventDate = eventDate; + this.eventDateMs = eventDateMs; this.eventType = eventType; this.resourceSid = resourceSid; this.resourceType = resourceType; @@ -157,141 +200,7 @@ private Event(@JsonProperty("account_sid") this.source = source; this.sourceIpAddress = sourceIpAddress; this.url = url; - } - - /** - * Returns The The account owning this event. - * - * @return The account owning this event - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The actor_sid. - * - * @return The actor_sid - */ - public final String getActorSid() { - return this.actorSid; - } - - /** - * Returns The The actor_type. - * - * @return The actor_type - */ - public final String getActorType() { - return this.actorType; - } - - /** - * Returns The The actor_url. - * - * @return The actor_url - */ - public final URI getActorUrl() { - return this.actorUrl; - } - - /** - * Returns The A description of the event. - * - * @return A description of the event - */ - public final String getDescription() { - return this.description; - } - - /** - * Returns The Data about this specific event.. - * - * @return Data about this specific event. - */ - public final Map getEventData() { - return this.eventData; - } - - /** - * Returns The The time this event was sent. - * - * @return The time this event was sent - */ - public final DateTime getEventDate() { - return this.eventDate; - } - - /** - * Returns The An identifier for this event. - * - * @return An identifier for this event - */ - public final String getEventType() { - return this.eventType; - } - - /** - * Returns The The sid of the object this event is most relevant to. - * - * @return The sid of the object this event is most relevant to - */ - public final String getResourceSid() { - return this.resourceSid; - } - - /** - * Returns The The type of object this event is most relevant to. - * - * @return The type of object this event is most relevant to - */ - public final String getResourceType() { - return this.resourceType; - } - - /** - * Returns The The resource_url. - * - * @return The resource_url - */ - public final URI getResourceUrl() { - return this.resourceUrl; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The source. - * - * @return The source - */ - public final String getSource() { - return this.source; - } - - /** - * Returns The The source_ip_address. - * - * @return The source_ip_address - */ - public final String getSourceIpAddress() { - return this.sourceIpAddress; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.workspaceSid = workspaceSid; } @Override @@ -305,61 +214,47 @@ public boolean equals(final Object o) { } Event other = (Event) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(actorSid, other.actorSid) && - Objects.equals(actorType, other.actorType) && - Objects.equals(actorUrl, other.actorUrl) && - Objects.equals(description, other.description) && - Objects.equals(eventData, other.eventData) && - Objects.equals(eventDate, other.eventDate) && - Objects.equals(eventType, other.eventType) && - Objects.equals(resourceSid, other.resourceSid) && - Objects.equals(resourceType, other.resourceType) && - Objects.equals(resourceUrl, other.resourceUrl) && - Objects.equals(sid, other.sid) && - Objects.equals(source, other.source) && - Objects.equals(sourceIpAddress, other.sourceIpAddress) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(actorSid, other.actorSid) && + Objects.equals(actorType, other.actorType) && + Objects.equals(actorUrl, other.actorUrl) && + Objects.equals(description, other.description) && + Objects.equals(eventData, other.eventData) && + Objects.equals(eventDate, other.eventDate) && + Objects.equals(eventDateMs, other.eventDateMs) && + Objects.equals(eventType, other.eventType) && + Objects.equals(resourceSid, other.resourceSid) && + Objects.equals(resourceType, other.resourceType) && + Objects.equals(resourceUrl, other.resourceUrl) && + Objects.equals(sid, other.sid) && + Objects.equals(source, other.source) && + Objects.equals(sourceIpAddress, other.sourceIpAddress) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - actorSid, - actorType, - actorUrl, - description, - eventData, - eventDate, - eventType, - resourceSid, - resourceType, - resourceUrl, - sid, - source, - sourceIpAddress, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("actorSid", actorSid) - .add("actorType", actorType) - .add("actorUrl", actorUrl) - .add("description", description) - .add("eventData", eventData) - .add("eventDate", eventDate) - .add("eventType", eventType) - .add("resourceSid", resourceSid) - .add("resourceType", resourceType) - .add("resourceUrl", resourceUrl) - .add("sid", sid) - .add("source", source) - .add("sourceIpAddress", sourceIpAddress) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + actorSid, + actorType, + actorUrl, + description, + eventData, + eventDate, + eventDateMs, + eventType, + resourceSid, + resourceType, + resourceUrl, + sid, + source, + sourceIpAddress, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventFetcher.java index 3214b29906..8cbb04a768 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class EventFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new EventFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public EventFetcher(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public EventFetcher(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Event - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Event fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Events/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Events/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Event fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Event fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Event fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Event.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Event content = Event.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventReader.java index 6f8cbb67e2..ca0cd6ca9c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/EventReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,310 +17,352 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class EventReader extends Reader { - private final String pathWorkspaceSid; - private DateTime endDate; + + private String pathWorkspaceSid; + private ZonedDateTime endDate; private String eventType; private Integer minutes; private String reservationSid; - private DateTime startDate; + private ZonedDateTime startDate; private String taskQueueSid; private String taskSid; private String workerSid; private String workflowSid; + private String taskChannel; + private String sid; + private Long pageSize; - /** - * Construct a new EventReader. - * - * @param pathWorkspaceSid The workspace_sid - */ public EventReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter events by an end date. This is helpful for defining a range of events - * to capture. Input is a GMT ISO 8601 Timestamp.. - * - * @param endDate Filter events by an end date. - * @return this - */ - public EventReader setEndDate(final DateTime endDate) { + public EventReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Filter events by those of a certain event type. - * - * @param eventType Filter events by those of a certain event type - * @return this - */ public EventReader setEventType(final String eventType) { this.eventType = eventType; return this; } - /** - * Filter events by up to ‘x’ minutes in the past. This is helpful for events - * for the last 15 minutes, 240 minutes (4 hours), and 480 minutes (8 hours) to - * see trends. Defaults to 15 minutes.. - * - * @param minutes Filter events by up to ‘x’ minutes in the past. - * @return this - */ public EventReader setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - /** - * Filter events by those pertaining to a particular reservation. - * - * @param reservationSid Filter events by those pertaining to a particular - * reservation - * @return this - */ public EventReader setReservationSid(final String reservationSid) { this.reservationSid = reservationSid; return this; } - /** - * Filter events by a start date. This is helpful for defining a range of events - * to capture. Input is a GMT ISO 8601 Timestamp.. - * - * @param startDate Filter events by a start date. - * @return this - */ - public EventReader setStartDate(final DateTime startDate) { + public EventReader setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - /** - * Filter events by those pertaining to a particular queue. - * - * @param taskQueueSid Filter events by those pertaining to a particular queue - * @return this - */ public EventReader setTaskQueueSid(final String taskQueueSid) { this.taskQueueSid = taskQueueSid; return this; } - /** - * Filter events by those pertaining to a particular task. - * - * @param taskSid Filter events by those pertaining to a particular task - * @return this - */ public EventReader setTaskSid(final String taskSid) { this.taskSid = taskSid; return this; } - /** - * Filter events by those pertaining to a particular worker. - * - * @param workerSid Filter events by those pertaining to a particular worker - * @return this - */ public EventReader setWorkerSid(final String workerSid) { this.workerSid = workerSid; return this; } - /** - * The workflow_sid. - * - * @param workflowSid The workflow_sid - * @return this - */ public EventReader setWorkflowSid(final String workflowSid) { this.workflowSid = workflowSid; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Event ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public EventReader setTaskChannel(final String taskChannel) { + this.taskChannel = taskChannel; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Event ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public EventReader setSid(final String sid) { + this.sid = sid; + return this; + } + + public EventReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Events"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Events", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Event ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Event read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "events", + response.getContent(), + Event.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Event Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Event read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "events", - response.getContent(), - Event.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (eventType != null) { - request.addQueryParam("EventType", eventType); + Serializer.toString( + request, + "EventType", + eventType, + ParameterType.QUERY + ); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (reservationSid != null) { - request.addQueryParam("ReservationSid", reservationSid); + Serializer.toString( + request, + "ReservationSid", + reservationSid, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (taskQueueSid != null) { - request.addQueryParam("TaskQueueSid", taskQueueSid); + Serializer.toString( + request, + "TaskQueueSid", + taskQueueSid, + ParameterType.QUERY + ); } if (taskSid != null) { - request.addQueryParam("TaskSid", taskSid); + Serializer.toString( + request, + "TaskSid", + taskSid, + ParameterType.QUERY + ); } if (workerSid != null) { - request.addQueryParam("WorkerSid", workerSid); + Serializer.toString( + request, + "WorkerSid", + workerSid, + ParameterType.QUERY + ); } if (workflowSid != null) { - request.addQueryParam("WorkflowSid", workflowSid); + Serializer.toString( + request, + "WorkflowSid", + workflowSid, + ParameterType.QUERY + ); + } + + if (taskChannel != null) { + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); + } + + if (sid != null) { + Serializer.toString(request, "Sid", sid, ParameterType.QUERY); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Task.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Task.java index e2835f7d92..c9e453380d 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Task.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Task.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,32 +17,62 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Task extends Resource { - private static final long serialVersionUID = 85038586124308L; + + public static TaskCreator creator(final String pathWorkspaceSid) { + return new TaskCreator(pathWorkspaceSid); + } + + public static TaskDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { + return new TaskDeleter(pathWorkspaceSid, pathSid); + } + + public static TaskFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { + return new TaskFetcher(pathWorkspaceSid, pathSid); + } + + public static TaskReader reader(final String pathWorkspaceSid) { + return new TaskReader(pathWorkspaceSid); + } + + public static TaskUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { + return new TaskUpdater(pathWorkspaceSid, pathSid); + } public enum Status { PENDING("pending"), @@ -51,85 +88,28 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } - /** - * Create a TaskFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return TaskFetcher capable of executing the fetch - */ - public static TaskFetcher fetcher(final String pathWorkspaceSid, - final String pathSid) { - return new TaskFetcher(pathWorkspaceSid, pathSid); - } - - /** - * Create a TaskUpdater to execute update. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return TaskUpdater capable of executing the update - */ - public static TaskUpdater updater(final String pathWorkspaceSid, - final String pathSid) { - return new TaskUpdater(pathWorkspaceSid, pathSid); - } - - /** - * Create a TaskDeleter to execute delete. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return TaskDeleter capable of executing the delete - */ - public static TaskDeleter deleter(final String pathWorkspaceSid, - final String pathSid) { - return new TaskDeleter(pathWorkspaceSid, pathSid); - } - - /** - * Create a TaskReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @return TaskReader capable of executing the read - */ - public static TaskReader reader(final String pathWorkspaceSid) { - return new TaskReader(pathWorkspaceSid); - } - - /** - * Create a TaskCreator to execute create. - * - * @param pathWorkspaceSid The workspace_sid - * @return TaskCreator capable of executing the create - */ - public static TaskCreator creator(final String pathWorkspaceSid) { - return new TaskCreator(pathWorkspaceSid); - } - /** * Converts a JSON String into a Task object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Task object represented by the provided JSON */ - public static Task fromJson(final String json, final ObjectMapper objectMapper) { + public static Task fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Task.class); @@ -143,12 +123,15 @@ public static Task fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Task object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Task object represented by the provided JSON */ - public static Task fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Task fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Task.class); @@ -159,280 +142,167 @@ public static Task fromJson(final InputStream json, final ObjectMapper objectMap } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter + private final String addons; + + @Getter private final Integer age; + + @Getter private final Task.Status assignmentStatus; + + @Getter private final String attributes; - private final String addons; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Boolean ignoreCapacity; + + @Getter + private final Map links; + + @Getter private final Integer priority; + + @Getter private final String reason; + + @Getter + private final String routingTarget; + + @Getter private final String sid; - private final String taskQueueSid; - private final String taskQueueFriendlyName; + + @Getter private final String taskChannelSid; + + @Getter private final String taskChannelUniqueName; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime taskQueueEnteredDate; + + @Getter + private final String taskQueueFriendlyName; + + @Getter + private final String taskQueueSid; + + @Getter private final Integer timeout; - private final String workflowSid; + + @Getter + private final URI url; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime virtualStartTime; + + @Getter private final String workflowFriendlyName; + + @Getter + private final String workflowSid; + + @Getter private final String workspaceSid; - private final URI url; - private final Map links; @JsonCreator - private Task(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("age") - final Integer age, - @JsonProperty("assignment_status") - final Task.Status assignmentStatus, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("addons") - final String addons, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("priority") - final Integer priority, - @JsonProperty("reason") - final String reason, - @JsonProperty("sid") - final String sid, - @JsonProperty("task_queue_sid") - final String taskQueueSid, - @JsonProperty("task_queue_friendly_name") - final String taskQueueFriendlyName, - @JsonProperty("task_channel_sid") - final String taskChannelSid, - @JsonProperty("task_channel_unique_name") - final String taskChannelUniqueName, - @JsonProperty("timeout") - final Integer timeout, - @JsonProperty("workflow_sid") - final String workflowSid, - @JsonProperty("workflow_friendly_name") - final String workflowFriendlyName, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { + private Task( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("addons") final String addons, + @JsonProperty("age") final Integer age, + @JsonProperty("assignment_status") final Task.Status assignmentStatus, + @JsonProperty("attributes") final String attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("ignore_capacity") final Boolean ignoreCapacity, + @JsonProperty("links") final Map links, + @JsonProperty("priority") final Integer priority, + @JsonProperty("reason") final String reason, + @JsonProperty("routing_target") final String routingTarget, + @JsonProperty("sid") final String sid, + @JsonProperty("task_channel_sid") final String taskChannelSid, + @JsonProperty( + "task_channel_unique_name" + ) final String taskChannelUniqueName, + @JsonProperty("task_queue_entered_date") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime taskQueueEnteredDate, + @JsonProperty( + "task_queue_friendly_name" + ) final String taskQueueFriendlyName, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty("timeout") final Integer timeout, + @JsonProperty("url") final URI url, + @JsonProperty("virtual_start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime virtualStartTime, + @JsonProperty( + "workflow_friendly_name" + ) final String workflowFriendlyName, + @JsonProperty("workflow_sid") final String workflowSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; + this.addons = addons; this.age = age; this.assignmentStatus = assignmentStatus; this.attributes = attributes; - this.addons = addons; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.ignoreCapacity = ignoreCapacity; + this.links = links; this.priority = priority; this.reason = reason; + this.routingTarget = routingTarget; this.sid = sid; - this.taskQueueSid = taskQueueSid; - this.taskQueueFriendlyName = taskQueueFriendlyName; this.taskChannelSid = taskChannelSid; this.taskChannelUniqueName = taskChannelUniqueName; + this.taskQueueEnteredDate = taskQueueEnteredDate; + this.taskQueueFriendlyName = taskQueueFriendlyName; + this.taskQueueSid = taskQueueSid; this.timeout = timeout; - this.workflowSid = workflowSid; + this.url = url; + this.virtualStartTime = virtualStartTime; this.workflowFriendlyName = workflowFriendlyName; + this.workflowSid = workflowSid; this.workspaceSid = workspaceSid; - this.url = url; - this.links = links; - } - - /** - * Returns The The ID of the account that owns this Task. - * - * @return The ID of the account that owns this Task - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The number of seconds since this task was created.. - * - * @return The number of seconds since this task was created. - */ - public final Integer getAge() { - return this.age; - } - - /** - * Returns The Returns the list of all Tasks in the workspace with the specified - * AssignmentStatus.. - * - * @return Returns the list of all Tasks in the workspace with the specified - * AssignmentStatus. - */ - public final Task.Status getAssignmentStatus() { - return this.assignmentStatus; - } - - /** - * Returns The The user-defined JSON string describing the custom attributes of - * this work.. - * - * @return The user-defined JSON string describing the custom attributes of - * this work. - */ - public final String getAttributes() { - return this.attributes; - } - - /** - * Returns The The addon data for all installed addons is returned with this - * attribute. - * - * @return The addon data for all installed addons is returned with this - * attribute - */ - public final String getAddons() { - return this.addons; - } - - /** - * Returns The Date this task was created, given as ISO 8601 format.. - * - * @return Date this task was created, given as ISO 8601 format. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The Date this task was updated, given as ISO 8601 format.. - * - * @return Date this task was updated, given as ISO 8601 format. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Retrieve the list of all Tasks in the workspace with the - * specified priority.. - * - * @return Retrieve the list of all Tasks in the workspace with the specified - * priority. - */ - public final Integer getPriority() { - return this.priority; - } - - /** - * Returns The The reason the task was canceled or completed. - * - * @return The reason the task was canceled or completed - */ - public final String getReason() { - return this.reason; - } - - /** - * Returns The The unique ID of the Task. - * - * @return The unique ID of the Task - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Returns the list of Tasks that are currently waiting in the - * TaskQueue identified by the Sid specified.. - * - * @return Returns the list of Tasks that are currently waiting in the - * TaskQueue identified by the Sid specified. - */ - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - - /** - * Returns The The task_queue_friendly_name. - * - * @return The task_queue_friendly_name - */ - public final String getTaskQueueFriendlyName() { - return this.taskQueueFriendlyName; - } - - /** - * Returns The The ID of the Task Channel. - * - * @return The ID of the Task Channel - */ - public final String getTaskChannelSid() { - return this.taskChannelSid; - } - - /** - * Returns The The unique name of the Task Channel. - * - * @return The unique name of the Task Channel - */ - public final String getTaskChannelUniqueName() { - return this.taskChannelUniqueName; - } - - /** - * Returns The The amount of time in seconds the task is allowed to live. - * - * @return The amount of time in seconds the task is allowed to live - */ - public final Integer getTimeout() { - return this.timeout; - } - - /** - * Returns The Returns the list of Tasks that are being controlled by the - * Workflow with the specified Sid value.. - * - * @return Returns the list of Tasks that are being controlled by the Workflow - * with the specified Sid value. - */ - public final String getWorkflowSid() { - return this.workflowSid; - } - - /** - * Returns The The workflow_friendly_name. - * - * @return The workflow_friendly_name - */ - public final String getWorkflowFriendlyName() { - return this.workflowFriendlyName; - } - - /** - * Returns The The ID of the Workspace that holds this Task. - * - * @return The ID of the Workspace that holds this Task - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -446,76 +316,67 @@ public boolean equals(final Object o) { } Task other = (Task) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(age, other.age) && - Objects.equals(assignmentStatus, other.assignmentStatus) && - Objects.equals(attributes, other.attributes) && - Objects.equals(addons, other.addons) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(priority, other.priority) && - Objects.equals(reason, other.reason) && - Objects.equals(sid, other.sid) && - Objects.equals(taskQueueSid, other.taskQueueSid) && - Objects.equals(taskQueueFriendlyName, other.taskQueueFriendlyName) && - Objects.equals(taskChannelSid, other.taskChannelSid) && - Objects.equals(taskChannelUniqueName, other.taskChannelUniqueName) && - Objects.equals(timeout, other.timeout) && - Objects.equals(workflowSid, other.workflowSid) && - Objects.equals(workflowFriendlyName, other.workflowFriendlyName) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addons, other.addons) && + Objects.equals(age, other.age) && + Objects.equals(assignmentStatus, other.assignmentStatus) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(ignoreCapacity, other.ignoreCapacity) && + Objects.equals(links, other.links) && + Objects.equals(priority, other.priority) && + Objects.equals(reason, other.reason) && + Objects.equals(routingTarget, other.routingTarget) && + Objects.equals(sid, other.sid) && + Objects.equals(taskChannelSid, other.taskChannelSid) && + Objects.equals( + taskChannelUniqueName, + other.taskChannelUniqueName + ) && + Objects.equals(taskQueueEnteredDate, other.taskQueueEnteredDate) && + Objects.equals( + taskQueueFriendlyName, + other.taskQueueFriendlyName + ) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals(timeout, other.timeout) && + Objects.equals(url, other.url) && + Objects.equals(virtualStartTime, other.virtualStartTime) && + Objects.equals(workflowFriendlyName, other.workflowFriendlyName) && + Objects.equals(workflowSid, other.workflowSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - age, - assignmentStatus, - attributes, - addons, - dateCreated, - dateUpdated, - priority, - reason, - sid, - taskQueueSid, - taskQueueFriendlyName, - taskChannelSid, - taskChannelUniqueName, - timeout, - workflowSid, - workflowFriendlyName, - workspaceSid, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("age", age) - .add("assignmentStatus", assignmentStatus) - .add("attributes", attributes) - .add("addons", addons) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("priority", priority) - .add("reason", reason) - .add("sid", sid) - .add("taskQueueSid", taskQueueSid) - .add("taskQueueFriendlyName", taskQueueFriendlyName) - .add("taskChannelSid", taskChannelSid) - .add("taskChannelUniqueName", taskChannelUniqueName) - .add("timeout", timeout) - .add("workflowSid", workflowSid) - .add("workflowFriendlyName", workflowFriendlyName) - .add("workspaceSid", workspaceSid) - .add("url", url) - .add("links", links) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + addons, + age, + assignmentStatus, + attributes, + dateCreated, + dateUpdated, + ignoreCapacity, + links, + priority, + reason, + routingTarget, + sid, + taskChannelSid, + taskChannelUniqueName, + taskQueueEnteredDate, + taskQueueFriendlyName, + taskQueueSid, + timeout, + url, + virtualStartTime, + workflowFriendlyName, + workflowSid, + workspaceSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannel.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannel.java index 1e6e9d8ed5..81bb8bb279 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannel.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -11,62 +18,79 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class TaskChannel extends Resource { - private static final long serialVersionUID = 123017740799311L; - /** - * Create a TaskChannelFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return TaskChannelFetcher capable of executing the fetch - */ - public static TaskChannelFetcher fetcher(final String pathWorkspaceSid, - final String pathSid) { + public static TaskChannelCreator creator( + final String pathWorkspaceSid, + final String friendlyName, + final String uniqueName + ) { + return new TaskChannelCreator( + pathWorkspaceSid, + friendlyName, + uniqueName + ); + } + + public static TaskChannelDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { + return new TaskChannelDeleter(pathWorkspaceSid, pathSid); + } + + public static TaskChannelFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new TaskChannelFetcher(pathWorkspaceSid, pathSid); } - /** - * Create a TaskChannelReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @return TaskChannelReader capable of executing the read - */ public static TaskChannelReader reader(final String pathWorkspaceSid) { return new TaskChannelReader(pathWorkspaceSid); } + public static TaskChannelUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { + return new TaskChannelUpdater(pathWorkspaceSid, pathSid); + } + /** - * Converts a JSON String into a TaskChannel object using the provided - * ObjectMapper. - * + * Converts a JSON String into a TaskChannel object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return TaskChannel object represented by the provided JSON */ - public static TaskChannel fromJson(final String json, final ObjectMapper objectMapper) { + public static TaskChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskChannel.class); @@ -80,12 +104,15 @@ public static TaskChannel fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a TaskChannel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return TaskChannel object represented by the provided JSON */ - public static TaskChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static TaskChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskChannel.class); @@ -96,112 +123,83 @@ public static TaskChannel fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final Boolean channelOptimizedRouting; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter + private final Map links; + + @Getter private final String sid; + + @Getter private final String uniqueName; - private final String workspaceSid; + + @Getter private final URI url; + @Getter + private final String workspaceSid; + @JsonCreator - private TaskChannel(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("sid") - final String sid, - @JsonProperty("unique_name") - final String uniqueName, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private TaskChannel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "channel_optimized_routing" + ) final Boolean channelOptimizedRouting, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("unique_name") final String uniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.channelOptimizedRouting = channelOptimizedRouting; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; + this.links = links; this.sid = sid; this.uniqueName = uniqueName; - this.workspaceSid = workspaceSid; this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique_name. - * - * @return The unique_name - */ - public final String getUniqueName() { - return this.uniqueName; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.workspaceSid = workspaceSid; } @Override @@ -215,40 +213,36 @@ public boolean equals(final Object o) { } TaskChannel other = (TaskChannel) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(sid, other.sid) && - Objects.equals(uniqueName, other.uniqueName) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + channelOptimizedRouting, + other.channelOptimizedRouting + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(uniqueName, other.uniqueName) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - friendlyName, - sid, - uniqueName, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("sid", sid) - .add("uniqueName", uniqueName) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + channelOptimizedRouting, + dateCreated, + dateUpdated, + friendlyName, + links, + sid, + uniqueName, + url, + workspaceSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelCreator.java new file mode 100644 index 0000000000..dbf04bb302 --- /dev/null +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelCreator.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.taskrouter.v1.workspace; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TaskChannelCreator extends Creator { + + private String pathWorkspaceSid; + private String friendlyName; + private String uniqueName; + private Boolean channelOptimizedRouting; + + public TaskChannelCreator( + final String pathWorkspaceSid, + final String friendlyName, + final String uniqueName + ) { + this.pathWorkspaceSid = pathWorkspaceSid; + this.friendlyName = friendlyName; + this.uniqueName = uniqueName; + } + + public TaskChannelCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public TaskChannelCreator setUniqueName(final String uniqueName) { + this.uniqueName = uniqueName; + return this; + } + + public TaskChannelCreator setChannelOptimizedRouting( + final Boolean channelOptimizedRouting + ) { + this.channelOptimizedRouting = channelOptimizedRouting; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TASKROUTER.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TaskChannel creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TaskChannel create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskChannel content = TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (uniqueName != null) { + Serializer.toString( + request, + "UniqueName", + uniqueName, + ParameterType.URLENCODED + ); + } + + if (channelOptimizedRouting != null) { + Serializer.toString( + request, + "ChannelOptimizedRouting", + channelOptimizedRouting, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelDeleter.java new file mode 100644 index 0000000000..1c31b625f1 --- /dev/null +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelDeleter.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.taskrouter.v1.workspace; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class TaskChannelDeleter extends Deleter { + + private String pathWorkspaceSid; + private String pathSid; + + public TaskChannelDeleter( + final String pathWorkspaceSid, + final String pathSid + ) { + this.pathWorkspaceSid = pathWorkspaceSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TASKROUTER.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TaskChannel delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelFetcher.java index 576abe2f85..60a0222c47 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TaskChannelFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new TaskChannelFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public TaskChannelFetcher(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public TaskChannelFetcher( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched TaskChannel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public TaskChannel fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskChannels/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskChannel fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TaskChannel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return TaskChannel.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TaskChannel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskChannel content = TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelReader.java index 491a27c2ac..0026b7b0ae 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,159 +17,195 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TaskChannelReader extends Reader { - private final String pathWorkspaceSid; - /** - * Construct a new TaskChannelReader. - * - * @param pathWorkspaceSid The workspace_sid - */ + private String pathWorkspaceSid; + private Long pageSize; + public TaskChannelReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TaskChannel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TaskChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TaskChannel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + TaskChannel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskChannels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return TaskChannel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + TaskChannel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TaskChannel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + TaskChannel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of TaskChannel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("TaskChannel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - TaskChannel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelUpdater.java new file mode 100644 index 0000000000..00c45f6f23 --- /dev/null +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskChannelUpdater.java @@ -0,0 +1,145 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.taskrouter.v1.workspace; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TaskChannelUpdater extends Updater { + + private String pathWorkspaceSid; + private String pathSid; + private String friendlyName; + private Boolean channelOptimizedRouting; + + public TaskChannelUpdater( + final String pathWorkspaceSid, + final String pathSid + ) { + this.pathWorkspaceSid = pathWorkspaceSid; + this.pathSid = pathSid; + } + + public TaskChannelUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public TaskChannelUpdater setChannelOptimizedRouting( + final Boolean channelOptimizedRouting + ) { + this.channelOptimizedRouting = channelOptimizedRouting; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskChannels/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.TASKROUTER.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TaskChannel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TaskChannel update(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskChannel content = TaskChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (channelOptimizedRouting != null) { + Serializer.toString( + request, + "ChannelOptimizedRouting", + channelOptimizedRouting, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskCreator.java index 538a251926..08169f65b2 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,159 +27,216 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class TaskCreator extends Creator { - private final String pathWorkspaceSid; + + private String pathWorkspaceSid; private Integer timeout; private Integer priority; private String taskChannel; private String workflowSid; private String attributes; + private ZonedDateTime virtualStartTime; + private String routingTarget; + private String ignoreCapacity; + private String taskQueueSid; - /** - * Construct a new TaskCreator. - * - * @param pathWorkspaceSid The workspace_sid - */ public TaskCreator(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * The amount of time in seconds the task is allowed to live up to a maximum of - * 2 weeks. Defaults to 24 hours. On timeout, `task.canceled` event will fire - * with description "Task TTL Exceeded".. - * - * @param timeout The amount of time in seconds the task is allowed to live up - * to a maximum of 2 weeks. - * @return this - */ public TaskCreator setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - /** - * Override priority for the Task. When supplied, the Task will take on the - * given priority unless it matches a Workflow Target with a Priority set. When - * not supplied, the Task will take on the priority of the matching Workflow - * Target.. - * - * @param priority Override priority for the Task. - * @return this - */ public TaskCreator setPriority(final Integer priority) { this.priority = priority; return this; } - /** - * When MultiTasking is enabled specify the type of the task by passing either - * TaskChannel Unique Name or Task Channel Sid. Default value is "default". - * - * @param taskChannel When MultiTasking is enabled specify the type of the task - * by passing either TaskChannel Unique Name or Task Channel - * Sid. - * @return this - */ public TaskCreator setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - /** - * The WorkflowSid for the Workflow that you would like to handle routing for - * this Task. If there is only one Workflow defined for the Workspace that you - * are posting a task to, then this is an optional parameter, and that single - * workflow will be used.. - * - * @param workflowSid The WorkflowSid for the Workflow that you would like to - * handle routing for this Task. - * @return this - */ public TaskCreator setWorkflowSid(final String workflowSid) { this.workflowSid = workflowSid; return this; } - /** - * Url-encoded JSON string describing the attributes of this task. This data - * will be passed back to the Workflow's AssignmentCallbackURL when the Task is - * assigned to a Worker. An example task: `{ "task_type": "call", - * "twilio_call_sid": "CAxxx", "customer_ticket_number": "12345" }`. - * - * @param attributes Url-encoded JSON string describing the attributes of this - * task. - * @return this - */ public TaskCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Task - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Task create(final TwilioRestClient client) { + public TaskCreator setVirtualStartTime( + final ZonedDateTime virtualStartTime + ) { + this.virtualStartTime = virtualStartTime; + return this; + } + + public TaskCreator setRoutingTarget(final String routingTarget) { + this.routingTarget = routingTarget; + return this; + } + + public TaskCreator setIgnoreCapacity(final String ignoreCapacity) { + this.ignoreCapacity = ignoreCapacity; + return this; + } + + public TaskCreator setTaskQueueSid(final String taskQueueSid) { + this.taskQueueSid = taskQueueSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Tasks"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Tasks", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Task creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Task create(final TwilioRestClient client) { + Response response = makeRequest(client); return Task.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Task content = Task.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (timeout != null) { - request.addPostParam("Timeout", timeout.toString()); + Serializer.toString( + request, + "Timeout", + timeout, + ParameterType.URLENCODED + ); } if (priority != null) { - request.addPostParam("Priority", priority.toString()); + Serializer.toString( + request, + "Priority", + priority, + ParameterType.URLENCODED + ); } if (taskChannel != null) { - request.addPostParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.URLENCODED + ); } if (workflowSid != null) { - request.addPostParam("WorkflowSid", workflowSid); + Serializer.toString( + request, + "WorkflowSid", + workflowSid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + + if (virtualStartTime != null) { + Serializer.toString( + request, + "VirtualStartTime", + virtualStartTime, + ParameterType.URLENCODED + ); + } + + if (routingTarget != null) { + Serializer.toString( + request, + "RoutingTarget", + routingTarget, + ParameterType.URLENCODED + ); + } + + if (ignoreCapacity != null) { + Serializer.toString( + request, + "IgnoreCapacity", + ignoreCapacity, + ParameterType.URLENCODED + ); + } + + if (taskQueueSid != null) { + Serializer.toString( + request, + "TaskQueueSid", + taskQueueSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskDeleter.java index 3a111a982e..61c640fa6c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +26,99 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class TaskDeleter extends Deleter { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new TaskDeleter. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public TaskDeleter(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + private String ifMatch; + + public TaskDeleter(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public TaskDeleter setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Tasks/" + this.pathSid + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Task delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskFetcher.java index f64211d963..2af8249bbb 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TaskFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new TaskFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public TaskFetcher(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public TaskFetcher(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Task - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Task fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Tasks/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Task fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Task fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Task.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Task content = Task.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueue.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueue.java index 763cfbb68b..efeefd38fb 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueue.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueue.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,32 +17,65 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class TaskQueue extends Resource { - private static final long serialVersionUID = 31174194031326L; + + public static TaskQueueCreator creator( + final String pathWorkspaceSid, + final String friendlyName + ) { + return new TaskQueueCreator(pathWorkspaceSid, friendlyName); + } + + public static TaskQueueDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { + return new TaskQueueDeleter(pathWorkspaceSid, pathSid); + } + + public static TaskQueueFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { + return new TaskQueueFetcher(pathWorkspaceSid, pathSid); + } + + public static TaskQueueReader reader(final String pathWorkspaceSid) { + return new TaskQueueReader(pathWorkspaceSid); + } + + public static TaskQueueUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { + return new TaskQueueUpdater(pathWorkspaceSid, pathSid); + } public enum TaskOrder { FIFO("FIFO"), @@ -47,15 +87,11 @@ private TaskOrder(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a TaskOrder from a string. - * @param value string value - * @return generated TaskOrder - */ @JsonCreator public static TaskOrder forValue(final String value) { return Promoter.enumFromString(value, TaskOrder.values()); @@ -63,78 +99,16 @@ public static TaskOrder forValue(final String value) { } /** - * Create a TaskQueueFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return TaskQueueFetcher capable of executing the fetch - */ - public static TaskQueueFetcher fetcher(final String pathWorkspaceSid, - final String pathSid) { - return new TaskQueueFetcher(pathWorkspaceSid, pathSid); - } - - /** - * Create a TaskQueueUpdater to execute update. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return TaskQueueUpdater capable of executing the update - */ - public static TaskQueueUpdater updater(final String pathWorkspaceSid, - final String pathSid) { - return new TaskQueueUpdater(pathWorkspaceSid, pathSid); - } - - /** - * Create a TaskQueueReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @return TaskQueueReader capable of executing the read - */ - public static TaskQueueReader reader(final String pathWorkspaceSid) { - return new TaskQueueReader(pathWorkspaceSid); - } - - /** - * Create a TaskQueueCreator to execute create. - * - * @param pathWorkspaceSid The workspace_sid - * @param friendlyName Human readable description of this TaskQueue - * @param reservationActivitySid ActivitySID to assign workers once a task is - * reserved for them - * @param assignmentActivitySid ActivitySID to assign workers once a task is - * assigned for them - * @return TaskQueueCreator capable of executing the create - */ - public static TaskQueueCreator creator(final String pathWorkspaceSid, - final String friendlyName, - final String reservationActivitySid, - final String assignmentActivitySid) { - return new TaskQueueCreator(pathWorkspaceSid, friendlyName, reservationActivitySid, assignmentActivitySid); - } - - /** - * Create a TaskQueueDeleter to execute delete. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return TaskQueueDeleter capable of executing the delete - */ - public static TaskQueueDeleter deleter(final String pathWorkspaceSid, - final String pathSid) { - return new TaskQueueDeleter(pathWorkspaceSid, pathSid); - } - - /** - * Converts a JSON String into a TaskQueue object using the provided - * ObjectMapper. - * + * Converts a JSON String into a TaskQueue object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return TaskQueue object represented by the provided JSON */ - public static TaskQueue fromJson(final String json, final ObjectMapper objectMapper) { + public static TaskQueue fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueue.class); @@ -148,12 +122,15 @@ public static TaskQueue fromJson(final String json, final ObjectMapper objectMap /** * Converts a JSON InputStream into a TaskQueue object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return TaskQueue object represented by the provided JSON */ - public static TaskQueue fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static TaskQueue fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueue.class); @@ -164,209 +141,114 @@ public static TaskQueue fromJson(final InputStream json, final ObjectMapper obje } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String assignmentActivitySid; + + @Getter private final String assignmentActivityName; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final String assignmentActivitySid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter + private final Map links; + + @Getter private final Integer maxReservedWorkers; - private final String reservationActivitySid; + + @Getter private final String reservationActivityName; + + @Getter + private final String reservationActivitySid; + + @Getter private final String sid; + + @Getter private final String targetWorkers; + + @Getter private final TaskQueue.TaskOrder taskOrder; + + @Getter private final URI url; + + @Getter private final String workspaceSid; - private final Map links; @JsonCreator - private TaskQueue(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("assignment_activity_sid") - final String assignmentActivitySid, - @JsonProperty("assignment_activity_name") - final String assignmentActivityName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("max_reserved_workers") - final Integer maxReservedWorkers, - @JsonProperty("reservation_activity_sid") - final String reservationActivitySid, - @JsonProperty("reservation_activity_name") - final String reservationActivityName, - @JsonProperty("sid") - final String sid, - @JsonProperty("target_workers") - final String targetWorkers, - @JsonProperty("task_order") - final TaskQueue.TaskOrder taskOrder, - @JsonProperty("url") - final URI url, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("links") - final Map links) { + private TaskQueue( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "assignment_activity_name" + ) final String assignmentActivityName, + @JsonProperty( + "assignment_activity_sid" + ) final String assignmentActivitySid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("max_reserved_workers") final Integer maxReservedWorkers, + @JsonProperty( + "reservation_activity_name" + ) final String reservationActivityName, + @JsonProperty( + "reservation_activity_sid" + ) final String reservationActivitySid, + @JsonProperty("sid") final String sid, + @JsonProperty("target_workers") final String targetWorkers, + @JsonProperty("task_order") final TaskQueue.TaskOrder taskOrder, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; - this.assignmentActivitySid = assignmentActivitySid; this.assignmentActivityName = assignmentActivityName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.assignmentActivitySid = assignmentActivitySid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; + this.links = links; this.maxReservedWorkers = maxReservedWorkers; - this.reservationActivitySid = reservationActivitySid; this.reservationActivityName = reservationActivityName; + this.reservationActivitySid = reservationActivitySid; this.sid = sid; this.targetWorkers = targetWorkers; this.taskOrder = taskOrder; this.url = url; this.workspaceSid = workspaceSid; - this.links = links; - } - - /** - * Returns The The ID of the Account that owns this TaskQueue. - * - * @return The ID of the Account that owns this TaskQueue - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The ActivitySID to assign workers once a task is assigned for them. - * - * @return ActivitySID to assign workers once a task is assigned for them - */ - public final String getAssignmentActivitySid() { - return this.assignmentActivitySid; - } - - /** - * Returns The The assignment_activity_name. - * - * @return The assignment_activity_name - */ - public final String getAssignmentActivityName() { - return this.assignmentActivityName; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Filter by a human readable description of a TaskQueue. - * - * @return Filter by a human readable description of a TaskQueue - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The maximum amount of workers to create reservations for the - * assignment of a task while in this queue.. - * - * @return The maximum amount of workers to create reservations for the - * assignment of a task while in this queue. - */ - public final Integer getMaxReservedWorkers() { - return this.maxReservedWorkers; - } - - /** - * Returns The ActivitySID to assign workers once a task is reserved for them. - * - * @return ActivitySID to assign workers once a task is reserved for them - */ - public final String getReservationActivitySid() { - return this.reservationActivitySid; - } - - /** - * Returns The The reservation_activity_name. - * - * @return The reservation_activity_name - */ - public final String getReservationActivityName() { - return this.reservationActivityName; - } - - /** - * Returns The The unique ID of the TaskQueue. - * - * @return The unique ID of the TaskQueue - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The A string describing the Worker selection criteria for any Tasks - * that enter this TaskQueue.. - * - * @return A string describing the Worker selection criteria for any Tasks that - * enter this TaskQueue. - */ - public final String getTargetWorkers() { - return this.targetWorkers; - } - - /** - * Returns The TaskOrder will determine which order the Tasks will be assigned - * to Workers.. - * - * @return TaskOrder will determine which order the Tasks will be assigned to - * Workers. - */ - public final TaskQueue.TaskOrder getTaskOrder() { - return this.taskOrder; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The ID of the Workspace that owns this TaskQueue. - * - * @return The ID of the Workspace that owns this TaskQueue - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -380,61 +262,55 @@ public boolean equals(final Object o) { } TaskQueue other = (TaskQueue) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(assignmentActivitySid, other.assignmentActivitySid) && - Objects.equals(assignmentActivityName, other.assignmentActivityName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(maxReservedWorkers, other.maxReservedWorkers) && - Objects.equals(reservationActivitySid, other.reservationActivitySid) && - Objects.equals(reservationActivityName, other.reservationActivityName) && - Objects.equals(sid, other.sid) && - Objects.equals(targetWorkers, other.targetWorkers) && - Objects.equals(taskOrder, other.taskOrder) && - Objects.equals(url, other.url) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + assignmentActivityName, + other.assignmentActivityName + ) && + Objects.equals( + assignmentActivitySid, + other.assignmentActivitySid + ) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(maxReservedWorkers, other.maxReservedWorkers) && + Objects.equals( + reservationActivityName, + other.reservationActivityName + ) && + Objects.equals( + reservationActivitySid, + other.reservationActivitySid + ) && + Objects.equals(sid, other.sid) && + Objects.equals(targetWorkers, other.targetWorkers) && + Objects.equals(taskOrder, other.taskOrder) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - assignmentActivitySid, - assignmentActivityName, - dateCreated, - dateUpdated, - friendlyName, - maxReservedWorkers, - reservationActivitySid, - reservationActivityName, - sid, - targetWorkers, - taskOrder, - url, - workspaceSid, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("assignmentActivitySid", assignmentActivitySid) - .add("assignmentActivityName", assignmentActivityName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("maxReservedWorkers", maxReservedWorkers) - .add("reservationActivitySid", reservationActivitySid) - .add("reservationActivityName", reservationActivityName) - .add("sid", sid) - .add("targetWorkers", targetWorkers) - .add("taskOrder", taskOrder) - .add("url", url) - .add("workspaceSid", workspaceSid) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + assignmentActivityName, + assignmentActivitySid, + dateCreated, + dateUpdated, + friendlyName, + links, + maxReservedWorkers, + reservationActivityName, + reservationActivitySid, + sid, + targetWorkers, + taskOrder, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueCreator.java index 63f3100ede..b21aa52661 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,149 +27,181 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TaskQueueCreator extends Creator { - private final String pathWorkspaceSid; - private final String friendlyName; - private final String reservationActivitySid; - private final String assignmentActivitySid; + + private String pathWorkspaceSid; + private String friendlyName; private String targetWorkers; private Integer maxReservedWorkers; private TaskQueue.TaskOrder taskOrder; + private String reservationActivitySid; + private String assignmentActivitySid; - /** - * Construct a new TaskQueueCreator. - * - * @param pathWorkspaceSid The workspace_sid - * @param friendlyName Human readable description of this TaskQueue - * @param reservationActivitySid ActivitySID to assign workers once a task is - * reserved for them - * @param assignmentActivitySid ActivitySID to assign workers once a task is - * assigned for them - */ - public TaskQueueCreator(final String pathWorkspaceSid, - final String friendlyName, - final String reservationActivitySid, - final String assignmentActivitySid) { + public TaskQueueCreator( + final String pathWorkspaceSid, + final String friendlyName + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; - this.reservationActivitySid = reservationActivitySid; - this.assignmentActivitySid = assignmentActivitySid; } - /** - * A string describing the Worker selection criteria for any Tasks that enter - * this TaskQueue. For example `'"language" == "spanish"'` If no TargetWorkers - * parameter is provided, Tasks will wait in this TaskQueue until they are - * either deleted or moved to another TaskQueue. Additional examples on how to - * describing Worker selection criteria below. Defaults to 1==1.. - * - * @param targetWorkers A string describing the Worker selection criteria for - * any Tasks that enter this TaskQueue. - * @return this - */ + public TaskQueueCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + public TaskQueueCreator setTargetWorkers(final String targetWorkers) { this.targetWorkers = targetWorkers; return this; } - /** - * The maximum amount of workers to create reservations for the assignment of a - * task while in this queue. Defaults to 1, with a Maximum of 50.. - * - * @param maxReservedWorkers The maximum amount of workers to create - * reservations for the assignment of a task while in - * this queue. - * @return this - */ - public TaskQueueCreator setMaxReservedWorkers(final Integer maxReservedWorkers) { + public TaskQueueCreator setMaxReservedWorkers( + final Integer maxReservedWorkers + ) { this.maxReservedWorkers = maxReservedWorkers; return this; } - /** - * TaskOrder will determine which order the Tasks will be assigned to Workers. - * Set this parameter to LIFO to assign most recently created Task first or FIFO - * to assign the oldest Task. Default is FIFO. [Click - * here](https://www.twilio.com/docs/api/taskrouter/last-first-out-lifo) to - * learn more.. - * - * @param taskOrder TaskOrder will determine which order the Tasks will be - * assigned to Workers. - * @return this - */ public TaskQueueCreator setTaskOrder(final TaskQueue.TaskOrder taskOrder) { this.taskOrder = taskOrder; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created TaskQueue - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public TaskQueue create(final TwilioRestClient client) { + public TaskQueueCreator setReservationActivitySid( + final String reservationActivitySid + ) { + this.reservationActivitySid = reservationActivitySid; + return this; + } + + public TaskQueueCreator setAssignmentActivitySid( + final String assignmentActivitySid + ) { + this.assignmentActivitySid = assignmentActivitySid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TaskQueue creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return TaskQueue.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TaskQueue create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskQueue content = TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } - if (reservationActivitySid != null) { - request.addPostParam("ReservationActivitySid", reservationActivitySid); + if (targetWorkers != null) { + Serializer.toString( + request, + "TargetWorkers", + targetWorkers, + ParameterType.URLENCODED + ); } - if (assignmentActivitySid != null) { - request.addPostParam("AssignmentActivitySid", assignmentActivitySid); + if (maxReservedWorkers != null) { + Serializer.toString( + request, + "MaxReservedWorkers", + maxReservedWorkers, + ParameterType.URLENCODED + ); } - if (targetWorkers != null) { - request.addPostParam("TargetWorkers", targetWorkers); + if (taskOrder != null) { + Serializer.toString( + request, + "TaskOrder", + taskOrder, + ParameterType.URLENCODED + ); } - if (maxReservedWorkers != null) { - request.addPostParam("MaxReservedWorkers", maxReservedWorkers.toString()); + if (reservationActivitySid != null) { + Serializer.toString( + request, + "ReservationActivitySid", + reservationActivitySid, + ParameterType.URLENCODED + ); } - if (taskOrder != null) { - request.addPostParam("TaskOrder", taskOrder.toString()); + if (assignmentActivitySid != null) { + Serializer.toString( + request, + "AssignmentActivitySid", + assignmentActivitySid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueDeleter.java index a547d025e8..df692ef060 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,84 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class TaskQueueDeleter extends Deleter { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new TaskQueueDeleter. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public TaskQueueDeleter(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public TaskQueueDeleter( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TaskQueue delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueFetcher.java index 6ff792591f..c95635ac06 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TaskQueueFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new TaskQueueFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public TaskQueueFetcher(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public TaskQueueFetcher( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched TaskQueue - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public TaskQueue fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TaskQueue fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return TaskQueue.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TaskQueue fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskQueue content = TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueReader.java index 5051aa3ff9..2b7464675b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,212 +17,257 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TaskQueueReader extends Reader { - private final String pathWorkspaceSid; + + private String pathWorkspaceSid; private String friendlyName; private String evaluateWorkerAttributes; private String workerSid; + private String ordering; + private Long pageSize; - /** - * Construct a new TaskQueueReader. - * - * @param pathWorkspaceSid The workspace_sid - */ public TaskQueueReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter by a human readable description of a TaskQueue (for example "Customer - * Support" or "2014 Election Campaign"). - * - * @param friendlyName Filter by a human readable description of a TaskQueue - * @return this - */ public TaskQueueReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Provide a Worker attributes expression, and this will return the list of - * TaskQueues that would distribute tasks to a worker with these attributes.. - * - * @param evaluateWorkerAttributes Provide a Worker attributes expression, and - * this will return the list of TaskQueues that - * would distribute tasks to a worker with these - * attributes. - * @return this - */ - public TaskQueueReader setEvaluateWorkerAttributes(final String evaluateWorkerAttributes) { + public TaskQueueReader setEvaluateWorkerAttributes( + final String evaluateWorkerAttributes + ) { this.evaluateWorkerAttributes = evaluateWorkerAttributes; return this; } - /** - * The worker_sid. - * - * @param workerSid The worker_sid - * @return this - */ public TaskQueueReader setWorkerSid(final String workerSid) { this.workerSid = workerSid; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TaskQueue ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TaskQueueReader setOrdering(final String ordering) { + this.ordering = ordering; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TaskQueue ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public TaskQueueReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "task_queues", + response.getContent(), + TaskQueue.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return TaskQueue ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "task_queues", + response.getContent(), + TaskQueue.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TaskQueue read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "task_queues", + response.getContent(), + TaskQueue.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of TaskQueue Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("TaskQueue read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "task_queues", - response.getContent(), - TaskQueue.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (evaluateWorkerAttributes != null) { - request.addQueryParam("EvaluateWorkerAttributes", evaluateWorkerAttributes); + Serializer.toString( + request, + "EvaluateWorkerAttributes", + evaluateWorkerAttributes, + ParameterType.QUERY + ); } if (workerSid != null) { - request.addQueryParam("WorkerSid", workerSid); + Serializer.toString( + request, + "WorkerSid", + workerSid, + ParameterType.QUERY + ); + } + + if (ordering != null) { + Serializer.toString( + request, + "Ordering", + ordering, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueUpdater.java index dd275770c2..f5370ec08b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskQueueUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,10 +27,13 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TaskQueueUpdater extends Updater { - private final String pathWorkspaceSid; - private final String pathSid; + + private String pathWorkspaceSid; + private String pathSid; private String friendlyName; private String targetWorkers; private String reservationActivitySid; @@ -27,171 +41,169 @@ public class TaskQueueUpdater extends Updater { private Integer maxReservedWorkers; private TaskQueue.TaskOrder taskOrder; - /** - * Construct a new TaskQueueUpdater. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public TaskQueueUpdater(final String pathWorkspaceSid, - final String pathSid) { + public TaskQueueUpdater( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Human readable description of this TaskQueue (for example "Support – Tier 1", - * "Sales" or "Escalation"). - * - * @param friendlyName Human readable description of this TaskQueue - * @return this - */ public TaskQueueUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A string describing the Worker selection criteria for any Tasks that enter - * this TaskQueue. For example '"language" == "spanish"' If no TargetWorkers - * parameter is provided, Tasks will wait in this queue until they are either - * deleted or moved to another queue. Additional examples on how to describing - * Worker selection criteria below.. - * - * @param targetWorkers A string describing the Worker selection criteria for - * any Tasks that enter this TaskQueue. - * @return this - */ public TaskQueueUpdater setTargetWorkers(final String targetWorkers) { this.targetWorkers = targetWorkers; return this; } - /** - * ActivitySID that will be assigned to Workers when they are reserved for a - * task from this TaskQueue.. - * - * @param reservationActivitySid ActivitySID that will be assigned to Workers - * when they are reserved for a task from this - * TaskQueue. - * @return this - */ - public TaskQueueUpdater setReservationActivitySid(final String reservationActivitySid) { + public TaskQueueUpdater setReservationActivitySid( + final String reservationActivitySid + ) { this.reservationActivitySid = reservationActivitySid; return this; } - /** - * ActivitySID that will be assigned to Workers when they are assigned a task - * from this TaskQueue.. - * - * @param assignmentActivitySid ActivitySID that will be assigned to Workers - * when they are assigned a task from this - * TaskQueue. - * @return this - */ - public TaskQueueUpdater setAssignmentActivitySid(final String assignmentActivitySid) { + public TaskQueueUpdater setAssignmentActivitySid( + final String assignmentActivitySid + ) { this.assignmentActivitySid = assignmentActivitySid; return this; } - /** - * The maximum amount of workers to create reservations for the assignment of a - * task while in this queue. Maximum of 50.. - * - * @param maxReservedWorkers The maximum amount of workers to create - * reservations for the assignment of a task while in - * this queue. - * @return this - */ - public TaskQueueUpdater setMaxReservedWorkers(final Integer maxReservedWorkers) { + public TaskQueueUpdater setMaxReservedWorkers( + final Integer maxReservedWorkers + ) { this.maxReservedWorkers = maxReservedWorkers; return this; } - /** - * TaskOrder will determine which order the Tasks will be assigned to Workers. - * Set this parameter to LIFO to assign most recently created Task first or FIFO - * to assign the oldest Task. Default is FIFO. [Click - * here](https://www.twilio.com/docs/api/taskrouter/last-first-out-lifo) to - * learn more.. - * - * @param taskOrder TaskOrder will determine which order the Tasks will be - * assigned to Workers. - * @return this - */ public TaskQueueUpdater setTaskOrder(final TaskQueue.TaskOrder taskOrder) { this.taskOrder = taskOrder; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated TaskQueue - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public TaskQueue update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueue update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TaskQueue update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return TaskQueue.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TaskQueue update(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskQueue content = TaskQueue.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (targetWorkers != null) { - request.addPostParam("TargetWorkers", targetWorkers); + Serializer.toString( + request, + "TargetWorkers", + targetWorkers, + ParameterType.URLENCODED + ); } if (reservationActivitySid != null) { - request.addPostParam("ReservationActivitySid", reservationActivitySid); + Serializer.toString( + request, + "ReservationActivitySid", + reservationActivitySid, + ParameterType.URLENCODED + ); } if (assignmentActivitySid != null) { - request.addPostParam("AssignmentActivitySid", assignmentActivitySid); + Serializer.toString( + request, + "AssignmentActivitySid", + assignmentActivitySid, + ParameterType.URLENCODED + ); } if (maxReservedWorkers != null) { - request.addPostParam("MaxReservedWorkers", maxReservedWorkers.toString()); + Serializer.toString( + request, + "MaxReservedWorkers", + maxReservedWorkers, + ParameterType.URLENCODED + ); } if (taskOrder != null) { - request.addPostParam("TaskOrder", taskOrder.toString()); + Serializer.toString( + request, + "TaskOrder", + taskOrder, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskReader.java index 495ed82ee2..e81292b042 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,20 +17,27 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.util.List; public class TaskReader extends Reader { - private final String pathWorkspaceSid; + + private String pathWorkspaceSid; private Integer priority; private List assignmentStatus; private String workflowSid; @@ -31,321 +45,323 @@ public class TaskReader extends Reader { private String taskQueueSid; private String taskQueueName; private String evaluateTaskAttributes; + private String routingTarget; private String ordering; private Boolean hasAddons; + private Long pageSize; - /** - * Construct a new TaskReader. - * - * @param pathWorkspaceSid The workspace_sid - */ public TaskReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Retrieve the list of all Tasks in the workspace with the specified priority.. - * - * @param priority Retrieve the list of all Tasks in the workspace with the - * specified priority. - * @return this - */ public TaskReader setPriority(final Integer priority) { this.priority = priority; return this; } - /** - * Returns the list of all Tasks in the workspace with the specified - * AssignmentStatus. Allowed AssignmentStatus values are pending, reserved, - * assigned, canceled, and completed.. - * - * @param assignmentStatus Returns the list of all Tasks in the workspace with - * the specified AssignmentStatus. - * @return this - */ public TaskReader setAssignmentStatus(final List assignmentStatus) { this.assignmentStatus = assignmentStatus; return this; } - /** - * Returns the list of all Tasks in the workspace with the specified - * AssignmentStatus. Allowed AssignmentStatus values are pending, reserved, - * assigned, canceled, and completed.. - * - * @param assignmentStatus Returns the list of all Tasks in the workspace with - * the specified AssignmentStatus. - * @return this - */ public TaskReader setAssignmentStatus(final String assignmentStatus) { return setAssignmentStatus(Promoter.listOfOne(assignmentStatus)); } - /** - * Returns the list of Tasks that are being controlled by the Workflow with the - * specified Sid value.. - * - * @param workflowSid Returns the list of Tasks that are being controlled by - * the Workflow with the specified Sid value. - * @return this - */ public TaskReader setWorkflowSid(final String workflowSid) { this.workflowSid = workflowSid; return this; } - /** - * Returns the list of Tasks that are being controlled by the Workflow with the - * specified FriendlyName value.. - * - * @param workflowName Returns the list of Tasks that are being controlled by - * the Workflow with the specified FriendlyName value. - * @return this - */ public TaskReader setWorkflowName(final String workflowName) { this.workflowName = workflowName; return this; } - /** - * Returns the list of Tasks that are currently waiting in the TaskQueue - * identified by the Sid specified.. - * - * @param taskQueueSid Returns the list of Tasks that are currently waiting in - * the TaskQueue identified by the Sid specified. - * @return this - */ public TaskReader setTaskQueueSid(final String taskQueueSid) { this.taskQueueSid = taskQueueSid; return this; } - /** - * Returns the list of Tasks that are currently waiting in the TaskQueue - * identified by the FriendlyName specified.. - * - * @param taskQueueName Returns the list of Tasks that are currently waiting in - * the TaskQueue identified by the FriendlyName specified. - * @return this - */ public TaskReader setTaskQueueName(final String taskQueueName) { this.taskQueueName = taskQueueName; return this; } - /** - * Provide a task attributes expression, and this will return tasks which match - * the attributes.. - * - * @param evaluateTaskAttributes Provide a task attributes expression, and this - * will return tasks which match the attributes. - * @return this - */ - public TaskReader setEvaluateTaskAttributes(final String evaluateTaskAttributes) { + public TaskReader setEvaluateTaskAttributes( + final String evaluateTaskAttributes + ) { this.evaluateTaskAttributes = evaluateTaskAttributes; return this; } - /** - * Use this parameter to control the order of the Tasks returned. The value - * should be passed in `Attribute:Order` format, where Attribute can be either - * `Priority` or `DateCreated` and Order can be either `asc` or `desc`. For - * example, `Priority:desc` returns Tasks ordered by Priority in descending - * order. To sort the Tasks by Priority and DateCreated pass - * `Priority:desc,DateCreated:asc`. By Default Tasks are returned sorted by - * DateCreated in ascending order.. - * - * @param ordering Use this parameter to control the order of the Tasks - * returned. - * @return this - */ + public TaskReader setRoutingTarget(final String routingTarget) { + this.routingTarget = routingTarget; + return this; + } + public TaskReader setOrdering(final String ordering) { this.ordering = ordering; return this; } - /** - * The has_addons. - * - * @param hasAddons The has_addons - * @return this - */ public TaskReader setHasAddons(final Boolean hasAddons) { this.hasAddons = hasAddons; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Task ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TaskReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Task ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "tasks", + response.getContent(), + Task.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Tasks"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Tasks", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Task ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "tasks", + response.getContent(), + Task.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Task read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "tasks", + response.getContent(), + Task.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Task Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Task read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "tasks", - response.getContent(), - Task.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (priority != null) { - request.addQueryParam("Priority", priority.toString()); + Serializer.toString( + request, + "Priority", + priority, + ParameterType.QUERY + ); } if (assignmentStatus != null) { - for (String prop : assignmentStatus) { - request.addQueryParam("AssignmentStatus", prop); + for (String param : assignmentStatus) { + Serializer.toString( + request, + "AssignmentStatus", + param, + ParameterType.QUERY + ); } } if (workflowSid != null) { - request.addQueryParam("WorkflowSid", workflowSid); + Serializer.toString( + request, + "WorkflowSid", + workflowSid, + ParameterType.QUERY + ); } if (workflowName != null) { - request.addQueryParam("WorkflowName", workflowName); + Serializer.toString( + request, + "WorkflowName", + workflowName, + ParameterType.QUERY + ); } if (taskQueueSid != null) { - request.addQueryParam("TaskQueueSid", taskQueueSid); + Serializer.toString( + request, + "TaskQueueSid", + taskQueueSid, + ParameterType.QUERY + ); } if (taskQueueName != null) { - request.addQueryParam("TaskQueueName", taskQueueName); + Serializer.toString( + request, + "TaskQueueName", + taskQueueName, + ParameterType.QUERY + ); } if (evaluateTaskAttributes != null) { - request.addQueryParam("EvaluateTaskAttributes", evaluateTaskAttributes); + Serializer.toString( + request, + "EvaluateTaskAttributes", + evaluateTaskAttributes, + ParameterType.QUERY + ); + } + + if (routingTarget != null) { + Serializer.toString( + request, + "RoutingTarget", + routingTarget, + ParameterType.QUERY + ); } if (ordering != null) { - request.addQueryParam("Ordering", ordering); + Serializer.toString( + request, + "Ordering", + ordering, + ParameterType.QUERY + ); } if (hasAddons != null) { - request.addQueryParam("HasAddons", hasAddons.toString()); + Serializer.toString( + request, + "HasAddons", + hasAddons, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskUpdater.java index 2524ab5110..d5772b00b4 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/TaskUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,154 +27,192 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class TaskUpdater extends Updater { - private final String pathWorkspaceSid; - private final String pathSid; + + private String pathWorkspaceSid; + private String pathSid; + private String ifMatch; private String attributes; private Task.Status assignmentStatus; private String reason; private Integer priority; private String taskChannel; + private ZonedDateTime virtualStartTime; - /** - * Construct a new TaskUpdater. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public TaskUpdater(final String pathWorkspaceSid, - final String pathSid) { + public TaskUpdater(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * The user-defined JSON data describing the custom attributes of this task.. - * - * @param attributes The user-defined JSON data describing the custom - * attributes of this task. - * @return this - */ public TaskUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * A 'pending' or 'reserved' Task may be canceled by posting - * AssignmentStatus='canceled'. Post AssignmentStatus='wrapping' to move Task to - * 'wrapup' state and AssignmentStatus='completed' to move a Task to 'completed' - * state.. - * - * @param assignmentStatus A 'pending' or 'reserved' Task may be canceled by - * posting AssignmentStatus='canceled'. - * @return this - */ public TaskUpdater setAssignmentStatus(final Task.Status assignmentStatus) { this.assignmentStatus = assignmentStatus; return this; } - /** - * This is only required if the Task is canceled or completed. This logs the - * reason the task was either canceled or completed and queues the task for - * deletion after 5 minutes.. - * - * @param reason This is only required if the Task is canceled or completed. - * @return this - */ public TaskUpdater setReason(final String reason) { this.reason = reason; return this; } - /** - * Override priority for the Task. When supplied, the Task will take on the - * given priority unless it matches a Workflow Target with a Priority set.. - * - * @param priority Override priority for the Task. - * @return this - */ public TaskUpdater setPriority(final Integer priority) { this.priority = priority; return this; } - /** - * The task_channel. - * - * @param taskChannel The task_channel - * @return this - */ public TaskUpdater setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Task - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Task update(final TwilioRestClient client) { + public TaskUpdater setVirtualStartTime( + final ZonedDateTime virtualStartTime + ) { + this.virtualStartTime = virtualStartTime; + return this; + } + + public TaskUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Tasks/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Tasks/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Task update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Task update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Task update(final TwilioRestClient client) { + Response response = makeRequest(client); return Task.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Task content = Task.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (assignmentStatus != null) { - request.addPostParam("AssignmentStatus", assignmentStatus.toString()); + Serializer.toString( + request, + "AssignmentStatus", + assignmentStatus, + ParameterType.URLENCODED + ); } if (reason != null) { - request.addPostParam("Reason", reason); + Serializer.toString( + request, + "Reason", + reason, + ParameterType.URLENCODED + ); } if (priority != null) { - request.addPostParam("Priority", priority.toString()); + Serializer.toString( + request, + "Priority", + priority, + ParameterType.URLENCODED + ); } if (taskChannel != null) { - request.addPostParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.URLENCODED + ); + } + + if (virtualStartTime != null) { + Serializer.toString( + request, + "VirtualStartTime", + virtualStartTime, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Worker.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Worker.java index 9e98360f1c..b65275bbad 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Worker.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Worker.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -11,97 +18,74 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Worker extends Resource { - private static final long serialVersionUID = 71992031157502L; - /** - * Create a WorkerReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @return WorkerReader capable of executing the read - */ - public static WorkerReader reader(final String pathWorkspaceSid) { - return new WorkerReader(pathWorkspaceSid); + public static WorkerCreator creator( + final String pathWorkspaceSid, + final String friendlyName + ) { + return new WorkerCreator(pathWorkspaceSid, friendlyName); } - /** - * Create a WorkerCreator to execute create. - * - * @param pathWorkspaceSid The workspace_sid - * @param friendlyName String representing user-friendly name for the Worker. - * @return WorkerCreator capable of executing the create - */ - public static WorkerCreator creator(final String pathWorkspaceSid, - final String friendlyName) { - return new WorkerCreator(pathWorkspaceSid, friendlyName); + public static WorkerDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { + return new WorkerDeleter(pathWorkspaceSid, pathSid); } - /** - * Create a WorkerFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return WorkerFetcher capable of executing the fetch - */ - public static WorkerFetcher fetcher(final String pathWorkspaceSid, - final String pathSid) { + public static WorkerFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { return new WorkerFetcher(pathWorkspaceSid, pathSid); } - /** - * Create a WorkerUpdater to execute update. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return WorkerUpdater capable of executing the update - */ - public static WorkerUpdater updater(final String pathWorkspaceSid, - final String pathSid) { - return new WorkerUpdater(pathWorkspaceSid, pathSid); + public static WorkerReader reader(final String pathWorkspaceSid) { + return new WorkerReader(pathWorkspaceSid); } - /** - * Create a WorkerDeleter to execute delete. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return WorkerDeleter capable of executing the delete - */ - public static WorkerDeleter deleter(final String pathWorkspaceSid, - final String pathSid) { - return new WorkerDeleter(pathWorkspaceSid, pathSid); + public static WorkerUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { + return new WorkerUpdater(pathWorkspaceSid, pathSid); } /** * Converts a JSON String into a Worker object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Worker object represented by the provided JSON */ - public static Worker fromJson(final String json, final ObjectMapper objectMapper) { + public static Worker fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Worker.class); @@ -115,12 +99,15 @@ public static Worker fromJson(final String json, final ObjectMapper objectMapper /** * Converts a JSON InputStream into a Worker object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Worker object represented by the provided JSON */ - public static Worker fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Worker fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Worker.class); @@ -131,178 +118,101 @@ public static Worker fromJson(final InputStream json, final ObjectMapper objectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final String activityName; + + @Getter private final String activitySid; + + @Getter private final String attributes; + + @Getter private final Boolean available; - private final DateTime dateCreated; - private final DateTime dateStatusChanged; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateStatusChanged; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter + private final Map links; + + @Getter private final String sid; - private final String workspaceSid; + + @Getter private final URI url; - private final Map links; + + @Getter + private final String workspaceSid; @JsonCreator - private Worker(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("activity_name") - final String activityName, - @JsonProperty("activity_sid") - final String activitySid, - @JsonProperty("attributes") - final String attributes, - @JsonProperty("available") - final Boolean available, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_status_changed") - final String dateStatusChanged, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("sid") - final String sid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { + private Worker( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("activity_name") final String activityName, + @JsonProperty("activity_sid") final String activitySid, + @JsonProperty("attributes") final String attributes, + @JsonProperty("available") final Boolean available, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_status_changed") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateStatusChanged, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.activityName = activityName; this.activitySid = activitySid; this.attributes = attributes; this.available = available; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateStatusChanged = DateConverter.iso8601DateTimeFromString(dateStatusChanged); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateStatusChanged = dateStatusChanged; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; + this.links = links; this.sid = sid; - this.workspaceSid = workspaceSid; this.url = url; - this.links = links; - } - - /** - * Returns The The ID of the account that owns this worker. - * - * @return The ID of the account that owns this worker - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The Filter by workers that are in a particular Activity by Friendly - * Name. - * - * @return Filter by workers that are in a particular Activity by Friendly Name - */ - public final String getActivityName() { - return this.activityName; - } - - /** - * Returns The Filter by workers that are in a particular Activity by SID. - * - * @return Filter by workers that are in a particular Activity by SID - */ - public final String getActivitySid() { - return this.activitySid; - } - - /** - * Returns The JSON object describing this worker.. - * - * @return JSON object describing this worker. - */ - public final String getAttributes() { - return this.attributes; - } - - /** - * Returns The Filter by workers that are available or unavailable.. - * - * @return Filter by workers that are available or unavailable. - */ - public final Boolean getAvailable() { - return this.available; - } - - /** - * Returns The DateTime this worker was created. - * - * @return DateTime this worker was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The DateTime of the last change to the Worker's activity.. - * - * @return DateTime of the last change to the Worker's activity. - */ - public final DateTime getDateStatusChanged() { - return this.dateStatusChanged; - } - - /** - * Returns The DateTime of the last update. - * - * @return DateTime of the last update - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Filter by a worker’s friendly name. - * - * @return Filter by a worker’s friendly name - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique ID of the worker. - * - * @return The unique ID of the worker - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The ID of the Workflow this worker is associated with. - * - * @return The ID of the Workflow this worker is associated with - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + this.workspaceSid = workspaceSid; } @Override @@ -316,55 +226,39 @@ public boolean equals(final Object o) { } Worker other = (Worker) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(activityName, other.activityName) && - Objects.equals(activitySid, other.activitySid) && - Objects.equals(attributes, other.attributes) && - Objects.equals(available, other.available) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateStatusChanged, other.dateStatusChanged) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(sid, other.sid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityName, other.activityName) && + Objects.equals(activitySid, other.activitySid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(available, other.available) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateStatusChanged, other.dateStatusChanged) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - activityName, - activitySid, - attributes, - available, - dateCreated, - dateStatusChanged, - dateUpdated, - friendlyName, - sid, - workspaceSid, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("activityName", activityName) - .add("activitySid", activitySid) - .add("attributes", attributes) - .add("available", available) - .add("dateCreated", dateCreated) - .add("dateStatusChanged", dateStatusChanged) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("sid", sid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + activityName, + activitySid, + attributes, + available, + dateCreated, + dateStatusChanged, + dateUpdated, + friendlyName, + links, + sid, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerCreator.java index e6d3a4049f..7465d26dcf 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,106 +27,127 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkerCreator extends Creator { - private final String pathWorkspaceSid; - private final String friendlyName; + + private String pathWorkspaceSid; + private String friendlyName; private String activitySid; private String attributes; - /** - * Construct a new WorkerCreator. - * - * @param pathWorkspaceSid The workspace_sid - * @param friendlyName String representing user-friendly name for the Worker. - */ - public WorkerCreator(final String pathWorkspaceSid, - final String friendlyName) { + public WorkerCreator( + final String pathWorkspaceSid, + final String friendlyName + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; } - /** - * A valid Activity describing the worker's initial state. See Activities for - * more information. If not provided, new Workers will be use the - * DefaultActivitySid configured on the Workspace.. - * - * @param activitySid A valid Activity describing the worker's initial state. - * @return this - */ + public WorkerCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + public WorkerCreator setActivitySid(final String activitySid) { this.activitySid = activitySid; return this; } - /** - * JSON object describing this worker. For example: `{ 'email: 'Bob@foo.com', - * 'phone': '8675309' }`. This data will be passed to the Assignment Callback - * URL whenever TaskRouter assigns a Task to this worker. Defaults to {}.. - * - * @param attributes JSON object describing this worker. - * @return this - */ public WorkerCreator setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Worker - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Worker create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workers"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Worker creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Worker create(final TwilioRestClient client) { + Response response = makeRequest(client); return Worker.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Worker content = Worker.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (activitySid != null) { - request.addPostParam("ActivitySid", activitySid); + Serializer.toString( + request, + "ActivitySid", + activitySid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerDeleter.java index 810c658fa8..d5c444f16e 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerDeleter.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +26,99 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class WorkerDeleter extends Deleter { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new WorkerDeleter. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public WorkerDeleter(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + private String ifMatch; + + public WorkerDeleter(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + public WorkerDeleter setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathSid + "", - client.getRegion() + path ); + addHeaderParams(request); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Worker delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER ); } - - return response.getStatusCode() == 204; } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerFetcher.java index 0ff4aceacb..90b69b870b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkerFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new WorkerFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public WorkerFetcher(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public WorkerFetcher(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Worker - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Worker fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Worker fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Worker fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Worker.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Worker content = Worker.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerReader.java index 6e7161ef56..84e825ef5a 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,17 +17,25 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkerReader extends Reader { - private final String pathWorkspaceSid; + + private String pathWorkspaceSid; private String activityName; private String activitySid; private String available; @@ -28,260 +43,287 @@ public class WorkerReader extends Reader { private String targetWorkersExpression; private String taskQueueName; private String taskQueueSid; + private String ordering; + private Long pageSize; - /** - * Construct a new WorkerReader. - * - * @param pathWorkspaceSid The workspace_sid - */ public WorkerReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter by workers that are in a particular Activity by Friendly Name. - * - * @param activityName Filter by workers that are in a particular Activity by - * Friendly Name - * @return this - */ public WorkerReader setActivityName(final String activityName) { this.activityName = activityName; return this; } - /** - * Filter by workers that are in a particular Activity by SID. - * - * @param activitySid Filter by workers that are in a particular Activity by SID - * @return this - */ public WorkerReader setActivitySid(final String activitySid) { this.activitySid = activitySid; return this; } - /** - * Filter by workers that are available or unavailable. (Note: This can be - * ‘true’, ‘1’’ or ‘yes’ to indicate a true value. All other values will - * represent false). - * - * @param available Filter by workers that are available or unavailable. - * @return this - */ public WorkerReader setAvailable(final String available) { this.available = available; return this; } - /** - * Filter by a worker’s friendly name. - * - * @param friendlyName Filter by a worker’s friendly name - * @return this - */ public WorkerReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Filter by workers that would match an expression on a TaskQueue. This is - * helpful for debugging which workers would match a potential queue.. - * - * @param targetWorkersExpression Filter by workers that would match an - * expression on a TaskQueue. - * @return this - */ - public WorkerReader setTargetWorkersExpression(final String targetWorkersExpression) { + public WorkerReader setTargetWorkersExpression( + final String targetWorkersExpression + ) { this.targetWorkersExpression = targetWorkersExpression; return this; } - /** - * Filter by workers that are eligible for a TaskQueue by Friendly Name. - * - * @param taskQueueName Filter by workers that are eligible for a TaskQueue by - * Friendly Name - * @return this - */ public WorkerReader setTaskQueueName(final String taskQueueName) { this.taskQueueName = taskQueueName; return this; } - /** - * Filter by workers that are eligible for a TaskQueue by SID. - * - * @param taskQueueSid Filter by workers that are eligible for a TaskQueue by - * SID - * @return this - */ public WorkerReader setTaskQueueSid(final String taskQueueSid) { this.taskQueueSid = taskQueueSid; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Worker ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public WorkerReader setOrdering(final String ordering) { + this.ordering = ordering; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Worker ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public WorkerReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "workers", + response.getContent(), + Worker.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workers"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Worker ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "workers", + response.getContent(), + Worker.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Worker read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "workers", + response.getContent(), + Worker.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Worker Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Worker read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "workers", - response.getContent(), - Worker.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (activityName != null) { - request.addQueryParam("ActivityName", activityName); + Serializer.toString( + request, + "ActivityName", + activityName, + ParameterType.QUERY + ); } if (activitySid != null) { - request.addQueryParam("ActivitySid", activitySid); + Serializer.toString( + request, + "ActivitySid", + activitySid, + ParameterType.QUERY + ); } if (available != null) { - request.addQueryParam("Available", available); + Serializer.toString( + request, + "Available", + available, + ParameterType.QUERY + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (targetWorkersExpression != null) { - request.addQueryParam("TargetWorkersExpression", targetWorkersExpression); + Serializer.toString( + request, + "TargetWorkersExpression", + targetWorkersExpression, + ParameterType.QUERY + ); } if (taskQueueName != null) { - request.addQueryParam("TaskQueueName", taskQueueName); + Serializer.toString( + request, + "TaskQueueName", + taskQueueName, + ParameterType.QUERY + ); } if (taskQueueSid != null) { - request.addQueryParam("TaskQueueSid", taskQueueSid); + Serializer.toString( + request, + "TaskQueueSid", + taskQueueSid, + ParameterType.QUERY + ); + } + + if (ordering != null) { + Serializer.toString( + request, + "Ordering", + ordering, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerUpdater.java index 17c895ffcb..666d5e2067 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkerUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,114 +27,161 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkerUpdater extends Updater { - private final String pathWorkspaceSid; - private final String pathSid; + + private String pathWorkspaceSid; + private String pathSid; + private String ifMatch; private String activitySid; private String attributes; private String friendlyName; + private Boolean rejectPendingReservations; - /** - * Construct a new WorkerUpdater. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public WorkerUpdater(final String pathWorkspaceSid, - final String pathSid) { + public WorkerUpdater(final String pathWorkspaceSid, final String pathSid) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * The activity_sid. - * - * @param activitySid The activity_sid - * @return this - */ public WorkerUpdater setActivitySid(final String activitySid) { this.activitySid = activitySid; return this; } - /** - * The attributes. - * - * @param attributes The attributes - * @return this - */ public WorkerUpdater setAttributes(final String attributes) { this.attributes = attributes; return this; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public WorkerUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Worker - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Worker update(final TwilioRestClient client) { + public WorkerUpdater setRejectPendingReservations( + final Boolean rejectPendingReservations + ) { + this.rejectPendingReservations = rejectPendingReservations; + return this; + } + + public WorkerUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workers/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Worker update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Worker update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Worker update(final TwilioRestClient client) { + Response response = makeRequest(client); return Worker.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Worker content = Worker.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (activitySid != null) { - request.addPostParam("ActivitySid", activitySid); + Serializer.toString( + request, + "ActivitySid", + activitySid, + ParameterType.URLENCODED + ); } if (attributes != null) { - request.addPostParam("Attributes", attributes); + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (rejectPendingReservations != null) { + Serializer.toString( + request, + "RejectPendingReservations", + rejectPendingReservations, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Workflow.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Workflow.java index b79dd77ac2..83da0431b1 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Workflow.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/Workflow.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -11,101 +18,79 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Workflow extends Resource { - private static final long serialVersionUID = 205559746169581L; - /** - * Create a WorkflowFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return WorkflowFetcher capable of executing the fetch - */ - public static WorkflowFetcher fetcher(final String pathWorkspaceSid, - final String pathSid) { - return new WorkflowFetcher(pathWorkspaceSid, pathSid); + public static WorkflowCreator creator( + final String pathWorkspaceSid, + final String friendlyName, + final String configuration + ) { + return new WorkflowCreator( + pathWorkspaceSid, + friendlyName, + configuration + ); } - /** - * Create a WorkflowUpdater to execute update. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return WorkflowUpdater capable of executing the update - */ - public static WorkflowUpdater updater(final String pathWorkspaceSid, - final String pathSid) { - return new WorkflowUpdater(pathWorkspaceSid, pathSid); + public static WorkflowDeleter deleter( + final String pathWorkspaceSid, + final String pathSid + ) { + return new WorkflowDeleter(pathWorkspaceSid, pathSid); } - /** - * Create a WorkflowDeleter to execute delete. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - * @return WorkflowDeleter capable of executing the delete - */ - public static WorkflowDeleter deleter(final String pathWorkspaceSid, - final String pathSid) { - return new WorkflowDeleter(pathWorkspaceSid, pathSid); + public static WorkflowFetcher fetcher( + final String pathWorkspaceSid, + final String pathSid + ) { + return new WorkflowFetcher(pathWorkspaceSid, pathSid); } - /** - * Create a WorkflowReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @return WorkflowReader capable of executing the read - */ public static WorkflowReader reader(final String pathWorkspaceSid) { return new WorkflowReader(pathWorkspaceSid); } - /** - * Create a WorkflowCreator to execute create. - * - * @param pathWorkspaceSid The workspace_sid - * @param friendlyName A string representing a human readable name for this - * Workflow. - * @param configuration JSON document configuring the rules for this Workflow. - * @return WorkflowCreator capable of executing the create - */ - public static WorkflowCreator creator(final String pathWorkspaceSid, - final String friendlyName, - final String configuration) { - return new WorkflowCreator(pathWorkspaceSid, friendlyName, configuration); + public static WorkflowUpdater updater( + final String pathWorkspaceSid, + final String pathSid + ) { + return new WorkflowUpdater(pathWorkspaceSid, pathSid); } /** - * Converts a JSON String into a Workflow object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Workflow object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Workflow object represented by the provided JSON */ - public static Workflow fromJson(final String json, final ObjectMapper objectMapper) { + public static Workflow fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Workflow.class); @@ -119,12 +104,15 @@ public static Workflow fromJson(final String json, final ObjectMapper objectMapp /** * Converts a JSON InputStream into a Workflow object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Workflow object represented by the provided JSON */ - public static Workflow fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Workflow fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Workflow.class); @@ -135,183 +123,102 @@ public static Workflow fromJson(final InputStream json, final ObjectMapper objec } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final URI assignmentCallbackUrl; + + @Getter private final String configuration; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String documentContentType; + + @Getter private final URI fallbackAssignmentCallbackUrl; + + @Getter private final String friendlyName; + + @Getter + private final Map links; + + @Getter private final String sid; + + @Getter private final Integer taskReservationTimeout; - private final String workspaceSid; + + @Getter private final URI url; - private final Map links; + + @Getter + private final String workspaceSid; @JsonCreator - private Workflow(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("assignment_callback_url") - final URI assignmentCallbackUrl, - @JsonProperty("configuration") - final String configuration, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("document_content_type") - final String documentContentType, - @JsonProperty("fallback_assignment_callback_url") - final URI fallbackAssignmentCallbackUrl, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("sid") - final String sid, - @JsonProperty("task_reservation_timeout") - final Integer taskReservationTimeout, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { + private Workflow( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "assignment_callback_url" + ) final URI assignmentCallbackUrl, + @JsonProperty("configuration") final String configuration, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("document_content_type") final String documentContentType, + @JsonProperty( + "fallback_assignment_callback_url" + ) final URI fallbackAssignmentCallbackUrl, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("sid") final String sid, + @JsonProperty( + "task_reservation_timeout" + ) final Integer taskReservationTimeout, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.assignmentCallbackUrl = assignmentCallbackUrl; this.configuration = configuration; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.documentContentType = documentContentType; this.fallbackAssignmentCallbackUrl = fallbackAssignmentCallbackUrl; this.friendlyName = friendlyName; + this.links = links; this.sid = sid; this.taskReservationTimeout = taskReservationTimeout; - this.workspaceSid = workspaceSid; this.url = url; - this.links = links; - } - - /** - * Returns The The ID of the account that owns this Workflow. - * - * @return The ID of the account that owns this Workflow - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The URL that will be called whenever a task managed by this - * Workflow is assigned to a Worker.. - * - * @return The URL that will be called whenever a task managed by this Workflow - * is assigned to a Worker. - */ - public final URI getAssignmentCallbackUrl() { - return this.assignmentCallbackUrl; - } - - /** - * Returns The JSON document configuring the rules for this Workflow.. - * - * @return JSON document configuring the rules for this Workflow. - */ - public final String getConfiguration() { - return this.configuration; - } - - /** - * Returns The The date this workflow was created.. - * - * @return The date this workflow was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this workflow was last updated.. - * - * @return The date this workflow was last updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The document_content_type. - * - * @return The document_content_type - */ - public final String getDocumentContentType() { - return this.documentContentType; - } - - /** - * Returns The If the request to the AssignmentCallbackUrl fails, the assignment - * callback will be made to this URL.. - * - * @return If the request to the AssignmentCallbackUrl fails, the assignment - * callback will be made to this URL. - */ - public final URI getFallbackAssignmentCallbackUrl() { - return this.fallbackAssignmentCallbackUrl; - } - - /** - * Returns The Human readable description of this Workflow. - * - * @return Human readable description of this Workflow - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The unique ID of the Workflow. - * - * @return The unique ID of the Workflow - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The Determines how long TaskRouter will wait for a confirmation - * response from your application after assigning a Task to a worker.. - * - * @return Determines how long TaskRouter will wait for a confirmation response - * from your application after assigning a Task to a worker. - */ - public final Integer getTaskReservationTimeout() { - return this.taskReservationTimeout; - } - - /** - * Returns The The ID of the Workspace that contains this Workflow. - * - * @return The ID of the Workspace that contains this Workflow - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + this.workspaceSid = workspaceSid; } @Override @@ -325,55 +232,48 @@ public boolean equals(final Object o) { } Workflow other = (Workflow) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(assignmentCallbackUrl, other.assignmentCallbackUrl) && - Objects.equals(configuration, other.configuration) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(documentContentType, other.documentContentType) && - Objects.equals(fallbackAssignmentCallbackUrl, other.fallbackAssignmentCallbackUrl) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(sid, other.sid) && - Objects.equals(taskReservationTimeout, other.taskReservationTimeout) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + assignmentCallbackUrl, + other.assignmentCallbackUrl + ) && + Objects.equals(configuration, other.configuration) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(documentContentType, other.documentContentType) && + Objects.equals( + fallbackAssignmentCallbackUrl, + other.fallbackAssignmentCallbackUrl + ) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(sid, other.sid) && + Objects.equals( + taskReservationTimeout, + other.taskReservationTimeout + ) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - assignmentCallbackUrl, - configuration, - dateCreated, - dateUpdated, - documentContentType, - fallbackAssignmentCallbackUrl, - friendlyName, - sid, - taskReservationTimeout, - workspaceSid, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("assignmentCallbackUrl", assignmentCallbackUrl) - .add("configuration", configuration) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("documentContentType", documentContentType) - .add("fallbackAssignmentCallbackUrl", fallbackAssignmentCallbackUrl) - .add("friendlyName", friendlyName) - .add("sid", sid) - .add("taskReservationTimeout", taskReservationTimeout) - .add("workspaceSid", workspaceSid) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + assignmentCallbackUrl, + configuration, + dateCreated, + dateUpdated, + documentContentType, + fallbackAssignmentCallbackUrl, + friendlyName, + links, + sid, + taskReservationTimeout, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowCreator.java index 5d2a9052e9..11c512998c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowCreator.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,169 +28,185 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class WorkflowCreator extends Creator { - private final String pathWorkspaceSid; - private final String friendlyName; - private final String configuration; + + private String pathWorkspaceSid; + private String friendlyName; + private String configuration; private URI assignmentCallbackUrl; private URI fallbackAssignmentCallbackUrl; private Integer taskReservationTimeout; - /** - * Construct a new WorkflowCreator. - * - * @param pathWorkspaceSid The workspace_sid - * @param friendlyName A string representing a human readable name for this - * Workflow. - * @param configuration JSON document configuring the rules for this Workflow. - */ - public WorkflowCreator(final String pathWorkspaceSid, - final String friendlyName, - final String configuration) { + public WorkflowCreator( + final String pathWorkspaceSid, + final String friendlyName, + final String configuration + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.friendlyName = friendlyName; this.configuration = configuration; } - /** - * A valid URL for the application that will process task assignment events. See - * [Handling Task Assignment - * Callback](https://www.twilio.com/docs/api/taskrouter/handling-assignment-callbacks) for more details.. - * - * @param assignmentCallbackUrl A valid URL for the application that will - * process task assignment events. - * @return this - */ - public WorkflowCreator setAssignmentCallbackUrl(final URI assignmentCallbackUrl) { + public WorkflowCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public WorkflowCreator setConfiguration(final String configuration) { + this.configuration = configuration; + return this; + } + + public WorkflowCreator setAssignmentCallbackUrl( + final URI assignmentCallbackUrl + ) { this.assignmentCallbackUrl = assignmentCallbackUrl; return this; } - /** - * A valid URL for the application that will process task assignment events. See - * [Handling Task Assignment - * Callback](https://www.twilio.com/docs/api/taskrouter/handling-assignment-callbacks) for more details.. - * - * @param assignmentCallbackUrl A valid URL for the application that will - * process task assignment events. - * @return this - */ - public WorkflowCreator setAssignmentCallbackUrl(final String assignmentCallbackUrl) { - return setAssignmentCallbackUrl(Promoter.uriFromString(assignmentCallbackUrl)); + public WorkflowCreator setAssignmentCallbackUrl( + final String assignmentCallbackUrl + ) { + return setAssignmentCallbackUrl( + Promoter.uriFromString(assignmentCallbackUrl) + ); } - /** - * If the request to the AssignmentCallbackUrl fails, the assignment callback - * will be made to this URL.. - * - * @param fallbackAssignmentCallbackUrl If the request to the - * AssignmentCallbackUrl fails, the - * assignment callback will be made to this - * URL. - * @return this - */ - public WorkflowCreator setFallbackAssignmentCallbackUrl(final URI fallbackAssignmentCallbackUrl) { + public WorkflowCreator setFallbackAssignmentCallbackUrl( + final URI fallbackAssignmentCallbackUrl + ) { this.fallbackAssignmentCallbackUrl = fallbackAssignmentCallbackUrl; return this; } - /** - * If the request to the AssignmentCallbackUrl fails, the assignment callback - * will be made to this URL.. - * - * @param fallbackAssignmentCallbackUrl If the request to the - * AssignmentCallbackUrl fails, the - * assignment callback will be made to this - * URL. - * @return this - */ - public WorkflowCreator setFallbackAssignmentCallbackUrl(final String fallbackAssignmentCallbackUrl) { - return setFallbackAssignmentCallbackUrl(Promoter.uriFromString(fallbackAssignmentCallbackUrl)); + public WorkflowCreator setFallbackAssignmentCallbackUrl( + final String fallbackAssignmentCallbackUrl + ) { + return setFallbackAssignmentCallbackUrl( + Promoter.uriFromString(fallbackAssignmentCallbackUrl) + ); } - /** - * An integer value controlling how long in seconds TaskRouter will wait for a - * confirmation response from your application after assigning a Task to a - * worker. See Task Assignment Callback for more information. Defaults to 120 - * seconds. Maximum value is 86400 (24 hours). - * - * @param taskReservationTimeout An integer value controlling how long in - * seconds TaskRouter will wait for a confirmation - * response from your application after assigning - * a Task to a worker. - * @return this - */ - public WorkflowCreator setTaskReservationTimeout(final Integer taskReservationTimeout) { + public WorkflowCreator setTaskReservationTimeout( + final Integer taskReservationTimeout + ) { this.taskReservationTimeout = taskReservationTimeout; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Workflow - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Workflow create(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workflows"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workflows", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Workflow creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Workflow create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Workflow.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Workflow content = Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (configuration != null) { - request.addPostParam("Configuration", configuration); + Serializer.toString( + request, + "Configuration", + configuration, + ParameterType.URLENCODED + ); } if (assignmentCallbackUrl != null) { - request.addPostParam("AssignmentCallbackUrl", assignmentCallbackUrl.toString()); + Serializer.toString( + request, + "AssignmentCallbackUrl", + assignmentCallbackUrl, + ParameterType.URLENCODED + ); } if (fallbackAssignmentCallbackUrl != null) { - request.addPostParam("FallbackAssignmentCallbackUrl", fallbackAssignmentCallbackUrl.toString()); + Serializer.toString( + request, + "FallbackAssignmentCallbackUrl", + fallbackAssignmentCallbackUrl, + ParameterType.URLENCODED + ); } if (taskReservationTimeout != null) { - request.addPostParam("TaskReservationTimeout", taskReservationTimeout.toString()); + Serializer.toString( + request, + "TaskReservationTimeout", + taskReservationTimeout, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowDeleter.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowDeleter.java index c9082f67a3..f3151748d2 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowDeleter.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,84 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class WorkflowDeleter extends Deleter { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new WorkflowDeleter. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public WorkflowDeleter(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public WorkflowDeleter( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workflows/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Workflow delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowFetcher.java index 3939e3a889..9fd90bdeb0 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,83 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkflowFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathSid; - /** - * Construct a new WorkflowFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public WorkflowFetcher(final String pathWorkspaceSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathSid; + + public WorkflowFetcher( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Workflow - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Workflow fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workflows/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Workflow fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Workflow.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Workflow fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Workflow content = Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowReader.java index fca3e51faf..f836b4985b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -10,176 +17,210 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkflowReader extends Reader { - private final String pathWorkspaceSid; + + private String pathWorkspaceSid; private String friendlyName; + private Long pageSize; - /** - * Construct a new WorkflowReader. - * - * @param pathWorkspaceSid The workspace_sid - */ public WorkflowReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Human readable description of this Workflow (for example "Customer Support" - * or "2014 Election Campaign"). - * - * @param friendlyName Human readable description of this Workflow - * @return this - */ public WorkflowReader setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Workflow ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public WorkflowReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Workflow ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "workflows", + response.getContent(), + Workflow.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workflows"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workflows", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Workflow ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "workflows", + response.getContent(), + Workflow.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Workflow read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "workflows", + response.getContent(), + Workflow.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Workflow Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Workflow read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "workflows", - response.getContent(), - Workflow.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowUpdater.java index b125078103..3f127099eb 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkflowUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,191 +28,200 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class WorkflowUpdater extends Updater { - private final String pathWorkspaceSid; - private final String pathSid; + + private String pathWorkspaceSid; + private String pathSid; private String friendlyName; private URI assignmentCallbackUrl; private URI fallbackAssignmentCallbackUrl; private String configuration; private Integer taskReservationTimeout; + private String reEvaluateTasks; - /** - * Construct a new WorkflowUpdater. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathSid The sid - */ - public WorkflowUpdater(final String pathWorkspaceSid, - final String pathSid) { + public WorkflowUpdater( + final String pathWorkspaceSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathSid = pathSid; } - /** - * A string representing a human readable name for this Workflow. Examples - * include 'Customer Support' or 'Sales Team'.. - * - * @param friendlyName A string representing a human readable name for this - * Workflow. - * @return this - */ public WorkflowUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * A valid URL for the application that will process task assignment events. See - * [Handling Task Assignment - * Callback](https://www.twilio.com/docs/api/taskrouter/handling-assignment-callbacks) for more details.. - * - * @param assignmentCallbackUrl A valid URL for the application that will - * process task assignment events. - * @return this - */ - public WorkflowUpdater setAssignmentCallbackUrl(final URI assignmentCallbackUrl) { + public WorkflowUpdater setAssignmentCallbackUrl( + final URI assignmentCallbackUrl + ) { this.assignmentCallbackUrl = assignmentCallbackUrl; return this; } - /** - * A valid URL for the application that will process task assignment events. See - * [Handling Task Assignment - * Callback](https://www.twilio.com/docs/api/taskrouter/handling-assignment-callbacks) for more details.. - * - * @param assignmentCallbackUrl A valid URL for the application that will - * process task assignment events. - * @return this - */ - public WorkflowUpdater setAssignmentCallbackUrl(final String assignmentCallbackUrl) { - return setAssignmentCallbackUrl(Promoter.uriFromString(assignmentCallbackUrl)); + public WorkflowUpdater setAssignmentCallbackUrl( + final String assignmentCallbackUrl + ) { + return setAssignmentCallbackUrl( + Promoter.uriFromString(assignmentCallbackUrl) + ); } - /** - * If the request to the AssignmentCallbackUrl fails, the assignment callback - * will be made to this URL.. - * - * @param fallbackAssignmentCallbackUrl If the request to the - * AssignmentCallbackUrl fails, the - * assignment callback will be made to this - * URL. - * @return this - */ - public WorkflowUpdater setFallbackAssignmentCallbackUrl(final URI fallbackAssignmentCallbackUrl) { + public WorkflowUpdater setFallbackAssignmentCallbackUrl( + final URI fallbackAssignmentCallbackUrl + ) { this.fallbackAssignmentCallbackUrl = fallbackAssignmentCallbackUrl; return this; } - /** - * If the request to the AssignmentCallbackUrl fails, the assignment callback - * will be made to this URL.. - * - * @param fallbackAssignmentCallbackUrl If the request to the - * AssignmentCallbackUrl fails, the - * assignment callback will be made to this - * URL. - * @return this - */ - public WorkflowUpdater setFallbackAssignmentCallbackUrl(final String fallbackAssignmentCallbackUrl) { - return setFallbackAssignmentCallbackUrl(Promoter.uriFromString(fallbackAssignmentCallbackUrl)); + public WorkflowUpdater setFallbackAssignmentCallbackUrl( + final String fallbackAssignmentCallbackUrl + ) { + return setFallbackAssignmentCallbackUrl( + Promoter.uriFromString(fallbackAssignmentCallbackUrl) + ); } - /** - * JSON document configuring the rules for this Workflow. See [Configuring - * Workflows](https://www.twilio.com/docs/api/taskrouter/workflow-configuration) - * for more information.. - * - * @param configuration JSON document configuring the rules for this Workflow. - * @return this - */ public WorkflowUpdater setConfiguration(final String configuration) { this.configuration = configuration; return this; } - /** - * An integer value controlling how long in seconds TaskRouter will wait for a - * confirmation response from your application after assigning a Task to a - * worker. Defaults to 120 seconds. Maximum value is 86400 (24 hours). - * - * @param taskReservationTimeout An integer value controlling how long in - * seconds TaskRouter will wait for a confirmation - * response from your application after assigning - * a Task to a worker. - * @return this - */ - public WorkflowUpdater setTaskReservationTimeout(final Integer taskReservationTimeout) { + public WorkflowUpdater setTaskReservationTimeout( + final Integer taskReservationTimeout + ) { this.taskReservationTimeout = taskReservationTimeout; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Workflow - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Workflow update(final TwilioRestClient client) { + public WorkflowUpdater setReEvaluateTasks(final String reEvaluateTasks) { + this.reEvaluateTasks = reEvaluateTasks; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workflows/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workflows/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Workflow update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Workflow update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Workflow.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Workflow update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Workflow content = Workflow.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (assignmentCallbackUrl != null) { - request.addPostParam("AssignmentCallbackUrl", assignmentCallbackUrl.toString()); + Serializer.toString( + request, + "AssignmentCallbackUrl", + assignmentCallbackUrl, + ParameterType.URLENCODED + ); } if (fallbackAssignmentCallbackUrl != null) { - request.addPostParam("FallbackAssignmentCallbackUrl", fallbackAssignmentCallbackUrl.toString()); + Serializer.toString( + request, + "FallbackAssignmentCallbackUrl", + fallbackAssignmentCallbackUrl, + ParameterType.URLENCODED + ); } if (configuration != null) { - request.addPostParam("Configuration", configuration); + Serializer.toString( + request, + "Configuration", + configuration, + ParameterType.URLENCODED + ); } if (taskReservationTimeout != null) { - request.addPostParam("TaskReservationTimeout", taskReservationTimeout.toString()); + Serializer.toString( + request, + "TaskReservationTimeout", + taskReservationTimeout, + ParameterType.URLENCODED + ); + } + + if (reEvaluateTasks != null) { + Serializer.toString( + request, + "ReEvaluateTasks", + reEvaluateTasks, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatistics.java index 0b462e480a..9246f8bd88 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -11,54 +18,53 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkspaceCumulativeStatistics extends Resource { - private static final long serialVersionUID = 278709267705066L; - /** - * Create a WorkspaceCumulativeStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @return WorkspaceCumulativeStatisticsFetcher capable of executing the fetch - */ - public static WorkspaceCumulativeStatisticsFetcher fetcher(final String pathWorkspaceSid) { + public static WorkspaceCumulativeStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkspaceCumulativeStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkspaceCumulativeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON String into a WorkspaceCumulativeStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkspaceCumulativeStatistics object represented by the provided JSON */ - public static WorkspaceCumulativeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkspaceCumulativeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkspaceCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkspaceCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -67,17 +73,23 @@ public static WorkspaceCumulativeStatistics fromJson(final String json, final Ob } /** - * Converts a JSON InputStream into a WorkspaceCumulativeStatistics object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkspaceCumulativeStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkspaceCumulativeStatistics object represented by the provided JSON */ - public static WorkspaceCumulativeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkspaceCumulativeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkspaceCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkspaceCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -85,284 +97,154 @@ public static WorkspaceCumulativeStatistics fromJson(final InputStream json, fin } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final Integer avgTaskAcceptanceTime; - private final DateTime startTime; - private final DateTime endTime; - private final Integer reservationsCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; + + @Getter private final Integer reservationsAccepted; - private final Integer reservationsRejected; - private final Integer reservationsTimedOut; + + @Getter private final Integer reservationsCanceled; + + @Getter + private final Integer reservationsCreated; + + @Getter + private final Integer reservationsRejected; + + @Getter private final Integer reservationsRescinded; - private final Map splitByWaitTime; - private final Map waitDurationUntilAccepted; - private final Map waitDurationUntilCanceled; + + @Getter + private final Integer reservationsTimedOut; + + @Getter + private final Object splitByWaitTime; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime startTime; + + @Getter private final Integer tasksCanceled; + + @Getter private final Integer tasksCompleted; + + @Getter private final Integer tasksCreated; + + @Getter private final Integer tasksDeleted; + + @Getter private final Integer tasksMoved; + + @Getter private final Integer tasksTimedOutInWorkflow; - private final String workspaceSid; + + @Getter private final URI url; + @Getter + private final Object waitDurationUntilAccepted; + + @Getter + private final Object waitDurationUntilCanceled; + + @Getter + private final String workspaceSid; + @JsonCreator - private WorkspaceCumulativeStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("avg_task_acceptance_time") - final Integer avgTaskAcceptanceTime, - @JsonProperty("start_time") - final String startTime, - @JsonProperty("end_time") - final String endTime, - @JsonProperty("reservations_created") - final Integer reservationsCreated, - @JsonProperty("reservations_accepted") - final Integer reservationsAccepted, - @JsonProperty("reservations_rejected") - final Integer reservationsRejected, - @JsonProperty("reservations_timed_out") - final Integer reservationsTimedOut, - @JsonProperty("reservations_canceled") - final Integer reservationsCanceled, - @JsonProperty("reservations_rescinded") - final Integer reservationsRescinded, - @JsonProperty("split_by_wait_time") - final Map splitByWaitTime, - @JsonProperty("wait_duration_until_accepted") - final Map waitDurationUntilAccepted, - @JsonProperty("wait_duration_until_canceled") - final Map waitDurationUntilCanceled, - @JsonProperty("tasks_canceled") - final Integer tasksCanceled, - @JsonProperty("tasks_completed") - final Integer tasksCompleted, - @JsonProperty("tasks_created") - final Integer tasksCreated, - @JsonProperty("tasks_deleted") - final Integer tasksDeleted, - @JsonProperty("tasks_moved") - final Integer tasksMoved, - @JsonProperty("tasks_timed_out_in_workflow") - final Integer tasksTimedOutInWorkflow, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private WorkspaceCumulativeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "avg_task_acceptance_time" + ) final Integer avgTaskAcceptanceTime, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty( + "reservations_accepted" + ) final Integer reservationsAccepted, + @JsonProperty( + "reservations_canceled" + ) final Integer reservationsCanceled, + @JsonProperty("reservations_created") final Integer reservationsCreated, + @JsonProperty( + "reservations_rejected" + ) final Integer reservationsRejected, + @JsonProperty( + "reservations_rescinded" + ) final Integer reservationsRescinded, + @JsonProperty( + "reservations_timed_out" + ) final Integer reservationsTimedOut, + @JsonProperty("split_by_wait_time") final Object splitByWaitTime, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime startTime, + @JsonProperty("tasks_canceled") final Integer tasksCanceled, + @JsonProperty("tasks_completed") final Integer tasksCompleted, + @JsonProperty("tasks_created") final Integer tasksCreated, + @JsonProperty("tasks_deleted") final Integer tasksDeleted, + @JsonProperty("tasks_moved") final Integer tasksMoved, + @JsonProperty( + "tasks_timed_out_in_workflow" + ) final Integer tasksTimedOutInWorkflow, + @JsonProperty("url") final URI url, + @JsonProperty( + "wait_duration_until_accepted" + ) final Object waitDurationUntilAccepted, + @JsonProperty( + "wait_duration_until_canceled" + ) final Object waitDurationUntilCanceled, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.avgTaskAcceptanceTime = avgTaskAcceptanceTime; - this.startTime = DateConverter.iso8601DateTimeFromString(startTime); - this.endTime = DateConverter.iso8601DateTimeFromString(endTime); - this.reservationsCreated = reservationsCreated; + this.endTime = endTime; this.reservationsAccepted = reservationsAccepted; - this.reservationsRejected = reservationsRejected; - this.reservationsTimedOut = reservationsTimedOut; this.reservationsCanceled = reservationsCanceled; + this.reservationsCreated = reservationsCreated; + this.reservationsRejected = reservationsRejected; this.reservationsRescinded = reservationsRescinded; + this.reservationsTimedOut = reservationsTimedOut; this.splitByWaitTime = splitByWaitTime; - this.waitDurationUntilAccepted = waitDurationUntilAccepted; - this.waitDurationUntilCanceled = waitDurationUntilCanceled; + this.startTime = startTime; this.tasksCanceled = tasksCanceled; this.tasksCompleted = tasksCompleted; this.tasksCreated = tasksCreated; this.tasksDeleted = tasksDeleted; this.tasksMoved = tasksMoved; this.tasksTimedOutInWorkflow = tasksTimedOutInWorkflow; - this.workspaceSid = workspaceSid; this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The average time from Task creation to acceptance. - * - * @return The average time from Task creation to acceptance - */ - public final Integer getAvgTaskAcceptanceTime() { - return this.avgTaskAcceptanceTime; - } - - /** - * Returns The The start_time. - * - * @return The start_time - */ - public final DateTime getStartTime() { - return this.startTime; - } - - /** - * Returns The The end_time. - * - * @return The end_time - */ - public final DateTime getEndTime() { - return this.endTime; - } - - /** - * Returns The The total number of Reservations that were created for Workers. - * - * @return The total number of Reservations that were created for Workers - */ - public final Integer getReservationsCreated() { - return this.reservationsCreated; - } - - /** - * Returns The The total number of Reservations accepted by Workers. - * - * @return The total number of Reservations accepted by Workers - */ - public final Integer getReservationsAccepted() { - return this.reservationsAccepted; - } - - /** - * Returns The The total number of Reservations that were rejected. - * - * @return The total number of Reservations that were rejected - */ - public final Integer getReservationsRejected() { - return this.reservationsRejected; - } - - /** - * Returns The The total number of Reservations that were timed out. - * - * @return The total number of Reservations that were timed out - */ - public final Integer getReservationsTimedOut() { - return this.reservationsTimedOut; - } - - /** - * Returns The The total number of Reservations that were canceled. - * - * @return The total number of Reservations that were canceled - */ - public final Integer getReservationsCanceled() { - return this.reservationsCanceled; - } - - /** - * Returns The The total number of Reservations that were rescinded. - * - * @return The total number of Reservations that were rescinded - */ - public final Integer getReservationsRescinded() { - return this.reservationsRescinded; - } - - /** - * Returns The The splits of the tasks canceled and accepted based on the - * provided SplitByWaitTime parameter.. - * - * @return The splits of the tasks canceled and accepted based on the provided - * SplitByWaitTime parameter. - */ - public final Map getSplitByWaitTime() { - return this.splitByWaitTime; - } - - /** - * Returns The The wait duration stats for tasks that were accepted.. - * - * @return The wait duration stats for tasks that were accepted. - */ - public final Map getWaitDurationUntilAccepted() { - return this.waitDurationUntilAccepted; - } - - /** - * Returns The The wait duration stats for tasks that were canceled.. - * - * @return The wait duration stats for tasks that were canceled. - */ - public final Map getWaitDurationUntilCanceled() { - return this.waitDurationUntilCanceled; - } - - /** - * Returns The The total number of Tasks that were canceled. - * - * @return The total number of Tasks that were canceled - */ - public final Integer getTasksCanceled() { - return this.tasksCanceled; - } - - /** - * Returns The The total number of Tasks that were completed. - * - * @return The total number of Tasks that were completed - */ - public final Integer getTasksCompleted() { - return this.tasksCompleted; - } - - /** - * Returns The The total number of Tasks created. - * - * @return The total number of Tasks created - */ - public final Integer getTasksCreated() { - return this.tasksCreated; - } - - /** - * Returns The The total number of Tasks that were deleted. - * - * @return The total number of Tasks that were deleted - */ - public final Integer getTasksDeleted() { - return this.tasksDeleted; - } - - /** - * Returns The The total number of Tasks that were moved from one queue to - * another. - * - * @return The total number of Tasks that were moved from one queue to another - */ - public final Integer getTasksMoved() { - return this.tasksMoved; - } - - /** - * Returns The The total number of Tasks that were timed out of their Workflows. - * - * @return The total number of Tasks that were timed out of their Workflows - */ - public final Integer getTasksTimedOutInWorkflow() { - return this.tasksTimedOutInWorkflow; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.waitDurationUntilAccepted = waitDurationUntilAccepted; + this.waitDurationUntilCanceled = waitDurationUntilCanceled; + this.workspaceSid = workspaceSid; } @Override @@ -376,79 +258,70 @@ public boolean equals(final Object o) { } WorkspaceCumulativeStatistics other = (WorkspaceCumulativeStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(avgTaskAcceptanceTime, other.avgTaskAcceptanceTime) && - Objects.equals(startTime, other.startTime) && - Objects.equals(endTime, other.endTime) && - Objects.equals(reservationsCreated, other.reservationsCreated) && - Objects.equals(reservationsAccepted, other.reservationsAccepted) && - Objects.equals(reservationsRejected, other.reservationsRejected) && - Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && - Objects.equals(reservationsCanceled, other.reservationsCanceled) && - Objects.equals(reservationsRescinded, other.reservationsRescinded) && - Objects.equals(splitByWaitTime, other.splitByWaitTime) && - Objects.equals(waitDurationUntilAccepted, other.waitDurationUntilAccepted) && - Objects.equals(waitDurationUntilCanceled, other.waitDurationUntilCanceled) && - Objects.equals(tasksCanceled, other.tasksCanceled) && - Objects.equals(tasksCompleted, other.tasksCompleted) && - Objects.equals(tasksCreated, other.tasksCreated) && - Objects.equals(tasksDeleted, other.tasksDeleted) && - Objects.equals(tasksMoved, other.tasksMoved) && - Objects.equals(tasksTimedOutInWorkflow, other.tasksTimedOutInWorkflow) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + avgTaskAcceptanceTime, + other.avgTaskAcceptanceTime + ) && + Objects.equals(endTime, other.endTime) && + Objects.equals(reservationsAccepted, other.reservationsAccepted) && + Objects.equals(reservationsCanceled, other.reservationsCanceled) && + Objects.equals(reservationsCreated, other.reservationsCreated) && + Objects.equals(reservationsRejected, other.reservationsRejected) && + Objects.equals( + reservationsRescinded, + other.reservationsRescinded + ) && + Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && + Objects.equals(splitByWaitTime, other.splitByWaitTime) && + Objects.equals(startTime, other.startTime) && + Objects.equals(tasksCanceled, other.tasksCanceled) && + Objects.equals(tasksCompleted, other.tasksCompleted) && + Objects.equals(tasksCreated, other.tasksCreated) && + Objects.equals(tasksDeleted, other.tasksDeleted) && + Objects.equals(tasksMoved, other.tasksMoved) && + Objects.equals( + tasksTimedOutInWorkflow, + other.tasksTimedOutInWorkflow + ) && + Objects.equals(url, other.url) && + Objects.equals( + waitDurationUntilAccepted, + other.waitDurationUntilAccepted + ) && + Objects.equals( + waitDurationUntilCanceled, + other.waitDurationUntilCanceled + ) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - avgTaskAcceptanceTime, - startTime, - endTime, - reservationsCreated, - reservationsAccepted, - reservationsRejected, - reservationsTimedOut, - reservationsCanceled, - reservationsRescinded, - splitByWaitTime, - waitDurationUntilAccepted, - waitDurationUntilCanceled, - tasksCanceled, - tasksCompleted, - tasksCreated, - tasksDeleted, - tasksMoved, - tasksTimedOutInWorkflow, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("avgTaskAcceptanceTime", avgTaskAcceptanceTime) - .add("startTime", startTime) - .add("endTime", endTime) - .add("reservationsCreated", reservationsCreated) - .add("reservationsAccepted", reservationsAccepted) - .add("reservationsRejected", reservationsRejected) - .add("reservationsTimedOut", reservationsTimedOut) - .add("reservationsCanceled", reservationsCanceled) - .add("reservationsRescinded", reservationsRescinded) - .add("splitByWaitTime", splitByWaitTime) - .add("waitDurationUntilAccepted", waitDurationUntilAccepted) - .add("waitDurationUntilCanceled", waitDurationUntilCanceled) - .add("tasksCanceled", tasksCanceled) - .add("tasksCompleted", tasksCompleted) - .add("tasksCreated", tasksCreated) - .add("tasksDeleted", tasksDeleted) - .add("tasksMoved", tasksMoved) - .add("tasksTimedOutInWorkflow", tasksTimedOutInWorkflow) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + avgTaskAcceptanceTime, + endTime, + reservationsAccepted, + reservationsCanceled, + reservationsCreated, + reservationsRejected, + reservationsRescinded, + reservationsTimedOut, + splitByWaitTime, + startTime, + tasksCanceled, + tasksCompleted, + tasksCreated, + tasksDeleted, + tasksMoved, + tasksTimedOutInWorkflow, + url, + waitDurationUntilAccepted, + waitDurationUntilCanceled, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatisticsFetcher.java index e257436b14..55c3cb2ed0 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceCumulativeStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,154 +26,168 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; -public class WorkspaceCumulativeStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private DateTime endDate; +public class WorkspaceCumulativeStatisticsFetcher + extends Fetcher { + + private String pathWorkspaceSid; + private ZonedDateTime endDate; private Integer minutes; - private DateTime startDate; + private ZonedDateTime startDate; private String taskChannel; private String splitByWaitTime; - /** - * Construct a new WorkspaceCumulativeStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - */ public WorkspaceCumulativeStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter cumulative statistics by an end date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp. - * - * @param endDate Filter cumulative statistics by an end date. - * @return this - */ - public WorkspaceCumulativeStatisticsFetcher setEndDate(final DateTime endDate) { + public WorkspaceCumulativeStatisticsFetcher setEndDate( + final ZonedDateTime endDate + ) { this.endDate = endDate; return this; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ - public WorkspaceCumulativeStatisticsFetcher setMinutes(final Integer minutes) { + public WorkspaceCumulativeStatisticsFetcher setMinutes( + final Integer minutes + ) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public WorkspaceCumulativeStatisticsFetcher setStartDate(final DateTime startDate) { + public WorkspaceCumulativeStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ - public WorkspaceCumulativeStatisticsFetcher setTaskChannel(final String taskChannel) { + public WorkspaceCumulativeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } - /** - * A comma separated values for viewing splits of tasks canceled and accepted - * above the given threshold in seconds. Ex: "5,30" would show splits of tasks - * that were canceled or accepted before or after 5 seconds and respectively, 30 - * seconds. This is great for showing short abandoned tasks or tasks that failed - * to meet your SLA.. - * - * @param splitByWaitTime A comma separated values for viewing splits of tasks - * canceled and accepted above the given threshold in - * seconds. - * @return this - */ - public WorkspaceCumulativeStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime) { + public WorkspaceCumulativeStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkspaceCumulativeStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkspaceCumulativeStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/CumulativeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/CumulativeStatistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkspaceCumulativeStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkspaceCumulativeStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkspaceCumulativeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkspaceCumulativeStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkspaceCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkspaceCumulativeStatistics content = + WorkspaceCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); + Serializer.toString( + request, + "SplitByWaitTime", + splitByWaitTime, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatistics.java index ccb089ede3..087a47848c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -11,53 +18,51 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkspaceRealTimeStatistics extends Resource { - private static final long serialVersionUID = 239335226503820L; - /** - * Create a WorkspaceRealTimeStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @return WorkspaceRealTimeStatisticsFetcher capable of executing the fetch - */ - public static WorkspaceRealTimeStatisticsFetcher fetcher(final String pathWorkspaceSid) { + public static WorkspaceRealTimeStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkspaceRealTimeStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkspaceRealTimeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON String into a WorkspaceRealTimeStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkspaceRealTimeStatistics object represented by the provided JSON */ - public static WorkspaceRealTimeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkspaceRealTimeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkspaceRealTimeStatistics.class); + return objectMapper.readValue( + json, + WorkspaceRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -66,17 +71,23 @@ public static WorkspaceRealTimeStatistics fromJson(final String json, final Obje } /** - * Converts a JSON InputStream into a WorkspaceRealTimeStatistics object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkspaceRealTimeStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkspaceRealTimeStatistics object represented by the provided JSON */ - public static WorkspaceRealTimeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkspaceRealTimeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkspaceRealTimeStatistics.class); + return objectMapper.readValue( + json, + WorkspaceRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -84,125 +95,77 @@ public static WorkspaceRealTimeStatistics fromJson(final InputStream json, final } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final List> activityStatistics; + + @Getter + private final List activityStatistics; + + @Getter private final Integer longestTaskWaitingAge; - private final Map tasksByPriority; - private final Map tasksByStatus; + + @Getter + private final String longestTaskWaitingSid; + + @Getter + private final Object tasksByPriority; + + @Getter + private final Object tasksByStatus; + + @Getter private final Integer totalTasks; + + @Getter private final Integer totalWorkers; - private final String workspaceSid; + + @Getter private final URI url; + @Getter + private final String workspaceSid; + @JsonCreator - private WorkspaceRealTimeStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("activity_statistics") - final List> activityStatistics, - @JsonProperty("longest_task_waiting_age") - final Integer longestTaskWaitingAge, - @JsonProperty("tasks_by_priority") - final Map tasksByPriority, - @JsonProperty("tasks_by_status") - final Map tasksByStatus, - @JsonProperty("total_tasks") - final Integer totalTasks, - @JsonProperty("total_workers") - final Integer totalWorkers, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private WorkspaceRealTimeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("activity_statistics") final List< + Object + > activityStatistics, + @JsonProperty( + "longest_task_waiting_age" + ) final Integer longestTaskWaitingAge, + @JsonProperty( + "longest_task_waiting_sid" + ) final String longestTaskWaitingSid, + @JsonProperty("tasks_by_priority") final Object tasksByPriority, + @JsonProperty("tasks_by_status") final Object tasksByStatus, + @JsonProperty("total_tasks") final Integer totalTasks, + @JsonProperty("total_workers") final Integer totalWorkers, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.activityStatistics = activityStatistics; this.longestTaskWaitingAge = longestTaskWaitingAge; + this.longestTaskWaitingSid = longestTaskWaitingSid; this.tasksByPriority = tasksByPriority; this.tasksByStatus = tasksByStatus; this.totalTasks = totalTasks; this.totalWorkers = totalWorkers; - this.workspaceSid = workspaceSid; this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The A breakdown of Workers by Activity. - * - * @return A breakdown of Workers by Activity - */ - public final List> getActivityStatistics() { - return this.activityStatistics; - } - - /** - * Returns The The age of the longest waiting Task. - * - * @return The age of the longest waiting Task - */ - public final Integer getLongestTaskWaitingAge() { - return this.longestTaskWaitingAge; - } - - /** - * Returns The The tasks_by_priority. - * - * @return The tasks_by_priority - */ - public final Map getTasksByPriority() { - return this.tasksByPriority; - } - - /** - * Returns The The Tasks broken down by status. - * - * @return The Tasks broken down by status - */ - public final Map getTasksByStatus() { - return this.tasksByStatus; - } - - /** - * Returns The The total number of Tasks. - * - * @return The total number of Tasks - */ - public final Integer getTotalTasks() { - return this.totalTasks; - } - - /** - * Returns The The total number of Workers in the workspace. - * - * @return The total number of Workers in the workspace - */ - public final Integer getTotalWorkers() { - return this.totalWorkers; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.workspaceSid = workspaceSid; } @Override @@ -216,43 +179,39 @@ public boolean equals(final Object o) { } WorkspaceRealTimeStatistics other = (WorkspaceRealTimeStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(activityStatistics, other.activityStatistics) && - Objects.equals(longestTaskWaitingAge, other.longestTaskWaitingAge) && - Objects.equals(tasksByPriority, other.tasksByPriority) && - Objects.equals(tasksByStatus, other.tasksByStatus) && - Objects.equals(totalTasks, other.totalTasks) && - Objects.equals(totalWorkers, other.totalWorkers) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityStatistics, other.activityStatistics) && + Objects.equals( + longestTaskWaitingAge, + other.longestTaskWaitingAge + ) && + Objects.equals( + longestTaskWaitingSid, + other.longestTaskWaitingSid + ) && + Objects.equals(tasksByPriority, other.tasksByPriority) && + Objects.equals(tasksByStatus, other.tasksByStatus) && + Objects.equals(totalTasks, other.totalTasks) && + Objects.equals(totalWorkers, other.totalWorkers) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - activityStatistics, - longestTaskWaitingAge, - tasksByPriority, - tasksByStatus, - totalTasks, - totalWorkers, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("activityStatistics", activityStatistics) - .add("longestTaskWaitingAge", longestTaskWaitingAge) - .add("tasksByPriority", tasksByPriority) - .add("tasksByStatus", tasksByStatus) - .add("totalTasks", totalTasks) - .add("totalWorkers", totalWorkers) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + activityStatistics, + longestTaskWaitingAge, + longestTaskWaitingSid, + tasksByPriority, + tasksByStatus, + totalTasks, + totalWorkers, + url, + workspaceSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatisticsFetcher.java index 3b139a594c..de65a71645 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceRealTimeStatisticsFetcher.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,79 +26,99 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -public class WorkspaceRealTimeStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; +public class WorkspaceRealTimeStatisticsFetcher + extends Fetcher { + + private String pathWorkspaceSid; private String taskChannel; - /** - * Construct a new WorkspaceRealTimeStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - */ public WorkspaceRealTimeStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ - public WorkspaceRealTimeStatisticsFetcher setTaskChannel(final String taskChannel) { + public WorkspaceRealTimeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkspaceRealTimeStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkspaceRealTimeStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/RealTimeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/RealTimeStatistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkspaceRealTimeStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkspaceRealTimeStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkspaceRealTimeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkspaceRealTimeStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkspaceRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkspaceRealTimeStatistics content = + WorkspaceRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatistics.java index 9464b24038..7f50158263 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; @@ -11,49 +18,44 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkspaceStatistics extends Resource { - private static final long serialVersionUID = 181724864721054L; - /** - * Create a WorkspaceStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @return WorkspaceStatisticsFetcher capable of executing the fetch - */ - public static WorkspaceStatisticsFetcher fetcher(final String pathWorkspaceSid) { + public static WorkspaceStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkspaceStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkspaceStatistics object using the provided - * ObjectMapper. - * + * Converts a JSON String into a WorkspaceStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkspaceStatistics object represented by the provided JSON */ - public static WorkspaceStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkspaceStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkspaceStatistics.class); @@ -65,14 +67,17 @@ public static WorkspaceStatistics fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a WorkspaceStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkspaceStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkspaceStatistics object represented by the provided JSON */ - public static WorkspaceStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkspaceStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkspaceStatistics.class); @@ -83,73 +88,46 @@ public static WorkspaceStatistics fromJson(final InputStream json, final ObjectM } } - private final Map realtime; - private final Map cumulative; - private final String accountSid; - private final String workspaceSid; - private final URI url; - - @JsonCreator - private WorkspaceStatistics(@JsonProperty("realtime") - final Map realtime, - @JsonProperty("cumulative") - final Map cumulative, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { - this.realtime = realtime; - this.cumulative = cumulative; - this.accountSid = accountSid; - this.workspaceSid = workspaceSid; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The realtime. - * - * @return The realtime - */ - public final Map getRealtime() { - return this.realtime; - } + @Getter + private final String accountSid; - /** - * Returns The The cumulative. - * - * @return The cumulative - */ - public final Map getCumulative() { - return this.cumulative; - } + @Getter + private final Object cumulative; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Object realtime; - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } + @Getter + private final URI url; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + @Getter + private final String workspaceSid; + + @JsonCreator + private WorkspaceStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Object cumulative, + @JsonProperty("realtime") final Object realtime, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { + this.accountSid = accountSid; + this.cumulative = cumulative; + this.realtime = realtime; + this.url = url; + this.workspaceSid = workspaceSid; } @Override @@ -163,31 +141,23 @@ public boolean equals(final Object o) { } WorkspaceStatistics other = (WorkspaceStatistics) o; - - return Objects.equals(realtime, other.realtime) && - Objects.equals(cumulative, other.cumulative) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(realtime, other.realtime) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(realtime, - cumulative, - accountSid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("realtime", realtime) - .add("cumulative", cumulative) - .add("accountSid", accountSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + cumulative, + realtime, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatisticsFetcher.java index c8e3ae4ed8..e75c180282 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/WorkspaceStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,154 +26,160 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class WorkspaceStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; + + private String pathWorkspaceSid; private Integer minutes; - private DateTime startDate; - private DateTime endDate; + private ZonedDateTime startDate; + private ZonedDateTime endDate; private String taskChannel; private String splitByWaitTime; - /** - * Construct a new WorkspaceStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - */ public WorkspaceStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ public WorkspaceStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public WorkspaceStatisticsFetcher setStartDate(final DateTime startDate) { + public WorkspaceStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter cumulative statistics by an end date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp. - * - * @param endDate Filter cumulative statistics by an end date. - * @return this - */ - public WorkspaceStatisticsFetcher setEndDate(final DateTime endDate) { + public WorkspaceStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ public WorkspaceStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - /** - * A comma separated values for viewing splits of tasks canceled and accepted - * above the given threshold in seconds. Ex: "5,30" would show splits of tasks - * that were canceled or accepted before or after 5 seconds and respectively, 30 - * seconds. This is great for showing short abandoned tasks or tasks that failed - * to meet your SLA.. - * - * @param splitByWaitTime A comma separated values for viewing splits of tasks - * canceled and accepted above the given threshold in - * seconds. - * @return this - */ - public WorkspaceStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime) { + public WorkspaceStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkspaceStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkspaceStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Statistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Statistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkspaceStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkspaceStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkspaceStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkspaceStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkspaceStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkspaceStatistics content = WorkspaceStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); + Serializer.toString( + request, + "SplitByWaitTime", + splitByWaitTime, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/Reservation.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/Reservation.java index 671da2648a..39d4a9711b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/Reservation.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/Reservation.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.task; @@ -10,32 +17,56 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Reservation extends Resource { - private static final long serialVersionUID = 63448280807644L; + + public static ReservationFetcher fetcher( + final String pathWorkspaceSid, + final String pathTaskSid, + final String pathSid + ) { + return new ReservationFetcher(pathWorkspaceSid, pathTaskSid, pathSid); + } + + public static ReservationReader reader( + final String pathWorkspaceSid, + final String pathTaskSid + ) { + return new ReservationReader(pathWorkspaceSid, pathTaskSid); + } + + public static ReservationUpdater updater( + final String pathWorkspaceSid, + final String pathTaskSid, + final String pathSid + ) { + return new ReservationUpdater(pathWorkspaceSid, pathTaskSid, pathSid); + } public enum Status { PENDING("pending"), @@ -43,7 +74,9 @@ public enum Status { REJECTED("rejected"), TIMEOUT("timeout"), CANCELED("canceled"), - RESCINDED("rescinded"); + RESCINDED("rescinded"), + WRAPPING("wrapping"), + COMPLETED("completed"); private final String value; @@ -51,21 +84,39 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); } } + public enum SupervisorMode { + MONITOR("monitor"), + WHISPER("whisper"), + BARGE("barge"); + + private final String value; + + private SupervisorMode(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static SupervisorMode forValue(final String value) { + return Promoter.enumFromString(value, SupervisorMode.values()); + } + } + public enum CallStatus { INITIATED("initiated"), RINGING("ringing"), @@ -78,15 +129,11 @@ private CallStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a CallStatus from a string. - * @param value string value - * @return generated CallStatus - */ @JsonCreator public static CallStatus forValue(final String value) { return Promoter.enumFromString(value, CallStatus.values()); @@ -108,15 +155,11 @@ private ConferenceEvent(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ConferenceEvent from a string. - * @param value string value - * @return generated ConferenceEvent - */ @JsonCreator public static ConferenceEvent forValue(final String value) { return Promoter.enumFromString(value, ConferenceEvent.values()); @@ -124,54 +167,16 @@ public static ConferenceEvent forValue(final String value) { } /** - * Create a ReservationReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskSid The task_sid - * @return ReservationReader capable of executing the read - */ - public static ReservationReader reader(final String pathWorkspaceSid, - final String pathTaskSid) { - return new ReservationReader(pathWorkspaceSid, pathTaskSid); - } - - /** - * Create a ReservationFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskSid The task_sid - * @param pathSid The sid - * @return ReservationFetcher capable of executing the fetch - */ - public static ReservationFetcher fetcher(final String pathWorkspaceSid, - final String pathTaskSid, - final String pathSid) { - return new ReservationFetcher(pathWorkspaceSid, pathTaskSid, pathSid); - } - - /** - * Create a ReservationUpdater to execute update. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskSid The task_sid - * @param pathSid The sid - * @return ReservationUpdater capable of executing the update - */ - public static ReservationUpdater updater(final String pathWorkspaceSid, - final String pathTaskSid, - final String pathSid) { - return new ReservationUpdater(pathWorkspaceSid, pathTaskSid, pathSid); - } - - /** - * Converts a JSON String into a Reservation object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Reservation object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Reservation object represented by the provided JSON */ - public static Reservation fromJson(final String json, final ObjectMapper objectMapper) { + public static Reservation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Reservation.class); @@ -185,12 +190,15 @@ public static Reservation fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a Reservation object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Reservation object represented by the provided JSON */ - public static Reservation fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Reservation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Reservation.class); @@ -201,151 +209,88 @@ public static Reservation fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Map links; + + @Getter private final Reservation.Status reservationStatus; + + @Getter private final String sid; + + @Getter private final String taskSid; + + @Getter + private final URI url; + + @Getter private final String workerName; + + @Getter private final String workerSid; + + @Getter private final String workspaceSid; - private final URI url; - private final Map links; @JsonCreator - private Reservation(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("reservation_status") - final Reservation.Status reservationStatus, - @JsonProperty("sid") - final String sid, - @JsonProperty("task_sid") - final String taskSid, - @JsonProperty("worker_name") - final String workerName, - @JsonProperty("worker_sid") - final String workerSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { + private Reservation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("links") final Map links, + @JsonProperty( + "reservation_status" + ) final Reservation.Status reservationStatus, + @JsonProperty("sid") final String sid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("url") final URI url, + @JsonProperty("worker_name") final String workerName, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.links = links; this.reservationStatus = reservationStatus; this.sid = sid; this.taskSid = taskSid; + this.url = url; this.workerName = workerName; this.workerSid = workerSid; this.workspaceSid = workspaceSid; - this.url = url; - this.links = links; - } - - /** - * Returns The The ID of the Account that owns this Task. - * - * @return The ID of the Account that owns this Task - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The current status of the reservation.. - * - * @return The current status of the reservation. - */ - public final Reservation.Status getReservationStatus() { - return this.reservationStatus; - } - - /** - * Returns The The unique ID of this Reservation.. - * - * @return The unique ID of this Reservation. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The ID of the reserved Task. - * - * @return The ID of the reserved Task - */ - public final String getTaskSid() { - return this.taskSid; - } - - /** - * Returns The Human readable description of the Worker that is reserved. - * - * @return Human readable description of the Worker that is reserved - */ - public final String getWorkerName() { - return this.workerName; - } - - /** - * Returns The The ID of the reserved Worker. - * - * @return The ID of the reserved Worker - */ - public final String getWorkerSid() { - return this.workerSid; - } - - /** - * Returns The The ID of the Workspace that this task is contained within.. - * - * @return The ID of the Workspace that this task is contained within. - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -359,49 +304,35 @@ public boolean equals(final Object o) { } Reservation other = (Reservation) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(reservationStatus, other.reservationStatus) && - Objects.equals(sid, other.sid) && - Objects.equals(taskSid, other.taskSid) && - Objects.equals(workerName, other.workerName) && - Objects.equals(workerSid, other.workerSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) && + Objects.equals(reservationStatus, other.reservationStatus) && + Objects.equals(sid, other.sid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(url, other.url) && + Objects.equals(workerName, other.workerName) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - reservationStatus, - sid, - taskSid, - workerName, - workerSid, - workspaceSid, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("reservationStatus", reservationStatus) - .add("sid", sid) - .add("taskSid", taskSid) - .add("workerName", workerName) - .add("workerSid", workerSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + links, + reservationStatus, + sid, + taskSid, + url, + workerName, + workerSid, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationFetcher.java index b8e371e6cb..7fe8c9c573 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.task; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,88 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ReservationFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathTaskSid; - private final String pathSid; - /** - * Construct a new ReservationFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskSid The task_sid - * @param pathSid The sid - */ - public ReservationFetcher(final String pathWorkspaceSid, - final String pathTaskSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathTaskSid; + private String pathSid; + + public ReservationFetcher( + final String pathWorkspaceSid, + final String pathTaskSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Reservation - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Reservation fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Tasks/" + this.pathTaskSid + "/Reservations/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Reservation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Reservation.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Reservation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Reservation content = Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationReader.java index 376f68c1c6..b5abf72356 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.task; @@ -10,181 +17,234 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ReservationReader extends Reader { - private final String pathWorkspaceSid; - private final String pathTaskSid; + + private String pathWorkspaceSid; + private String pathTaskSid; private Reservation.Status reservationStatus; + private String workerSid; + private Long pageSize; - /** - * Construct a new ReservationReader. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskSid The task_sid - */ - public ReservationReader(final String pathWorkspaceSid, - final String pathTaskSid) { + public ReservationReader( + final String pathWorkspaceSid, + final String pathTaskSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskSid = pathTaskSid; } - /** - * Returns the list of reservations for a task with a specified - * ReservationStatus. - * - * @param reservationStatus Returns the list of reservations for a task with a - * specified ReservationStatus - * @return this - */ - public ReservationReader setReservationStatus(final Reservation.Status reservationStatus) { + public ReservationReader setReservationStatus( + final Reservation.Status reservationStatus + ) { this.reservationStatus = reservationStatus; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Reservation ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ReservationReader setWorkerSid(final String workerSid) { + this.workerSid = workerSid; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Reservation ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ReservationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "reservations", + response.getContent(), + Reservation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Tasks/" + this.pathTaskSid + "/Reservations", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Reservation ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "reservations", + response.getContent(), + Reservation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Reservation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "reservations", + response.getContent(), + Reservation.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Reservation Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Reservation read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "reservations", - response.getContent(), - Reservation.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (reservationStatus != null) { - request.addQueryParam("ReservationStatus", reservationStatus.toString()); + Serializer.toString( + request, + "ReservationStatus", + reservationStatus, + ParameterType.QUERY + ); + } + + if (workerSid != null) { + Serializer.toString( + request, + "WorkerSid", + workerSid, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationUpdater.java index 2049bb9749..91f097b8d7 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/task/ReservationUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.task; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,14 +28,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class ReservationUpdater extends Updater { - private final String pathWorkspaceSid; - private final String pathTaskSid; - private final String pathSid; + + private String pathWorkspaceSid; + private String pathTaskSid; + private String pathSid; + private String ifMatch; private Reservation.Status reservationStatus; private String workerActivitySid; private String instruction; @@ -74,929 +88,993 @@ public class ReservationUpdater extends Updater { private String sipAuthPassword; private List dequeueStatusCallbackEvent; private String postWorkActivitySid; - - /** - * Construct a new ReservationUpdater. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskSid The task_sid - * @param pathSid The sid - */ - public ReservationUpdater(final String pathWorkspaceSid, - final String pathTaskSid, - final String pathSid) { + private Reservation.SupervisorMode supervisorMode; + private String supervisor; + private Boolean endConferenceOnCustomerExit; + private Boolean beepOnCustomerEntrance; + private String jitterBufferSize; + + public ReservationUpdater( + final String pathWorkspaceSid, + final String pathTaskSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskSid = pathTaskSid; this.pathSid = pathSid; } - /** - * Yes. - * - * @param reservationStatus Yes - * @return this - */ - public ReservationUpdater setReservationStatus(final Reservation.Status reservationStatus) { + public ReservationUpdater setReservationStatus( + final Reservation.Status reservationStatus + ) { this.reservationStatus = reservationStatus; return this; } - /** - * No. - * - * @param workerActivitySid No - * @return this - */ - public ReservationUpdater setWorkerActivitySid(final String workerActivitySid) { + public ReservationUpdater setWorkerActivitySid( + final String workerActivitySid + ) { this.workerActivitySid = workerActivitySid; return this; } - /** - * Yes. - * - * @param instruction Yes - * @return this - */ public ReservationUpdater setInstruction(final String instruction) { this.instruction = instruction; return this; } - /** - * No. - * - * @param dequeuePostWorkActivitySid No - * @return this - */ - public ReservationUpdater setDequeuePostWorkActivitySid(final String dequeuePostWorkActivitySid) { + public ReservationUpdater setDequeuePostWorkActivitySid( + final String dequeuePostWorkActivitySid + ) { this.dequeuePostWorkActivitySid = dequeuePostWorkActivitySid; return this; } - /** - * Yes. - * - * @param dequeueFrom Yes - * @return this - */ public ReservationUpdater setDequeueFrom(final String dequeueFrom) { this.dequeueFrom = dequeueFrom; return this; } - /** - * No. - * - * @param dequeueRecord No - * @return this - */ public ReservationUpdater setDequeueRecord(final String dequeueRecord) { this.dequeueRecord = dequeueRecord; return this; } - /** - * No. - * - * @param dequeueTimeout No - * @return this - */ public ReservationUpdater setDequeueTimeout(final Integer dequeueTimeout) { this.dequeueTimeout = dequeueTimeout; return this; } - /** - * No. - * - * @param dequeueTo No - * @return this - */ public ReservationUpdater setDequeueTo(final String dequeueTo) { this.dequeueTo = dequeueTo; return this; } - /** - * No. - * - * @param dequeueStatusCallbackUrl No - * @return this - */ - public ReservationUpdater setDequeueStatusCallbackUrl(final URI dequeueStatusCallbackUrl) { + public ReservationUpdater setDequeueStatusCallbackUrl( + final URI dequeueStatusCallbackUrl + ) { this.dequeueStatusCallbackUrl = dequeueStatusCallbackUrl; return this; } - /** - * No. - * - * @param dequeueStatusCallbackUrl No - * @return this - */ - public ReservationUpdater setDequeueStatusCallbackUrl(final String dequeueStatusCallbackUrl) { - return setDequeueStatusCallbackUrl(Promoter.uriFromString(dequeueStatusCallbackUrl)); + public ReservationUpdater setDequeueStatusCallbackUrl( + final String dequeueStatusCallbackUrl + ) { + return setDequeueStatusCallbackUrl( + Promoter.uriFromString(dequeueStatusCallbackUrl) + ); } - /** - * Yes. - * - * @param callFrom Yes - * @return this - */ public ReservationUpdater setCallFrom(final String callFrom) { this.callFrom = callFrom; return this; } - /** - * No. - * - * @param callRecord No - * @return this - */ public ReservationUpdater setCallRecord(final String callRecord) { this.callRecord = callRecord; return this; } - /** - * No. - * - * @param callTimeout No - * @return this - */ public ReservationUpdater setCallTimeout(final Integer callTimeout) { this.callTimeout = callTimeout; return this; } - /** - * No. - * - * @param callTo No - * @return this - */ public ReservationUpdater setCallTo(final String callTo) { this.callTo = callTo; return this; } - /** - * Yes. - * - * @param callUrl Yes - * @return this - */ public ReservationUpdater setCallUrl(final URI callUrl) { this.callUrl = callUrl; return this; } - /** - * Yes. - * - * @param callUrl Yes - * @return this - */ public ReservationUpdater setCallUrl(final String callUrl) { return setCallUrl(Promoter.uriFromString(callUrl)); } - /** - * No. - * - * @param callStatusCallbackUrl No - * @return this - */ - public ReservationUpdater setCallStatusCallbackUrl(final URI callStatusCallbackUrl) { + public ReservationUpdater setCallStatusCallbackUrl( + final URI callStatusCallbackUrl + ) { this.callStatusCallbackUrl = callStatusCallbackUrl; return this; } - /** - * No. - * - * @param callStatusCallbackUrl No - * @return this - */ - public ReservationUpdater setCallStatusCallbackUrl(final String callStatusCallbackUrl) { - return setCallStatusCallbackUrl(Promoter.uriFromString(callStatusCallbackUrl)); + public ReservationUpdater setCallStatusCallbackUrl( + final String callStatusCallbackUrl + ) { + return setCallStatusCallbackUrl( + Promoter.uriFromString(callStatusCallbackUrl) + ); } - /** - * No. - * - * @param callAccept No - * @return this - */ public ReservationUpdater setCallAccept(final Boolean callAccept) { this.callAccept = callAccept; return this; } - /** - * Yes. - * - * @param redirectCallSid Yes - * @return this - */ public ReservationUpdater setRedirectCallSid(final String redirectCallSid) { this.redirectCallSid = redirectCallSid; return this; } - /** - * No. - * - * @param redirectAccept No - * @return this - */ public ReservationUpdater setRedirectAccept(final Boolean redirectAccept) { this.redirectAccept = redirectAccept; return this; } - /** - * Yes. - * - * @param redirectUrl Yes - * @return this - */ public ReservationUpdater setRedirectUrl(final URI redirectUrl) { this.redirectUrl = redirectUrl; return this; } - /** - * Yes. - * - * @param redirectUrl Yes - * @return this - */ public ReservationUpdater setRedirectUrl(final String redirectUrl) { return setRedirectUrl(Promoter.uriFromString(redirectUrl)); } - /** - * No. - * - * @param to No - * @return this - */ public ReservationUpdater setTo(final String to) { this.to = to; return this; } - /** - * No. - * - * @param from No - * @return this - */ public ReservationUpdater setFrom(final String from) { this.from = from; return this; } - /** - * The status_callback. - * - * @param statusCallback The status_callback - * @return this - */ public ReservationUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * The status_callback. - * - * @param statusCallback The status_callback - * @return this - */ public ReservationUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The status_callback_method. - * - * @param statusCallbackMethod The status_callback_method - * @return this - */ - public ReservationUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public ReservationUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * The status_callback_event. - * - * @param statusCallbackEvent The status_callback_event - * @return this - */ - public ReservationUpdater setStatusCallbackEvent(final List statusCallbackEvent) { + public ReservationUpdater setStatusCallbackEvent( + final List statusCallbackEvent + ) { this.statusCallbackEvent = statusCallbackEvent; return this; } - /** - * The status_callback_event. - * - * @param statusCallbackEvent The status_callback_event - * @return this - */ - public ReservationUpdater setStatusCallbackEvent(final Reservation.CallStatus statusCallbackEvent) { + public ReservationUpdater setStatusCallbackEvent( + final Reservation.CallStatus statusCallbackEvent + ) { return setStatusCallbackEvent(Promoter.listOfOne(statusCallbackEvent)); } - /** - * No. - * - * @param timeout No - * @return this - */ public ReservationUpdater setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - /** - * The record. - * - * @param record The record - * @return this - */ public ReservationUpdater setRecord(final Boolean record) { this.record = record; return this; } - /** - * The muted. - * - * @param muted The muted - * @return this - */ public ReservationUpdater setMuted(final Boolean muted) { this.muted = muted; return this; } - /** - * The beep. - * - * @param beep The beep - * @return this - */ public ReservationUpdater setBeep(final String beep) { this.beep = beep; return this; } - /** - * The start_conference_on_enter. - * - * @param startConferenceOnEnter The start_conference_on_enter - * @return this - */ - public ReservationUpdater setStartConferenceOnEnter(final Boolean startConferenceOnEnter) { + public ReservationUpdater setStartConferenceOnEnter( + final Boolean startConferenceOnEnter + ) { this.startConferenceOnEnter = startConferenceOnEnter; return this; } - /** - * The end_conference_on_exit. - * - * @param endConferenceOnExit The end_conference_on_exit - * @return this - */ - public ReservationUpdater setEndConferenceOnExit(final Boolean endConferenceOnExit) { + public ReservationUpdater setEndConferenceOnExit( + final Boolean endConferenceOnExit + ) { this.endConferenceOnExit = endConferenceOnExit; return this; } - /** - * The wait_url. - * - * @param waitUrl The wait_url - * @return this - */ public ReservationUpdater setWaitUrl(final URI waitUrl) { this.waitUrl = waitUrl; return this; } - /** - * The wait_url. - * - * @param waitUrl The wait_url - * @return this - */ public ReservationUpdater setWaitUrl(final String waitUrl) { return setWaitUrl(Promoter.uriFromString(waitUrl)); } - /** - * The wait_method. - * - * @param waitMethod The wait_method - * @return this - */ public ReservationUpdater setWaitMethod(final HttpMethod waitMethod) { this.waitMethod = waitMethod; return this; } - /** - * The early_media. - * - * @param earlyMedia The early_media - * @return this - */ public ReservationUpdater setEarlyMedia(final Boolean earlyMedia) { this.earlyMedia = earlyMedia; return this; } - /** - * The max_participants. - * - * @param maxParticipants The max_participants - * @return this - */ - public ReservationUpdater setMaxParticipants(final Integer maxParticipants) { + public ReservationUpdater setMaxParticipants( + final Integer maxParticipants + ) { this.maxParticipants = maxParticipants; return this; } - /** - * The conference_status_callback. - * - * @param conferenceStatusCallback The conference_status_callback - * @return this - */ - public ReservationUpdater setConferenceStatusCallback(final URI conferenceStatusCallback) { + public ReservationUpdater setConferenceStatusCallback( + final URI conferenceStatusCallback + ) { this.conferenceStatusCallback = conferenceStatusCallback; return this; } - /** - * The conference_status_callback. - * - * @param conferenceStatusCallback The conference_status_callback - * @return this - */ - public ReservationUpdater setConferenceStatusCallback(final String conferenceStatusCallback) { - return setConferenceStatusCallback(Promoter.uriFromString(conferenceStatusCallback)); + public ReservationUpdater setConferenceStatusCallback( + final String conferenceStatusCallback + ) { + return setConferenceStatusCallback( + Promoter.uriFromString(conferenceStatusCallback) + ); } - /** - * The conference_status_callback_method. - * - * @param conferenceStatusCallbackMethod The conference_status_callback_method - * @return this - */ - public ReservationUpdater setConferenceStatusCallbackMethod(final HttpMethod conferenceStatusCallbackMethod) { + public ReservationUpdater setConferenceStatusCallbackMethod( + final HttpMethod conferenceStatusCallbackMethod + ) { this.conferenceStatusCallbackMethod = conferenceStatusCallbackMethod; return this; } - /** - * The conference_status_callback_event. - * - * @param conferenceStatusCallbackEvent The conference_status_callback_event - * @return this - */ - public ReservationUpdater setConferenceStatusCallbackEvent(final List conferenceStatusCallbackEvent) { + public ReservationUpdater setConferenceStatusCallbackEvent( + final List conferenceStatusCallbackEvent + ) { this.conferenceStatusCallbackEvent = conferenceStatusCallbackEvent; return this; } - /** - * The conference_status_callback_event. - * - * @param conferenceStatusCallbackEvent The conference_status_callback_event - * @return this - */ - public ReservationUpdater setConferenceStatusCallbackEvent(final Reservation.ConferenceEvent conferenceStatusCallbackEvent) { - return setConferenceStatusCallbackEvent(Promoter.listOfOne(conferenceStatusCallbackEvent)); + public ReservationUpdater setConferenceStatusCallbackEvent( + final Reservation.ConferenceEvent conferenceStatusCallbackEvent + ) { + return setConferenceStatusCallbackEvent( + Promoter.listOfOne(conferenceStatusCallbackEvent) + ); } - /** - * The conference_record. - * - * @param conferenceRecord The conference_record - * @return this - */ - public ReservationUpdater setConferenceRecord(final String conferenceRecord) { + public ReservationUpdater setConferenceRecord( + final String conferenceRecord + ) { this.conferenceRecord = conferenceRecord; return this; } - /** - * The conference_trim. - * - * @param conferenceTrim The conference_trim - * @return this - */ public ReservationUpdater setConferenceTrim(final String conferenceTrim) { this.conferenceTrim = conferenceTrim; return this; } - /** - * The recording_channels. - * - * @param recordingChannels The recording_channels - * @return this - */ - public ReservationUpdater setRecordingChannels(final String recordingChannels) { + public ReservationUpdater setRecordingChannels( + final String recordingChannels + ) { this.recordingChannels = recordingChannels; return this; } - /** - * The recording_status_callback. - * - * @param recordingStatusCallback The recording_status_callback - * @return this - */ - public ReservationUpdater setRecordingStatusCallback(final URI recordingStatusCallback) { + public ReservationUpdater setRecordingStatusCallback( + final URI recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - /** - * The recording_status_callback. - * - * @param recordingStatusCallback The recording_status_callback - * @return this - */ - public ReservationUpdater setRecordingStatusCallback(final String recordingStatusCallback) { - return setRecordingStatusCallback(Promoter.uriFromString(recordingStatusCallback)); + public ReservationUpdater setRecordingStatusCallback( + final String recordingStatusCallback + ) { + return setRecordingStatusCallback( + Promoter.uriFromString(recordingStatusCallback) + ); } - /** - * The recording_status_callback_method. - * - * @param recordingStatusCallbackMethod The recording_status_callback_method - * @return this - */ - public ReservationUpdater setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod) { + public ReservationUpdater setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - /** - * The conference_recording_status_callback. - * - * @param conferenceRecordingStatusCallback The - * conference_recording_status_callback - * @return this - */ - public ReservationUpdater setConferenceRecordingStatusCallback(final URI conferenceRecordingStatusCallback) { - this.conferenceRecordingStatusCallback = conferenceRecordingStatusCallback; + public ReservationUpdater setConferenceRecordingStatusCallback( + final URI conferenceRecordingStatusCallback + ) { + this.conferenceRecordingStatusCallback = + conferenceRecordingStatusCallback; return this; } - /** - * The conference_recording_status_callback. - * - * @param conferenceRecordingStatusCallback The - * conference_recording_status_callback - * @return this - */ - public ReservationUpdater setConferenceRecordingStatusCallback(final String conferenceRecordingStatusCallback) { - return setConferenceRecordingStatusCallback(Promoter.uriFromString(conferenceRecordingStatusCallback)); + public ReservationUpdater setConferenceRecordingStatusCallback( + final String conferenceRecordingStatusCallback + ) { + return setConferenceRecordingStatusCallback( + Promoter.uriFromString(conferenceRecordingStatusCallback) + ); } - /** - * The conference_recording_status_callback_method. - * - * @param conferenceRecordingStatusCallbackMethod The - * conference_recording_status_callback_method - * @return this - */ - public ReservationUpdater setConferenceRecordingStatusCallbackMethod(final HttpMethod conferenceRecordingStatusCallbackMethod) { - this.conferenceRecordingStatusCallbackMethod = conferenceRecordingStatusCallbackMethod; + public ReservationUpdater setConferenceRecordingStatusCallbackMethod( + final HttpMethod conferenceRecordingStatusCallbackMethod + ) { + this.conferenceRecordingStatusCallbackMethod = + conferenceRecordingStatusCallbackMethod; return this; } - /** - * The region. - * - * @param region The region - * @return this - */ public ReservationUpdater setRegion(final String region) { this.region = region; return this; } - /** - * The sip_auth_username. - * - * @param sipAuthUsername The sip_auth_username - * @return this - */ public ReservationUpdater setSipAuthUsername(final String sipAuthUsername) { this.sipAuthUsername = sipAuthUsername; return this; } - /** - * The sip_auth_password. - * - * @param sipAuthPassword The sip_auth_password - * @return this - */ public ReservationUpdater setSipAuthPassword(final String sipAuthPassword) { this.sipAuthPassword = sipAuthPassword; return this; } - /** - * No. - * - * @param dequeueStatusCallbackEvent No - * @return this - */ - public ReservationUpdater setDequeueStatusCallbackEvent(final List dequeueStatusCallbackEvent) { + public ReservationUpdater setDequeueStatusCallbackEvent( + final List dequeueStatusCallbackEvent + ) { this.dequeueStatusCallbackEvent = dequeueStatusCallbackEvent; return this; } - /** - * No. - * - * @param dequeueStatusCallbackEvent No - * @return this - */ - public ReservationUpdater setDequeueStatusCallbackEvent(final String dequeueStatusCallbackEvent) { - return setDequeueStatusCallbackEvent(Promoter.listOfOne(dequeueStatusCallbackEvent)); + public ReservationUpdater setDequeueStatusCallbackEvent( + final String dequeueStatusCallbackEvent + ) { + return setDequeueStatusCallbackEvent( + Promoter.listOfOne(dequeueStatusCallbackEvent) + ); } - /** - * No. - * - * @param postWorkActivitySid No - * @return this - */ - public ReservationUpdater setPostWorkActivitySid(final String postWorkActivitySid) { + public ReservationUpdater setPostWorkActivitySid( + final String postWorkActivitySid + ) { this.postWorkActivitySid = postWorkActivitySid; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Reservation - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Reservation update(final TwilioRestClient client) { + public ReservationUpdater setSupervisorMode( + final Reservation.SupervisorMode supervisorMode + ) { + this.supervisorMode = supervisorMode; + return this; + } + + public ReservationUpdater setSupervisor(final String supervisor) { + this.supervisor = supervisor; + return this; + } + + public ReservationUpdater setEndConferenceOnCustomerExit( + final Boolean endConferenceOnCustomerExit + ) { + this.endConferenceOnCustomerExit = endConferenceOnCustomerExit; + return this; + } + + public ReservationUpdater setBeepOnCustomerEntrance( + final Boolean beepOnCustomerEntrance + ) { + this.beepOnCustomerEntrance = beepOnCustomerEntrance; + return this; + } + + public ReservationUpdater setJitterBufferSize( + final String jitterBufferSize + ) { + this.jitterBufferSize = jitterBufferSize; + return this; + } + + public ReservationUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Tasks/{TaskSid}/Reservations/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = path.replace("{" + "TaskSid" + "}", this.pathTaskSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Tasks/" + this.pathTaskSid + "/Reservations/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Reservation update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Reservation update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Reservation.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Reservation content = Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (reservationStatus != null) { - request.addPostParam("ReservationStatus", reservationStatus.toString()); + Serializer.toString( + request, + "ReservationStatus", + reservationStatus, + ParameterType.URLENCODED + ); } if (workerActivitySid != null) { - request.addPostParam("WorkerActivitySid", workerActivitySid); + Serializer.toString( + request, + "WorkerActivitySid", + workerActivitySid, + ParameterType.URLENCODED + ); } if (instruction != null) { - request.addPostParam("Instruction", instruction); + Serializer.toString( + request, + "Instruction", + instruction, + ParameterType.URLENCODED + ); } if (dequeuePostWorkActivitySid != null) { - request.addPostParam("DequeuePostWorkActivitySid", dequeuePostWorkActivitySid); + Serializer.toString( + request, + "DequeuePostWorkActivitySid", + dequeuePostWorkActivitySid, + ParameterType.URLENCODED + ); } if (dequeueFrom != null) { - request.addPostParam("DequeueFrom", dequeueFrom); + Serializer.toString( + request, + "DequeueFrom", + dequeueFrom, + ParameterType.URLENCODED + ); } if (dequeueRecord != null) { - request.addPostParam("DequeueRecord", dequeueRecord); + Serializer.toString( + request, + "DequeueRecord", + dequeueRecord, + ParameterType.URLENCODED + ); } if (dequeueTimeout != null) { - request.addPostParam("DequeueTimeout", dequeueTimeout.toString()); + Serializer.toString( + request, + "DequeueTimeout", + dequeueTimeout, + ParameterType.URLENCODED + ); } if (dequeueTo != null) { - request.addPostParam("DequeueTo", dequeueTo); + Serializer.toString( + request, + "DequeueTo", + dequeueTo, + ParameterType.URLENCODED + ); } if (dequeueStatusCallbackUrl != null) { - request.addPostParam("DequeueStatusCallbackUrl", dequeueStatusCallbackUrl.toString()); + Serializer.toString( + request, + "DequeueStatusCallbackUrl", + dequeueStatusCallbackUrl, + ParameterType.URLENCODED + ); } if (callFrom != null) { - request.addPostParam("CallFrom", callFrom); + Serializer.toString( + request, + "CallFrom", + callFrom, + ParameterType.URLENCODED + ); } if (callRecord != null) { - request.addPostParam("CallRecord", callRecord); + Serializer.toString( + request, + "CallRecord", + callRecord, + ParameterType.URLENCODED + ); } if (callTimeout != null) { - request.addPostParam("CallTimeout", callTimeout.toString()); + Serializer.toString( + request, + "CallTimeout", + callTimeout, + ParameterType.URLENCODED + ); } if (callTo != null) { - request.addPostParam("CallTo", callTo); + Serializer.toString( + request, + "CallTo", + callTo, + ParameterType.URLENCODED + ); } if (callUrl != null) { - request.addPostParam("CallUrl", callUrl.toString()); + Serializer.toString( + request, + "CallUrl", + callUrl, + ParameterType.URLENCODED + ); } if (callStatusCallbackUrl != null) { - request.addPostParam("CallStatusCallbackUrl", callStatusCallbackUrl.toString()); + Serializer.toString( + request, + "CallStatusCallbackUrl", + callStatusCallbackUrl, + ParameterType.URLENCODED + ); } if (callAccept != null) { - request.addPostParam("CallAccept", callAccept.toString()); + Serializer.toString( + request, + "CallAccept", + callAccept, + ParameterType.URLENCODED + ); } if (redirectCallSid != null) { - request.addPostParam("RedirectCallSid", redirectCallSid); + Serializer.toString( + request, + "RedirectCallSid", + redirectCallSid, + ParameterType.URLENCODED + ); } if (redirectAccept != null) { - request.addPostParam("RedirectAccept", redirectAccept.toString()); + Serializer.toString( + request, + "RedirectAccept", + redirectAccept, + ParameterType.URLENCODED + ); } if (redirectUrl != null) { - request.addPostParam("RedirectUrl", redirectUrl.toString()); + Serializer.toString( + request, + "RedirectUrl", + redirectUrl, + ParameterType.URLENCODED + ); } if (to != null) { - request.addPostParam("To", to); + Serializer.toString(request, "To", to, ParameterType.URLENCODED); } if (from != null) { - request.addPostParam("From", from); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallbackEvent != null) { - for (Reservation.CallStatus prop : statusCallbackEvent) { - request.addPostParam("StatusCallbackEvent", prop.toString()); + for (Reservation.CallStatus param : statusCallbackEvent) { + Serializer.toString( + request, + "StatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (timeout != null) { - request.addPostParam("Timeout", timeout.toString()); + Serializer.toString( + request, + "Timeout", + timeout, + ParameterType.URLENCODED + ); } if (record != null) { - request.addPostParam("Record", record.toString()); + Serializer.toString( + request, + "Record", + record, + ParameterType.URLENCODED + ); } if (muted != null) { - request.addPostParam("Muted", muted.toString()); + Serializer.toString( + request, + "Muted", + muted, + ParameterType.URLENCODED + ); } if (beep != null) { - request.addPostParam("Beep", beep); + Serializer.toString( + request, + "Beep", + beep, + ParameterType.URLENCODED + ); } if (startConferenceOnEnter != null) { - request.addPostParam("StartConferenceOnEnter", startConferenceOnEnter.toString()); + Serializer.toString( + request, + "StartConferenceOnEnter", + startConferenceOnEnter, + ParameterType.URLENCODED + ); } if (endConferenceOnExit != null) { - request.addPostParam("EndConferenceOnExit", endConferenceOnExit.toString()); + Serializer.toString( + request, + "EndConferenceOnExit", + endConferenceOnExit, + ParameterType.URLENCODED + ); } if (waitUrl != null) { - request.addPostParam("WaitUrl", waitUrl.toString()); + Serializer.toString( + request, + "WaitUrl", + waitUrl, + ParameterType.URLENCODED + ); } if (waitMethod != null) { - request.addPostParam("WaitMethod", waitMethod.toString()); + Serializer.toString( + request, + "WaitMethod", + waitMethod, + ParameterType.URLENCODED + ); } if (earlyMedia != null) { - request.addPostParam("EarlyMedia", earlyMedia.toString()); + Serializer.toString( + request, + "EarlyMedia", + earlyMedia, + ParameterType.URLENCODED + ); } if (maxParticipants != null) { - request.addPostParam("MaxParticipants", maxParticipants.toString()); + Serializer.toString( + request, + "MaxParticipants", + maxParticipants, + ParameterType.URLENCODED + ); } if (conferenceStatusCallback != null) { - request.addPostParam("ConferenceStatusCallback", conferenceStatusCallback.toString()); + Serializer.toString( + request, + "ConferenceStatusCallback", + conferenceStatusCallback, + ParameterType.URLENCODED + ); } if (conferenceStatusCallbackMethod != null) { - request.addPostParam("ConferenceStatusCallbackMethod", conferenceStatusCallbackMethod.toString()); + Serializer.toString( + request, + "ConferenceStatusCallbackMethod", + conferenceStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (conferenceStatusCallbackEvent != null) { - for (Reservation.ConferenceEvent prop : conferenceStatusCallbackEvent) { - request.addPostParam("ConferenceStatusCallbackEvent", prop.toString()); + for (Reservation.ConferenceEvent param : conferenceStatusCallbackEvent) { + Serializer.toString( + request, + "ConferenceStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (conferenceRecord != null) { - request.addPostParam("ConferenceRecord", conferenceRecord); + Serializer.toString( + request, + "ConferenceRecord", + conferenceRecord, + ParameterType.URLENCODED + ); } if (conferenceTrim != null) { - request.addPostParam("ConferenceTrim", conferenceTrim); + Serializer.toString( + request, + "ConferenceTrim", + conferenceTrim, + ParameterType.URLENCODED + ); } if (recordingChannels != null) { - request.addPostParam("RecordingChannels", recordingChannels); + Serializer.toString( + request, + "RecordingChannels", + recordingChannels, + ParameterType.URLENCODED + ); } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback.toString()); + Serializer.toString( + request, + "RecordingStatusCallback", + recordingStatusCallback, + ParameterType.URLENCODED + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); + Serializer.toString( + request, + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (conferenceRecordingStatusCallback != null) { - request.addPostParam("ConferenceRecordingStatusCallback", conferenceRecordingStatusCallback.toString()); + Serializer.toString( + request, + "ConferenceRecordingStatusCallback", + conferenceRecordingStatusCallback, + ParameterType.URLENCODED + ); } if (conferenceRecordingStatusCallbackMethod != null) { - request.addPostParam("ConferenceRecordingStatusCallbackMethod", conferenceRecordingStatusCallbackMethod.toString()); + Serializer.toString( + request, + "ConferenceRecordingStatusCallbackMethod", + conferenceRecordingStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (region != null) { - request.addPostParam("Region", region); + Serializer.toString( + request, + "Region", + region, + ParameterType.URLENCODED + ); } if (sipAuthUsername != null) { - request.addPostParam("SipAuthUsername", sipAuthUsername); + Serializer.toString( + request, + "SipAuthUsername", + sipAuthUsername, + ParameterType.URLENCODED + ); } if (sipAuthPassword != null) { - request.addPostParam("SipAuthPassword", sipAuthPassword); + Serializer.toString( + request, + "SipAuthPassword", + sipAuthPassword, + ParameterType.URLENCODED + ); } if (dequeueStatusCallbackEvent != null) { - for (String prop : dequeueStatusCallbackEvent) { - request.addPostParam("DequeueStatusCallbackEvent", prop); + for (String param : dequeueStatusCallbackEvent) { + Serializer.toString( + request, + "DequeueStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (postWorkActivitySid != null) { - request.addPostParam("PostWorkActivitySid", postWorkActivitySid); + Serializer.toString( + request, + "PostWorkActivitySid", + postWorkActivitySid, + ParameterType.URLENCODED + ); + } + + if (supervisorMode != null) { + Serializer.toString( + request, + "SupervisorMode", + supervisorMode, + ParameterType.URLENCODED + ); + } + + if (supervisor != null) { + Serializer.toString( + request, + "Supervisor", + supervisor, + ParameterType.URLENCODED + ); + } + + if (endConferenceOnCustomerExit != null) { + Serializer.toString( + request, + "EndConferenceOnCustomerExit", + endConferenceOnCustomerExit, + ParameterType.URLENCODED + ); + } + + if (beepOnCustomerEntrance != null) { + Serializer.toString( + request, + "BeepOnCustomerEntrance", + beepOnCustomerEntrance, + ParameterType.URLENCODED + ); + } + + if (jitterBufferSize != null) { + Serializer.toString( + request, + "JitterBufferSize", + jitterBufferSize, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueBulkRealTimeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueBulkRealTimeStatistics.java new file mode 100644 index 0000000000..176f5346d4 --- /dev/null +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueBulkRealTimeStatistics.java @@ -0,0 +1,176 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.taskrouter.v1.workspace.taskqueue; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TaskQueueBulkRealTimeStatistics extends Resource { + + public static TaskQueueBulkRealTimeStatisticsCreator creator( + final String pathWorkspaceSid + ) { + return new TaskQueueBulkRealTimeStatisticsCreator(pathWorkspaceSid); + } + + /** + * Converts a JSON String into a TaskQueueBulkRealTimeStatistics object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TaskQueueBulkRealTimeStatistics object represented by the provided JSON + */ + public static TaskQueueBulkRealTimeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + TaskQueueBulkRealTimeStatistics.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TaskQueueBulkRealTimeStatistics object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TaskQueueBulkRealTimeStatistics object represented by the provided JSON + */ + public static TaskQueueBulkRealTimeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + TaskQueueBulkRealTimeStatistics.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final List taskQueueData; + + @Getter + private final Integer taskQueueResponseCount; + + @Getter + private final URI url; + + @Getter + private final String workspaceSid; + + @JsonCreator + private TaskQueueBulkRealTimeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("task_queue_data") final List taskQueueData, + @JsonProperty( + "task_queue_response_count" + ) final Integer taskQueueResponseCount, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { + this.accountSid = accountSid; + this.taskQueueData = taskQueueData; + this.taskQueueResponseCount = taskQueueResponseCount; + this.url = url; + this.workspaceSid = workspaceSid; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TaskQueueBulkRealTimeStatistics other = + (TaskQueueBulkRealTimeStatistics) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(taskQueueData, other.taskQueueData) && + Objects.equals( + taskQueueResponseCount, + other.taskQueueResponseCount + ) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + taskQueueData, + taskQueueResponseCount, + url, + workspaceSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueBulkRealTimeStatisticsCreator.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueBulkRealTimeStatisticsCreator.java new file mode 100644 index 0000000000..330f706ec7 --- /dev/null +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueBulkRealTimeStatisticsCreator.java @@ -0,0 +1,126 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.taskrouter.v1.workspace.taskqueue; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TaskQueueBulkRealTimeStatisticsCreator + extends Creator { + + private String pathWorkspaceSid; + private Object body; + + public TaskQueueBulkRealTimeStatisticsCreator( + final String pathWorkspaceSid + ) { + this.pathWorkspaceSid = pathWorkspaceSid; + } + + public TaskQueueBulkRealTimeStatisticsCreator setBody(final Object body) { + this.body = body; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/TaskQueues/RealTimeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TASKROUTER.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TaskQueueBulkRealTimeStatistics creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TaskQueueBulkRealTimeStatistics create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return TaskQueueBulkRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskQueueBulkRealTimeStatistics content = + TaskQueueBulkRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (body != null) { + request.setBody( + TaskQueueBulkRealTimeStatistics.toJson(body, objectMapper) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatistics.java index 2da4f836d2..372912a9ac 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; @@ -11,56 +18,57 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class TaskQueueCumulativeStatistics extends Resource { - private static final long serialVersionUID = 150757949753643L; - /** - * Create a TaskQueueCumulativeStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskQueueSid The task_queue_sid - * @return TaskQueueCumulativeStatisticsFetcher capable of executing the fetch - */ - public static TaskQueueCumulativeStatisticsFetcher fetcher(final String pathWorkspaceSid, - final String pathTaskQueueSid) { - return new TaskQueueCumulativeStatisticsFetcher(pathWorkspaceSid, pathTaskQueueSid); + public static TaskQueueCumulativeStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { + return new TaskQueueCumulativeStatisticsFetcher( + pathWorkspaceSid, + pathTaskQueueSid + ); } /** - * Converts a JSON String into a TaskQueueCumulativeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON String into a TaskQueueCumulativeStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return TaskQueueCumulativeStatistics object represented by the provided JSON */ - public static TaskQueueCumulativeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static TaskQueueCumulativeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TaskQueueCumulativeStatistics.class); + return objectMapper.readValue( + json, + TaskQueueCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -69,17 +77,23 @@ public static TaskQueueCumulativeStatistics fromJson(final String json, final Ob } /** - * Converts a JSON InputStream into a TaskQueueCumulativeStatistics object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a TaskQueueCumulativeStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return TaskQueueCumulativeStatistics object represented by the provided JSON */ - public static TaskQueueCumulativeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static TaskQueueCumulativeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TaskQueueCumulativeStatistics.class); + return objectMapper.readValue( + json, + TaskQueueCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -87,302 +101,160 @@ public static TaskQueueCumulativeStatistics fromJson(final InputStream json, fin } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final Integer avgTaskAcceptanceTime; - private final DateTime startTime; - private final DateTime endTime; - private final Integer reservationsCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; + + @Getter private final Integer reservationsAccepted; - private final Integer reservationsRejected; - private final Integer reservationsTimedOut; + + @Getter private final Integer reservationsCanceled; + + @Getter + private final Integer reservationsCreated; + + @Getter + private final Integer reservationsRejected; + + @Getter private final Integer reservationsRescinded; - private final Map splitByWaitTime; + + @Getter + private final Integer reservationsTimedOut; + + @Getter + private final Object splitByWaitTime; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime startTime; + + @Getter private final String taskQueueSid; - private final Map waitDurationUntilAccepted; - private final Map waitDurationUntilCanceled; + + @Getter private final Integer tasksCanceled; + + @Getter private final Integer tasksCompleted; + + @Getter private final Integer tasksDeleted; + + @Getter private final Integer tasksEntered; + + @Getter private final Integer tasksMoved; - private final String workspaceSid; + + @Getter private final URI url; + @Getter + private final Object waitDurationInQueueUntilAccepted; + + @Getter + private final Object waitDurationUntilAccepted; + + @Getter + private final Object waitDurationUntilCanceled; + + @Getter + private final String workspaceSid; + @JsonCreator - private TaskQueueCumulativeStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("avg_task_acceptance_time") - final Integer avgTaskAcceptanceTime, - @JsonProperty("start_time") - final String startTime, - @JsonProperty("end_time") - final String endTime, - @JsonProperty("reservations_created") - final Integer reservationsCreated, - @JsonProperty("reservations_accepted") - final Integer reservationsAccepted, - @JsonProperty("reservations_rejected") - final Integer reservationsRejected, - @JsonProperty("reservations_timed_out") - final Integer reservationsTimedOut, - @JsonProperty("reservations_canceled") - final Integer reservationsCanceled, - @JsonProperty("reservations_rescinded") - final Integer reservationsRescinded, - @JsonProperty("split_by_wait_time") - final Map splitByWaitTime, - @JsonProperty("task_queue_sid") - final String taskQueueSid, - @JsonProperty("wait_duration_until_accepted") - final Map waitDurationUntilAccepted, - @JsonProperty("wait_duration_until_canceled") - final Map waitDurationUntilCanceled, - @JsonProperty("tasks_canceled") - final Integer tasksCanceled, - @JsonProperty("tasks_completed") - final Integer tasksCompleted, - @JsonProperty("tasks_deleted") - final Integer tasksDeleted, - @JsonProperty("tasks_entered") - final Integer tasksEntered, - @JsonProperty("tasks_moved") - final Integer tasksMoved, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private TaskQueueCumulativeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "avg_task_acceptance_time" + ) final Integer avgTaskAcceptanceTime, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty( + "reservations_accepted" + ) final Integer reservationsAccepted, + @JsonProperty( + "reservations_canceled" + ) final Integer reservationsCanceled, + @JsonProperty("reservations_created") final Integer reservationsCreated, + @JsonProperty( + "reservations_rejected" + ) final Integer reservationsRejected, + @JsonProperty( + "reservations_rescinded" + ) final Integer reservationsRescinded, + @JsonProperty( + "reservations_timed_out" + ) final Integer reservationsTimedOut, + @JsonProperty("split_by_wait_time") final Object splitByWaitTime, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime startTime, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty("tasks_canceled") final Integer tasksCanceled, + @JsonProperty("tasks_completed") final Integer tasksCompleted, + @JsonProperty("tasks_deleted") final Integer tasksDeleted, + @JsonProperty("tasks_entered") final Integer tasksEntered, + @JsonProperty("tasks_moved") final Integer tasksMoved, + @JsonProperty("url") final URI url, + @JsonProperty( + "wait_duration_in_queue_until_accepted" + ) final Object waitDurationInQueueUntilAccepted, + @JsonProperty( + "wait_duration_until_accepted" + ) final Object waitDurationUntilAccepted, + @JsonProperty( + "wait_duration_until_canceled" + ) final Object waitDurationUntilCanceled, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.avgTaskAcceptanceTime = avgTaskAcceptanceTime; - this.startTime = DateConverter.iso8601DateTimeFromString(startTime); - this.endTime = DateConverter.iso8601DateTimeFromString(endTime); - this.reservationsCreated = reservationsCreated; + this.endTime = endTime; this.reservationsAccepted = reservationsAccepted; - this.reservationsRejected = reservationsRejected; - this.reservationsTimedOut = reservationsTimedOut; this.reservationsCanceled = reservationsCanceled; + this.reservationsCreated = reservationsCreated; + this.reservationsRejected = reservationsRejected; this.reservationsRescinded = reservationsRescinded; + this.reservationsTimedOut = reservationsTimedOut; this.splitByWaitTime = splitByWaitTime; + this.startTime = startTime; this.taskQueueSid = taskQueueSid; - this.waitDurationUntilAccepted = waitDurationUntilAccepted; - this.waitDurationUntilCanceled = waitDurationUntilCanceled; this.tasksCanceled = tasksCanceled; this.tasksCompleted = tasksCompleted; this.tasksDeleted = tasksDeleted; this.tasksEntered = tasksEntered; this.tasksMoved = tasksMoved; - this.workspaceSid = workspaceSid; this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The average time from Task creation to reservation acceptance - * while in this TaskQueue. - * - * @return The average time from Task creation to reservation acceptance while - * in this TaskQueue - */ - public final Integer getAvgTaskAcceptanceTime() { - return this.avgTaskAcceptanceTime; - } - - /** - * Returns The The start_time. - * - * @return The start_time - */ - public final DateTime getStartTime() { - return this.startTime; - } - - /** - * Returns The The end_time. - * - * @return The end_time - */ - public final DateTime getEndTime() { - return this.endTime; - } - - /** - * Returns The The total number of Reservations that were created for Tasks - * while in this TaskQueue. - * - * @return The total number of Reservations that were created for Tasks while - * in this TaskQueue - */ - public final Integer getReservationsCreated() { - return this.reservationsCreated; - } - - /** - * Returns The The total number of Reservations that were accepted for Tasks - * while in this TaskQueue. - * - * @return The total number of Reservations that were accepted for Tasks while - * in this TaskQueue - */ - public final Integer getReservationsAccepted() { - return this.reservationsAccepted; - } - - /** - * Returns The The total number of Reservations that were rejected for Tasks - * while in this TaskQueue. - * - * @return The total number of Reservations that were rejected for Tasks while - * in this TaskQueue - */ - public final Integer getReservationsRejected() { - return this.reservationsRejected; - } - - /** - * Returns The The total number of Reservations that were timed out for Tasks - * while in this TaskQueue. - * - * @return The total number of Reservations that were timed out for Tasks while - * in this TaskQueue - */ - public final Integer getReservationsTimedOut() { - return this.reservationsTimedOut; - } - - /** - * Returns The The total number of Reservations that were canceled for Tasks - * while in this TaskQueue. - * - * @return The total number of Reservations that were canceled for Tasks while - * in this TaskQueue - */ - public final Integer getReservationsCanceled() { - return this.reservationsCanceled; - } - - /** - * Returns The The total number of Reservations that were rescinded. - * - * @return The total number of Reservations that were rescinded - */ - public final Integer getReservationsRescinded() { - return this.reservationsRescinded; - } - - /** - * Returns The The splits of the tasks canceled and accepted based on the - * provided SplitByWaitTime parameter. - * - * @return The splits of the tasks canceled and accepted based on the provided - * SplitByWaitTime parameter - */ - public final Map getSplitByWaitTime() { - return this.splitByWaitTime; - } - - /** - * Returns The The task_queue_sid. - * - * @return The task_queue_sid - */ - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - - /** - * Returns The The wait duration stats for tasks that were accepted while in - * this TaskQueue. - * - * @return The wait duration stats for tasks that were accepted while in this - * TaskQueue - */ - public final Map getWaitDurationUntilAccepted() { - return this.waitDurationUntilAccepted; - } - - /** - * Returns The The wait duration stats for tasks that were canceled while in - * this TaskQueue. - * - * @return The wait duration stats for tasks that were canceled while in this - * TaskQueue - */ - public final Map getWaitDurationUntilCanceled() { - return this.waitDurationUntilCanceled; - } - - /** - * Returns The The total number of Tasks canceled while in this TaskQueue. - * - * @return The total number of Tasks canceled while in this TaskQueue - */ - public final Integer getTasksCanceled() { - return this.tasksCanceled; - } - - /** - * Returns The The total number of Tasks completed while in this TaskQueue. - * - * @return The total number of Tasks completed while in this TaskQueue - */ - public final Integer getTasksCompleted() { - return this.tasksCompleted; - } - - /** - * Returns The The total number of Tasks that were deleted while in this - * TaskQueue. - * - * @return The total number of Tasks that were deleted while in this TaskQueue - */ - public final Integer getTasksDeleted() { - return this.tasksDeleted; - } - - /** - * Returns The The total number of Tasks entered into this TaskQueue. - * - * @return The total number of Tasks entered into this TaskQueue - */ - public final Integer getTasksEntered() { - return this.tasksEntered; - } - - /** - * Returns The The total number of Tasks moved to another TaskQueue from this - * TaskQueue. - * - * @return The total number of Tasks moved to another TaskQueue from this - * TaskQueue - */ - public final Integer getTasksMoved() { - return this.tasksMoved; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.waitDurationInQueueUntilAccepted = + waitDurationInQueueUntilAccepted; + this.waitDurationUntilAccepted = waitDurationUntilAccepted; + this.waitDurationUntilCanceled = waitDurationUntilCanceled; + this.workspaceSid = workspaceSid; } @Override @@ -396,79 +268,72 @@ public boolean equals(final Object o) { } TaskQueueCumulativeStatistics other = (TaskQueueCumulativeStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(avgTaskAcceptanceTime, other.avgTaskAcceptanceTime) && - Objects.equals(startTime, other.startTime) && - Objects.equals(endTime, other.endTime) && - Objects.equals(reservationsCreated, other.reservationsCreated) && - Objects.equals(reservationsAccepted, other.reservationsAccepted) && - Objects.equals(reservationsRejected, other.reservationsRejected) && - Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && - Objects.equals(reservationsCanceled, other.reservationsCanceled) && - Objects.equals(reservationsRescinded, other.reservationsRescinded) && - Objects.equals(splitByWaitTime, other.splitByWaitTime) && - Objects.equals(taskQueueSid, other.taskQueueSid) && - Objects.equals(waitDurationUntilAccepted, other.waitDurationUntilAccepted) && - Objects.equals(waitDurationUntilCanceled, other.waitDurationUntilCanceled) && - Objects.equals(tasksCanceled, other.tasksCanceled) && - Objects.equals(tasksCompleted, other.tasksCompleted) && - Objects.equals(tasksDeleted, other.tasksDeleted) && - Objects.equals(tasksEntered, other.tasksEntered) && - Objects.equals(tasksMoved, other.tasksMoved) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + avgTaskAcceptanceTime, + other.avgTaskAcceptanceTime + ) && + Objects.equals(endTime, other.endTime) && + Objects.equals(reservationsAccepted, other.reservationsAccepted) && + Objects.equals(reservationsCanceled, other.reservationsCanceled) && + Objects.equals(reservationsCreated, other.reservationsCreated) && + Objects.equals(reservationsRejected, other.reservationsRejected) && + Objects.equals( + reservationsRescinded, + other.reservationsRescinded + ) && + Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && + Objects.equals(splitByWaitTime, other.splitByWaitTime) && + Objects.equals(startTime, other.startTime) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals(tasksCanceled, other.tasksCanceled) && + Objects.equals(tasksCompleted, other.tasksCompleted) && + Objects.equals(tasksDeleted, other.tasksDeleted) && + Objects.equals(tasksEntered, other.tasksEntered) && + Objects.equals(tasksMoved, other.tasksMoved) && + Objects.equals(url, other.url) && + Objects.equals( + waitDurationInQueueUntilAccepted, + other.waitDurationInQueueUntilAccepted + ) && + Objects.equals( + waitDurationUntilAccepted, + other.waitDurationUntilAccepted + ) && + Objects.equals( + waitDurationUntilCanceled, + other.waitDurationUntilCanceled + ) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - avgTaskAcceptanceTime, - startTime, - endTime, - reservationsCreated, - reservationsAccepted, - reservationsRejected, - reservationsTimedOut, - reservationsCanceled, - reservationsRescinded, - splitByWaitTime, - taskQueueSid, - waitDurationUntilAccepted, - waitDurationUntilCanceled, - tasksCanceled, - tasksCompleted, - tasksDeleted, - tasksEntered, - tasksMoved, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("avgTaskAcceptanceTime", avgTaskAcceptanceTime) - .add("startTime", startTime) - .add("endTime", endTime) - .add("reservationsCreated", reservationsCreated) - .add("reservationsAccepted", reservationsAccepted) - .add("reservationsRejected", reservationsRejected) - .add("reservationsTimedOut", reservationsTimedOut) - .add("reservationsCanceled", reservationsCanceled) - .add("reservationsRescinded", reservationsRescinded) - .add("splitByWaitTime", splitByWaitTime) - .add("taskQueueSid", taskQueueSid) - .add("waitDurationUntilAccepted", waitDurationUntilAccepted) - .add("waitDurationUntilCanceled", waitDurationUntilCanceled) - .add("tasksCanceled", tasksCanceled) - .add("tasksCompleted", tasksCompleted) - .add("tasksDeleted", tasksDeleted) - .add("tasksEntered", tasksEntered) - .add("tasksMoved", tasksMoved) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + avgTaskAcceptanceTime, + endTime, + reservationsAccepted, + reservationsCanceled, + reservationsCreated, + reservationsRejected, + reservationsRescinded, + reservationsTimedOut, + splitByWaitTime, + startTime, + taskQueueSid, + tasksCanceled, + tasksCompleted, + tasksDeleted, + tasksEntered, + tasksMoved, + url, + waitDurationInQueueUntilAccepted, + waitDurationUntilAccepted, + waitDurationUntilCanceled, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatisticsFetcher.java index 809eacd262..c08af3eae1 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueCumulativeStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,158 +26,179 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; -public class TaskQueueCumulativeStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathTaskQueueSid; - private DateTime endDate; +public class TaskQueueCumulativeStatisticsFetcher + extends Fetcher { + + private String pathWorkspaceSid; + private String pathTaskQueueSid; + private ZonedDateTime endDate; private Integer minutes; - private DateTime startDate; + private ZonedDateTime startDate; private String taskChannel; private String splitByWaitTime; - /** - * Construct a new TaskQueueCumulativeStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskQueueSid The task_queue_sid - */ - public TaskQueueCumulativeStatisticsFetcher(final String pathWorkspaceSid, - final String pathTaskQueueSid) { + public TaskQueueCumulativeStatisticsFetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskQueueSid = pathTaskQueueSid; } - /** - * Filter cumulative statistics by an end date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp.. - * - * @param endDate Filter cumulative statistics by an end date. - * @return this - */ - public TaskQueueCumulativeStatisticsFetcher setEndDate(final DateTime endDate) { + public TaskQueueCumulativeStatisticsFetcher setEndDate( + final ZonedDateTime endDate + ) { this.endDate = endDate; return this; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ - public TaskQueueCumulativeStatisticsFetcher setMinutes(final Integer minutes) { + public TaskQueueCumulativeStatisticsFetcher setMinutes( + final Integer minutes + ) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp.. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public TaskQueueCumulativeStatisticsFetcher setStartDate(final DateTime startDate) { + public TaskQueueCumulativeStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ - public TaskQueueCumulativeStatisticsFetcher setTaskChannel(final String taskChannel) { + public TaskQueueCumulativeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } - /** - * A comma separated values for viewing splits of tasks canceled and accepted - * above the given threshold in seconds. Ex: "5,30" would show splits of tasks - * that were canceled or accepted before or after 5 seconds and respectively, 30 - * seconds. This is great for showing short abandoned tasks or tasks that failed - * to meet your SLA.. - * - * @param splitByWaitTime A comma separated values for viewing splits of tasks - * canceled and accepted above the given threshold in - * seconds. - * @return this - */ - public TaskQueueCumulativeStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime) { + public TaskQueueCumulativeStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched TaskQueueCumulativeStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public TaskQueueCumulativeStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/CumulativeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "TaskQueueSid" + "}", + this.pathTaskQueueSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues/" + this.pathTaskQueueSid + "/CumulativeStatistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueueCumulativeStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TaskQueueCumulativeStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return TaskQueueCumulativeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TaskQueueCumulativeStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskQueueCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskQueueCumulativeStatistics content = + TaskQueueCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); + Serializer.toString( + request, + "SplitByWaitTime", + splitByWaitTime, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatistics.java index e6e05b05b2..afdbaaba54 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; @@ -11,55 +18,55 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class TaskQueueRealTimeStatistics extends Resource { - private static final long serialVersionUID = 165753411245187L; - /** - * Create a TaskQueueRealTimeStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskQueueSid The task_queue_sid - * @return TaskQueueRealTimeStatisticsFetcher capable of executing the fetch - */ - public static TaskQueueRealTimeStatisticsFetcher fetcher(final String pathWorkspaceSid, - final String pathTaskQueueSid) { - return new TaskQueueRealTimeStatisticsFetcher(pathWorkspaceSid, pathTaskQueueSid); + public static TaskQueueRealTimeStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { + return new TaskQueueRealTimeStatisticsFetcher( + pathWorkspaceSid, + pathTaskQueueSid + ); } /** - * Converts a JSON String into a TaskQueueRealTimeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON String into a TaskQueueRealTimeStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return TaskQueueRealTimeStatistics object represented by the provided JSON */ - public static TaskQueueRealTimeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static TaskQueueRealTimeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TaskQueueRealTimeStatistics.class); + return objectMapper.readValue( + json, + TaskQueueRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -68,17 +75,23 @@ public static TaskQueueRealTimeStatistics fromJson(final String json, final Obje } /** - * Converts a JSON InputStream into a TaskQueueRealTimeStatistics object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a TaskQueueRealTimeStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return TaskQueueRealTimeStatistics object represented by the provided JSON */ - public static TaskQueueRealTimeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static TaskQueueRealTimeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, TaskQueueRealTimeStatistics.class); + return objectMapper.readValue( + json, + TaskQueueRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -86,154 +99,105 @@ public static TaskQueueRealTimeStatistics fromJson(final InputStream json, final } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final List> activityStatistics; + + @Getter + private final List activityStatistics; + + @Getter + private final Integer longestRelativeTaskAgeInQueue; + + @Getter + private final String longestRelativeTaskSidInQueue; + + @Getter private final Integer longestTaskWaitingAge; + + @Getter + private final String longestTaskWaitingSid; + + @Getter private final String taskQueueSid; - private final Map tasksByPriority; - private final Map tasksByStatus; + + @Getter + private final Object tasksByPriority; + + @Getter + private final Object tasksByStatus; + + @Getter private final Integer totalAvailableWorkers; + + @Getter private final Integer totalEligibleWorkers; + + @Getter private final Integer totalTasks; - private final String workspaceSid; + + @Getter private final URI url; + @Getter + private final String workspaceSid; + @JsonCreator - private TaskQueueRealTimeStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("activity_statistics") - final List> activityStatistics, - @JsonProperty("longest_task_waiting_age") - final Integer longestTaskWaitingAge, - @JsonProperty("task_queue_sid") - final String taskQueueSid, - @JsonProperty("tasks_by_priority") - final Map tasksByPriority, - @JsonProperty("tasks_by_status") - final Map tasksByStatus, - @JsonProperty("total_available_workers") - final Integer totalAvailableWorkers, - @JsonProperty("total_eligible_workers") - final Integer totalEligibleWorkers, - @JsonProperty("total_tasks") - final Integer totalTasks, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private TaskQueueRealTimeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("activity_statistics") final List< + Object + > activityStatistics, + @JsonProperty( + "longest_relative_task_age_in_queue" + ) final Integer longestRelativeTaskAgeInQueue, + @JsonProperty( + "longest_relative_task_sid_in_queue" + ) final String longestRelativeTaskSidInQueue, + @JsonProperty( + "longest_task_waiting_age" + ) final Integer longestTaskWaitingAge, + @JsonProperty( + "longest_task_waiting_sid" + ) final String longestTaskWaitingSid, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty("tasks_by_priority") final Object tasksByPriority, + @JsonProperty("tasks_by_status") final Object tasksByStatus, + @JsonProperty( + "total_available_workers" + ) final Integer totalAvailableWorkers, + @JsonProperty( + "total_eligible_workers" + ) final Integer totalEligibleWorkers, + @JsonProperty("total_tasks") final Integer totalTasks, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.activityStatistics = activityStatistics; + this.longestRelativeTaskAgeInQueue = longestRelativeTaskAgeInQueue; + this.longestRelativeTaskSidInQueue = longestRelativeTaskSidInQueue; this.longestTaskWaitingAge = longestTaskWaitingAge; + this.longestTaskWaitingSid = longestTaskWaitingSid; this.taskQueueSid = taskQueueSid; this.tasksByPriority = tasksByPriority; this.tasksByStatus = tasksByStatus; this.totalAvailableWorkers = totalAvailableWorkers; this.totalEligibleWorkers = totalEligibleWorkers; this.totalTasks = totalTasks; - this.workspaceSid = workspaceSid; this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The current Worker status count breakdown by Activity. - * - * @return The current Worker status count breakdown by Activity - */ - public final List> getActivityStatistics() { - return this.activityStatistics; - } - - /** - * Returns The The age of the longest waiting Task. - * - * @return The age of the longest waiting Task - */ - public final Integer getLongestTaskWaitingAge() { - return this.longestTaskWaitingAge; - } - - /** - * Returns The The task_queue_sid. - * - * @return The task_queue_sid - */ - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - - /** - * Returns The The Tasks broken down by priority. - * - * @return The Tasks broken down by priority - */ - public final Map getTasksByPriority() { - return this.tasksByPriority; - } - - /** - * Returns The The Tasks broken down by status. - * - * @return The Tasks broken down by status - */ - public final Map getTasksByStatus() { - return this.tasksByStatus; - } - - /** - * Returns The The total number of Workers available for Tasks in this - * TaskQueue. - * - * @return The total number of Workers available for Tasks in this TaskQueue - */ - public final Integer getTotalAvailableWorkers() { - return this.totalAvailableWorkers; - } - - /** - * Returns The The total number of Workers eligible for Tasks in this TaskQueue, - * irrespective of Activity state.. - * - * @return The total number of Workers eligible for Tasks in this TaskQueue, - * irrespective of Activity state. - */ - public final Integer getTotalEligibleWorkers() { - return this.totalEligibleWorkers; - } - - /** - * Returns The The total number of Tasks. - * - * @return The total number of Tasks - */ - public final Integer getTotalTasks() { - return this.totalTasks; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.workspaceSid = workspaceSid; } @Override @@ -247,49 +211,56 @@ public boolean equals(final Object o) { } TaskQueueRealTimeStatistics other = (TaskQueueRealTimeStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(activityStatistics, other.activityStatistics) && - Objects.equals(longestTaskWaitingAge, other.longestTaskWaitingAge) && - Objects.equals(taskQueueSid, other.taskQueueSid) && - Objects.equals(tasksByPriority, other.tasksByPriority) && - Objects.equals(tasksByStatus, other.tasksByStatus) && - Objects.equals(totalAvailableWorkers, other.totalAvailableWorkers) && - Objects.equals(totalEligibleWorkers, other.totalEligibleWorkers) && - Objects.equals(totalTasks, other.totalTasks) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityStatistics, other.activityStatistics) && + Objects.equals( + longestRelativeTaskAgeInQueue, + other.longestRelativeTaskAgeInQueue + ) && + Objects.equals( + longestRelativeTaskSidInQueue, + other.longestRelativeTaskSidInQueue + ) && + Objects.equals( + longestTaskWaitingAge, + other.longestTaskWaitingAge + ) && + Objects.equals( + longestTaskWaitingSid, + other.longestTaskWaitingSid + ) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals(tasksByPriority, other.tasksByPriority) && + Objects.equals(tasksByStatus, other.tasksByStatus) && + Objects.equals( + totalAvailableWorkers, + other.totalAvailableWorkers + ) && + Objects.equals(totalEligibleWorkers, other.totalEligibleWorkers) && + Objects.equals(totalTasks, other.totalTasks) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - activityStatistics, - longestTaskWaitingAge, - taskQueueSid, - tasksByPriority, - tasksByStatus, - totalAvailableWorkers, - totalEligibleWorkers, - totalTasks, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("activityStatistics", activityStatistics) - .add("longestTaskWaitingAge", longestTaskWaitingAge) - .add("taskQueueSid", taskQueueSid) - .add("tasksByPriority", tasksByPriority) - .add("tasksByStatus", tasksByStatus) - .add("totalAvailableWorkers", totalAvailableWorkers) - .add("totalEligibleWorkers", totalEligibleWorkers) - .add("totalTasks", totalTasks) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + activityStatistics, + longestRelativeTaskAgeInQueue, + longestRelativeTaskSidInQueue, + longestTaskWaitingAge, + longestTaskWaitingSid, + taskQueueSid, + tasksByPriority, + tasksByStatus, + totalAvailableWorkers, + totalEligibleWorkers, + totalTasks, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatisticsFetcher.java index 36f6f7417a..2078f08f4e 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueRealTimeStatisticsFetcher.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,83 +26,110 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -public class TaskQueueRealTimeStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathTaskQueueSid; +public class TaskQueueRealTimeStatisticsFetcher + extends Fetcher { + + private String pathWorkspaceSid; + private String pathTaskQueueSid; private String taskChannel; - /** - * Construct a new TaskQueueRealTimeStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskQueueSid The task_queue_sid - */ - public TaskQueueRealTimeStatisticsFetcher(final String pathWorkspaceSid, - final String pathTaskQueueSid) { + public TaskQueueRealTimeStatisticsFetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskQueueSid = pathTaskQueueSid; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ - public TaskQueueRealTimeStatisticsFetcher setTaskChannel(final String taskChannel) { + public TaskQueueRealTimeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched TaskQueueRealTimeStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public TaskQueueRealTimeStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/RealTimeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "TaskQueueSid" + "}", + this.pathTaskQueueSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues/" + this.pathTaskQueueSid + "/RealTimeStatistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueueRealTimeStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TaskQueueRealTimeStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return TaskQueueRealTimeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TaskQueueRealTimeStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskQueueRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskQueueRealTimeStatistics content = + TaskQueueRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatistics.java index 0d7aece89a..5437a31c53 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; @@ -11,51 +18,48 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class TaskQueueStatistics extends Resource { - private static final long serialVersionUID = 25740453860502L; - /** - * Create a TaskQueueStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskQueueSid The task_queue_sid - * @return TaskQueueStatisticsFetcher capable of executing the fetch - */ - public static TaskQueueStatisticsFetcher fetcher(final String pathWorkspaceSid, - final String pathTaskQueueSid) { - return new TaskQueueStatisticsFetcher(pathWorkspaceSid, pathTaskQueueSid); + public static TaskQueueStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { + return new TaskQueueStatisticsFetcher( + pathWorkspaceSid, + pathTaskQueueSid + ); } /** - * Converts a JSON String into a TaskQueueStatistics object using the provided - * ObjectMapper. - * + * Converts a JSON String into a TaskQueueStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return TaskQueueStatistics object represented by the provided JSON */ - public static TaskQueueStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static TaskQueueStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueueStatistics.class); @@ -67,14 +71,17 @@ public static TaskQueueStatistics fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a TaskQueueStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a TaskQueueStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return TaskQueueStatistics object represented by the provided JSON */ - public static TaskQueueStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static TaskQueueStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueueStatistics.class); @@ -85,86 +92,51 @@ public static TaskQueueStatistics fromJson(final InputStream json, final ObjectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final Map cumulative; - private final Map realtime; + + @Getter + private final Object cumulative; + + @Getter + private final Object realtime; + + @Getter private final String taskQueueSid; - private final String workspaceSid; + + @Getter private final URI url; + @Getter + private final String workspaceSid; + @JsonCreator - private TaskQueueStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("cumulative") - final Map cumulative, - @JsonProperty("realtime") - final Map realtime, - @JsonProperty("task_queue_sid") - final String taskQueueSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private TaskQueueStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Object cumulative, + @JsonProperty("realtime") final Object realtime, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.cumulative = cumulative; this.realtime = realtime; this.taskQueueSid = taskQueueSid; - this.workspaceSid = workspaceSid; this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The cumulative. - * - * @return The cumulative - */ - public final Map getCumulative() { - return this.cumulative; - } - - /** - * Returns The The realtime. - * - * @return The realtime - */ - public final Map getRealtime() { - return this.realtime; - } - - /** - * Returns The The task_queue_sid. - * - * @return The task_queue_sid - */ - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.workspaceSid = workspaceSid; } @Override @@ -178,34 +150,25 @@ public boolean equals(final Object o) { } TaskQueueStatistics other = (TaskQueueStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(cumulative, other.cumulative) && - Objects.equals(realtime, other.realtime) && - Objects.equals(taskQueueSid, other.taskQueueSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(realtime, other.realtime) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - cumulative, - realtime, - taskQueueSid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("cumulative", cumulative) - .add("realtime", realtime) - .add("taskQueueSid", taskQueueSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + cumulative, + realtime, + taskQueueSid, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatisticsFetcher.java index a9dedb3b24..c89d2e01ea 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueueStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,158 +26,171 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class TaskQueueStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathTaskQueueSid; - private DateTime endDate; + + private String pathWorkspaceSid; + private String pathTaskQueueSid; + private ZonedDateTime endDate; private Integer minutes; - private DateTime startDate; + private ZonedDateTime startDate; private String taskChannel; private String splitByWaitTime; - /** - * Construct a new TaskQueueStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathTaskQueueSid The task_queue_sid - */ - public TaskQueueStatisticsFetcher(final String pathWorkspaceSid, - final String pathTaskQueueSid) { + public TaskQueueStatisticsFetcher( + final String pathWorkspaceSid, + final String pathTaskQueueSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathTaskQueueSid = pathTaskQueueSid; } - /** - * Filter cumulative statistics by an end date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp.. - * - * @param endDate Filter cumulative statistics by an end date. - * @return this - */ - public TaskQueueStatisticsFetcher setEndDate(final DateTime endDate) { + public TaskQueueStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ public TaskQueueStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp.. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public TaskQueueStatisticsFetcher setStartDate(final DateTime startDate) { + public TaskQueueStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ public TaskQueueStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - /** - * A comma separated values for viewing splits of tasks canceled and accepted - * above the given threshold in seconds. Ex: "5,30" would show splits of tasks - * that were canceled or accepted before or after 5 seconds and respectively, 30 - * seconds. This is great for showing short abandoned tasks or tasks that failed - * to meet your SLA.. - * - * @param splitByWaitTime A comma separated values for viewing splits of tasks - * canceled and accepted above the given threshold in - * seconds. - * @return this - */ - public TaskQueueStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime) { + public TaskQueueStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched TaskQueueStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public TaskQueueStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/TaskQueues/{TaskQueueSid}/Statistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "TaskQueueSid" + "}", + this.pathTaskQueueSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues/" + this.pathTaskQueueSid + "/Statistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("TaskQueueStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "TaskQueueStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return TaskQueueStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TaskQueueStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TaskQueueStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TaskQueueStatistics content = TaskQueueStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); + Serializer.toString( + request, + "SplitByWaitTime", + splitByWaitTime, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatistics.java index ff8872c02d..1a8aafaa9b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; @@ -11,48 +18,43 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class TaskQueuesStatistics extends Resource { - private static final long serialVersionUID = 212191647411252L; - /** - * Create a TaskQueuesStatisticsReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @return TaskQueuesStatisticsReader capable of executing the read - */ - public static TaskQueuesStatisticsReader reader(final String pathWorkspaceSid) { + public static TaskQueuesStatisticsReader reader( + final String pathWorkspaceSid + ) { return new TaskQueuesStatisticsReader(pathWorkspaceSid); } /** - * Converts a JSON String into a TaskQueuesStatistics object using the provided - * ObjectMapper. - * + * Converts a JSON String into a TaskQueuesStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return TaskQueuesStatistics object represented by the provided JSON */ - public static TaskQueuesStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static TaskQueuesStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueuesStatistics.class); @@ -64,14 +66,17 @@ public static TaskQueuesStatistics fromJson(final String json, final ObjectMappe } /** - * Converts a JSON InputStream into a TaskQueuesStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a TaskQueuesStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return TaskQueuesStatistics object represented by the provided JSON */ - public static TaskQueuesStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static TaskQueuesStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, TaskQueuesStatistics.class); @@ -82,23 +87,41 @@ public static TaskQueuesStatistics fromJson(final InputStream json, final Object } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final Map cumulative; - private final Map realtime; + + @Getter + private final Object cumulative; + + @Getter + private final Object realtime; + + @Getter private final String taskQueueSid; + + @Getter private final String workspaceSid; @JsonCreator - private TaskQueuesStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("cumulative") - final Map cumulative, - @JsonProperty("realtime") - final Map realtime, - @JsonProperty("task_queue_sid") - final String taskQueueSid, - @JsonProperty("workspace_sid") - final String workspaceSid) { + private TaskQueuesStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Object cumulative, + @JsonProperty("realtime") final Object realtime, + @JsonProperty("task_queue_sid") final String taskQueueSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.cumulative = cumulative; this.realtime = realtime; @@ -106,51 +129,6 @@ private TaskQueuesStatistics(@JsonProperty("account_sid") this.workspaceSid = workspaceSid; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The cumulative. - * - * @return The cumulative - */ - public final Map getCumulative() { - return this.cumulative; - } - - /** - * Returns The The realtime. - * - * @return The realtime - */ - public final Map getRealtime() { - return this.realtime; - } - - /** - * Returns The The task_queue_sid. - * - * @return The task_queue_sid - */ - public final String getTaskQueueSid() { - return this.taskQueueSid; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -162,31 +140,23 @@ public boolean equals(final Object o) { } TaskQueuesStatistics other = (TaskQueuesStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(cumulative, other.cumulative) && - Objects.equals(realtime, other.realtime) && - Objects.equals(taskQueueSid, other.taskQueueSid) && - Objects.equals(workspaceSid, other.workspaceSid); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(realtime, other.realtime) && + Objects.equals(taskQueueSid, other.taskQueueSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - cumulative, - realtime, - taskQueueSid, - workspaceSid); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("cumulative", cumulative) - .add("realtime", realtime) - .add("taskQueueSid", taskQueueSid) - .add("workspaceSid", workspaceSid) - .toString(); + return Objects.hash( + accountSid, + cumulative, + realtime, + taskQueueSid, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatisticsReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatisticsReader.java index bc7c25d7ba..2f66b5a2a4 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatisticsReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/taskqueue/TaskQueuesStatisticsReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.taskqueue; @@ -10,269 +17,294 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; -import com.twilio.converter.DateConverter; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class TaskQueuesStatisticsReader extends Reader { - private final String pathWorkspaceSid; - private DateTime endDate; + + private String pathWorkspaceSid; + private ZonedDateTime endDate; private String friendlyName; private Integer minutes; - private DateTime startDate; + private ZonedDateTime startDate; private String taskChannel; private String splitByWaitTime; + private Long pageSize; - /** - * Construct a new TaskQueuesStatisticsReader. - * - * @param pathWorkspaceSid The workspace_sid - */ public TaskQueuesStatisticsReader(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter cumulative statistics by an end date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp.. - * - * @param endDate Filter cumulative statistics by an end date. - * @return this - */ - public TaskQueuesStatisticsReader setEndDate(final DateTime endDate) { + public TaskQueuesStatisticsReader setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Filter the TaskQueue stats based on a TaskQueue’s name (only for list - * resource). - * - * @param friendlyName Filter the TaskQueue stats based on a TaskQueue’s name - * @return this - */ - public TaskQueuesStatisticsReader setFriendlyName(final String friendlyName) { + public TaskQueuesStatisticsReader setFriendlyName( + final String friendlyName + ) { this.friendlyName = friendlyName; return this; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ public TaskQueuesStatisticsReader setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp.. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public TaskQueuesStatisticsReader setStartDate(final DateTime startDate) { + public TaskQueuesStatisticsReader setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ public TaskQueuesStatisticsReader setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - /** - * A comma separated values for viewing splits of tasks canceled and accepted - * above the given threshold in seconds. Ex: "5,30" would show splits of tasks - * that were canceled or accepted before or after 5 seconds and respectively, 30 - * seconds. This is great for showing short abandoned tasks or tasks that failed - * to meet your SLA.. - * - * @param splitByWaitTime A comma separated values for viewing splits of tasks - * canceled and accepted above the given threshold in - * seconds. - * @return this - */ - public TaskQueuesStatisticsReader setSplitByWaitTime(final String splitByWaitTime) { + public TaskQueuesStatisticsReader setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TaskQueuesStatistics ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public TaskQueuesStatisticsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return TaskQueuesStatistics ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "task_queues_statistics", + response.getContent(), + TaskQueuesStatistics.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/TaskQueues/Statistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/TaskQueues/Statistics", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return TaskQueuesStatistics ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "task_queues_statistics", + response.getContent(), + TaskQueuesStatistics.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TaskQueuesStatistics read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "task_queues_statistics", + response.getContent(), + TaskQueuesStatistics.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of TaskQueuesStatistics Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("TaskQueuesStatistics read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "task_queues_statistics", - response.getContent(), - TaskQueuesStatistics.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); + Serializer.toString( + request, + "SplitByWaitTime", + splitByWaitTime, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/Reservation.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/Reservation.java index 3d51130229..57c18f16c1 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/Reservation.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/Reservation.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; @@ -10,32 +17,56 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Reservation extends Resource { - private static final long serialVersionUID = 63448280807644L; + + public static ReservationFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { + return new ReservationFetcher(pathWorkspaceSid, pathWorkerSid, pathSid); + } + + public static ReservationReader reader( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { + return new ReservationReader(pathWorkspaceSid, pathWorkerSid); + } + + public static ReservationUpdater updater( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { + return new ReservationUpdater(pathWorkspaceSid, pathWorkerSid, pathSid); + } public enum Status { PENDING("pending"), @@ -43,7 +74,9 @@ public enum Status { REJECTED("rejected"), TIMEOUT("timeout"), CANCELED("canceled"), - RESCINDED("rescinded"); + RESCINDED("rescinded"), + WRAPPING("wrapping"), + COMPLETED("completed"); private final String value; @@ -51,15 +84,11 @@ private Status(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a Status from a string. - * @param value string value - * @return generated Status - */ @JsonCreator public static Status forValue(final String value) { return Promoter.enumFromString(value, Status.values()); @@ -78,15 +107,11 @@ private CallStatus(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a CallStatus from a string. - * @param value string value - * @return generated CallStatus - */ @JsonCreator public static CallStatus forValue(final String value) { return Promoter.enumFromString(value, CallStatus.values()); @@ -108,15 +133,11 @@ private ConferenceEvent(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a ConferenceEvent from a string. - * @param value string value - * @return generated ConferenceEvent - */ @JsonCreator public static ConferenceEvent forValue(final String value) { return Promoter.enumFromString(value, ConferenceEvent.values()); @@ -124,54 +145,16 @@ public static ConferenceEvent forValue(final String value) { } /** - * Create a ReservationReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @return ReservationReader capable of executing the read - */ - public static ReservationReader reader(final String pathWorkspaceSid, - final String pathWorkerSid) { - return new ReservationReader(pathWorkspaceSid, pathWorkerSid); - } - - /** - * Create a ReservationFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @param pathSid The sid - * @return ReservationFetcher capable of executing the fetch - */ - public static ReservationFetcher fetcher(final String pathWorkspaceSid, - final String pathWorkerSid, - final String pathSid) { - return new ReservationFetcher(pathWorkspaceSid, pathWorkerSid, pathSid); - } - - /** - * Create a ReservationUpdater to execute update. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @param pathSid The sid - * @return ReservationUpdater capable of executing the update - */ - public static ReservationUpdater updater(final String pathWorkspaceSid, - final String pathWorkerSid, - final String pathSid) { - return new ReservationUpdater(pathWorkspaceSid, pathWorkerSid, pathSid); - } - - /** - * Converts a JSON String into a Reservation object using the provided - * ObjectMapper. - * + * Converts a JSON String into a Reservation object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Reservation object represented by the provided JSON */ - public static Reservation fromJson(final String json, final ObjectMapper objectMapper) { + public static Reservation fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Reservation.class); @@ -185,12 +168,15 @@ public static Reservation fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a Reservation object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Reservation object represented by the provided JSON */ - public static Reservation fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Reservation fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Reservation.class); @@ -201,151 +187,88 @@ public static Reservation fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final Map links; + + @Getter private final Reservation.Status reservationStatus; + + @Getter private final String sid; + + @Getter private final String taskSid; + + @Getter + private final URI url; + + @Getter private final String workerName; + + @Getter private final String workerSid; + + @Getter private final String workspaceSid; - private final URI url; - private final Map links; @JsonCreator - private Reservation(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("reservation_status") - final Reservation.Status reservationStatus, - @JsonProperty("sid") - final String sid, - @JsonProperty("task_sid") - final String taskSid, - @JsonProperty("worker_name") - final String workerName, - @JsonProperty("worker_sid") - final String workerSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { + private Reservation( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("links") final Map links, + @JsonProperty( + "reservation_status" + ) final Reservation.Status reservationStatus, + @JsonProperty("sid") final String sid, + @JsonProperty("task_sid") final String taskSid, + @JsonProperty("url") final URI url, + @JsonProperty("worker_name") final String workerName, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.links = links; this.reservationStatus = reservationStatus; this.sid = sid; this.taskSid = taskSid; + this.url = url; this.workerName = workerName; this.workerSid = workerSid; this.workspaceSid = workspaceSid; - this.url = url; - this.links = links; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The Filter by a worker’s reservation status. - * - * @return Filter by a worker’s reservation status - */ - public final Reservation.Status getReservationStatus() { - return this.reservationStatus; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The task_sid. - * - * @return The task_sid - */ - public final String getTaskSid() { - return this.taskSid; - } - - /** - * Returns The The worker_name. - * - * @return The worker_name - */ - public final String getWorkerName() { - return this.workerName; - } - - /** - * Returns The The worker_sid. - * - * @return The worker_sid - */ - public final String getWorkerSid() { - return this.workerSid; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; } @Override @@ -359,49 +282,35 @@ public boolean equals(final Object o) { } Reservation other = (Reservation) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(reservationStatus, other.reservationStatus) && - Objects.equals(sid, other.sid) && - Objects.equals(taskSid, other.taskSid) && - Objects.equals(workerName, other.workerName) && - Objects.equals(workerSid, other.workerSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(links, other.links) && + Objects.equals(reservationStatus, other.reservationStatus) && + Objects.equals(sid, other.sid) && + Objects.equals(taskSid, other.taskSid) && + Objects.equals(url, other.url) && + Objects.equals(workerName, other.workerName) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - dateCreated, - dateUpdated, - reservationStatus, - sid, - taskSid, - workerName, - workerSid, - workspaceSid, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("reservationStatus", reservationStatus) - .add("sid", sid) - .add("taskSid", taskSid) - .add("workerName", workerName) - .add("workerSid", workerSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + links, + reservationStatus, + sid, + taskSid, + url, + workerName, + workerSid, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationFetcher.java index 85e1066bfc..4369909d09 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ReservationFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathWorkerSid; - private final String pathSid; - /** - * Construct a new ReservationFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @param pathSid The sid - */ - public ReservationFetcher(final String pathWorkspaceSid, - final String pathWorkerSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathWorkerSid; + private String pathSid; + + public ReservationFetcher( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Reservation - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Reservation fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathWorkerSid + "/Reservations/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Reservation fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public Reservation fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return Reservation.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Reservation content = Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationReader.java index 79b0a1891c..7d6141c651 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; @@ -10,180 +17,223 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class ReservationReader extends Reader { - private final String pathWorkspaceSid; - private final String pathWorkerSid; + + private String pathWorkspaceSid; + private String pathWorkerSid; private Reservation.Status reservationStatus; + private Long pageSize; - /** - * Construct a new ReservationReader. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - */ - public ReservationReader(final String pathWorkspaceSid, - final String pathWorkerSid) { + public ReservationReader( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; } - /** - * Filter by a worker’s reservation status (pending, accepted, rejected, - * timeout, canceled, rescinded). - * - * @param reservationStatus Filter by a worker’s reservation status - * @return this - */ - public ReservationReader setReservationStatus(final Reservation.Status reservationStatus) { + public ReservationReader setReservationStatus( + final Reservation.Status reservationStatus + ) { this.reservationStatus = reservationStatus; return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Reservation ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public ReservationReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Reservation ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "reservations", + response.getContent(), + Reservation.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathWorkerSid + "/Reservations", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Reservation ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "reservations", + response.getContent(), + Reservation.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Reservation read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "reservations", + response.getContent(), + Reservation.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Reservation Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Reservation read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "reservations", - response.getContent(), - Reservation.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (reservationStatus != null) { - request.addQueryParam("ReservationStatus", reservationStatus.toString()); + Serializer.toString( + request, + "ReservationStatus", + reservationStatus, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); } if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationUpdater.java index 5b9501373c..4fa5f1510b 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/ReservationUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,14 +28,17 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; import java.util.List; public class ReservationUpdater extends Updater { - private final String pathWorkspaceSid; - private final String pathWorkerSid; - private final String pathSid; + + private String pathWorkspaceSid; + private String pathWorkerSid; + private String pathSid; + private String ifMatch; private Reservation.Status reservationStatus; private String workerActivitySid; private String instruction; @@ -74,929 +88,965 @@ public class ReservationUpdater extends Updater { private String sipAuthPassword; private List dequeueStatusCallbackEvent; private String postWorkActivitySid; - - /** - * Construct a new ReservationUpdater. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @param pathSid The sid - */ - public ReservationUpdater(final String pathWorkspaceSid, - final String pathWorkerSid, - final String pathSid) { + private Boolean endConferenceOnCustomerExit; + private Boolean beepOnCustomerEntrance; + private String jitterBufferSize; + + public ReservationUpdater( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; this.pathSid = pathSid; } - /** - * Yes. - * - * @param reservationStatus Yes - * @return this - */ - public ReservationUpdater setReservationStatus(final Reservation.Status reservationStatus) { + public ReservationUpdater setReservationStatus( + final Reservation.Status reservationStatus + ) { this.reservationStatus = reservationStatus; return this; } - /** - * No. - * - * @param workerActivitySid No - * @return this - */ - public ReservationUpdater setWorkerActivitySid(final String workerActivitySid) { + public ReservationUpdater setWorkerActivitySid( + final String workerActivitySid + ) { this.workerActivitySid = workerActivitySid; return this; } - /** - * Yes. - * - * @param instruction Yes - * @return this - */ public ReservationUpdater setInstruction(final String instruction) { this.instruction = instruction; return this; } - /** - * No. - * - * @param dequeuePostWorkActivitySid No - * @return this - */ - public ReservationUpdater setDequeuePostWorkActivitySid(final String dequeuePostWorkActivitySid) { + public ReservationUpdater setDequeuePostWorkActivitySid( + final String dequeuePostWorkActivitySid + ) { this.dequeuePostWorkActivitySid = dequeuePostWorkActivitySid; return this; } - /** - * Yes. - * - * @param dequeueFrom Yes - * @return this - */ public ReservationUpdater setDequeueFrom(final String dequeueFrom) { this.dequeueFrom = dequeueFrom; return this; } - /** - * The dequeue_record. - * - * @param dequeueRecord The dequeue_record - * @return this - */ public ReservationUpdater setDequeueRecord(final String dequeueRecord) { this.dequeueRecord = dequeueRecord; return this; } - /** - * The dequeue_timeout. - * - * @param dequeueTimeout The dequeue_timeout - * @return this - */ public ReservationUpdater setDequeueTimeout(final Integer dequeueTimeout) { this.dequeueTimeout = dequeueTimeout; return this; } - /** - * The dequeue_to. - * - * @param dequeueTo The dequeue_to - * @return this - */ public ReservationUpdater setDequeueTo(final String dequeueTo) { this.dequeueTo = dequeueTo; return this; } - /** - * The dequeue_status_callback_url. - * - * @param dequeueStatusCallbackUrl The dequeue_status_callback_url - * @return this - */ - public ReservationUpdater setDequeueStatusCallbackUrl(final URI dequeueStatusCallbackUrl) { + public ReservationUpdater setDequeueStatusCallbackUrl( + final URI dequeueStatusCallbackUrl + ) { this.dequeueStatusCallbackUrl = dequeueStatusCallbackUrl; return this; } - /** - * The dequeue_status_callback_url. - * - * @param dequeueStatusCallbackUrl The dequeue_status_callback_url - * @return this - */ - public ReservationUpdater setDequeueStatusCallbackUrl(final String dequeueStatusCallbackUrl) { - return setDequeueStatusCallbackUrl(Promoter.uriFromString(dequeueStatusCallbackUrl)); + public ReservationUpdater setDequeueStatusCallbackUrl( + final String dequeueStatusCallbackUrl + ) { + return setDequeueStatusCallbackUrl( + Promoter.uriFromString(dequeueStatusCallbackUrl) + ); } - /** - * Yes. - * - * @param callFrom Yes - * @return this - */ public ReservationUpdater setCallFrom(final String callFrom) { this.callFrom = callFrom; return this; } - /** - * The call_record. - * - * @param callRecord The call_record - * @return this - */ public ReservationUpdater setCallRecord(final String callRecord) { this.callRecord = callRecord; return this; } - /** - * The call_timeout. - * - * @param callTimeout The call_timeout - * @return this - */ public ReservationUpdater setCallTimeout(final Integer callTimeout) { this.callTimeout = callTimeout; return this; } - /** - * The call_to. - * - * @param callTo The call_to - * @return this - */ public ReservationUpdater setCallTo(final String callTo) { this.callTo = callTo; return this; } - /** - * Yes. - * - * @param callUrl Yes - * @return this - */ public ReservationUpdater setCallUrl(final URI callUrl) { this.callUrl = callUrl; return this; } - /** - * Yes. - * - * @param callUrl Yes - * @return this - */ public ReservationUpdater setCallUrl(final String callUrl) { return setCallUrl(Promoter.uriFromString(callUrl)); } - /** - * No. - * - * @param callStatusCallbackUrl No - * @return this - */ - public ReservationUpdater setCallStatusCallbackUrl(final URI callStatusCallbackUrl) { + public ReservationUpdater setCallStatusCallbackUrl( + final URI callStatusCallbackUrl + ) { this.callStatusCallbackUrl = callStatusCallbackUrl; return this; } - /** - * No. - * - * @param callStatusCallbackUrl No - * @return this - */ - public ReservationUpdater setCallStatusCallbackUrl(final String callStatusCallbackUrl) { - return setCallStatusCallbackUrl(Promoter.uriFromString(callStatusCallbackUrl)); + public ReservationUpdater setCallStatusCallbackUrl( + final String callStatusCallbackUrl + ) { + return setCallStatusCallbackUrl( + Promoter.uriFromString(callStatusCallbackUrl) + ); } - /** - * No. - * - * @param callAccept No - * @return this - */ public ReservationUpdater setCallAccept(final Boolean callAccept) { this.callAccept = callAccept; return this; } - /** - * The redirect_call_sid. - * - * @param redirectCallSid The redirect_call_sid - * @return this - */ public ReservationUpdater setRedirectCallSid(final String redirectCallSid) { this.redirectCallSid = redirectCallSid; return this; } - /** - * The redirect_accept. - * - * @param redirectAccept The redirect_accept - * @return this - */ public ReservationUpdater setRedirectAccept(final Boolean redirectAccept) { this.redirectAccept = redirectAccept; return this; } - /** - * The redirect_url. - * - * @param redirectUrl The redirect_url - * @return this - */ public ReservationUpdater setRedirectUrl(final URI redirectUrl) { this.redirectUrl = redirectUrl; return this; } - /** - * The redirect_url. - * - * @param redirectUrl The redirect_url - * @return this - */ public ReservationUpdater setRedirectUrl(final String redirectUrl) { return setRedirectUrl(Promoter.uriFromString(redirectUrl)); } - /** - * The to. - * - * @param to The to - * @return this - */ public ReservationUpdater setTo(final String to) { this.to = to; return this; } - /** - * The from. - * - * @param from The from - * @return this - */ public ReservationUpdater setFrom(final String from) { this.from = from; return this; } - /** - * The status_callback. - * - * @param statusCallback The status_callback - * @return this - */ public ReservationUpdater setStatusCallback(final URI statusCallback) { this.statusCallback = statusCallback; return this; } - /** - * The status_callback. - * - * @param statusCallback The status_callback - * @return this - */ public ReservationUpdater setStatusCallback(final String statusCallback) { return setStatusCallback(Promoter.uriFromString(statusCallback)); } - /** - * The status_callback_method. - * - * @param statusCallbackMethod The status_callback_method - * @return this - */ - public ReservationUpdater setStatusCallbackMethod(final HttpMethod statusCallbackMethod) { + public ReservationUpdater setStatusCallbackMethod( + final HttpMethod statusCallbackMethod + ) { this.statusCallbackMethod = statusCallbackMethod; return this; } - /** - * The status_callback_event. - * - * @param statusCallbackEvent The status_callback_event - * @return this - */ - public ReservationUpdater setStatusCallbackEvent(final List statusCallbackEvent) { + public ReservationUpdater setStatusCallbackEvent( + final List statusCallbackEvent + ) { this.statusCallbackEvent = statusCallbackEvent; return this; } - /** - * The status_callback_event. - * - * @param statusCallbackEvent The status_callback_event - * @return this - */ - public ReservationUpdater setStatusCallbackEvent(final Reservation.CallStatus statusCallbackEvent) { + public ReservationUpdater setStatusCallbackEvent( + final Reservation.CallStatus statusCallbackEvent + ) { return setStatusCallbackEvent(Promoter.listOfOne(statusCallbackEvent)); } - /** - * The timeout. - * - * @param timeout The timeout - * @return this - */ public ReservationUpdater setTimeout(final Integer timeout) { this.timeout = timeout; return this; } - /** - * The record. - * - * @param record The record - * @return this - */ public ReservationUpdater setRecord(final Boolean record) { this.record = record; return this; } - /** - * The muted. - * - * @param muted The muted - * @return this - */ public ReservationUpdater setMuted(final Boolean muted) { this.muted = muted; return this; } - /** - * The beep. - * - * @param beep The beep - * @return this - */ public ReservationUpdater setBeep(final String beep) { this.beep = beep; return this; } - /** - * The start_conference_on_enter. - * - * @param startConferenceOnEnter The start_conference_on_enter - * @return this - */ - public ReservationUpdater setStartConferenceOnEnter(final Boolean startConferenceOnEnter) { + public ReservationUpdater setStartConferenceOnEnter( + final Boolean startConferenceOnEnter + ) { this.startConferenceOnEnter = startConferenceOnEnter; return this; } - /** - * The end_conference_on_exit. - * - * @param endConferenceOnExit The end_conference_on_exit - * @return this - */ - public ReservationUpdater setEndConferenceOnExit(final Boolean endConferenceOnExit) { + public ReservationUpdater setEndConferenceOnExit( + final Boolean endConferenceOnExit + ) { this.endConferenceOnExit = endConferenceOnExit; return this; } - /** - * The wait_url. - * - * @param waitUrl The wait_url - * @return this - */ public ReservationUpdater setWaitUrl(final URI waitUrl) { this.waitUrl = waitUrl; return this; } - /** - * The wait_url. - * - * @param waitUrl The wait_url - * @return this - */ public ReservationUpdater setWaitUrl(final String waitUrl) { return setWaitUrl(Promoter.uriFromString(waitUrl)); } - /** - * The wait_method. - * - * @param waitMethod The wait_method - * @return this - */ public ReservationUpdater setWaitMethod(final HttpMethod waitMethod) { this.waitMethod = waitMethod; return this; } - /** - * The early_media. - * - * @param earlyMedia The early_media - * @return this - */ public ReservationUpdater setEarlyMedia(final Boolean earlyMedia) { this.earlyMedia = earlyMedia; return this; } - /** - * The max_participants. - * - * @param maxParticipants The max_participants - * @return this - */ - public ReservationUpdater setMaxParticipants(final Integer maxParticipants) { + public ReservationUpdater setMaxParticipants( + final Integer maxParticipants + ) { this.maxParticipants = maxParticipants; return this; } - /** - * The conference_status_callback. - * - * @param conferenceStatusCallback The conference_status_callback - * @return this - */ - public ReservationUpdater setConferenceStatusCallback(final URI conferenceStatusCallback) { + public ReservationUpdater setConferenceStatusCallback( + final URI conferenceStatusCallback + ) { this.conferenceStatusCallback = conferenceStatusCallback; return this; } - /** - * The conference_status_callback. - * - * @param conferenceStatusCallback The conference_status_callback - * @return this - */ - public ReservationUpdater setConferenceStatusCallback(final String conferenceStatusCallback) { - return setConferenceStatusCallback(Promoter.uriFromString(conferenceStatusCallback)); + public ReservationUpdater setConferenceStatusCallback( + final String conferenceStatusCallback + ) { + return setConferenceStatusCallback( + Promoter.uriFromString(conferenceStatusCallback) + ); } - /** - * The conference_status_callback_method. - * - * @param conferenceStatusCallbackMethod The conference_status_callback_method - * @return this - */ - public ReservationUpdater setConferenceStatusCallbackMethod(final HttpMethod conferenceStatusCallbackMethod) { + public ReservationUpdater setConferenceStatusCallbackMethod( + final HttpMethod conferenceStatusCallbackMethod + ) { this.conferenceStatusCallbackMethod = conferenceStatusCallbackMethod; return this; } - /** - * The conference_status_callback_event. - * - * @param conferenceStatusCallbackEvent The conference_status_callback_event - * @return this - */ - public ReservationUpdater setConferenceStatusCallbackEvent(final List conferenceStatusCallbackEvent) { + public ReservationUpdater setConferenceStatusCallbackEvent( + final List conferenceStatusCallbackEvent + ) { this.conferenceStatusCallbackEvent = conferenceStatusCallbackEvent; return this; } - /** - * The conference_status_callback_event. - * - * @param conferenceStatusCallbackEvent The conference_status_callback_event - * @return this - */ - public ReservationUpdater setConferenceStatusCallbackEvent(final Reservation.ConferenceEvent conferenceStatusCallbackEvent) { - return setConferenceStatusCallbackEvent(Promoter.listOfOne(conferenceStatusCallbackEvent)); + public ReservationUpdater setConferenceStatusCallbackEvent( + final Reservation.ConferenceEvent conferenceStatusCallbackEvent + ) { + return setConferenceStatusCallbackEvent( + Promoter.listOfOne(conferenceStatusCallbackEvent) + ); } - /** - * The conference_record. - * - * @param conferenceRecord The conference_record - * @return this - */ - public ReservationUpdater setConferenceRecord(final String conferenceRecord) { + public ReservationUpdater setConferenceRecord( + final String conferenceRecord + ) { this.conferenceRecord = conferenceRecord; return this; } - /** - * The conference_trim. - * - * @param conferenceTrim The conference_trim - * @return this - */ public ReservationUpdater setConferenceTrim(final String conferenceTrim) { this.conferenceTrim = conferenceTrim; return this; } - /** - * The recording_channels. - * - * @param recordingChannels The recording_channels - * @return this - */ - public ReservationUpdater setRecordingChannels(final String recordingChannels) { + public ReservationUpdater setRecordingChannels( + final String recordingChannels + ) { this.recordingChannels = recordingChannels; return this; } - /** - * The recording_status_callback. - * - * @param recordingStatusCallback The recording_status_callback - * @return this - */ - public ReservationUpdater setRecordingStatusCallback(final URI recordingStatusCallback) { + public ReservationUpdater setRecordingStatusCallback( + final URI recordingStatusCallback + ) { this.recordingStatusCallback = recordingStatusCallback; return this; } - /** - * The recording_status_callback. - * - * @param recordingStatusCallback The recording_status_callback - * @return this - */ - public ReservationUpdater setRecordingStatusCallback(final String recordingStatusCallback) { - return setRecordingStatusCallback(Promoter.uriFromString(recordingStatusCallback)); + public ReservationUpdater setRecordingStatusCallback( + final String recordingStatusCallback + ) { + return setRecordingStatusCallback( + Promoter.uriFromString(recordingStatusCallback) + ); } - /** - * The recording_status_callback_method. - * - * @param recordingStatusCallbackMethod The recording_status_callback_method - * @return this - */ - public ReservationUpdater setRecordingStatusCallbackMethod(final HttpMethod recordingStatusCallbackMethod) { + public ReservationUpdater setRecordingStatusCallbackMethod( + final HttpMethod recordingStatusCallbackMethod + ) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; } - /** - * The conference_recording_status_callback. - * - * @param conferenceRecordingStatusCallback The - * conference_recording_status_callback - * @return this - */ - public ReservationUpdater setConferenceRecordingStatusCallback(final URI conferenceRecordingStatusCallback) { - this.conferenceRecordingStatusCallback = conferenceRecordingStatusCallback; + public ReservationUpdater setConferenceRecordingStatusCallback( + final URI conferenceRecordingStatusCallback + ) { + this.conferenceRecordingStatusCallback = + conferenceRecordingStatusCallback; return this; } - /** - * The conference_recording_status_callback. - * - * @param conferenceRecordingStatusCallback The - * conference_recording_status_callback - * @return this - */ - public ReservationUpdater setConferenceRecordingStatusCallback(final String conferenceRecordingStatusCallback) { - return setConferenceRecordingStatusCallback(Promoter.uriFromString(conferenceRecordingStatusCallback)); + public ReservationUpdater setConferenceRecordingStatusCallback( + final String conferenceRecordingStatusCallback + ) { + return setConferenceRecordingStatusCallback( + Promoter.uriFromString(conferenceRecordingStatusCallback) + ); } - /** - * The conference_recording_status_callback_method. - * - * @param conferenceRecordingStatusCallbackMethod The - * conference_recording_status_callback_method - * @return this - */ - public ReservationUpdater setConferenceRecordingStatusCallbackMethod(final HttpMethod conferenceRecordingStatusCallbackMethod) { - this.conferenceRecordingStatusCallbackMethod = conferenceRecordingStatusCallbackMethod; + public ReservationUpdater setConferenceRecordingStatusCallbackMethod( + final HttpMethod conferenceRecordingStatusCallbackMethod + ) { + this.conferenceRecordingStatusCallbackMethod = + conferenceRecordingStatusCallbackMethod; return this; } - /** - * The region. - * - * @param region The region - * @return this - */ public ReservationUpdater setRegion(final String region) { this.region = region; return this; } - /** - * The sip_auth_username. - * - * @param sipAuthUsername The sip_auth_username - * @return this - */ public ReservationUpdater setSipAuthUsername(final String sipAuthUsername) { this.sipAuthUsername = sipAuthUsername; return this; } - /** - * The sip_auth_password. - * - * @param sipAuthPassword The sip_auth_password - * @return this - */ public ReservationUpdater setSipAuthPassword(final String sipAuthPassword) { this.sipAuthPassword = sipAuthPassword; return this; } - /** - * The dequeue_status_callback_event. - * - * @param dequeueStatusCallbackEvent The dequeue_status_callback_event - * @return this - */ - public ReservationUpdater setDequeueStatusCallbackEvent(final List dequeueStatusCallbackEvent) { + public ReservationUpdater setDequeueStatusCallbackEvent( + final List dequeueStatusCallbackEvent + ) { this.dequeueStatusCallbackEvent = dequeueStatusCallbackEvent; return this; } - /** - * The dequeue_status_callback_event. - * - * @param dequeueStatusCallbackEvent The dequeue_status_callback_event - * @return this - */ - public ReservationUpdater setDequeueStatusCallbackEvent(final String dequeueStatusCallbackEvent) { - return setDequeueStatusCallbackEvent(Promoter.listOfOne(dequeueStatusCallbackEvent)); + public ReservationUpdater setDequeueStatusCallbackEvent( + final String dequeueStatusCallbackEvent + ) { + return setDequeueStatusCallbackEvent( + Promoter.listOfOne(dequeueStatusCallbackEvent) + ); } - /** - * The post_work_activity_sid. - * - * @param postWorkActivitySid The post_work_activity_sid - * @return this - */ - public ReservationUpdater setPostWorkActivitySid(final String postWorkActivitySid) { + public ReservationUpdater setPostWorkActivitySid( + final String postWorkActivitySid + ) { this.postWorkActivitySid = postWorkActivitySid; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Reservation - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Reservation update(final TwilioRestClient client) { + public ReservationUpdater setEndConferenceOnCustomerExit( + final Boolean endConferenceOnCustomerExit + ) { + this.endConferenceOnCustomerExit = endConferenceOnCustomerExit; + return this; + } + + public ReservationUpdater setBeepOnCustomerEntrance( + final Boolean beepOnCustomerEntrance + ) { + this.beepOnCustomerEntrance = beepOnCustomerEntrance; + return this; + } + + public ReservationUpdater setJitterBufferSize( + final String jitterBufferSize + ) { + this.jitterBufferSize = jitterBufferSize; + return this; + } + + public ReservationUpdater setIfMatch(final String ifMatch) { + this.ifMatch = ifMatch; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Reservations/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathWorkerSid + "/Reservations/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addHeaderParams(request); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Reservation update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Reservation update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return Reservation.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public Reservation update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Reservation content = Reservation.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (reservationStatus != null) { - request.addPostParam("ReservationStatus", reservationStatus.toString()); + Serializer.toString( + request, + "ReservationStatus", + reservationStatus, + ParameterType.URLENCODED + ); } if (workerActivitySid != null) { - request.addPostParam("WorkerActivitySid", workerActivitySid); + Serializer.toString( + request, + "WorkerActivitySid", + workerActivitySid, + ParameterType.URLENCODED + ); } if (instruction != null) { - request.addPostParam("Instruction", instruction); + Serializer.toString( + request, + "Instruction", + instruction, + ParameterType.URLENCODED + ); } if (dequeuePostWorkActivitySid != null) { - request.addPostParam("DequeuePostWorkActivitySid", dequeuePostWorkActivitySid); + Serializer.toString( + request, + "DequeuePostWorkActivitySid", + dequeuePostWorkActivitySid, + ParameterType.URLENCODED + ); } if (dequeueFrom != null) { - request.addPostParam("DequeueFrom", dequeueFrom); + Serializer.toString( + request, + "DequeueFrom", + dequeueFrom, + ParameterType.URLENCODED + ); } if (dequeueRecord != null) { - request.addPostParam("DequeueRecord", dequeueRecord); + Serializer.toString( + request, + "DequeueRecord", + dequeueRecord, + ParameterType.URLENCODED + ); } if (dequeueTimeout != null) { - request.addPostParam("DequeueTimeout", dequeueTimeout.toString()); + Serializer.toString( + request, + "DequeueTimeout", + dequeueTimeout, + ParameterType.URLENCODED + ); } if (dequeueTo != null) { - request.addPostParam("DequeueTo", dequeueTo); + Serializer.toString( + request, + "DequeueTo", + dequeueTo, + ParameterType.URLENCODED + ); } if (dequeueStatusCallbackUrl != null) { - request.addPostParam("DequeueStatusCallbackUrl", dequeueStatusCallbackUrl.toString()); + Serializer.toString( + request, + "DequeueStatusCallbackUrl", + dequeueStatusCallbackUrl, + ParameterType.URLENCODED + ); } if (callFrom != null) { - request.addPostParam("CallFrom", callFrom); + Serializer.toString( + request, + "CallFrom", + callFrom, + ParameterType.URLENCODED + ); } if (callRecord != null) { - request.addPostParam("CallRecord", callRecord); + Serializer.toString( + request, + "CallRecord", + callRecord, + ParameterType.URLENCODED + ); } if (callTimeout != null) { - request.addPostParam("CallTimeout", callTimeout.toString()); + Serializer.toString( + request, + "CallTimeout", + callTimeout, + ParameterType.URLENCODED + ); } if (callTo != null) { - request.addPostParam("CallTo", callTo); + Serializer.toString( + request, + "CallTo", + callTo, + ParameterType.URLENCODED + ); } if (callUrl != null) { - request.addPostParam("CallUrl", callUrl.toString()); + Serializer.toString( + request, + "CallUrl", + callUrl, + ParameterType.URLENCODED + ); } if (callStatusCallbackUrl != null) { - request.addPostParam("CallStatusCallbackUrl", callStatusCallbackUrl.toString()); + Serializer.toString( + request, + "CallStatusCallbackUrl", + callStatusCallbackUrl, + ParameterType.URLENCODED + ); } if (callAccept != null) { - request.addPostParam("CallAccept", callAccept.toString()); + Serializer.toString( + request, + "CallAccept", + callAccept, + ParameterType.URLENCODED + ); } if (redirectCallSid != null) { - request.addPostParam("RedirectCallSid", redirectCallSid); + Serializer.toString( + request, + "RedirectCallSid", + redirectCallSid, + ParameterType.URLENCODED + ); } if (redirectAccept != null) { - request.addPostParam("RedirectAccept", redirectAccept.toString()); + Serializer.toString( + request, + "RedirectAccept", + redirectAccept, + ParameterType.URLENCODED + ); } if (redirectUrl != null) { - request.addPostParam("RedirectUrl", redirectUrl.toString()); + Serializer.toString( + request, + "RedirectUrl", + redirectUrl, + ParameterType.URLENCODED + ); } if (to != null) { - request.addPostParam("To", to); + Serializer.toString(request, "To", to, ParameterType.URLENCODED); } if (from != null) { - request.addPostParam("From", from); + Serializer.toString( + request, + "From", + from, + ParameterType.URLENCODED + ); } if (statusCallback != null) { - request.addPostParam("StatusCallback", statusCallback.toString()); + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); } if (statusCallbackMethod != null) { - request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString()); + Serializer.toString( + request, + "StatusCallbackMethod", + statusCallbackMethod, + ParameterType.URLENCODED + ); } if (statusCallbackEvent != null) { - for (Reservation.CallStatus prop : statusCallbackEvent) { - request.addPostParam("StatusCallbackEvent", prop.toString()); + for (Reservation.CallStatus param : statusCallbackEvent) { + Serializer.toString( + request, + "StatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (timeout != null) { - request.addPostParam("Timeout", timeout.toString()); + Serializer.toString( + request, + "Timeout", + timeout, + ParameterType.URLENCODED + ); } if (record != null) { - request.addPostParam("Record", record.toString()); + Serializer.toString( + request, + "Record", + record, + ParameterType.URLENCODED + ); } if (muted != null) { - request.addPostParam("Muted", muted.toString()); + Serializer.toString( + request, + "Muted", + muted, + ParameterType.URLENCODED + ); } if (beep != null) { - request.addPostParam("Beep", beep); + Serializer.toString( + request, + "Beep", + beep, + ParameterType.URLENCODED + ); } if (startConferenceOnEnter != null) { - request.addPostParam("StartConferenceOnEnter", startConferenceOnEnter.toString()); + Serializer.toString( + request, + "StartConferenceOnEnter", + startConferenceOnEnter, + ParameterType.URLENCODED + ); } if (endConferenceOnExit != null) { - request.addPostParam("EndConferenceOnExit", endConferenceOnExit.toString()); + Serializer.toString( + request, + "EndConferenceOnExit", + endConferenceOnExit, + ParameterType.URLENCODED + ); } if (waitUrl != null) { - request.addPostParam("WaitUrl", waitUrl.toString()); + Serializer.toString( + request, + "WaitUrl", + waitUrl, + ParameterType.URLENCODED + ); } if (waitMethod != null) { - request.addPostParam("WaitMethod", waitMethod.toString()); + Serializer.toString( + request, + "WaitMethod", + waitMethod, + ParameterType.URLENCODED + ); } if (earlyMedia != null) { - request.addPostParam("EarlyMedia", earlyMedia.toString()); + Serializer.toString( + request, + "EarlyMedia", + earlyMedia, + ParameterType.URLENCODED + ); } if (maxParticipants != null) { - request.addPostParam("MaxParticipants", maxParticipants.toString()); + Serializer.toString( + request, + "MaxParticipants", + maxParticipants, + ParameterType.URLENCODED + ); } if (conferenceStatusCallback != null) { - request.addPostParam("ConferenceStatusCallback", conferenceStatusCallback.toString()); + Serializer.toString( + request, + "ConferenceStatusCallback", + conferenceStatusCallback, + ParameterType.URLENCODED + ); } if (conferenceStatusCallbackMethod != null) { - request.addPostParam("ConferenceStatusCallbackMethod", conferenceStatusCallbackMethod.toString()); + Serializer.toString( + request, + "ConferenceStatusCallbackMethod", + conferenceStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (conferenceStatusCallbackEvent != null) { - for (Reservation.ConferenceEvent prop : conferenceStatusCallbackEvent) { - request.addPostParam("ConferenceStatusCallbackEvent", prop.toString()); + for (Reservation.ConferenceEvent param : conferenceStatusCallbackEvent) { + Serializer.toString( + request, + "ConferenceStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (conferenceRecord != null) { - request.addPostParam("ConferenceRecord", conferenceRecord); + Serializer.toString( + request, + "ConferenceRecord", + conferenceRecord, + ParameterType.URLENCODED + ); } if (conferenceTrim != null) { - request.addPostParam("ConferenceTrim", conferenceTrim); + Serializer.toString( + request, + "ConferenceTrim", + conferenceTrim, + ParameterType.URLENCODED + ); } if (recordingChannels != null) { - request.addPostParam("RecordingChannels", recordingChannels); + Serializer.toString( + request, + "RecordingChannels", + recordingChannels, + ParameterType.URLENCODED + ); } if (recordingStatusCallback != null) { - request.addPostParam("RecordingStatusCallback", recordingStatusCallback.toString()); + Serializer.toString( + request, + "RecordingStatusCallback", + recordingStatusCallback, + ParameterType.URLENCODED + ); } if (recordingStatusCallbackMethod != null) { - request.addPostParam("RecordingStatusCallbackMethod", recordingStatusCallbackMethod.toString()); + Serializer.toString( + request, + "RecordingStatusCallbackMethod", + recordingStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (conferenceRecordingStatusCallback != null) { - request.addPostParam("ConferenceRecordingStatusCallback", conferenceRecordingStatusCallback.toString()); + Serializer.toString( + request, + "ConferenceRecordingStatusCallback", + conferenceRecordingStatusCallback, + ParameterType.URLENCODED + ); } if (conferenceRecordingStatusCallbackMethod != null) { - request.addPostParam("ConferenceRecordingStatusCallbackMethod", conferenceRecordingStatusCallbackMethod.toString()); + Serializer.toString( + request, + "ConferenceRecordingStatusCallbackMethod", + conferenceRecordingStatusCallbackMethod, + ParameterType.URLENCODED + ); } if (region != null) { - request.addPostParam("Region", region); + Serializer.toString( + request, + "Region", + region, + ParameterType.URLENCODED + ); } if (sipAuthUsername != null) { - request.addPostParam("SipAuthUsername", sipAuthUsername); + Serializer.toString( + request, + "SipAuthUsername", + sipAuthUsername, + ParameterType.URLENCODED + ); } if (sipAuthPassword != null) { - request.addPostParam("SipAuthPassword", sipAuthPassword); + Serializer.toString( + request, + "SipAuthPassword", + sipAuthPassword, + ParameterType.URLENCODED + ); } if (dequeueStatusCallbackEvent != null) { - for (String prop : dequeueStatusCallbackEvent) { - request.addPostParam("DequeueStatusCallbackEvent", prop); + for (String param : dequeueStatusCallbackEvent) { + Serializer.toString( + request, + "DequeueStatusCallbackEvent", + param, + ParameterType.URLENCODED + ); } } if (postWorkActivitySid != null) { - request.addPostParam("PostWorkActivitySid", postWorkActivitySid); + Serializer.toString( + request, + "PostWorkActivitySid", + postWorkActivitySid, + ParameterType.URLENCODED + ); + } + + if (endConferenceOnCustomerExit != null) { + Serializer.toString( + request, + "EndConferenceOnCustomerExit", + endConferenceOnCustomerExit, + ParameterType.URLENCODED + ); + } + + if (beepOnCustomerEntrance != null) { + Serializer.toString( + request, + "BeepOnCustomerEntrance", + beepOnCustomerEntrance, + ParameterType.URLENCODED + ); + } + + if (jitterBufferSize != null) { + Serializer.toString( + request, + "JitterBufferSize", + jitterBufferSize, + ParameterType.URLENCODED + ); + } + } + + private void addHeaderParams(final Request request) { + if (ifMatch != null) { + Serializer.toString( + request, + "If-Match", + ifMatch, + ParameterType.HEADER + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannel.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannel.java index f867a06a1f..fa317427cb 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannel.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannel.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; @@ -11,80 +18,72 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkerChannel extends Resource { - private static final long serialVersionUID = 181596062682267L; - /** - * Create a WorkerChannelReader to execute read. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @return WorkerChannelReader capable of executing the read - */ - public static WorkerChannelReader reader(final String pathWorkspaceSid, - final String pathWorkerSid) { - return new WorkerChannelReader(pathWorkspaceSid, pathWorkerSid); + public static WorkerChannelFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { + return new WorkerChannelFetcher( + pathWorkspaceSid, + pathWorkerSid, + pathSid + ); } - /** - * Create a WorkerChannelFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @param pathSid The sid - * @return WorkerChannelFetcher capable of executing the fetch - */ - public static WorkerChannelFetcher fetcher(final String pathWorkspaceSid, - final String pathWorkerSid, - final String pathSid) { - return new WorkerChannelFetcher(pathWorkspaceSid, pathWorkerSid, pathSid); + public static WorkerChannelReader reader( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { + return new WorkerChannelReader(pathWorkspaceSid, pathWorkerSid); } - /** - * Create a WorkerChannelUpdater to execute update. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @param pathSid The sid - * @return WorkerChannelUpdater capable of executing the update - */ - public static WorkerChannelUpdater updater(final String pathWorkspaceSid, - final String pathWorkerSid, - final String pathSid) { - return new WorkerChannelUpdater(pathWorkspaceSid, pathWorkerSid, pathSid); + public static WorkerChannelUpdater updater( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { + return new WorkerChannelUpdater( + pathWorkspaceSid, + pathWorkerSid, + pathSid + ); } /** - * Converts a JSON String into a WorkerChannel object using the provided - * ObjectMapper. - * + * Converts a JSON String into a WorkerChannel object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkerChannel object represented by the provided JSON */ - public static WorkerChannel fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkerChannel fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkerChannel.class); @@ -98,12 +97,15 @@ public static WorkerChannel fromJson(final String json, final ObjectMapper objec /** * Converts a JSON InputStream into a WorkerChannel object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkerChannel object represented by the provided JSON */ - public static WorkerChannel fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkerChannel fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkerChannel.class); @@ -114,183 +116,100 @@ public static WorkerChannel fromJson(final InputStream json, final ObjectMapper } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final Integer assignedTasks; + + @Getter private final Boolean available; + + @Getter private final Integer availableCapacityPercentage; + + @Getter private final Integer configuredCapacity; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String sid; + + @Getter private final String taskChannelSid; + + @Getter private final String taskChannelUniqueName; + + @Getter + private final URI url; + + @Getter private final String workerSid; + + @Getter private final String workspaceSid; - private final URI url; @JsonCreator - private WorkerChannel(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("assigned_tasks") - final Integer assignedTasks, - @JsonProperty("available") - final Boolean available, - @JsonProperty("available_capacity_percentage") - final Integer availableCapacityPercentage, - @JsonProperty("configured_capacity") - final Integer configuredCapacity, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("sid") - final String sid, - @JsonProperty("task_channel_sid") - final String taskChannelSid, - @JsonProperty("task_channel_unique_name") - final String taskChannelUniqueName, - @JsonProperty("worker_sid") - final String workerSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private WorkerChannel( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("assigned_tasks") final Integer assignedTasks, + @JsonProperty("available") final Boolean available, + @JsonProperty( + "available_capacity_percentage" + ) final Integer availableCapacityPercentage, + @JsonProperty("configured_capacity") final Integer configuredCapacity, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("sid") final String sid, + @JsonProperty("task_channel_sid") final String taskChannelSid, + @JsonProperty( + "task_channel_unique_name" + ) final String taskChannelUniqueName, + @JsonProperty("url") final URI url, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.assignedTasks = assignedTasks; this.available = available; this.availableCapacityPercentage = availableCapacityPercentage; this.configuredCapacity = configuredCapacity; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.sid = sid; this.taskChannelSid = taskChannelSid; this.taskChannelUniqueName = taskChannelUniqueName; + this.url = url; this.workerSid = workerSid; this.workspaceSid = workspaceSid; - this.url = url; - } - - /** - * Returns The The unique ID of the Account that owns this WorkerChannel.. - * - * @return The unique ID of the Account that owns this WorkerChannel. - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The total number of tasks assigned to Worker for this TaskChannel - * type.. - * - * @return The total number of tasks assigned to Worker for this TaskChannel - * type. - */ - public final Integer getAssignedTasks() { - return this.assignedTasks; - } - - /** - * Returns The Boolean value indicating whether the worker should receive Tasks - * of this TaskChannel type.. - * - * @return Boolean value indicating whether the worker should receive Tasks of - * this TaskChannel type. - */ - public final Boolean getAvailable() { - return this.available; - } - - /** - * Returns The The current available capacity between 0 to 100 for this - * TaskChannel.. - * - * @return The current available capacity between 0 to 100 for this TaskChannel. - */ - public final Integer getAvailableCapacityPercentage() { - return this.availableCapacityPercentage; - } - - /** - * Returns The The current configured capacity for the WorkerChannel.. - * - * @return The current configured capacity for the WorkerChannel. - */ - public final Integer getConfiguredCapacity() { - return this.configuredCapacity; - } - - /** - * Returns The The date this Activity was created.. - * - * @return The date this Activity was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this Activity was updated.. - * - * @return The date this Activity was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The unique ID for this WorkerChannel.. - * - * @return The unique ID for this WorkerChannel. - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique ID of the TaskChannel.. - * - * @return The unique ID of the TaskChannel. - */ - public final String getTaskChannelSid() { - return this.taskChannelSid; - } - - /** - * Returns The The unique name of TaskChannel, such as 'voice', 'sms', etc.. - * - * @return The unique name of TaskChannel, such as 'voice', 'sms', etc. - */ - public final String getTaskChannelUniqueName() { - return this.taskChannelUniqueName; - } - - /** - * Returns The The unique ID of the Worker that this WorkerChannel belongs to.. - * - * @return The unique ID of the Worker that this WorkerChannel belongs to. - */ - public final String getWorkerSid() { - return this.workerSid; - } - - /** - * Returns The The unique ID of the Workspace that this WorkerChannel belongs - * to.. - * - * @return The unique ID of the Workspace that this WorkerChannel belongs to. - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; } @Override @@ -304,55 +223,45 @@ public boolean equals(final Object o) { } WorkerChannel other = (WorkerChannel) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(assignedTasks, other.assignedTasks) && - Objects.equals(available, other.available) && - Objects.equals(availableCapacityPercentage, other.availableCapacityPercentage) && - Objects.equals(configuredCapacity, other.configuredCapacity) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(sid, other.sid) && - Objects.equals(taskChannelSid, other.taskChannelSid) && - Objects.equals(taskChannelUniqueName, other.taskChannelUniqueName) && - Objects.equals(workerSid, other.workerSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(assignedTasks, other.assignedTasks) && + Objects.equals(available, other.available) && + Objects.equals( + availableCapacityPercentage, + other.availableCapacityPercentage + ) && + Objects.equals(configuredCapacity, other.configuredCapacity) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(sid, other.sid) && + Objects.equals(taskChannelSid, other.taskChannelSid) && + Objects.equals( + taskChannelUniqueName, + other.taskChannelUniqueName + ) && + Objects.equals(url, other.url) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - assignedTasks, - available, - availableCapacityPercentage, - configuredCapacity, - dateCreated, - dateUpdated, - sid, - taskChannelSid, - taskChannelUniqueName, - workerSid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("assignedTasks", assignedTasks) - .add("available", available) - .add("availableCapacityPercentage", availableCapacityPercentage) - .add("configuredCapacity", configuredCapacity) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("sid", sid) - .add("taskChannelSid", taskChannelSid) - .add("taskChannelUniqueName", taskChannelUniqueName) - .add("workerSid", workerSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + assignedTasks, + available, + availableCapacityPercentage, + configuredCapacity, + dateCreated, + dateUpdated, + sid, + taskChannelSid, + taskChannelUniqueName, + url, + workerSid, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelFetcher.java index be9dfd615b..22624736c8 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,62 +24,92 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkerChannelFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathWorkerSid; - private final String pathSid; - /** - * Construct a new WorkerChannelFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @param pathSid The sid - */ - public WorkerChannelFetcher(final String pathWorkspaceSid, - final String pathWorkerSid, - final String pathSid) { + private String pathWorkspaceSid; + private String pathWorkerSid; + private String pathSid; + + public WorkerChannelFetcher( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkerChannel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkerChannel fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathWorkerSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkerChannel fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkerChannel fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public WorkerChannel fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkerChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return WorkerChannel.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkerChannel content = WorkerChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelReader.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelReader.java index da0f0f0004..3b2515dbe8 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelReader.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; @@ -10,163 +17,206 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkerChannelReader extends Reader { - private final String pathWorkspaceSid; - private final String pathWorkerSid; - - /** - * Construct a new WorkerChannelReader. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - */ - public WorkerChannelReader(final String pathWorkspaceSid, - final String pathWorkerSid) { + + private String pathWorkspaceSid; + private String pathWorkerSid; + private Long pageSize; + + public WorkerChannelReader( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return WorkerChannel ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public WorkerChannelReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return WorkerChannel ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + WorkerChannel.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathWorkerSid + "/Channels", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return WorkerChannel ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "channels", + response.getContent(), + WorkerChannel.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "WorkerChannel read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "channels", + response.getContent(), + WorkerChannel.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TASKROUTER.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of WorkerChannel Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("WorkerChannel read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "channels", - response.getContent(), - WorkerChannel.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelUpdater.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelUpdater.java index 3c0cfd642c..0889a1bf11 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelUpdater.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerChannelUpdater.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,107 +27,126 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class WorkerChannelUpdater extends Updater { - private final String pathWorkspaceSid; - private final String pathWorkerSid; - private final String pathSid; + + private String pathWorkspaceSid; + private String pathWorkerSid; + private String pathSid; private Integer capacity; private Boolean available; - /** - * Construct a new WorkerChannelUpdater. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @param pathSid The sid - */ - public WorkerChannelUpdater(final String pathWorkspaceSid, - final String pathWorkerSid, - final String pathSid) { + public WorkerChannelUpdater( + final String pathWorkspaceSid, + final String pathWorkerSid, + final String pathSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; this.pathSid = pathSid; } - /** - * The total number of Tasks worker should handle for this TaskChannel type. - * TaskRouter will only create reservations for Tasks of this TaskChannel type - * up to the capacity configured. If the capacity is 0, no new reservations will - * be created. - * - * @param capacity The total number of Tasks worker should handle for this - * TaskChannel type. - * @return this - */ public WorkerChannelUpdater setCapacity(final Integer capacity) { this.capacity = capacity; return this; } - /** - * Toggle the availability of the WorkerChannel. Set this to 'False' to make - * worker unavailable to receive any new Tasks of this TaskChannel type.. - * - * @param available Toggle the availability of the WorkerChannel. - * @return this - */ public WorkerChannelUpdater setAvailable(final Boolean available) { this.available = available; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated WorkerChannel - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkerChannel update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Channels/{Sid}"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathWorkerSid + "/Channels/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkerChannel update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkerChannel update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public WorkerChannel update(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkerChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return WorkerChannel.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkerChannel content = WorkerChannel.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (capacity != null) { - request.addPostParam("Capacity", capacity.toString()); + Serializer.toString( + request, + "Capacity", + capacity, + ParameterType.URLENCODED + ); } if (available != null) { - request.addPostParam("Available", available.toString()); + Serializer.toString( + request, + "Available", + available, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatistics.java index 2369011068..b10cb24227 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; @@ -11,51 +18,45 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkerStatistics extends Resource { - private static final long serialVersionUID = 174560494604680L; - /** - * Create a WorkerStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - * @return WorkerStatisticsFetcher capable of executing the fetch - */ - public static WorkerStatisticsFetcher fetcher(final String pathWorkspaceSid, - final String pathWorkerSid) { + public static WorkerStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { return new WorkerStatisticsFetcher(pathWorkspaceSid, pathWorkerSid); } /** - * Converts a JSON String into a WorkerStatistics object using the provided - * ObjectMapper. - * + * Converts a JSON String into a WorkerStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkerStatistics object represented by the provided JSON */ - public static WorkerStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkerStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkerStatistics.class); @@ -69,12 +70,15 @@ public static WorkerStatistics fromJson(final String json, final ObjectMapper ob /** * Converts a JSON InputStream into a WorkerStatistics object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkerStatistics object represented by the provided JSON */ - public static WorkerStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkerStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkerStatistics.class); @@ -85,73 +89,46 @@ public static WorkerStatistics fromJson(final InputStream json, final ObjectMapp } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final Map cumulative; + + @Getter + private final Object cumulative; + + @Getter + private final URI url; + + @Getter private final String workerSid; + + @Getter private final String workspaceSid; - private final URI url; @JsonCreator - private WorkerStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("cumulative") - final Map cumulative, - @JsonProperty("worker_sid") - final String workerSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private WorkerStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Object cumulative, + @JsonProperty("url") final URI url, + @JsonProperty("worker_sid") final String workerSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.cumulative = cumulative; + this.url = url; this.workerSid = workerSid; this.workspaceSid = workspaceSid; - this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The cumulative. - * - * @return The cumulative - */ - public final Map getCumulative() { - return this.cumulative; - } - - /** - * Returns The The worker_sid. - * - * @return The worker_sid - */ - public final String getWorkerSid() { - return this.workerSid; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; } @Override @@ -165,31 +142,23 @@ public boolean equals(final Object o) { } WorkerStatistics other = (WorkerStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(cumulative, other.cumulative) && - Objects.equals(workerSid, other.workerSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(url, other.url) && + Objects.equals(workerSid, other.workerSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - cumulative, - workerSid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("cumulative", cumulative) - .add("workerSid", workerSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + cumulative, + url, + workerSid, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatisticsFetcher.java index edeb89cb67..f07eb08710 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkerStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,138 +26,152 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class WorkerStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathWorkerSid; + + private String pathWorkspaceSid; + private String pathWorkerSid; private Integer minutes; - private DateTime startDate; - private DateTime endDate; + private ZonedDateTime startDate; + private ZonedDateTime endDate; private String taskChannel; - /** - * Construct a new WorkerStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkerSid The worker_sid - */ - public WorkerStatisticsFetcher(final String pathWorkspaceSid, - final String pathWorkerSid) { + public WorkerStatisticsFetcher( + final String pathWorkspaceSid, + final String pathWorkerSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkerSid = pathWorkerSid; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ public WorkerStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a string of the format: - * yyyy-MM-dd’T’HH:mm:ss’Z’.. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public WorkerStatisticsFetcher setStartDate(final DateTime startDate) { + public WorkerStatisticsFetcher setStartDate(final ZonedDateTime startDate) { this.startDate = startDate; return this; } - /** - * Filter cumulative statistics by a end date. This is helpful for defining a - * range of statistics to capture. Input is a string of the format: - * yyyy-MM-dd’T’HH:mm:ss’Z’.. - * - * @param endDate Filter cumulative statistics by a end date. - * @return this - */ - public WorkerStatisticsFetcher setEndDate(final DateTime endDate) { + public WorkerStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Filter cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", - * "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter cumulative statistics by TaskChannel. - * @return this - */ public WorkerStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkerStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkerStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/{WorkerSid}/Statistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkerSid" + "}", + this.pathWorkerSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/" + this.pathWorkerSid + "/Statistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkerStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkerStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkerStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkerStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkerStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkerStatistics content = WorkerStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatistics.java index 886cca3d01..2f0d89e2fe 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; @@ -11,55 +18,54 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkersCumulativeStatistics extends Resource { - private static final long serialVersionUID = 89273605202076L; - /** - * Create a WorkersCumulativeStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @return WorkersCumulativeStatisticsFetcher capable of executing the fetch - */ - public static WorkersCumulativeStatisticsFetcher fetcher(final String pathWorkspaceSid) { + public static WorkersCumulativeStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkersCumulativeStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkersCumulativeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON String into a WorkersCumulativeStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkersCumulativeStatistics object represented by the provided JSON */ - public static WorkersCumulativeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkersCumulativeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkersCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkersCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -68,17 +74,23 @@ public static WorkersCumulativeStatistics fromJson(final String json, final Obje } /** - * Converts a JSON InputStream into a WorkersCumulativeStatistics object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkersCumulativeStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkersCumulativeStatistics object represented by the provided JSON */ - public static WorkersCumulativeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkersCumulativeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkersCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkersCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -86,166 +98,103 @@ public static WorkersCumulativeStatistics fromJson(final InputStream json, final } } - private final String accountSid; - private final DateTime startTime; - private final DateTime endTime; - private final List> activityDurations; - private final Integer reservationsCreated; - private final Integer reservationsAccepted; - private final Integer reservationsRejected; - private final Integer reservationsTimedOut; - private final Integer reservationsCanceled; - private final Integer reservationsRescinded; - private final String workspaceSid; - private final URI url; - - @JsonCreator - private WorkersCumulativeStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("start_time") - final String startTime, - @JsonProperty("end_time") - final String endTime, - @JsonProperty("activity_durations") - final List> activityDurations, - @JsonProperty("reservations_created") - final Integer reservationsCreated, - @JsonProperty("reservations_accepted") - final Integer reservationsAccepted, - @JsonProperty("reservations_rejected") - final Integer reservationsRejected, - @JsonProperty("reservations_timed_out") - final Integer reservationsTimedOut, - @JsonProperty("reservations_canceled") - final Integer reservationsCanceled, - @JsonProperty("reservations_rescinded") - final Integer reservationsRescinded, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.startTime = DateConverter.iso8601DateTimeFromString(startTime); - this.endTime = DateConverter.iso8601DateTimeFromString(endTime); - this.activityDurations = activityDurations; - this.reservationsCreated = reservationsCreated; - this.reservationsAccepted = reservationsAccepted; - this.reservationsRejected = reservationsRejected; - this.reservationsTimedOut = reservationsTimedOut; - this.reservationsCanceled = reservationsCanceled; - this.reservationsRescinded = reservationsRescinded; - this.workspaceSid = workspaceSid; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String accountSid; - /** - * Returns The The start_time. - * - * @return The start_time - */ - public final DateTime getStartTime() { - return this.startTime; - } + @Getter + private final List activityDurations; - /** - * Returns The The end_time. - * - * @return The end_time - */ - public final DateTime getEndTime() { - return this.endTime; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; - /** - * Returns The The minimum, average, maximum and total time Workers spent in - * each Activity. - * - * @return The minimum, average, maximum and total time Workers spent in each - * Activity - */ - public final List> getActivityDurations() { - return this.activityDurations; - } + @Getter + private final Integer reservationsAccepted; - /** - * Returns The The total number of Reservations that were created. - * - * @return The total number of Reservations that were created - */ - public final Integer getReservationsCreated() { - return this.reservationsCreated; - } + @Getter + private final Integer reservationsCanceled; - /** - * Returns The The total number of Reservations that were accepted. - * - * @return The total number of Reservations that were accepted - */ - public final Integer getReservationsAccepted() { - return this.reservationsAccepted; - } + @Getter + private final Integer reservationsCreated; - /** - * Returns The The total number of Reservations that were rejected. - * - * @return The total number of Reservations that were rejected - */ - public final Integer getReservationsRejected() { - return this.reservationsRejected; - } + @Getter + private final Integer reservationsRejected; - /** - * Returns The The total number of Reservations that were timed out. - * - * @return The total number of Reservations that were timed out - */ - public final Integer getReservationsTimedOut() { - return this.reservationsTimedOut; - } + @Getter + private final Integer reservationsRescinded; - /** - * Returns The The total number of Reservations that were canceled. - * - * @return The total number of Reservations that were canceled - */ - public final Integer getReservationsCanceled() { - return this.reservationsCanceled; - } + @Getter + private final Integer reservationsTimedOut; - /** - * Returns The The total number of Reservations that were rescinded. - * - * @return The total number of Reservations that were rescinded - */ - public final Integer getReservationsRescinded() { - return this.reservationsRescinded; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime startTime; - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } + @Getter + private final URI url; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + @Getter + private final String workspaceSid; + + @JsonCreator + private WorkersCumulativeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("activity_durations") final List< + Object + > activityDurations, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty( + "reservations_accepted" + ) final Integer reservationsAccepted, + @JsonProperty( + "reservations_canceled" + ) final Integer reservationsCanceled, + @JsonProperty("reservations_created") final Integer reservationsCreated, + @JsonProperty( + "reservations_rejected" + ) final Integer reservationsRejected, + @JsonProperty( + "reservations_rescinded" + ) final Integer reservationsRescinded, + @JsonProperty( + "reservations_timed_out" + ) final Integer reservationsTimedOut, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime startTime, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { + this.accountSid = accountSid; + this.activityDurations = activityDurations; + this.endTime = endTime; + this.reservationsAccepted = reservationsAccepted; + this.reservationsCanceled = reservationsCanceled; + this.reservationsCreated = reservationsCreated; + this.reservationsRejected = reservationsRejected; + this.reservationsRescinded = reservationsRescinded; + this.reservationsTimedOut = reservationsTimedOut; + this.startTime = startTime; + this.url = url; + this.workspaceSid = workspaceSid; } @Override @@ -259,52 +208,40 @@ public boolean equals(final Object o) { } WorkersCumulativeStatistics other = (WorkersCumulativeStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(startTime, other.startTime) && - Objects.equals(endTime, other.endTime) && - Objects.equals(activityDurations, other.activityDurations) && - Objects.equals(reservationsCreated, other.reservationsCreated) && - Objects.equals(reservationsAccepted, other.reservationsAccepted) && - Objects.equals(reservationsRejected, other.reservationsRejected) && - Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && - Objects.equals(reservationsCanceled, other.reservationsCanceled) && - Objects.equals(reservationsRescinded, other.reservationsRescinded) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityDurations, other.activityDurations) && + Objects.equals(endTime, other.endTime) && + Objects.equals(reservationsAccepted, other.reservationsAccepted) && + Objects.equals(reservationsCanceled, other.reservationsCanceled) && + Objects.equals(reservationsCreated, other.reservationsCreated) && + Objects.equals(reservationsRejected, other.reservationsRejected) && + Objects.equals( + reservationsRescinded, + other.reservationsRescinded + ) && + Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && + Objects.equals(startTime, other.startTime) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - startTime, - endTime, - activityDurations, - reservationsCreated, - reservationsAccepted, - reservationsRejected, - reservationsTimedOut, - reservationsCanceled, - reservationsRescinded, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("startTime", startTime) - .add("endTime", endTime) - .add("activityDurations", activityDurations) - .add("reservationsCreated", reservationsCreated) - .add("reservationsAccepted", reservationsAccepted) - .add("reservationsRejected", reservationsRejected) - .add("reservationsTimedOut", reservationsTimedOut) - .add("reservationsCanceled", reservationsCanceled) - .add("reservationsRescinded", reservationsRescinded) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + activityDurations, + endTime, + reservationsAccepted, + reservationsCanceled, + reservationsCreated, + reservationsRejected, + reservationsRescinded, + reservationsTimedOut, + startTime, + url, + workspaceSid + ); + } +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatisticsFetcher.java index c8f092d2f6..2c976768aa 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersCumulativeStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,134 +26,152 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; -public class WorkersCumulativeStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private DateTime endDate; +public class WorkersCumulativeStatisticsFetcher + extends Fetcher { + + private String pathWorkspaceSid; + private ZonedDateTime endDate; private Integer minutes; - private DateTime startDate; + private ZonedDateTime startDate; private String taskChannel; - /** - * Construct a new WorkersCumulativeStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - */ public WorkersCumulativeStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter cumulative statistics by a end date. This is helpful for defining a - * range of statistics to capture. Input is a string of the format: - * yyyy-MM-dd’T’HH:mm:ss’Z’.. - * - * @param endDate Filter cumulative statistics by a end date. - * @return this - */ - public WorkersCumulativeStatisticsFetcher setEndDate(final DateTime endDate) { + public WorkersCumulativeStatisticsFetcher setEndDate( + final ZonedDateTime endDate + ) { this.endDate = endDate; return this; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ - public WorkersCumulativeStatisticsFetcher setMinutes(final Integer minutes) { + public WorkersCumulativeStatisticsFetcher setMinutes( + final Integer minutes + ) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a string of the format: - * yyyy-MM-dd’T’HH:mm:ss’Z’.. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public WorkersCumulativeStatisticsFetcher setStartDate(final DateTime startDate) { + public WorkersCumulativeStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", - * "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter cumulative statistics by TaskChannel. - * @return this - */ - public WorkersCumulativeStatisticsFetcher setTaskChannel(final String taskChannel) { + public WorkersCumulativeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkersCumulativeStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkersCumulativeStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/CumulativeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/CumulativeStatistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkersCumulativeStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkersCumulativeStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkersCumulativeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkersCumulativeStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkersCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkersCumulativeStatistics content = + WorkersCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatistics.java index 21088e7a98..c2441862f9 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; @@ -11,53 +18,51 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.util.List; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkersRealTimeStatistics extends Resource { - private static final long serialVersionUID = 59891376471139L; - /** - * Create a WorkersRealTimeStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @return WorkersRealTimeStatisticsFetcher capable of executing the fetch - */ - public static WorkersRealTimeStatisticsFetcher fetcher(final String pathWorkspaceSid) { + public static WorkersRealTimeStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkersRealTimeStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkersRealTimeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON String into a WorkersRealTimeStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkersRealTimeStatistics object represented by the provided JSON */ - public static WorkersRealTimeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkersRealTimeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkersRealTimeStatistics.class); + return objectMapper.readValue( + json, + WorkersRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -66,17 +71,23 @@ public static WorkersRealTimeStatistics fromJson(final String json, final Object } /** - * Converts a JSON InputStream into a WorkersRealTimeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkersRealTimeStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkersRealTimeStatistics object represented by the provided JSON */ - public static WorkersRealTimeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkersRealTimeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkersRealTimeStatistics.class); + return objectMapper.readValue( + json, + WorkersRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -84,73 +95,48 @@ public static WorkersRealTimeStatistics fromJson(final InputStream json, final O } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final List> activityStatistics; + + @Getter + private final List activityStatistics; + + @Getter private final Integer totalWorkers; - private final String workspaceSid; + + @Getter private final URI url; + @Getter + private final String workspaceSid; + @JsonCreator - private WorkersRealTimeStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("activity_statistics") - final List> activityStatistics, - @JsonProperty("total_workers") - final Integer totalWorkers, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private WorkersRealTimeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("activity_statistics") final List< + Object + > activityStatistics, + @JsonProperty("total_workers") final Integer totalWorkers, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.activityStatistics = activityStatistics; this.totalWorkers = totalWorkers; - this.workspaceSid = workspaceSid; this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The current Worker status count breakdown by Activity. - * - * @return The current Worker status count breakdown by Activity - */ - public final List> getActivityStatistics() { - return this.activityStatistics; - } - - /** - * Returns The The total number of Workers. - * - * @return The total number of Workers - */ - public final Integer getTotalWorkers() { - return this.totalWorkers; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + this.workspaceSid = workspaceSid; } @Override @@ -164,31 +150,23 @@ public boolean equals(final Object o) { } WorkersRealTimeStatistics other = (WorkersRealTimeStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(activityStatistics, other.activityStatistics) && - Objects.equals(totalWorkers, other.totalWorkers) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(activityStatistics, other.activityStatistics) && + Objects.equals(totalWorkers, other.totalWorkers) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - activityStatistics, - totalWorkers, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("activityStatistics", activityStatistics) - .add("totalWorkers", totalWorkers) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + activityStatistics, + totalWorkers, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatisticsFetcher.java index 57671bd69e..b44a872a73 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersRealTimeStatisticsFetcher.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,79 +26,99 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -public class WorkersRealTimeStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; +public class WorkersRealTimeStatisticsFetcher + extends Fetcher { + + private String pathWorkspaceSid; private String taskChannel; - /** - * Construct a new WorkersRealTimeStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - */ public WorkersRealTimeStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", - * "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter cumulative statistics by TaskChannel. - * @return this - */ - public WorkersRealTimeStatisticsFetcher setTaskChannel(final String taskChannel) { + public WorkersRealTimeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkersRealTimeStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkersRealTimeStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workers/RealTimeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/RealTimeStatistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkersRealTimeStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkersRealTimeStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkersRealTimeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkersRealTimeStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkersRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkersRealTimeStatistics content = WorkersRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatistics.java index 7a6ea9543a..13c9a4cd7d 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; @@ -11,49 +18,44 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkersStatistics extends Resource { - private static final long serialVersionUID = 181724864721054L; - /** - * Create a WorkersStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @return WorkersStatisticsFetcher capable of executing the fetch - */ - public static WorkersStatisticsFetcher fetcher(final String pathWorkspaceSid) { + public static WorkersStatisticsFetcher fetcher( + final String pathWorkspaceSid + ) { return new WorkersStatisticsFetcher(pathWorkspaceSid); } /** - * Converts a JSON String into a WorkersStatistics object using the provided - * ObjectMapper. - * + * Converts a JSON String into a WorkersStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkersStatistics object represented by the provided JSON */ - public static WorkersStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkersStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkersStatistics.class); @@ -65,14 +67,17 @@ public static WorkersStatistics fromJson(final String json, final ObjectMapper o } /** - * Converts a JSON InputStream into a WorkersStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkersStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkersStatistics object represented by the provided JSON */ - public static WorkersStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkersStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkersStatistics.class); @@ -83,73 +88,46 @@ public static WorkersStatistics fromJson(final InputStream json, final ObjectMap } } - private final Map realtime; - private final Map cumulative; - private final String accountSid; - private final String workspaceSid; - private final URI url; - - @JsonCreator - private WorkersStatistics(@JsonProperty("realtime") - final Map realtime, - @JsonProperty("cumulative") - final Map cumulative, - @JsonProperty("account_sid") - final String accountSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { - this.realtime = realtime; - this.cumulative = cumulative; - this.accountSid = accountSid; - this.workspaceSid = workspaceSid; - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The realtime. - * - * @return The realtime - */ - public final Map getRealtime() { - return this.realtime; - } + @Getter + private final String accountSid; - /** - * Returns The The cumulative. - * - * @return The cumulative - */ - public final Map getCumulative() { - return this.cumulative; - } + @Getter + private final Object cumulative; - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final Object realtime; - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } + @Getter + private final URI url; - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; + @Getter + private final String workspaceSid; + + @JsonCreator + private WorkersStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Object cumulative, + @JsonProperty("realtime") final Object realtime, + @JsonProperty("url") final URI url, + @JsonProperty("workspace_sid") final String workspaceSid + ) { + this.accountSid = accountSid; + this.cumulative = cumulative; + this.realtime = realtime; + this.url = url; + this.workspaceSid = workspaceSid; } @Override @@ -163,31 +141,23 @@ public boolean equals(final Object o) { } WorkersStatistics other = (WorkersStatistics) o; - - return Objects.equals(realtime, other.realtime) && - Objects.equals(cumulative, other.cumulative) && - Objects.equals(accountSid, other.accountSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(realtime, other.realtime) && + Objects.equals(url, other.url) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(realtime, - cumulative, - accountSid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("realtime", realtime) - .add("cumulative", cumulative) - .add("accountSid", accountSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + cumulative, + realtime, + url, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatisticsFetcher.java index e88205cdca..97446fc77e 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/worker/WorkersStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.worker; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,186 +26,190 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class WorkersStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; + + private String pathWorkspaceSid; private Integer minutes; - private DateTime startDate; - private DateTime endDate; + private ZonedDateTime startDate; + private ZonedDateTime endDate; private String taskQueueSid; private String taskQueueName; private String friendlyName; private String taskChannel; - /** - * Construct a new WorkersStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - */ public WorkersStatisticsFetcher(final String pathWorkspaceSid) { this.pathWorkspaceSid = pathWorkspaceSid; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ public WorkersStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a string of the format: - * yyyy-MM-dd’T’HH:mm:ss’Z’.. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public WorkersStatisticsFetcher setStartDate(final DateTime startDate) { + public WorkersStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter cumulative statistics by a end date. This is helpful for defining a - * range of statistics to capture. Input is a string of the format: - * yyyy-MM-dd’T’HH:mm:ss’Z’.. - * - * @param endDate Filter cumulative statistics by a end date. - * @return this - */ - public WorkersStatisticsFetcher setEndDate(final DateTime endDate) { + public WorkersStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Filter the real-time and cumulative statistics based on Workers tied to a - * particular queue. - * - * @param taskQueueSid Filter the real-time and cumulative statistics based on - * Workers tied to a particular queue - * @return this - */ public WorkersStatisticsFetcher setTaskQueueSid(final String taskQueueSid) { this.taskQueueSid = taskQueueSid; return this; } - /** - * Filter the real-time and cumulative statistics based on Workers tied to a - * particular queue. - * - * @param taskQueueName Filter the real-time and cumulative statistics based on - * Workers tied to a particular queue - * @return this - */ - public WorkersStatisticsFetcher setTaskQueueName(final String taskQueueName) { + public WorkersStatisticsFetcher setTaskQueueName( + final String taskQueueName + ) { this.taskQueueName = taskQueueName; return this; } - /** - * The friendly_name. - * - * @param friendlyName The friendly_name - * @return this - */ public WorkersStatisticsFetcher setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * Filter cumulative statistics by TaskChannel. Takes in a Unique Name ("voice", - * "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter cumulative statistics by TaskChannel. - * @return this - */ public WorkersStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkersStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkersStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Workspaces/{WorkspaceSid}/Workers/Statistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workers/Statistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkersStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkersStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public WorkersStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkersStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return WorkersStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkersStatistics content = WorkersStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (taskQueueSid != null) { - request.addQueryParam("TaskQueueSid", taskQueueSid); + Serializer.toString( + request, + "TaskQueueSid", + taskQueueSid, + ParameterType.QUERY + ); } if (taskQueueName != null) { - request.addQueryParam("TaskQueueName", taskQueueName); + Serializer.toString( + request, + "TaskQueueName", + taskQueueName, + ParameterType.QUERY + ); } if (friendlyName != null) { - request.addQueryParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatistics.java index c1745ea918..79bdf33b31 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.workflow; @@ -11,56 +18,57 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkflowCumulativeStatistics extends Resource { - private static final long serialVersionUID = 190316702112429L; - /** - * Create a WorkflowCumulativeStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkflowSid The workflow_sid - * @return WorkflowCumulativeStatisticsFetcher capable of executing the fetch - */ - public static WorkflowCumulativeStatisticsFetcher fetcher(final String pathWorkspaceSid, - final String pathWorkflowSid) { - return new WorkflowCumulativeStatisticsFetcher(pathWorkspaceSid, pathWorkflowSid); + public static WorkflowCumulativeStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { + return new WorkflowCumulativeStatisticsFetcher( + pathWorkspaceSid, + pathWorkflowSid + ); } /** - * Converts a JSON String into a WorkflowCumulativeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON String into a WorkflowCumulativeStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkflowCumulativeStatistics object represented by the provided JSON */ - public static WorkflowCumulativeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkflowCumulativeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkflowCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkflowCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -69,17 +77,23 @@ public static WorkflowCumulativeStatistics fromJson(final String json, final Obj } /** - * Converts a JSON InputStream into a WorkflowCumulativeStatistics object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkflowCumulativeStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkflowCumulativeStatistics object represented by the provided JSON */ - public static WorkflowCumulativeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkflowCumulativeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkflowCumulativeStatistics.class); + return objectMapper.readValue( + json, + WorkflowCumulativeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -87,297 +101,159 @@ public static WorkflowCumulativeStatistics fromJson(final InputStream json, fina } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final Integer avgTaskAcceptanceTime; - private final DateTime startTime; - private final DateTime endTime; - private final Integer reservationsCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime endTime; + + @Getter private final Integer reservationsAccepted; - private final Integer reservationsRejected; - private final Integer reservationsTimedOut; + + @Getter private final Integer reservationsCanceled; + + @Getter + private final Integer reservationsCreated; + + @Getter + private final Integer reservationsRejected; + + @Getter private final Integer reservationsRescinded; - private final Map splitByWaitTime; - private final Map waitDurationUntilAccepted; - private final Map waitDurationUntilCanceled; + + @Getter + private final Integer reservationsTimedOut; + + @Getter + private final Object splitByWaitTime; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime startTime; + + @Getter private final Integer tasksCanceled; + + @Getter private final Integer tasksCompleted; - private final Integer tasksEntered; + + @Getter private final Integer tasksDeleted; + + @Getter + private final Integer tasksEntered; + + @Getter private final Integer tasksMoved; + + @Getter private final Integer tasksTimedOutInWorkflow; + + @Getter + private final URI url; + + @Getter + private final Object waitDurationUntilAccepted; + + @Getter + private final Object waitDurationUntilCanceled; + + @Getter private final String workflowSid; + + @Getter private final String workspaceSid; - private final URI url; @JsonCreator - private WorkflowCumulativeStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("avg_task_acceptance_time") - final Integer avgTaskAcceptanceTime, - @JsonProperty("start_time") - final String startTime, - @JsonProperty("end_time") - final String endTime, - @JsonProperty("reservations_created") - final Integer reservationsCreated, - @JsonProperty("reservations_accepted") - final Integer reservationsAccepted, - @JsonProperty("reservations_rejected") - final Integer reservationsRejected, - @JsonProperty("reservations_timed_out") - final Integer reservationsTimedOut, - @JsonProperty("reservations_canceled") - final Integer reservationsCanceled, - @JsonProperty("reservations_rescinded") - final Integer reservationsRescinded, - @JsonProperty("split_by_wait_time") - final Map splitByWaitTime, - @JsonProperty("wait_duration_until_accepted") - final Map waitDurationUntilAccepted, - @JsonProperty("wait_duration_until_canceled") - final Map waitDurationUntilCanceled, - @JsonProperty("tasks_canceled") - final Integer tasksCanceled, - @JsonProperty("tasks_completed") - final Integer tasksCompleted, - @JsonProperty("tasks_entered") - final Integer tasksEntered, - @JsonProperty("tasks_deleted") - final Integer tasksDeleted, - @JsonProperty("tasks_moved") - final Integer tasksMoved, - @JsonProperty("tasks_timed_out_in_workflow") - final Integer tasksTimedOutInWorkflow, - @JsonProperty("workflow_sid") - final String workflowSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private WorkflowCumulativeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "avg_task_acceptance_time" + ) final Integer avgTaskAcceptanceTime, + @JsonProperty("end_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime endTime, + @JsonProperty( + "reservations_accepted" + ) final Integer reservationsAccepted, + @JsonProperty( + "reservations_canceled" + ) final Integer reservationsCanceled, + @JsonProperty("reservations_created") final Integer reservationsCreated, + @JsonProperty( + "reservations_rejected" + ) final Integer reservationsRejected, + @JsonProperty( + "reservations_rescinded" + ) final Integer reservationsRescinded, + @JsonProperty( + "reservations_timed_out" + ) final Integer reservationsTimedOut, + @JsonProperty("split_by_wait_time") final Object splitByWaitTime, + @JsonProperty("start_time") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime startTime, + @JsonProperty("tasks_canceled") final Integer tasksCanceled, + @JsonProperty("tasks_completed") final Integer tasksCompleted, + @JsonProperty("tasks_deleted") final Integer tasksDeleted, + @JsonProperty("tasks_entered") final Integer tasksEntered, + @JsonProperty("tasks_moved") final Integer tasksMoved, + @JsonProperty( + "tasks_timed_out_in_workflow" + ) final Integer tasksTimedOutInWorkflow, + @JsonProperty("url") final URI url, + @JsonProperty( + "wait_duration_until_accepted" + ) final Object waitDurationUntilAccepted, + @JsonProperty( + "wait_duration_until_canceled" + ) final Object waitDurationUntilCanceled, + @JsonProperty("workflow_sid") final String workflowSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.avgTaskAcceptanceTime = avgTaskAcceptanceTime; - this.startTime = DateConverter.iso8601DateTimeFromString(startTime); - this.endTime = DateConverter.iso8601DateTimeFromString(endTime); - this.reservationsCreated = reservationsCreated; + this.endTime = endTime; this.reservationsAccepted = reservationsAccepted; - this.reservationsRejected = reservationsRejected; - this.reservationsTimedOut = reservationsTimedOut; this.reservationsCanceled = reservationsCanceled; + this.reservationsCreated = reservationsCreated; + this.reservationsRejected = reservationsRejected; this.reservationsRescinded = reservationsRescinded; + this.reservationsTimedOut = reservationsTimedOut; this.splitByWaitTime = splitByWaitTime; - this.waitDurationUntilAccepted = waitDurationUntilAccepted; - this.waitDurationUntilCanceled = waitDurationUntilCanceled; + this.startTime = startTime; this.tasksCanceled = tasksCanceled; this.tasksCompleted = tasksCompleted; - this.tasksEntered = tasksEntered; this.tasksDeleted = tasksDeleted; + this.tasksEntered = tasksEntered; this.tasksMoved = tasksMoved; this.tasksTimedOutInWorkflow = tasksTimedOutInWorkflow; + this.url = url; + this.waitDurationUntilAccepted = waitDurationUntilAccepted; + this.waitDurationUntilCanceled = waitDurationUntilCanceled; this.workflowSid = workflowSid; this.workspaceSid = workspaceSid; - this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The average time from Task creation to acceptance. - * - * @return The average time from Task creation to acceptance - */ - public final Integer getAvgTaskAcceptanceTime() { - return this.avgTaskAcceptanceTime; - } - - /** - * Returns The The start_time. - * - * @return The start_time - */ - public final DateTime getStartTime() { - return this.startTime; - } - - /** - * Returns The The end_time. - * - * @return The end_time - */ - public final DateTime getEndTime() { - return this.endTime; - } - - /** - * Returns The The total number of Reservations that were created for Workers. - * - * @return The total number of Reservations that were created for Workers - */ - public final Integer getReservationsCreated() { - return this.reservationsCreated; - } - - /** - * Returns The The total number of Reservations accepted by Workers. - * - * @return The total number of Reservations accepted by Workers - */ - public final Integer getReservationsAccepted() { - return this.reservationsAccepted; - } - - /** - * Returns The The total number of Reservations that were rejected. - * - * @return The total number of Reservations that were rejected - */ - public final Integer getReservationsRejected() { - return this.reservationsRejected; - } - - /** - * Returns The The total number of Reservations that were timed out. - * - * @return The total number of Reservations that were timed out - */ - public final Integer getReservationsTimedOut() { - return this.reservationsTimedOut; - } - - /** - * Returns The The total number of Reservations that were canceled. - * - * @return The total number of Reservations that were canceled - */ - public final Integer getReservationsCanceled() { - return this.reservationsCanceled; - } - - /** - * Returns The The total number of Reservations that were rescinded. - * - * @return The total number of Reservations that were rescinded - */ - public final Integer getReservationsRescinded() { - return this.reservationsRescinded; - } - - /** - * Returns The The splits of the tasks canceled and accepted based on the - * provided SplitByWaitTime parameter.. - * - * @return The splits of the tasks canceled and accepted based on the provided - * SplitByWaitTime parameter. - */ - public final Map getSplitByWaitTime() { - return this.splitByWaitTime; - } - - /** - * Returns The The wait duration stats for tasks that were accepted.. - * - * @return The wait duration stats for tasks that were accepted. - */ - public final Map getWaitDurationUntilAccepted() { - return this.waitDurationUntilAccepted; - } - - /** - * Returns The The wait duration stats for tasks that were canceled.. - * - * @return The wait duration stats for tasks that were canceled. - */ - public final Map getWaitDurationUntilCanceled() { - return this.waitDurationUntilCanceled; - } - - /** - * Returns The The total number of Tasks that were canceled. - * - * @return The total number of Tasks that were canceled - */ - public final Integer getTasksCanceled() { - return this.tasksCanceled; - } - - /** - * Returns The The total number of Tasks that were completed. - * - * @return The total number of Tasks that were completed - */ - public final Integer getTasksCompleted() { - return this.tasksCompleted; - } - - /** - * Returns The The total number of Tasks that entered this Workflow. - * - * @return The total number of Tasks that entered this Workflow - */ - public final Integer getTasksEntered() { - return this.tasksEntered; - } - - /** - * Returns The The total number of Tasks that were deleted. - * - * @return The total number of Tasks that were deleted - */ - public final Integer getTasksDeleted() { - return this.tasksDeleted; - } - - /** - * Returns The The total number of Tasks that were moved from one queue to - * another. - * - * @return The total number of Tasks that were moved from one queue to another - */ - public final Integer getTasksMoved() { - return this.tasksMoved; - } - - /** - * Returns The The total number of Tasks that were timed out of their Workflows. - * - * @return The total number of Tasks that were timed out of their Workflows - */ - public final Integer getTasksTimedOutInWorkflow() { - return this.tasksTimedOutInWorkflow; - } - - /** - * Returns The The workflow_sid. - * - * @return The workflow_sid - */ - public final String getWorkflowSid() { - return this.workflowSid; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; } @Override @@ -391,82 +267,72 @@ public boolean equals(final Object o) { } WorkflowCumulativeStatistics other = (WorkflowCumulativeStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(avgTaskAcceptanceTime, other.avgTaskAcceptanceTime) && - Objects.equals(startTime, other.startTime) && - Objects.equals(endTime, other.endTime) && - Objects.equals(reservationsCreated, other.reservationsCreated) && - Objects.equals(reservationsAccepted, other.reservationsAccepted) && - Objects.equals(reservationsRejected, other.reservationsRejected) && - Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && - Objects.equals(reservationsCanceled, other.reservationsCanceled) && - Objects.equals(reservationsRescinded, other.reservationsRescinded) && - Objects.equals(splitByWaitTime, other.splitByWaitTime) && - Objects.equals(waitDurationUntilAccepted, other.waitDurationUntilAccepted) && - Objects.equals(waitDurationUntilCanceled, other.waitDurationUntilCanceled) && - Objects.equals(tasksCanceled, other.tasksCanceled) && - Objects.equals(tasksCompleted, other.tasksCompleted) && - Objects.equals(tasksEntered, other.tasksEntered) && - Objects.equals(tasksDeleted, other.tasksDeleted) && - Objects.equals(tasksMoved, other.tasksMoved) && - Objects.equals(tasksTimedOutInWorkflow, other.tasksTimedOutInWorkflow) && - Objects.equals(workflowSid, other.workflowSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + avgTaskAcceptanceTime, + other.avgTaskAcceptanceTime + ) && + Objects.equals(endTime, other.endTime) && + Objects.equals(reservationsAccepted, other.reservationsAccepted) && + Objects.equals(reservationsCanceled, other.reservationsCanceled) && + Objects.equals(reservationsCreated, other.reservationsCreated) && + Objects.equals(reservationsRejected, other.reservationsRejected) && + Objects.equals( + reservationsRescinded, + other.reservationsRescinded + ) && + Objects.equals(reservationsTimedOut, other.reservationsTimedOut) && + Objects.equals(splitByWaitTime, other.splitByWaitTime) && + Objects.equals(startTime, other.startTime) && + Objects.equals(tasksCanceled, other.tasksCanceled) && + Objects.equals(tasksCompleted, other.tasksCompleted) && + Objects.equals(tasksDeleted, other.tasksDeleted) && + Objects.equals(tasksEntered, other.tasksEntered) && + Objects.equals(tasksMoved, other.tasksMoved) && + Objects.equals( + tasksTimedOutInWorkflow, + other.tasksTimedOutInWorkflow + ) && + Objects.equals(url, other.url) && + Objects.equals( + waitDurationUntilAccepted, + other.waitDurationUntilAccepted + ) && + Objects.equals( + waitDurationUntilCanceled, + other.waitDurationUntilCanceled + ) && + Objects.equals(workflowSid, other.workflowSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - avgTaskAcceptanceTime, - startTime, - endTime, - reservationsCreated, - reservationsAccepted, - reservationsRejected, - reservationsTimedOut, - reservationsCanceled, - reservationsRescinded, - splitByWaitTime, - waitDurationUntilAccepted, - waitDurationUntilCanceled, - tasksCanceled, - tasksCompleted, - tasksEntered, - tasksDeleted, - tasksMoved, - tasksTimedOutInWorkflow, - workflowSid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("avgTaskAcceptanceTime", avgTaskAcceptanceTime) - .add("startTime", startTime) - .add("endTime", endTime) - .add("reservationsCreated", reservationsCreated) - .add("reservationsAccepted", reservationsAccepted) - .add("reservationsRejected", reservationsRejected) - .add("reservationsTimedOut", reservationsTimedOut) - .add("reservationsCanceled", reservationsCanceled) - .add("reservationsRescinded", reservationsRescinded) - .add("splitByWaitTime", splitByWaitTime) - .add("waitDurationUntilAccepted", waitDurationUntilAccepted) - .add("waitDurationUntilCanceled", waitDurationUntilCanceled) - .add("tasksCanceled", tasksCanceled) - .add("tasksCompleted", tasksCompleted) - .add("tasksEntered", tasksEntered) - .add("tasksDeleted", tasksDeleted) - .add("tasksMoved", tasksMoved) - .add("tasksTimedOutInWorkflow", tasksTimedOutInWorkflow) - .add("workflowSid", workflowSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + avgTaskAcceptanceTime, + endTime, + reservationsAccepted, + reservationsCanceled, + reservationsCreated, + reservationsRejected, + reservationsRescinded, + reservationsTimedOut, + splitByWaitTime, + startTime, + tasksCanceled, + tasksCompleted, + tasksDeleted, + tasksEntered, + tasksMoved, + tasksTimedOutInWorkflow, + url, + waitDurationUntilAccepted, + waitDurationUntilCanceled, + workflowSid, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatisticsFetcher.java index 1b31b3a845..22c0612c8c 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowCumulativeStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.workflow; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,158 +26,179 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; -public class WorkflowCumulativeStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathWorkflowSid; - private DateTime endDate; +public class WorkflowCumulativeStatisticsFetcher + extends Fetcher { + + private String pathWorkspaceSid; + private String pathWorkflowSid; + private ZonedDateTime endDate; private Integer minutes; - private DateTime startDate; + private ZonedDateTime startDate; private String taskChannel; private String splitByWaitTime; - /** - * Construct a new WorkflowCumulativeStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkflowSid The workflow_sid - */ - public WorkflowCumulativeStatisticsFetcher(final String pathWorkspaceSid, - final String pathWorkflowSid) { + public WorkflowCumulativeStatisticsFetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkflowSid = pathWorkflowSid; } - /** - * Filter cumulative statistics by an end date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp. - * - * @param endDate Filter cumulative statistics by an end date. - * @return this - */ - public WorkflowCumulativeStatisticsFetcher setEndDate(final DateTime endDate) { + public WorkflowCumulativeStatisticsFetcher setEndDate( + final ZonedDateTime endDate + ) { this.endDate = endDate; return this; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ - public WorkflowCumulativeStatisticsFetcher setMinutes(final Integer minutes) { + public WorkflowCumulativeStatisticsFetcher setMinutes( + final Integer minutes + ) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public WorkflowCumulativeStatisticsFetcher setStartDate(final DateTime startDate) { + public WorkflowCumulativeStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ - public WorkflowCumulativeStatisticsFetcher setTaskChannel(final String taskChannel) { + public WorkflowCumulativeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } - /** - * A comma separated values for viewing splits of tasks canceled and accepted - * above the given threshold in seconds. Ex: "5,30" would show splits of tasks - * that were canceled or accepted before or after 5 seconds and respectively, 30 - * seconds. This is great for showing short abandoned tasks or tasks that failed - * to meet your SLA.. - * - * @param splitByWaitTime A comma separated values for viewing splits of tasks - * canceled and accepted above the given threshold in - * seconds. - * @return this - */ - public WorkflowCumulativeStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime) { + public WorkflowCumulativeStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkflowCumulativeStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkflowCumulativeStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/CumulativeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkflowSid" + "}", + this.pathWorkflowSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workflows/" + this.pathWorkflowSid + "/CumulativeStatistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkflowCumulativeStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkflowCumulativeStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkflowCumulativeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkflowCumulativeStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkflowCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkflowCumulativeStatistics content = + WorkflowCumulativeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); + Serializer.toString( + request, + "SplitByWaitTime", + splitByWaitTime, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatistics.java index 87c3949348..ef686577c6 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.workflow; @@ -11,54 +18,54 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkflowRealTimeStatistics extends Resource { - private static final long serialVersionUID = 202087989924L; - /** - * Create a WorkflowRealTimeStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkflowSid The workflow_sid - * @return WorkflowRealTimeStatisticsFetcher capable of executing the fetch - */ - public static WorkflowRealTimeStatisticsFetcher fetcher(final String pathWorkspaceSid, - final String pathWorkflowSid) { - return new WorkflowRealTimeStatisticsFetcher(pathWorkspaceSid, pathWorkflowSid); + public static WorkflowRealTimeStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { + return new WorkflowRealTimeStatisticsFetcher( + pathWorkspaceSid, + pathWorkflowSid + ); } /** - * Converts a JSON String into a WorkflowRealTimeStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON String into a WorkflowRealTimeStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkflowRealTimeStatistics object represented by the provided JSON */ - public static WorkflowRealTimeStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkflowRealTimeStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkflowRealTimeStatistics.class); + return objectMapper.readValue( + json, + WorkflowRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -67,17 +74,23 @@ public static WorkflowRealTimeStatistics fromJson(final String json, final Objec } /** - * Converts a JSON InputStream into a WorkflowRealTimeStatistics object using - * the provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkflowRealTimeStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkflowRealTimeStatistics object represented by the provided JSON */ - public static WorkflowRealTimeStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkflowRealTimeStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { - return objectMapper.readValue(json, WorkflowRealTimeStatistics.class); + return objectMapper.readValue( + json, + WorkflowRealTimeStatistics.class + ); } catch (final JsonMappingException | JsonParseException e) { throw new ApiException(e.getMessage(), e); } catch (final IOException e) { @@ -85,112 +98,70 @@ public static WorkflowRealTimeStatistics fromJson(final InputStream json, final } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final Integer longestTaskWaitingAge; - private final Map tasksByPriority; - private final Map tasksByStatus; + + @Getter + private final String longestTaskWaitingSid; + + @Getter + private final Object tasksByPriority; + + @Getter + private final Object tasksByStatus; + + @Getter private final Integer totalTasks; + + @Getter + private final URI url; + + @Getter private final String workflowSid; + + @Getter private final String workspaceSid; - private final URI url; @JsonCreator - private WorkflowRealTimeStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("longest_task_waiting_age") - final Integer longestTaskWaitingAge, - @JsonProperty("tasks_by_priority") - final Map tasksByPriority, - @JsonProperty("tasks_by_status") - final Map tasksByStatus, - @JsonProperty("total_tasks") - final Integer totalTasks, - @JsonProperty("workflow_sid") - final String workflowSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private WorkflowRealTimeStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "longest_task_waiting_age" + ) final Integer longestTaskWaitingAge, + @JsonProperty( + "longest_task_waiting_sid" + ) final String longestTaskWaitingSid, + @JsonProperty("tasks_by_priority") final Object tasksByPriority, + @JsonProperty("tasks_by_status") final Object tasksByStatus, + @JsonProperty("total_tasks") final Integer totalTasks, + @JsonProperty("url") final URI url, + @JsonProperty("workflow_sid") final String workflowSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.longestTaskWaitingAge = longestTaskWaitingAge; + this.longestTaskWaitingSid = longestTaskWaitingSid; this.tasksByPriority = tasksByPriority; this.tasksByStatus = tasksByStatus; this.totalTasks = totalTasks; + this.url = url; this.workflowSid = workflowSid; this.workspaceSid = workspaceSid; - this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The age of the longest waiting Task. - * - * @return The age of the longest waiting Task - */ - public final Integer getLongestTaskWaitingAge() { - return this.longestTaskWaitingAge; - } - - /** - * Returns The The tasks_by_priority. - * - * @return The tasks_by_priority - */ - public final Map getTasksByPriority() { - return this.tasksByPriority; - } - - /** - * Returns The The Tasks broken down by status. - * - * @return The Tasks broken down by status - */ - public final Map getTasksByStatus() { - return this.tasksByStatus; - } - - /** - * Returns The The total number of Tasks. - * - * @return The total number of Tasks - */ - public final Integer getTotalTasks() { - return this.totalTasks; - } - - /** - * Returns The The workflow_sid. - * - * @return The workflow_sid - */ - public final String getWorkflowSid() { - return this.workflowSid; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; } @Override @@ -204,40 +175,37 @@ public boolean equals(final Object o) { } WorkflowRealTimeStatistics other = (WorkflowRealTimeStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(longestTaskWaitingAge, other.longestTaskWaitingAge) && - Objects.equals(tasksByPriority, other.tasksByPriority) && - Objects.equals(tasksByStatus, other.tasksByStatus) && - Objects.equals(totalTasks, other.totalTasks) && - Objects.equals(workflowSid, other.workflowSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals( + longestTaskWaitingAge, + other.longestTaskWaitingAge + ) && + Objects.equals( + longestTaskWaitingSid, + other.longestTaskWaitingSid + ) && + Objects.equals(tasksByPriority, other.tasksByPriority) && + Objects.equals(tasksByStatus, other.tasksByStatus) && + Objects.equals(totalTasks, other.totalTasks) && + Objects.equals(url, other.url) && + Objects.equals(workflowSid, other.workflowSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - longestTaskWaitingAge, - tasksByPriority, - tasksByStatus, - totalTasks, - workflowSid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("longestTaskWaitingAge", longestTaskWaitingAge) - .add("tasksByPriority", tasksByPriority) - .add("tasksByStatus", tasksByStatus) - .add("totalTasks", totalTasks) - .add("workflowSid", workflowSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + longestTaskWaitingAge, + longestTaskWaitingSid, + tasksByPriority, + tasksByStatus, + totalTasks, + url, + workflowSid, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatisticsFetcher.java index d8b8b2ea2e..85a0ed6409 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowRealTimeStatisticsFetcher.java @@ -1,13 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.workflow; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,83 +26,110 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; -public class WorkflowRealTimeStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathWorkflowSid; +public class WorkflowRealTimeStatisticsFetcher + extends Fetcher { + + private String pathWorkspaceSid; + private String pathWorkflowSid; private String taskChannel; - /** - * Construct a new WorkflowRealTimeStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkflowSid The workflow_sid - */ - public WorkflowRealTimeStatisticsFetcher(final String pathWorkspaceSid, - final String pathWorkflowSid) { + public WorkflowRealTimeStatisticsFetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkflowSid = pathWorkflowSid; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ - public WorkflowRealTimeStatisticsFetcher setTaskChannel(final String taskChannel) { + public WorkflowRealTimeStatisticsFetcher setTaskChannel( + final String taskChannel + ) { this.taskChannel = taskChannel; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkflowRealTimeStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkflowRealTimeStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/RealTimeStatistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkflowSid" + "}", + this.pathWorkflowSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workflows/" + this.pathWorkflowSid + "/RealTimeStatistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkflowRealTimeStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkflowRealTimeStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkflowRealTimeStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkflowRealTimeStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkflowRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkflowRealTimeStatistics content = + WorkflowRealTimeStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatistics.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatistics.java index 67807db602..04bb2e2a17 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatistics.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatistics.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.workflow; @@ -11,51 +18,45 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; import com.twilio.base.Resource; -import com.twilio.converter.Converter; +import com.twilio.base.Resource; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class WorkflowStatistics extends Resource { - private static final long serialVersionUID = 71533106021042L; - /** - * Create a WorkflowStatisticsFetcher to execute fetch. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkflowSid The workflow_sid - * @return WorkflowStatisticsFetcher capable of executing the fetch - */ - public static WorkflowStatisticsFetcher fetcher(final String pathWorkspaceSid, - final String pathWorkflowSid) { + public static WorkflowStatisticsFetcher fetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { return new WorkflowStatisticsFetcher(pathWorkspaceSid, pathWorkflowSid); } /** - * Converts a JSON String into a WorkflowStatistics object using the provided - * ObjectMapper. - * + * Converts a JSON String into a WorkflowStatistics object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return WorkflowStatistics object represented by the provided JSON */ - public static WorkflowStatistics fromJson(final String json, final ObjectMapper objectMapper) { + public static WorkflowStatistics fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkflowStatistics.class); @@ -67,14 +68,17 @@ public static WorkflowStatistics fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a WorkflowStatistics object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a WorkflowStatistics object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return WorkflowStatistics object represented by the provided JSON */ - public static WorkflowStatistics fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static WorkflowStatistics fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, WorkflowStatistics.class); @@ -85,86 +89,51 @@ public static WorkflowStatistics fromJson(final InputStream json, final ObjectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final Map cumulative; - private final Map realtime; + + @Getter + private final Object cumulative; + + @Getter + private final Object realtime; + + @Getter + private final URI url; + + @Getter private final String workflowSid; + + @Getter private final String workspaceSid; - private final URI url; @JsonCreator - private WorkflowStatistics(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("cumulative") - final Map cumulative, - @JsonProperty("realtime") - final Map realtime, - @JsonProperty("workflow_sid") - final String workflowSid, - @JsonProperty("workspace_sid") - final String workspaceSid, - @JsonProperty("url") - final URI url) { + private WorkflowStatistics( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("cumulative") final Object cumulative, + @JsonProperty("realtime") final Object realtime, + @JsonProperty("url") final URI url, + @JsonProperty("workflow_sid") final String workflowSid, + @JsonProperty("workspace_sid") final String workspaceSid + ) { this.accountSid = accountSid; this.cumulative = cumulative; this.realtime = realtime; + this.url = url; this.workflowSid = workflowSid; this.workspaceSid = workspaceSid; - this.url = url; - } - - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The cumulative. - * - * @return The cumulative - */ - public final Map getCumulative() { - return this.cumulative; - } - - /** - * Returns The The realtime. - * - * @return The realtime - */ - public final Map getRealtime() { - return this.realtime; - } - - /** - * Returns The The workflow_sid. - * - * @return The workflow_sid - */ - public final String getWorkflowSid() { - return this.workflowSid; - } - - /** - * Returns The The workspace_sid. - * - * @return The workspace_sid - */ - public final String getWorkspaceSid() { - return this.workspaceSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; } @Override @@ -178,34 +147,25 @@ public boolean equals(final Object o) { } WorkflowStatistics other = (WorkflowStatistics) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(cumulative, other.cumulative) && - Objects.equals(realtime, other.realtime) && - Objects.equals(workflowSid, other.workflowSid) && - Objects.equals(workspaceSid, other.workspaceSid) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(cumulative, other.cumulative) && + Objects.equals(realtime, other.realtime) && + Objects.equals(url, other.url) && + Objects.equals(workflowSid, other.workflowSid) && + Objects.equals(workspaceSid, other.workspaceSid) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - cumulative, - realtime, - workflowSid, - workspaceSid, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("cumulative", cumulative) - .add("realtime", realtime) - .add("workflowSid", workflowSid) - .add("workspaceSid", workspaceSid) - .add("url", url) - .toString(); + return Objects.hash( + accountSid, + cumulative, + realtime, + url, + workflowSid, + workspaceSid + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatisticsFetcher.java b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatisticsFetcher.java index fba019396b..ae69ec45b4 100644 --- a/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatisticsFetcher.java +++ b/src/main/java/com/twilio/rest/taskrouter/v1/workspace/workflow/WorkflowStatisticsFetcher.java @@ -1,14 +1,23 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Taskrouter + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.taskrouter.v1.workspace.workflow; import com.twilio.base.Fetcher; -import com.twilio.converter.DateConverter; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,158 +26,171 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; -import org.joda.time.DateTime; +import com.twilio.type.*; +import java.io.InputStream; +import java.time.ZonedDateTime; public class WorkflowStatisticsFetcher extends Fetcher { - private final String pathWorkspaceSid; - private final String pathWorkflowSid; + + private String pathWorkspaceSid; + private String pathWorkflowSid; private Integer minutes; - private DateTime startDate; - private DateTime endDate; + private ZonedDateTime startDate; + private ZonedDateTime endDate; private String taskChannel; private String splitByWaitTime; - /** - * Construct a new WorkflowStatisticsFetcher. - * - * @param pathWorkspaceSid The workspace_sid - * @param pathWorkflowSid The workflow_sid - */ - public WorkflowStatisticsFetcher(final String pathWorkspaceSid, - final String pathWorkflowSid) { + public WorkflowStatisticsFetcher( + final String pathWorkspaceSid, + final String pathWorkflowSid + ) { this.pathWorkspaceSid = pathWorkspaceSid; this.pathWorkflowSid = pathWorkflowSid; } - /** - * Filter cumulative statistics by up to ‘x’ minutes in the past. This is - * helpful for statistics for the last 15 minutes, 240 minutes (4 hours), and - * 480 minutes (8 hours) to see trends. Defaults to 15 minutes.. - * - * @param minutes Filter cumulative statistics by up to ‘x’ minutes in the past. - * @return this - */ public WorkflowStatisticsFetcher setMinutes(final Integer minutes) { this.minutes = minutes; return this; } - /** - * Filter cumulative statistics by a start date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp. - * - * @param startDate Filter cumulative statistics by a start date. - * @return this - */ - public WorkflowStatisticsFetcher setStartDate(final DateTime startDate) { + public WorkflowStatisticsFetcher setStartDate( + final ZonedDateTime startDate + ) { this.startDate = startDate; return this; } - /** - * Filter cumulative statistics by an end date. This is helpful for defining a - * range of statistics to capture. Input is a GMT ISO 8601 Timestamp. - * - * @param endDate Filter cumulative statistics by an end date. - * @return this - */ - public WorkflowStatisticsFetcher setEndDate(final DateTime endDate) { + public WorkflowStatisticsFetcher setEndDate(final ZonedDateTime endDate) { this.endDate = endDate; return this; } - /** - * Filter real-time and cumulative statistics by TaskChannel. Takes in a Unique - * Name ("voice", "sms", "default", etc.) or a TaskChannelSid.. - * - * @param taskChannel Filter real-time and cumulative statistics by TaskChannel. - * @return this - */ public WorkflowStatisticsFetcher setTaskChannel(final String taskChannel) { this.taskChannel = taskChannel; return this; } - /** - * A comma separated values for viewing splits of tasks canceled and accepted - * above the given threshold in seconds. Ex: "5,30" would show splits of tasks - * that were canceled or accepted before or after 5 seconds and respectively, 30 - * seconds. This is great for showing short abandoned tasks or tasks that failed - * to meet your SLA.. - * - * @param splitByWaitTime A comma separated values for viewing splits of tasks - * canceled and accepted above the given threshold in - * seconds. - * @return this - */ - public WorkflowStatisticsFetcher setSplitByWaitTime(final String splitByWaitTime) { + public WorkflowStatisticsFetcher setSplitByWaitTime( + final String splitByWaitTime + ) { this.splitByWaitTime = splitByWaitTime; return this; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched WorkflowStatistics - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public WorkflowStatistics fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/Workspaces/{WorkspaceSid}/Workflows/{WorkflowSid}/Statistics"; + + path = + path.replace( + "{" + "WorkspaceSid" + "}", + this.pathWorkspaceSid.toString() + ); + path = + path.replace( + "{" + "WorkflowSid" + "}", + this.pathWorkflowSid.toString() + ); + Request request = new Request( HttpMethod.GET, Domains.TASKROUTER.toString(), - "/v1/Workspaces/" + this.pathWorkspaceSid + "/Workflows/" + this.pathWorkflowSid + "/Statistics", - client.getRegion() + path ); - addQueryParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("WorkflowStatistics fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "WorkflowStatistics fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return WorkflowStatistics.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public WorkflowStatistics fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return WorkflowStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + WorkflowStatistics content = WorkflowStatistics.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { if (minutes != null) { - request.addQueryParam("Minutes", minutes.toString()); + Serializer.toString( + request, + "Minutes", + minutes, + ParameterType.QUERY + ); } if (startDate != null) { - request.addQueryParam("StartDate", startDate.toString()); + Serializer.toString( + request, + "StartDate", + startDate, + ParameterType.QUERY + ); } if (endDate != null) { - request.addQueryParam("EndDate", endDate.toString()); + Serializer.toString( + request, + "EndDate", + endDate, + ParameterType.QUERY + ); } if (taskChannel != null) { - request.addQueryParam("TaskChannel", taskChannel); + Serializer.toString( + request, + "TaskChannel", + taskChannel, + ParameterType.QUERY + ); } if (splitByWaitTime != null) { - request.addQueryParam("SplitByWaitTime", splitByWaitTime); + Serializer.toString( + request, + "SplitByWaitTime", + splitByWaitTime, + ParameterType.QUERY + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/Trunk.java b/src/main/java/com/twilio/rest/trunking/v1/Trunk.java index 3ab7a2be52..4cdbb8c4cd 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/Trunk.java +++ b/src/main/java/com/twilio/rest/trunking/v1/Trunk.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1; @@ -10,117 +17,110 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.Converter; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class Trunk extends Resource { - private static final long serialVersionUID = 237038422793901L; - public enum RecordingSetting { - DO_NOT_RECORD("do-not-record"), - RECORD_FROM_RINGING("record-from-ringing"), - RECORD_FROM_ANSWER("record-from-answer"); + public static TrunkCreator creator() { + return new TrunkCreator(); + } + + public static TrunkDeleter deleter(final String pathSid) { + return new TrunkDeleter(pathSid); + } + + public static TrunkFetcher fetcher(final String pathSid) { + return new TrunkFetcher(pathSid); + } + + public static TrunkReader reader() { + return new TrunkReader(); + } + + public static TrunkUpdater updater(final String pathSid) { + return new TrunkUpdater(pathSid); + } + + public enum TransferSetting { + DISABLE_ALL("disable-all"), + ENABLE_ALL("enable-all"), + SIP_ONLY("sip-only"); private final String value; - private RecordingSetting(final String value) { + private TransferSetting(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a RecordingSetting from a string. - * @param value string value - * @return generated RecordingSetting - */ @JsonCreator - public static RecordingSetting forValue(final String value) { - return Promoter.enumFromString(value, RecordingSetting.values()); + public static TransferSetting forValue(final String value) { + return Promoter.enumFromString(value, TransferSetting.values()); } } - /** - * Create a TrunkFetcher to execute fetch. - * - * @param pathSid The sid - * @return TrunkFetcher capable of executing the fetch - */ - public static TrunkFetcher fetcher(final String pathSid) { - return new TrunkFetcher(pathSid); - } + public enum TransferCallerId { + FROM_TRANSFEREE("from-transferee"), + FROM_TRANSFEROR("from-transferor"); - /** - * Create a TrunkDeleter to execute delete. - * - * @param pathSid The sid - * @return TrunkDeleter capable of executing the delete - */ - public static TrunkDeleter deleter(final String pathSid) { - return new TrunkDeleter(pathSid); - } + private final String value; - /** - * Create a TrunkCreator to execute create. - * - * @return TrunkCreator capable of executing the create - */ - public static TrunkCreator creator() { - return new TrunkCreator(); - } + private TransferCallerId(final String value) { + this.value = value; + } - /** - * Create a TrunkReader to execute read. - * - * @return TrunkReader capable of executing the read - */ - public static TrunkReader reader() { - return new TrunkReader(); - } + @JsonValue + public String toString() { + return value; + } - /** - * Create a TrunkUpdater to execute update. - * - * @param pathSid The sid - * @return TrunkUpdater capable of executing the update - */ - public static TrunkUpdater updater(final String pathSid) { - return new TrunkUpdater(pathSid); + @JsonCreator + public static TransferCallerId forValue(final String value) { + return Promoter.enumFromString(value, TransferCallerId.values()); + } } /** * Converts a JSON String into a Trunk object using the provided ObjectMapper. - * + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return Trunk object represented by the provided JSON */ - public static Trunk fromJson(final String json, final ObjectMapper objectMapper) { + public static Trunk fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trunk.class); @@ -134,12 +134,15 @@ public static Trunk fromJson(final String json, final ObjectMapper objectMapper) /** * Converts a JSON InputStream into a Trunk object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return Trunk object represented by the provided JSON */ - public static Trunk fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static Trunk fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, Trunk.class); @@ -150,211 +153,127 @@ public static Trunk fromJson(final InputStream json, final ObjectMapper objectMa } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; - private final String domainName; - private final HttpMethod disasterRecoveryMethod; - private final URI disasterRecoveryUrl; - private final String friendlyName; - private final Boolean secure; - private final Map recording; - private final Boolean cnamLookupEnabled; + + @Getter private final String authType; + + @Getter private final List authTypeSet; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final String sid; - private final URI url; - private final Map links; - @JsonCreator - private Trunk(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("domain_name") - final String domainName, - @JsonProperty("disaster_recovery_method") - final HttpMethod disasterRecoveryMethod, - @JsonProperty("disaster_recovery_url") - final URI disasterRecoveryUrl, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("secure") - final Boolean secure, - @JsonProperty("recording") - final Map recording, - @JsonProperty("cnam_lookup_enabled") - final Boolean cnamLookupEnabled, - @JsonProperty("auth_type") - final String authType, - @JsonProperty("auth_type_set") - final List authTypeSet, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("sid") - final String sid, - @JsonProperty("url") - final URI url, - @JsonProperty("links") - final Map links) { - this.accountSid = accountSid; - this.domainName = domainName; - this.disasterRecoveryMethod = disasterRecoveryMethod; - this.disasterRecoveryUrl = disasterRecoveryUrl; - this.friendlyName = friendlyName; - this.secure = secure; - this.recording = recording; - this.cnamLookupEnabled = cnamLookupEnabled; - this.authType = authType; - this.authTypeSet = authTypeSet; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.sid = sid; - this.url = url; - this.links = links; - } + @Getter + private final Boolean cnamLookupEnabled; - /** - * Returns The The unique ID of the Account that owns this Trunk.. - * - * @return The unique ID of the Account that owns this Trunk. - */ - public final String getAccountSid() { - return this.accountSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique address you reserve on Twilio to which you route your - * SIP traffic.. - * - * @return The unique address you reserve on Twilio to which you route your SIP - * traffic. - */ - public final String getDomainName() { - return this.domainName; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The The HTTP method Twilio will use when requesting the - * DisasterRecoveryUrl.. - * - * @return The HTTP method Twilio will use when requesting the - * DisasterRecoveryUrl. - */ - public final HttpMethod getDisasterRecoveryMethod() { - return this.disasterRecoveryMethod; - } + @Getter + private final HttpMethod disasterRecoveryMethod; - /** - * Returns The The HTTP URL that Twilio will request if an error occurs while - * sending SIP traffic towards your configured Origination URL.. - * - * @return The HTTP URL that Twilio will request if an error occurs while - * sending SIP traffic towards your configured Origination URL. - */ - public final URI getDisasterRecoveryUrl() { - return this.disasterRecoveryUrl; - } + @Getter + private final URI disasterRecoveryUrl; - /** - * Returns The A human-readable name for the Trunk.. - * - * @return A human-readable name for the Trunk. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String domainName; - /** - * Returns The The Secure Trunking settings for this trunk.. - * - * @return The Secure Trunking settings for this trunk. - */ - public final Boolean getSecure() { - return this.secure; - } + @Getter + private final String friendlyName; - /** - * Returns The The recording settings for this trunk.. - * - * @return The recording settings for this trunk. - */ - public final Map getRecording() { - return this.recording; - } + @Getter + private final Map links; - /** - * Returns The The Caller ID Name (CNAM) lookup setting for this trunk.. - * - * @return The Caller ID Name (CNAM) lookup setting for this trunk. - */ - public final Boolean getCnamLookupEnabled() { - return this.cnamLookupEnabled; - } + @Getter + private final Object recording; - /** - * Returns The The types of authentication you have mapped to your domain.. - * - * @return The types of authentication you have mapped to your domain. - */ - public final String getAuthType() { - return this.authType; - } + @Getter + private final Boolean secure; - /** - * Returns The The auth_type_set. - * - * @return The auth_type_set - */ - public final List getAuthTypeSet() { - return this.authTypeSet; - } + @Getter + private final String sid; - /** - * Returns The The date this Activity was created.. - * - * @return The date this Activity was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final Boolean symmetricRtpEnabled; - /** - * Returns The The date this Activity was updated.. - * - * @return The date this Activity was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final Trunk.TransferCallerId transferCallerId; - /** - * Returns The A 34 character string that uniquely identifies the SIP Trunk in - * Twilio.. - * - * @return A 34 character string that uniquely identifies the SIP Trunk in - * Twilio. - */ - public final String getSid() { - return this.sid; - } + @Getter + private final Trunk.TransferSetting transferMode; - /** - * Returns The The URL for this resource, relative to https://trunking.. - * - * @return The URL for this resource, relative to https://trunking. - */ - public final URI getUrl() { - return this.url; - } + @Getter + private final URI url; - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; + @JsonCreator + private Trunk( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("auth_type") final String authType, + @JsonProperty("auth_type_set") final List authTypeSet, + @JsonProperty("cnam_lookup_enabled") final Boolean cnamLookupEnabled, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty( + "disaster_recovery_method" + ) final HttpMethod disasterRecoveryMethod, + @JsonProperty("disaster_recovery_url") final URI disasterRecoveryUrl, + @JsonProperty("domain_name") final String domainName, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("recording") final Object recording, + @JsonProperty("secure") final Boolean secure, + @JsonProperty("sid") final String sid, + @JsonProperty( + "symmetric_rtp_enabled" + ) final Boolean symmetricRtpEnabled, + @JsonProperty( + "transfer_caller_id" + ) final Trunk.TransferCallerId transferCallerId, + @JsonProperty("transfer_mode") final Trunk.TransferSetting transferMode, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.authType = authType; + this.authTypeSet = authTypeSet; + this.cnamLookupEnabled = cnamLookupEnabled; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.disasterRecoveryMethod = disasterRecoveryMethod; + this.disasterRecoveryUrl = disasterRecoveryUrl; + this.domainName = domainName; + this.friendlyName = friendlyName; + this.links = links; + this.recording = recording; + this.secure = secure; + this.sid = sid; + this.symmetricRtpEnabled = symmetricRtpEnabled; + this.transferCallerId = transferCallerId; + this.transferMode = transferMode; + this.url = url; } @Override @@ -368,61 +287,52 @@ public boolean equals(final Object o) { } Trunk other = (Trunk) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(domainName, other.domainName) && - Objects.equals(disasterRecoveryMethod, other.disasterRecoveryMethod) && - Objects.equals(disasterRecoveryUrl, other.disasterRecoveryUrl) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(secure, other.secure) && - Objects.equals(recording, other.recording) && - Objects.equals(cnamLookupEnabled, other.cnamLookupEnabled) && - Objects.equals(authType, other.authType) && - Objects.equals(authTypeSet, other.authTypeSet) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(sid, other.sid) && - Objects.equals(url, other.url) && - Objects.equals(links, other.links); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(authType, other.authType) && + Objects.equals(authTypeSet, other.authTypeSet) && + Objects.equals(cnamLookupEnabled, other.cnamLookupEnabled) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals( + disasterRecoveryMethod, + other.disasterRecoveryMethod + ) && + Objects.equals(disasterRecoveryUrl, other.disasterRecoveryUrl) && + Objects.equals(domainName, other.domainName) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(recording, other.recording) && + Objects.equals(secure, other.secure) && + Objects.equals(sid, other.sid) && + Objects.equals(symmetricRtpEnabled, other.symmetricRtpEnabled) && + Objects.equals(transferCallerId, other.transferCallerId) && + Objects.equals(transferMode, other.transferMode) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - domainName, - disasterRecoveryMethod, - disasterRecoveryUrl, - friendlyName, - secure, - recording, - cnamLookupEnabled, - authType, - authTypeSet, - dateCreated, - dateUpdated, - sid, - url, - links); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("domainName", domainName) - .add("disasterRecoveryMethod", disasterRecoveryMethod) - .add("disasterRecoveryUrl", disasterRecoveryUrl) - .add("friendlyName", friendlyName) - .add("secure", secure) - .add("recording", recording) - .add("cnamLookupEnabled", cnamLookupEnabled) - .add("authType", authType) - .add("authTypeSet", authTypeSet) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("sid", sid) - .add("url", url) - .add("links", links) - .toString(); + return Objects.hash( + accountSid, + authType, + authTypeSet, + cnamLookupEnabled, + dateCreated, + dateUpdated, + disasterRecoveryMethod, + disasterRecoveryUrl, + domainName, + friendlyName, + links, + recording, + secure, + sid, + symmetricRtpEnabled, + transferCallerId, + transferMode, + url + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkCreator.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkCreator.java index ab00f6c08a..ac891f161b 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkCreator.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,205 +28,204 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class TrunkCreator extends Creator { + private String friendlyName; private String domainName; private URI disasterRecoveryUrl; private HttpMethod disasterRecoveryMethod; - private Trunk.RecordingSetting recording; + private Trunk.TransferSetting transferMode; private Boolean secure; private Boolean cnamLookupEnabled; + private Trunk.TransferCallerId transferCallerId; + + public TrunkCreator() {} - /** - * A human-readable name for the Trunk.. - * - * @param friendlyName A human-readable name for the Trunk. - * @return this - */ public TrunkCreator setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The unique address you reserve on Twilio to which you route your SIP traffic. - * Domain names can contain letters, digits, and `-` and must always end with - * `pstn.twilio.com`. See [Termination - * Settings](https://www.twilio.com/docs/sip-trunking/getting-started#termination) for more information.. - * - * @param domainName The unique address you reserve on Twilio to which you - * route your SIP traffic. - * @return this - */ public TrunkCreator setDomainName(final String domainName) { this.domainName = domainName; return this; } - /** - * The HTTP URL that Twilio will request if an error occurs while sending SIP - * traffic towards your configured Origination URL. Twilio will retrieve TwiML - * from this URL and execute those instructions like any other normal TwiML - * call. See [Disaster - * Recovery](https://www.twilio.com/docs/sip-trunking/getting-started#disaster-recovery) for more information.. - * - * @param disasterRecoveryUrl The HTTP URL that Twilio will request if an error - * occurs while sending SIP traffic towards your - * configured Origination URL. - * @return this - */ public TrunkCreator setDisasterRecoveryUrl(final URI disasterRecoveryUrl) { this.disasterRecoveryUrl = disasterRecoveryUrl; return this; } - /** - * The HTTP URL that Twilio will request if an error occurs while sending SIP - * traffic towards your configured Origination URL. Twilio will retrieve TwiML - * from this URL and execute those instructions like any other normal TwiML - * call. See [Disaster - * Recovery](https://www.twilio.com/docs/sip-trunking/getting-started#disaster-recovery) for more information.. - * - * @param disasterRecoveryUrl The HTTP URL that Twilio will request if an error - * occurs while sending SIP traffic towards your - * configured Origination URL. - * @return this - */ - public TrunkCreator setDisasterRecoveryUrl(final String disasterRecoveryUrl) { - return setDisasterRecoveryUrl(Promoter.uriFromString(disasterRecoveryUrl)); + public TrunkCreator setDisasterRecoveryUrl( + final String disasterRecoveryUrl + ) { + return setDisasterRecoveryUrl( + Promoter.uriFromString(disasterRecoveryUrl) + ); } - /** - * The HTTP method Twilio will use when requesting the `DisasterRecoveryUrl`. - * Either `GET` or `POST`.. - * - * @param disasterRecoveryMethod The HTTP method Twilio will use when - * requesting the DisasterRecoveryUrl. - * @return this - */ - public TrunkCreator setDisasterRecoveryMethod(final HttpMethod disasterRecoveryMethod) { + public TrunkCreator setDisasterRecoveryMethod( + final HttpMethod disasterRecoveryMethod + ) { this.disasterRecoveryMethod = disasterRecoveryMethod; return this; } - /** - * The recording settings for this trunk. If turned on, all calls going through - * this trunk will be recorded and the recording can either start when the call - * is ringing or when the call is answered. See - * [Recording](https://www.twilio.com/docs/sip-trunking/getting-started#recording) for more information.. - * - * @param recording The recording settings for this trunk. - * @return this - */ - public TrunkCreator setRecording(final Trunk.RecordingSetting recording) { - this.recording = recording; + public TrunkCreator setTransferMode( + final Trunk.TransferSetting transferMode + ) { + this.transferMode = transferMode; return this; } - /** - * The Secure Trunking settings for this trunk. If turned on, all calls going - * through this trunk will be secure using SRTP for media and TLS for - * signalling. If turned off, then RTP will be used for media. See [Secure - * Trunking](https://www.twilio.com/docs/sip-trunking/getting-started#securetrunking) for more information.. - * - * @param secure The Secure Trunking settings for this trunk. - * @return this - */ public TrunkCreator setSecure(final Boolean secure) { this.secure = secure; return this; } - /** - * The Caller ID Name (CNAM) lookup setting for this trunk. If turned on, all - * inbound calls to this SIP Trunk from the United States and Canada will - * automatically perform a CNAM Lookup and display Caller ID data on your phone. - * See [CNAM](https://www.twilio.com/docs/sip-trunking#CNAM) Lookups for more - * information.. - * - * @param cnamLookupEnabled The Caller ID Name (CNAM) lookup setting for this - * trunk. - * @return this - */ public TrunkCreator setCnamLookupEnabled(final Boolean cnamLookupEnabled) { this.cnamLookupEnabled = cnamLookupEnabled; return this; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created Trunk - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Trunk create(final TwilioRestClient client) { + public TrunkCreator setTransferCallerId( + final Trunk.TransferCallerId transferCallerId + ) { + this.transferCallerId = transferCallerId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks"; + Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), - "/v1/Trunks", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Trunk creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Trunk create(final TwilioRestClient client) { + Response response = makeRequest(client); return Trunk.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Trunk content = Trunk.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (domainName != null) { - request.addPostParam("DomainName", domainName); + Serializer.toString( + request, + "DomainName", + domainName, + ParameterType.URLENCODED + ); } if (disasterRecoveryUrl != null) { - request.addPostParam("DisasterRecoveryUrl", disasterRecoveryUrl.toString()); + Serializer.toString( + request, + "DisasterRecoveryUrl", + disasterRecoveryUrl, + ParameterType.URLENCODED + ); } if (disasterRecoveryMethod != null) { - request.addPostParam("DisasterRecoveryMethod", disasterRecoveryMethod.toString()); + Serializer.toString( + request, + "DisasterRecoveryMethod", + disasterRecoveryMethod, + ParameterType.URLENCODED + ); } - if (recording != null) { - request.addPostParam("Recording", recording.toString()); + if (transferMode != null) { + Serializer.toString( + request, + "TransferMode", + transferMode, + ParameterType.URLENCODED + ); } if (secure != null) { - request.addPostParam("Secure", secure.toString()); + Serializer.toString( + request, + "Secure", + secure, + ParameterType.URLENCODED + ); } if (cnamLookupEnabled != null) { - request.addPostParam("CnamLookupEnabled", cnamLookupEnabled.toString()); + Serializer.toString( + request, + "CnamLookupEnabled", + cnamLookupEnabled, + ParameterType.URLENCODED + ); + } + + if (transferCallerId != null) { + Serializer.toString( + request, + "TransferCallerId", + transferCallerId, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkDeleter.java index af1ff3c076..2c332aec0c 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,53 +24,74 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class TrunkDeleter extends Deleter { - private final String pathSid; - /** - * Construct a new TrunkDeleter. - * - * @param pathSid The sid - */ + private String pathSid; + public TrunkDeleter(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Trunk delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkFetcher.java index e649280f48..4c26a933a7 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,54 +24,70 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TrunkFetcher extends Fetcher { - private final String pathSid; - /** - * Construct a new TrunkFetcher. - * - * @param pathSid The sid - */ + private String pathSid; + public TrunkFetcher(final String pathSid) { this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched Trunk - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Trunk fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Trunk fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Trunk fetch(final TwilioRestClient client) { + Response response = makeRequest(client); return Trunk.fromJson(response.getStream(), client.getObjectMapper()); } -} \ No newline at end of file + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Trunk content = Trunk.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkReader.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkReader.java index 03c8194610..ec98c58b22 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1; @@ -10,148 +17,182 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class TrunkReader extends Reader { - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Trunk ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + + private Long pageSize; + + public TrunkReader() {} + + public TrunkReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return Trunk ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "trunks", + response.getContent(), + Trunk.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Trunks"; + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return Trunk ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "trunks", + response.getContent(), + Trunk.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Trunk read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "trunks", + response.getContent(), + Trunk.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of Trunk Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("Trunk read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "trunks", - response.getContent(), - Trunk.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/TrunkUpdater.java b/src/main/java/com/twilio/rest/trunking/v1/TrunkUpdater.java index cc296f166c..c2d26874e7 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/TrunkUpdater.java +++ b/src/main/java/com/twilio/rest/trunking/v1/TrunkUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,215 +28,209 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class TrunkUpdater extends Updater { - private final String pathSid; + + private String pathSid; private String friendlyName; private String domainName; private URI disasterRecoveryUrl; private HttpMethod disasterRecoveryMethod; - private Trunk.RecordingSetting recording; + private Trunk.TransferSetting transferMode; private Boolean secure; private Boolean cnamLookupEnabled; + private Trunk.TransferCallerId transferCallerId; - /** - * Construct a new TrunkUpdater. - * - * @param pathSid The sid - */ public TrunkUpdater(final String pathSid) { this.pathSid = pathSid; } - /** - * A human-readable name for the Trunk.. - * - * @param friendlyName A human-readable name for the Trunk. - * @return this - */ public TrunkUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The unique address you reserve on Twilio to which you route your SIP traffic. - * Domain names can contain letters, digits, and `-` and must always end with - * `pstn.twilio.com`. See [Termination - * Settings](https://www.twilio.com/docs/sip-trunking/getting-started#termination) for more information.. - * - * @param domainName The unique address you reserve on Twilio to which you - * route your SIP traffic. - * @return this - */ public TrunkUpdater setDomainName(final String domainName) { this.domainName = domainName; return this; } - /** - * The HTTP URL that Twilio will request if an error occurs while sending SIP - * traffic towards your configured Origination URL. Twilio will retrieve TwiML - * from this URL and execute those instructions like any other normal TwiML - * call. See [Disaster - * Recovery](https://www.twilio.com/docs/sip-trunking/getting-started#disaster-recovery) for more information.. - * - * @param disasterRecoveryUrl The HTTP URL that Twilio will request if an error - * occurs while sending SIP traffic towards your - * configured Origination URL. - * @return this - */ public TrunkUpdater setDisasterRecoveryUrl(final URI disasterRecoveryUrl) { this.disasterRecoveryUrl = disasterRecoveryUrl; return this; } - /** - * The HTTP URL that Twilio will request if an error occurs while sending SIP - * traffic towards your configured Origination URL. Twilio will retrieve TwiML - * from this URL and execute those instructions like any other normal TwiML - * call. See [Disaster - * Recovery](https://www.twilio.com/docs/sip-trunking/getting-started#disaster-recovery) for more information.. - * - * @param disasterRecoveryUrl The HTTP URL that Twilio will request if an error - * occurs while sending SIP traffic towards your - * configured Origination URL. - * @return this - */ - public TrunkUpdater setDisasterRecoveryUrl(final String disasterRecoveryUrl) { - return setDisasterRecoveryUrl(Promoter.uriFromString(disasterRecoveryUrl)); + public TrunkUpdater setDisasterRecoveryUrl( + final String disasterRecoveryUrl + ) { + return setDisasterRecoveryUrl( + Promoter.uriFromString(disasterRecoveryUrl) + ); } - /** - * The HTTP method Twilio will use when requesting the `DisasterRecoveryUrl`. - * Either `GET` or `POST`.. - * - * @param disasterRecoveryMethod The HTTP method Twilio will use when - * requesting the DisasterRecoveryUrl. - * @return this - */ - public TrunkUpdater setDisasterRecoveryMethod(final HttpMethod disasterRecoveryMethod) { + public TrunkUpdater setDisasterRecoveryMethod( + final HttpMethod disasterRecoveryMethod + ) { this.disasterRecoveryMethod = disasterRecoveryMethod; return this; } - /** - * The recording settings for this trunk. If turned on, all calls going through - * this trunk will be recorded and the recording can either start when the call - * is ringing or when the call is answered. See - * [Recording](https://www.twilio.com/docs/sip-trunking/getting-started#recording) for more information.. - * - * @param recording The recording settings for this trunk. - * @return this - */ - public TrunkUpdater setRecording(final Trunk.RecordingSetting recording) { - this.recording = recording; + public TrunkUpdater setTransferMode( + final Trunk.TransferSetting transferMode + ) { + this.transferMode = transferMode; return this; } - /** - * The Secure Trunking settings for this trunk. If turned on, all calls going - * through this trunk will be secure using SRTP for media and TLS for - * signalling. If turned off, then RTP will be used for media. See [Secure - * Trunking](https://www.twilio.com/docs/sip-trunking/getting-started#securetrunking) for more information.. - * - * @param secure The Secure Trunking settings for this trunk. - * @return this - */ public TrunkUpdater setSecure(final Boolean secure) { this.secure = secure; return this; } - /** - * The Caller ID Name (CNAM) lookup setting for this trunk. If turned on, all - * inbound calls to this SIP Trunk from the United States and Canada will - * automatically perform a CNAM Lookup and display Caller ID data on your phone. - * See [CNAM](https://www.twilio.com/docs/sip-trunking#CNAM) Lookups for more - * information.. - * - * @param cnamLookupEnabled The Caller ID Name (CNAM) lookup setting for this - * trunk. - * @return this - */ public TrunkUpdater setCnamLookupEnabled(final Boolean cnamLookupEnabled) { this.cnamLookupEnabled = cnamLookupEnabled; return this; } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated Trunk - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Trunk update(final TwilioRestClient client) { + public TrunkUpdater setTransferCallerId( + final Trunk.TransferCallerId transferCallerId + ) { + this.transferCallerId = transferCallerId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("Trunk update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "Trunk update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + @Override + public Trunk update(final TwilioRestClient client) { + Response response = makeRequest(client); return Trunk.fromJson(response.getStream(), client.getObjectMapper()); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Trunk content = Trunk.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + private void addPostParams(final Request request) { if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (domainName != null) { - request.addPostParam("DomainName", domainName); + Serializer.toString( + request, + "DomainName", + domainName, + ParameterType.URLENCODED + ); } if (disasterRecoveryUrl != null) { - request.addPostParam("DisasterRecoveryUrl", disasterRecoveryUrl.toString()); + Serializer.toString( + request, + "DisasterRecoveryUrl", + disasterRecoveryUrl, + ParameterType.URLENCODED + ); } if (disasterRecoveryMethod != null) { - request.addPostParam("DisasterRecoveryMethod", disasterRecoveryMethod.toString()); + Serializer.toString( + request, + "DisasterRecoveryMethod", + disasterRecoveryMethod, + ParameterType.URLENCODED + ); } - if (recording != null) { - request.addPostParam("Recording", recording.toString()); + if (transferMode != null) { + Serializer.toString( + request, + "TransferMode", + transferMode, + ParameterType.URLENCODED + ); } if (secure != null) { - request.addPostParam("Secure", secure.toString()); + Serializer.toString( + request, + "Secure", + secure, + ParameterType.URLENCODED + ); } if (cnamLookupEnabled != null) { - request.addPostParam("CnamLookupEnabled", cnamLookupEnabled.toString()); + Serializer.toString( + request, + "CnamLookupEnabled", + cnamLookupEnabled, + ParameterType.URLENCODED + ); + } + + if (transferCallerId != null) { + Serializer.toString( + request, + "TransferCallerId", + transferCallerId, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialList.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialList.java index c1723f900d..f0a3cc047c 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialList.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialList.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; @@ -11,89 +18,66 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class CredentialList extends Resource { - private static final long serialVersionUID = 45032598628398L; - /** - * Create a CredentialListFetcher to execute fetch. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return CredentialListFetcher capable of executing the fetch - */ - public static CredentialListFetcher fetcher(final String pathTrunkSid, - final String pathSid) { - return new CredentialListFetcher(pathTrunkSid, pathSid); + public static CredentialListCreator creator( + final String pathTrunkSid, + final String credentialListSid + ) { + return new CredentialListCreator(pathTrunkSid, credentialListSid); } - /** - * Create a CredentialListDeleter to execute delete. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return CredentialListDeleter capable of executing the delete - */ - public static CredentialListDeleter deleter(final String pathTrunkSid, - final String pathSid) { + public static CredentialListDeleter deleter( + final String pathTrunkSid, + final String pathSid + ) { return new CredentialListDeleter(pathTrunkSid, pathSid); } - /** - * Create a CredentialListCreator to execute create. - * - * @param pathTrunkSid The trunk_sid - * @param credentialListSid The SID of the Credential List that you want to - * associate with this trunk. Once associated, Twilio - * will start authenticating access to the trunk - * against this list. - * @return CredentialListCreator capable of executing the create - */ - public static CredentialListCreator creator(final String pathTrunkSid, - final String credentialListSid) { - return new CredentialListCreator(pathTrunkSid, credentialListSid); + public static CredentialListFetcher fetcher( + final String pathTrunkSid, + final String pathSid + ) { + return new CredentialListFetcher(pathTrunkSid, pathSid); } - /** - * Create a CredentialListReader to execute read. - * - * @param pathTrunkSid The trunk_sid - * @return CredentialListReader capable of executing the read - */ public static CredentialListReader reader(final String pathTrunkSid) { return new CredentialListReader(pathTrunkSid); } /** - * Converts a JSON String into a CredentialList object using the provided - * ObjectMapper. - * + * Converts a JSON String into a CredentialList object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return CredentialList object represented by the provided JSON */ - public static CredentialList fromJson(final String json, final ObjectMapper objectMapper) { + public static CredentialList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialList.class); @@ -107,12 +91,15 @@ public static CredentialList fromJson(final String json, final ObjectMapper obje /** * Converts a JSON InputStream into a CredentialList object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return CredentialList object represented by the provided JSON */ - public static CredentialList fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static CredentialList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, CredentialList.class); @@ -123,101 +110,68 @@ public static CredentialList fromJson(final InputStream json, final ObjectMapper } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter private final String sid; + + @Getter private final String trunkSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final URI url; @JsonCreator - private CredentialList(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { + private CredentialList( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; this.sid = sid; this.trunkSid = trunkSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.url = url; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The trunk_sid. - * - * @return The trunk_sid - */ - public final String getTrunkSid() { - return this.trunkSid; - } - - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -229,37 +183,27 @@ public boolean equals(final Object o) { } CredentialList other = (CredentialList) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(sid, other.sid) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - sid, - trunkSid, - friendlyName, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("sid", sid) - .add("trunkSid", trunkSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + trunkSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListCreator.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListCreator.java index eecd0781be..d948e4eae1 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,73 +27,99 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialListCreator extends Creator { - private final String pathTrunkSid; - private final String credentialListSid; - /** - * Construct a new CredentialListCreator. - * - * @param pathTrunkSid The trunk_sid - * @param credentialListSid The SID of the Credential List that you want to - * associate with this trunk. Once associated, Twilio - * will start authenticating access to the trunk - * against this list. - */ - public CredentialListCreator(final String pathTrunkSid, - final String credentialListSid) { + private String pathTrunkSid; + private String credentialListSid; + + public CredentialListCreator( + final String pathTrunkSid, + final String credentialListSid + ) { this.pathTrunkSid = pathTrunkSid; this.credentialListSid = credentialListSid; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created CredentialList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public CredentialList create(final TwilioRestClient client) { + public CredentialListCreator setCredentialListSid( + final String credentialListSid + ) { + this.credentialListSid = credentialListSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/CredentialLists"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/CredentialLists", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialList creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public CredentialList create(final TwilioRestClient client) { + Response response = makeRequest(client); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CredentialList content = CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (credentialListSid != null) { - request.addPostParam("CredentialListSid", credentialListSid); + Serializer.toString( + request, + "CredentialListSid", + credentialListSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListDeleter.java index acfbd52cb5..a8248c285e 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class CredentialListDeleter extends Deleter { - private final String pathTrunkSid; - private final String pathSid; - /** - * Construct a new CredentialListDeleter. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public CredentialListDeleter(final String pathTrunkSid, - final String pathSid) { + private String pathTrunkSid; + private String pathSid; + + public CredentialListDeleter( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/CredentialLists/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/CredentialLists/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialList delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListFetcher.java index 9e324e357d..366a8f77ca 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,80 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialListFetcher extends Fetcher { - private final String pathTrunkSid; - private final String pathSid; - /** - * Construct a new CredentialListFetcher. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public CredentialListFetcher(final String pathTrunkSid, - final String pathSid) { + private String pathTrunkSid; + private String pathSid; + + public CredentialListFetcher( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched CredentialList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public CredentialList fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/CredentialLists/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/CredentialLists/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("CredentialList fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "CredentialList fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return CredentialList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public CredentialList fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CredentialList content = CredentialList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListReader.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListReader.java index 4f4476308a..5ee4a4c7dd 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/CredentialListReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; @@ -10,159 +17,192 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class CredentialListReader extends Reader { - private final String pathTrunkSid; - /** - * Construct a new CredentialListReader. - * - * @param pathTrunkSid The trunk_sid - */ + private String pathTrunkSid; + private Long pageSize; + public CredentialListReader(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return CredentialList ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public CredentialListReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return CredentialList ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credential_lists", + response.getContent(), + CredentialList.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/CredentialLists"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/CredentialLists", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return CredentialList ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "credential_lists", + response.getContent(), + CredentialList.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CredentialList read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "credential_lists", + response.getContent(), + CredentialList.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of CredentialList Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("CredentialList read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "credential_lists", - response.getContent(), - CredentialList.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlList.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlList.java index 107e453bc8..4d7877e075 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlList.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlList.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; @@ -11,87 +18,69 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class IpAccessControlList extends Resource { - private static final long serialVersionUID = 45032598628398L; - /** - * Create a IpAccessControlListFetcher to execute fetch. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return IpAccessControlListFetcher capable of executing the fetch - */ - public static IpAccessControlListFetcher fetcher(final String pathTrunkSid, - final String pathSid) { - return new IpAccessControlListFetcher(pathTrunkSid, pathSid); + public static IpAccessControlListCreator creator( + final String pathTrunkSid, + final String ipAccessControlListSid + ) { + return new IpAccessControlListCreator( + pathTrunkSid, + ipAccessControlListSid + ); } - /** - * Create a IpAccessControlListDeleter to execute delete. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return IpAccessControlListDeleter capable of executing the delete - */ - public static IpAccessControlListDeleter deleter(final String pathTrunkSid, - final String pathSid) { + public static IpAccessControlListDeleter deleter( + final String pathTrunkSid, + final String pathSid + ) { return new IpAccessControlListDeleter(pathTrunkSid, pathSid); } - /** - * Create a IpAccessControlListCreator to execute create. - * - * @param pathTrunkSid The trunk_sid - * @param ipAccessControlListSid The SID of the IP Access Control List that you - * want to associate with this trunk. - * @return IpAccessControlListCreator capable of executing the create - */ - public static IpAccessControlListCreator creator(final String pathTrunkSid, - final String ipAccessControlListSid) { - return new IpAccessControlListCreator(pathTrunkSid, ipAccessControlListSid); + public static IpAccessControlListFetcher fetcher( + final String pathTrunkSid, + final String pathSid + ) { + return new IpAccessControlListFetcher(pathTrunkSid, pathSid); } - /** - * Create a IpAccessControlListReader to execute read. - * - * @param pathTrunkSid The trunk_sid - * @return IpAccessControlListReader capable of executing the read - */ public static IpAccessControlListReader reader(final String pathTrunkSid) { return new IpAccessControlListReader(pathTrunkSid); } /** - * Converts a JSON String into a IpAccessControlList object using the provided - * ObjectMapper. - * + * Converts a JSON String into a IpAccessControlList object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return IpAccessControlList object represented by the provided JSON */ - public static IpAccessControlList fromJson(final String json, final ObjectMapper objectMapper) { + public static IpAccessControlList fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAccessControlList.class); @@ -103,14 +92,17 @@ public static IpAccessControlList fromJson(final String json, final ObjectMapper } /** - * Converts a JSON InputStream into a IpAccessControlList object using the - * provided ObjectMapper. - * + * Converts a JSON InputStream into a IpAccessControlList object using the provided + * ObjectMapper. + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return IpAccessControlList object represented by the provided JSON */ - public static IpAccessControlList fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static IpAccessControlList fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, IpAccessControlList.class); @@ -121,101 +113,68 @@ public static IpAccessControlList fromJson(final InputStream json, final ObjectM } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter private final String sid; + + @Getter private final String trunkSid; - private final String friendlyName; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter private final URI url; @JsonCreator - private IpAccessControlList(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { + private IpAccessControlList( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("url") final URI url + ) { this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; this.sid = sid; this.trunkSid = trunkSid; - this.friendlyName = friendlyName; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); this.url = url; } - /** - * Returns The The unique sid that identifies this account. - * - * @return The unique sid that identifies this account - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The A string that uniquely identifies this resource. - * - * @return A string that uniquely identifies this resource - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The unique sid that identifies the associated Trunk. - * - * @return The unique sid that identifies the associated Trunk - */ - public final String getTrunkSid() { - return this.trunkSid; - } - - /** - * Returns The A human readable description of this resource. - * - * @return A human readable description of this resource - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The date this resource was created. - * - * @return The date this resource was created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date this resource was last updated. - * - * @return The date this resource was last updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -227,37 +186,27 @@ public boolean equals(final Object o) { } IpAccessControlList other = (IpAccessControlList) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(sid, other.sid) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(url, other.url) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - sid, - trunkSid, - friendlyName, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("sid", sid) - .add("trunkSid", trunkSid) - .add("friendlyName", friendlyName) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + friendlyName, + sid, + trunkSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListCreator.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListCreator.java index 7b0e7c5dc1..68226c06a3 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,71 +27,99 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAccessControlListCreator extends Creator { - private final String pathTrunkSid; - private final String ipAccessControlListSid; - /** - * Construct a new IpAccessControlListCreator. - * - * @param pathTrunkSid The trunk_sid - * @param ipAccessControlListSid The SID of the IP Access Control List that you - * want to associate with this trunk. - */ - public IpAccessControlListCreator(final String pathTrunkSid, - final String ipAccessControlListSid) { + private String pathTrunkSid; + private String ipAccessControlListSid; + + public IpAccessControlListCreator( + final String pathTrunkSid, + final String ipAccessControlListSid + ) { this.pathTrunkSid = pathTrunkSid; this.ipAccessControlListSid = ipAccessControlListSid; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created IpAccessControlList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAccessControlList create(final TwilioRestClient client) { + public IpAccessControlListCreator setIpAccessControlListSid( + final String ipAccessControlListSid + ) { + this.ipAccessControlListSid = ipAccessControlListSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/IpAccessControlLists"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/IpAccessControlLists", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlList creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public IpAccessControlList create(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAccessControlList content = IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (ipAccessControlListSid != null) { - request.addPostParam("IpAccessControlListSid", ipAccessControlListSid); + Serializer.toString( + request, + "IpAccessControlListSid", + ipAccessControlListSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListDeleter.java index 77aae9df48..6e80c5c3e4 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class IpAccessControlListDeleter extends Deleter { - private final String pathTrunkSid; - private final String pathSid; - /** - * Construct a new IpAccessControlListDeleter. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public IpAccessControlListDeleter(final String pathTrunkSid, - final String pathSid) { + private String pathTrunkSid; + private String pathSid; + + public IpAccessControlListDeleter( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/IpAccessControlLists/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/IpAccessControlLists/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlList delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListFetcher.java index afcfa70f3a..da86055d60 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,80 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAccessControlListFetcher extends Fetcher { - private final String pathTrunkSid; - private final String pathSid; - /** - * Construct a new IpAccessControlListFetcher. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public IpAccessControlListFetcher(final String pathTrunkSid, - final String pathSid) { + private String pathTrunkSid; + private String pathSid; + + public IpAccessControlListFetcher( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched IpAccessControlList - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public IpAccessControlList fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/IpAccessControlLists/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/IpAccessControlLists/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("IpAccessControlList fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "IpAccessControlList fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return IpAccessControlList.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public IpAccessControlList fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + IpAccessControlList content = IpAccessControlList.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListReader.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListReader.java index 3abf3ec5a7..c2b5f827d6 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/IpAccessControlListReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; @@ -10,159 +17,194 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class IpAccessControlListReader extends Reader { - private final String pathTrunkSid; - /** - * Construct a new IpAccessControlListReader. - * - * @param pathTrunkSid The trunk_sid - */ + private String pathTrunkSid; + private Long pageSize; + public IpAccessControlListReader(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlList ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public IpAccessControlListReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlList ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_access_control_lists", + response.getContent(), + IpAccessControlList.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/IpAccessControlLists"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/IpAccessControlLists", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return IpAccessControlList ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "ip_access_control_lists", + response.getContent(), + IpAccessControlList.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "IpAccessControlList read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "ip_access_control_lists", + response.getContent(), + IpAccessControlList.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of IpAccessControlList Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("IpAccessControlList read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "ip_access_control_lists", - response.getContent(), - IpAccessControlList.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrl.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrl.java index e5bf464f6a..4fad6dff5c 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrl.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrl.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; @@ -11,110 +18,84 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; -import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.Map; +import java.time.ZonedDateTime; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class OriginationUrl extends Resource { - private static final long serialVersionUID = 147762448771620L; - /** - * Create a OriginationUrlFetcher to execute fetch. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return OriginationUrlFetcher capable of executing the fetch - */ - public static OriginationUrlFetcher fetcher(final String pathTrunkSid, - final String pathSid) { - return new OriginationUrlFetcher(pathTrunkSid, pathSid); - } - - /** - * Create a OriginationUrlDeleter to execute delete. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return OriginationUrlDeleter capable of executing the delete - */ - public static OriginationUrlDeleter deleter(final String pathTrunkSid, - final String pathSid) { + public static OriginationUrlCreator creator( + final String pathTrunkSid, + final Integer weight, + final Integer priority, + final Boolean enabled, + final String friendlyName, + final URI sipUrl + ) { + return new OriginationUrlCreator( + pathTrunkSid, + weight, + priority, + enabled, + friendlyName, + sipUrl + ); + } + + public static OriginationUrlDeleter deleter( + final String pathTrunkSid, + final String pathSid + ) { return new OriginationUrlDeleter(pathTrunkSid, pathSid); } - /** - * Create a OriginationUrlCreator to execute create. - * - * @param pathTrunkSid The trunk_sid - * @param weight Weight is used to determine the share of load when more than - * one URI has the same priority. - * @param priority Priority ranks the importance of the URI. - * @param enabled A boolean value indicating whether the URL is enabled or - * disabled. - * @param friendlyName A human readable descriptive text, up to 64 characters - * long. - * @param sipUrl The SIP address you want Twilio to route your Origination - * calls to. - * @return OriginationUrlCreator capable of executing the create - */ - public static OriginationUrlCreator creator(final String pathTrunkSid, - final Integer weight, - final Integer priority, - final Boolean enabled, - final String friendlyName, - final URI sipUrl) { - return new OriginationUrlCreator(pathTrunkSid, weight, priority, enabled, friendlyName, sipUrl); + public static OriginationUrlFetcher fetcher( + final String pathTrunkSid, + final String pathSid + ) { + return new OriginationUrlFetcher(pathTrunkSid, pathSid); } - /** - * Create a OriginationUrlReader to execute read. - * - * @param pathTrunkSid The trunk_sid - * @return OriginationUrlReader capable of executing the read - */ public static OriginationUrlReader reader(final String pathTrunkSid) { return new OriginationUrlReader(pathTrunkSid); } - /** - * Create a OriginationUrlUpdater to execute update. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return OriginationUrlUpdater capable of executing the update - */ - public static OriginationUrlUpdater updater(final String pathTrunkSid, - final String pathSid) { + public static OriginationUrlUpdater updater( + final String pathTrunkSid, + final String pathSid + ) { return new OriginationUrlUpdater(pathTrunkSid, pathSid); } /** - * Converts a JSON String into a OriginationUrl object using the provided - * ObjectMapper. - * + * Converts a JSON String into a OriginationUrl object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return OriginationUrl object represented by the provided JSON */ - public static OriginationUrl fromJson(final String json, final ObjectMapper objectMapper) { + public static OriginationUrl fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OriginationUrl.class); @@ -128,12 +109,15 @@ public static OriginationUrl fromJson(final String json, final ObjectMapper obje /** * Converts a JSON InputStream into a OriginationUrl object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return OriginationUrl object represented by the provided JSON */ - public static OriginationUrl fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static OriginationUrl fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, OriginationUrl.class); @@ -144,157 +128,86 @@ public static OriginationUrl fromJson(final InputStream json, final ObjectMapper } } - private final String accountSid; - private final String sid; - private final String trunkSid; - private final Integer weight; - private final Boolean enabled; - private final URI sipUrl; - private final String friendlyName; - private final Integer priority; - private final DateTime dateCreated; - private final DateTime dateUpdated; - private final URI url; - - @JsonCreator - private OriginationUrl(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("sid") - final String sid, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("weight") - final Integer weight, - @JsonProperty("enabled") - final Boolean enabled, - @JsonProperty("sip_url") - final URI sipUrl, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("priority") - final Integer priority, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("url") - final URI url) { - this.accountSid = accountSid; - this.sid = sid; - this.trunkSid = trunkSid; - this.weight = weight; - this.enabled = enabled; - this.sipUrl = sipUrl; - this.friendlyName = friendlyName; - this.priority = priority; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); - this.url = url; + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } } - /** - * Returns The The unique ID of the Account that owns this Origination URL.. - * - * @return The unique ID of the Account that owns this Origination URL. - */ - public final String getAccountSid() { - return this.accountSid; - } + @Getter + private final String accountSid; - /** - * Returns The A 34 character string that uniquely identifies the Origination - * URL in this Twilio Trunk.. - * - * @return A 34 character string that uniquely identifies the Origination URL - * in this Twilio Trunk. - */ - public final String getSid() { - return this.sid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; - /** - * Returns The The unique ID of the Trunk that owns this Origination URL.. - * - * @return The unique ID of the Trunk that owns this Origination URL. - */ - public final String getTrunkSid() { - return this.trunkSid; - } + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; - /** - * Returns The Weight is used to determine the share of load when more than one - * URI has the same priority.. - * - * @return Weight is used to determine the share of load when more than one URI - * has the same priority. - */ - public final Integer getWeight() { - return this.weight; - } + @Getter + private final Boolean enabled; - /** - * Returns The A boolean value indicating whether the URL is enabled or - * disabled.. - * - * @return A boolean value indicating whether the URL is enabled or disabled. - */ - public final Boolean getEnabled() { - return this.enabled; - } + @Getter + private final String friendlyName; - /** - * Returns The The SIP address you want Twilio to route your Origination calls - * to.. - * - * @return The SIP address you want Twilio to route your Origination calls to. - */ - public final URI getSipUrl() { - return this.sipUrl; - } + @Getter + private final Integer priority; - /** - * Returns The A human readable descriptive text, up to 64 characters long.. - * - * @return A human readable descriptive text, up to 64 characters long. - */ - public final String getFriendlyName() { - return this.friendlyName; - } + @Getter + private final String sid; - /** - * Returns The Priority ranks the importance of the URI.. - * - * @return Priority ranks the importance of the URI. - */ - public final Integer getPriority() { - return this.priority; - } + @Getter + private final URI sipUrl; - /** - * Returns The The date this Activity was created.. - * - * @return The date this Activity was created. - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } + @Getter + private final String trunkSid; - /** - * Returns The The date this Activity was updated.. - * - * @return The date this Activity was updated. - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } + @Getter + private final URI url; - /** - * Returns The The URL for this resource, relative to https://trunking.. - * - * @return The URL for this resource, relative to https://trunking. - */ - public final URI getUrl() { - return this.url; + @Getter + private final Integer weight; + + @JsonCreator + private OriginationUrl( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("enabled") final Boolean enabled, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("priority") final Integer priority, + @JsonProperty("sid") final String sid, + @JsonProperty("sip_url") final URI sipUrl, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("url") final URI url, + @JsonProperty("weight") final Integer weight + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.enabled = enabled; + this.friendlyName = friendlyName; + this.priority = priority; + this.sid = sid; + this.sipUrl = sipUrl; + this.trunkSid = trunkSid; + this.url = url; + this.weight = weight; } @Override @@ -308,49 +221,35 @@ public boolean equals(final Object o) { } OriginationUrl other = (OriginationUrl) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(sid, other.sid) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(weight, other.weight) && - Objects.equals(enabled, other.enabled) && - Objects.equals(sipUrl, other.sipUrl) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(priority, other.priority) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(url, other.url); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(enabled, other.enabled) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(priority, other.priority) && + Objects.equals(sid, other.sid) && + Objects.equals(sipUrl, other.sipUrl) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(url, other.url) && + Objects.equals(weight, other.weight) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - sid, - trunkSid, - weight, - enabled, - sipUrl, - friendlyName, - priority, - dateCreated, - dateUpdated, - url); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("sid", sid) - .add("trunkSid", trunkSid) - .add("weight", weight) - .add("enabled", enabled) - .add("sipUrl", sipUrl) - .add("friendlyName", friendlyName) - .add("priority", priority) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("url", url) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + enabled, + friendlyName, + priority, + sid, + sipUrl, + trunkSid, + url, + weight + ); + } +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlCreator.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlCreator.java index d8e3c52cf9..52a76794c9 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlCreator.java @@ -1,13 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,37 +28,27 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class OriginationUrlCreator extends Creator { - private final String pathTrunkSid; - private final Integer weight; - private final Integer priority; - private final Boolean enabled; - private final String friendlyName; - private final URI sipUrl; - - /** - * Construct a new OriginationUrlCreator. - * - * @param pathTrunkSid The trunk_sid - * @param weight Weight is used to determine the share of load when more than - * one URI has the same priority. - * @param priority Priority ranks the importance of the URI. - * @param enabled A boolean value indicating whether the URL is enabled or - * disabled. - * @param friendlyName A human readable descriptive text, up to 64 characters - * long. - * @param sipUrl The SIP address you want Twilio to route your Origination - * calls to. - */ - public OriginationUrlCreator(final String pathTrunkSid, - final Integer weight, - final Integer priority, - final Boolean enabled, - final String friendlyName, - final URI sipUrl) { + + private String pathTrunkSid; + private Integer weight; + private Integer priority; + private Boolean enabled; + private String friendlyName; + private URI sipUrl; + + public OriginationUrlCreator( + final String pathTrunkSid, + final Integer weight, + final Integer priority, + final Boolean enabled, + final String friendlyName, + final URI sipUrl + ) { this.pathTrunkSid = pathTrunkSid; this.weight = weight; this.priority = priority; @@ -55,69 +57,141 @@ public OriginationUrlCreator(final String pathTrunkSid, this.sipUrl = sipUrl; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created OriginationUrl - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public OriginationUrl create(final TwilioRestClient client) { + public OriginationUrlCreator setWeight(final Integer weight) { + this.weight = weight; + return this; + } + + public OriginationUrlCreator setPriority(final Integer priority) { + this.priority = priority; + return this; + } + + public OriginationUrlCreator setEnabled(final Boolean enabled) { + this.enabled = enabled; + return this; + } + + public OriginationUrlCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public OriginationUrlCreator setSipUrl(final URI sipUrl) { + this.sipUrl = sipUrl; + return this; + } + + public OriginationUrlCreator setSipUrl(final String sipUrl) { + return setSipUrl(Promoter.uriFromString(sipUrl)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/OriginationUrls"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/OriginationUrls", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "OriginationUrl creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public OriginationUrl create(final TwilioRestClient client) { + Response response = makeRequest(client); + return OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return OriginationUrl.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OriginationUrl content = OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (weight != null) { - request.addPostParam("Weight", weight.toString()); + Serializer.toString( + request, + "Weight", + weight, + ParameterType.URLENCODED + ); } if (priority != null) { - request.addPostParam("Priority", priority.toString()); + Serializer.toString( + request, + "Priority", + priority, + ParameterType.URLENCODED + ); } if (enabled != null) { - request.addPostParam("Enabled", enabled.toString()); + Serializer.toString( + request, + "Enabled", + enabled, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (sipUrl != null) { - request.addPostParam("SipUrl", sipUrl.toString()); + Serializer.toString( + request, + "SipUrl", + sipUrl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlDeleter.java index d701122279..f6b2d43700 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,81 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class OriginationUrlDeleter extends Deleter { - private final String pathTrunkSid; - private final String pathSid; - /** - * Construct a new OriginationUrlDeleter. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public OriginationUrlDeleter(final String pathTrunkSid, - final String pathSid) { + private String pathTrunkSid; + private String pathSid; + + public OriginationUrlDeleter( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/OriginationUrls/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "OriginationUrl delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlFetcher.java index 68e6a67447..86bf185a8e 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,80 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class OriginationUrlFetcher extends Fetcher { - private final String pathTrunkSid; - private final String pathSid; - /** - * Construct a new OriginationUrlFetcher. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public OriginationUrlFetcher(final String pathTrunkSid, - final String pathSid) { + private String pathTrunkSid; + private String pathSid; + + public OriginationUrlFetcher( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched OriginationUrl - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public OriginationUrl fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/OriginationUrls/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "OriginationUrl fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return OriginationUrl.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public OriginationUrl fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OriginationUrl content = OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlReader.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlReader.java index ba810ddcaa..5e47c914a0 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; @@ -10,159 +17,192 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class OriginationUrlReader extends Reader { - private final String pathTrunkSid; - /** - * Construct a new OriginationUrlReader. - * - * @param pathTrunkSid The trunk_sid - */ + private String pathTrunkSid; + private Long pageSize; + public OriginationUrlReader(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return OriginationUrl ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public OriginationUrlReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return OriginationUrl ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "origination_urls", + response.getContent(), + OriginationUrl.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/OriginationUrls"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/OriginationUrls", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return OriginationUrl ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "origination_urls", + response.getContent(), + OriginationUrl.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "OriginationUrl read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "origination_urls", + response.getContent(), + OriginationUrl.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of OriginationUrl Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("OriginationUrl read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "origination_urls", - response.getContent(), - OriginationUrl.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlUpdater.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlUpdater.java index 0a997368da..6e73de849c 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlUpdater.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/OriginationUrlUpdater.java @@ -1,14 +1,25 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; +import com.twilio.base.TwilioResponse; import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -17,169 +28,164 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; - +import com.twilio.type.*; +import java.io.InputStream; import java.net.URI; public class OriginationUrlUpdater extends Updater { - private final String pathTrunkSid; - private final String pathSid; + + private String pathTrunkSid; + private String pathSid; private Integer weight; private Integer priority; private Boolean enabled; private String friendlyName; private URI sipUrl; - /** - * Construct a new OriginationUrlUpdater. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public OriginationUrlUpdater(final String pathTrunkSid, - final String pathSid) { + public OriginationUrlUpdater( + final String pathTrunkSid, + final String pathSid + ) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Weight is used to determine the share of load when more than one URI has the - * same priority. Its values range from 1 to 65535. The higher the value, the - * more load a URI is given. Defaults to 10.. - * - * @param weight Weight is used to determine the share of load when more than - * one URI has the same priority. - * @return this - */ public OriginationUrlUpdater setWeight(final Integer weight) { this.weight = weight; return this; } - /** - * Priority ranks the importance of the URI. Values range from 0 to 65535, where - * the lowest number represents the highest importance. Defaults to 10.. - * - * @param priority Priority ranks the importance of the URI. - * @return this - */ public OriginationUrlUpdater setPriority(final Integer priority) { this.priority = priority; return this; } - /** - * A boolean value indicating whether the URL is enabled or disabled. Defaults - * to true.. - * - * @param enabled A boolean value indicating whether the URL is enabled or - * disabled. - * @return this - */ public OriginationUrlUpdater setEnabled(final Boolean enabled) { this.enabled = enabled; return this; } - /** - * A human readable descriptive text, up to 64 characters long.. - * - * @param friendlyName A human readable descriptive text, up to 64 characters - * long. - * @return this - */ public OriginationUrlUpdater setFriendlyName(final String friendlyName) { this.friendlyName = friendlyName; return this; } - /** - * The SIP address you want Twilio to route your Origination calls to. This must - * be a `sip:` schema. `sips` is NOT supported. - * - * @param sipUrl The SIP address you want Twilio to route your Origination - * calls to. - * @return this - */ public OriginationUrlUpdater setSipUrl(final URI sipUrl) { this.sipUrl = sipUrl; return this; } - /** - * The SIP address you want Twilio to route your Origination calls to. This must - * be a `sip:` schema. `sips` is NOT supported. - * - * @param sipUrl The SIP address you want Twilio to route your Origination - * calls to. - * @return this - */ public OriginationUrlUpdater setSipUrl(final String sipUrl) { return setSipUrl(Promoter.uriFromString(sipUrl)); } - /** - * Make the request to the Twilio API to perform the update. - * - * @param client TwilioRestClient with which to make the request - * @return Updated OriginationUrl - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public OriginationUrl update(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/OriginationUrls/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/OriginationUrls/" + this.pathSid + "", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("OriginationUrl update failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "OriginationUrl update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return OriginationUrl.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public OriginationUrl update(final TwilioRestClient client) { + Response response = makeRequest(client); + return OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + OriginationUrl content = OriginationUrl.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (weight != null) { - request.addPostParam("Weight", weight.toString()); + Serializer.toString( + request, + "Weight", + weight, + ParameterType.URLENCODED + ); } if (priority != null) { - request.addPostParam("Priority", priority.toString()); + Serializer.toString( + request, + "Priority", + priority, + ParameterType.URLENCODED + ); } if (enabled != null) { - request.addPostParam("Enabled", enabled.toString()); + Serializer.toString( + request, + "Enabled", + enabled, + ParameterType.URLENCODED + ); } if (friendlyName != null) { - request.addPostParam("FriendlyName", friendlyName); + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); } if (sipUrl != null) { - request.addPostParam("SipUrl", sipUrl.toString()); + Serializer.toString( + request, + "SipUrl", + sipUrl, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumber.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumber.java index 88a00a8c54..6de5f9fe6a 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumber.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumber.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; @@ -10,32 +17,60 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.MoreObjects; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; import com.twilio.base.Resource; -import com.twilio.converter.DateConverter; import com.twilio.converter.Promoter; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; -import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; -import com.twilio.http.Request; -import com.twilio.http.Response; -import com.twilio.http.TwilioRestClient; -import com.twilio.rest.Domains; -import org.joda.time.DateTime; - +import com.twilio.type.*; +import com.twilio.type.PhoneNumberCapabilities; +import java.io.IOException; import java.io.IOException; import java.io.InputStream; import java.net.URI; +import java.time.ZonedDateTime; import java.util.Map; import java.util.Objects; +import lombok.Getter; +import lombok.ToString; @JsonIgnoreProperties(ignoreUnknown = true) +@ToString public class PhoneNumber extends Resource { - private static final long serialVersionUID = 152136077896645L; + + public static PhoneNumberCreator creator( + final String pathTrunkSid, + final String phoneNumberSid + ) { + return new PhoneNumberCreator(pathTrunkSid, phoneNumberSid); + } + + public static PhoneNumberDeleter deleter( + final String pathTrunkSid, + final String pathSid + ) { + return new PhoneNumberDeleter(pathTrunkSid, pathSid); + } + + public static PhoneNumberFetcher fetcher( + final String pathTrunkSid, + final String pathSid + ) { + return new PhoneNumberFetcher(pathTrunkSid, pathSid); + } + + public static PhoneNumberReader reader(final String pathTrunkSid) { + return new PhoneNumberReader(pathTrunkSid); + } public enum AddressRequirement { NONE("none"), @@ -49,15 +84,11 @@ private AddressRequirement(final String value) { this.value = value; } + @JsonValue public String toString() { return value; } - /** - * Generate a AddressRequirement from a string. - * @param value string value - * @return generated AddressRequirement - */ @JsonCreator public static AddressRequirement forValue(final String value) { return Promoter.enumFromString(value, AddressRequirement.values()); @@ -65,61 +96,16 @@ public static AddressRequirement forValue(final String value) { } /** - * Create a PhoneNumberFetcher to execute fetch. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return PhoneNumberFetcher capable of executing the fetch - */ - public static PhoneNumberFetcher fetcher(final String pathTrunkSid, - final String pathSid) { - return new PhoneNumberFetcher(pathTrunkSid, pathSid); - } - - /** - * Create a PhoneNumberDeleter to execute delete. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - * @return PhoneNumberDeleter capable of executing the delete - */ - public static PhoneNumberDeleter deleter(final String pathTrunkSid, - final String pathSid) { - return new PhoneNumberDeleter(pathTrunkSid, pathSid); - } - - /** - * Create a PhoneNumberCreator to execute create. - * - * @param pathTrunkSid The trunk_sid - * @param phoneNumberSid The SID of the Incoming Phone Number that you want to - * associate with this trunk. - * @return PhoneNumberCreator capable of executing the create - */ - public static PhoneNumberCreator creator(final String pathTrunkSid, - final String phoneNumberSid) { - return new PhoneNumberCreator(pathTrunkSid, phoneNumberSid); - } - - /** - * Create a PhoneNumberReader to execute read. - * - * @param pathTrunkSid The trunk_sid - * @return PhoneNumberReader capable of executing the read - */ - public static PhoneNumberReader reader(final String pathTrunkSid) { - return new PhoneNumberReader(pathTrunkSid); - } - - /** - * Converts a JSON String into a PhoneNumber object using the provided - * ObjectMapper. - * + * Converts a JSON String into a PhoneNumber object using the provided ObjectMapper. + * * @param json Raw JSON String * @param objectMapper Jackson ObjectMapper * @return PhoneNumber object represented by the provided JSON */ - public static PhoneNumber fromJson(final String json, final ObjectMapper objectMapper) { + public static PhoneNumber fromJson( + final String json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -133,12 +119,15 @@ public static PhoneNumber fromJson(final String json, final ObjectMapper objectM /** * Converts a JSON InputStream into a PhoneNumber object using the provided * ObjectMapper. - * + * * @param json Raw JSON InputStream * @param objectMapper Jackson ObjectMapper * @return PhoneNumber object represented by the provided JSON */ - public static PhoneNumber fromJson(final InputStream json, final ObjectMapper objectMapper) { + public static PhoneNumber fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { // Convert all checked exceptions to Runtime try { return objectMapper.readValue(json, PhoneNumber.class); @@ -149,93 +138,154 @@ public static PhoneNumber fromJson(final InputStream json, final ObjectMapper ob } } + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter private final String accountSid; + + @Getter private final PhoneNumber.AddressRequirement addressRequirements; + + @Getter private final String apiVersion; + + @Getter private final Boolean beta; - private final Map capabilities; - private final DateTime dateCreated; - private final DateTime dateUpdated; + + @Getter + private final PhoneNumberCapabilities capabilities; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter private final String friendlyName; + + @Getter private final Map links; + + @Getter private final com.twilio.type.PhoneNumber phoneNumber; + + @Getter private final String sid; + + @Getter private final String smsApplicationSid; + + @Getter private final HttpMethod smsFallbackMethod; + + @Getter private final URI smsFallbackUrl; + + @Getter private final HttpMethod smsMethod; + + @Getter private final URI smsUrl; + + @Getter private final URI statusCallback; + + @Getter private final HttpMethod statusCallbackMethod; + + @Getter private final String trunkSid; + + @Getter private final URI url; + + @Getter private final String voiceApplicationSid; + + @Getter private final Boolean voiceCallerIdLookup; + + @Getter private final HttpMethod voiceFallbackMethod; + + @Getter private final URI voiceFallbackUrl; + + @Getter private final HttpMethod voiceMethod; + + @Getter private final URI voiceUrl; @JsonCreator - private PhoneNumber(@JsonProperty("account_sid") - final String accountSid, - @JsonProperty("address_requirements") - final PhoneNumber.AddressRequirement addressRequirements, - @JsonProperty("api_version") - final String apiVersion, - @JsonProperty("beta") - final Boolean beta, - @JsonProperty("capabilities") - final Map capabilities, - @JsonProperty("date_created") - final String dateCreated, - @JsonProperty("date_updated") - final String dateUpdated, - @JsonProperty("friendly_name") - final String friendlyName, - @JsonProperty("links") - final Map links, - @JsonProperty("phone_number") - final com.twilio.type.PhoneNumber phoneNumber, - @JsonProperty("sid") - final String sid, - @JsonProperty("sms_application_sid") - final String smsApplicationSid, - @JsonProperty("sms_fallback_method") - final HttpMethod smsFallbackMethod, - @JsonProperty("sms_fallback_url") - final URI smsFallbackUrl, - @JsonProperty("sms_method") - final HttpMethod smsMethod, - @JsonProperty("sms_url") - final URI smsUrl, - @JsonProperty("status_callback") - final URI statusCallback, - @JsonProperty("status_callback_method") - final HttpMethod statusCallbackMethod, - @JsonProperty("trunk_sid") - final String trunkSid, - @JsonProperty("url") - final URI url, - @JsonProperty("voice_application_sid") - final String voiceApplicationSid, - @JsonProperty("voice_caller_id_lookup") - final Boolean voiceCallerIdLookup, - @JsonProperty("voice_fallback_method") - final HttpMethod voiceFallbackMethod, - @JsonProperty("voice_fallback_url") - final URI voiceFallbackUrl, - @JsonProperty("voice_method") - final HttpMethod voiceMethod, - @JsonProperty("voice_url") - final URI voiceUrl) { + private PhoneNumber( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty( + "address_requirements" + ) final PhoneNumber.AddressRequirement addressRequirements, + @JsonProperty("api_version") final String apiVersion, + @JsonProperty("beta") final Boolean beta, + @JsonProperty( + "capabilities" + ) final PhoneNumberCapabilities capabilities, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty( + "phone_number" + ) final com.twilio.type.PhoneNumber phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("sms_application_sid") final String smsApplicationSid, + @JsonProperty("sms_fallback_method") final HttpMethod smsFallbackMethod, + @JsonProperty("sms_fallback_url") final URI smsFallbackUrl, + @JsonProperty("sms_method") final HttpMethod smsMethod, + @JsonProperty("sms_url") final URI smsUrl, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty( + "status_callback_method" + ) final HttpMethod statusCallbackMethod, + @JsonProperty("trunk_sid") final String trunkSid, + @JsonProperty("url") final URI url, + @JsonProperty("voice_application_sid") final String voiceApplicationSid, + @JsonProperty( + "voice_caller_id_lookup" + ) final Boolean voiceCallerIdLookup, + @JsonProperty( + "voice_fallback_method" + ) final HttpMethod voiceFallbackMethod, + @JsonProperty("voice_fallback_url") final URI voiceFallbackUrl, + @JsonProperty("voice_method") final HttpMethod voiceMethod, + @JsonProperty("voice_url") final URI voiceUrl + ) { this.accountSid = accountSid; this.addressRequirements = addressRequirements; this.apiVersion = apiVersion; this.beta = beta; this.capabilities = capabilities; - this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated); - this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated); + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; this.friendlyName = friendlyName; this.links = links; this.phoneNumber = phoneNumber; @@ -257,240 +307,6 @@ private PhoneNumber(@JsonProperty("account_sid") this.voiceUrl = voiceUrl; } - /** - * Returns The The account_sid. - * - * @return The account_sid - */ - public final String getAccountSid() { - return this.accountSid; - } - - /** - * Returns The The address_requirements. - * - * @return The address_requirements - */ - public final PhoneNumber.AddressRequirement getAddressRequirements() { - return this.addressRequirements; - } - - /** - * Returns The The api_version. - * - * @return The api_version - */ - public final String getApiVersion() { - return this.apiVersion; - } - - /** - * Returns The The beta. - * - * @return The beta - */ - public final Boolean getBeta() { - return this.beta; - } - - /** - * Returns The The capabilities. - * - * @return The capabilities - */ - public final Map getCapabilities() { - return this.capabilities; - } - - /** - * Returns The The date_created. - * - * @return The date_created - */ - public final DateTime getDateCreated() { - return this.dateCreated; - } - - /** - * Returns The The date_updated. - * - * @return The date_updated - */ - public final DateTime getDateUpdated() { - return this.dateUpdated; - } - - /** - * Returns The The friendly_name. - * - * @return The friendly_name - */ - public final String getFriendlyName() { - return this.friendlyName; - } - - /** - * Returns The The links. - * - * @return The links - */ - public final Map getLinks() { - return this.links; - } - - /** - * Returns The The phone_number. - * - * @return The phone_number - */ - public final com.twilio.type.PhoneNumber getPhoneNumber() { - return this.phoneNumber; - } - - /** - * Returns The The sid. - * - * @return The sid - */ - public final String getSid() { - return this.sid; - } - - /** - * Returns The The sms_application_sid. - * - * @return The sms_application_sid - */ - public final String getSmsApplicationSid() { - return this.smsApplicationSid; - } - - /** - * Returns The The sms_fallback_method. - * - * @return The sms_fallback_method - */ - public final HttpMethod getSmsFallbackMethod() { - return this.smsFallbackMethod; - } - - /** - * Returns The The sms_fallback_url. - * - * @return The sms_fallback_url - */ - public final URI getSmsFallbackUrl() { - return this.smsFallbackUrl; - } - - /** - * Returns The The sms_method. - * - * @return The sms_method - */ - public final HttpMethod getSmsMethod() { - return this.smsMethod; - } - - /** - * Returns The The sms_url. - * - * @return The sms_url - */ - public final URI getSmsUrl() { - return this.smsUrl; - } - - /** - * Returns The The status_callback. - * - * @return The status_callback - */ - public final URI getStatusCallback() { - return this.statusCallback; - } - - /** - * Returns The The status_callback_method. - * - * @return The status_callback_method - */ - public final HttpMethod getStatusCallbackMethod() { - return this.statusCallbackMethod; - } - - /** - * Returns The The trunk_sid. - * - * @return The trunk_sid - */ - public final String getTrunkSid() { - return this.trunkSid; - } - - /** - * Returns The The url. - * - * @return The url - */ - public final URI getUrl() { - return this.url; - } - - /** - * Returns The The voice_application_sid. - * - * @return The voice_application_sid - */ - public final String getVoiceApplicationSid() { - return this.voiceApplicationSid; - } - - /** - * Returns The The voice_caller_id_lookup. - * - * @return The voice_caller_id_lookup - */ - public final Boolean getVoiceCallerIdLookup() { - return this.voiceCallerIdLookup; - } - - /** - * Returns The The voice_fallback_method. - * - * @return The voice_fallback_method - */ - public final HttpMethod getVoiceFallbackMethod() { - return this.voiceFallbackMethod; - } - - /** - * Returns The The voice_fallback_url. - * - * @return The voice_fallback_url - */ - public final URI getVoiceFallbackUrl() { - return this.voiceFallbackUrl; - } - - /** - * Returns The The voice_method. - * - * @return The voice_method - */ - public final HttpMethod getVoiceMethod() { - return this.voiceMethod; - } - - /** - * Returns The The voice_url. - * - * @return The voice_url - */ - public final URI getVoiceUrl() { - return this.voiceUrl; - } - @Override public boolean equals(final Object o) { if (this == o) { @@ -502,94 +318,65 @@ public boolean equals(final Object o) { } PhoneNumber other = (PhoneNumber) o; - - return Objects.equals(accountSid, other.accountSid) && - Objects.equals(addressRequirements, other.addressRequirements) && - Objects.equals(apiVersion, other.apiVersion) && - Objects.equals(beta, other.beta) && - Objects.equals(capabilities, other.capabilities) && - Objects.equals(dateCreated, other.dateCreated) && - Objects.equals(dateUpdated, other.dateUpdated) && - Objects.equals(friendlyName, other.friendlyName) && - Objects.equals(links, other.links) && - Objects.equals(phoneNumber, other.phoneNumber) && - Objects.equals(sid, other.sid) && - Objects.equals(smsApplicationSid, other.smsApplicationSid) && - Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && - Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && - Objects.equals(smsMethod, other.smsMethod) && - Objects.equals(smsUrl, other.smsUrl) && - Objects.equals(statusCallback, other.statusCallback) && - Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && - Objects.equals(trunkSid, other.trunkSid) && - Objects.equals(url, other.url) && - Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && - Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && - Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && - Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && - Objects.equals(voiceMethod, other.voiceMethod) && - Objects.equals(voiceUrl, other.voiceUrl); + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(addressRequirements, other.addressRequirements) && + Objects.equals(apiVersion, other.apiVersion) && + Objects.equals(beta, other.beta) && + Objects.equals(capabilities, other.capabilities) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(smsApplicationSid, other.smsApplicationSid) && + Objects.equals(smsFallbackMethod, other.smsFallbackMethod) && + Objects.equals(smsFallbackUrl, other.smsFallbackUrl) && + Objects.equals(smsMethod, other.smsMethod) && + Objects.equals(smsUrl, other.smsUrl) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(statusCallbackMethod, other.statusCallbackMethod) && + Objects.equals(trunkSid, other.trunkSid) && + Objects.equals(url, other.url) && + Objects.equals(voiceApplicationSid, other.voiceApplicationSid) && + Objects.equals(voiceCallerIdLookup, other.voiceCallerIdLookup) && + Objects.equals(voiceFallbackMethod, other.voiceFallbackMethod) && + Objects.equals(voiceFallbackUrl, other.voiceFallbackUrl) && + Objects.equals(voiceMethod, other.voiceMethod) && + Objects.equals(voiceUrl, other.voiceUrl) + ); } @Override public int hashCode() { - return Objects.hash(accountSid, - addressRequirements, - apiVersion, - beta, - capabilities, - dateCreated, - dateUpdated, - friendlyName, - links, - phoneNumber, - sid, - smsApplicationSid, - smsFallbackMethod, - smsFallbackUrl, - smsMethod, - smsUrl, - statusCallback, - statusCallbackMethod, - trunkSid, - url, - voiceApplicationSid, - voiceCallerIdLookup, - voiceFallbackMethod, - voiceFallbackUrl, - voiceMethod, - voiceUrl); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(this) - .add("accountSid", accountSid) - .add("addressRequirements", addressRequirements) - .add("apiVersion", apiVersion) - .add("beta", beta) - .add("capabilities", capabilities) - .add("dateCreated", dateCreated) - .add("dateUpdated", dateUpdated) - .add("friendlyName", friendlyName) - .add("links", links) - .add("phoneNumber", phoneNumber) - .add("sid", sid) - .add("smsApplicationSid", smsApplicationSid) - .add("smsFallbackMethod", smsFallbackMethod) - .add("smsFallbackUrl", smsFallbackUrl) - .add("smsMethod", smsMethod) - .add("smsUrl", smsUrl) - .add("statusCallback", statusCallback) - .add("statusCallbackMethod", statusCallbackMethod) - .add("trunkSid", trunkSid) - .add("url", url) - .add("voiceApplicationSid", voiceApplicationSid) - .add("voiceCallerIdLookup", voiceCallerIdLookup) - .add("voiceFallbackMethod", voiceFallbackMethod) - .add("voiceFallbackUrl", voiceFallbackUrl) - .add("voiceMethod", voiceMethod) - .add("voiceUrl", voiceUrl) - .toString(); - } -} \ No newline at end of file + return Objects.hash( + accountSid, + addressRequirements, + apiVersion, + beta, + capabilities, + dateCreated, + dateUpdated, + friendlyName, + links, + phoneNumber, + sid, + smsApplicationSid, + smsFallbackMethod, + smsFallbackUrl, + smsMethod, + smsUrl, + statusCallback, + statusCallbackMethod, + trunkSid, + url, + voiceApplicationSid, + voiceCallerIdLookup, + voiceFallbackMethod, + voiceFallbackUrl, + voiceMethod, + voiceUrl + ); + } +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberCreator.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberCreator.java index 4347778169..c7ece0d9b1 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberCreator.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberCreator.java @@ -1,13 +1,24 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,71 +27,97 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PhoneNumberCreator extends Creator { - private final String pathTrunkSid; - private final String phoneNumberSid; - /** - * Construct a new PhoneNumberCreator. - * - * @param pathTrunkSid The trunk_sid - * @param phoneNumberSid The SID of the Incoming Phone Number that you want to - * associate with this trunk. - */ - public PhoneNumberCreator(final String pathTrunkSid, - final String phoneNumberSid) { + private String pathTrunkSid; + private String phoneNumberSid; + + public PhoneNumberCreator( + final String pathTrunkSid, + final String phoneNumberSid + ) { this.pathTrunkSid = pathTrunkSid; this.phoneNumberSid = phoneNumberSid; } - /** - * Make the request to the Twilio API to perform the create. - * - * @param client TwilioRestClient with which to make the request - * @return Created PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber create(final TwilioRestClient client) { + public PhoneNumberCreator setPhoneNumberSid(final String phoneNumberSid) { + this.phoneNumberSid = phoneNumberSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/PhoneNumbers"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + Request request = new Request( HttpMethod.POST, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/PhoneNumbers", - client.getRegion() + path ); - + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); addPostParams(request); + Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber creation failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public PhoneNumber create(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } - /** - * Add the requested post parameters to the Request. - * - * @param request Request to add post params to - */ private void addPostParams(final Request request) { if (phoneNumberSid != null) { - request.addPostParam("PhoneNumberSid", phoneNumberSid); + Serializer.toString( + request, + "PhoneNumberSid", + phoneNumberSid, + ParameterType.URLENCODED + ); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberDeleter.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberDeleter.java index 6f3994851d..82ed5c4da4 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberDeleter.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberDeleter.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,57 +24,78 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; public class PhoneNumberDeleter extends Deleter { - private final String pathTrunkSid; - private final String pathSid; - /** - * Construct a new PhoneNumberDeleter. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public PhoneNumberDeleter(final String pathTrunkSid, - final String pathSid) { + private String pathTrunkSid; + private String pathSid; + + public PhoneNumberDeleter(final String pathTrunkSid, final String pathSid) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the delete. - * - * @param client TwilioRestClient with which to make the request - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public boolean delete(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/PhoneNumbers/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; Request request = new Request( HttpMethod.DELETE, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/PhoneNumbers/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber delete failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } - return response.getStatusCode() == 204; + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberFetcher.java index 215679cc03..6b98e3e3e7 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberFetcher.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberFetcher.java @@ -1,13 +1,21 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; @@ -16,58 +24,77 @@ import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PhoneNumberFetcher extends Fetcher { - private final String pathTrunkSid; - private final String pathSid; - /** - * Construct a new PhoneNumberFetcher. - * - * @param pathTrunkSid The trunk_sid - * @param pathSid The sid - */ - public PhoneNumberFetcher(final String pathTrunkSid, - final String pathSid) { + private String pathTrunkSid; + private String pathSid; + + public PhoneNumberFetcher(final String pathTrunkSid, final String pathSid) { this.pathTrunkSid = pathTrunkSid; this.pathSid = pathSid; } - /** - * Make the request to the Twilio API to perform the fetch. - * - * @param client TwilioRestClient with which to make the request - * @return Fetched PhoneNumber - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public PhoneNumber fetch(final TwilioRestClient client) { + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/PhoneNumbers/{Sid}"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/PhoneNumbers/" + this.pathSid + "", - client.getRegion() + path ); Response response = client.request(request); if (response == null) { - throw new ApiConnectionException("PhoneNumber fetch failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); + throw new ApiConnectionException( + "PhoneNumber fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); if (restException == null) { - throw new ApiException("Server Error, no content"); + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); } - - throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null - ); + throw new ApiException(restException); } + return response; + } - return PhoneNumber.fromJson(response.getStream(), client.getObjectMapper()); + @Override + public PhoneNumber fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + PhoneNumber content = PhoneNumber.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberReader.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberReader.java index 41260337fc..af3f1ebf2c 100644 --- a/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberReader.java +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/PhoneNumberReader.java @@ -1,8 +1,15 @@ -/** +/* * This code was generated by - * \ / _ _ _| _ _ - * | (_)\/(_)(_|\/| |(/_ v1.0.0 - * / / + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. */ package com.twilio.rest.trunking.v1.trunk; @@ -10,159 +17,192 @@ import com.twilio.base.Page; import com.twilio.base.Reader; import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; import com.twilio.exception.ApiConnectionException; import com.twilio.exception.ApiException; import com.twilio.exception.RestException; import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; import com.twilio.http.Request; import com.twilio.http.Response; import com.twilio.http.TwilioRestClient; import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; public class PhoneNumberReader extends Reader { - private final String pathTrunkSid; - /** - * Construct a new PhoneNumberReader. - * - * @param pathTrunkSid The trunk_sid - */ + private String pathTrunkSid; + private Long pageSize; + public PhoneNumberReader(final String pathTrunkSid) { this.pathTrunkSid = pathTrunkSid; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - public ResourceSet read(final TwilioRestClient client) { - return new ResourceSet<>(this, client, firstPage(client)); + public PhoneNumberReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; } - /** - * Make the request to the Twilio API to perform the read. - * - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ - @Override - @SuppressWarnings("checkstyle:linelength") - public Page firstPage(final TwilioRestClient client) { + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/PhoneNumbers"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + Request request = new Request( HttpMethod.GET, Domains.TRUNKING.toString(), - "/v1/Trunks/" + this.pathTrunkSid + "/PhoneNumbers", - client.getRegion() + path ); - addQueryParams(request); - return pageForRequest(client, request); + return request; } - /** - * Retrieve the target page from the Twilio API. - * - * @param targetUrl API-generated URL for the requested results page - * @param client TwilioRestClient with which to make the request - * @return PhoneNumber ResourceSet - */ @Override - @SuppressWarnings("checkstyle:linelength") - public Page getPage(final String targetUrl, final TwilioRestClient client) { - Request request = new Request( - HttpMethod.GET, - targetUrl - ); + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); return pageForRequest(client, request); } - /** - * Retrieve the next page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Next Page - */ + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "PhoneNumber read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "phone_numbers", + response.getContent(), + PhoneNumber.class, + client.getObjectMapper() + ); + } + @Override - public Page nextPage(final Page page, - final TwilioRestClient client) { + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getNextPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getPreviousPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Retrieve the previous page from the Twilio API. - * - * @param page current page - * @param client TwilioRestClient with which to make the request - * @return Previous Page - */ @Override - public Page previousPage(final Page page, - final TwilioRestClient client) { + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { Request request = new Request( HttpMethod.GET, - page.getPreviousPageUrl( - Domains.TRUNKING.toString(), - client.getRegion() - ) + page.getNextPageUrl(Domains.API.toString()) ); return pageForRequest(client, request); } - /** - * Generate a Page of PhoneNumber Resources for a given request. - * - * @param client TwilioRestClient with which to make the request - * @param request Request to generate a page for - * @return Page for the Request - */ - private Page pageForRequest(final TwilioRestClient client, final Request request) { - Response response = client.request(request); - - if (response == null) { - throw new ApiConnectionException("PhoneNumber read failed: Unable to connect to server"); - } else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) { - RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper()); - if (restException == null) { - throw new ApiException("Server Error, no content"); - } - + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { throw new ApiException( - restException.getMessage(), - restException.getCode(), - restException.getMoreInfo(), - restException.getStatus(), - null + "Invalid URL: URL must be a valid Twilio domain" ); } - - return Page.fromJson( - "phone_numbers", - response.getContent(), - PhoneNumber.class, - client.getObjectMapper() - ); + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); } - /** - * Add the requested query string arguments to the Request. - * - * @param request Request to add query string arguments to - */ private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + if (getPageSize() != null) { request.addQueryParam("PageSize", Integer.toString(getPageSize())); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/Recording.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/Recording.java new file mode 100644 index 0000000000..df3fd1638a --- /dev/null +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/Recording.java @@ -0,0 +1,186 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trunking.v1.trunk; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Recording extends Resource { + + public static RecordingFetcher fetcher(final String pathTrunkSid) { + return new RecordingFetcher(pathTrunkSid); + } + + public static RecordingUpdater updater(final String pathTrunkSid) { + return new RecordingUpdater(pathTrunkSid); + } + + public enum RecordingMode { + DO_NOT_RECORD("do-not-record"), + RECORD_FROM_RINGING("record-from-ringing"), + RECORD_FROM_ANSWER("record-from-answer"), + RECORD_FROM_RINGING_DUAL("record-from-ringing-dual"), + RECORD_FROM_ANSWER_DUAL("record-from-answer-dual"); + + private final String value; + + private RecordingMode(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RecordingMode forValue(final String value) { + return Promoter.enumFromString(value, RecordingMode.values()); + } + } + + public enum RecordingTrim { + TRIM_SILENCE("trim-silence"), + DO_NOT_TRIM("do-not-trim"); + + private final String value; + + private RecordingTrim(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static RecordingTrim forValue(final String value) { + return Promoter.enumFromString(value, RecordingTrim.values()); + } + } + + /** + * Converts a JSON String into a Recording object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Recording.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Recording object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Recording object represented by the provided JSON + */ + public static Recording fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Recording.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Recording.RecordingMode mode; + + @Getter + private final Recording.RecordingTrim trim; + + @JsonCreator + private Recording( + @JsonProperty("mode") final Recording.RecordingMode mode, + @JsonProperty("trim") final Recording.RecordingTrim trim + ) { + this.mode = mode; + this.trim = trim; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Recording other = (Recording) o; + return ( + Objects.equals(mode, other.mode) && Objects.equals(trim, other.trim) + ); + } + + @Override + public int hashCode() { + return Objects.hash(mode, trim); + } +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingFetcher.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingFetcher.java new file mode 100644 index 0000000000..6799a898a9 --- /dev/null +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trunking.v1.trunk; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RecordingFetcher extends Fetcher { + + private String pathTrunkSid; + + public RecordingFetcher(final String pathTrunkSid) { + this.pathTrunkSid = pathTrunkSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/Recording"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUNKING.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Recording fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Recording fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recording content = Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingUpdater.java b/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingUpdater.java new file mode 100644 index 0000000000..2a694ff6a8 --- /dev/null +++ b/src/main/java/com/twilio/rest/trunking/v1/trunk/RecordingUpdater.java @@ -0,0 +1,134 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trunking + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trunking.v1.trunk; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class RecordingUpdater extends Updater { + + private String pathTrunkSid; + private Recording.RecordingMode mode; + private Recording.RecordingTrim trim; + + public RecordingUpdater(final String pathTrunkSid) { + this.pathTrunkSid = pathTrunkSid; + } + + public RecordingUpdater setMode(final Recording.RecordingMode mode) { + this.mode = mode; + return this; + } + + public RecordingUpdater setTrim(final Recording.RecordingTrim trim) { + this.trim = trim; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Trunks/{TrunkSid}/Recording"; + + path = + path.replace("{" + "TrunkSid" + "}", this.pathTrunkSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUNKING.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Recording update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Recording update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Recording content = Recording.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (mode != null) { + Serializer.toString( + request, + "Mode", + mode, + ParameterType.URLENCODED + ); + } + + if (trim != null) { + Serializer.toString( + request, + "Trim", + trim, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistration.java b/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistration.java new file mode 100644 index 0000000000..847e7942fe --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistration.java @@ -0,0 +1,812 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class A2PBrandRegistration extends Resource { + + public static A2PBrandRegistrationCreator creator( + final A2PBrandRegistration.TrusthubV1A2pBrandRegistrationRequest trusthubV1A2pBrandRegistrationRequest + ) { + return new A2PBrandRegistrationCreator( + trusthubV1A2pBrandRegistrationRequest + ); + } + + public enum BrandType { + STANDARD("STANDARD"), + SOLE_PROPRIETOR("SOLE_PROPRIETOR"); + + private final String value; + + private BrandType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BrandType forValue(final String value) { + return Promoter.enumFromString(value, BrandType.values()); + } + } + + @JsonDeserialize( + builder = TrusthubV1A2pBrandRegistrationRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TrusthubV1A2pBrandRegistrationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("brandType") + @Getter + private final A2PBrandRegistration.BrandType brandType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("themeSetId") + @Getter + private final String themeSetId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendlyName") + @Getter + private final String friendlyName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("notificationEmail") + @Getter + private final String notificationEmail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessName") + @Getter + private final String businessName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessRegistrationAuthority") + @Getter + private final String businessRegistrationAuthority; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessRegistrationNumber") + @Getter + private final String businessRegistrationNumber; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessIndustry") + @Getter + private final String businessIndustry; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessWebsite") + @Getter + private final URI businessWebsite; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessType") + @Getter + private final String businessType; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStockSymbol") + @Getter + private final String businessStockSymbol; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStockExchange") + @Getter + private final String businessStockExchange; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessTaxExemptStatus") + @Getter + private final String businessTaxExemptStatus; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("brandExternalVettingToken") + @Getter + private final String brandExternalVettingToken; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStreetAddress") + @Getter + private final String businessStreetAddress; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStreetAddress2") + @Getter + private final String businessStreetAddress2; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessCity") + @Getter + private final String businessCity; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStateProvinceRegion") + @Getter + private final String businessStateProvinceRegion; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessPostalCode") + @Getter + private final String businessPostalCode; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessCountry") + @Getter + private final String businessCountry; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessContactFirstName") + @Getter + private final String businessContactFirstName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessContactLastName") + @Getter + private final String businessContactLastName; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessContactEmail") + @Getter + private final String businessContactEmail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessContactPhone") + @Getter + private final com.twilio.type.PhoneNumber businessContactPhone; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("authorizedContactVerificationEmail") + @Getter + private final String authorizedContactVerificationEmail; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("authorizedContactMobilePhoneNumberE164") + @Getter + private final com.twilio.type.PhoneNumber authorizedContactMobilePhoneNumberE164; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isTest") + @Getter + private final Boolean isTest; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("skipAutomaticSecVet") + @Getter + private final Boolean skipAutomaticSecVet; + + private TrusthubV1A2pBrandRegistrationRequest(Builder builder) { + this.brandType = builder.brandType; + this.themeSetId = builder.themeSetId; + this.friendlyName = builder.friendlyName; + this.notificationEmail = builder.notificationEmail; + this.businessName = builder.businessName; + this.businessRegistrationAuthority = + builder.businessRegistrationAuthority; + this.businessRegistrationNumber = + builder.businessRegistrationNumber; + this.businessIndustry = builder.businessIndustry; + this.businessWebsite = builder.businessWebsite; + this.businessType = builder.businessType; + this.businessStockSymbol = builder.businessStockSymbol; + this.businessStockExchange = builder.businessStockExchange; + this.businessTaxExemptStatus = builder.businessTaxExemptStatus; + this.brandExternalVettingToken = builder.brandExternalVettingToken; + this.businessStreetAddress = builder.businessStreetAddress; + this.businessStreetAddress2 = builder.businessStreetAddress2; + this.businessCity = builder.businessCity; + this.businessStateProvinceRegion = + builder.businessStateProvinceRegion; + this.businessPostalCode = builder.businessPostalCode; + this.businessCountry = builder.businessCountry; + this.businessContactFirstName = builder.businessContactFirstName; + this.businessContactLastName = builder.businessContactLastName; + this.businessContactEmail = builder.businessContactEmail; + this.businessContactPhone = builder.businessContactPhone; + this.authorizedContactVerificationEmail = + builder.authorizedContactVerificationEmail; + this.authorizedContactMobilePhoneNumberE164 = + builder.authorizedContactMobilePhoneNumberE164; + this.isTest = builder.isTest; + this.skipAutomaticSecVet = builder.skipAutomaticSecVet; + } + + public static Builder builder( + final A2PBrandRegistration.BrandType brandType, + final String notificationEmail + ) { + return new Builder(brandType, notificationEmail); + } + + public static TrusthubV1A2pBrandRegistrationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + TrusthubV1A2pBrandRegistrationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("brandType") + private A2PBrandRegistration.BrandType brandType; + + @JsonProperty("themeSetId") + private String themeSetId; + + @JsonProperty("friendlyName") + private String friendlyName; + + @JsonProperty("notificationEmail") + private String notificationEmail; + + @JsonProperty("businessName") + private String businessName; + + @JsonProperty("businessRegistrationAuthority") + private String businessRegistrationAuthority; + + @JsonProperty("businessRegistrationNumber") + private String businessRegistrationNumber; + + @JsonProperty("businessIndustry") + private String businessIndustry; + + @JsonProperty("businessWebsite") + private URI businessWebsite; + + @JsonProperty("businessType") + private String businessType; + + @JsonProperty("businessStockSymbol") + private String businessStockSymbol; + + @JsonProperty("businessStockExchange") + private String businessStockExchange; + + @JsonProperty("businessTaxExemptStatus") + private String businessTaxExemptStatus; + + @JsonProperty("brandExternalVettingToken") + private String brandExternalVettingToken; + + @JsonProperty("businessStreetAddress") + private String businessStreetAddress; + + @JsonProperty("businessStreetAddress2") + private String businessStreetAddress2; + + @JsonProperty("businessCity") + private String businessCity; + + @JsonProperty("businessStateProvinceRegion") + private String businessStateProvinceRegion; + + @JsonProperty("businessPostalCode") + private String businessPostalCode; + + @JsonProperty("businessCountry") + private String businessCountry; + + @JsonProperty("businessContactFirstName") + private String businessContactFirstName; + + @JsonProperty("businessContactLastName") + private String businessContactLastName; + + @JsonProperty("businessContactEmail") + private String businessContactEmail; + + @JsonProperty("businessContactPhone") + private com.twilio.type.PhoneNumber businessContactPhone; + + @JsonProperty("authorizedContactVerificationEmail") + private String authorizedContactVerificationEmail; + + @JsonProperty("authorizedContactMobilePhoneNumberE164") + private com.twilio.type.PhoneNumber authorizedContactMobilePhoneNumberE164; + + @JsonProperty("isTest") + private Boolean isTest; + + @JsonProperty("skipAutomaticSecVet") + private Boolean skipAutomaticSecVet; + + @JsonCreator + public Builder( + @JsonProperty( + "brandType" + ) final A2PBrandRegistration.BrandType brandType, + @JsonProperty( + "notificationEmail" + ) final String notificationEmail + ) { + this.brandType = brandType; + this.notificationEmail = notificationEmail; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("themeSetId") + public Builder themeSetId(String themeSetId) { + this.themeSetId = themeSetId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("friendlyName") + public Builder friendlyName(String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessName") + public Builder businessName(String businessName) { + this.businessName = businessName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessRegistrationAuthority") + public Builder businessRegistrationAuthority( + String businessRegistrationAuthority + ) { + this.businessRegistrationAuthority = + businessRegistrationAuthority; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessRegistrationNumber") + public Builder businessRegistrationNumber( + String businessRegistrationNumber + ) { + this.businessRegistrationNumber = businessRegistrationNumber; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessIndustry") + public Builder businessIndustry(String businessIndustry) { + this.businessIndustry = businessIndustry; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessWebsite") + public Builder businessWebsite(URI businessWebsite) { + this.businessWebsite = businessWebsite; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessType") + public Builder businessType(String businessType) { + this.businessType = businessType; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStockSymbol") + public Builder businessStockSymbol(String businessStockSymbol) { + this.businessStockSymbol = businessStockSymbol; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStockExchange") + public Builder businessStockExchange(String businessStockExchange) { + this.businessStockExchange = businessStockExchange; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessTaxExemptStatus") + public Builder businessTaxExemptStatus( + String businessTaxExemptStatus + ) { + this.businessTaxExemptStatus = businessTaxExemptStatus; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("brandExternalVettingToken") + public Builder brandExternalVettingToken( + String brandExternalVettingToken + ) { + this.brandExternalVettingToken = brandExternalVettingToken; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStreetAddress") + public Builder businessStreetAddress(String businessStreetAddress) { + this.businessStreetAddress = businessStreetAddress; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStreetAddress2") + public Builder businessStreetAddress2( + String businessStreetAddress2 + ) { + this.businessStreetAddress2 = businessStreetAddress2; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessCity") + public Builder businessCity(String businessCity) { + this.businessCity = businessCity; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessStateProvinceRegion") + public Builder businessStateProvinceRegion( + String businessStateProvinceRegion + ) { + this.businessStateProvinceRegion = businessStateProvinceRegion; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessPostalCode") + public Builder businessPostalCode(String businessPostalCode) { + this.businessPostalCode = businessPostalCode; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessCountry") + public Builder businessCountry(String businessCountry) { + this.businessCountry = businessCountry; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessContactFirstName") + public Builder businessContactFirstName( + String businessContactFirstName + ) { + this.businessContactFirstName = businessContactFirstName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessContactLastName") + public Builder businessContactLastName( + String businessContactLastName + ) { + this.businessContactLastName = businessContactLastName; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessContactEmail") + public Builder businessContactEmail(String businessContactEmail) { + this.businessContactEmail = businessContactEmail; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("businessContactPhone") + public Builder businessContactPhone( + com.twilio.type.PhoneNumber businessContactPhone + ) { + this.businessContactPhone = businessContactPhone; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("authorizedContactVerificationEmail") + public Builder authorizedContactVerificationEmail( + String authorizedContactVerificationEmail + ) { + this.authorizedContactVerificationEmail = + authorizedContactVerificationEmail; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("authorizedContactMobilePhoneNumberE164") + public Builder authorizedContactMobilePhoneNumberE164( + com.twilio.type.PhoneNumber authorizedContactMobilePhoneNumberE164 + ) { + this.authorizedContactMobilePhoneNumberE164 = + authorizedContactMobilePhoneNumberE164; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("isTest") + public Builder isTest(Boolean isTest) { + this.isTest = isTest; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("skipAutomaticSecVet") + public Builder skipAutomaticSecVet(Boolean skipAutomaticSecVet) { + this.skipAutomaticSecVet = skipAutomaticSecVet; + return this; + } + + public TrusthubV1A2pBrandRegistrationRequest build() { + return new TrusthubV1A2pBrandRegistrationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TrusthubV1A2pBrandRegistrationRequest other = + (TrusthubV1A2pBrandRegistrationRequest) o; + return ( + Objects.equals(brandType, other.brandType) && + Objects.equals(themeSetId, other.themeSetId) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(notificationEmail, other.notificationEmail) && + Objects.equals(businessName, other.businessName) && + Objects.equals( + businessRegistrationAuthority, + other.businessRegistrationAuthority + ) && + Objects.equals( + businessRegistrationNumber, + other.businessRegistrationNumber + ) && + Objects.equals(businessIndustry, other.businessIndustry) && + Objects.equals(businessWebsite, other.businessWebsite) && + Objects.equals(businessType, other.businessType) && + Objects.equals( + businessStockSymbol, + other.businessStockSymbol + ) && + Objects.equals( + businessStockExchange, + other.businessStockExchange + ) && + Objects.equals( + businessTaxExemptStatus, + other.businessTaxExemptStatus + ) && + Objects.equals( + brandExternalVettingToken, + other.brandExternalVettingToken + ) && + Objects.equals( + businessStreetAddress, + other.businessStreetAddress + ) && + Objects.equals( + businessStreetAddress2, + other.businessStreetAddress2 + ) && + Objects.equals(businessCity, other.businessCity) && + Objects.equals( + businessStateProvinceRegion, + other.businessStateProvinceRegion + ) && + Objects.equals(businessPostalCode, other.businessPostalCode) && + Objects.equals(businessCountry, other.businessCountry) && + Objects.equals( + businessContactFirstName, + other.businessContactFirstName + ) && + Objects.equals( + businessContactLastName, + other.businessContactLastName + ) && + Objects.equals( + businessContactEmail, + other.businessContactEmail + ) && + Objects.equals( + businessContactPhone, + other.businessContactPhone + ) && + Objects.equals( + authorizedContactVerificationEmail, + other.authorizedContactVerificationEmail + ) && + Objects.equals( + authorizedContactMobilePhoneNumberE164, + other.authorizedContactMobilePhoneNumberE164 + ) && + Objects.equals(isTest, other.isTest) && + Objects.equals(skipAutomaticSecVet, other.skipAutomaticSecVet) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + brandType, + themeSetId, + friendlyName, + notificationEmail, + businessName, + businessRegistrationAuthority, + businessRegistrationNumber, + businessIndustry, + businessWebsite, + businessType, + businessStockSymbol, + businessStockExchange, + businessTaxExemptStatus, + brandExternalVettingToken, + businessStreetAddress, + businessStreetAddress2, + businessCity, + businessStateProvinceRegion, + businessPostalCode, + businessCountry, + businessContactFirstName, + businessContactLastName, + businessContactEmail, + businessContactPhone, + authorizedContactVerificationEmail, + authorizedContactMobilePhoneNumberE164, + isTest, + skipAutomaticSecVet + ); + } + } + + /** + * Converts a JSON String into a A2PBrandRegistration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return A2PBrandRegistration object represented by the provided JSON + */ + public static A2PBrandRegistration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, A2PBrandRegistration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a A2PBrandRegistration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return A2PBrandRegistration object represented by the provided JSON + */ + public static A2PBrandRegistration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, A2PBrandRegistration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String id; + + @Getter + private final String sessionId; + + @Getter + private final String sessionToken; + + @JsonCreator + private A2PBrandRegistration( + @JsonProperty("id") final String id, + @JsonProperty("sessionId") final String sessionId, + @JsonProperty("sessionToken") final String sessionToken + ) { + this.id = id; + this.sessionId = sessionId; + this.sessionToken = sessionToken; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + A2PBrandRegistration other = (A2PBrandRegistration) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(sessionToken, other.sessionToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, sessionId, sessionToken); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationCreator.java new file mode 100644 index 0000000000..dcc54c6c84 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationCreator.java @@ -0,0 +1,121 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class A2PBrandRegistrationCreator extends Creator { + + private A2PBrandRegistration.TrusthubV1A2pBrandRegistrationRequest trusthubV1A2pBrandRegistrationRequest; + + public A2PBrandRegistrationCreator( + final A2PBrandRegistration.TrusthubV1A2pBrandRegistrationRequest trusthubV1A2pBrandRegistrationRequest + ) { + this.trusthubV1A2pBrandRegistrationRequest = + trusthubV1A2pBrandRegistrationRequest; + } + + public A2PBrandRegistrationCreator setTrusthubV1A2pBrandRegistrationRequest( + final A2PBrandRegistration.TrusthubV1A2pBrandRegistrationRequest trusthubV1A2pBrandRegistrationRequest + ) { + this.trusthubV1A2pBrandRegistrationRequest = + trusthubV1A2pBrandRegistrationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/A2PBrandRegistrations"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "A2PBrandRegistration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public A2PBrandRegistration create(final TwilioRestClient client) { + Response response = makeRequest(client); + return A2PBrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + A2PBrandRegistration content = A2PBrandRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (trusthubV1A2pBrandRegistrationRequest != null) { + request.setBody( + A2PBrandRegistration.toJson( + trusthubV1A2pBrandRegistrationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationEmbeddedSession.java b/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationEmbeddedSession.java new file mode 100644 index 0000000000..ac23a2d1ab --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationEmbeddedSession.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class A2PBrandRegistrationEmbeddedSession extends Resource { + + public static A2PBrandRegistrationEmbeddedSessionCreator creator( + final String pathId + ) { + return new A2PBrandRegistrationEmbeddedSessionCreator(pathId); + } + + /** + * Converts a JSON String into a A2PBrandRegistrationEmbeddedSession object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return A2PBrandRegistrationEmbeddedSession object represented by the provided JSON + */ + public static A2PBrandRegistrationEmbeddedSession fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + A2PBrandRegistrationEmbeddedSession.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a A2PBrandRegistrationEmbeddedSession object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return A2PBrandRegistrationEmbeddedSession object represented by the provided JSON + */ + public static A2PBrandRegistrationEmbeddedSession fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + A2PBrandRegistrationEmbeddedSession.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String id; + + @Getter + private final String sessionId; + + @Getter + private final String sessionToken; + + @JsonCreator + private A2PBrandRegistrationEmbeddedSession( + @JsonProperty("id") final String id, + @JsonProperty("sessionId") final String sessionId, + @JsonProperty("sessionToken") final String sessionToken + ) { + this.id = id; + this.sessionId = sessionId; + this.sessionToken = sessionToken; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + A2PBrandRegistrationEmbeddedSession other = + (A2PBrandRegistrationEmbeddedSession) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(sessionToken, other.sessionToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, sessionId, sessionToken); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationEmbeddedSessionCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationEmbeddedSessionCreator.java new file mode 100644 index 0000000000..a0d4f1cc6e --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/A2PBrandRegistrationEmbeddedSessionCreator.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class A2PBrandRegistrationEmbeddedSessionCreator + extends Creator { + + private String pathId; + + public A2PBrandRegistrationEmbeddedSessionCreator(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/A2PBrandRegistrations/{Id}/EmbeddedSessions"; + + path = path.replace("{" + "Id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "A2PBrandRegistrationEmbeddedSession creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public A2PBrandRegistrationEmbeddedSession create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return A2PBrandRegistrationEmbeddedSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + A2PBrandRegistrationEmbeddedSession + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + A2PBrandRegistrationEmbeddedSession content = + A2PBrandRegistrationEmbeddedSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistration.java b/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistration.java new file mode 100644 index 0000000000..0ceccf8a32 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistration.java @@ -0,0 +1,693 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class A2PCampaignRegistration extends Resource { + + public static A2PCampaignRegistrationCreator creator( + final A2PCampaignRegistration.TrusthubV1A2pCampaignRegistrationRequest trusthubV1A2pCampaignRegistrationRequest + ) { + return new A2PCampaignRegistrationCreator( + trusthubV1A2pCampaignRegistrationRequest + ); + } + + @JsonDeserialize( + builder = TrusthubV1A2pCampaignRegistrationRequest.Builder.class + ) + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @ToString + public static class TrusthubV1A2pCampaignRegistrationRequest { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("a2pBrandRegistrationSid") + @Getter + private final String a2pBrandRegistrationSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("messagingServiceSid") + @Getter + private final String messagingServiceSid; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("themeSetId") + @Getter + private final String themeSetId; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseCategories") + @Getter + private final List useCaseCategories; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseDescription") + @Getter + private final String useCaseDescription; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage1") + @Getter + private final String useCaseSampleMessage1; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage2") + @Getter + private final String useCaseSampleMessage2; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage3") + @Getter + private final String useCaseSampleMessage3; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage4") + @Getter + private final String useCaseSampleMessage4; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage5") + @Getter + private final String useCaseSampleMessage5; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseOptInTypes") + @Getter + private final List useCaseOptInTypes; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseOptInDescription") + @Getter + private final String useCaseOptInDescription; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("hasEmbeddedLinks") + @Getter + private final Boolean hasEmbeddedLinks; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("hasEmbeddedPhone") + @Getter + private final Boolean hasEmbeddedPhone; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("embeddedUrlSample") + @Getter + private final URI embeddedUrlSample; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("directLending") + @Getter + private final Boolean directLending; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ageGated") + @Getter + private final Boolean ageGated; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("privacyPolicyUrl") + @Getter + private final URI privacyPolicyUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("termsAndConditionsUrl") + @Getter + private final URI termsAndConditionsUrl; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("optInKeywords") + @Getter + private final List optInKeywords; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("optInMessageSample") + @Getter + private final String optInMessageSample; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("optOutKeywords") + @Getter + private final List optOutKeywords; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("optOutMessageSample") + @Getter + private final String optOutMessageSample; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("helpKeywords") + @Getter + private final List helpKeywords; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("helpMessageSample") + @Getter + private final String helpMessageSample; + + private TrusthubV1A2pCampaignRegistrationRequest(Builder builder) { + this.a2pBrandRegistrationSid = builder.a2pBrandRegistrationSid; + this.messagingServiceSid = builder.messagingServiceSid; + this.themeSetId = builder.themeSetId; + this.useCaseCategories = builder.useCaseCategories; + this.useCaseDescription = builder.useCaseDescription; + this.useCaseSampleMessage1 = builder.useCaseSampleMessage1; + this.useCaseSampleMessage2 = builder.useCaseSampleMessage2; + this.useCaseSampleMessage3 = builder.useCaseSampleMessage3; + this.useCaseSampleMessage4 = builder.useCaseSampleMessage4; + this.useCaseSampleMessage5 = builder.useCaseSampleMessage5; + this.useCaseOptInTypes = builder.useCaseOptInTypes; + this.useCaseOptInDescription = builder.useCaseOptInDescription; + this.hasEmbeddedLinks = builder.hasEmbeddedLinks; + this.hasEmbeddedPhone = builder.hasEmbeddedPhone; + this.embeddedUrlSample = builder.embeddedUrlSample; + this.directLending = builder.directLending; + this.ageGated = builder.ageGated; + this.privacyPolicyUrl = builder.privacyPolicyUrl; + this.termsAndConditionsUrl = builder.termsAndConditionsUrl; + this.optInKeywords = builder.optInKeywords; + this.optInMessageSample = builder.optInMessageSample; + this.optOutKeywords = builder.optOutKeywords; + this.optOutMessageSample = builder.optOutMessageSample; + this.helpKeywords = builder.helpKeywords; + this.helpMessageSample = builder.helpMessageSample; + } + + public static Builder builder(final String a2pBrandRegistrationSid) { + return new Builder(a2pBrandRegistrationSid); + } + + public static TrusthubV1A2pCampaignRegistrationRequest fromJson( + String jsonString, + ObjectMapper mapper + ) throws IOException { + return mapper.readValue( + jsonString, + TrusthubV1A2pCampaignRegistrationRequest.class + ); + } + + @JsonIgnoreProperties(ignoreUnknown = true) + @JsonPOJOBuilder(withPrefix = "") + public static class Builder { + + @JsonProperty("a2pBrandRegistrationSid") + private String a2pBrandRegistrationSid; + + @JsonProperty("messagingServiceSid") + private String messagingServiceSid; + + @JsonProperty("themeSetId") + private String themeSetId; + + @JsonProperty("useCaseCategories") + private List useCaseCategories; + + @JsonProperty("useCaseDescription") + private String useCaseDescription; + + @JsonProperty("useCaseSampleMessage1") + private String useCaseSampleMessage1; + + @JsonProperty("useCaseSampleMessage2") + private String useCaseSampleMessage2; + + @JsonProperty("useCaseSampleMessage3") + private String useCaseSampleMessage3; + + @JsonProperty("useCaseSampleMessage4") + private String useCaseSampleMessage4; + + @JsonProperty("useCaseSampleMessage5") + private String useCaseSampleMessage5; + + @JsonProperty("useCaseOptInTypes") + private List useCaseOptInTypes; + + @JsonProperty("useCaseOptInDescription") + private String useCaseOptInDescription; + + @JsonProperty("hasEmbeddedLinks") + private Boolean hasEmbeddedLinks; + + @JsonProperty("hasEmbeddedPhone") + private Boolean hasEmbeddedPhone; + + @JsonProperty("embeddedUrlSample") + private URI embeddedUrlSample; + + @JsonProperty("directLending") + private Boolean directLending; + + @JsonProperty("ageGated") + private Boolean ageGated; + + @JsonProperty("privacyPolicyUrl") + private URI privacyPolicyUrl; + + @JsonProperty("termsAndConditionsUrl") + private URI termsAndConditionsUrl; + + @JsonProperty("optInKeywords") + private List optInKeywords; + + @JsonProperty("optInMessageSample") + private String optInMessageSample; + + @JsonProperty("optOutKeywords") + private List optOutKeywords; + + @JsonProperty("optOutMessageSample") + private String optOutMessageSample; + + @JsonProperty("helpKeywords") + private List helpKeywords; + + @JsonProperty("helpMessageSample") + private String helpMessageSample; + + @JsonCreator + public Builder( + @JsonProperty( + "a2pBrandRegistrationSid" + ) final String a2pBrandRegistrationSid + ) { + this.a2pBrandRegistrationSid = a2pBrandRegistrationSid; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("messagingServiceSid") + public Builder messagingServiceSid(String messagingServiceSid) { + this.messagingServiceSid = messagingServiceSid; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("themeSetId") + public Builder themeSetId(String themeSetId) { + this.themeSetId = themeSetId; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseCategories") + public Builder useCaseCategories(List useCaseCategories) { + this.useCaseCategories = useCaseCategories; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseDescription") + public Builder useCaseDescription(String useCaseDescription) { + this.useCaseDescription = useCaseDescription; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage1") + public Builder useCaseSampleMessage1(String useCaseSampleMessage1) { + this.useCaseSampleMessage1 = useCaseSampleMessage1; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage2") + public Builder useCaseSampleMessage2(String useCaseSampleMessage2) { + this.useCaseSampleMessage2 = useCaseSampleMessage2; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage3") + public Builder useCaseSampleMessage3(String useCaseSampleMessage3) { + this.useCaseSampleMessage3 = useCaseSampleMessage3; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage4") + public Builder useCaseSampleMessage4(String useCaseSampleMessage4) { + this.useCaseSampleMessage4 = useCaseSampleMessage4; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseSampleMessage5") + public Builder useCaseSampleMessage5(String useCaseSampleMessage5) { + this.useCaseSampleMessage5 = useCaseSampleMessage5; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseOptInTypes") + public Builder useCaseOptInTypes(List useCaseOptInTypes) { + this.useCaseOptInTypes = useCaseOptInTypes; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("useCaseOptInDescription") + public Builder useCaseOptInDescription( + String useCaseOptInDescription + ) { + this.useCaseOptInDescription = useCaseOptInDescription; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("hasEmbeddedLinks") + public Builder hasEmbeddedLinks(Boolean hasEmbeddedLinks) { + this.hasEmbeddedLinks = hasEmbeddedLinks; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("hasEmbeddedPhone") + public Builder hasEmbeddedPhone(Boolean hasEmbeddedPhone) { + this.hasEmbeddedPhone = hasEmbeddedPhone; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("embeddedUrlSample") + public Builder embeddedUrlSample(URI embeddedUrlSample) { + this.embeddedUrlSample = embeddedUrlSample; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("directLending") + public Builder directLending(Boolean directLending) { + this.directLending = directLending; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("ageGated") + public Builder ageGated(Boolean ageGated) { + this.ageGated = ageGated; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("privacyPolicyUrl") + public Builder privacyPolicyUrl(URI privacyPolicyUrl) { + this.privacyPolicyUrl = privacyPolicyUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("termsAndConditionsUrl") + public Builder termsAndConditionsUrl(URI termsAndConditionsUrl) { + this.termsAndConditionsUrl = termsAndConditionsUrl; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("optInKeywords") + public Builder optInKeywords(List optInKeywords) { + this.optInKeywords = optInKeywords; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("optInMessageSample") + public Builder optInMessageSample(String optInMessageSample) { + this.optInMessageSample = optInMessageSample; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("optOutKeywords") + public Builder optOutKeywords(List optOutKeywords) { + this.optOutKeywords = optOutKeywords; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("optOutMessageSample") + public Builder optOutMessageSample(String optOutMessageSample) { + this.optOutMessageSample = optOutMessageSample; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("helpKeywords") + public Builder helpKeywords(List helpKeywords) { + this.helpKeywords = helpKeywords; + return this; + } + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + @JsonProperty("helpMessageSample") + public Builder helpMessageSample(String helpMessageSample) { + this.helpMessageSample = helpMessageSample; + return this; + } + + public TrusthubV1A2pCampaignRegistrationRequest build() { + return new TrusthubV1A2pCampaignRegistrationRequest(this); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TrusthubV1A2pCampaignRegistrationRequest other = + (TrusthubV1A2pCampaignRegistrationRequest) o; + return ( + Objects.equals( + a2pBrandRegistrationSid, + other.a2pBrandRegistrationSid + ) && + Objects.equals( + messagingServiceSid, + other.messagingServiceSid + ) && + Objects.equals(themeSetId, other.themeSetId) && + Objects.equals(useCaseCategories, other.useCaseCategories) && + Objects.equals(useCaseDescription, other.useCaseDescription) && + Objects.equals( + useCaseSampleMessage1, + other.useCaseSampleMessage1 + ) && + Objects.equals( + useCaseSampleMessage2, + other.useCaseSampleMessage2 + ) && + Objects.equals( + useCaseSampleMessage3, + other.useCaseSampleMessage3 + ) && + Objects.equals( + useCaseSampleMessage4, + other.useCaseSampleMessage4 + ) && + Objects.equals( + useCaseSampleMessage5, + other.useCaseSampleMessage5 + ) && + Objects.equals(useCaseOptInTypes, other.useCaseOptInTypes) && + Objects.equals( + useCaseOptInDescription, + other.useCaseOptInDescription + ) && + Objects.equals(hasEmbeddedLinks, other.hasEmbeddedLinks) && + Objects.equals(hasEmbeddedPhone, other.hasEmbeddedPhone) && + Objects.equals(embeddedUrlSample, other.embeddedUrlSample) && + Objects.equals(directLending, other.directLending) && + Objects.equals(ageGated, other.ageGated) && + Objects.equals(privacyPolicyUrl, other.privacyPolicyUrl) && + Objects.equals( + termsAndConditionsUrl, + other.termsAndConditionsUrl + ) && + Objects.equals(optInKeywords, other.optInKeywords) && + Objects.equals(optInMessageSample, other.optInMessageSample) && + Objects.equals(optOutKeywords, other.optOutKeywords) && + Objects.equals( + optOutMessageSample, + other.optOutMessageSample + ) && + Objects.equals(helpKeywords, other.helpKeywords) && + Objects.equals(helpMessageSample, other.helpMessageSample) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + a2pBrandRegistrationSid, + messagingServiceSid, + themeSetId, + useCaseCategories, + useCaseDescription, + useCaseSampleMessage1, + useCaseSampleMessage2, + useCaseSampleMessage3, + useCaseSampleMessage4, + useCaseSampleMessage5, + useCaseOptInTypes, + useCaseOptInDescription, + hasEmbeddedLinks, + hasEmbeddedPhone, + embeddedUrlSample, + directLending, + ageGated, + privacyPolicyUrl, + termsAndConditionsUrl, + optInKeywords, + optInMessageSample, + optOutKeywords, + optOutMessageSample, + helpKeywords, + helpMessageSample + ); + } + } + + /** + * Converts a JSON String into a A2PCampaignRegistration object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return A2PCampaignRegistration object represented by the provided JSON + */ + public static A2PCampaignRegistration fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, A2PCampaignRegistration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a A2PCampaignRegistration object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return A2PCampaignRegistration object represented by the provided JSON + */ + public static A2PCampaignRegistration fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, A2PCampaignRegistration.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String id; + + @Getter + private final String sessionId; + + @Getter + private final String sessionToken; + + @JsonCreator + private A2PCampaignRegistration( + @JsonProperty("id") final String id, + @JsonProperty("sessionId") final String sessionId, + @JsonProperty("sessionToken") final String sessionToken + ) { + this.id = id; + this.sessionId = sessionId; + this.sessionToken = sessionToken; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + A2PCampaignRegistration other = (A2PCampaignRegistration) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(sessionToken, other.sessionToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, sessionId, sessionToken); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationCreator.java new file mode 100644 index 0000000000..e7bdc0091c --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationCreator.java @@ -0,0 +1,122 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class A2PCampaignRegistrationCreator + extends Creator { + + private A2PCampaignRegistration.TrusthubV1A2pCampaignRegistrationRequest trusthubV1A2pCampaignRegistrationRequest; + + public A2PCampaignRegistrationCreator( + final A2PCampaignRegistration.TrusthubV1A2pCampaignRegistrationRequest trusthubV1A2pCampaignRegistrationRequest + ) { + this.trusthubV1A2pCampaignRegistrationRequest = + trusthubV1A2pCampaignRegistrationRequest; + } + + public A2PCampaignRegistrationCreator setTrusthubV1A2pCampaignRegistrationRequest( + final A2PCampaignRegistration.TrusthubV1A2pCampaignRegistrationRequest trusthubV1A2pCampaignRegistrationRequest + ) { + this.trusthubV1A2pCampaignRegistrationRequest = + trusthubV1A2pCampaignRegistrationRequest; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/A2PCampaignRegistrations"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.JSON); + addPostParams(request, client); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "A2PCampaignRegistration creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public A2PCampaignRegistration create(final TwilioRestClient client) { + Response response = makeRequest(client); + return A2PCampaignRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + A2PCampaignRegistration content = A2PCampaignRegistration.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request, TwilioRestClient client) { + ObjectMapper objectMapper = client.getObjectMapper(); + if (trusthubV1A2pCampaignRegistrationRequest != null) { + request.setBody( + A2PCampaignRegistration.toJson( + trusthubV1A2pCampaignRegistrationRequest, + objectMapper + ) + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationEmbeddedSession.java b/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationEmbeddedSession.java new file mode 100644 index 0000000000..65227dfcc9 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationEmbeddedSession.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class A2PCampaignRegistrationEmbeddedSession extends Resource { + + public static A2PCampaignRegistrationEmbeddedSessionCreator creator( + final String pathId + ) { + return new A2PCampaignRegistrationEmbeddedSessionCreator(pathId); + } + + /** + * Converts a JSON String into a A2PCampaignRegistrationEmbeddedSession object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return A2PCampaignRegistrationEmbeddedSession object represented by the provided JSON + */ + public static A2PCampaignRegistrationEmbeddedSession fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + A2PCampaignRegistrationEmbeddedSession.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a A2PCampaignRegistrationEmbeddedSession object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return A2PCampaignRegistrationEmbeddedSession object represented by the provided JSON + */ + public static A2PCampaignRegistrationEmbeddedSession fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + A2PCampaignRegistrationEmbeddedSession.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String id; + + @Getter + private final String sessionId; + + @Getter + private final String sessionToken; + + @JsonCreator + private A2PCampaignRegistrationEmbeddedSession( + @JsonProperty("id") final String id, + @JsonProperty("sessionId") final String sessionId, + @JsonProperty("sessionToken") final String sessionToken + ) { + this.id = id; + this.sessionId = sessionId; + this.sessionToken = sessionToken; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + A2PCampaignRegistrationEmbeddedSession other = + (A2PCampaignRegistrationEmbeddedSession) o; + return ( + Objects.equals(id, other.id) && + Objects.equals(sessionId, other.sessionId) && + Objects.equals(sessionToken, other.sessionToken) + ); + } + + @Override + public int hashCode() { + return Objects.hash(id, sessionId, sessionToken); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationEmbeddedSessionCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationEmbeddedSessionCreator.java new file mode 100644 index 0000000000..1c755091b9 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/A2PCampaignRegistrationEmbeddedSessionCreator.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class A2PCampaignRegistrationEmbeddedSessionCreator + extends Creator { + + private String pathId; + + public A2PCampaignRegistrationEmbeddedSessionCreator(final String pathId) { + this.pathId = pathId; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/A2PCampaignRegistrations/{Id}/EmbeddedSessions"; + + path = path.replace("{" + "Id" + "}", this.pathId.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "A2PCampaignRegistrationEmbeddedSession creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public A2PCampaignRegistrationEmbeddedSession create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return A2PCampaignRegistrationEmbeddedSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + A2PCampaignRegistrationEmbeddedSession + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + A2PCampaignRegistrationEmbeddedSession content = + A2PCampaignRegistrationEmbeddedSession.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiries.java b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiries.java new file mode 100644 index 0000000000..14c329e18a --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiries.java @@ -0,0 +1,159 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ComplianceInquiries extends Resource { + + public static ComplianceInquiriesCreator creator() { + return new ComplianceInquiriesCreator(); + } + + public static ComplianceInquiriesUpdater updater( + final String pathCustomerId, + final String primaryProfileSid + ) { + return new ComplianceInquiriesUpdater( + pathCustomerId, + primaryProfileSid + ); + } + + /** + * Converts a JSON String into a ComplianceInquiries object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ComplianceInquiries object represented by the provided JSON + */ + public static ComplianceInquiries fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ComplianceInquiries.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ComplianceInquiries object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ComplianceInquiries object represented by the provided JSON + */ + public static ComplianceInquiries fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, ComplianceInquiries.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String customerId; + + @Getter + private final String inquiryId; + + @Getter + private final String inquirySessionToken; + + @Getter + private final URI url; + + @JsonCreator + private ComplianceInquiries( + @JsonProperty("customer_id") final String customerId, + @JsonProperty("inquiry_id") final String inquiryId, + @JsonProperty("inquiry_session_token") final String inquirySessionToken, + @JsonProperty("url") final URI url + ) { + this.customerId = customerId; + this.inquiryId = inquiryId; + this.inquirySessionToken = inquirySessionToken; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ComplianceInquiries other = (ComplianceInquiries) o; + return ( + Objects.equals(customerId, other.customerId) && + Objects.equals(inquiryId, other.inquiryId) && + Objects.equals(inquirySessionToken, other.inquirySessionToken) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(customerId, inquiryId, inquirySessionToken, url); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiriesCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiriesCreator.java new file mode 100644 index 0000000000..4aa5db4090 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiriesCreator.java @@ -0,0 +1,147 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ComplianceInquiriesCreator extends Creator { + + private String notificationEmail; + private String themeSetId; + private String primaryProfileSid; + + public ComplianceInquiriesCreator() {} + + public ComplianceInquiriesCreator setNotificationEmail( + final String notificationEmail + ) { + this.notificationEmail = notificationEmail; + return this; + } + + public ComplianceInquiriesCreator setThemeSetId(final String themeSetId) { + this.themeSetId = themeSetId; + return this; + } + + public ComplianceInquiriesCreator setPrimaryProfileSid( + final String primaryProfileSid + ) { + this.primaryProfileSid = primaryProfileSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ComplianceInquiries/Customers/Initialize"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ComplianceInquiries creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ComplianceInquiries create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ComplianceInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ComplianceInquiries content = ComplianceInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (notificationEmail != null) { + Serializer.toString( + request, + "NotificationEmail", + notificationEmail, + ParameterType.URLENCODED + ); + } + + if (themeSetId != null) { + Serializer.toString( + request, + "ThemeSetId", + themeSetId, + ParameterType.URLENCODED + ); + } + + if (primaryProfileSid != null) { + Serializer.toString( + request, + "PrimaryProfileSid", + primaryProfileSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiriesUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiriesUpdater.java new file mode 100644 index 0000000000..a3128327f6 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceInquiriesUpdater.java @@ -0,0 +1,144 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ComplianceInquiriesUpdater extends Updater { + + private String pathCustomerId; + private String primaryProfileSid; + private String themeSetId; + + public ComplianceInquiriesUpdater( + final String pathCustomerId, + final String primaryProfileSid + ) { + this.pathCustomerId = pathCustomerId; + this.primaryProfileSid = primaryProfileSid; + } + + public ComplianceInquiriesUpdater setPrimaryProfileSid( + final String primaryProfileSid + ) { + this.primaryProfileSid = primaryProfileSid; + return this; + } + + public ComplianceInquiriesUpdater setThemeSetId(final String themeSetId) { + this.themeSetId = themeSetId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ComplianceInquiries/Customers/{CustomerId}/Initialize"; + + path = + path.replace( + "{" + "CustomerId" + "}", + this.pathCustomerId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ComplianceInquiries update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ComplianceInquiries update(final TwilioRestClient client) { + Response response = makeRequest(client); + return ComplianceInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ComplianceInquiries content = ComplianceInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (primaryProfileSid != null) { + Serializer.toString( + request, + "PrimaryProfileSid", + primaryProfileSid, + ParameterType.URLENCODED + ); + } + + if (themeSetId != null) { + Serializer.toString( + request, + "ThemeSetId", + themeSetId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiries.java b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiries.java new file mode 100644 index 0000000000..31cc694eb3 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiries.java @@ -0,0 +1,273 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ComplianceRegistrationInquiries extends Resource { + + public static ComplianceRegistrationInquiriesCreator creator( + final ComplianceRegistrationInquiries.EndUserType endUserType, + final ComplianceRegistrationInquiries.PhoneNumberType phoneNumberType + ) { + return new ComplianceRegistrationInquiriesCreator( + endUserType, + phoneNumberType + ); + } + + public static ComplianceRegistrationInquiriesUpdater updater( + final String pathRegistrationId + ) { + return new ComplianceRegistrationInquiriesUpdater(pathRegistrationId); + } + + public enum EndUserType { + INDIVIDUAL("Individual"), + BUSINESS("Business"); + + private final String value; + + private EndUserType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static EndUserType forValue(final String value) { + return Promoter.enumFromString(value, EndUserType.values()); + } + } + + public enum BusinessIdentityType { + DIRECT_CUSTOMER("direct_customer"), + ISV_RESELLER_OR_PARTNER("isv_reseller_or_partner"), + UNKNOWN("unknown"); + + private final String value; + + private BusinessIdentityType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BusinessIdentityType forValue(final String value) { + return Promoter.enumFromString( + value, + BusinessIdentityType.values() + ); + } + } + + public enum BusinessRegistrationAuthority { + UK_CRN("UK:CRN"), + US_EIN("US:EIN"), + CA_CBN("CA:CBN"), + AU_ACN("AU:ACN"), + OTHER("Other"); + + private final String value; + + private BusinessRegistrationAuthority(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BusinessRegistrationAuthority forValue( + final String value + ) { + return Promoter.enumFromString( + value, + BusinessRegistrationAuthority.values() + ); + } + } + + public enum PhoneNumberType { + LOCAL("local"), + NATIONAL("national"), + MOBILE("mobile"), + TOLL_FREE("toll-free"); + + private final String value; + + private PhoneNumberType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static PhoneNumberType forValue(final String value) { + return Promoter.enumFromString(value, PhoneNumberType.values()); + } + } + + /** + * Converts a JSON String into a ComplianceRegistrationInquiries object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ComplianceRegistrationInquiries object represented by the provided JSON + */ + public static ComplianceRegistrationInquiries fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ComplianceRegistrationInquiries.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ComplianceRegistrationInquiries object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ComplianceRegistrationInquiries object represented by the provided JSON + */ + public static ComplianceRegistrationInquiries fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ComplianceRegistrationInquiries.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String inquiryId; + + @Getter + private final String inquirySessionToken; + + @Getter + private final String registrationId; + + @Getter + private final URI url; + + @JsonCreator + private ComplianceRegistrationInquiries( + @JsonProperty("inquiry_id") final String inquiryId, + @JsonProperty("inquiry_session_token") final String inquirySessionToken, + @JsonProperty("registration_id") final String registrationId, + @JsonProperty("url") final URI url + ) { + this.inquiryId = inquiryId; + this.inquirySessionToken = inquirySessionToken; + this.registrationId = registrationId; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ComplianceRegistrationInquiries other = + (ComplianceRegistrationInquiries) o; + return ( + Objects.equals(inquiryId, other.inquiryId) && + Objects.equals(inquirySessionToken, other.inquirySessionToken) && + Objects.equals(registrationId, other.registrationId) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + inquiryId, + inquirySessionToken, + registrationId, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiriesCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiriesCreator.java new file mode 100644 index 0000000000..9c87a49c17 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiriesCreator.java @@ -0,0 +1,773 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ComplianceRegistrationInquiriesCreator + extends Creator { + + private ComplianceRegistrationInquiries.EndUserType endUserType; + private ComplianceRegistrationInquiries.PhoneNumberType phoneNumberType; + private ComplianceRegistrationInquiries.BusinessIdentityType businessIdentityType; + private ComplianceRegistrationInquiries.BusinessRegistrationAuthority businessRegistrationAuthority; + private String businessLegalName; + private String notificationEmail; + private Boolean acceptedNotificationReceipt; + private String businessRegistrationNumber; + private String businessWebsiteUrl; + private String friendlyName; + private String authorizedRepresentative1FirstName; + private String authorizedRepresentative1LastName; + private String authorizedRepresentative1Phone; + private String authorizedRepresentative1Email; + private String authorizedRepresentative1DateOfBirth; + private String addressStreet; + private String addressStreetSecondary; + private String addressCity; + private String addressSubdivision; + private String addressPostalCode; + private String addressCountryCode; + private String emergencyAddressStreet; + private String emergencyAddressStreetSecondary; + private String emergencyAddressCity; + private String emergencyAddressSubdivision; + private String emergencyAddressPostalCode; + private String emergencyAddressCountryCode; + private Boolean useAddressAsEmergencyAddress; + private String fileName; + private String _file; + private String firstName; + private String lastName; + private String dateOfBirth; + private String individualEmail; + private String individualPhone; + private Boolean isIsvEmbed; + private String isvRegisteringForSelfOrTenant; + private String statusCallbackUrl; + private String themeSetId; + + public ComplianceRegistrationInquiriesCreator( + final ComplianceRegistrationInquiries.EndUserType endUserType, + final ComplianceRegistrationInquiries.PhoneNumberType phoneNumberType + ) { + this.endUserType = endUserType; + this.phoneNumberType = phoneNumberType; + } + + public ComplianceRegistrationInquiriesCreator setEndUserType( + final ComplianceRegistrationInquiries.EndUserType endUserType + ) { + this.endUserType = endUserType; + return this; + } + + public ComplianceRegistrationInquiriesCreator setPhoneNumberType( + final ComplianceRegistrationInquiries.PhoneNumberType phoneNumberType + ) { + this.phoneNumberType = phoneNumberType; + return this; + } + + public ComplianceRegistrationInquiriesCreator setBusinessIdentityType( + final ComplianceRegistrationInquiries.BusinessIdentityType businessIdentityType + ) { + this.businessIdentityType = businessIdentityType; + return this; + } + + public ComplianceRegistrationInquiriesCreator setBusinessRegistrationAuthority( + final ComplianceRegistrationInquiries.BusinessRegistrationAuthority businessRegistrationAuthority + ) { + this.businessRegistrationAuthority = businessRegistrationAuthority; + return this; + } + + public ComplianceRegistrationInquiriesCreator setBusinessLegalName( + final String businessLegalName + ) { + this.businessLegalName = businessLegalName; + return this; + } + + public ComplianceRegistrationInquiriesCreator setNotificationEmail( + final String notificationEmail + ) { + this.notificationEmail = notificationEmail; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAcceptedNotificationReceipt( + final Boolean acceptedNotificationReceipt + ) { + this.acceptedNotificationReceipt = acceptedNotificationReceipt; + return this; + } + + public ComplianceRegistrationInquiriesCreator setBusinessRegistrationNumber( + final String businessRegistrationNumber + ) { + this.businessRegistrationNumber = businessRegistrationNumber; + return this; + } + + public ComplianceRegistrationInquiriesCreator setBusinessWebsiteUrl( + final String businessWebsiteUrl + ) { + this.businessWebsiteUrl = businessWebsiteUrl; + return this; + } + + public ComplianceRegistrationInquiriesCreator setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAuthorizedRepresentative1FirstName( + final String authorizedRepresentative1FirstName + ) { + this.authorizedRepresentative1FirstName = + authorizedRepresentative1FirstName; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAuthorizedRepresentative1LastName( + final String authorizedRepresentative1LastName + ) { + this.authorizedRepresentative1LastName = + authorizedRepresentative1LastName; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAuthorizedRepresentative1Phone( + final String authorizedRepresentative1Phone + ) { + this.authorizedRepresentative1Phone = authorizedRepresentative1Phone; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAuthorizedRepresentative1Email( + final String authorizedRepresentative1Email + ) { + this.authorizedRepresentative1Email = authorizedRepresentative1Email; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAuthorizedRepresentative1DateOfBirth( + final String authorizedRepresentative1DateOfBirth + ) { + this.authorizedRepresentative1DateOfBirth = + authorizedRepresentative1DateOfBirth; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAddressStreet( + final String addressStreet + ) { + this.addressStreet = addressStreet; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAddressStreetSecondary( + final String addressStreetSecondary + ) { + this.addressStreetSecondary = addressStreetSecondary; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAddressCity( + final String addressCity + ) { + this.addressCity = addressCity; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAddressSubdivision( + final String addressSubdivision + ) { + this.addressSubdivision = addressSubdivision; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAddressPostalCode( + final String addressPostalCode + ) { + this.addressPostalCode = addressPostalCode; + return this; + } + + public ComplianceRegistrationInquiriesCreator setAddressCountryCode( + final String addressCountryCode + ) { + this.addressCountryCode = addressCountryCode; + return this; + } + + public ComplianceRegistrationInquiriesCreator setEmergencyAddressStreet( + final String emergencyAddressStreet + ) { + this.emergencyAddressStreet = emergencyAddressStreet; + return this; + } + + public ComplianceRegistrationInquiriesCreator setEmergencyAddressStreetSecondary( + final String emergencyAddressStreetSecondary + ) { + this.emergencyAddressStreetSecondary = emergencyAddressStreetSecondary; + return this; + } + + public ComplianceRegistrationInquiriesCreator setEmergencyAddressCity( + final String emergencyAddressCity + ) { + this.emergencyAddressCity = emergencyAddressCity; + return this; + } + + public ComplianceRegistrationInquiriesCreator setEmergencyAddressSubdivision( + final String emergencyAddressSubdivision + ) { + this.emergencyAddressSubdivision = emergencyAddressSubdivision; + return this; + } + + public ComplianceRegistrationInquiriesCreator setEmergencyAddressPostalCode( + final String emergencyAddressPostalCode + ) { + this.emergencyAddressPostalCode = emergencyAddressPostalCode; + return this; + } + + public ComplianceRegistrationInquiriesCreator setEmergencyAddressCountryCode( + final String emergencyAddressCountryCode + ) { + this.emergencyAddressCountryCode = emergencyAddressCountryCode; + return this; + } + + public ComplianceRegistrationInquiriesCreator setUseAddressAsEmergencyAddress( + final Boolean useAddressAsEmergencyAddress + ) { + this.useAddressAsEmergencyAddress = useAddressAsEmergencyAddress; + return this; + } + + public ComplianceRegistrationInquiriesCreator setFileName( + final String fileName + ) { + this.fileName = fileName; + return this; + } + + public ComplianceRegistrationInquiriesCreator set_file(final String _file) { + this._file = _file; + return this; + } + + public ComplianceRegistrationInquiriesCreator setFirstName( + final String firstName + ) { + this.firstName = firstName; + return this; + } + + public ComplianceRegistrationInquiriesCreator setLastName( + final String lastName + ) { + this.lastName = lastName; + return this; + } + + public ComplianceRegistrationInquiriesCreator setDateOfBirth( + final String dateOfBirth + ) { + this.dateOfBirth = dateOfBirth; + return this; + } + + public ComplianceRegistrationInquiriesCreator setIndividualEmail( + final String individualEmail + ) { + this.individualEmail = individualEmail; + return this; + } + + public ComplianceRegistrationInquiriesCreator setIndividualPhone( + final String individualPhone + ) { + this.individualPhone = individualPhone; + return this; + } + + public ComplianceRegistrationInquiriesCreator setIsIsvEmbed( + final Boolean isIsvEmbed + ) { + this.isIsvEmbed = isIsvEmbed; + return this; + } + + public ComplianceRegistrationInquiriesCreator setIsvRegisteringForSelfOrTenant( + final String isvRegisteringForSelfOrTenant + ) { + this.isvRegisteringForSelfOrTenant = isvRegisteringForSelfOrTenant; + return this; + } + + public ComplianceRegistrationInquiriesCreator setStatusCallbackUrl( + final String statusCallbackUrl + ) { + this.statusCallbackUrl = statusCallbackUrl; + return this; + } + + public ComplianceRegistrationInquiriesCreator setThemeSetId( + final String themeSetId + ) { + this.themeSetId = themeSetId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ComplianceInquiries/Registration/RegulatoryCompliance/GB/Initialize"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ComplianceRegistrationInquiries creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ComplianceRegistrationInquiries create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return ComplianceRegistrationInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ComplianceRegistrationInquiries content = + ComplianceRegistrationInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (endUserType != null) { + Serializer.toString( + request, + "EndUserType", + endUserType, + ParameterType.URLENCODED + ); + } + + if (phoneNumberType != null) { + Serializer.toString( + request, + "PhoneNumberType", + phoneNumberType, + ParameterType.URLENCODED + ); + } + + if (businessIdentityType != null) { + Serializer.toString( + request, + "BusinessIdentityType", + businessIdentityType, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationAuthority != null) { + Serializer.toString( + request, + "BusinessRegistrationAuthority", + businessRegistrationAuthority, + ParameterType.URLENCODED + ); + } + + if (businessLegalName != null) { + Serializer.toString( + request, + "BusinessLegalName", + businessLegalName, + ParameterType.URLENCODED + ); + } + + if (notificationEmail != null) { + Serializer.toString( + request, + "NotificationEmail", + notificationEmail, + ParameterType.URLENCODED + ); + } + + if (acceptedNotificationReceipt != null) { + Serializer.toString( + request, + "AcceptedNotificationReceipt", + acceptedNotificationReceipt, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationNumber != null) { + Serializer.toString( + request, + "BusinessRegistrationNumber", + businessRegistrationNumber, + ParameterType.URLENCODED + ); + } + + if (businessWebsiteUrl != null) { + Serializer.toString( + request, + "BusinessWebsiteUrl", + businessWebsiteUrl, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (authorizedRepresentative1FirstName != null) { + Serializer.toString( + request, + "AuthorizedRepresentative1FirstName", + authorizedRepresentative1FirstName, + ParameterType.URLENCODED + ); + } + + if (authorizedRepresentative1LastName != null) { + Serializer.toString( + request, + "AuthorizedRepresentative1LastName", + authorizedRepresentative1LastName, + ParameterType.URLENCODED + ); + } + + if (authorizedRepresentative1Phone != null) { + Serializer.toString( + request, + "AuthorizedRepresentative1Phone", + authorizedRepresentative1Phone, + ParameterType.URLENCODED + ); + } + + if (authorizedRepresentative1Email != null) { + Serializer.toString( + request, + "AuthorizedRepresentative1Email", + authorizedRepresentative1Email, + ParameterType.URLENCODED + ); + } + + if (authorizedRepresentative1DateOfBirth != null) { + Serializer.toString( + request, + "AuthorizedRepresentative1DateOfBirth", + authorizedRepresentative1DateOfBirth, + ParameterType.URLENCODED + ); + } + + if (addressStreet != null) { + Serializer.toString( + request, + "AddressStreet", + addressStreet, + ParameterType.URLENCODED + ); + } + + if (addressStreetSecondary != null) { + Serializer.toString( + request, + "AddressStreetSecondary", + addressStreetSecondary, + ParameterType.URLENCODED + ); + } + + if (addressCity != null) { + Serializer.toString( + request, + "AddressCity", + addressCity, + ParameterType.URLENCODED + ); + } + + if (addressSubdivision != null) { + Serializer.toString( + request, + "AddressSubdivision", + addressSubdivision, + ParameterType.URLENCODED + ); + } + + if (addressPostalCode != null) { + Serializer.toString( + request, + "AddressPostalCode", + addressPostalCode, + ParameterType.URLENCODED + ); + } + + if (addressCountryCode != null) { + Serializer.toString( + request, + "AddressCountryCode", + addressCountryCode, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressStreet != null) { + Serializer.toString( + request, + "EmergencyAddressStreet", + emergencyAddressStreet, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressStreetSecondary != null) { + Serializer.toString( + request, + "EmergencyAddressStreetSecondary", + emergencyAddressStreetSecondary, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressCity != null) { + Serializer.toString( + request, + "EmergencyAddressCity", + emergencyAddressCity, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressSubdivision != null) { + Serializer.toString( + request, + "EmergencyAddressSubdivision", + emergencyAddressSubdivision, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressPostalCode != null) { + Serializer.toString( + request, + "EmergencyAddressPostalCode", + emergencyAddressPostalCode, + ParameterType.URLENCODED + ); + } + + if (emergencyAddressCountryCode != null) { + Serializer.toString( + request, + "EmergencyAddressCountryCode", + emergencyAddressCountryCode, + ParameterType.URLENCODED + ); + } + + if (useAddressAsEmergencyAddress != null) { + Serializer.toString( + request, + "UseAddressAsEmergencyAddress", + useAddressAsEmergencyAddress, + ParameterType.URLENCODED + ); + } + + if (fileName != null) { + Serializer.toString( + request, + "FileName", + fileName, + ParameterType.URLENCODED + ); + } + + if (_file != null) { + Serializer.toString( + request, + "File", + _file, + ParameterType.URLENCODED + ); + } + + if (firstName != null) { + Serializer.toString( + request, + "FirstName", + firstName, + ParameterType.URLENCODED + ); + } + + if (lastName != null) { + Serializer.toString( + request, + "LastName", + lastName, + ParameterType.URLENCODED + ); + } + + if (dateOfBirth != null) { + Serializer.toString( + request, + "DateOfBirth", + dateOfBirth, + ParameterType.URLENCODED + ); + } + + if (individualEmail != null) { + Serializer.toString( + request, + "IndividualEmail", + individualEmail, + ParameterType.URLENCODED + ); + } + + if (individualPhone != null) { + Serializer.toString( + request, + "IndividualPhone", + individualPhone, + ParameterType.URLENCODED + ); + } + + if (isIsvEmbed != null) { + Serializer.toString( + request, + "IsIsvEmbed", + isIsvEmbed, + ParameterType.URLENCODED + ); + } + + if (isvRegisteringForSelfOrTenant != null) { + Serializer.toString( + request, + "IsvRegisteringForSelfOrTenant", + isvRegisteringForSelfOrTenant, + ParameterType.URLENCODED + ); + } + + if (statusCallbackUrl != null) { + Serializer.toString( + request, + "StatusCallbackUrl", + statusCallbackUrl, + ParameterType.URLENCODED + ); + } + + if (themeSetId != null) { + Serializer.toString( + request, + "ThemeSetId", + themeSetId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiriesUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiriesUpdater.java new file mode 100644 index 0000000000..b5efbb16ee --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceRegistrationInquiriesUpdater.java @@ -0,0 +1,148 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ComplianceRegistrationInquiriesUpdater + extends Updater { + + private String pathRegistrationId; + private Boolean isIsvEmbed; + private String themeSetId; + + public ComplianceRegistrationInquiriesUpdater( + final String pathRegistrationId + ) { + this.pathRegistrationId = pathRegistrationId; + } + + public ComplianceRegistrationInquiriesUpdater setIsIsvEmbed( + final Boolean isIsvEmbed + ) { + this.isIsvEmbed = isIsvEmbed; + return this; + } + + public ComplianceRegistrationInquiriesUpdater setThemeSetId( + final String themeSetId + ) { + this.themeSetId = themeSetId; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/ComplianceInquiries/Registration/{RegistrationId}/RegulatoryCompliance/GB/Initialize"; + + path = + path.replace( + "{" + "RegistrationId" + "}", + this.pathRegistrationId.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ComplianceRegistrationInquiries update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ComplianceRegistrationInquiries update( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return ComplianceRegistrationInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ComplianceRegistrationInquiries content = + ComplianceRegistrationInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (isIsvEmbed != null) { + Serializer.toString( + request, + "IsIsvEmbed", + isIsvEmbed, + ParameterType.URLENCODED + ); + } + + if (themeSetId != null) { + Serializer.toString( + request, + "ThemeSetId", + themeSetId, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/ComplianceTollfreeInquiries.java b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceTollfreeInquiries.java new file mode 100644 index 0000000000..c888e4f0cd --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceTollfreeInquiries.java @@ -0,0 +1,216 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class ComplianceTollfreeInquiries extends Resource { + + public static ComplianceTollfreeInquiriesCreator creator( + final com.twilio.type.PhoneNumber tollfreePhoneNumber, + final String notificationEmail + ) { + return new ComplianceTollfreeInquiriesCreator( + tollfreePhoneNumber, + notificationEmail + ); + } + + public enum BusinessType { + PRIVATE_PROFIT("PRIVATE_PROFIT"), + PUBLIC_PROFIT("PUBLIC_PROFIT"), + NON_PROFIT("NON_PROFIT"), + SOLE_PROPRIETOR("SOLE_PROPRIETOR"), + GOVERNMENT("GOVERNMENT"); + + private final String value; + + private BusinessType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static BusinessType forValue(final String value) { + return Promoter.enumFromString(value, BusinessType.values()); + } + } + + public enum OptInType { + VERBAL("VERBAL"), + WEB_FORM("WEB_FORM"), + PAPER_FORM("PAPER_FORM"), + VIA_TEXT("VIA_TEXT"), + MOBILE_QR_CODE("MOBILE_QR_CODE"); + + private final String value; + + private OptInType(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static OptInType forValue(final String value) { + return Promoter.enumFromString(value, OptInType.values()); + } + } + + /** + * Converts a JSON String into a ComplianceTollfreeInquiries object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return ComplianceTollfreeInquiries object represented by the provided JSON + */ + public static ComplianceTollfreeInquiries fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ComplianceTollfreeInquiries.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a ComplianceTollfreeInquiries object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return ComplianceTollfreeInquiries object represented by the provided JSON + */ + public static ComplianceTollfreeInquiries fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + ComplianceTollfreeInquiries.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String inquiryId; + + @Getter + private final String inquirySessionToken; + + @Getter + private final String registrationId; + + @Getter + private final URI url; + + @JsonCreator + private ComplianceTollfreeInquiries( + @JsonProperty("inquiry_id") final String inquiryId, + @JsonProperty("inquiry_session_token") final String inquirySessionToken, + @JsonProperty("registration_id") final String registrationId, + @JsonProperty("url") final URI url + ) { + this.inquiryId = inquiryId; + this.inquirySessionToken = inquirySessionToken; + this.registrationId = registrationId; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + ComplianceTollfreeInquiries other = (ComplianceTollfreeInquiries) o; + return ( + Objects.equals(inquiryId, other.inquiryId) && + Objects.equals(inquirySessionToken, other.inquirySessionToken) && + Objects.equals(registrationId, other.registrationId) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + inquiryId, + inquirySessionToken, + registrationId, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/ComplianceTollfreeInquiriesCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceTollfreeInquiriesCreator.java new file mode 100644 index 0000000000..3d97678744 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/ComplianceTollfreeInquiriesCreator.java @@ -0,0 +1,794 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.List; + +public class ComplianceTollfreeInquiriesCreator + extends Creator { + + private com.twilio.type.PhoneNumber tollfreePhoneNumber; + private String notificationEmail; + private String customerProfileSid; + private String businessName; + private String businessWebsite; + private List useCaseCategories; + private String useCaseSummary; + private String productionMessageSample; + private List optInImageUrls; + private ComplianceTollfreeInquiries.OptInType optInType; + private String messageVolume; + private String businessStreetAddress; + private String businessStreetAddress2; + private String businessCity; + private String businessStateProvinceRegion; + private String businessPostalCode; + private String businessCountry; + private String additionalInformation; + private String businessContactFirstName; + private String businessContactLastName; + private String businessContactEmail; + private com.twilio.type.PhoneNumber businessContactPhone; + private String themeSetId; + private Boolean skipMessagingUseCase; + private String businessRegistrationNumber; + private String businessRegistrationAuthority; + private String businessRegistrationCountry; + private ComplianceTollfreeInquiries.BusinessType businessType; + private String doingBusinessAs; + private String optInConfirmationMessage; + private String helpMessageSample; + private String privacyPolicyUrl; + private String termsAndConditionsUrl; + private Boolean ageGatedContent; + private String externalReferenceId; + private List optInKeywords; + private String vettingId; + private String vettingProvider; + + public ComplianceTollfreeInquiriesCreator( + final com.twilio.type.PhoneNumber tollfreePhoneNumber, + final String notificationEmail + ) { + this.tollfreePhoneNumber = tollfreePhoneNumber; + this.notificationEmail = notificationEmail; + } + + public ComplianceTollfreeInquiriesCreator setTollfreePhoneNumber( + final com.twilio.type.PhoneNumber tollfreePhoneNumber + ) { + this.tollfreePhoneNumber = tollfreePhoneNumber; + return this; + } + + public ComplianceTollfreeInquiriesCreator setTollfreePhoneNumber( + final String tollfreePhoneNumber + ) { + return setTollfreePhoneNumber( + Promoter.phoneNumberFromString(tollfreePhoneNumber) + ); + } + + public ComplianceTollfreeInquiriesCreator setNotificationEmail( + final String notificationEmail + ) { + this.notificationEmail = notificationEmail; + return this; + } + + public ComplianceTollfreeInquiriesCreator setCustomerProfileSid( + final String customerProfileSid + ) { + this.customerProfileSid = customerProfileSid; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessName( + final String businessName + ) { + this.businessName = businessName; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessWebsite( + final String businessWebsite + ) { + this.businessWebsite = businessWebsite; + return this; + } + + public ComplianceTollfreeInquiriesCreator setUseCaseCategories( + final List useCaseCategories + ) { + this.useCaseCategories = useCaseCategories; + return this; + } + + public ComplianceTollfreeInquiriesCreator setUseCaseCategories( + final String useCaseCategories + ) { + return setUseCaseCategories(Promoter.listOfOne(useCaseCategories)); + } + + public ComplianceTollfreeInquiriesCreator setUseCaseSummary( + final String useCaseSummary + ) { + this.useCaseSummary = useCaseSummary; + return this; + } + + public ComplianceTollfreeInquiriesCreator setProductionMessageSample( + final String productionMessageSample + ) { + this.productionMessageSample = productionMessageSample; + return this; + } + + public ComplianceTollfreeInquiriesCreator setOptInImageUrls( + final List optInImageUrls + ) { + this.optInImageUrls = optInImageUrls; + return this; + } + + public ComplianceTollfreeInquiriesCreator setOptInImageUrls( + final String optInImageUrls + ) { + return setOptInImageUrls(Promoter.listOfOne(optInImageUrls)); + } + + public ComplianceTollfreeInquiriesCreator setOptInType( + final ComplianceTollfreeInquiries.OptInType optInType + ) { + this.optInType = optInType; + return this; + } + + public ComplianceTollfreeInquiriesCreator setMessageVolume( + final String messageVolume + ) { + this.messageVolume = messageVolume; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessStreetAddress( + final String businessStreetAddress + ) { + this.businessStreetAddress = businessStreetAddress; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessStreetAddress2( + final String businessStreetAddress2 + ) { + this.businessStreetAddress2 = businessStreetAddress2; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessCity( + final String businessCity + ) { + this.businessCity = businessCity; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessStateProvinceRegion( + final String businessStateProvinceRegion + ) { + this.businessStateProvinceRegion = businessStateProvinceRegion; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessPostalCode( + final String businessPostalCode + ) { + this.businessPostalCode = businessPostalCode; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessCountry( + final String businessCountry + ) { + this.businessCountry = businessCountry; + return this; + } + + public ComplianceTollfreeInquiriesCreator setAdditionalInformation( + final String additionalInformation + ) { + this.additionalInformation = additionalInformation; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessContactFirstName( + final String businessContactFirstName + ) { + this.businessContactFirstName = businessContactFirstName; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessContactLastName( + final String businessContactLastName + ) { + this.businessContactLastName = businessContactLastName; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessContactEmail( + final String businessContactEmail + ) { + this.businessContactEmail = businessContactEmail; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessContactPhone( + final com.twilio.type.PhoneNumber businessContactPhone + ) { + this.businessContactPhone = businessContactPhone; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessContactPhone( + final String businessContactPhone + ) { + return setBusinessContactPhone( + Promoter.phoneNumberFromString(businessContactPhone) + ); + } + + public ComplianceTollfreeInquiriesCreator setThemeSetId( + final String themeSetId + ) { + this.themeSetId = themeSetId; + return this; + } + + public ComplianceTollfreeInquiriesCreator setSkipMessagingUseCase( + final Boolean skipMessagingUseCase + ) { + this.skipMessagingUseCase = skipMessagingUseCase; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessRegistrationNumber( + final String businessRegistrationNumber + ) { + this.businessRegistrationNumber = businessRegistrationNumber; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessRegistrationAuthority( + final String businessRegistrationAuthority + ) { + this.businessRegistrationAuthority = businessRegistrationAuthority; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessRegistrationCountry( + final String businessRegistrationCountry + ) { + this.businessRegistrationCountry = businessRegistrationCountry; + return this; + } + + public ComplianceTollfreeInquiriesCreator setBusinessType( + final ComplianceTollfreeInquiries.BusinessType businessType + ) { + this.businessType = businessType; + return this; + } + + public ComplianceTollfreeInquiriesCreator setDoingBusinessAs( + final String doingBusinessAs + ) { + this.doingBusinessAs = doingBusinessAs; + return this; + } + + public ComplianceTollfreeInquiriesCreator setOptInConfirmationMessage( + final String optInConfirmationMessage + ) { + this.optInConfirmationMessage = optInConfirmationMessage; + return this; + } + + public ComplianceTollfreeInquiriesCreator setHelpMessageSample( + final String helpMessageSample + ) { + this.helpMessageSample = helpMessageSample; + return this; + } + + public ComplianceTollfreeInquiriesCreator setPrivacyPolicyUrl( + final String privacyPolicyUrl + ) { + this.privacyPolicyUrl = privacyPolicyUrl; + return this; + } + + public ComplianceTollfreeInquiriesCreator setTermsAndConditionsUrl( + final String termsAndConditionsUrl + ) { + this.termsAndConditionsUrl = termsAndConditionsUrl; + return this; + } + + public ComplianceTollfreeInquiriesCreator setAgeGatedContent( + final Boolean ageGatedContent + ) { + this.ageGatedContent = ageGatedContent; + return this; + } + + public ComplianceTollfreeInquiriesCreator setExternalReferenceId( + final String externalReferenceId + ) { + this.externalReferenceId = externalReferenceId; + return this; + } + + public ComplianceTollfreeInquiriesCreator setOptInKeywords( + final List optInKeywords + ) { + this.optInKeywords = optInKeywords; + return this; + } + + public ComplianceTollfreeInquiriesCreator setOptInKeywords( + final String optInKeywords + ) { + return setOptInKeywords(Promoter.listOfOne(optInKeywords)); + } + + public ComplianceTollfreeInquiriesCreator setVettingId( + final String vettingId + ) { + this.vettingId = vettingId; + return this; + } + + public ComplianceTollfreeInquiriesCreator setVettingProvider( + final String vettingProvider + ) { + this.vettingProvider = vettingProvider; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/ComplianceInquiries/Tollfree/Initialize"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "ComplianceTollfreeInquiries creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public ComplianceTollfreeInquiries create(final TwilioRestClient client) { + Response response = makeRequest(client); + return ComplianceTollfreeInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + ComplianceTollfreeInquiries content = + ComplianceTollfreeInquiries.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (tollfreePhoneNumber != null) { + Serializer.toString( + request, + "TollfreePhoneNumber", + tollfreePhoneNumber, + ParameterType.URLENCODED + ); + } + + if (notificationEmail != null) { + Serializer.toString( + request, + "NotificationEmail", + notificationEmail, + ParameterType.URLENCODED + ); + } + + if (customerProfileSid != null) { + Serializer.toString( + request, + "CustomerProfileSid", + customerProfileSid, + ParameterType.URLENCODED + ); + } + + if (businessName != null) { + Serializer.toString( + request, + "BusinessName", + businessName, + ParameterType.URLENCODED + ); + } + + if (businessWebsite != null) { + Serializer.toString( + request, + "BusinessWebsite", + businessWebsite, + ParameterType.URLENCODED + ); + } + + if (useCaseCategories != null) { + for (String param : useCaseCategories) { + Serializer.toString( + request, + "UseCaseCategories", + param, + ParameterType.URLENCODED + ); + } + } + + if (useCaseSummary != null) { + Serializer.toString( + request, + "UseCaseSummary", + useCaseSummary, + ParameterType.URLENCODED + ); + } + + if (productionMessageSample != null) { + Serializer.toString( + request, + "ProductionMessageSample", + productionMessageSample, + ParameterType.URLENCODED + ); + } + + if (optInImageUrls != null) { + for (String param : optInImageUrls) { + Serializer.toString( + request, + "OptInImageUrls", + param, + ParameterType.URLENCODED + ); + } + } + + if (optInType != null) { + Serializer.toString( + request, + "OptInType", + optInType, + ParameterType.URLENCODED + ); + } + + if (messageVolume != null) { + Serializer.toString( + request, + "MessageVolume", + messageVolume, + ParameterType.URLENCODED + ); + } + + if (businessStreetAddress != null) { + Serializer.toString( + request, + "BusinessStreetAddress", + businessStreetAddress, + ParameterType.URLENCODED + ); + } + + if (businessStreetAddress2 != null) { + Serializer.toString( + request, + "BusinessStreetAddress2", + businessStreetAddress2, + ParameterType.URLENCODED + ); + } + + if (businessCity != null) { + Serializer.toString( + request, + "BusinessCity", + businessCity, + ParameterType.URLENCODED + ); + } + + if (businessStateProvinceRegion != null) { + Serializer.toString( + request, + "BusinessStateProvinceRegion", + businessStateProvinceRegion, + ParameterType.URLENCODED + ); + } + + if (businessPostalCode != null) { + Serializer.toString( + request, + "BusinessPostalCode", + businessPostalCode, + ParameterType.URLENCODED + ); + } + + if (businessCountry != null) { + Serializer.toString( + request, + "BusinessCountry", + businessCountry, + ParameterType.URLENCODED + ); + } + + if (additionalInformation != null) { + Serializer.toString( + request, + "AdditionalInformation", + additionalInformation, + ParameterType.URLENCODED + ); + } + + if (businessContactFirstName != null) { + Serializer.toString( + request, + "BusinessContactFirstName", + businessContactFirstName, + ParameterType.URLENCODED + ); + } + + if (businessContactLastName != null) { + Serializer.toString( + request, + "BusinessContactLastName", + businessContactLastName, + ParameterType.URLENCODED + ); + } + + if (businessContactEmail != null) { + Serializer.toString( + request, + "BusinessContactEmail", + businessContactEmail, + ParameterType.URLENCODED + ); + } + + if (businessContactPhone != null) { + Serializer.toString( + request, + "BusinessContactPhone", + businessContactPhone, + ParameterType.URLENCODED + ); + } + + if (themeSetId != null) { + Serializer.toString( + request, + "ThemeSetId", + themeSetId, + ParameterType.URLENCODED + ); + } + + if (skipMessagingUseCase != null) { + Serializer.toString( + request, + "SkipMessagingUseCase", + skipMessagingUseCase, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationNumber != null) { + Serializer.toString( + request, + "BusinessRegistrationNumber", + businessRegistrationNumber, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationAuthority != null) { + Serializer.toString( + request, + "BusinessRegistrationAuthority", + businessRegistrationAuthority, + ParameterType.URLENCODED + ); + } + + if (businessRegistrationCountry != null) { + Serializer.toString( + request, + "BusinessRegistrationCountry", + businessRegistrationCountry, + ParameterType.URLENCODED + ); + } + + if (businessType != null) { + Serializer.toString( + request, + "BusinessType", + businessType, + ParameterType.URLENCODED + ); + } + + if (doingBusinessAs != null) { + Serializer.toString( + request, + "DoingBusinessAs", + doingBusinessAs, + ParameterType.URLENCODED + ); + } + + if (optInConfirmationMessage != null) { + Serializer.toString( + request, + "OptInConfirmationMessage", + optInConfirmationMessage, + ParameterType.URLENCODED + ); + } + + if (helpMessageSample != null) { + Serializer.toString( + request, + "HelpMessageSample", + helpMessageSample, + ParameterType.URLENCODED + ); + } + + if (privacyPolicyUrl != null) { + Serializer.toString( + request, + "PrivacyPolicyUrl", + privacyPolicyUrl, + ParameterType.URLENCODED + ); + } + + if (termsAndConditionsUrl != null) { + Serializer.toString( + request, + "TermsAndConditionsUrl", + termsAndConditionsUrl, + ParameterType.URLENCODED + ); + } + + if (ageGatedContent != null) { + Serializer.toString( + request, + "AgeGatedContent", + ageGatedContent, + ParameterType.URLENCODED + ); + } + + if (externalReferenceId != null) { + Serializer.toString( + request, + "ExternalReferenceId", + externalReferenceId, + ParameterType.URLENCODED + ); + } + + if (optInKeywords != null) { + for (String param : optInKeywords) { + Serializer.toString( + request, + "OptInKeywords", + param, + ParameterType.URLENCODED + ); + } + } + + if (vettingId != null) { + Serializer.toString( + request, + "VettingId", + vettingId, + ParameterType.URLENCODED + ); + } + + if (vettingProvider != null) { + Serializer.toString( + request, + "VettingProvider", + vettingProvider, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfiles.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfiles.java new file mode 100644 index 0000000000..a9bc86f59a --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfiles.java @@ -0,0 +1,283 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CustomerProfiles extends Resource { + + public static CustomerProfilesCreator creator( + final String friendlyName, + final String email, + final String policySid + ) { + return new CustomerProfilesCreator(friendlyName, email, policySid); + } + + public static CustomerProfilesDeleter deleter(final String pathSid) { + return new CustomerProfilesDeleter(pathSid); + } + + public static CustomerProfilesFetcher fetcher(final String pathSid) { + return new CustomerProfilesFetcher(pathSid); + } + + public static CustomerProfilesReader reader() { + return new CustomerProfilesReader(); + } + + public static CustomerProfilesUpdater updater(final String pathSid) { + return new CustomerProfilesUpdater(pathSid); + } + + public enum Status { + DRAFT("draft"), + PENDING_REVIEW("pending-review"), + IN_REVIEW("in-review"), + TWILIO_REJECTED("twilio-rejected"), + TWILIO_APPROVED("twilio-approved"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a CustomerProfiles object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfiles object represented by the provided JSON + */ + public static CustomerProfiles fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CustomerProfiles.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CustomerProfiles object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfiles object represented by the provided JSON + */ + public static CustomerProfiles fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, CustomerProfiles.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final List errors; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String policySid; + + @Getter + private final String sid; + + @Getter + private final CustomerProfiles.Status status; + + @Getter + private final URI statusCallback; + + @Getter + private final URI url; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime validUntil; + + @JsonCreator + private CustomerProfiles( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("errors") final List errors, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final CustomerProfiles.Status status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("url") final URI url, + @JsonProperty("valid_until") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime validUntil + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.errors = errors; + this.friendlyName = friendlyName; + this.links = links; + this.policySid = policySid; + this.sid = sid; + this.status = status; + this.statusCallback = statusCallback; + this.url = url; + this.validUntil = validUntil; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomerProfiles other = (CustomerProfiles) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(errors, other.errors) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(policySid, other.policySid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(url, other.url) && + Objects.equals(validUntil, other.validUntil) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + email, + errors, + friendlyName, + links, + policySid, + sid, + status, + statusCallback, + url, + validUntil + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesCreator.java new file mode 100644 index 0000000000..ef4ccf456e --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesCreator.java @@ -0,0 +1,174 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class CustomerProfilesCreator extends Creator { + + private String friendlyName; + private String email; + private String policySid; + private URI statusCallback; + + public CustomerProfilesCreator( + final String friendlyName, + final String email, + final String policySid + ) { + this.friendlyName = friendlyName; + this.email = email; + this.policySid = policySid; + } + + public CustomerProfilesCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public CustomerProfilesCreator setEmail(final String email) { + this.email = email; + return this; + } + + public CustomerProfilesCreator setPolicySid(final String policySid) { + this.policySid = policySid; + return this; + } + + public CustomerProfilesCreator setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public CustomerProfilesCreator setStatusCallback( + final String statusCallback + ) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/CustomerProfiles"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfiles creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfiles create(final TwilioRestClient client) { + Response response = makeRequest(client); + return CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfiles content = CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + + if (policySid != null) { + Serializer.toString( + request, + "PolicySid", + policySid, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesDeleter.java new file mode 100644 index 0000000000..c2543c18ec --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class CustomerProfilesDeleter extends Deleter { + + private String pathSid; + + public CustomerProfilesDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/CustomerProfiles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfiles delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesFetcher.java new file mode 100644 index 0000000000..a5c05be700 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesFetcher extends Fetcher { + + private String pathSid; + + public CustomerProfilesFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/CustomerProfiles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfiles fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfiles fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfiles content = CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopy.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopy.java new file mode 100644 index 0000000000..b677e3429d --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopy.java @@ -0,0 +1,240 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CustomerProfilesProvisionalCopy extends Resource { + + public static CustomerProfilesProvisionalCopyCreator creator( + final String pathCustomerProfileSid + ) { + return new CustomerProfilesProvisionalCopyCreator( + pathCustomerProfileSid + ); + } + + public static CustomerProfilesProvisionalCopyFetcher fetcher( + final String pathCustomerProfileSid + ) { + return new CustomerProfilesProvisionalCopyFetcher( + pathCustomerProfileSid + ); + } + + /** + * Converts a JSON String into a CustomerProfilesProvisionalCopy object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesProvisionalCopy object represented by the provided JSON + */ + public static CustomerProfilesProvisionalCopy fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomerProfilesProvisionalCopy.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CustomerProfilesProvisionalCopy object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesProvisionalCopy object represented by the provided JSON + */ + public static CustomerProfilesProvisionalCopy fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomerProfilesProvisionalCopy.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String customerProfileSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final String friendlyName; + + @Getter + private final String policySid; + + @Getter + private final String status; + + @Getter + private final URI statusCallback; + + @Getter + private final URI url; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime validUntil; + + @JsonCreator + private CustomerProfilesProvisionalCopy( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("status") final String status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("url") final URI url, + @JsonProperty("valid_until") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime validUntil + ) { + this.accountSid = accountSid; + this.customerProfileSid = customerProfileSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.friendlyName = friendlyName; + this.policySid = policySid; + this.status = status; + this.statusCallback = statusCallback; + this.url = url; + this.validUntil = validUntil; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomerProfilesProvisionalCopy other = + (CustomerProfilesProvisionalCopy) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(policySid, other.policySid) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(url, other.url) && + Objects.equals(validUntil, other.validUntil) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + customerProfileSid, + dateCreated, + dateUpdated, + email, + friendlyName, + policySid, + status, + statusCallback, + url, + validUntil + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopyCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopyCreator.java new file mode 100644 index 0000000000..ab823d926b --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopyCreator.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesProvisionalCopyCreator + extends Creator { + + private String pathCustomerProfileSid; + + public CustomerProfilesProvisionalCopyCreator( + final String pathCustomerProfileSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ProvisionalCopy"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesProvisionalCopy creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfilesProvisionalCopy create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomerProfilesProvisionalCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfilesProvisionalCopy content = + CustomerProfilesProvisionalCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopyFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopyFetcher.java new file mode 100644 index 0000000000..0c0f8c288b --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesProvisionalCopyFetcher.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesProvisionalCopyFetcher + extends Fetcher { + + private String pathCustomerProfileSid; + + public CustomerProfilesProvisionalCopyFetcher( + final String pathCustomerProfileSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ProvisionalCopy"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesProvisionalCopy fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfilesProvisionalCopy fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomerProfilesProvisionalCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfilesProvisionalCopy content = + CustomerProfilesProvisionalCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesReader.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesReader.java new file mode 100644 index 0000000000..2c9ea0c330 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesReader.java @@ -0,0 +1,244 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesReader extends Reader { + + private CustomerProfiles.Status status; + private String friendlyName; + private String policySid; + private Long pageSize; + + public CustomerProfilesReader() {} + + public CustomerProfilesReader setStatus( + final CustomerProfiles.Status status + ) { + this.status = status; + return this; + } + + public CustomerProfilesReader setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public CustomerProfilesReader setPolicySid(final String policySid) { + this.policySid = policySid; + return this; + } + + public CustomerProfilesReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + CustomerProfiles.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/CustomerProfiles"; + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + CustomerProfiles.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CustomerProfiles read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + CustomerProfiles.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (policySid != null) { + Serializer.toString( + request, + "PolicySid", + policySid, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesUpdater.java new file mode 100644 index 0000000000..242e17ea6d --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/CustomerProfilesUpdater.java @@ -0,0 +1,173 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class CustomerProfilesUpdater extends Updater { + + private String pathSid; + private CustomerProfiles.Status status; + private URI statusCallback; + private String friendlyName; + private String email; + + public CustomerProfilesUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public CustomerProfilesUpdater setStatus( + final CustomerProfiles.Status status + ) { + this.status = status; + return this; + } + + public CustomerProfilesUpdater setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public CustomerProfilesUpdater setStatusCallback( + final String statusCallback + ) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + public CustomerProfilesUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public CustomerProfilesUpdater setEmail(final String email) { + this.email = email; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/CustomerProfiles/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfiles update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfiles update(final TwilioRestClient client) { + Response response = makeRequest(client); + return CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfiles content = CustomerProfiles.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUser.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUser.java new file mode 100644 index 0000000000..f45c5ece5d --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUser.java @@ -0,0 +1,214 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EndUser extends Resource { + + public static EndUserCreator creator( + final String friendlyName, + final String type + ) { + return new EndUserCreator(friendlyName, type); + } + + public static EndUserDeleter deleter(final String pathSid) { + return new EndUserDeleter(pathSid); + } + + public static EndUserFetcher fetcher(final String pathSid) { + return new EndUserFetcher(pathSid); + } + + public static EndUserReader reader() { + return new EndUserReader(); + } + + public static EndUserUpdater updater(final String pathSid) { + return new EndUserUpdater(pathSid); + } + + /** + * Converts a JSON String into a EndUser object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EndUser object represented by the provided JSON + */ + public static EndUser fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EndUser.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EndUser object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EndUser object represented by the provided JSON + */ + public static EndUser fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EndUser.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object attributes; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @Getter + private final String type; + + @Getter + private final URI url; + + @JsonCreator + private EndUser( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final Object attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.sid = sid; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EndUser other = (EndUser) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + dateCreated, + dateUpdated, + friendlyName, + sid, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserCreator.java new file mode 100644 index 0000000000..2c5db9cc88 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserCreator.java @@ -0,0 +1,143 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserCreator extends Creator { + + private String friendlyName; + private String type; + private Object attributes; + + public EndUserCreator(final String friendlyName, final String type) { + this.friendlyName = friendlyName; + this.type = type; + } + + public EndUserCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public EndUserCreator setType(final String type) { + this.type = type; + return this; + } + + public EndUserCreator setAttributes(final Object attributes) { + this.attributes = attributes; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/EndUsers"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUser creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EndUser create(final TwilioRestClient client) { + Response response = makeRequest(client); + return EndUser.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EndUser content = EndUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserDeleter.java new file mode 100644 index 0000000000..cbd323d213 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class EndUserDeleter extends Deleter { + + private String pathSid; + + public EndUserDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/EndUsers/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUser delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserFetcher.java new file mode 100644 index 0000000000..7eda2952e2 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserFetcher extends Fetcher { + + private String pathSid; + + public EndUserFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/EndUsers/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUser fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EndUser fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EndUser.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EndUser content = EndUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserReader.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserReader.java new file mode 100644 index 0000000000..34a742b444 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserReader extends Reader { + + private Long pageSize; + + public EndUserReader() {} + + public EndUserReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + EndUser.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/EndUsers"; + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + EndUser.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "EndUser read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + EndUser.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserType.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserType.java new file mode 100644 index 0000000000..24fb669995 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserType.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class EndUserType extends Resource { + + public static EndUserTypeFetcher fetcher(final String pathSid) { + return new EndUserTypeFetcher(pathSid); + } + + public static EndUserTypeReader reader() { + return new EndUserTypeReader(); + } + + /** + * Converts a JSON String into a EndUserType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return EndUserType object represented by the provided JSON + */ + public static EndUserType fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EndUserType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a EndUserType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return EndUserType object represented by the provided JSON + */ + public static EndUserType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, EndUserType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List fields; + + @Getter + private final String friendlyName; + + @Getter + private final String machineName; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private EndUserType( + @JsonProperty("fields") final List fields, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("machine_name") final String machineName, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.fields = fields; + this.friendlyName = friendlyName; + this.machineName = machineName; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + EndUserType other = (EndUserType) o; + return ( + Objects.equals(fields, other.fields) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(machineName, other.machineName) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(fields, friendlyName, machineName, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeFetcher.java new file mode 100644 index 0000000000..34c9595907 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserTypeFetcher extends Fetcher { + + private String pathSid; + + public EndUserTypeFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/EndUserTypes/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUserType fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EndUserType fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return EndUserType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EndUserType content = EndUserType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeReader.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeReader.java new file mode 100644 index 0000000000..b75fb39c7e --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserTypeReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserTypeReader extends Reader { + + private Long pageSize; + + public EndUserTypeReader() {} + + public EndUserTypeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "end_user_types", + response.getContent(), + EndUserType.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/EndUserTypes"; + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "end_user_types", + response.getContent(), + EndUserType.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "EndUserType read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "end_user_types", + response.getContent(), + EndUserType.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/EndUserUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/EndUserUpdater.java new file mode 100644 index 0000000000..bb1a2efbf0 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/EndUserUpdater.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class EndUserUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private Object attributes; + + public EndUserUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public EndUserUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public EndUserUpdater setAttributes(final Object attributes) { + this.attributes = attributes; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/EndUsers/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "EndUser update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public EndUser update(final TwilioRestClient client) { + Response response = makeRequest(client); + return EndUser.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + EndUser content = EndUser.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/Policies.java b/src/main/java/com/twilio/rest/trusthub/v1/Policies.java new file mode 100644 index 0000000000..1d47da815e --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/Policies.java @@ -0,0 +1,153 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Policies extends Resource { + + public static PoliciesFetcher fetcher(final String pathSid) { + return new PoliciesFetcher(pathSid); + } + + public static PoliciesReader reader() { + return new PoliciesReader(); + } + + /** + * Converts a JSON String into a Policies object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Policies object represented by the provided JSON + */ + public static Policies fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Policies.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Policies object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Policies object represented by the provided JSON + */ + public static Policies fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Policies.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String friendlyName; + + @Getter + private final Object requirements; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Policies( + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("requirements") final Object requirements, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.friendlyName = friendlyName; + this.requirements = requirements; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Policies other = (Policies) o; + return ( + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(requirements, other.requirements) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(friendlyName, requirements, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/PoliciesFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/PoliciesFetcher.java new file mode 100644 index 0000000000..7e8df5348b --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/PoliciesFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PoliciesFetcher extends Fetcher { + + private String pathSid; + + public PoliciesFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/Policies/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Policies fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Policies fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Policies.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Policies content = Policies.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/PoliciesReader.java b/src/main/java/com/twilio/rest/trusthub/v1/PoliciesReader.java new file mode 100644 index 0000000000..916d632090 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/PoliciesReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class PoliciesReader extends Reader { + + private Long pageSize; + + public PoliciesReader() {} + + public PoliciesReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Policies.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/Policies"; + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + Policies.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Policies read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + Policies.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocument.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocument.java new file mode 100644 index 0000000000..2e5294f6e2 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocument.java @@ -0,0 +1,255 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SupportingDocument extends Resource { + + public static SupportingDocumentCreator creator( + final String friendlyName, + final String type + ) { + return new SupportingDocumentCreator(friendlyName, type); + } + + public static SupportingDocumentDeleter deleter(final String pathSid) { + return new SupportingDocumentDeleter(pathSid); + } + + public static SupportingDocumentFetcher fetcher(final String pathSid) { + return new SupportingDocumentFetcher(pathSid); + } + + public static SupportingDocumentReader reader() { + return new SupportingDocumentReader(); + } + + public static SupportingDocumentUpdater updater(final String pathSid) { + return new SupportingDocumentUpdater(pathSid); + } + + public enum Status { + DRAFT("DRAFT"), + PENDING_REVIEW("PENDING_REVIEW"), + REJECTED("REJECTED"), + APPROVED("APPROVED"), + EXPIRED("EXPIRED"), + PROVISIONALLY_APPROVED("PROVISIONALLY_APPROVED"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a SupportingDocument object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocument object represented by the provided JSON + */ + public static SupportingDocument fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SupportingDocument.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SupportingDocument object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocument object represented by the provided JSON + */ + public static SupportingDocument fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SupportingDocument.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Object attributes; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String friendlyName; + + @Getter + private final String mimeType; + + @Getter + private final String sid; + + @Getter + private final SupportingDocument.Status status; + + @Getter + private final String type; + + @Getter + private final URI url; + + @JsonCreator + private SupportingDocument( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("attributes") final Object attributes, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("mime_type") final String mimeType, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final SupportingDocument.Status status, + @JsonProperty("type") final String type, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.attributes = attributes; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.friendlyName = friendlyName; + this.mimeType = mimeType; + this.sid = sid; + this.status = status; + this.type = type; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SupportingDocument other = (SupportingDocument) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(attributes, other.attributes) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(mimeType, other.mimeType) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(type, other.type) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + attributes, + dateCreated, + dateUpdated, + friendlyName, + mimeType, + sid, + status, + type, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentCreator.java new file mode 100644 index 0000000000..133933b2a6 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentCreator.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentCreator extends Creator { + + private String friendlyName; + private String type; + private Object attributes; + + public SupportingDocumentCreator( + final String friendlyName, + final String type + ) { + this.friendlyName = friendlyName; + this.type = type; + } + + public SupportingDocumentCreator setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public SupportingDocumentCreator setType(final String type) { + this.type = type; + return this; + } + + public SupportingDocumentCreator setAttributes(final Object attributes) { + this.attributes = attributes; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SupportingDocuments"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SupportingDocument create(final TwilioRestClient client) { + Response response = makeRequest(client); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SupportingDocument content = SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (type != null) { + Serializer.toString( + request, + "Type", + type, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentDeleter.java new file mode 100644 index 0000000000..e96ecdfff5 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class SupportingDocumentDeleter extends Deleter { + + private String pathSid; + + public SupportingDocumentDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SupportingDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentFetcher.java new file mode 100644 index 0000000000..580cec8ebd --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentFetcher extends Fetcher { + + private String pathSid; + + public SupportingDocumentFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SupportingDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SupportingDocument fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SupportingDocument content = SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentReader.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentReader.java new file mode 100644 index 0000000000..0f61a4bbd4 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentReader extends Reader { + + private Long pageSize; + + public SupportingDocumentReader() {} + + public SupportingDocumentReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + SupportingDocument.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/SupportingDocuments"; + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + SupportingDocument.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + SupportingDocument.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentType.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentType.java new file mode 100644 index 0000000000..99d66b2774 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentType.java @@ -0,0 +1,160 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class SupportingDocumentType extends Resource { + + public static SupportingDocumentTypeFetcher fetcher(final String pathSid) { + return new SupportingDocumentTypeFetcher(pathSid); + } + + public static SupportingDocumentTypeReader reader() { + return new SupportingDocumentTypeReader(); + } + + /** + * Converts a JSON String into a SupportingDocumentType object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocumentType object represented by the provided JSON + */ + public static SupportingDocumentType fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SupportingDocumentType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a SupportingDocumentType object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return SupportingDocumentType object represented by the provided JSON + */ + public static SupportingDocumentType fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, SupportingDocumentType.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final List fields; + + @Getter + private final String friendlyName; + + @Getter + private final String machineName; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private SupportingDocumentType( + @JsonProperty("fields") final List fields, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("machine_name") final String machineName, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.fields = fields; + this.friendlyName = friendlyName; + this.machineName = machineName; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + SupportingDocumentType other = (SupportingDocumentType) o; + return ( + Objects.equals(fields, other.fields) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(machineName, other.machineName) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(fields, friendlyName, machineName, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeFetcher.java new file mode 100644 index 0000000000..1a490d9cbe --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeFetcher.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentTypeFetcher + extends Fetcher { + + private String pathSid; + + public SupportingDocumentTypeFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SupportingDocumentTypes/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocumentType fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SupportingDocumentType fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return SupportingDocumentType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SupportingDocumentType content = SupportingDocumentType.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeReader.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeReader.java new file mode 100644 index 0000000000..ad3729bbda --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentTypeReader.java @@ -0,0 +1,207 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentTypeReader + extends Reader { + + private Long pageSize; + + public SupportingDocumentTypeReader() {} + + public SupportingDocumentTypeReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "supporting_document_types", + response.getContent(), + SupportingDocumentType.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/SupportingDocumentTypes"; + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "supporting_document_types", + response.getContent(), + SupportingDocumentType.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "SupportingDocumentType read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "supporting_document_types", + response.getContent(), + SupportingDocumentType.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentUpdater.java new file mode 100644 index 0000000000..37847e24cb --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/SupportingDocumentUpdater.java @@ -0,0 +1,135 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SupportingDocumentUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private Object attributes; + + public SupportingDocumentUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public SupportingDocumentUpdater setFriendlyName( + final String friendlyName + ) { + this.friendlyName = friendlyName; + return this; + } + + public SupportingDocumentUpdater setAttributes(final Object attributes) { + this.attributes = attributes; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/SupportingDocuments/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "SupportingDocument update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public SupportingDocument update(final TwilioRestClient client) { + Response response = makeRequest(client); + return SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + SupportingDocument content = SupportingDocument.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (attributes != null) { + Serializer.toString( + request, + "Attributes", + attributes, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProducts.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProducts.java new file mode 100644 index 0000000000..8d14475a5d --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProducts.java @@ -0,0 +1,283 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TrustProducts extends Resource { + + public static TrustProductsCreator creator( + final String friendlyName, + final String email, + final String policySid + ) { + return new TrustProductsCreator(friendlyName, email, policySid); + } + + public static TrustProductsDeleter deleter(final String pathSid) { + return new TrustProductsDeleter(pathSid); + } + + public static TrustProductsFetcher fetcher(final String pathSid) { + return new TrustProductsFetcher(pathSid); + } + + public static TrustProductsReader reader() { + return new TrustProductsReader(); + } + + public static TrustProductsUpdater updater(final String pathSid) { + return new TrustProductsUpdater(pathSid); + } + + public enum Status { + DRAFT("draft"), + PENDING_REVIEW("pending-review"), + IN_REVIEW("in-review"), + TWILIO_REJECTED("twilio-rejected"), + TWILIO_APPROVED("twilio-approved"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a TrustProducts object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProducts object represented by the provided JSON + */ + public static TrustProducts fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TrustProducts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TrustProducts object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProducts object represented by the provided JSON + */ + public static TrustProducts fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TrustProducts.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final List errors; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final String policySid; + + @Getter + private final String sid; + + @Getter + private final TrustProducts.Status status; + + @Getter + private final URI statusCallback; + + @Getter + private final URI url; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime validUntil; + + @JsonCreator + private TrustProducts( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("errors") final List errors, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final TrustProducts.Status status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("url") final URI url, + @JsonProperty("valid_until") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime validUntil + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.errors = errors; + this.friendlyName = friendlyName; + this.links = links; + this.policySid = policySid; + this.sid = sid; + this.status = status; + this.statusCallback = statusCallback; + this.url = url; + this.validUntil = validUntil; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TrustProducts other = (TrustProducts) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(errors, other.errors) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(policySid, other.policySid) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(url, other.url) && + Objects.equals(validUntil, other.validUntil) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + email, + errors, + friendlyName, + links, + policySid, + sid, + status, + statusCallback, + url, + validUntil + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsCreator.java new file mode 100644 index 0000000000..497c4b8fae --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsCreator.java @@ -0,0 +1,172 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class TrustProductsCreator extends Creator { + + private String friendlyName; + private String email; + private String policySid; + private URI statusCallback; + + public TrustProductsCreator( + final String friendlyName, + final String email, + final String policySid + ) { + this.friendlyName = friendlyName; + this.email = email; + this.policySid = policySid; + } + + public TrustProductsCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public TrustProductsCreator setEmail(final String email) { + this.email = email; + return this; + } + + public TrustProductsCreator setPolicySid(final String policySid) { + this.policySid = policySid; + return this; + } + + public TrustProductsCreator setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public TrustProductsCreator setStatusCallback(final String statusCallback) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts"; + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProducts creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProducts create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProducts content = TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + + if (policySid != null) { + Serializer.toString( + request, + "PolicySid", + policySid, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsDeleter.java new file mode 100644 index 0000000000..ff77722e96 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class TrustProductsDeleter extends Deleter { + + private String pathSid; + + public TrustProductsDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProducts delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsFetcher.java new file mode 100644 index 0000000000..2826affadb --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsFetcher.java @@ -0,0 +1,96 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsFetcher extends Fetcher { + + private String pathSid; + + public TrustProductsFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProducts fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProducts fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProducts content = TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopy.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopy.java new file mode 100644 index 0000000000..c92d6b7796 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopy.java @@ -0,0 +1,235 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TrustProductsProvisionalCopy extends Resource { + + public static TrustProductsProvisionalCopyCreator creator( + final String pathTrustProductSid + ) { + return new TrustProductsProvisionalCopyCreator(pathTrustProductSid); + } + + public static TrustProductsProvisionalCopyFetcher fetcher( + final String pathTrustProductSid + ) { + return new TrustProductsProvisionalCopyFetcher(pathTrustProductSid); + } + + /** + * Converts a JSON String into a TrustProductsProvisionalCopy object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsProvisionalCopy object represented by the provided JSON + */ + public static TrustProductsProvisionalCopy fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + TrustProductsProvisionalCopy.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TrustProductsProvisionalCopy object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsProvisionalCopy object represented by the provided JSON + */ + public static TrustProductsProvisionalCopy fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + TrustProductsProvisionalCopy.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String email; + + @Getter + private final String friendlyName; + + @Getter + private final String policySid; + + @Getter + private final String status; + + @Getter + private final URI statusCallback; + + @Getter + private final String trustProductSid; + + @Getter + private final URI url; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime validUntil; + + @JsonCreator + private TrustProductsProvisionalCopy( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("email") final String email, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("status") final String status, + @JsonProperty("status_callback") final URI statusCallback, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("url") final URI url, + @JsonProperty("valid_until") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime validUntil + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.email = email; + this.friendlyName = friendlyName; + this.policySid = policySid; + this.status = status; + this.statusCallback = statusCallback; + this.trustProductSid = trustProductSid; + this.url = url; + this.validUntil = validUntil; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TrustProductsProvisionalCopy other = (TrustProductsProvisionalCopy) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(email, other.email) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(policySid, other.policySid) && + Objects.equals(status, other.status) && + Objects.equals(statusCallback, other.statusCallback) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(url, other.url) && + Objects.equals(validUntil, other.validUntil) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + dateUpdated, + email, + friendlyName, + policySid, + status, + statusCallback, + trustProductSid, + url, + validUntil + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopyCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopyCreator.java new file mode 100644 index 0000000000..0ddd9d84fe --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopyCreator.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsProvisionalCopyCreator + extends Creator { + + private String pathTrustProductSid; + + public TrustProductsProvisionalCopyCreator( + final String pathTrustProductSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{TrustProductSid}/ProvisionalCopy"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsProvisionalCopy creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProductsProvisionalCopy create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TrustProductsProvisionalCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProductsProvisionalCopy content = + TrustProductsProvisionalCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopyFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopyFetcher.java new file mode 100644 index 0000000000..5eb1357ffa --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsProvisionalCopyFetcher.java @@ -0,0 +1,104 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsProvisionalCopyFetcher + extends Fetcher { + + private String pathTrustProductSid; + + public TrustProductsProvisionalCopyFetcher( + final String pathTrustProductSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{TrustProductSid}/ProvisionalCopy"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsProvisionalCopy fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProductsProvisionalCopy fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TrustProductsProvisionalCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProductsProvisionalCopy content = + TrustProductsProvisionalCopy.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsReader.java new file mode 100644 index 0000000000..0056e57298 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsReader.java @@ -0,0 +1,242 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsReader extends Reader { + + private TrustProducts.Status status; + private String friendlyName; + private String policySid; + private Long pageSize; + + public TrustProductsReader() {} + + public TrustProductsReader setStatus(final TrustProducts.Status status) { + this.status = status; + return this; + } + + public TrustProductsReader setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public TrustProductsReader setPolicySid(final String policySid) { + this.policySid = policySid; + return this; + } + + public TrustProductsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + TrustProducts.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts"; + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + TrustProducts.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TrustProducts read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + TrustProducts.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (status != null) { + Serializer.toString(request, "Status", status, ParameterType.QUERY); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.QUERY + ); + } + + if (policySid != null) { + Serializer.toString( + request, + "PolicySid", + policySid, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsUpdater.java b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsUpdater.java new file mode 100644 index 0000000000..e5ca4b7bf5 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/TrustProductsUpdater.java @@ -0,0 +1,169 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Promoter; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.net.URI; + +public class TrustProductsUpdater extends Updater { + + private String pathSid; + private TrustProducts.Status status; + private URI statusCallback; + private String friendlyName; + private String email; + + public TrustProductsUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public TrustProductsUpdater setStatus(final TrustProducts.Status status) { + this.status = status; + return this; + } + + public TrustProductsUpdater setStatusCallback(final URI statusCallback) { + this.statusCallback = statusCallback; + return this; + } + + public TrustProductsUpdater setStatusCallback(final String statusCallback) { + return setStatusCallback(Promoter.uriFromString(statusCallback)); + } + + public TrustProductsUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public TrustProductsUpdater setEmail(final String email) { + this.email = email; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProducts update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProducts update(final TwilioRestClient client) { + Response response = makeRequest(client); + return TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProducts content = TrustProducts.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (status != null) { + Serializer.toString( + request, + "Status", + status, + ParameterType.URLENCODED + ); + } + + if (statusCallback != null) { + Serializer.toString( + request, + "StatusCallback", + statusCallback, + ParameterType.URLENCODED + ); + } + + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (email != null) { + Serializer.toString( + request, + "Email", + email, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignment.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignment.java new file mode 100644 index 0000000000..cd12f5858b --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignment.java @@ -0,0 +1,226 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CustomerProfilesChannelEndpointAssignment extends Resource { + + public static CustomerProfilesChannelEndpointAssignmentCreator creator( + final String pathCustomerProfileSid, + final String channelEndpointType, + final String channelEndpointSid + ) { + return new CustomerProfilesChannelEndpointAssignmentCreator( + pathCustomerProfileSid, + channelEndpointType, + channelEndpointSid + ); + } + + public static CustomerProfilesChannelEndpointAssignmentDeleter deleter( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesChannelEndpointAssignmentDeleter( + pathCustomerProfileSid, + pathSid + ); + } + + public static CustomerProfilesChannelEndpointAssignmentFetcher fetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesChannelEndpointAssignmentFetcher( + pathCustomerProfileSid, + pathSid + ); + } + + public static CustomerProfilesChannelEndpointAssignmentReader reader( + final String pathCustomerProfileSid + ) { + return new CustomerProfilesChannelEndpointAssignmentReader( + pathCustomerProfileSid + ); + } + + /** + * Converts a JSON String into a CustomerProfilesChannelEndpointAssignment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesChannelEndpointAssignment object represented by the provided JSON + */ + public static CustomerProfilesChannelEndpointAssignment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomerProfilesChannelEndpointAssignment.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CustomerProfilesChannelEndpointAssignment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesChannelEndpointAssignment object represented by the provided JSON + */ + public static CustomerProfilesChannelEndpointAssignment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomerProfilesChannelEndpointAssignment.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String channelEndpointSid; + + @Getter + private final String channelEndpointType; + + @Getter + private final String customerProfileSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private CustomerProfilesChannelEndpointAssignment( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_endpoint_sid") final String channelEndpointSid, + @JsonProperty("channel_endpoint_type") final String channelEndpointType, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelEndpointSid = channelEndpointSid; + this.channelEndpointType = channelEndpointType; + this.customerProfileSid = customerProfileSid; + this.dateCreated = dateCreated; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomerProfilesChannelEndpointAssignment other = + (CustomerProfilesChannelEndpointAssignment) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelEndpointSid, other.channelEndpointSid) && + Objects.equals(channelEndpointType, other.channelEndpointType) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + channelEndpointSid, + channelEndpointType, + customerProfileSid, + dateCreated, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentCreator.java new file mode 100644 index 0000000000..0190e2cb20 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentCreator.java @@ -0,0 +1,152 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesChannelEndpointAssignmentCreator + extends Creator { + + private String pathCustomerProfileSid; + private String channelEndpointType; + private String channelEndpointSid; + + public CustomerProfilesChannelEndpointAssignmentCreator( + final String pathCustomerProfileSid, + final String channelEndpointType, + final String channelEndpointSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + this.channelEndpointType = channelEndpointType; + this.channelEndpointSid = channelEndpointSid; + } + + public CustomerProfilesChannelEndpointAssignmentCreator setChannelEndpointType( + final String channelEndpointType + ) { + this.channelEndpointType = channelEndpointType; + return this; + } + + public CustomerProfilesChannelEndpointAssignmentCreator setChannelEndpointSid( + final String channelEndpointSid + ) { + this.channelEndpointSid = channelEndpointSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesChannelEndpointAssignment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfilesChannelEndpointAssignment create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomerProfilesChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + CustomerProfilesChannelEndpointAssignment + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + CustomerProfilesChannelEndpointAssignment content = + CustomerProfilesChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (channelEndpointType != null) { + Serializer.toString( + request, + "ChannelEndpointType", + channelEndpointType, + ParameterType.URLENCODED + ); + } + + if (channelEndpointSid != null) { + Serializer.toString( + request, + "ChannelEndpointSid", + channelEndpointSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentDeleter.java new file mode 100644 index 0000000000..175cc67cf4 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentDeleter.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class CustomerProfilesChannelEndpointAssignmentDeleter + extends Deleter { + + private String pathCustomerProfileSid; + private String pathSid; + + public CustomerProfilesChannelEndpointAssignmentDeleter( + final String pathCustomerProfileSid, + final String pathSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid}"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesChannelEndpointAssignment delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentFetcher.java new file mode 100644 index 0000000000..85c177327b --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesChannelEndpointAssignmentFetcher + extends Fetcher { + + private String pathCustomerProfileSid; + private String pathSid; + + public CustomerProfilesChannelEndpointAssignmentFetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments/{Sid}"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesChannelEndpointAssignment fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfilesChannelEndpointAssignment fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomerProfilesChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + CustomerProfilesChannelEndpointAssignment + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + CustomerProfilesChannelEndpointAssignment content = + CustomerProfilesChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentReader.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentReader.java new file mode 100644 index 0000000000..e6480cd743 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesChannelEndpointAssignmentReader.java @@ -0,0 +1,252 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesChannelEndpointAssignmentReader + extends Reader { + + private String pathCustomerProfileSid; + private String channelEndpointSid; + private String channelEndpointSids; + private Long pageSize; + + public CustomerProfilesChannelEndpointAssignmentReader( + final String pathCustomerProfileSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + } + + public CustomerProfilesChannelEndpointAssignmentReader setChannelEndpointSid( + final String channelEndpointSid + ) { + this.channelEndpointSid = channelEndpointSid; + return this; + } + + public CustomerProfilesChannelEndpointAssignmentReader setChannelEndpointSids( + final String channelEndpointSids + ) { + this.channelEndpointSids = channelEndpointSids; + return this; + } + + public CustomerProfilesChannelEndpointAssignmentReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse< + CustomerProfilesChannelEndpointAssignment + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + CustomerProfilesChannelEndpointAssignment.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/ChannelEndpointAssignments"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + CustomerProfilesChannelEndpointAssignment.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesChannelEndpointAssignment read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + CustomerProfilesChannelEndpointAssignment.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (channelEndpointSid != null) { + Serializer.toString( + request, + "ChannelEndpointSid", + channelEndpointSid, + ParameterType.QUERY + ); + } + + if (channelEndpointSids != null) { + Serializer.toString( + request, + "ChannelEndpointSids", + channelEndpointSids, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignments.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignments.java new file mode 100644 index 0000000000..016cf2830e --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignments.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CustomerProfilesEntityAssignments extends Resource { + + public static CustomerProfilesEntityAssignmentsCreator creator( + final String pathCustomerProfileSid, + final String objectSid + ) { + return new CustomerProfilesEntityAssignmentsCreator( + pathCustomerProfileSid, + objectSid + ); + } + + public static CustomerProfilesEntityAssignmentsDeleter deleter( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesEntityAssignmentsDeleter( + pathCustomerProfileSid, + pathSid + ); + } + + public static CustomerProfilesEntityAssignmentsFetcher fetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesEntityAssignmentsFetcher( + pathCustomerProfileSid, + pathSid + ); + } + + public static CustomerProfilesEntityAssignmentsReader reader( + final String pathCustomerProfileSid + ) { + return new CustomerProfilesEntityAssignmentsReader( + pathCustomerProfileSid + ); + } + + /** + * Converts a JSON String into a CustomerProfilesEntityAssignments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesEntityAssignments object represented by the provided JSON + */ + public static CustomerProfilesEntityAssignments fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomerProfilesEntityAssignments.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CustomerProfilesEntityAssignments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesEntityAssignments object represented by the provided JSON + */ + public static CustomerProfilesEntityAssignments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomerProfilesEntityAssignments.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String customerProfileSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String objectSid; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private CustomerProfilesEntityAssignments( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("object_sid") final String objectSid, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.customerProfileSid = customerProfileSid; + this.dateCreated = dateCreated; + this.objectSid = objectSid; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomerProfilesEntityAssignments other = + (CustomerProfilesEntityAssignments) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(objectSid, other.objectSid) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + customerProfileSid, + dateCreated, + objectSid, + sid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsCreator.java new file mode 100644 index 0000000000..71212eee8e --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsCreator.java @@ -0,0 +1,133 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesEntityAssignmentsCreator + extends Creator { + + private String pathCustomerProfileSid; + private String objectSid; + + public CustomerProfilesEntityAssignmentsCreator( + final String pathCustomerProfileSid, + final String objectSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + this.objectSid = objectSid; + } + + public CustomerProfilesEntityAssignmentsCreator setObjectSid( + final String objectSid + ) { + this.objectSid = objectSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesEntityAssignments creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfilesEntityAssignments create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomerProfilesEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfilesEntityAssignments content = + CustomerProfilesEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (objectSid != null) { + Serializer.toString( + request, + "ObjectSid", + objectSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsDeleter.java new file mode 100644 index 0000000000..8ec3715126 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsDeleter.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class CustomerProfilesEntityAssignmentsDeleter + extends Deleter { + + private String pathCustomerProfileSid; + private String pathSid; + + public CustomerProfilesEntityAssignmentsDeleter( + final String pathCustomerProfileSid, + final String pathSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments/{Sid}"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesEntityAssignments delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsFetcher.java new file mode 100644 index 0000000000..995484806e --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesEntityAssignmentsFetcher + extends Fetcher { + + private String pathCustomerProfileSid; + private String pathSid; + + public CustomerProfilesEntityAssignmentsFetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments/{Sid}"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesEntityAssignments fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfilesEntityAssignments fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return CustomerProfilesEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfilesEntityAssignments content = + CustomerProfilesEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsReader.java new file mode 100644 index 0000000000..63ad179675 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEntityAssignmentsReader.java @@ -0,0 +1,235 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesEntityAssignmentsReader + extends Reader { + + private String pathCustomerProfileSid; + private String objectType; + private Long pageSize; + + public CustomerProfilesEntityAssignmentsReader( + final String pathCustomerProfileSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + } + + public CustomerProfilesEntityAssignmentsReader setObjectType( + final String objectType + ) { + this.objectType = objectType; + return this; + } + + public CustomerProfilesEntityAssignmentsReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse< + CustomerProfilesEntityAssignments + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + CustomerProfilesEntityAssignments.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/EntityAssignments"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + CustomerProfilesEntityAssignments.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesEntityAssignments read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + CustomerProfilesEntityAssignments.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (objectType != null) { + Serializer.toString( + request, + "ObjectType", + objectType, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluations.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluations.java new file mode 100644 index 0000000000..ca6814e60e --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluations.java @@ -0,0 +1,242 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class CustomerProfilesEvaluations extends Resource { + + public static CustomerProfilesEvaluationsCreator creator( + final String pathCustomerProfileSid, + final String policySid + ) { + return new CustomerProfilesEvaluationsCreator( + pathCustomerProfileSid, + policySid + ); + } + + public static CustomerProfilesEvaluationsFetcher fetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + return new CustomerProfilesEvaluationsFetcher( + pathCustomerProfileSid, + pathSid + ); + } + + public static CustomerProfilesEvaluationsReader reader( + final String pathCustomerProfileSid + ) { + return new CustomerProfilesEvaluationsReader(pathCustomerProfileSid); + } + + public enum Status { + COMPLIANT("compliant"), + NONCOMPLIANT("noncompliant"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a CustomerProfilesEvaluations object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesEvaluations object represented by the provided JSON + */ + public static CustomerProfilesEvaluations fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomerProfilesEvaluations.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a CustomerProfilesEvaluations object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return CustomerProfilesEvaluations object represented by the provided JSON + */ + public static CustomerProfilesEvaluations fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + CustomerProfilesEvaluations.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String customerProfileSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String policySid; + + @Getter + private final List results; + + @Getter + private final String sid; + + @Getter + private final CustomerProfilesEvaluations.Status status; + + @Getter + private final URI url; + + @JsonCreator + private CustomerProfilesEvaluations( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("customer_profile_sid") final String customerProfileSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("results") final List results, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final CustomerProfilesEvaluations.Status status, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.customerProfileSid = customerProfileSid; + this.dateCreated = dateCreated; + this.policySid = policySid; + this.results = results; + this.sid = sid; + this.status = status; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + CustomerProfilesEvaluations other = (CustomerProfilesEvaluations) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(customerProfileSid, other.customerProfileSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(policySid, other.policySid) && + Objects.equals(results, other.results) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + customerProfileSid, + dateCreated, + policySid, + results, + sid, + status, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsCreator.java new file mode 100644 index 0000000000..6bbd72578d --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsCreator.java @@ -0,0 +1,130 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesEvaluationsCreator + extends Creator { + + private String pathCustomerProfileSid; + private String policySid; + + public CustomerProfilesEvaluationsCreator( + final String pathCustomerProfileSid, + final String policySid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + this.policySid = policySid; + } + + public CustomerProfilesEvaluationsCreator setPolicySid( + final String policySid + ) { + this.policySid = policySid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesEvaluations creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfilesEvaluations create(final TwilioRestClient client) { + Response response = makeRequest(client); + return CustomerProfilesEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfilesEvaluations content = + CustomerProfilesEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (policySid != null) { + Serializer.toString( + request, + "PolicySid", + policySid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsFetcher.java new file mode 100644 index 0000000000..b7addfb845 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsFetcher.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesEvaluationsFetcher + extends Fetcher { + + private String pathCustomerProfileSid; + private String pathSid; + + public CustomerProfilesEvaluationsFetcher( + final String pathCustomerProfileSid, + final String pathSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations/{Sid}"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesEvaluations fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public CustomerProfilesEvaluations fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return CustomerProfilesEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + CustomerProfilesEvaluations content = + CustomerProfilesEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsReader.java new file mode 100644 index 0000000000..507c6c27e7 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/customerprofiles/CustomerProfilesEvaluationsReader.java @@ -0,0 +1,215 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.customerprofiles; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class CustomerProfilesEvaluationsReader + extends Reader { + + private String pathCustomerProfileSid; + private Long pageSize; + + public CustomerProfilesEvaluationsReader( + final String pathCustomerProfileSid + ) { + this.pathCustomerProfileSid = pathCustomerProfileSid; + } + + public CustomerProfilesEvaluationsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + CustomerProfilesEvaluations.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/CustomerProfiles/{CustomerProfileSid}/Evaluations"; + + path = + path.replace( + "{" + "CustomerProfileSid" + "}", + this.pathCustomerProfileSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + CustomerProfilesEvaluations.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "CustomerProfilesEvaluations read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + CustomerProfilesEvaluations.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignment.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignment.java new file mode 100644 index 0000000000..6e9e6feeab --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignment.java @@ -0,0 +1,226 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TrustProductsChannelEndpointAssignment extends Resource { + + public static TrustProductsChannelEndpointAssignmentCreator creator( + final String pathTrustProductSid, + final String channelEndpointType, + final String channelEndpointSid + ) { + return new TrustProductsChannelEndpointAssignmentCreator( + pathTrustProductSid, + channelEndpointType, + channelEndpointSid + ); + } + + public static TrustProductsChannelEndpointAssignmentDeleter deleter( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsChannelEndpointAssignmentDeleter( + pathTrustProductSid, + pathSid + ); + } + + public static TrustProductsChannelEndpointAssignmentFetcher fetcher( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsChannelEndpointAssignmentFetcher( + pathTrustProductSid, + pathSid + ); + } + + public static TrustProductsChannelEndpointAssignmentReader reader( + final String pathTrustProductSid + ) { + return new TrustProductsChannelEndpointAssignmentReader( + pathTrustProductSid + ); + } + + /** + * Converts a JSON String into a TrustProductsChannelEndpointAssignment object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsChannelEndpointAssignment object represented by the provided JSON + */ + public static TrustProductsChannelEndpointAssignment fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + TrustProductsChannelEndpointAssignment.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TrustProductsChannelEndpointAssignment object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsChannelEndpointAssignment object represented by the provided JSON + */ + public static TrustProductsChannelEndpointAssignment fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + TrustProductsChannelEndpointAssignment.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final String channelEndpointSid; + + @Getter + private final String channelEndpointType; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String sid; + + @Getter + private final String trustProductSid; + + @Getter + private final URI url; + + @JsonCreator + private TrustProductsChannelEndpointAssignment( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channel_endpoint_sid") final String channelEndpointSid, + @JsonProperty("channel_endpoint_type") final String channelEndpointType, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("sid") final String sid, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.channelEndpointSid = channelEndpointSid; + this.channelEndpointType = channelEndpointType; + this.dateCreated = dateCreated; + this.sid = sid; + this.trustProductSid = trustProductSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TrustProductsChannelEndpointAssignment other = + (TrustProductsChannelEndpointAssignment) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channelEndpointSid, other.channelEndpointSid) && + Objects.equals(channelEndpointType, other.channelEndpointType) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(sid, other.sid) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + channelEndpointSid, + channelEndpointType, + dateCreated, + sid, + trustProductSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentCreator.java new file mode 100644 index 0000000000..ba2476aa72 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentCreator.java @@ -0,0 +1,152 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsChannelEndpointAssignmentCreator + extends Creator { + + private String pathTrustProductSid; + private String channelEndpointType; + private String channelEndpointSid; + + public TrustProductsChannelEndpointAssignmentCreator( + final String pathTrustProductSid, + final String channelEndpointType, + final String channelEndpointSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + this.channelEndpointType = channelEndpointType; + this.channelEndpointSid = channelEndpointSid; + } + + public TrustProductsChannelEndpointAssignmentCreator setChannelEndpointType( + final String channelEndpointType + ) { + this.channelEndpointType = channelEndpointType; + return this; + } + + public TrustProductsChannelEndpointAssignmentCreator setChannelEndpointSid( + final String channelEndpointSid + ) { + this.channelEndpointSid = channelEndpointSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsChannelEndpointAssignment creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProductsChannelEndpointAssignment create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return TrustProductsChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + TrustProductsChannelEndpointAssignment + > createWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + TrustProductsChannelEndpointAssignment content = + TrustProductsChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (channelEndpointType != null) { + Serializer.toString( + request, + "ChannelEndpointType", + channelEndpointType, + ParameterType.URLENCODED + ); + } + + if (channelEndpointSid != null) { + Serializer.toString( + request, + "ChannelEndpointSid", + channelEndpointSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentDeleter.java new file mode 100644 index 0000000000..f2f9b21f53 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentDeleter.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class TrustProductsChannelEndpointAssignmentDeleter + extends Deleter { + + private String pathTrustProductSid; + private String pathSid; + + public TrustProductsChannelEndpointAssignmentDeleter( + final String pathTrustProductSid, + final String pathSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid}"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsChannelEndpointAssignment delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentFetcher.java new file mode 100644 index 0000000000..413e813b95 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentFetcher.java @@ -0,0 +1,111 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsChannelEndpointAssignmentFetcher + extends Fetcher { + + private String pathTrustProductSid; + private String pathSid; + + public TrustProductsChannelEndpointAssignmentFetcher( + final String pathTrustProductSid, + final String pathSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments/{Sid}"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsChannelEndpointAssignment fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProductsChannelEndpointAssignment fetch( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return TrustProductsChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse< + TrustProductsChannelEndpointAssignment + > fetchWithResponse(final TwilioRestClient client) { + Response response = makeRequest(client); + TrustProductsChannelEndpointAssignment content = + TrustProductsChannelEndpointAssignment.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentReader.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentReader.java new file mode 100644 index 0000000000..65e3e0fc9d --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsChannelEndpointAssignmentReader.java @@ -0,0 +1,252 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsChannelEndpointAssignmentReader + extends Reader { + + private String pathTrustProductSid; + private String channelEndpointSid; + private String channelEndpointSids; + private Long pageSize; + + public TrustProductsChannelEndpointAssignmentReader( + final String pathTrustProductSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + } + + public TrustProductsChannelEndpointAssignmentReader setChannelEndpointSid( + final String channelEndpointSid + ) { + this.channelEndpointSid = channelEndpointSid; + return this; + } + + public TrustProductsChannelEndpointAssignmentReader setChannelEndpointSids( + final String channelEndpointSids + ) { + this.channelEndpointSids = channelEndpointSids; + return this; + } + + public TrustProductsChannelEndpointAssignmentReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse< + TrustProductsChannelEndpointAssignment + > readWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + TrustProductsChannelEndpointAssignment.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = + "/v1/TrustProducts/{TrustProductSid}/ChannelEndpointAssignments"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + TrustProductsChannelEndpointAssignment.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TrustProductsChannelEndpointAssignment read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + TrustProductsChannelEndpointAssignment.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (channelEndpointSid != null) { + Serializer.toString( + request, + "ChannelEndpointSid", + channelEndpointSid, + ParameterType.QUERY + ); + } + + if (channelEndpointSids != null) { + Serializer.toString( + request, + "ChannelEndpointSids", + channelEndpointSids, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignments.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignments.java new file mode 100644 index 0000000000..b37aa7d9ad --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignments.java @@ -0,0 +1,215 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TrustProductsEntityAssignments extends Resource { + + public static TrustProductsEntityAssignmentsCreator creator( + final String pathTrustProductSid, + final String objectSid + ) { + return new TrustProductsEntityAssignmentsCreator( + pathTrustProductSid, + objectSid + ); + } + + public static TrustProductsEntityAssignmentsDeleter deleter( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsEntityAssignmentsDeleter( + pathTrustProductSid, + pathSid + ); + } + + public static TrustProductsEntityAssignmentsFetcher fetcher( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsEntityAssignmentsFetcher( + pathTrustProductSid, + pathSid + ); + } + + public static TrustProductsEntityAssignmentsReader reader( + final String pathTrustProductSid + ) { + return new TrustProductsEntityAssignmentsReader(pathTrustProductSid); + } + + /** + * Converts a JSON String into a TrustProductsEntityAssignments object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsEntityAssignments object represented by the provided JSON + */ + public static TrustProductsEntityAssignments fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + TrustProductsEntityAssignments.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TrustProductsEntityAssignments object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsEntityAssignments object represented by the provided JSON + */ + public static TrustProductsEntityAssignments fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue( + json, + TrustProductsEntityAssignments.class + ); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String objectSid; + + @Getter + private final String sid; + + @Getter + private final String trustProductSid; + + @Getter + private final URI url; + + @JsonCreator + private TrustProductsEntityAssignments( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("object_sid") final String objectSid, + @JsonProperty("sid") final String sid, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.objectSid = objectSid; + this.sid = sid; + this.trustProductSid = trustProductSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TrustProductsEntityAssignments other = + (TrustProductsEntityAssignments) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(objectSid, other.objectSid) && + Objects.equals(sid, other.sid) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + objectSid, + sid, + trustProductSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsCreator.java new file mode 100644 index 0000000000..6940e8ac29 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsCreator.java @@ -0,0 +1,132 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsEntityAssignmentsCreator + extends Creator { + + private String pathTrustProductSid; + private String objectSid; + + public TrustProductsEntityAssignmentsCreator( + final String pathTrustProductSid, + final String objectSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + this.objectSid = objectSid; + } + + public TrustProductsEntityAssignmentsCreator setObjectSid( + final String objectSid + ) { + this.objectSid = objectSid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{TrustProductSid}/EntityAssignments"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsEntityAssignments creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProductsEntityAssignments create( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + return TrustProductsEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProductsEntityAssignments content = + TrustProductsEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (objectSid != null) { + Serializer.toString( + request, + "ObjectSid", + objectSid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsDeleter.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsDeleter.java new file mode 100644 index 0000000000..0d884fbd5a --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsDeleter.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class TrustProductsEntityAssignmentsDeleter + extends Deleter { + + private String pathTrustProductSid; + private String pathSid; + + public TrustProductsEntityAssignmentsDeleter( + final String pathTrustProductSid, + final String pathSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/TrustProducts/{TrustProductSid}/EntityAssignments/{Sid}"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsEntityAssignments delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsFetcher.java new file mode 100644 index 0000000000..541e982fca --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsFetcher.java @@ -0,0 +1,109 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsEntityAssignmentsFetcher + extends Fetcher { + + private String pathTrustProductSid; + private String pathSid; + + public TrustProductsEntityAssignmentsFetcher( + final String pathTrustProductSid, + final String pathSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = + "/v1/TrustProducts/{TrustProductSid}/EntityAssignments/{Sid}"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsEntityAssignments fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProductsEntityAssignments fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TrustProductsEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProductsEntityAssignments content = + TrustProductsEntityAssignments.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsReader.java new file mode 100644 index 0000000000..825a679bd3 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEntityAssignmentsReader.java @@ -0,0 +1,234 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsEntityAssignmentsReader + extends Reader { + + private String pathTrustProductSid; + private String objectType; + private Long pageSize; + + public TrustProductsEntityAssignmentsReader( + final String pathTrustProductSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + } + + public TrustProductsEntityAssignmentsReader setObjectType( + final String objectType + ) { + this.objectType = objectType; + return this; + } + + public TrustProductsEntityAssignmentsReader setPageSize( + final Long pageSize + ) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + TrustProductsEntityAssignments.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = + new ResourceSet<>(this, client, page); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{TrustProductSid}/EntityAssignments"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse< + Page + > firstPageWithResponse(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + TrustProductsEntityAssignments.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TrustProductsEntityAssignments read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + TrustProductsEntityAssignments.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (objectType != null) { + Serializer.toString( + request, + "ObjectType", + objectType, + ParameterType.QUERY + ); + } + + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluations.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluations.java new file mode 100644 index 0000000000..f5dc61dd50 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluations.java @@ -0,0 +1,236 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class TrustProductsEvaluations extends Resource { + + public static TrustProductsEvaluationsCreator creator( + final String pathTrustProductSid, + final String policySid + ) { + return new TrustProductsEvaluationsCreator( + pathTrustProductSid, + policySid + ); + } + + public static TrustProductsEvaluationsFetcher fetcher( + final String pathTrustProductSid, + final String pathSid + ) { + return new TrustProductsEvaluationsFetcher( + pathTrustProductSid, + pathSid + ); + } + + public static TrustProductsEvaluationsReader reader( + final String pathTrustProductSid + ) { + return new TrustProductsEvaluationsReader(pathTrustProductSid); + } + + public enum Status { + COMPLIANT("compliant"), + NONCOMPLIANT("noncompliant"); + + private final String value; + + private Status(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static Status forValue(final String value) { + return Promoter.enumFromString(value, Status.values()); + } + } + + /** + * Converts a JSON String into a TrustProductsEvaluations object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsEvaluations object represented by the provided JSON + */ + public static TrustProductsEvaluations fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TrustProductsEvaluations.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a TrustProductsEvaluations object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return TrustProductsEvaluations object represented by the provided JSON + */ + public static TrustProductsEvaluations fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, TrustProductsEvaluations.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @Getter + private final String policySid; + + @Getter + private final List results; + + @Getter + private final String sid; + + @Getter + private final TrustProductsEvaluations.Status status; + + @Getter + private final String trustProductSid; + + @Getter + private final URI url; + + @JsonCreator + private TrustProductsEvaluations( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("policy_sid") final String policySid, + @JsonProperty("results") final List results, + @JsonProperty("sid") final String sid, + @JsonProperty("status") final TrustProductsEvaluations.Status status, + @JsonProperty("trust_product_sid") final String trustProductSid, + @JsonProperty("url") final URI url + ) { + this.accountSid = accountSid; + this.dateCreated = dateCreated; + this.policySid = policySid; + this.results = results; + this.sid = sid; + this.status = status; + this.trustProductSid = trustProductSid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + TrustProductsEvaluations other = (TrustProductsEvaluations) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(policySid, other.policySid) && + Objects.equals(results, other.results) && + Objects.equals(sid, other.sid) && + Objects.equals(status, other.status) && + Objects.equals(trustProductSid, other.trustProductSid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + dateCreated, + policySid, + results, + sid, + status, + trustProductSid, + url + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsCreator.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsCreator.java new file mode 100644 index 0000000000..41f5024442 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsCreator.java @@ -0,0 +1,129 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsEvaluationsCreator + extends Creator { + + private String pathTrustProductSid; + private String policySid; + + public TrustProductsEvaluationsCreator( + final String pathTrustProductSid, + final String policySid + ) { + this.pathTrustProductSid = pathTrustProductSid; + this.policySid = policySid; + } + + public TrustProductsEvaluationsCreator setPolicySid( + final String policySid + ) { + this.policySid = policySid; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{TrustProductSid}/Evaluations"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + + Request request = new Request( + HttpMethod.POST, + Domains.TRUSTHUB.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsEvaluations creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProductsEvaluations create(final TwilioRestClient client) { + Response response = makeRequest(client); + return TrustProductsEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProductsEvaluations content = TrustProductsEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (policySid != null) { + Serializer.toString( + request, + "PolicySid", + policySid, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsFetcher.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsFetcher.java new file mode 100644 index 0000000000..4582cbeb25 --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsFetcher.java @@ -0,0 +1,107 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsEvaluationsFetcher + extends Fetcher { + + private String pathTrustProductSid; + private String pathSid; + + public TrustProductsEvaluationsFetcher( + final String pathTrustProductSid, + final String pathSid + ) { + this.pathTrustProductSid = pathTrustProductSid; + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{TrustProductSid}/Evaluations/{Sid}"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "TrustProductsEvaluations fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public TrustProductsEvaluations fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return TrustProductsEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + TrustProductsEvaluations content = TrustProductsEvaluations.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsReader.java b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsReader.java new file mode 100644 index 0000000000..ab3eb4d20b --- /dev/null +++ b/src/main/java/com/twilio/rest/trusthub/v1/trustproducts/TrustProductsEvaluationsReader.java @@ -0,0 +1,216 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Trusthub + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.trusthub.v1.trustproducts; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TrustProductsEvaluationsReader + extends Reader { + + private String pathTrustProductSid; + private Long pageSize; + + public TrustProductsEvaluationsReader(final String pathTrustProductSid) { + this.pathTrustProductSid = pathTrustProductSid; + } + + public TrustProductsEvaluationsReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + TrustProductsEvaluations.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v1/TrustProducts/{TrustProductSid}/Evaluations"; + + path = + path.replace( + "{" + "TrustProductSid" + "}", + this.pathTrustProductSid.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.TRUSTHUB.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read( + final TwilioRestClient client + ) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "results", + response.getContent(), + TrustProductsEvaluations.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "TrustProductsEvaluations read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "results", + response.getContent(), + TrustProductsEvaluations.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/Form.java b/src/main/java/com/twilio/rest/verify/v2/Form.java new file mode 100644 index 0000000000..e11c68d2cb --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/Form.java @@ -0,0 +1,171 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.converter.Promoter; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Form extends Resource { + + public static FormFetcher fetcher(final Form.FormTypes pathFormType) { + return new FormFetcher(pathFormType); + } + + public enum FormTypes { + FORM_PUSH("form-push"); + + private final String value; + + private FormTypes(final String value) { + this.value = value; + } + + @JsonValue + public String toString() { + return value; + } + + @JsonCreator + public static FormTypes forValue(final String value) { + return Promoter.enumFromString(value, FormTypes.values()); + } + } + + /** + * Converts a JSON String into a Form object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Form object represented by the provided JSON + */ + public static Form fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Form.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Form object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Form object represented by the provided JSON + */ + public static Form fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Form.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final Object formMeta; + + @Getter + private final Form.FormTypes formType; + + @Getter + private final Object forms; + + @Getter + private final URI url; + + @JsonCreator + private Form( + @JsonProperty("form_meta") final Object formMeta, + @JsonProperty("form_type") final Form.FormTypes formType, + @JsonProperty("forms") final Object forms, + @JsonProperty("url") final URI url + ) { + this.formMeta = formMeta; + this.formType = formType; + this.forms = forms; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Form other = (Form) o; + return ( + Objects.equals(formMeta, other.formMeta) && + Objects.equals(formType, other.formType) && + Objects.equals(forms, other.forms) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(formMeta, formType, forms, url); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/FormFetcher.java b/src/main/java/com/twilio/rest/verify/v2/FormFetcher.java new file mode 100644 index 0000000000..ecec6fdec2 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/FormFetcher.java @@ -0,0 +1,94 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class FormFetcher extends Fetcher
    { + + private Form.FormTypes pathFormType; + + public FormFetcher(final Form.FormTypes pathFormType) { + this.pathFormType = pathFormType; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Forms/{FormType}"; + + path = + path.replace("{" + "FormType" + "}", this.pathFormType.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.VERIFY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Form fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Form fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Form.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Form content = Form.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/Safelist.java b/src/main/java/com/twilio/rest/verify/v2/Safelist.java new file mode 100644 index 0000000000..ab15073c50 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/Safelist.java @@ -0,0 +1,151 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Safelist extends Resource { + + public static SafelistCreator creator(final String phoneNumber) { + return new SafelistCreator(phoneNumber); + } + + public static SafelistDeleter deleter(final String pathPhoneNumber) { + return new SafelistDeleter(pathPhoneNumber); + } + + public static SafelistFetcher fetcher(final String pathPhoneNumber) { + return new SafelistFetcher(pathPhoneNumber); + } + + /** + * Converts a JSON String into a Safelist object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Safelist object represented by the provided JSON + */ + public static Safelist fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Safelist.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Safelist object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Safelist object represented by the provided JSON + */ + public static Safelist fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Safelist.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String phoneNumber; + + @Getter + private final String sid; + + @Getter + private final URI url; + + @JsonCreator + private Safelist( + @JsonProperty("phone_number") final String phoneNumber, + @JsonProperty("sid") final String sid, + @JsonProperty("url") final URI url + ) { + this.phoneNumber = phoneNumber; + this.sid = sid; + this.url = url; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Safelist other = (Safelist) o; + return ( + Objects.equals(phoneNumber, other.phoneNumber) && + Objects.equals(sid, other.sid) && + Objects.equals(url, other.url) + ); + } + + @Override + public int hashCode() { + return Objects.hash(phoneNumber, sid, url); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/SafelistCreator.java b/src/main/java/com/twilio/rest/verify/v2/SafelistCreator.java new file mode 100644 index 0000000000..48f7729363 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/SafelistCreator.java @@ -0,0 +1,115 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SafelistCreator extends Creator { + + private String phoneNumber; + + public SafelistCreator(final String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public SafelistCreator setPhoneNumber(final String phoneNumber) { + this.phoneNumber = phoneNumber; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/SafeList/Numbers"; + + Request request = new Request( + HttpMethod.POST, + Domains.VERIFY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Safelist creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Safelist create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Safelist content = Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (phoneNumber != null) { + Serializer.toString( + request, + "PhoneNumber", + phoneNumber, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/SafelistDeleter.java b/src/main/java/com/twilio/rest/verify/v2/SafelistDeleter.java new file mode 100644 index 0000000000..eb15cd0751 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/SafelistDeleter.java @@ -0,0 +1,101 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class SafelistDeleter extends Deleter { + + private String pathPhoneNumber; + + public SafelistDeleter(final String pathPhoneNumber) { + this.pathPhoneNumber = pathPhoneNumber; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/SafeList/Numbers/{PhoneNumber}"; + + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.VERIFY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Safelist delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/SafelistFetcher.java b/src/main/java/com/twilio/rest/verify/v2/SafelistFetcher.java new file mode 100644 index 0000000000..c04f4ca822 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/SafelistFetcher.java @@ -0,0 +1,100 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class SafelistFetcher extends Fetcher { + + private String pathPhoneNumber; + + public SafelistFetcher(final String pathPhoneNumber) { + this.pathPhoneNumber = pathPhoneNumber; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/SafeList/Numbers/{PhoneNumber}"; + + path = + path.replace( + "{" + "PhoneNumber" + "}", + this.pathPhoneNumber.toString() + ); + + Request request = new Request( + HttpMethod.GET, + Domains.VERIFY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Safelist fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Safelist fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Safelist content = Safelist.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/Service.java b/src/main/java/com/twilio/rest/verify/v2/Service.java new file mode 100644 index 0000000000..cfd329e741 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/Service.java @@ -0,0 +1,313 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.time.ZonedDateTime; +import java.util.Map; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Service extends Resource { + + public static ServiceCreator creator(final String friendlyName) { + return new ServiceCreator(friendlyName); + } + + public static ServiceDeleter deleter(final String pathSid) { + return new ServiceDeleter(pathSid); + } + + public static ServiceFetcher fetcher(final String pathSid) { + return new ServiceFetcher(pathSid); + } + + public static ServiceReader reader() { + return new ServiceReader(); + } + + public static ServiceUpdater updater(final String pathSid) { + return new ServiceUpdater(pathSid); + } + + /** + * Converts a JSON String into a Service object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Service.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Service object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Service object represented by the provided JSON + */ + public static Service fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Service.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final Integer codeLength; + + @Getter + private final Boolean customCodeEnabled; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateCreated; + + @JsonSerialize(using = com.twilio.converter.ISO8601Serializer.class) + @Getter + private final ZonedDateTime dateUpdated; + + @Getter + private final String defaultTemplateSid; + + @Getter + private final Boolean doNotShareWarningEnabled; + + @Getter + private final Boolean dtmfInputRequired; + + @Getter + private final String friendlyName; + + @Getter + private final Map links; + + @Getter + private final Boolean lookupEnabled; + + @Getter + private final Object passkeys; + + @Getter + private final Boolean psd2Enabled; + + @Getter + private final Object push; + + @Getter + private final String sid; + + @Getter + private final Boolean skipSmsToLandlines; + + @Getter + private final Object totp; + + @Getter + private final String ttsName; + + @Getter + private final URI url; + + @Getter + private final Boolean verifyEventSubscriptionEnabled; + + @Getter + private final Object whatsapp; + + @JsonCreator + private Service( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("code_length") final Integer codeLength, + @JsonProperty("custom_code_enabled") final Boolean customCodeEnabled, + @JsonProperty("date_created") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateCreated, + @JsonProperty("date_updated") @JsonDeserialize( + using = com.twilio.converter.ISO8601Deserializer.class + ) @JsonSerialize( + using = com.twilio.converter.ISO8601Serializer.class + ) final ZonedDateTime dateUpdated, + @JsonProperty("default_template_sid") final String defaultTemplateSid, + @JsonProperty( + "do_not_share_warning_enabled" + ) final Boolean doNotShareWarningEnabled, + @JsonProperty("dtmf_input_required") final Boolean dtmfInputRequired, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("links") final Map links, + @JsonProperty("lookup_enabled") final Boolean lookupEnabled, + @JsonProperty("passkeys") final Object passkeys, + @JsonProperty("psd2_enabled") final Boolean psd2Enabled, + @JsonProperty("push") final Object push, + @JsonProperty("sid") final String sid, + @JsonProperty("skip_sms_to_landlines") final Boolean skipSmsToLandlines, + @JsonProperty("totp") final Object totp, + @JsonProperty("tts_name") final String ttsName, + @JsonProperty("url") final URI url, + @JsonProperty( + "verify_event_subscription_enabled" + ) final Boolean verifyEventSubscriptionEnabled, + @JsonProperty("whatsapp") final Object whatsapp + ) { + this.accountSid = accountSid; + this.codeLength = codeLength; + this.customCodeEnabled = customCodeEnabled; + this.dateCreated = dateCreated; + this.dateUpdated = dateUpdated; + this.defaultTemplateSid = defaultTemplateSid; + this.doNotShareWarningEnabled = doNotShareWarningEnabled; + this.dtmfInputRequired = dtmfInputRequired; + this.friendlyName = friendlyName; + this.links = links; + this.lookupEnabled = lookupEnabled; + this.passkeys = passkeys; + this.psd2Enabled = psd2Enabled; + this.push = push; + this.sid = sid; + this.skipSmsToLandlines = skipSmsToLandlines; + this.totp = totp; + this.ttsName = ttsName; + this.url = url; + this.verifyEventSubscriptionEnabled = verifyEventSubscriptionEnabled; + this.whatsapp = whatsapp; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Service other = (Service) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(codeLength, other.codeLength) && + Objects.equals(customCodeEnabled, other.customCodeEnabled) && + Objects.equals(dateCreated, other.dateCreated) && + Objects.equals(dateUpdated, other.dateUpdated) && + Objects.equals(defaultTemplateSid, other.defaultTemplateSid) && + Objects.equals( + doNotShareWarningEnabled, + other.doNotShareWarningEnabled + ) && + Objects.equals(dtmfInputRequired, other.dtmfInputRequired) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(links, other.links) && + Objects.equals(lookupEnabled, other.lookupEnabled) && + Objects.equals(passkeys, other.passkeys) && + Objects.equals(psd2Enabled, other.psd2Enabled) && + Objects.equals(push, other.push) && + Objects.equals(sid, other.sid) && + Objects.equals(skipSmsToLandlines, other.skipSmsToLandlines) && + Objects.equals(totp, other.totp) && + Objects.equals(ttsName, other.ttsName) && + Objects.equals(url, other.url) && + Objects.equals( + verifyEventSubscriptionEnabled, + other.verifyEventSubscriptionEnabled + ) && + Objects.equals(whatsapp, other.whatsapp) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + codeLength, + customCodeEnabled, + dateCreated, + dateUpdated, + defaultTemplateSid, + doNotShareWarningEnabled, + dtmfInputRequired, + friendlyName, + links, + lookupEnabled, + passkeys, + psd2Enabled, + push, + sid, + skipSmsToLandlines, + totp, + ttsName, + url, + verifyEventSubscriptionEnabled, + whatsapp + ); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceCreator.java b/src/main/java/com/twilio/rest/verify/v2/ServiceCreator.java new file mode 100644 index 0000000000..363a5a6c45 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceCreator.java @@ -0,0 +1,517 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Creator; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceCreator extends Creator { + + private String friendlyName; + private Integer codeLength; + private Boolean lookupEnabled; + private Boolean skipSmsToLandlines; + private Boolean dtmfInputRequired; + private String ttsName; + private Boolean psd2Enabled; + private Boolean doNotShareWarningEnabled; + private Boolean customCodeEnabled; + private Boolean pushIncludeDate; + private String pushApnCredentialSid; + private String pushFcmCredentialSid; + private String totpIssuer; + private Integer totpTimeStep; + private Integer totpCodeLength; + private Integer totpSkew; + private String defaultTemplateSid; + private String whatsappMsgServiceSid; + private String whatsappFrom; + private String passkeysRelyingPartyId; + private String passkeysRelyingPartyName; + private String passkeysRelyingPartyOrigins; + private String passkeysAuthenticatorAttachment; + private String passkeysDiscoverableCredentials; + private String passkeysUserVerification; + private Boolean verifyEventSubscriptionEnabled; + + public ServiceCreator(final String friendlyName) { + this.friendlyName = friendlyName; + } + + public ServiceCreator setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ServiceCreator setCodeLength(final Integer codeLength) { + this.codeLength = codeLength; + return this; + } + + public ServiceCreator setLookupEnabled(final Boolean lookupEnabled) { + this.lookupEnabled = lookupEnabled; + return this; + } + + public ServiceCreator setSkipSmsToLandlines( + final Boolean skipSmsToLandlines + ) { + this.skipSmsToLandlines = skipSmsToLandlines; + return this; + } + + public ServiceCreator setDtmfInputRequired( + final Boolean dtmfInputRequired + ) { + this.dtmfInputRequired = dtmfInputRequired; + return this; + } + + public ServiceCreator setTtsName(final String ttsName) { + this.ttsName = ttsName; + return this; + } + + public ServiceCreator setPsd2Enabled(final Boolean psd2Enabled) { + this.psd2Enabled = psd2Enabled; + return this; + } + + public ServiceCreator setDoNotShareWarningEnabled( + final Boolean doNotShareWarningEnabled + ) { + this.doNotShareWarningEnabled = doNotShareWarningEnabled; + return this; + } + + public ServiceCreator setCustomCodeEnabled( + final Boolean customCodeEnabled + ) { + this.customCodeEnabled = customCodeEnabled; + return this; + } + + public ServiceCreator setPushIncludeDate(final Boolean pushIncludeDate) { + this.pushIncludeDate = pushIncludeDate; + return this; + } + + public ServiceCreator setPushApnCredentialSid( + final String pushApnCredentialSid + ) { + this.pushApnCredentialSid = pushApnCredentialSid; + return this; + } + + public ServiceCreator setPushFcmCredentialSid( + final String pushFcmCredentialSid + ) { + this.pushFcmCredentialSid = pushFcmCredentialSid; + return this; + } + + public ServiceCreator setTotpIssuer(final String totpIssuer) { + this.totpIssuer = totpIssuer; + return this; + } + + public ServiceCreator setTotpTimeStep(final Integer totpTimeStep) { + this.totpTimeStep = totpTimeStep; + return this; + } + + public ServiceCreator setTotpCodeLength(final Integer totpCodeLength) { + this.totpCodeLength = totpCodeLength; + return this; + } + + public ServiceCreator setTotpSkew(final Integer totpSkew) { + this.totpSkew = totpSkew; + return this; + } + + public ServiceCreator setDefaultTemplateSid( + final String defaultTemplateSid + ) { + this.defaultTemplateSid = defaultTemplateSid; + return this; + } + + public ServiceCreator setWhatsappMsgServiceSid( + final String whatsappMsgServiceSid + ) { + this.whatsappMsgServiceSid = whatsappMsgServiceSid; + return this; + } + + public ServiceCreator setWhatsappFrom(final String whatsappFrom) { + this.whatsappFrom = whatsappFrom; + return this; + } + + public ServiceCreator setPasskeysRelyingPartyId( + final String passkeysRelyingPartyId + ) { + this.passkeysRelyingPartyId = passkeysRelyingPartyId; + return this; + } + + public ServiceCreator setPasskeysRelyingPartyName( + final String passkeysRelyingPartyName + ) { + this.passkeysRelyingPartyName = passkeysRelyingPartyName; + return this; + } + + public ServiceCreator setPasskeysRelyingPartyOrigins( + final String passkeysRelyingPartyOrigins + ) { + this.passkeysRelyingPartyOrigins = passkeysRelyingPartyOrigins; + return this; + } + + public ServiceCreator setPasskeysAuthenticatorAttachment( + final String passkeysAuthenticatorAttachment + ) { + this.passkeysAuthenticatorAttachment = passkeysAuthenticatorAttachment; + return this; + } + + public ServiceCreator setPasskeysDiscoverableCredentials( + final String passkeysDiscoverableCredentials + ) { + this.passkeysDiscoverableCredentials = passkeysDiscoverableCredentials; + return this; + } + + public ServiceCreator setPasskeysUserVerification( + final String passkeysUserVerification + ) { + this.passkeysUserVerification = passkeysUserVerification; + return this; + } + + public ServiceCreator setVerifyEventSubscriptionEnabled( + final Boolean verifyEventSubscriptionEnabled + ) { + this.verifyEventSubscriptionEnabled = verifyEventSubscriptionEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services"; + + Request request = new Request( + HttpMethod.POST, + Domains.VERIFY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service creation failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service create(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse createWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (codeLength != null) { + Serializer.toString( + request, + "CodeLength", + codeLength, + ParameterType.URLENCODED + ); + } + + if (lookupEnabled != null) { + Serializer.toString( + request, + "LookupEnabled", + lookupEnabled, + ParameterType.URLENCODED + ); + } + + if (skipSmsToLandlines != null) { + Serializer.toString( + request, + "SkipSmsToLandlines", + skipSmsToLandlines, + ParameterType.URLENCODED + ); + } + + if (dtmfInputRequired != null) { + Serializer.toString( + request, + "DtmfInputRequired", + dtmfInputRequired, + ParameterType.URLENCODED + ); + } + + if (ttsName != null) { + Serializer.toString( + request, + "TtsName", + ttsName, + ParameterType.URLENCODED + ); + } + + if (psd2Enabled != null) { + Serializer.toString( + request, + "Psd2Enabled", + psd2Enabled, + ParameterType.URLENCODED + ); + } + + if (doNotShareWarningEnabled != null) { + Serializer.toString( + request, + "DoNotShareWarningEnabled", + doNotShareWarningEnabled, + ParameterType.URLENCODED + ); + } + + if (customCodeEnabled != null) { + Serializer.toString( + request, + "CustomCodeEnabled", + customCodeEnabled, + ParameterType.URLENCODED + ); + } + + if (pushIncludeDate != null) { + Serializer.toString( + request, + "Push.IncludeDate", + pushIncludeDate, + ParameterType.URLENCODED + ); + } + + if (pushApnCredentialSid != null) { + Serializer.toString( + request, + "Push.ApnCredentialSid", + pushApnCredentialSid, + ParameterType.URLENCODED + ); + } + + if (pushFcmCredentialSid != null) { + Serializer.toString( + request, + "Push.FcmCredentialSid", + pushFcmCredentialSid, + ParameterType.URLENCODED + ); + } + + if (totpIssuer != null) { + Serializer.toString( + request, + "Totp.Issuer", + totpIssuer, + ParameterType.URLENCODED + ); + } + + if (totpTimeStep != null) { + Serializer.toString( + request, + "Totp.TimeStep", + totpTimeStep, + ParameterType.URLENCODED + ); + } + + if (totpCodeLength != null) { + Serializer.toString( + request, + "Totp.CodeLength", + totpCodeLength, + ParameterType.URLENCODED + ); + } + + if (totpSkew != null) { + Serializer.toString( + request, + "Totp.Skew", + totpSkew, + ParameterType.URLENCODED + ); + } + + if (defaultTemplateSid != null) { + Serializer.toString( + request, + "DefaultTemplateSid", + defaultTemplateSid, + ParameterType.URLENCODED + ); + } + + if (whatsappMsgServiceSid != null) { + Serializer.toString( + request, + "Whatsapp.MsgServiceSid", + whatsappMsgServiceSid, + ParameterType.URLENCODED + ); + } + + if (whatsappFrom != null) { + Serializer.toString( + request, + "Whatsapp.From", + whatsappFrom, + ParameterType.URLENCODED + ); + } + + if (passkeysRelyingPartyId != null) { + Serializer.toString( + request, + "Passkeys.RelyingParty.Id", + passkeysRelyingPartyId, + ParameterType.URLENCODED + ); + } + + if (passkeysRelyingPartyName != null) { + Serializer.toString( + request, + "Passkeys.RelyingParty.Name", + passkeysRelyingPartyName, + ParameterType.URLENCODED + ); + } + + if (passkeysRelyingPartyOrigins != null) { + Serializer.toString( + request, + "Passkeys.RelyingParty.Origins", + passkeysRelyingPartyOrigins, + ParameterType.URLENCODED + ); + } + + if (passkeysAuthenticatorAttachment != null) { + Serializer.toString( + request, + "Passkeys.AuthenticatorAttachment", + passkeysAuthenticatorAttachment, + ParameterType.URLENCODED + ); + } + + if (passkeysDiscoverableCredentials != null) { + Serializer.toString( + request, + "Passkeys.DiscoverableCredentials", + passkeysDiscoverableCredentials, + ParameterType.URLENCODED + ); + } + + if (passkeysUserVerification != null) { + Serializer.toString( + request, + "Passkeys.UserVerification", + passkeysUserVerification, + ParameterType.URLENCODED + ); + } + + if (verifyEventSubscriptionEnabled != null) { + Serializer.toString( + request, + "VerifyEventSubscriptionEnabled", + verifyEventSubscriptionEnabled, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceDeleter.java b/src/main/java/com/twilio/rest/verify/v2/ServiceDeleter.java new file mode 100644 index 0000000000..5aab8972e4 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceDeleter.java @@ -0,0 +1,97 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Deleter; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; +import java.util.function.Predicate; + +public class ServiceDeleter extends Deleter { + + private String pathSid; + + public ServiceDeleter(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Request request = new Request( + HttpMethod.DELETE, + Domains.VERIFY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service delete failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public boolean delete(final TwilioRestClient client) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + return deleteStatuses.test(response.getStatusCode()); + } + + @Override + public TwilioResponse deleteWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Predicate deleteStatuses = i -> + i != null && i >= 200 && i < 300; + Boolean deleted = deleteStatuses.test(response.getStatusCode()); + return new TwilioResponse<>( + deleted, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceFetcher.java b/src/main/java/com/twilio/rest/verify/v2/ServiceFetcher.java new file mode 100644 index 0000000000..074194c40c --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceFetcher.java @@ -0,0 +1,93 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Fetcher; +import com.twilio.base.TwilioResponse; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceFetcher extends Fetcher { + + private String pathSid; + + public ServiceFetcher(final String pathSid) { + this.pathSid = pathSid; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.GET, + Domains.VERIFY.toString(), + path + ); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service fetch failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service fetch(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse fetchWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceReader.java b/src/main/java/com/twilio/rest/verify/v2/ServiceReader.java new file mode 100644 index 0000000000..6b027a970e --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceReader.java @@ -0,0 +1,202 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceReader extends Reader { + + private Long pageSize; + + public ServiceReader() {} + + public ServiceReader setPageSize(final Long pageSize) { + this.pageSize = pageSize; + return this; + } + + public ResourceSetResponse readWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + ResourceSet resourceSet = new ResourceSet<>( + this, + client, + page + ); + return new ResourceSetResponse<>( + resourceSet, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Request buildFirstPageRequest(final TwilioRestClient client) { + String path = "/v2/Services"; + + Request request = new Request( + HttpMethod.GET, + Domains.VERIFY.toString(), + path + ); + addQueryParams(request); + return request; + } + + @Override + public ResourceSet read(final TwilioRestClient client) { + return new ResourceSet<>(this, client, firstPage(client)); + } + + public Page firstPage(final TwilioRestClient client) { + Request request = buildFirstPageRequest(client); + return pageForRequest(client, request); + } + + public TwilioResponse> firstPageWithResponse( + final TwilioRestClient client + ) { + Request request = buildFirstPageRequest(client); + Response response = makeRequest(client, request); + Page page = Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + return new TwilioResponse<>( + page, + response.getStatusCode(), + response.getHeaders() + ); + } + + private Response makeRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = client.request(request); + if (response == null) { + throw new ApiConnectionException( + "Service read failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + private Page pageForRequest( + final TwilioRestClient client, + final Request request + ) { + Response response = makeRequest(client, request); + return Page.fromJson( + "services", + response.getContent(), + Service.class, + client.getObjectMapper() + ); + } + + @Override + public Page previousPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getPreviousPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page nextPage( + final Page page, + final TwilioRestClient client + ) { + Request request = new Request( + HttpMethod.GET, + page.getNextPageUrl(Domains.API.toString()) + ); + return pageForRequest(client, request); + } + + @Override + public Page getPage( + final String targetUrl, + final TwilioRestClient client + ) { + if (!com.twilio.http.HttpUtility.isValidTwilioUrl(targetUrl)) { + throw new ApiException( + "Invalid URL: URL must be a valid Twilio domain" + ); + } + Request request = new Request(HttpMethod.GET, targetUrl); + return pageForRequest(client, request); + } + + private void addQueryParams(final Request request) { + if (pageSize != null) { + Serializer.toString( + request, + "PageSize", + pageSize, + ParameterType.QUERY + ); + } + + if (getPageSize() != null) { + request.addQueryParam("PageSize", Integer.toString(getPageSize())); + } + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/ServiceUpdater.java b/src/main/java/com/twilio/rest/verify/v2/ServiceUpdater.java new file mode 100644 index 0000000000..8f83e69cdf --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/ServiceUpdater.java @@ -0,0 +1,520 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.TwilioResponse; +import com.twilio.base.Updater; +import com.twilio.constant.EnumConstants; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class ServiceUpdater extends Updater { + + private String pathSid; + private String friendlyName; + private Integer codeLength; + private Boolean lookupEnabled; + private Boolean skipSmsToLandlines; + private Boolean dtmfInputRequired; + private String ttsName; + private Boolean psd2Enabled; + private Boolean doNotShareWarningEnabled; + private Boolean customCodeEnabled; + private Boolean pushIncludeDate; + private String pushApnCredentialSid; + private String pushFcmCredentialSid; + private String totpIssuer; + private Integer totpTimeStep; + private Integer totpCodeLength; + private Integer totpSkew; + private String defaultTemplateSid; + private String whatsappMsgServiceSid; + private String whatsappFrom; + private String passkeysRelyingPartyId; + private String passkeysRelyingPartyName; + private String passkeysRelyingPartyOrigins; + private String passkeysAuthenticatorAttachment; + private String passkeysDiscoverableCredentials; + private String passkeysUserVerification; + private Boolean verifyEventSubscriptionEnabled; + + public ServiceUpdater(final String pathSid) { + this.pathSid = pathSid; + } + + public ServiceUpdater setFriendlyName(final String friendlyName) { + this.friendlyName = friendlyName; + return this; + } + + public ServiceUpdater setCodeLength(final Integer codeLength) { + this.codeLength = codeLength; + return this; + } + + public ServiceUpdater setLookupEnabled(final Boolean lookupEnabled) { + this.lookupEnabled = lookupEnabled; + return this; + } + + public ServiceUpdater setSkipSmsToLandlines( + final Boolean skipSmsToLandlines + ) { + this.skipSmsToLandlines = skipSmsToLandlines; + return this; + } + + public ServiceUpdater setDtmfInputRequired( + final Boolean dtmfInputRequired + ) { + this.dtmfInputRequired = dtmfInputRequired; + return this; + } + + public ServiceUpdater setTtsName(final String ttsName) { + this.ttsName = ttsName; + return this; + } + + public ServiceUpdater setPsd2Enabled(final Boolean psd2Enabled) { + this.psd2Enabled = psd2Enabled; + return this; + } + + public ServiceUpdater setDoNotShareWarningEnabled( + final Boolean doNotShareWarningEnabled + ) { + this.doNotShareWarningEnabled = doNotShareWarningEnabled; + return this; + } + + public ServiceUpdater setCustomCodeEnabled( + final Boolean customCodeEnabled + ) { + this.customCodeEnabled = customCodeEnabled; + return this; + } + + public ServiceUpdater setPushIncludeDate(final Boolean pushIncludeDate) { + this.pushIncludeDate = pushIncludeDate; + return this; + } + + public ServiceUpdater setPushApnCredentialSid( + final String pushApnCredentialSid + ) { + this.pushApnCredentialSid = pushApnCredentialSid; + return this; + } + + public ServiceUpdater setPushFcmCredentialSid( + final String pushFcmCredentialSid + ) { + this.pushFcmCredentialSid = pushFcmCredentialSid; + return this; + } + + public ServiceUpdater setTotpIssuer(final String totpIssuer) { + this.totpIssuer = totpIssuer; + return this; + } + + public ServiceUpdater setTotpTimeStep(final Integer totpTimeStep) { + this.totpTimeStep = totpTimeStep; + return this; + } + + public ServiceUpdater setTotpCodeLength(final Integer totpCodeLength) { + this.totpCodeLength = totpCodeLength; + return this; + } + + public ServiceUpdater setTotpSkew(final Integer totpSkew) { + this.totpSkew = totpSkew; + return this; + } + + public ServiceUpdater setDefaultTemplateSid( + final String defaultTemplateSid + ) { + this.defaultTemplateSid = defaultTemplateSid; + return this; + } + + public ServiceUpdater setWhatsappMsgServiceSid( + final String whatsappMsgServiceSid + ) { + this.whatsappMsgServiceSid = whatsappMsgServiceSid; + return this; + } + + public ServiceUpdater setWhatsappFrom(final String whatsappFrom) { + this.whatsappFrom = whatsappFrom; + return this; + } + + public ServiceUpdater setPasskeysRelyingPartyId( + final String passkeysRelyingPartyId + ) { + this.passkeysRelyingPartyId = passkeysRelyingPartyId; + return this; + } + + public ServiceUpdater setPasskeysRelyingPartyName( + final String passkeysRelyingPartyName + ) { + this.passkeysRelyingPartyName = passkeysRelyingPartyName; + return this; + } + + public ServiceUpdater setPasskeysRelyingPartyOrigins( + final String passkeysRelyingPartyOrigins + ) { + this.passkeysRelyingPartyOrigins = passkeysRelyingPartyOrigins; + return this; + } + + public ServiceUpdater setPasskeysAuthenticatorAttachment( + final String passkeysAuthenticatorAttachment + ) { + this.passkeysAuthenticatorAttachment = passkeysAuthenticatorAttachment; + return this; + } + + public ServiceUpdater setPasskeysDiscoverableCredentials( + final String passkeysDiscoverableCredentials + ) { + this.passkeysDiscoverableCredentials = passkeysDiscoverableCredentials; + return this; + } + + public ServiceUpdater setPasskeysUserVerification( + final String passkeysUserVerification + ) { + this.passkeysUserVerification = passkeysUserVerification; + return this; + } + + public ServiceUpdater setVerifyEventSubscriptionEnabled( + final Boolean verifyEventSubscriptionEnabled + ) { + this.verifyEventSubscriptionEnabled = verifyEventSubscriptionEnabled; + return this; + } + + private Response makeRequest(final TwilioRestClient client) { + String path = "/v2/Services/{Sid}"; + + path = path.replace("{" + "Sid" + "}", this.pathSid.toString()); + + Request request = new Request( + HttpMethod.POST, + Domains.VERIFY.toString(), + path + ); + request.setContentType(EnumConstants.ContentType.FORM_URLENCODED); + addPostParams(request); + + Response response = client.request(request); + + if (response == null) { + throw new ApiConnectionException( + "Service update failed: Unable to connect to server" + ); + } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) { + InputStream inputStream = response.getStream(); + RestException restException = RestException.fromJson( + inputStream, + client.getObjectMapper() + ); + if (restException == null) { + throw new ApiException( + "Server Error, no content", + response.getStatusCode() + ); + } + throw new ApiException(restException); + } + return response; + } + + @Override + public Service update(final TwilioRestClient client) { + Response response = makeRequest(client); + return Service.fromJson(response.getStream(), client.getObjectMapper()); + } + + @Override + public TwilioResponse updateWithResponse( + final TwilioRestClient client + ) { + Response response = makeRequest(client); + Service content = Service.fromJson( + response.getStream(), + client.getObjectMapper() + ); + return new TwilioResponse<>( + content, + response.getStatusCode(), + response.getHeaders() + ); + } + + private void addPostParams(final Request request) { + if (friendlyName != null) { + Serializer.toString( + request, + "FriendlyName", + friendlyName, + ParameterType.URLENCODED + ); + } + + if (codeLength != null) { + Serializer.toString( + request, + "CodeLength", + codeLength, + ParameterType.URLENCODED + ); + } + + if (lookupEnabled != null) { + Serializer.toString( + request, + "LookupEnabled", + lookupEnabled, + ParameterType.URLENCODED + ); + } + + if (skipSmsToLandlines != null) { + Serializer.toString( + request, + "SkipSmsToLandlines", + skipSmsToLandlines, + ParameterType.URLENCODED + ); + } + + if (dtmfInputRequired != null) { + Serializer.toString( + request, + "DtmfInputRequired", + dtmfInputRequired, + ParameterType.URLENCODED + ); + } + + if (ttsName != null) { + Serializer.toString( + request, + "TtsName", + ttsName, + ParameterType.URLENCODED + ); + } + + if (psd2Enabled != null) { + Serializer.toString( + request, + "Psd2Enabled", + psd2Enabled, + ParameterType.URLENCODED + ); + } + + if (doNotShareWarningEnabled != null) { + Serializer.toString( + request, + "DoNotShareWarningEnabled", + doNotShareWarningEnabled, + ParameterType.URLENCODED + ); + } + + if (customCodeEnabled != null) { + Serializer.toString( + request, + "CustomCodeEnabled", + customCodeEnabled, + ParameterType.URLENCODED + ); + } + + if (pushIncludeDate != null) { + Serializer.toString( + request, + "Push.IncludeDate", + pushIncludeDate, + ParameterType.URLENCODED + ); + } + + if (pushApnCredentialSid != null) { + Serializer.toString( + request, + "Push.ApnCredentialSid", + pushApnCredentialSid, + ParameterType.URLENCODED + ); + } + + if (pushFcmCredentialSid != null) { + Serializer.toString( + request, + "Push.FcmCredentialSid", + pushFcmCredentialSid, + ParameterType.URLENCODED + ); + } + + if (totpIssuer != null) { + Serializer.toString( + request, + "Totp.Issuer", + totpIssuer, + ParameterType.URLENCODED + ); + } + + if (totpTimeStep != null) { + Serializer.toString( + request, + "Totp.TimeStep", + totpTimeStep, + ParameterType.URLENCODED + ); + } + + if (totpCodeLength != null) { + Serializer.toString( + request, + "Totp.CodeLength", + totpCodeLength, + ParameterType.URLENCODED + ); + } + + if (totpSkew != null) { + Serializer.toString( + request, + "Totp.Skew", + totpSkew, + ParameterType.URLENCODED + ); + } + + if (defaultTemplateSid != null) { + Serializer.toString( + request, + "DefaultTemplateSid", + defaultTemplateSid, + ParameterType.URLENCODED + ); + } + + if (whatsappMsgServiceSid != null) { + Serializer.toString( + request, + "Whatsapp.MsgServiceSid", + whatsappMsgServiceSid, + ParameterType.URLENCODED + ); + } + + if (whatsappFrom != null) { + Serializer.toString( + request, + "Whatsapp.From", + whatsappFrom, + ParameterType.URLENCODED + ); + } + + if (passkeysRelyingPartyId != null) { + Serializer.toString( + request, + "Passkeys.RelyingParty.Id", + passkeysRelyingPartyId, + ParameterType.URLENCODED + ); + } + + if (passkeysRelyingPartyName != null) { + Serializer.toString( + request, + "Passkeys.RelyingParty.Name", + passkeysRelyingPartyName, + ParameterType.URLENCODED + ); + } + + if (passkeysRelyingPartyOrigins != null) { + Serializer.toString( + request, + "Passkeys.RelyingParty.Origins", + passkeysRelyingPartyOrigins, + ParameterType.URLENCODED + ); + } + + if (passkeysAuthenticatorAttachment != null) { + Serializer.toString( + request, + "Passkeys.AuthenticatorAttachment", + passkeysAuthenticatorAttachment, + ParameterType.URLENCODED + ); + } + + if (passkeysDiscoverableCredentials != null) { + Serializer.toString( + request, + "Passkeys.DiscoverableCredentials", + passkeysDiscoverableCredentials, + ParameterType.URLENCODED + ); + } + + if (passkeysUserVerification != null) { + Serializer.toString( + request, + "Passkeys.UserVerification", + passkeysUserVerification, + ParameterType.URLENCODED + ); + } + + if (verifyEventSubscriptionEnabled != null) { + Serializer.toString( + request, + "VerifyEventSubscriptionEnabled", + verifyEventSubscriptionEnabled, + ParameterType.URLENCODED + ); + } + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/Template.java b/src/main/java/com/twilio/rest/verify/v2/Template.java new file mode 100644 index 0000000000..b6e19cb155 --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/Template.java @@ -0,0 +1,161 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.twilio.base.Resource; +import com.twilio.base.Resource; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.type.*; +import java.io.IOException; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Objects; +import lombok.Getter; +import lombok.ToString; + +@JsonIgnoreProperties(ignoreUnknown = true) +@ToString +public class Template extends Resource { + + public static TemplateReader reader() { + return new TemplateReader(); + } + + /** + * Converts a JSON String into a Template object using the provided ObjectMapper. + * + * @param json Raw JSON String + * @param objectMapper Jackson ObjectMapper + * @return Template object represented by the provided JSON + */ + public static Template fromJson( + final String json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Template.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + /** + * Converts a JSON InputStream into a Template object using the provided + * ObjectMapper. + * + * @param json Raw JSON InputStream + * @param objectMapper Jackson ObjectMapper + * @return Template object represented by the provided JSON + */ + public static Template fromJson( + final InputStream json, + final ObjectMapper objectMapper + ) { + // Convert all checked exceptions to Runtime + try { + return objectMapper.readValue(json, Template.class); + } catch (final JsonMappingException | JsonParseException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + public static String toJson(Object object, ObjectMapper mapper) { + try { + return mapper.writeValueAsString(object); + } catch (final JsonMappingException e) { + throw new ApiException(e.getMessage(), e); + } catch (JsonProcessingException e) { + throw new ApiException(e.getMessage(), e); + } catch (final IOException e) { + throw new ApiConnectionException(e.getMessage(), e); + } + } + + @Getter + private final String accountSid; + + @Getter + private final List channels; + + @Getter + private final String friendlyName; + + @Getter + private final String sid; + + @Getter + private final Object translations; + + @JsonCreator + private Template( + @JsonProperty("account_sid") final String accountSid, + @JsonProperty("channels") final List channels, + @JsonProperty("friendly_name") final String friendlyName, + @JsonProperty("sid") final String sid, + @JsonProperty("translations") final Object translations + ) { + this.accountSid = accountSid; + this.channels = channels; + this.friendlyName = friendlyName; + this.sid = sid; + this.translations = translations; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } + + Template other = (Template) o; + return ( + Objects.equals(accountSid, other.accountSid) && + Objects.equals(channels, other.channels) && + Objects.equals(friendlyName, other.friendlyName) && + Objects.equals(sid, other.sid) && + Objects.equals(translations, other.translations) + ); + } + + @Override + public int hashCode() { + return Objects.hash( + accountSid, + channels, + friendlyName, + sid, + translations + ); + } +} diff --git a/src/main/java/com/twilio/rest/verify/v2/TemplateReader.java b/src/main/java/com/twilio/rest/verify/v2/TemplateReader.java new file mode 100644 index 0000000000..088c87707c --- /dev/null +++ b/src/main/java/com/twilio/rest/verify/v2/TemplateReader.java @@ -0,0 +1,217 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Verify + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.twilio.rest.verify.v2; + +import com.twilio.base.Page; +import com.twilio.base.Reader; +import com.twilio.base.ResourceSet; +import com.twilio.base.ResourceSetResponse; +import com.twilio.base.TwilioResponse; +import com.twilio.constant.EnumConstants.ParameterType; +import com.twilio.converter.Serializer; +import com.twilio.exception.ApiConnectionException; +import com.twilio.exception.ApiException; +import com.twilio.exception.RestException; +import com.twilio.http.HttpMethod; +import com.twilio.http.HttpUtility; +import com.twilio.http.Request; +import com.twilio.http.Response; +import com.twilio.http.TwilioRestClient; +import com.twilio.rest.Domains; +import com.twilio.type.*; +import java.io.InputStream; + +public class TemplateReader extends Reader